24
|
1 ;;; tex.el --- Support for TeX documents.
|
|
2
|
|
3 ;; Maintainer: Per Abrahamsen <auc-tex@sunsite.auc.dk>
|
|
4 ;; Version: 9.7i
|
|
5 ;; Keywords: wp
|
|
6 ;; X-URL: http://sunsite.auc.dk/auctex
|
|
7
|
|
8 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
|
|
9 ;; Copyright (C) 1987 Lars Peter Fischer
|
|
10 ;; Copyright (C) 1991 Kresten Krab Thorup
|
|
11 ;; Copyright (C) 1993, 1994, 1996, 1997 Per Abrahamsen
|
|
12 ;;
|
|
13 ;; This program is free software; you can redistribute it and/or modify
|
|
14 ;; it under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 1, or (at your option)
|
|
16 ;; any later version.
|
|
17 ;;
|
|
18 ;; This program is distributed in the hope that it will be useful,
|
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 ;; GNU General Public License for more details.
|
|
22 ;;
|
|
23 ;; You should have received a copy of the GNU General Public License
|
|
24 ;; along with this program; if not, write to the Free Software
|
|
25 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
26
|
|
27 ;;; Code:
|
|
28
|
|
29 ;;; Site Customization
|
|
30 ;;
|
|
31 ;; The following variables are likely to need to be changed for your
|
|
32 ;; site. It is suggested that you do this by *not* changing this
|
|
33 ;; file, but instead copy those definitions you need to change to
|
|
34 ;; `tex-site.el'.
|
|
35
|
|
36 (defvar TeX-lisp-directory "auctex/"
|
|
37 "*The directory where the AUC TeX lisp files are located.")
|
|
38
|
|
39 ;; Change this to point to the place where the TeX macros are stored
|
|
40 ;; at yourt site. [Ignore when bundled with XEmacs]
|
|
41 (defvar TeX-macro-global '("/usr/lib/texmf/tex/")
|
|
42 "*Directories containing the sites TeX macro files and style files.
|
|
43
|
|
44 The directory names *must* end with a slash.")
|
|
45
|
|
46 ;; How to print.
|
|
47
|
|
48 (defvar TeX-print-command "dvips %s -P%p"
|
|
49 "*Command used to print a file.
|
|
50
|
|
51 First %p is expanded to the printer name, then ordinary expansion is
|
|
52 performed as specified in TeX-expand-list.")
|
|
53
|
|
54 (defvar TeX-queue-command "lpq -P%p"
|
|
55 "*Command used to show the status of a printer queue.
|
|
56
|
|
57 First %p is expanded to the printer name, then ordinary expansion is
|
|
58 performed as specified in TeX-expand-list.")
|
|
59
|
|
60 ;; This is the major configuration variable. Most sites will only
|
|
61 ;; need to change the second string in each entry, which is the name
|
|
62 ;; of a command to send to the shell. If you use other formatters
|
|
63 ;; like AMSLaTeX or AMSTeX, you can add those to the list. See
|
|
64 ;; TeX-expand-list for a description of the % escapes
|
|
65
|
|
66 (defvar TeX-command-list
|
|
67 ;; You may have to remove the single quotes around the command
|
|
68 ;; arguments if you use DOS.
|
|
69 (list (list "TeX" "tex '\\nonstopmode\\input %t'" 'TeX-run-TeX nil t)
|
|
70 (list "TeX Interactive" "tex %t" 'TeX-run-interactive nil t)
|
|
71 (list "LaTeX" "%l '\\nonstopmode\\input{%t}'"
|
|
72 'TeX-run-LaTeX nil t)
|
|
73 (list "LaTeX Interactive" "%l %t" 'TeX-run-interactive nil t)
|
|
74 (list "LaTeX2e" "latex2e '\\nonstopmode\\input{%t}'"
|
|
75 'TeX-run-LaTeX nil t)
|
|
76 (if (or window-system (getenv "DISPLAY"))
|
|
77 (list "View" "%v " 'TeX-run-background t nil)
|
|
78 (list "View" "dvi2tty -q -w 132 %s " 'TeX-run-command t nil))
|
|
79 (list "Print" "%p " 'TeX-run-command t nil)
|
|
80 (list "Queue" "%q" 'TeX-run-background nil nil)
|
|
81 (list "File" "dvips %d -o %f " 'TeX-run-command t nil)
|
|
82 (list "BibTeX" "bibtex %s" 'TeX-run-BibTeX nil nil)
|
|
83 (list "Index" "makeindex %s" 'TeX-run-command nil t)
|
|
84 ;; (list "Check" "chktex -v3 %s" 'TeX-run-compile nil t)
|
|
85 ;; Uncomment the above line and comment out the next line to
|
|
86 ;; use `chktex' instead of `lacheck'.
|
|
87 (list "Check" "lacheck %s" 'TeX-run-compile nil t)
|
|
88 (list "Spell" "<ignored>" 'TeX-run-ispell nil nil)
|
|
89 (list "Other" "" 'TeX-run-command t t)
|
|
90 ;; Not part of standard TeX.
|
|
91 (list "Makeinfo" "makeinfo %t" 'TeX-run-compile nil t)
|
|
92 (list "AmSTeX" "amstex '\\nonstopmode\\input %t'"
|
|
93 'TeX-run-TeX nil t))
|
|
94 "*List of commands to execute on the current document.
|
|
95
|
|
96 Each element is a list, whose first element is the name of the command
|
|
97 as it will be presented to the user.
|
|
98
|
|
99 The second element is the string handed to the shell after being
|
|
100 expanded. The expansion is done using the information found in
|
|
101 TeX-expand-list.
|
|
102
|
|
103 The third element is the function which actually start the process.
|
|
104 Several such hooks has been defined:
|
|
105
|
|
106 TeX-run-command: Start up the process and show the output in a
|
|
107 separate buffer. Check that there is not two commands running for the
|
|
108 same file. Return the process object.
|
|
109
|
|
110 TeX-run-format: As TeX-run-command, but assume the output is created
|
|
111 by a TeX macro package. Return the process object.
|
|
112
|
|
113 TeX-run-TeX: For TeX output.
|
|
114
|
|
115 TeX-run-LaTeX: For LaTeX output.
|
|
116
|
|
117 TeX-run-interactive: Run TeX or LaTeX interactively.
|
|
118
|
|
119 TeX-run-BibTeX: For BibTeX output.
|
|
120
|
|
121 TeX-run-compile: Use `compile' to run the process.
|
|
122
|
|
123 TeX-run-shell: Use `shell-command' to run the process.
|
|
124
|
|
125 TeX-run-discard: Start the process in the background, discarding its
|
|
126 output.
|
|
127
|
|
128 TeX-run-background: Start the process in the background, show output
|
|
129 in other window.
|
|
130
|
|
131 TeX-run-dviout: Special hook for the Japanese dviout previewer for
|
|
132 PC-9801.
|
|
133
|
|
134 To create your own hook, define a function taking three arguments: The
|
|
135 name of the command, the command string, and the name of the file to
|
|
136 process. It might be useful to use TeX-run-command in order to
|
|
137 create an asynchronous process.
|
|
138
|
|
139 If the fourth element is non-nil, the user will get a chance to
|
|
140 modify the expanded string.
|
|
141
|
|
142 The fifth element is obsolete and ignored.")
|
|
143
|
|
144 ;; You may want to change the default LaTeX version for your site.
|
|
145 (defvar LaTeX-version "2e"
|
|
146 "Default LaTeX version. Currently recognized is \"2\" and \"2e\".")
|
|
147
|
|
148 ;; You may want special options to the view command depending on the
|
|
149 ;; style options. Only works if parsing is enabled.
|
|
150
|
|
151 (defvar LaTeX-command-style
|
|
152 (if (string-equal LaTeX-version "2")
|
|
153 ;; There is a lot of different LaTeX 2 based formats.
|
|
154 '(("^latex2e$" "latex2e")
|
|
155 ("^foils$" "foiltex")
|
|
156 ("^ams" "amslatex")
|
|
157 ("^slides$" "slitex")
|
|
158 ("^plfonts\\|plhb$" "platex")
|
|
159 ("." "latex"))
|
|
160 ;; They have all been combined in LaTeX 2e.
|
|
161 '(("." "latex")))
|
|
162 "*List of style options and LaTeX commands.
|
|
163
|
|
164 If the first element (a regular expresion) matches the name of one of
|
|
165 the style files, any occurrence of the string %l in a command in
|
|
166 TeX-command-list will be replaced with the second element. The first
|
|
167 match is used, if no match is found the %l is replaced with the empty
|
|
168 string.")
|
|
169
|
|
170 ;; Enter the names of the printers available at your site, or nil if
|
|
171 ;; you only have one printer.
|
|
172
|
|
173 (defvar TeX-printer-list
|
|
174 '(("Local" "dvips -f %s | lpr" "lpq")
|
|
175 ("lw") ("ps"))
|
|
176 "*List of available printers.
|
|
177
|
|
178 The first element of each entry is the printer name.
|
|
179
|
|
180 The second element is the command used to print to this
|
|
181 printer. It defaults to the value of TeX-print-command.
|
|
182
|
|
183 The third element is the command used to examine the print queue for
|
|
184 this printer. It defaults to the value of TeX-queue-command.
|
|
185
|
|
186 Any occurence of `%p' in the second or third element is expanded to
|
|
187 the printer name given in the first element, then ordinary expansion
|
|
188 is performed as specified in TeX-expand-list.")
|
|
189
|
|
190 ;; The name of the most used printer.
|
|
191
|
|
192 (defvar TeX-printer-default (or (getenv "PRINTER")
|
|
193 (and TeX-printer-list
|
|
194 (car (car TeX-printer-list)))
|
|
195 "lw")
|
|
196 "*Default printer to use with TeX-command.")
|
|
197
|
|
198 ;; You may want special options to the view command depending on the
|
|
199 ;; style options. Only works if parsing is enabled.
|
|
200
|
|
201 (defvar TeX-view-style '(("^a5$" "xdvi %d -paper a5")
|
|
202 ("^landscape$" "xdvi %d -paper a4r -s 4")
|
|
203 ;; The latest xdvi can show embedded postscript.
|
|
204 ;; If you don't have that, uncomment next line.
|
|
205 ;; ("^epsf$" "ghostview %f")
|
|
206 ("." "xdvi %d"))
|
|
207 "*List of style options and view options.
|
|
208
|
|
209 If the first element (a regular expresion) matches the name of one of
|
|
210 the style files, any occurrence of the string %v in a command in
|
|
211 TeX-command-list will be replaced with the second element. The first
|
|
212 match is used, if no match is found the %v is replaced with the empty
|
|
213 string.")
|
|
214
|
|
215 ;; This is the list of expansion for the commands in
|
|
216 ;; TeX-command-list. Not likely to be changed, but you may e.g. want
|
|
217 ;; to handle .ps files.
|
|
218
|
|
219 (defvar TeX-expand-list
|
|
220 (list (list "%p" 'TeX-printer-query) ;%p must be the first entry
|
|
221 (list "%q" (function (lambda ()
|
|
222 (TeX-printer-query TeX-queue-command 2))))
|
|
223 (list "%v" 'TeX-style-check TeX-view-style)
|
|
224 (list "%l" 'TeX-style-check LaTeX-command-style)
|
|
225 (list "%s" 'file nil t)
|
|
226 (list "%t" 'file 't t)
|
|
227 (list "%d" 'file "dvi" t)
|
|
228 (list "%f" 'file "ps" t))
|
|
229 "*List of expansion strings for TeX command names.
|
|
230
|
|
231 Each entry is a list with two or more elements. The first element is
|
|
232 the string to be expanded. The second element is the name of a
|
|
233 function returning the expanded string when called with the remaining
|
|
234 elements as arguments. The special value `file' will be expanded to
|
|
235 the name of the file being processed, with an optional extension.")
|
|
236
|
|
237 ;; End of Site Customization.
|
|
238
|
|
239 ;;; Import
|
|
240
|
|
241 (or (assoc TeX-lisp-directory (mapcar 'list load-path)) ;No `member' yet.
|
|
242 (setq load-path (cons TeX-lisp-directory load-path)))
|
|
243
|
|
244 (defvar no-doc
|
|
245 "This function is part of AUC TeX, but has not yet been loaded.
|
|
246 Full documentation will be available after autoloading the function."
|
|
247 "Documentation for autoload functions.")
|
|
248
|
|
249 ;; This hook will store bibitems when you save a BibTeX buffer.
|
|
250 (defvar bibtex-mode-hook nil)
|
|
251 (or (memq 'BibTeX-auto-store bibtex-mode-hook) ;No `add-hook' yet.
|
|
252 (setq bibtex-mode-hook (cons 'BibTeX-auto-store bibtex-mode-hook)))
|
|
253
|
|
254 (autoload 'BibTeX-auto-store "latex" no-doc t)
|
|
255
|
|
256 (autoload 'LaTeX-math-mode "latex" no-doc t)
|
|
257 (autoload 'japanese-plain-tex-mode "tex-jp" no-doc t)
|
|
258 (autoload 'japanese-latex-mode "tex-jp" no-doc t)
|
|
259 (autoload 'japanese-slitex-mode "tex-jp" no-doc t)
|
|
260 (autoload 'texinfo-mode "tex-info" no-doc t)
|
|
261 (autoload 'latex-mode "latex" no-doc t)
|
|
262
|
|
263 (autoload 'multi-prompt "multi-prompt" no-doc nil)
|
|
264
|
|
265 ;;; Portability.
|
|
266
|
|
267 (require 'easymenu)
|
|
268
|
|
269 ;; An GNU Emacs 19 function.
|
|
270 (or (fboundp 'set-text-properties)
|
|
271 (fset 'set-text-properties (symbol-function 'ignore)))
|
|
272
|
|
273 ;; An GNU Emacs 19 variable.
|
|
274 (defvar minor-mode-map-alist nil)
|
|
275
|
|
276 ;;; Special support for Emacs 18
|
|
277
|
|
278 (cond ((< (string-to-int emacs-version) 19)
|
|
279
|
|
280 (condition-case error
|
|
281 (require 'outline) ;No provide in Emacs 18 outline.el
|
|
282 (error (provide 'outline)))
|
|
283
|
|
284 ;; Emacs 18 grok this regexp, but you loose the ability to use
|
|
285 ;; whitespace anywhere in your documentstyle command.
|
|
286 (defvar LaTeX-auto-minimal-regexp-list
|
|
287 '(("\\\\documentstyle\\[\\([^#\\\\\\.\n\r]+\\)\\]{\\([^#\\\\\\.\n\r]+\\)}"
|
|
288 (1 2) LaTeX-auto-style)
|
|
289 ("\\\\documentstyle{\\([^#\\\\\\.\n\r]+\\)}" (1) LaTeX-auto-style)
|
|
290 ("\\\\documentclass\\[\\([^#\\\\\\.\n\r]+\\)\\]{\\([^#\\\\\\.\n\r]+\\)}"
|
|
291 (1 2) LaTeX-auto-style)
|
|
292 ("\\\\documentclass{\\([^#\\\\\\.\n\r]+\\)}" (1) LaTeX-auto-style))
|
|
293 "Minimal list of regular expressions matching LaTeX macro definitions.")
|
|
294
|
|
295 ;; The Emacs 19 definition of `comment-region'.
|
|
296 (defun comment-region (beg end &optional arg)
|
|
297 "Comment the region; third arg numeric means use ARG comment characters.
|
|
298 If ARG is negative, delete that many comment characters instead.
|
|
299 Comments are terminated on each line, even for syntax in which newline does
|
|
300 not end the comment. Blank lines do not get comments."
|
|
301 ;; if someone wants it to only put a comment-start at the beginning and
|
|
302 ;; comment-end at the end then typing it, C-x C-x, closing it, C-x C-x
|
|
303 ;; is easy enough. No option is made here for other than commenting
|
|
304 ;; every line.
|
|
305 (interactive "r\np")
|
|
306 (or comment-start (error "No comment syntax is defined"))
|
|
307 (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
|
|
308 (save-excursion
|
|
309 (save-restriction
|
|
310 (let ((cs comment-start) (ce comment-end))
|
|
311 (cond ((not arg) (setq arg 1))
|
|
312 ((> arg 1)
|
|
313 (while (> (setq arg (1- arg)) 0)
|
|
314 (setq cs (concat cs comment-start)
|
|
315 ce (concat ce comment-end)))))
|
|
316 (narrow-to-region beg end)
|
|
317 (goto-char beg)
|
|
318 (while (not (eobp))
|
|
319 (if (< arg 0)
|
|
320 (let ((count arg))
|
|
321 (while (and (> 1 (setq count (1+ count)))
|
|
322 (looking-at (regexp-quote cs)))
|
|
323 (delete-char (length cs)))
|
|
324 (if (string= "" ce) ()
|
|
325 (setq count arg)
|
|
326 (while (> 1 (setq count (1+ count)))
|
|
327 (end-of-line)
|
|
328 ;; this is questionable if comment-end ends in whitespace
|
|
329 ;; that is pretty brain-damaged though
|
|
330 (skip-chars-backward " \t")
|
|
331 (backward-char (length ce))
|
|
332 (if (looking-at (regexp-quote ce))
|
|
333 (delete-char (length ce)))))
|
|
334 (forward-line 1))
|
|
335 (if (looking-at "[ \t]*$") ()
|
|
336 (insert cs)
|
|
337 (if (string= "" ce) ()
|
|
338 (end-of-line)
|
|
339 (insert ce)))
|
|
340 (search-forward "\n" nil 'move)))))))
|
|
341
|
|
342 ;; The Emacs 19 definition of `add-hook'.
|
|
343 (defun add-hook (hook function &optional append)
|
|
344 "Add to the value of HOOK the function FUNCTION.
|
|
345 FUNCTION is not added if already present.
|
|
346 FUNCTION is added (if necessary) at the beginning of the hook list
|
|
347 unless the optional argument APPEND is non-nil, in which case
|
|
348 FUNCTION is added at the end.
|
|
349
|
|
350 HOOK should be a symbol, and FUNCTION may be any valid function. If
|
|
351 HOOK is void, it is first set to nil. If HOOK's value is a single
|
|
352 function, it is changed to a list of functions."
|
|
353 (or (boundp hook) (set hook nil))
|
|
354 ;; If the hook value is a single function, turn it into a list.
|
|
355 (let ((old (symbol-value hook)))
|
|
356 (if (or (not (listp old)) (eq (car old) 'lambda))
|
|
357 (set hook (list old))))
|
|
358 (or (if (consp function)
|
|
359 ;; Clever way to tell whether a given lambda-expression
|
|
360 ;; is equal to anything in the hook.
|
|
361 (let ((tail (assoc (cdr function) (symbol-value hook))))
|
|
362 (equal function tail))
|
|
363 (memq function (symbol-value hook)))
|
|
364 (set hook
|
|
365 (if append
|
|
366 (nconc (symbol-value hook) (list function))
|
|
367 (cons function (symbol-value hook))))))
|
|
368
|
|
369 ;; An Emacs 19 function.
|
|
370 (defun make-directory (dir)
|
|
371 "Create the directory DIR."
|
|
372 (shell-command (concat "mkdir " (if (string-match "/$" dir)
|
|
373 (substring dir 0 -1)
|
|
374 dir))))
|
|
375
|
|
376 ;; An Emacs 19 function.
|
|
377 (defun abbreviate-file-name (name)
|
|
378 name)
|
|
379
|
|
380 ;; Different interface for each variant.
|
|
381 (defun TeX-active-mark ()
|
|
382 ;; Emacs 18 does not have active marks.
|
|
383 nil)
|
|
384
|
|
385 ;; Different interface for each variant.
|
|
386 (defun TeX-mark-active ()
|
|
387 ;; In Emacs 18 (mark) returns nil when not active.
|
|
388 (mark))
|
|
389
|
|
390 ;; An Emacs 19 function.
|
|
391 (defun member (elt list)
|
|
392 "Return non-nil if ELT is an element of LIST. Comparison done with EQUAL.
|
|
393 The value is actually the tail of LIST whose car is ELT."
|
|
394 (while (and list (not (equal elt (car list))))
|
|
395 (setq list (cdr list)))
|
|
396 list)
|
|
397
|
|
398 ;; An Emacs 19 macro.
|
|
399 (defmacro save-match-data (&rest body)
|
|
400 "Execute the BODY forms, restoring the global value of the match data."
|
|
401 (let ((original (make-symbol "match-data")))
|
|
402 (list
|
|
403 'let (list (list original '(match-data)))
|
|
404 (list 'unwind-protect
|
|
405 (cons 'progn body)
|
|
406 (list 'store-match-data original)))))
|
|
407
|
|
408 )
|
|
409
|
|
410 ;;; Special support for XEmacs
|
|
411
|
|
412 ((or (string-match "Lucid" emacs-version)
|
|
413 (string-match "XEmacs" emacs-version))
|
|
414
|
|
415 (if (eq emacs-minor-version 13)
|
|
416 ;; XEmacs 19.13 had a partial defintion of set-text-properties.
|
|
417 (defadvice set-text-properties (around ignore-strings activate)
|
|
418 "Ignore strings."
|
|
419 (or (stringp (ad-get-arg 3))
|
|
420 ad-do-it)))
|
|
421
|
|
422 (defadvice popup-mode-menu (before LaTeX-update activate)
|
|
423 "Run `LaTeX-menu-update' before showing menu."
|
|
424 (and (fboundp 'LaTeX-menu-update)
|
|
425 (LaTeX-menu-update)))
|
|
426
|
|
427 (defun TeX-mark-active ()
|
|
428 ;; In Lucid (mark) returns nil when not active.
|
|
429 (if zmacs-regions
|
|
430 (mark)
|
|
431 (mark t)))
|
|
432
|
|
433 (defun TeX-active-mark ()
|
|
434 (and zmacs-regions (mark)))
|
|
435
|
|
436 ;; Lucid 19.11 have no idea what `kill-all-local-variables' is
|
|
437 ;; supposed to do. I have to explicitly clear `TeX-symbol-list'
|
|
438 ;; despite it being buffer local. You can verify this by removing the
|
|
439 ;; hook below, setting a breakpoint just after the call to
|
|
440 ;; `kill-all-local-variables' in `VirTeX-common-initialization' and
|
|
441 ;; examine the local and global value of `TeX-symbol-list'. Make sure
|
|
442 ;; you have a `%%% mode: latex' line in your file variable section,
|
|
443 ;; and have latex-mode as your default mode for ".tex" files.
|
|
444 ;; Unfortunately I have been unable to isolate the error further.
|
|
445 (add-hook 'change-major-mode-hook
|
|
446 '(lambda () (setq TeX-symbol-list nil
|
|
447 LaTeX-environment-list nil)))
|
|
448
|
|
449 ;; Lucid 19.6 grok this regexp, but you loose the ability to use
|
|
450 ;; whitespace in your documentstyle command.
|
|
451 (string-match "\\`[0-9]+\\.\\([0-9]+\\)" emacs-version)
|
|
452 (or (> (string-to-int (substring emacs-version
|
|
453 (match-beginning 1) (match-end 1)))
|
|
454 8)
|
|
455 (> (string-to-int emacs-version) 19)
|
|
456 (boundp 'LaTeX-auto-minimal-regexp-list)
|
|
457 (setq LaTeX-auto-minimal-regexp-list
|
|
458 '(("\\\\documentstyle\\[\\([^#\\\\\\.\n\r]+\\)\\]{\\([^#\\\\\\.\n\r]+\\)}"
|
|
459 (1 2) LaTeX-auto-style)
|
|
460 ("\\\\documentstyle{\\([^#\\\\\\.\n\r]+\\)}" (1) LaTeX-auto-style)
|
|
461 ("\\\\documentclass\\[\\([^#\\\\\\.\n\r]+\\)\\]{\\([^#\\\\\\.\n\r]+\\)}"
|
|
462 (1 2) LaTeX-auto-style)
|
|
463 ("\\\\documentclass{\\([^#\\\\\\.\n\r]+\\)}" (1) LaTeX-auto-style))))
|
|
464
|
|
465 ;; Lucid only
|
|
466 (fset 'TeX-activate-region (symbol-function 'zmacs-activate-region))
|
|
467
|
|
468 )
|
|
469 ;;; Special support for GNU Emacs 19
|
|
470
|
|
471 (t
|
|
472
|
|
473 (defun TeX-mark-active ()
|
|
474 ;; In FSF 19 mark-active indicates if mark is active.
|
|
475 mark-active)
|
|
476
|
|
477 (defun TeX-active-mark ()
|
|
478 (and transient-mark-mode mark-active))
|
|
479
|
|
480 (defun TeX-activate-region ())
|
|
481
|
|
482 ))
|
|
483
|
|
484 ;;; Version
|
|
485
|
|
486 ;; These two variables are automatically updated with "make dist", so
|
|
487 ;; be careful before changing anything.
|
|
488
|
|
489 (defconst AUC-TeX-version "9.7i"
|
|
490 "AUC TeX version number")
|
|
491
|
|
492 (defconst AUC-TeX-date "Thu Feb 20 11:30:55 MET 1997"
|
|
493 "AUC TeX release date")
|
|
494
|
|
495 ;;; Buffer
|
|
496
|
|
497 (defvar TeX-display-help t
|
|
498 "*Non-nil means popup help when stepping thrugh errors with \\[TeX-next-error]")
|
|
499
|
|
500 (defvar TeX-debug-bad-boxes nil
|
|
501 "*Non-nil means also find overfull/underfull boxes warnings with TeX-next-error")
|
|
502
|
|
503 (defvar TeX-command-BibTeX "BibTeX"
|
|
504 "*The name of the BibTeX entry in TeX-command-list.")
|
|
505 (make-variable-buffer-local 'TeX-command-BibTeX)
|
|
506
|
|
507 (defvar TeX-command-Show "View"
|
|
508 "*The default command to show (view or print) a TeX file.
|
|
509 Must be the car of an entry in TeX-command-list.")
|
|
510 (make-variable-buffer-local 'TeX-command-Show)
|
|
511
|
|
512 (defvar TeX-command-Print "Print"
|
|
513 "The name of the Print entry in TeX-command-Print.")
|
|
514
|
|
515 (defvar TeX-command-Queue "Queue"
|
|
516 "The name of the Queue entry in TeX-command-Queue.")
|
|
517
|
|
518 (autoload 'TeX-region-create "tex-buf" no-doc nil)
|
|
519 (autoload 'TeX-save-document "tex-buf" no-doc t)
|
|
520 (autoload 'TeX-home-buffer "tex-buf" no-doc t)
|
|
521 (autoload 'TeX-command-region "tex-buf" no-doc t)
|
|
522 (autoload 'TeX-command-buffer "tex-buf" no-doc t)
|
|
523 (autoload 'TeX-command-master "tex-buf" no-doc t)
|
|
524 (autoload 'TeX-command "tex-buf" no-doc nil)
|
|
525 (autoload 'TeX-kill-job "tex-buf" no-doc t)
|
|
526 (autoload 'TeX-recenter-output-buffer "tex-buf" no-doc t)
|
|
527 (autoload 'TeX-next-error "tex-buf" no-doc t)
|
|
528 (autoload 'TeX-toggle-debug-boxes "tex-buf" no-doc t)
|
|
529 (autoload 'TeX-region-file "tex-buf" no-doc nil)
|
|
530
|
|
531 (defvar TeX-trailer-start nil
|
|
532 "Regular expression delimiting start of trailer in a TeX file.")
|
|
533
|
|
534 (make-variable-buffer-local 'TeX-trailer-start)
|
|
535
|
|
536 (defvar TeX-header-end nil
|
|
537 "Regular expression delimiting end of header in a TeX file.")
|
|
538
|
|
539 (make-variable-buffer-local 'TeX-header-end)
|
|
540
|
|
541 (defvar TeX-command-default nil
|
|
542 "The default command for TeX-command in the current major mode.")
|
|
543
|
|
544 (make-variable-buffer-local 'TeX-command-default)
|
|
545
|
|
546
|
|
547 ;;; Master File
|
|
548
|
|
549 (defvar TeX-one-master "\\.tex$"
|
|
550 "*Regular expression matching ordinary TeX files.
|
|
551
|
|
552 You should set this variable to match the name of all files, where
|
|
553 automatically adding a file variable with the name of the master file
|
|
554 is a good idea. When AUC TeX add the name of the master file as a
|
|
555 file variable, it does not need to ask next time you edit the file.
|
|
556
|
|
557 If you dislike AUC TeX automatically modifying your files, you can set
|
|
558 this variable to \"<none>\".")
|
|
559
|
|
560 (defun TeX-master-file (&optional extension nondirectory)
|
|
561 "Return the name of the master file for the current document.
|
|
562
|
|
563 If optional argument EXTENSION is non-nil, add that file extension to
|
|
564 the name. Special value `t' means use `TeX-default-extension'.
|
|
565
|
|
566 If optional second argument NONDIRECTORY is non-nil, do not include
|
|
567 the directory.
|
|
568
|
|
569 Currently is will check for the presence of a ``Master:'' line in
|
|
570 the beginning of the file, but that feature will be phased out."
|
|
571 (if (eq extension t)
|
|
572 (setq extension TeX-default-extension))
|
|
573 (let ((my-name (if (buffer-file-name)
|
|
574 (TeX-strip-extension nil (list TeX-default-extension) t)
|
|
575 "<none>")))
|
|
576 (save-excursion
|
|
577 (save-restriction
|
|
578 (widen)
|
|
579 (goto-char (point-min))
|
|
580 (cond
|
|
581 ;; Special value 't means it is own master (a free file).
|
|
582 ((equal TeX-master my-name)
|
|
583 (setq TeX-master t))
|
|
584
|
|
585 ;; For files shared between many documents.
|
|
586 ((eq 'shared TeX-master)
|
|
587 (setq TeX-master
|
|
588 (TeX-strip-extension
|
|
589 (read-file-name "Master file: (default this file) "
|
|
590 nil "///")
|
|
591 (list TeX-default-extension)
|
|
592 'path))
|
|
593 (if (or (string-equal TeX-master "///")
|
|
594 (string-equal TeX-master ""))
|
|
595 (setq TeX-master t)))
|
|
596
|
|
597 ;; We might already know the name.
|
|
598 (TeX-master)
|
|
599
|
|
600 ;; Support the ``Master:'' line (under protest!)
|
|
601 ((re-search-forward
|
|
602 "^%% *[Mm]aster:?[ \t]*\\([^ \t\n]+\\)" 500 t)
|
|
603 (setq TeX-master
|
|
604 (TeX-strip-extension (TeX-match-buffer 1)
|
|
605 (list TeX-default-extension)))
|
|
606 (if TeX-convert-master
|
|
607 (progn
|
|
608 (beginning-of-line)
|
|
609 (kill-line 1)
|
|
610 (TeX-add-local-master))))
|
|
611
|
|
612 ;; Is this a master file?
|
|
613 ((re-search-forward TeX-header-end 10000 t)
|
|
614 (setq TeX-master my-name))
|
|
615
|
|
616 ;; Ask the user (but add it as a local variable).
|
|
617 (t
|
|
618 (setq TeX-master
|
|
619 (TeX-strip-extension
|
|
620 (condition-case name
|
|
621 (read-file-name "Master file: (default this file) "
|
|
622 nil "<default>")
|
|
623 (quit "<quit>"))
|
|
624 (list TeX-default-extension)
|
|
625 'path))
|
|
626 (cond ((string-equal TeX-master "<quit>")
|
|
627 (setq TeX-master t))
|
|
628 ((or (string-equal TeX-master "<default>")
|
|
629 (string-equal TeX-master ""))
|
|
630 (setq TeX-master t)
|
|
631 (TeX-add-local-master))
|
|
632 (t
|
|
633 (TeX-add-local-master)))))))
|
|
634
|
|
635 (let ((name (if (eq TeX-master t)
|
|
636 my-name
|
|
637 TeX-master)))
|
|
638
|
|
639 (if (TeX-match-extension name)
|
|
640 ;; If it already have an extension...
|
|
641 (if (equal extension TeX-default-extension)
|
|
642 ;; Use instead of the default extension
|
|
643 (setq extension nil)
|
|
644 ;; Otherwise drop it.
|
|
645 (setq name (TeX-strip-extension name))))
|
|
646
|
|
647 ;; Remove directory if needed.
|
|
648 (if nondirectory
|
|
649 (setq name (file-name-nondirectory name)))
|
|
650
|
|
651 (if extension
|
|
652 (concat name "." extension)
|
|
653 name))))
|
|
654
|
|
655 (defun TeX-master-directory ()
|
|
656 "Directory of master file."
|
|
657 (abbreviate-file-name
|
|
658 (expand-file-name
|
|
659 (concat (file-name-directory buffer-file-name)
|
|
660 (file-name-directory (TeX-master-file))))))
|
|
661
|
|
662 (defvar TeX-master t
|
|
663 "*The master file associated with the current buffer.
|
|
664 If the file being edited is actually included from another file, you
|
|
665 can tell AUC TeX the name of the master file by setting this variable.
|
|
666 If there are multiple levels of nesting, specify the top level file.
|
|
667
|
|
668 If this variable is nil, AUC TeX will query you for the name.
|
|
669
|
|
670 If the variable is t, AUC TeX will assume the file is a master file
|
|
671 itself.
|
|
672
|
|
673 If the variable is 'shared, AUC TeX will query for the name, but not
|
|
674 change the file.
|
|
675
|
|
676 It is suggested that you use the File Variables (see the info node in
|
|
677 the Emacs manual) to set this variable permanently for each file.")
|
|
678
|
|
679 (make-variable-buffer-local 'TeX-master)
|
|
680
|
|
681 (defvar TeX-convert-master t
|
|
682 "*If not nil, automatically convert ``Master:'' lines to file variables.
|
|
683 This will be done when AUC TeX first try to use the master file.")
|
|
684
|
|
685 (defun TeX-add-local-master ()
|
|
686 "Add local variable for TeX-master."
|
|
687
|
|
688 (if (and (buffer-file-name)
|
|
689 (string-match TeX-one-master
|
|
690 (file-name-nondirectory (buffer-file-name)))
|
|
691 (not buffer-read-only))
|
|
692 (progn
|
|
693 (goto-char (point-max))
|
|
694 (if (re-search-backward (concat "^\\([^\n]+\\)Local " "Variables:")
|
|
695 (- (point-max) 3000) t)
|
|
696 (let ((prefix (TeX-match-buffer 1)))
|
|
697 (re-search-forward (regexp-quote (concat prefix
|
|
698 "End:")))
|
|
699 (beginning-of-line 1)
|
|
700 (insert prefix "TeX-master: " (prin1-to-string TeX-master) "\n"))
|
|
701 (insert "\n%%% Local " "Variables: \n"
|
|
702 "%%% mode: " (substring (symbol-name major-mode) 0 -5)
|
|
703 "\n"
|
|
704 "%%% TeX-master: " (prin1-to-string TeX-master) "\n"
|
|
705 "%%% End: \n")))))
|
|
706
|
|
707 ;;; Style Paths
|
|
708
|
|
709 (or (string-match "/\\'" TeX-lisp-directory)
|
|
710 (setq TeX-lisp-directory (concat TeX-lisp-directory "/")))
|
|
711
|
|
712 (defvar TeX-auto-global (concat TeX-lisp-directory "auto/")
|
|
713 "*Directory containing automatically generated information.
|
|
714 Must end with a slash.
|
|
715
|
|
716 For storing automatic extracted information about the TeX macros
|
|
717 shared by all users of a site.")
|
|
718
|
|
719 (defvar TeX-style-global (concat TeX-lisp-directory "style/")
|
|
720 "*Directory containing hand generated TeX information.
|
|
721 Must end with a slash.
|
|
722
|
|
723 These correspond to TeX macros shared by all users of a site.")
|
|
724
|
|
725 (defvar TeX-auto-local "auto/"
|
|
726 "*Directory containing automatically generated TeX information.
|
|
727 Must end with a slash.
|
|
728
|
|
729 This correspond to TeX macros found in the current directory.")
|
|
730
|
|
731 (defvar TeX-style-local "style/"
|
|
732 "*Directory containing hand generated TeX information.
|
|
733 Must end with a slash.
|
|
734
|
|
735 These correspond to TeX macros found in the current directory.")
|
|
736
|
|
737 (defun TeX-split-string (regexp string)
|
|
738 "Returns a list of strings. given REGEXP the STRING is split into
|
|
739 sections which in string was seperated by REGEXP.
|
|
740
|
|
741 Examples:
|
|
742
|
|
743 (TeX-split-string \"\:\" \"abc:def:ghi\")
|
|
744 -> (\"abc\" \"def\" \"ghi\")
|
|
745
|
|
746 (TeX-split-string \" *\" \"dvips -Plw -p3 -c4 testfile.dvi\")
|
|
747
|
|
748 -> (\"dvips\" \"-Plw\" \"-p3\" \"-c4\" \"testfile.dvi\")
|
|
749
|
|
750 If REGEXP is nil, or \"\", an error will occur."
|
|
751
|
|
752 (let ((start 0)
|
|
753 (result '()))
|
|
754 (while (string-match regexp string start)
|
|
755 (let ((match (string-match regexp string start)))
|
|
756 (setq result (cons (substring string start match) result))
|
|
757 (setq start (match-end 0))))
|
|
758 (setq result (cons (substring string start nil) result))
|
|
759 (nreverse result)))
|
|
760
|
|
761 (defun TeX-directory-absolute-p (dir)
|
|
762 ;; Non-nil iff DIR is the name of an absolute directory.
|
|
763 (if (memq system-type '(ms-dos emx windows-nt))
|
|
764 (string-match "^\\([A-Za-z]:\\)?/" dir)
|
|
765 (string-match "^/" dir)))
|
|
766
|
|
767 (defun TeX-parse-path (env)
|
|
768 ;; Return a list if private TeX directories found in environment
|
|
769 ;; variable ENV.
|
|
770 (let* ((value (getenv env))
|
|
771 (entries (and value (TeX-split-string ":" value)))
|
|
772 entry
|
|
773 answers)
|
|
774 (while entries
|
|
775 (setq entry (car entries))
|
|
776 (setq entries (cdr entries))
|
|
777 (or (string-match "/$" entry)
|
|
778 (setq entry (concat entry "/")))
|
|
779 (and (string-match "//$" entry)
|
|
780 (setq entry (substring entry 0 -1)))
|
|
781 (or (not (TeX-directory-absolute-p entry))
|
|
782 (member entry TeX-macro-global)
|
|
783 (string-equal "/" entry)
|
|
784 (setq answers (cons entry answers))))
|
|
785 answers))
|
|
786
|
|
787 (defvar TeX-macro-private (append (TeX-parse-path "TEXINPUTS")
|
|
788 (TeX-parse-path "BIBINPUTS"))
|
|
789 "*Directories where you store your personal TeX macros.
|
|
790 Each must end with a slash.")
|
|
791
|
|
792 (defvar TeX-auto-private (mapcar (function (lambda (entry)
|
|
793 (concat entry TeX-auto-local)))
|
|
794 TeX-macro-private)
|
|
795 "*List of directories containing automatically generated information.
|
|
796 Must end with a slash.
|
|
797
|
|
798 These correspond to the personal TeX macros.")
|
|
799
|
|
800 (if (stringp TeX-auto-private) ;Backward compatibility
|
|
801 (setq TeX-auto-private (list TeX-auto-private)))
|
|
802
|
|
803 (defvar TeX-style-private (mapcar (function (lambda (entry)
|
|
804 (concat entry
|
|
805 TeX-style-local)))
|
|
806 TeX-macro-private)
|
|
807 "*List of directories containing hand generated information.
|
|
808 Must end with a slash.
|
|
809
|
|
810 These correspond to the personal TeX macros.")
|
|
811
|
|
812 (if (stringp TeX-style-private) ;Backward compatibility
|
|
813 (setq TeX-style-private (list TeX-style-private)))
|
|
814
|
|
815 (defvar TeX-style-path
|
|
816 (let ((path))
|
|
817 (mapcar (function (lambda (file) (if file (setq path (cons file path)))))
|
|
818 (append (list TeX-auto-global TeX-style-global)
|
|
819 TeX-auto-private TeX-style-private
|
|
820 (list TeX-auto-local TeX-style-local)))
|
|
821 path)
|
|
822 "*List of directories to search for AUC TeX style files.")
|
|
823
|
|
824 (defvar TeX-check-path (append (list "./") TeX-macro-private TeX-macro-global)
|
|
825 "*Directory path to search for dependencies.
|
|
826
|
|
827 If nil, just check the current file.
|
|
828 Used when checking if any files have changed.")
|
|
829
|
|
830 ;;; Style Files
|
|
831
|
|
832 (defvar TeX-style-hook-list nil
|
|
833 "List of TeX style hooks currently loaded.
|
|
834
|
|
835 Each entry is a list where the first element is the name of the style,
|
|
836 and the remaining elements are hooks to be run when that style is
|
|
837 active.")
|
|
838
|
|
839 (defvar TeX-byte-compile nil
|
|
840 "*Not nil means try to byte compile auto files before loading.")
|
|
841
|
|
842 (defun TeX-load-style (style)
|
|
843 "Search for and load each definition for style in TeX-style-path."
|
|
844 (cond ((assoc style TeX-style-hook-list)) ; We already found it
|
|
845 ((string-match "\\`\\(.+/\\)\\([^/]*\\)\\'" style) ;Complex path
|
|
846 (let* ((dir (substring style (match-beginning 1) (match-end 1)))
|
|
847 (style (substring style (match-beginning 2) (match-end 2)))
|
|
848 (TeX-style-path (append (list (concat dir TeX-auto-local)
|
|
849 (concat dir TeX-style-local))
|
|
850 TeX-style-path)))
|
|
851 (TeX-load-style style)))
|
|
852 (t ;Relative path
|
|
853 ;; Insert empty list to mark the fact that we have searched.
|
|
854 (setq TeX-style-hook-list (cons (list style) TeX-style-hook-list))
|
|
855 ;; Now check each element of the path
|
|
856 (mapcar (function (lambda (name)
|
|
857 (TeX-load-style-file (if (string-match "/$" name)
|
|
858 (concat name style)
|
|
859 (concat name "/" style)))))
|
|
860 TeX-style-path))))
|
|
861
|
|
862 (defun TeX-load-style-file (file)
|
|
863 ;; Load FILE checking for a lisp extensions.
|
|
864 (let ((el (concat file ".el"))
|
|
865 (elc (concat file ".elc")))
|
|
866 (cond ((and (null TeX-byte-compile)
|
|
867 (file-readable-p el))
|
|
868 (load-file el))
|
|
869 ((file-newer-than-file-p el elc)
|
|
870 (if (not (file-writable-p elc))
|
|
871 (load-file el)
|
|
872 (byte-compile-file el)
|
|
873 (load-file elc)))
|
|
874 ((file-readable-p elc)
|
|
875 (load-file elc))
|
|
876 ((file-readable-p el)
|
|
877 (load-file el)))))
|
|
878
|
|
879 (defun TeX-add-style-hook (style hook)
|
|
880 "Give STYLE yet another HOOK to run."
|
|
881 (let ((entry (assoc style TeX-style-hook-list)))
|
|
882 (if (null entry)
|
|
883 (setq TeX-style-hook-list (cons (list style hook) TeX-style-hook-list))
|
|
884 (setcdr entry (cons hook (cdr entry))))))
|
|
885
|
|
886 (defun TeX-unload-style (style)
|
|
887 "Forget that we once loaded STYLE."
|
|
888 (cond ((null (assoc style TeX-style-hook-list)))
|
|
889 ((equal (car (car TeX-style-hook-list)) style)
|
|
890 (setq TeX-style-hook-list (cdr TeX-style-hook-list)))
|
|
891 (t
|
|
892 (let ((entry TeX-style-hook-list))
|
|
893 (while (not (equal (car (car (cdr entry))) style))
|
|
894 (setq entry (cdr entry)))
|
|
895 (setcdr entry (cdr (cdr entry)))))))
|
|
896
|
|
897 (defvar TeX-virgin-style (if (and TeX-auto-global
|
|
898 (file-directory-p TeX-auto-global))
|
|
899 "virtex"
|
|
900 "NoVirtexSymbols")
|
|
901 "Style all documents use.")
|
|
902
|
|
903 (defvar TeX-active-styles nil
|
|
904 "List of styles currently active in the document.")
|
|
905
|
|
906 (make-variable-buffer-local 'TeX-active-styles)
|
|
907
|
|
908 (defun TeX-run-style-hooks (&rest styles)
|
|
909 "Run the TeX following style hooks."
|
|
910 (mapcar (function
|
|
911 (lambda (style)
|
|
912 (if (TeX-member style TeX-active-styles 'string-equal)
|
|
913 () ;Avoid recursion.
|
|
914 (setq TeX-active-styles
|
|
915 (cons style TeX-active-styles))
|
|
916 (TeX-load-style style)
|
|
917 (if (string-match "\\`\\(.+/\\)\\([^/]*\\)\\'" style)
|
|
918 (setq style ; Complex path
|
|
919 (substring style (match-beginning 2) (match-end 2))))
|
|
920 (mapcar 'funcall
|
|
921 (cdr-safe (assoc style TeX-style-hook-list))))))
|
|
922 styles))
|
|
923
|
|
924 (defvar TeX-parse-self nil
|
|
925 "*Parse file after loading it if no style hook is found for it.")
|
|
926
|
|
927 (defvar TeX-style-hook-applied-p nil
|
|
928 "Nil, unless the style specific hooks have been applied.")
|
|
929 (make-variable-buffer-local 'TeX-style-hook-applied-p)
|
|
930
|
|
931 (defun TeX-update-style (&optional force)
|
|
932 "Run style specific hooks for the current document.
|
|
933
|
|
934 Only do this if it has not been done before, or if optional argument
|
|
935 FORCE is not nil."
|
|
936
|
|
937 (if (or (eq TeX-auto-update 'BibTeX) ; Not a real TeX buffer
|
|
938 (and (not force) TeX-style-hook-applied-p))
|
|
939 ()
|
|
940 (setq TeX-style-hook-applied-p t)
|
|
941 (message "Applying style hooks...")
|
|
942 (TeX-run-style-hooks (TeX-strip-extension nil nil t))
|
|
943 ;; Run parent style hooks if it has a single parent that isn't itself.
|
|
944 (if (or (not (memq TeX-master '(nil t)))
|
|
945 (and (buffer-file-name)
|
|
946 (string-match TeX-one-master
|
|
947 (file-name-nondirectory (buffer-file-name)))))
|
|
948 (TeX-run-style-hooks (TeX-master-file)))
|
|
949
|
|
950 (if (and TeX-parse-self
|
|
951 (null (cdr-safe (assoc (TeX-strip-extension nil nil t)
|
|
952 TeX-style-hook-list))))
|
|
953 (TeX-auto-apply))
|
|
954
|
|
955 (message "Applying style hooks... done")))
|
|
956
|
|
957 (defvar TeX-remove-style-hook nil
|
|
958 "List of hooks to call when we remove the style specific information.")
|
|
959 (make-variable-buffer-local 'TeX-remove-style-hook)
|
|
960
|
|
961 (defun TeX-remove-style ()
|
|
962 "Remnove all style specific information."
|
|
963 (setq TeX-style-hook-applied-p nil)
|
|
964 (run-hooks 'TeX-remove-style-hooks)
|
|
965 (setq TeX-active-styles (list TeX-virgin-style)))
|
|
966
|
|
967 (defun TeX-style-list ()
|
|
968 "Return a list of all styles (subfils) use by the current document."
|
|
969 (TeX-update-style)
|
|
970 TeX-active-styles)
|
|
971
|
|
972 ;;; Special Characters
|
|
973
|
|
974 (defvar TeX-esc "\\" "The TeX escape character.")
|
|
975 (make-variable-buffer-local 'TeX-esc)
|
|
976
|
|
977 (defvar TeX-grop "{" "The TeX group opening character.")
|
|
978 (make-variable-buffer-local 'TeX-grop)
|
|
979
|
|
980 (defvar TeX-grcl "}" "The TeX group closing character.")
|
|
981 (make-variable-buffer-local 'TeX-grcl)
|
|
982
|
|
983 ;;; Symbols
|
|
984
|
|
985 ;; Must be before keymaps.
|
|
986
|
|
987 (defvar TeX-complete-word 'ispell-complete-word
|
|
988 "*Function to call for completing non-macros in tex-mode.")
|
|
989
|
|
990 (defvar TeX-complete-list nil
|
|
991 "List of ways to complete the preceding text.
|
|
992
|
|
993 Each entry is a list with the following elements:
|
|
994
|
|
995 0. Regexp matching the preceding text.
|
|
996 1. A number indicating the subgroup in the regexp containing the text.
|
|
997 2. A function returning an alist of possible completions.
|
|
998 3. Text to append after a succesful completion.
|
|
999
|
|
1000 Or alternatively:
|
|
1001
|
|
1002 0. Regexp matching the preceding text.
|
|
1003 1. Function to do the actual completion.")
|
|
1004
|
|
1005 (defun TeX-complete-symbol ()
|
|
1006 "Perform completion on TeX/LaTeX symbol preceding point."
|
|
1007 (interactive "*")
|
|
1008 (let ((list TeX-complete-list)
|
|
1009 entry)
|
|
1010 (while list
|
|
1011 (setq entry (car list)
|
|
1012 list (cdr list))
|
|
1013 (if (TeX-looking-at-backward (car entry) 250)
|
|
1014 (setq list nil)))
|
|
1015 (if (numberp (nth 1 entry))
|
|
1016 (let* ((sub (nth 1 entry))
|
|
1017 (close (nth 3 entry))
|
|
1018 (begin (match-beginning sub))
|
|
1019 (end (match-end sub))
|
|
1020 (pattern (TeX-match-buffer 0))
|
|
1021 (symbol (buffer-substring begin end))
|
|
1022 (list (funcall (nth 2 entry)))
|
|
1023 (completion (try-completion symbol list)))
|
|
1024 (cond ((eq completion t)
|
|
1025 (and close
|
|
1026 (not (looking-at (regexp-quote close)))
|
|
1027 (insert close)))
|
|
1028 ((null completion)
|
|
1029 (error "Can't find completion for \"%s\"" pattern))
|
|
1030 ((not (string-equal symbol completion))
|
|
1031 (delete-region begin end)
|
|
1032 (insert completion)
|
|
1033 (and close
|
|
1034 (eq (try-completion completion list) t)
|
|
1035 (not (looking-at (regexp-quote close)))
|
|
1036 (insert close)))
|
|
1037 (t
|
|
1038 (message "Making completion list...")
|
|
1039 (let ((list (all-completions symbol list nil)))
|
|
1040 (with-output-to-temp-buffer "*Completions*"
|
|
1041 (display-completion-list list)))
|
|
1042 (message "Making completion list...done"))))
|
|
1043 (funcall (nth 1 entry)))))
|
|
1044
|
|
1045 (defvar TeX-default-macro "ref"
|
|
1046 "*The default macro when creating new ones with TeX-insert-macro.")
|
|
1047
|
|
1048 (make-variable-buffer-local 'TeX-default-macro)
|
|
1049
|
|
1050 (defvar TeX-insert-braces t
|
|
1051 "*If non-nil, append a empty pair of braces after inserting a macro.")
|
|
1052
|
|
1053 (defun TeX-math-mode-p ()
|
|
1054 "Are we in TeX math mode?"
|
|
1055 ;; This should check for dollar signs, but thats to hard for now.
|
|
1056 (and (boundp 'LaTeX-math-mode) LaTeX-math-mode))
|
|
1057
|
|
1058 (defun TeX-insert-macro (symbol)
|
|
1059 "Insert TeX macro with completion.
|
|
1060
|
|
1061 AUC TeX knows of some macros, and may query for extra arguments."
|
|
1062 (interactive (list (completing-read (concat "Macro (default "
|
|
1063 TeX-default-macro
|
|
1064 "): "
|
|
1065 TeX-esc)
|
|
1066 (TeX-symbol-list))))
|
|
1067 (cond ((string-equal symbol "")
|
|
1068 (setq symbol TeX-default-macro))
|
|
1069 ((interactive-p)
|
|
1070 (setq TeX-default-macro symbol)))
|
|
1071 (TeX-parse-macro symbol (cdr-safe (assoc symbol (TeX-symbol-list)))))
|
|
1072
|
|
1073 (defvar TeX-electric-macro-map nil)
|
|
1074
|
|
1075 (if TeX-electric-macro-map
|
|
1076 ()
|
|
1077 (setq TeX-electric-macro-map (copy-keymap minibuffer-local-completion-map))
|
|
1078 (define-key TeX-electric-macro-map " " 'minibuffer-complete-and-exit))
|
|
1079
|
|
1080 (defun TeX-electric-macro ()
|
|
1081 "Insert TeX macro with completion.
|
|
1082
|
|
1083 AUC TeX knows of some macros, and may query for extra arguments.
|
|
1084 Space will complete and exit."
|
|
1085 (interactive)
|
|
1086 (if (memq (preceding-char) '(?\\ ?.))
|
|
1087 (call-interactively 'self-insert-command)
|
|
1088 (let ((minibuffer-local-completion-map TeX-electric-macro-map))
|
|
1089 (call-interactively 'TeX-insert-macro))))
|
|
1090
|
|
1091 (defun TeX-parse-macro (symbol args)
|
|
1092 "How to parse TeX macros which takes one or more arguments."
|
|
1093
|
|
1094 ;; First argument is the name of the macro.
|
|
1095
|
|
1096 ;; If called with no additional arguments, insert macro with point
|
|
1097 ;; inside braces. Otherwise, each argument of this function should
|
|
1098 ;; match an argument to the TeX macro. What is done depend on the
|
|
1099 ;; argument type.
|
|
1100
|
|
1101 ;; string: Use the string as a prompt to prompt for the argument.
|
|
1102
|
|
1103 ;; number: Insert that many braces, leave point inside the first.
|
|
1104
|
|
1105 ;; nil: Insert empty braces.
|
|
1106
|
|
1107 ;; t: Insert empty braces, leave point between the braces.
|
|
1108
|
|
1109 ;; other symbols: Call the symbol as a function. You can define
|
|
1110 ;; your own hook, or use one of the predefined argument hooks. If
|
|
1111 ;; you add new hooks, you can assume that point is placed directly
|
|
1112 ;; after the previous argument, or after the macro name if this is
|
|
1113 ;; the first argument. Please leave point located efter the
|
|
1114 ;; argument you are inserting. If you want point to be located
|
|
1115 ;; somewhere else after all hooks have been processed, set the value
|
|
1116 ;; of `exit-mark'. It will point nowhere, until the argument hook
|
|
1117 ;; set it. By convention, these hook all start with `TeX-arg-'.
|
|
1118
|
|
1119 ;; list: If the car is a string, insert it as a prompt and the next
|
|
1120 ;; element as initial input. Otherwise, call the car of the list
|
|
1121 ;; with the remaining elements as arguments.
|
|
1122
|
|
1123 ;; vector: Optional argument. If it has more than one element,
|
|
1124 ;; parse it as a list, otherwise parse the only element as above.
|
|
1125 ;; Use square brackets instead of curly braces, and is not inserted
|
|
1126 ;; on empty user input.
|
|
1127
|
|
1128 (insert TeX-esc symbol)
|
|
1129 (let ((exit-mark (make-marker))
|
|
1130 (position (point)))
|
|
1131 (TeX-parse-arguments args)
|
|
1132 (cond ((marker-position exit-mark)
|
|
1133 (goto-char (marker-position exit-mark))
|
|
1134 (set-marker exit-mark nil))
|
|
1135 ((and TeX-insert-braces
|
|
1136 (equal position (point))
|
|
1137 (string-match "[a-zA-Z]+" symbol)
|
|
1138 (not (TeX-math-mode-p)))
|
|
1139 (insert TeX-grop TeX-grcl)))))
|
|
1140
|
|
1141 (defun TeX-arg-string (optional &optional prompt input)
|
|
1142 "Prompt for a string."
|
|
1143 (TeX-argument-insert
|
|
1144 (read-string (TeX-argument-prompt optional prompt "Text") input)
|
|
1145 optional))
|
|
1146
|
|
1147 (defun TeX-parse-arguments (args)
|
|
1148 "Parse TeX macro arguments.
|
|
1149
|
|
1150 See TeX-parse-macro for details."
|
|
1151 (let ((last-optional-rejected nil))
|
|
1152 (while args
|
|
1153 (if (vectorp (car args))
|
|
1154 (if last-optional-rejected
|
|
1155 ()
|
|
1156 (let ((< LaTeX-optop)
|
|
1157 (> LaTeX-optcl))
|
|
1158 (TeX-parse-argument t (if (equal (length (car args)) 1)
|
|
1159 (aref (car args) 0)
|
|
1160 (append (car args) nil)))))
|
|
1161 (let ((< TeX-grop)
|
|
1162 (> TeX-grcl))
|
|
1163 (setq last-optional-rejected nil)
|
|
1164 (TeX-parse-argument nil (car args))))
|
|
1165 (setq args (cdr args)))))
|
|
1166
|
|
1167 (defun TeX-parse-argument (optional arg)
|
|
1168 "Depending on OPTIONAL, insert TeX macro argument ARG in curly braces.
|
|
1169 If OPTIONAL is set, only insert if there is anything to insert, and
|
|
1170 then use scare brackets.
|
|
1171
|
|
1172 See TeX-parse-macro for details."
|
|
1173
|
|
1174 (cond ((stringp arg)
|
|
1175 (TeX-arg-string optional arg))
|
|
1176 ((numberp arg)
|
|
1177 (if (< arg 1)
|
|
1178 ()
|
|
1179 (TeX-parse-argument optional t)
|
|
1180 (while (> arg 1)
|
|
1181 (TeX-parse-argument optional nil)
|
|
1182 (setq arg (- arg 1)))))
|
|
1183 ((null arg)
|
|
1184 (insert < >))
|
|
1185 ((eq arg t)
|
|
1186 (insert < )
|
|
1187 (set-marker exit-mark (point))
|
|
1188 (insert >))
|
|
1189 ((symbolp arg)
|
|
1190 (funcall arg optional))
|
|
1191 ((listp arg)
|
|
1192 (let ((head (car arg))
|
|
1193 (tail (cdr arg)))
|
|
1194 (cond ((stringp head)
|
|
1195 (apply 'TeX-arg-string optional arg))
|
|
1196 ((symbolp head)
|
|
1197 (apply head optional tail))
|
|
1198 (t (error "Unknown list argument type %s"
|
|
1199 (prin1-to-string head))))))
|
|
1200 (t (error "Unknown argument type %s" (prin1-to-string arg)))))
|
|
1201
|
|
1202 (defun TeX-argument-insert (name optional &optional prefix)
|
|
1203 "Insert NAME surrounded by curly braces.
|
|
1204
|
|
1205 If OPTIONAL, only insert it if not empty, and then use scuare brackets."
|
|
1206 (if (and optional (string-equal name ""))
|
|
1207 (setq last-optional-rejected t)
|
|
1208 (insert <)
|
|
1209 (if prefix
|
|
1210 (insert prefix))
|
|
1211 (if (and (string-equal name "")
|
|
1212 (null (marker-position exit-mark)))
|
|
1213 (set-marker exit-mark (point))
|
|
1214 (insert name))
|
|
1215 (insert >)))
|
|
1216
|
|
1217 (defun TeX-argument-prompt (optional prompt default &optional complete)
|
|
1218 "Return a argument prompt.
|
|
1219
|
|
1220 If OPTIONAL is not nil then the prompt will start with ``(Optional) ''.
|
|
1221
|
|
1222 PROMPT will be used if not nil, otherwise use DEFAULT.
|
|
1223
|
|
1224 Unless optional argument COMPLETE is non-nil, ``: '' will be appended."
|
|
1225 (concat (if optional "(Optional) " "")
|
|
1226 (if prompt prompt default)
|
|
1227 (if complete "" ": ")))
|
|
1228
|
|
1229 ;;; The Mode
|
|
1230
|
|
1231 (defvar TeX-format-list
|
|
1232 '(("AMSTEX" ams-tex-mode
|
|
1233 "\\\\document\\b")
|
|
1234 ("LATEX" latex-mode
|
|
1235 "\\\\\\(begin\\|section\\|chapter\\|documentstyle\\|documentclass\\)\\b")
|
|
1236 ("TEX" plain-tex-mode "."))
|
|
1237 "*List of format packages to consider when choosing a TeX mode.
|
|
1238
|
|
1239 A list with a entry for each format package available at the site.
|
|
1240
|
|
1241 Each entry is a list with three elements.
|
|
1242
|
|
1243 1. The name of the format package.
|
|
1244 2. The name of the major mode.
|
|
1245 3. A regexp typically matched in the beginning of the file.
|
|
1246
|
|
1247 When entering tex-mode, each regexp is tried in turn in order to find
|
|
1248 when major mode to enter.")
|
|
1249
|
|
1250 (defvar TeX-default-mode 'latex-mode
|
|
1251 "*Mode to enter for a new file when it can't be determined whether
|
|
1252 the file is plain TeX or LaTeX or what.")
|
|
1253
|
|
1254 (defvar TeX-force-default-mode nil
|
|
1255 "*If set to nil, try to infer the mode of the file from its content.")
|
|
1256
|
|
1257 ;;; Do not ;;;###autoload because of conflict with standard tex-mode.el.
|
|
1258 (defun tex-mode ()
|
|
1259 "Major mode for editing files of input for TeX or LaTeX.
|
|
1260 Tries to guess whether this file is for plain TeX or LaTeX.
|
|
1261
|
|
1262 The algorithm is as follows:
|
|
1263
|
|
1264 1) if the file is empty or TeX-force-default-mode is not set to nil,
|
|
1265 TeX-default-mode is chosen
|
|
1266 2) If \\documentstyle or \\begin{, \\section{, \\part{ or \\chapter{ is
|
|
1267 found, latex-mode is selected.
|
|
1268 3) Otherwise, use plain-tex-mode "
|
|
1269 (interactive)
|
|
1270
|
|
1271 (funcall (if (or (equal (buffer-size) 0)
|
|
1272 TeX-force-default-mode)
|
|
1273 TeX-default-mode
|
|
1274 (save-excursion
|
|
1275 (goto-char (point-min))
|
|
1276 (let ((comment-start-skip ;Used by TeX-in-comment
|
|
1277 (concat
|
|
1278 "\\(\\(^\\|[^\\]\\)\\("
|
|
1279 (regexp-quote TeX-esc)
|
|
1280 (regexp-quote TeX-esc)
|
|
1281 "\\)*\\)\\(%+ *\\)"))
|
|
1282 (entry TeX-format-list)
|
|
1283 answer)
|
|
1284 (while (and entry (not answer))
|
|
1285 (if (re-search-forward (nth 2 (car entry))
|
|
1286 10000 t)
|
|
1287 (if (not (TeX-in-comment))
|
|
1288 (setq answer (nth 1 (car entry))))
|
|
1289 (setq entry (cdr entry))))
|
|
1290 (if answer
|
|
1291 answer
|
|
1292 TeX-default-mode))))))
|
|
1293
|
|
1294 ;;; Do not ;;;###autoload because of conflict with standard tex-mode.el.
|
|
1295 (defun plain-tex-mode ()
|
|
1296 "Major mode for editing files of input for plain TeX.
|
|
1297 See info under AUC TeX for documentation.
|
|
1298
|
|
1299 Special commands:
|
|
1300 \\{TeX-mode-map}
|
|
1301
|
|
1302 Entering plain-tex-mode calls the value of text-mode-hook,
|
|
1303 then the value of TeX-mode-hook, and then the value
|
|
1304 of plain-TeX-mode-hook."
|
|
1305 (interactive)
|
|
1306 (plain-TeX-common-initialization)
|
|
1307 (setq mode-name "TeX")
|
|
1308 (setq major-mode 'plain-tex-mode)
|
|
1309 (setq TeX-command-default "TeX")
|
|
1310 (run-hooks 'text-mode-hook 'TeX-mode-hook 'plain-TeX-mode-hook))
|
|
1311
|
|
1312 ;;;###autoload
|
|
1313 (defun ams-tex-mode ()
|
|
1314 "Major mode for editing files of input for AmS TeX.
|
|
1315 See info under AUC TeX for documentation.
|
|
1316
|
|
1317 Special commands:
|
|
1318 \\{TeX-mode-map}
|
|
1319
|
|
1320 Entering AmS-tex-mode calls the value of text-mode-hook,
|
|
1321 then the value of TeX-mode-hook, and then the value
|
|
1322 of AmS-TeX-mode-hook."
|
|
1323 (interactive)
|
|
1324 (plain-TeX-common-initialization)
|
|
1325 (setq mode-name "AmS TeX")
|
|
1326 (setq major-mode 'ams-tex-mode)
|
|
1327 (setq TeX-command-default "AmSTeX")
|
|
1328 (run-hooks 'text-mode-hook 'TeX-mode-hook 'AmS-TeX-mode-hook))
|
|
1329
|
|
1330 (defun VirTeX-common-initialization ()
|
|
1331 ;; Initialize
|
|
1332 (kill-all-local-variables)
|
|
1333 (setq local-abbrev-table text-mode-abbrev-table)
|
|
1334 (setq indent-tabs-mode nil)
|
|
1335
|
|
1336 ;; Ispell support
|
|
1337 (make-local-variable 'ispell-parser)
|
|
1338 (setq ispell-parser 'tex)
|
|
1339 (make-local-variable 'ispell-tex-p)
|
|
1340 (setq ispell-tex-p t)
|
|
1341
|
|
1342 ;; Redefine some standard varaibles
|
|
1343 (make-local-variable 'paragraph-start)
|
|
1344 (make-local-variable 'paragraph-separate)
|
|
1345 (make-local-variable 'comment-start)
|
|
1346 (setq comment-start "%")
|
|
1347 (make-local-variable 'comment-start-skip)
|
|
1348 (setq comment-start-skip
|
|
1349 (concat
|
|
1350 "\\(\\(^\\|[^\\]\\)\\("
|
|
1351 (regexp-quote TeX-esc)
|
|
1352 (regexp-quote TeX-esc)
|
|
1353 "\\)*\\)\\(%+ *\\)"))
|
|
1354 (make-local-variable 'comment-indent-hook)
|
|
1355 (setq comment-indent-hook 'TeX-comment-indent)
|
|
1356 (make-local-variable 'comment-multi-line)
|
|
1357 (setq comment-multi-line nil)
|
|
1358 (make-local-variable 'compile-command)
|
|
1359 (if (boundp 'compile-command)
|
|
1360 ()
|
|
1361 (setq compile-command "make"))
|
|
1362 (make-local-variable 'words-include-escapes)
|
|
1363 (setq words-include-escapes nil)
|
|
1364
|
|
1365 ;; Make TAB stand out
|
|
1366 ;; (make-local-variable 'buffer-display-table)
|
|
1367 ;; (setq buffer-display-table (if standard-display-table
|
|
1368 ;; (copy-sequence standard-display-table)
|
|
1369 ;; (make-display-table)))
|
|
1370 ;; (aset buffer-display-table ?\t (apply 'vector (append "<TAB>" nil)))
|
|
1371
|
|
1372 ;; Symbol completion.
|
|
1373 (make-local-variable 'TeX-complete-list)
|
|
1374 (setq TeX-complete-list
|
|
1375 (list (list "\\\\\\([a-zA-Z]*\\)"
|
|
1376 1 'TeX-symbol-list (if TeX-insert-braces "{}"))
|
|
1377 (list "" TeX-complete-word)))
|
|
1378
|
|
1379 ;; We want this to be early in the list, so we do not add it before
|
|
1380 ;; we enter TeX mode the first time.
|
|
1381 (if (boundp 'local-write-file-hooks)
|
|
1382 (add-hook 'local-write-file-hooks 'TeX-safe-auto-write)
|
|
1383 (add-hook 'write-file-hooks 'TeX-safe-auto-write))
|
|
1384 (make-local-variable 'TeX-auto-update)
|
|
1385 (setq TeX-auto-update t))
|
|
1386
|
|
1387 (defun plain-TeX-common-initialization ()
|
|
1388 ;; Common initialization for plain TeX like modes.
|
|
1389 (VirTeX-common-initialization)
|
|
1390 (use-local-map plain-TeX-mode-map)
|
|
1391 (easy-menu-add TeX-mode-menu plain-TeX-mode-map)
|
|
1392 (easy-menu-add plain-TeX-mode-menu plain-TeX-mode-map)
|
|
1393 (set-syntax-table TeX-mode-syntax-table)
|
|
1394 (setq paragraph-start
|
|
1395 (concat
|
|
1396 "\\(^[ \t]*$"
|
|
1397 "\\|" (regexp-quote TeX-esc) "par\\|"
|
|
1398 "^[ \t]*"
|
|
1399 (regexp-quote TeX-esc)
|
|
1400 "\\("
|
|
1401 "begin\\|end\\|part\\|chapter\\|"
|
|
1402 "section\\|subsection\\|subsubsection\\|"
|
|
1403 "paragraph\\|include\\|includeonly\\|"
|
|
1404 "tableofcontents\\|appendix\\|label\\|caption\\|"
|
|
1405 "\\[\\|\\]" ; display math delimitors
|
|
1406 "\\)"
|
|
1407 "\\|"
|
|
1408 "^[ \t]*\\$\\$" ; display math delimitor
|
|
1409 "\\)" ))
|
|
1410 (setq paragraph-separate
|
|
1411 (concat
|
|
1412 "\\("
|
|
1413 (regexp-quote TeX-esc)
|
|
1414 "par\\|"
|
|
1415 "^[ \t]*$\\|"
|
|
1416 "^[ \t]*"
|
|
1417 (regexp-quote TeX-esc)
|
|
1418 "\\("
|
|
1419 "begin\\|end\\|label\\|caption\\|part\\|chapter\\|"
|
|
1420 "section\\|subsection\\|subsubsection\\|"
|
|
1421 "paragraph\\|include\\|includeonly\\|"
|
|
1422 "tableofcontents\\|appendix\\|" (regexp-quote TeX-esc)
|
|
1423 "\\)"
|
|
1424 "\\)"))
|
|
1425 (setq TeX-header-end (regexp-quote "%**end of header"))
|
|
1426 (setq TeX-trailer-start (regexp-quote (concat TeX-esc "bye")))
|
|
1427 (TeX-run-style-hooks "TEX"))
|
|
1428
|
|
1429 ;;; Hilighting
|
|
1430
|
|
1431 (if (boundp 'hilit-patterns-alist)
|
|
1432 (let ((latex-patterns (cdr-safe (assq 'latex-mode hilit-patterns-alist)))
|
|
1433 (plain-tex-patterns (cdr-safe (assq 'plain-tex-mode
|
|
1434 hilit-patterns-alist))))
|
|
1435 (if (and latex-patterns plain-tex-patterns)
|
|
1436 (setq hilit-patterns-alist
|
|
1437 (append (list (cons 'ams-tex-mode plain-tex-patterns))
|
|
1438 hilit-patterns-alist)))))
|
|
1439
|
|
1440 ;;; Parsing
|
|
1441
|
|
1442 (defvar TeX-auto-parser '((styles TeX-auto-file TeX-run-style-hooks)))
|
|
1443 ;; Alist of parsed information.
|
|
1444 ;; Each entry is a list with the following elements:
|
|
1445 ;;
|
|
1446 ;; 0. Name of information type.
|
|
1447 ;; 1. Name of temporary variable used when parsing.
|
|
1448 ;; 2. Name of function to add information to add to #3.
|
|
1449 ;; 3. Name of variable holding buffer local information.
|
|
1450 ;; 4. Name of variable indicating that #3 has changed.
|
|
1451
|
|
1452
|
|
1453 (defconst TeX-auto-parser-temporary 1)
|
|
1454 (defconst TeX-auto-parser-add 2)
|
|
1455 (defconst TeX-auto-parser-local 3)
|
|
1456 (defconst TeX-auto-parser-change 4)
|
|
1457
|
|
1458 (defun TeX-auto-add-type (name prefix &optional plural)
|
|
1459 "Add information about name to the parser using PREFIX.
|
|
1460
|
|
1461 Optional third argument PLURAL is the plural form of TYPE.
|
|
1462 By default just add a `s'.
|
|
1463
|
|
1464 This function create a set of variables and functions to maintain a
|
|
1465 separate type of information in the parser."
|
|
1466 (let* ((names (or plural (concat name "s")))
|
|
1467 (tmp (intern (concat prefix "-auto-" name)))
|
|
1468 (add (intern (concat prefix "-add-" names)))
|
|
1469 (local (intern (concat prefix "-" name "-list")))
|
|
1470 (change (intern (concat prefix "-" name "-changed"))))
|
|
1471 (setq TeX-auto-parser
|
|
1472 (cons (list name tmp add local change) TeX-auto-parser))
|
|
1473 (set local nil)
|
|
1474 (make-variable-buffer-local local)
|
|
1475 (set change nil)
|
|
1476 (make-variable-buffer-local change)
|
|
1477 (fset add (list 'lambda '(&rest entries)
|
|
1478 (concat "Add information about " (upcase name)
|
|
1479 " to the current buffer.")
|
|
1480 (list 'TeX-auto-add-information name 'entries)))
|
|
1481 (fset local (list 'lambda nil
|
|
1482 (concat "List of " names
|
|
1483 " active in the current buffer.")
|
|
1484 (list 'TeX-auto-list-information name)))
|
|
1485 (add-hook 'TeX-remove-style-hook
|
|
1486 (list 'lambda nil (list 'setq (symbol-name local) nil)))))
|
|
1487
|
|
1488 (defun TeX-auto-add-information (name entries)
|
|
1489 ;; For NAME in `TeX-auto-parser' add ENTRIES.
|
|
1490 (let* ((entry (assoc name TeX-auto-parser))
|
|
1491 (change (nth TeX-auto-parser-change entry))
|
|
1492 (change-value (symbol-value change))
|
|
1493 (local (nth TeX-auto-parser-local entry))
|
|
1494 (local-value (symbol-value local)))
|
|
1495 (if change-value
|
|
1496 (set local (cons entries local-value))
|
|
1497 (set change t)
|
|
1498 (set local (list entries local-value)))))
|
|
1499
|
|
1500 (defun TeX-auto-list-information (name)
|
|
1501 ;; Return information in `TeX-auto-parser' about NAME.
|
|
1502 (TeX-update-style)
|
|
1503 (let* ((entry (assoc name TeX-auto-parser))
|
|
1504 (change (nth TeX-auto-parser-change entry))
|
|
1505 (change-value (symbol-value change))
|
|
1506 (local (nth TeX-auto-parser-local entry)))
|
|
1507 (if (not change-value)
|
|
1508 ()
|
|
1509 (set change nil)
|
|
1510 ;; Sort it
|
|
1511 (message "Sorting " name "...")
|
|
1512 (set local
|
|
1513 (sort (mapcar 'TeX-listify (apply 'append (symbol-value local)))
|
|
1514 'TeX-car-string-lessp))
|
|
1515 ;; Make it unique
|
|
1516 (message "Removing duplicates...")
|
|
1517 (let ((entry (symbol-value local)))
|
|
1518 (while (and entry (cdr entry))
|
|
1519 (let ((this (car entry))
|
|
1520 (next (car (cdr entry))))
|
|
1521 (if (not (string-equal (car this) (car next)))
|
|
1522 (setq entry (cdr entry))
|
|
1523 ;; We have two equal symbols. Use the one with
|
|
1524 ;; most arguments.
|
|
1525 (if (> (length next) (length this))
|
|
1526 (setcdr this (cdr next)))
|
|
1527 (setcdr entry (cdr (cdr entry)))))))
|
|
1528 (message "Removing duplicates... done"))
|
|
1529 (symbol-value local)))
|
|
1530
|
|
1531 (TeX-auto-add-type "symbol" "TeX")
|
|
1532
|
|
1533 (defvar TeX-auto-apply-hook nil
|
|
1534 "Hook run when a buffer is parsed and the information is applied.")
|
|
1535
|
|
1536 (defun TeX-auto-apply ()
|
|
1537 ;; Parse and apply TeX information in the current buffer.
|
|
1538 (TeX-auto-parse)
|
|
1539 (run-hooks 'TeX-auto-apply-hook)
|
|
1540 (mapcar 'TeX-auto-apply-entry TeX-auto-parser))
|
|
1541
|
|
1542 (defun TeX-auto-apply-entry (entry)
|
|
1543 ;; Apply the information in an entry in `TeX-auto-parser'.
|
|
1544 (let ((value (symbol-value (nth TeX-auto-parser-temporary entry)))
|
|
1545 (add (nth TeX-auto-parser-add entry)))
|
|
1546 (if value (apply add value))))
|
|
1547
|
|
1548 (defun TeX-safe-auto-write ()
|
|
1549 ;; Call TeX-auto-write safely
|
|
1550 (condition-case name
|
|
1551 (and (boundp 'TeX-auto-update)
|
|
1552 TeX-auto-update
|
|
1553 (TeX-auto-write))
|
|
1554 (error nil))
|
|
1555 ;; Continue with the other write file hooks.
|
|
1556 nil)
|
|
1557
|
|
1558 (defvar TeX-auto-save nil
|
|
1559 "*Automatically save style information when saving the buffer.")
|
|
1560
|
|
1561 (defvar TeX-auto-untabify t
|
|
1562 "*Automatically untabify when saving the buffer.")
|
|
1563
|
|
1564 (defun TeX-auto-write ()
|
|
1565 ;; Save all relevant TeX information from the current buffer.
|
|
1566 (if TeX-auto-untabify
|
|
1567 (untabify (point-min) (point-max)))
|
|
1568 (if (and TeX-auto-save TeX-auto-local)
|
|
1569 (let* ((file (concat (TeX-master-directory)
|
|
1570 TeX-auto-local
|
|
1571 (if (string-match "/$" TeX-auto-local) "" "/")
|
|
1572 (TeX-strip-extension nil TeX-all-extensions t)
|
|
1573 ".el"))
|
|
1574 (dir (file-name-directory file)))
|
|
1575 ;; Create auto directory if possible.
|
|
1576 (if (not (file-exists-p dir))
|
|
1577 (condition-case name
|
|
1578 (make-directory (substring dir 0 -1))
|
|
1579 (error nil)))
|
|
1580 (if (file-writable-p file)
|
|
1581 (save-excursion
|
|
1582 (TeX-update-style)
|
|
1583 (TeX-auto-store file))
|
|
1584 (message "Can't write style information.")))))
|
|
1585
|
|
1586 (defvar TeX-macro-default (car-safe TeX-macro-private)
|
|
1587 "*Default directory to search for TeX macros.")
|
|
1588
|
|
1589 (defvar TeX-auto-default (car-safe TeX-auto-private)
|
|
1590 "*Default directory to place automatically generated TeX information.")
|
|
1591
|
|
1592 ;;;###autoload
|
|
1593 (defun TeX-auto-generate (tex auto)
|
|
1594 "Generate style file for TEX and store it in AUTO.
|
|
1595 If TEX is a directory, generate style files for all files in the directory."
|
|
1596 (interactive (list (setq TeX-macro-default
|
|
1597 (expand-file-name (read-file-name
|
|
1598 "TeX file or directory: "
|
|
1599 TeX-macro-default
|
|
1600 TeX-macro-default 'confirm)))
|
|
1601 (setq TeX-auto-default
|
|
1602 (expand-file-name (read-file-name
|
|
1603 "AUTO lisp directory: "
|
|
1604 TeX-auto-default
|
|
1605 TeX-auto-default 'confirm)))))
|
|
1606 (cond ((not (file-readable-p tex)))
|
|
1607 ((string-match TeX-ignore-file tex))
|
|
1608 ((file-directory-p tex)
|
|
1609 (let ((files (directory-files tex))
|
|
1610 (default-directory (concat (if (TeX-directory-absolute-p tex)
|
|
1611 ""
|
|
1612 default-directory)
|
|
1613 (if (string-match "/$" tex)
|
|
1614 tex
|
|
1615 (concat tex "/")))))
|
|
1616 (mapcar (function (lambda (file)
|
|
1617 (if (or TeX-file-recurse
|
|
1618 (not (file-directory-p file)))
|
|
1619 (TeX-auto-generate file auto))))
|
|
1620 files)))
|
|
1621 ((TeX-match-extension tex (append TeX-file-extensions
|
|
1622 BibTeX-file-extensions))
|
|
1623 (save-excursion
|
|
1624 (set-buffer (find-file-noselect tex))
|
|
1625 (message "Parsing %s..." tex)
|
|
1626 (TeX-auto-store (concat auto
|
|
1627 (if (string-match "/$" auto) "" "/")
|
|
1628 (TeX-strip-extension tex
|
|
1629 TeX-all-extensions
|
|
1630 t)
|
|
1631 ".el"))
|
|
1632 (kill-buffer (current-buffer))
|
|
1633 (message "Parsing %s... done" tex)))))
|
|
1634
|
|
1635 ;;;###autoload
|
|
1636 (defun TeX-auto-generate-global ()
|
|
1637 "Create global auto directory for global TeX macro definitions."
|
|
1638 (interactive)
|
|
1639 (make-directory (if (string-match "/$" TeX-auto-global)
|
|
1640 (substring TeX-auto-global 0 -1)
|
|
1641 TeX-auto-global))
|
|
1642 (mapcar (function (lambda (macro) (TeX-auto-generate macro TeX-auto-global)))
|
|
1643 TeX-macro-global)
|
|
1644 (byte-recompile-directory TeX-auto-global 0))
|
|
1645
|
|
1646 (defun TeX-auto-store (file)
|
|
1647 ;; Extract information for auc tex from current buffer and store it in FILE.
|
|
1648 (TeX-auto-parse)
|
|
1649
|
|
1650 (if (member nil (mapcar 'TeX-auto-entry-clear-p TeX-auto-parser))
|
|
1651 (let ((style (TeX-strip-extension nil TeX-all-extensions t)))
|
|
1652 (TeX-unload-style style)
|
|
1653 (save-excursion
|
|
1654 (set-buffer (generate-new-buffer file))
|
|
1655 (erase-buffer)
|
|
1656 (insert "(TeX-add-style-hook \"" style "\"\n"
|
|
1657 " (function\n"
|
|
1658 " (lambda ()")
|
|
1659 (mapcar 'TeX-auto-insert TeX-auto-parser)
|
|
1660 (insert ")))\n\n")
|
|
1661 (write-region (point-min) (point-max) file nil 'silent)
|
|
1662 (kill-buffer (current-buffer))))
|
|
1663 (if (file-exists-p (concat file "c"))
|
|
1664 (delete-file (concat file "c")))
|
|
1665 (if (file-exists-p file)
|
|
1666 (delete-file file))))
|
|
1667
|
|
1668 (defun TeX-auto-entry-clear-p (entry)
|
|
1669 ;; Check if the temporary for `TeX-auto-parser' entry ENTRY is clear.
|
|
1670 (null (symbol-value (nth TeX-auto-parser-temporary entry))))
|
|
1671
|
|
1672 (defun TeX-auto-insert (entry)
|
|
1673 ;; Insert code to initialize ENTRY from `TeX-auto-parser'.
|
|
1674 (let ((name (symbol-name (nth TeX-auto-parser-add entry)))
|
|
1675 (list (symbol-value (nth TeX-auto-parser-temporary entry))))
|
|
1676 (if (null list)
|
|
1677 ()
|
|
1678 (insert "\n (" name)
|
|
1679 (while list
|
|
1680 (insert "\n ")
|
|
1681 (if (stringp (car list))
|
|
1682 (insert (prin1-to-string (car list)))
|
|
1683 (insert "'" (prin1-to-string (car list))))
|
|
1684 (setq list (cdr list)))
|
|
1685 (insert ")"))))
|
|
1686
|
|
1687 (defvar TeX-auto-ignore
|
|
1688 '("csname" "filedate" "fileversion" "docdate" "next" "labelitemi"
|
|
1689 "labelitemii" "labelitemiii" "labelitemiv" "labelitemv"
|
|
1690 "labelenumi" "labelenumii" "labelenumiii" "labelenumiv"
|
|
1691 "labelenumv" "theenumi" "theenumii" "theenumiii" "theenumiv"
|
|
1692 "theenumv" "document" "par" "do" "expandafter")
|
|
1693 "List of symbols to ignore when scanning a TeX style file.")
|
|
1694
|
|
1695 (defun TeX-auto-add-regexp (regexp)
|
|
1696 "Add REGEXP to TeX-auto-regexp-list if not already a member."
|
|
1697 (if (symbolp TeX-auto-regexp-list)
|
|
1698 (setq TeX-auto-regexp-list (symbol-value TeX-auto-regexp-list)))
|
|
1699 (or (memq regexp TeX-auto-regexp-list)
|
|
1700 (setq TeX-auto-regexp-list (cons regexp TeX-auto-regexp-list))))
|
|
1701
|
|
1702 (defvar TeX-auto-empty-regexp-list
|
|
1703 '(("<IMPOSSIBLE>\\(\\'\\`\\)" 1 ignore))
|
|
1704 "List of regular expressions guaranteed to match nothing.")
|
|
1705
|
|
1706 (defvar plain-TeX-auto-regexp-list
|
|
1707 '(("\\\\def\\\\\\([a-zA-Z]+\\)[^a-zA-Z@]" 1 TeX-auto-symbol-check)
|
|
1708 ("\\\\let\\\\\\([a-zA-Z]+\\)[^a-zA-Z@]" 1 TeX-auto-symbol-check)
|
|
1709 ("\\\\font\\\\\\([a-zA-Z]+\\)[^a-zA-Z@]" 1 TeX-auto-symbol)
|
|
1710 ("\\\\chardef\\\\\\([a-zA-Z]+\\)[^a-zA-Z@]" 1 TeX-auto-symbol)
|
|
1711 ("\\\\new\\(count|dimen|muskip|skip\\)\\\\\\([a-z]+\\)[^a-zA-Z@]"
|
|
1712 2 TeX-auto-symbol)
|
|
1713 ("\\\\newfont{?\\\\\\([a-zA-Z]+\\)}?" 1 TeX-auto-symbol)
|
|
1714 ("\\\\typein\\[\\\\\\([a-zA-Z]+\\)\\]" 1 TeX-auto-symbol)
|
|
1715 ("\\\\input +\\(\\.*[^#%\\\\\\.\n\r]+\\)\\(\\.[^#%\\\\\\.\n\r]+\\)?"
|
|
1716 1 TeX-auto-file)
|
|
1717 ("\\\\mathchardef\\\\\\([a-zA-Z]+\\)[^a-zA-Z@]" 1 TeX-auto-symbol))
|
|
1718 "List of regular expression matching common LaTeX macro definitions.")
|
|
1719
|
|
1720 (defvar TeX-auto-full-regexp-list plain-TeX-auto-regexp-list
|
|
1721 "Full list of regular expression matching TeX macro definitions.")
|
|
1722
|
|
1723 (defvar TeX-auto-prepare-hook nil
|
|
1724 "List of hooks to be called before parsing a TeX file.")
|
|
1725
|
|
1726 (defvar TeX-auto-cleanup-hook nil
|
|
1727 "List of hooks to be called after parsing a TeX file.")
|
|
1728
|
|
1729 (defvar TeX-auto-parse-length 999999
|
|
1730 "*Maximal length of TeX file that will be parsed.")
|
|
1731 (make-variable-buffer-local 'TeX-auto-parse-length)
|
|
1732
|
|
1733 (defun TeX-auto-parse ()
|
|
1734 "Parse TeX information in current buffer.
|
|
1735
|
|
1736 Call the functions in TeX-auto-prepare-hook before parsing, and the
|
|
1737 functions in TeX-auto-cleanup-hook after parsing."
|
|
1738
|
|
1739 (let ((case-fold-search nil)
|
|
1740 (regexp-list (if (symbolp TeX-auto-regexp-list)
|
|
1741 (symbol-value TeX-auto-regexp-list)
|
|
1742 TeX-auto-regexp-list)))
|
|
1743
|
|
1744 (mapcar 'TeX-auto-clear-entry TeX-auto-parser)
|
|
1745 (run-hooks 'TeX-auto-prepare-hook)
|
|
1746
|
|
1747 ;; Parse
|
|
1748 (save-excursion
|
|
1749 (goto-char (min (point-max) TeX-auto-parse-length))
|
|
1750 ;; Extract the information.
|
|
1751 (let ((regexp (concat "\\("
|
|
1752 (mapconcat 'car regexp-list "\\)\\|\\(")
|
|
1753 "\\)")))
|
|
1754 (while (re-search-backward regexp nil t)
|
|
1755 (if (TeX-in-comment)
|
|
1756 ()
|
|
1757 (let* ((entry (TeX-member nil regexp-list
|
|
1758 (function (lambda (a b)
|
|
1759 (looking-at (nth 0 b))))))
|
|
1760 (symbol (nth 2 entry))
|
|
1761 (match (nth 1 entry)))
|
|
1762 (if (fboundp symbol)
|
|
1763 (funcall symbol match)
|
|
1764 (set symbol (cons (if (listp match)
|
|
1765 (mapcar 'TeX-match-buffer match)
|
|
1766 (TeX-match-buffer match))
|
|
1767 (symbol-value symbol)))))))))
|
|
1768
|
|
1769 ;; Cleanup ignored symbols.
|
|
1770
|
|
1771 ;; NOTE: This is O(N M) where it could be O(N log N + M log M) if we
|
|
1772 ;; sorted the lists first.
|
|
1773 (while (member (car TeX-auto-symbol) TeX-auto-ignore)
|
|
1774 (setq TeX-auto-symbol (cdr TeX-auto-symbol)))
|
|
1775 (let ((list TeX-auto-symbol))
|
|
1776 (while (and list (cdr list))
|
|
1777 (if (member (car (cdr list)) TeX-auto-ignore)
|
|
1778 (setcdr list (cdr (cdr list)))
|
|
1779 (setq list (cdr list)))))
|
|
1780
|
|
1781 (run-hooks 'TeX-auto-cleanup-hook)))
|
|
1782
|
|
1783 (defun TeX-auto-clear-entry (entry)
|
|
1784 ;; Set the temporary variable in ENTRY to nil.
|
|
1785 (set (nth TeX-auto-parser-temporary entry) nil))
|
|
1786
|
|
1787 (defvar LaTeX-auto-end-symbol nil)
|
|
1788
|
|
1789 (defun TeX-auto-symbol-check (match)
|
|
1790 "Add MATCH to TeX-auto-symbols.
|
|
1791 Check for potential LaTeX environments."
|
|
1792 (let ((symbol (if (listp match)
|
|
1793 (mapcar 'TeX-match-buffer match)
|
|
1794 (TeX-match-buffer match))))
|
|
1795 (if (and (stringp symbol)
|
|
1796 (string-match "^end\\(.+\\)$" symbol))
|
|
1797 (setq LaTeX-auto-end-symbol
|
|
1798 (cons (substring symbol (match-beginning 1) (match-end 1))
|
|
1799 LaTeX-auto-end-symbol))
|
|
1800 (setq TeX-auto-symbol (cons symbol TeX-auto-symbol)))))
|
|
1801
|
|
1802 ;;; Utilities
|
|
1803 ;;
|
|
1804 ;; Some of these functions has little to do with TeX, but nonetheless we
|
|
1805 ;; should use the "TeX-" prefix to avoid name clashes.
|
|
1806
|
|
1807 (defvar TeX-auto-regexp-list 'TeX-auto-full-regexp-list
|
|
1808 "*List of regular expresions used for parsing the current file.")
|
|
1809 (make-variable-buffer-local 'TeX-auto-regexp-list)
|
|
1810
|
|
1811 (defvar TeX-file-extensions '("tex" "sty" "cls" "ltx" "texi" "texinfo")
|
|
1812 "*File extensions used by manually generated TeX files.")
|
|
1813
|
|
1814 (defvar TeX-all-extensions '("[^.\n]+")
|
|
1815 "All possible file extensions.")
|
|
1816
|
|
1817 (defvar TeX-default-extension "tex"
|
|
1818 "*Default extension for TeX files.")
|
|
1819
|
|
1820 (make-variable-buffer-local 'TeX-default-extension)
|
|
1821
|
|
1822 (defvar BibTeX-file-extensions '("bib")
|
|
1823 "Valid file extensions for BibTeX files.")
|
|
1824
|
|
1825 (defvar BibTeX-style-extensions '("bst")
|
|
1826 "Valid file extensions for BibTeX styles.")
|
|
1827
|
|
1828 (defvar TeX-ignore-file "\\(^\\|/\\)\\(\\.\\|\\.\\.\\|RCS\\|SCCS\\|CVS\\)$"
|
|
1829 "*Regular expression matching file names to ignore.
|
|
1830
|
|
1831 These files or directories will not be considered when searching for
|
|
1832 TeX files in a directory.")
|
|
1833
|
|
1834 (defvar TeX-file-recurse t
|
|
1835 "*If not nil, search TeX directories recursivly.")
|
|
1836
|
|
1837 (defun TeX-match-extension (file &optional extensions)
|
|
1838 "Return non-nil if FILE has an one of EXTENSIONS.
|
|
1839
|
|
1840 If EXTENSIONS is not specified or nil, the value of
|
|
1841 TeX-file-extensions is used instead."
|
|
1842
|
|
1843 (if (null extensions)
|
|
1844 (setq extensions TeX-file-extensions))
|
|
1845
|
|
1846 (let ((regexp (concat "\\.\\("
|
|
1847 (mapconcat 'identity extensions "\\|")
|
|
1848 "\\)$")))
|
|
1849 (string-match regexp file)))
|
|
1850
|
|
1851 (defun TeX-strip-extension (&optional string extensions nodir nostrip)
|
|
1852 "Return STRING without any trailing extension in EXTENSIONS.
|
|
1853 If NODIR is `t', also remove directory part of STRING.
|
|
1854 If NODIR is `path', remove directory part of STRING if it is equal to
|
|
1855 the current directory, TeX-macro-private or TeX-macro-global.
|
|
1856 If NOSTRIP is set, do not remove extension after all.
|
|
1857 STRING defaults to the name of the current buffer.
|
|
1858 EXTENSIONS defaults to TeX-file-extensions."
|
|
1859
|
|
1860 (if (null string)
|
|
1861 (setq string (or (buffer-file-name) "<none>")))
|
|
1862
|
|
1863 (if (null extensions)
|
|
1864 (setq extensions TeX-file-extensions))
|
|
1865
|
|
1866 (let* ((strip (if (and (not nostrip)
|
|
1867 (TeX-match-extension string extensions))
|
|
1868 (substring string 0 (match-beginning 0))
|
|
1869 string))
|
|
1870 (dir (file-name-directory (expand-file-name strip))))
|
|
1871 (if (or (eq nodir t)
|
|
1872 (string-equal dir (expand-file-name "./"))
|
|
1873 (member dir TeX-macro-global)
|
|
1874 (member dir TeX-macro-private))
|
|
1875 (file-name-nondirectory strip)
|
|
1876 strip)))
|
|
1877
|
|
1878 (defun TeX-search-files (&optional directories extensions nodir strip)
|
|
1879 "Return a list of all reachable files in DIRECTORIES ending with EXTENSIONS.
|
|
1880 If optional argument NODIR is set, remove directory part.
|
|
1881 If optional argument STRIP is set, remove file extension.
|
|
1882 If optional argument DIRECTORIES is set, search in those directories.
|
|
1883 Otherwise, search in all TeX macro directories.
|
|
1884 If optional argument EXTENSIONS is not set, use TeX-file-extensions"
|
|
1885
|
|
1886 (if (null extensions)
|
|
1887 (setq extensions TeX-file-extensions))
|
|
1888
|
|
1889 (if (null directories)
|
|
1890 (setq directories
|
|
1891 (cons "./" (append TeX-macro-private TeX-macro-global))))
|
|
1892
|
|
1893 (let (match)
|
|
1894
|
|
1895 (while directories
|
|
1896 (let* ((directory (car directories))
|
|
1897 (content (and directory
|
|
1898 (file-readable-p directory)
|
|
1899 (file-directory-p directory)
|
|
1900 (directory-files directory))))
|
|
1901
|
|
1902 (setq directories (cdr directories))
|
|
1903
|
|
1904 (while content
|
|
1905 (let ((file (concat directory (car content))))
|
|
1906
|
|
1907 (setq content (cdr content))
|
|
1908 (cond ((string-match TeX-ignore-file file))
|
|
1909 ((not (file-readable-p file)))
|
|
1910 ((file-directory-p file)
|
|
1911 (if TeX-file-recurse
|
|
1912 (setq directories
|
|
1913 (cons (concat file "/") directories))))
|
|
1914 ((TeX-match-extension file extensions)
|
|
1915 (setq match (cons (TeX-strip-extension file
|
|
1916 extensions
|
|
1917 nodir
|
|
1918 (not strip))
|
|
1919 match))))))))
|
|
1920
|
|
1921 match))
|
|
1922
|
|
1923 (defun TeX-car-string-lessp (a b)
|
|
1924 (string-lessp (car a) (car b)))
|
|
1925
|
|
1926 (defun TeX-listify (a)
|
|
1927 (if (listp a) a (list a)))
|
|
1928
|
|
1929 (defun TeX-member (elt list how)
|
|
1930 "Returns the member ELT in LIST. Comparison done with HOW.
|
|
1931
|
|
1932 Return nil if ELT is not a member of LIST."
|
|
1933 (while (and list (not (funcall how elt (car list))))
|
|
1934 (setq list (cdr list)))
|
|
1935 (car-safe list))
|
|
1936
|
|
1937 (defun TeX-assoc (elem list)
|
|
1938 "Like assoc, except case incentive."
|
|
1939 (let ((case-fold-search t))
|
|
1940 (TeX-member elem list
|
|
1941 (function (lambda (a b)
|
|
1942 (string-match (concat "^" (regexp-quote a) "$")
|
|
1943 (car b)))))))
|
|
1944
|
|
1945 (defun TeX-match-buffer (n)
|
|
1946 "Return the substring corresponding to the N'th match.
|
|
1947 See match-data for details."
|
|
1948 (if (match-beginning n)
|
|
1949 (let ((str (buffer-substring (match-beginning n) (match-end n))))
|
|
1950 (set-text-properties 0 (length str) nil str)
|
|
1951 (copy-sequence str))
|
|
1952 ""))
|
|
1953
|
|
1954 (defun TeX-function-p (arg)
|
|
1955 "Return non-nil if ARG is callable as a function."
|
|
1956 (or (and (fboundp 'byte-code-function-p)
|
|
1957 (byte-code-function-p arg))
|
|
1958 (and (listp arg)
|
|
1959 (eq (car arg) 'lambda))
|
|
1960 (and (symbolp arg)
|
|
1961 (fboundp arg))))
|
|
1962
|
|
1963 (defun TeX-looking-at-backward (regexp &optional limit)
|
|
1964 ;; Return non-nil if the text before point matches REGEXP.
|
|
1965 ;; Optional second argument LIMIT gives a max number of characters
|
|
1966 ;; to look backward for.
|
|
1967 (let ((pos (point)))
|
|
1968 (save-excursion
|
|
1969 (and (re-search-backward regexp
|
|
1970 (if limit (max (point-min) (- (point) limit)))
|
|
1971 t)
|
|
1972 (eq (match-end 0) pos)))))
|
|
1973
|
|
1974 ;;; Syntax Table
|
|
1975
|
|
1976 (defvar TeX-mode-syntax-table (make-syntax-table)
|
|
1977 "Syntax table used while in TeX mode.")
|
|
1978
|
|
1979 (make-variable-buffer-local 'TeX-mode-syntax-table)
|
|
1980
|
|
1981 (progn ; Define TeX-mode-syntax-table.
|
|
1982 (modify-syntax-entry (string-to-char TeX-esc)
|
|
1983 "\\" TeX-mode-syntax-table)
|
|
1984 (modify-syntax-entry ?\f ">" TeX-mode-syntax-table)
|
|
1985 (modify-syntax-entry ?\n ">" TeX-mode-syntax-table)
|
|
1986 (modify-syntax-entry (string-to-char TeX-grop)
|
|
1987 (concat "(" TeX-grcl)
|
|
1988 TeX-mode-syntax-table)
|
|
1989 (modify-syntax-entry (string-to-char TeX-grcl)
|
|
1990 (concat ")" TeX-grop)
|
|
1991 TeX-mode-syntax-table)
|
|
1992 (modify-syntax-entry ?% "<" TeX-mode-syntax-table)
|
|
1993 (modify-syntax-entry ?\" "." TeX-mode-syntax-table)
|
|
1994 (modify-syntax-entry ?& "." TeX-mode-syntax-table)
|
|
1995 (modify-syntax-entry ?_ "." TeX-mode-syntax-table)
|
|
1996 (modify-syntax-entry ?@ "_" TeX-mode-syntax-table)
|
|
1997 (modify-syntax-entry ?~ " " TeX-mode-syntax-table)
|
|
1998 (modify-syntax-entry ?$ "$" TeX-mode-syntax-table)
|
|
1999 (modify-syntax-entry ?' "w" TeX-mode-syntax-table))
|
|
2000
|
|
2001 ;;; Menu Support
|
|
2002
|
|
2003 (defvar TeX-command-current 'TeX-command-master)
|
|
2004 ;; Function used to run external command.
|
|
2005
|
|
2006 (defun TeX-command-select-master ()
|
|
2007 (interactive)
|
|
2008 (message "Next command will be on the master file")
|
|
2009 (setq TeX-command-current 'TeX-command-master))
|
|
2010
|
|
2011 (defun TeX-command-select-buffer ()
|
|
2012 (interactive)
|
|
2013 (message "Next command will be on the buffer")
|
|
2014 (setq TeX-command-current 'TeX-command-buffer))
|
|
2015
|
|
2016 (defun TeX-command-select-region ()
|
|
2017 (interactive)
|
|
2018 (message "Next command will be on the region")
|
|
2019 (setq TeX-command-current 'TeX-command-region))
|
|
2020
|
|
2021 (defvar TeX-command-force nil)
|
|
2022 ;; If non-nil, TeX-command-query will return the value of this
|
|
2023 ;; variable instead of quering the user.
|
|
2024
|
|
2025 (defun TeX-command-menu (name)
|
|
2026 ;; Execute TeX-command-list NAME from a menu.
|
|
2027 (let ((TeX-command-force name))
|
|
2028 (funcall TeX-command-current)))
|
|
2029
|
|
2030 (defun TeX-command-menu-print (printer command name)
|
|
2031 ;; Print on PRINTER using method COMMAND to run NAME.
|
|
2032 (let ((TeX-printer-default printer)
|
|
2033 (TeX-printer-list nil)
|
|
2034 (TeX-print-command command))
|
|
2035 (TeX-command-menu name)))
|
|
2036
|
|
2037 (defun TeX-command-menu-printer-entry (entry)
|
|
2038 ;; Return TeX-printer-list ENTRY as a menu item.
|
|
2039 (vector (nth 0 entry)
|
|
2040 (list 'TeX-command-menu-print
|
|
2041 (nth 0 entry)
|
|
2042 (or (nth lookup entry) command)
|
|
2043 name)
|
|
2044 t))
|
|
2045
|
|
2046 ;; Begin fix part 1 by Ulrik Dickow <dickow@nbi.dk> 16-Feb-1996,
|
|
2047 ;; to make queue command usable. Easy but ugly code duplication again.
|
|
2048
|
|
2049 (defun TeX-command-menu-queue (printer command name)
|
|
2050 ;; Show queue for PRINTER using method COMMAND to run NAME.
|
|
2051 (let ((TeX-printer-default printer)
|
|
2052 (TeX-printer-list nil)
|
|
2053 (TeX-queue-command command))
|
|
2054 (TeX-command-menu name)))
|
|
2055
|
|
2056 (defun TeX-command-menu-queue-entry (entry)
|
|
2057 ;; Return TeX-printer-list ENTRY as a menu item.
|
|
2058 (vector (nth 0 entry)
|
|
2059 (list 'TeX-command-menu-queue
|
|
2060 (nth 0 entry)
|
|
2061 (or (nth lookup entry) command)
|
|
2062 name)
|
|
2063 t))
|
|
2064
|
|
2065 ;; End fix part 1.
|
|
2066
|
|
2067 (defun TeX-command-menu-entry (entry)
|
|
2068 ;; Return TeX-command-list ENTRY as a menu item.
|
|
2069 (let ((name (car entry)))
|
|
2070 (cond ((and (string-equal name TeX-command-Print)
|
|
2071 TeX-printer-list)
|
|
2072 (let ((command TeX-print-command)
|
|
2073 (lookup 1))
|
|
2074 (append (list TeX-command-Print)
|
|
2075 (mapcar 'TeX-command-menu-printer-entry
|
|
2076 TeX-printer-list))))
|
|
2077 ((and (string-equal name TeX-command-Queue)
|
|
2078 TeX-printer-list)
|
|
2079 (let ((command TeX-queue-command)
|
|
2080 (lookup 2))
|
|
2081 (append (list TeX-command-Queue)
|
|
2082 (mapcar 'TeX-command-menu-queue-entry ; dickow fix part 2.
|
|
2083 TeX-printer-list))))
|
|
2084 (t
|
|
2085 (vector name (list 'TeX-command-menu name) t)))))
|
|
2086
|
|
2087 ;;; Keymap
|
|
2088
|
|
2089 (defvar TeX-electric-escape nil
|
|
2090 "If this is non-nil when AUC TeX is loaded, the TeX escape
|
|
2091 character ``\\'' will be bound to `TeX-electric-macro'.")
|
|
2092
|
|
2093 (defvar TeX-mode-map nil
|
|
2094 "Keymap for common TeX and LaTeX commands.")
|
|
2095
|
|
2096 (if TeX-mode-map
|
|
2097 ()
|
|
2098 (setq TeX-mode-map (make-sparse-keymap))
|
|
2099
|
|
2100 ;; Standard
|
|
2101 ;; (define-key TeX-mode-map "\177" 'backward-delete-char-untabify)
|
|
2102 (define-key TeX-mode-map "\C-c}" 'up-list)
|
|
2103 (define-key TeX-mode-map "\C-c#" 'TeX-normal-mode)
|
|
2104 (define-key TeX-mode-map "\C-c\C-n" 'TeX-normal-mode)
|
|
2105 (define-key TeX-mode-map "\C-c?" 'describe-mode)
|
|
2106 (define-key TeX-mode-map "\C-c\C-i" 'TeX-goto-info-page)
|
|
2107
|
|
2108 ;; From tex.el
|
|
2109 (define-key TeX-mode-map "\"" 'TeX-insert-quote)
|
|
2110 (define-key TeX-mode-map "$" 'TeX-insert-dollar)
|
|
2111 (define-key TeX-mode-map "." 'TeX-insert-punctuation)
|
|
2112 (define-key TeX-mode-map "," 'TeX-insert-punctuation)
|
|
2113 (define-key TeX-mode-map "\C-c{" 'TeX-insert-braces)
|
|
2114 (define-key TeX-mode-map "\C-c\C-f" 'TeX-font)
|
|
2115 (define-key TeX-mode-map "\C-c\C-m" 'TeX-insert-macro)
|
|
2116 (if TeX-electric-escape
|
|
2117 (define-key TeX-mode-map "\\" 'TeX-electric-macro))
|
|
2118 (define-key TeX-mode-map "\e\t" 'TeX-complete-symbol) ;*** Emacs 19 way
|
|
2119
|
|
2120 (define-key TeX-mode-map "\C-c;" 'TeX-comment-region)
|
|
2121 (define-key TeX-mode-map "\C-c%" 'TeX-comment-paragraph)
|
|
2122
|
|
2123 (define-key TeX-mode-map "\C-c'" 'TeX-comment-paragraph) ;*** Old way
|
|
2124 (define-key TeX-mode-map "\C-c:" 'TeX-un-comment-region) ;*** Old way
|
|
2125 (define-key TeX-mode-map "\C-c\"" 'TeX-un-comment) ;*** Old way
|
|
2126
|
|
2127 ;; From tex-buf.el
|
|
2128 (define-key TeX-mode-map "\C-c\C-d" 'TeX-save-document)
|
|
2129 (define-key TeX-mode-map "\C-c\C-r" 'TeX-command-region)
|
|
2130 (define-key TeX-mode-map "\C-c\C-b" 'TeX-command-buffer)
|
|
2131 (define-key TeX-mode-map "\C-c\C-c" 'TeX-command-master)
|
|
2132 (define-key TeX-mode-map "\C-c\C-k" 'TeX-kill-job)
|
|
2133 (define-key TeX-mode-map "\C-c\C-l" 'TeX-recenter-output-buffer)
|
|
2134 (define-key TeX-mode-map "\C-c^" 'TeX-home-buffer)
|
|
2135 (define-key TeX-mode-map "\C-c`" 'TeX-next-error)
|
|
2136 (define-key TeX-mode-map "\C-c\C-w" 'TeX-toggle-debug-boxes))
|
|
2137
|
|
2138 (easy-menu-define TeX-mode-menu
|
|
2139 TeX-mode-map
|
|
2140 "Menu used in TeX mode."
|
|
2141 (append '("Command")
|
|
2142 '(("Command on"
|
|
2143 [ "Master File" TeX-command-select-master
|
|
2144 :keys "C-c C-c" :style radio
|
|
2145 :selected (eq TeX-command-current 'TeX-command-master) ]
|
|
2146 [ "Buffer" TeX-command-select-buffer
|
|
2147 :keys "C-c C-b" :style radio
|
|
2148 :selected (eq TeX-command-current 'TeX-command-buffer) ]
|
|
2149 [ "Region" TeX-command-select-region
|
|
2150 :keys "C-c C-r" :style radio
|
|
2151 :selected (eq TeX-command-current 'TeX-command-region) ]))
|
|
2152 (let ((file 'TeX-command-on-current))
|
|
2153 (mapcar 'TeX-command-menu-entry TeX-command-list))))
|
|
2154
|
|
2155 (defvar plain-TeX-mode-map (copy-keymap TeX-mode-map)
|
|
2156 "Keymap used in plain TeX mode.")
|
|
2157
|
|
2158 (easy-menu-define plain-TeX-mode-menu
|
|
2159 plain-TeX-mode-map
|
|
2160 "Menu used in plain TeX mode."
|
|
2161 (list "TeX"
|
|
2162 ["Macro..." TeX-insert-macro t]
|
|
2163 ["Complete" TeX-complete-symbol t]
|
|
2164 ["Save Document" TeX-save-document t]
|
|
2165 ["Next Error" TeX-next-error t]
|
|
2166 ["Kill Job" TeX-kill-job t]
|
|
2167 ["Debug Bad Boxes" TeX-toggle-debug-boxes
|
|
2168 :style toggle :selected TeX-debug-bad-boxes ]
|
|
2169 ["Switch to Original File" TeX-home-buffer t]
|
|
2170 ["Recenter Output Buffer" TeX-recenter-output-buffer t]
|
|
2171 ;; ["Uncomment" TeX-un-comment t]
|
|
2172 ["Uncomment Region" TeX-un-comment-region t]
|
|
2173 ;; ["Comment Paragraph" TeX-comment-paragraph t]
|
|
2174 ["Comment Region" TeX-comment-region t]
|
|
2175 ["Switch to Master file" TeX-home-buffer t]
|
|
2176 ["Documentation" TeX-goto-info-page t]
|
|
2177 ["Submit bug report" TeX-submit-bug-report t]
|
|
2178 ["Reset Buffer" TeX-normal-mode t]
|
|
2179 ["Reset AUC TeX" (TeX-normal-mode t) :keys "C-u C-c C-n"]))
|
|
2180
|
|
2181 ;;; Comments
|
|
2182
|
|
2183 (defun TeX-un-comment-region (start end level)
|
|
2184 "Remove up to LEVEL comment characters from each line in the region."
|
|
2185 (interactive "*r\np")
|
|
2186 (comment-region start end (- level)))
|
|
2187
|
|
2188 (defun TeX-un-comment (level)
|
|
2189 "Delete up to LEVEL %'s from the beginning of each line in a comment."
|
|
2190 (interactive "*p")
|
|
2191 (save-excursion
|
|
2192 ; Find first comment line
|
|
2193 (re-search-backward (concat "^[^" comment-start "]") nil 'limit)
|
|
2194 (let ((beg (point)))
|
|
2195 (forward-line 1)
|
|
2196 ; Find last comment line
|
|
2197 (re-search-forward (concat "^[^" comment-start "]") nil 'limit)
|
|
2198 ; Uncomment region
|
|
2199 (comment-region beg (point) (- level)))))
|
|
2200
|
|
2201 (fset 'TeX-comment-region 'comment-region)
|
|
2202
|
|
2203 (defun TeX-comment-paragraph (level)
|
|
2204 "Inserts LEVEL %'s at the beginning of every line in the current paragraph."
|
|
2205 (interactive "*p")
|
|
2206 (if (< level 0)
|
|
2207 (TeX-un-comment (- level))
|
|
2208 (save-excursion
|
|
2209 (mark-paragraph)
|
|
2210 (comment-region (point) (mark) level))))
|
|
2211
|
|
2212 (defun TeX-in-comment ()
|
|
2213 ;; Return non-nil if point is in a comment.
|
|
2214 (if (or (bolp)
|
|
2215 (null comment-start-skip)
|
|
2216 (eq (preceding-char) ?\r))
|
|
2217 nil
|
|
2218 (save-excursion
|
|
2219 (let ((pos (point)))
|
|
2220 (re-search-backward "^\\|\r" nil t)
|
|
2221 (or (looking-at comment-start-skip)
|
|
2222 (re-search-forward comment-start-skip pos t))))))
|
|
2223
|
|
2224 ;;; Indentation
|
|
2225
|
|
2226 (defun TeX-brace-count-line ()
|
|
2227 "Count number of open/closed braces."
|
|
2228 (save-excursion
|
|
2229 (save-restriction
|
|
2230 (let ((count 0))
|
|
2231 (narrow-to-region (point)
|
|
2232 (save-excursion
|
|
2233 (re-search-forward "[^\\\\]%\\|\n\\|\\'")
|
|
2234 (backward-char)
|
|
2235 (point)))
|
|
2236
|
|
2237 (while (re-search-forward "\\({\\|}\\|\\\\.\\)" nil t)
|
|
2238 (cond
|
|
2239 ((string= "{" (TeX-match-buffer 1))
|
|
2240 (setq count (+ count TeX-brace-indent-level)))
|
|
2241 ((string= "}" (TeX-match-buffer 1))
|
|
2242 (setq count (- count TeX-brace-indent-level)))))
|
|
2243 count))))
|
|
2244
|
|
2245 (defvar TeX-brace-indent-level 2
|
|
2246 "*The level of indentation produced by a open brace.")
|
|
2247
|
|
2248 (defun TeX-comment-indent ()
|
|
2249 (if (looking-at "%%%")
|
|
2250 (current-column)
|
|
2251 (skip-chars-backward " \t")
|
|
2252 (max (if (bolp) 0 (1+ (current-column)))
|
|
2253 comment-column)))
|
|
2254
|
|
2255 ;;; Fonts
|
|
2256
|
|
2257 (defvar TeX-font-list '((?\C-b "{\\bf " "}")
|
|
2258 (?\C-c "{\\sc " "}")
|
|
2259 (?\C-e "{\\em " "\\/}")
|
|
2260 (?\C-i "{\\it " "\\/}")
|
|
2261 (?\C-r "{\\rm " "}")
|
|
2262 (?\C-s "{\\sl " "\\/}")
|
|
2263 (?\C-t "{\\tt " "}")
|
|
2264 (?\C-d "" "" t))
|
|
2265 "*List of fonts used by TeX-font.
|
|
2266
|
|
2267 Each entry is a list with three elements. The first element is the
|
|
2268 key to active the font. The second element is the string to insert
|
|
2269 before point, and the third element is the string to insert after
|
|
2270 point. An optional fourth element means always replace if not nil.")
|
|
2271
|
|
2272 (defvar TeX-font-replace-function 'TeX-font-replace
|
|
2273 "Determines the function which is called when a font should be replaced.")
|
|
2274
|
|
2275 (defun TeX-describe-font-entry (entry)
|
|
2276 ;; A textual description of an ENTRY in TeX-font-list.
|
|
2277 (concat (format "%8s\t" (key-description (char-to-string (nth 0 entry))))
|
|
2278 (if (nth 3 entry)
|
|
2279 "-- delete font"
|
|
2280 (format "%10s %s" (nth 1 entry) (nth 2 entry)))))
|
|
2281
|
|
2282 (defun TeX-font (replace what)
|
|
2283 "Insert template for font change command.
|
|
2284 If REPLACE is not nil, replace current font. WHAT determines the font
|
|
2285 to use, as specified by TeX-font-list."
|
|
2286 (interactive "*P\nc")
|
|
2287 (TeX-update-style)
|
|
2288 (let* ((entry (assoc what TeX-font-list)))
|
|
2289 (setq replace (or replace (nth 3 entry)))
|
|
2290 (cond ((null entry)
|
|
2291 (let ((help (concat "Font list:\n\n"
|
|
2292 (mapconcat 'TeX-describe-font-entry
|
|
2293 TeX-font-list "\n"))))
|
|
2294 (with-output-to-temp-buffer "*Help*"
|
|
2295 (set-buffer "*Help*")
|
|
2296 (insert help))))
|
|
2297 (replace
|
|
2298 (funcall TeX-font-replace-function (nth 1 entry) (nth 2 entry)))
|
|
2299 ((TeX-active-mark)
|
|
2300 (save-excursion
|
|
2301 (cond ((> (mark) (point))
|
|
2302 (insert (nth 1 entry))
|
|
2303 (goto-char (mark))
|
|
2304 (insert (nth 2 entry)))
|
|
2305 (t
|
|
2306 (insert (nth 2 entry))
|
|
2307 (goto-char (mark))
|
|
2308 (insert (nth 1 entry))))))
|
|
2309 (t
|
|
2310 (insert (nth 1 entry))
|
|
2311 (save-excursion
|
|
2312 (insert (nth 2 entry)))))))
|
|
2313 (defun TeX-font-replace (start end)
|
|
2314 "Replace font specification around point with START and END."
|
|
2315 (save-excursion
|
|
2316 (while (not (looking-at "{\\\\[a-zA-Z]+ "))
|
|
2317 (up-list -1))
|
|
2318 (forward-sexp)
|
|
2319 (save-excursion
|
|
2320 (replace-match start t t))
|
|
2321 (if (save-excursion
|
|
2322 (backward-char 3)
|
|
2323 (if (looking-at (regexp-quote "\\/}"))
|
|
2324 (progn
|
|
2325 (delete-char 3)
|
|
2326 nil)
|
|
2327 t))
|
|
2328 (delete-backward-char 1))
|
|
2329 (insert end)))
|
|
2330
|
|
2331 ;;; Dollars
|
|
2332 ;;
|
|
2333 ;; Originally stolen from VorTeX.
|
|
2334 ;; Copyright (C) 1986, 1987, 1988 Pehong Chen (phc@renoir.berkeley.edu)
|
|
2335
|
|
2336 (defvar TeX-dollar-sign ?$
|
|
2337 "*Character user to enter and leaver math mode in TeX.")
|
|
2338
|
|
2339 (defconst TeX-dollar-string (char-to-string TeX-dollar-sign))
|
|
2340
|
|
2341 (defconst TeX-dollar-regexp
|
|
2342 (concat "^" (regexp-quote TeX-dollar-string) "\\|[^" TeX-esc "]"
|
|
2343 (regexp-quote TeX-dollar-string)))
|
|
2344
|
|
2345 (defvar TeX-dollar-list nil)
|
|
2346 (make-variable-buffer-local 'TeX-match-dollar-on)
|
|
2347
|
|
2348 (defvar TeX-par-start nil)
|
|
2349 (make-variable-buffer-local 'TeX-par-start)
|
|
2350
|
|
2351 (defvar TeX-par-end nil)
|
|
2352 (make-variable-buffer-local 'TeX-par-end)
|
|
2353
|
|
2354 (defvar TeX-symbol-marker nil)
|
|
2355
|
|
2356 (defvar TeX-symbol-marker-pos 0)
|
|
2357
|
|
2358 (defun TeX-bouncing-point (m)
|
|
2359 (save-excursion
|
|
2360 (if (pos-visible-in-window-p)
|
|
2361 (sit-for 1)
|
|
2362 (let* ((pos1 (point))
|
|
2363 (pos2 (+ pos1 m))
|
|
2364 (sym (buffer-substring pos1 pos2))
|
|
2365 (msg1 (progn (beginning-of-line) (buffer-substring (point) pos1)))
|
|
2366 (msg2 (progn (end-of-line) (buffer-substring pos2 (point)))))
|
|
2367 (message "%s`%s'%s" msg1 sym msg2)))))
|
|
2368
|
|
2369 (defun TeX-locate-delimiter (pos sym symlst)
|
|
2370 (let ((marker nil)
|
|
2371 (marker-pos 0)
|
|
2372 (pair t)
|
|
2373 (head nil))
|
|
2374 (catch 'loop
|
|
2375 (while symlst
|
|
2376 (setq marker (car symlst))
|
|
2377 (setq marker-pos (1- (marker-position marker)))
|
|
2378 (if (and (/= pos marker-pos) (= (char-after marker-pos) sym))
|
|
2379 (if (> pos marker-pos)
|
|
2380 (progn
|
|
2381 (setq TeX-symbol-marker-pos marker-pos)
|
|
2382 (setq TeX-symbol-marker marker)
|
|
2383 (setq head (cons marker head))
|
|
2384 (setq pair (not pair)))
|
|
2385 (if pair (setq TeX-symbol-marker nil))
|
|
2386 (throw 'loop (append (reverse head)
|
|
2387 (cons (set-marker (make-marker) (1+ pos))
|
|
2388 symlst)))))
|
|
2389 (setq symlst (cdr symlst)))
|
|
2390 (if pair (setq TeX-symbol-marker nil))
|
|
2391 (reverse (cons (set-marker (make-marker) (1+ pos)) head)))))
|
|
2392
|
|
2393 (defun TeX-dollar-verify ()
|
|
2394 ;; Verify if the current paragraph is the same as last.
|
|
2395 ;; If so, do nothing, otherwise reset TeX-par-start and TeX-par-end and
|
|
2396 ;; reconstruct the symbol-list.
|
|
2397 (let ((start (save-excursion
|
|
2398 (if (re-search-backward paragraph-separate nil t)
|
|
2399 (point)
|
|
2400 1)))
|
|
2401 (end (save-excursion
|
|
2402 (if (re-search-forward paragraph-separate nil t)
|
|
2403 (1+ (point))
|
|
2404 (1+ (point-max)))))
|
|
2405 (init nil))
|
|
2406 (if (null TeX-par-start)
|
|
2407 (setq TeX-par-start (set-marker (make-marker) 1)))
|
|
2408 (if (/= (marker-position TeX-par-start) start)
|
|
2409 (progn
|
|
2410 (set-marker TeX-par-start start)
|
|
2411 (setq init t)))
|
|
2412 (if (null TeX-par-end)
|
|
2413 (setq TeX-par-end (set-marker (make-marker) 1)))
|
|
2414 (if (/= (marker-position TeX-par-end) end)
|
|
2415 (progn
|
|
2416 (set-marker TeX-par-end end)
|
|
2417 (setq init t)))
|
|
2418 (if init
|
|
2419 (save-excursion
|
|
2420 (setq TeX-dollar-list nil)
|
|
2421 (goto-char start)
|
|
2422 (while (re-search-forward TeX-dollar-regexp end t)
|
|
2423 (setq TeX-dollar-list
|
|
2424 (append TeX-dollar-list
|
|
2425 (list (set-marker (make-marker)
|
|
2426 (if (= (following-char)
|
|
2427 TeX-dollar-sign)
|
|
2428 (progn
|
|
2429 (forward-char 1)
|
|
2430 (point))
|
|
2431 (point)))))))))))
|
|
2432
|
|
2433 (defun TeX-insert-dollar (&optional arg)
|
|
2434 "Insert dollar sign.
|
|
2435
|
|
2436 Show matching dollar sign if this dollar sign end the TeX math mode.
|
|
2437 Ensure double dollar signs match up correctly by inserting extra
|
|
2438 dollar signs when needed.
|
|
2439
|
|
2440 With optional ARG, insert that many dollar signs."
|
|
2441 (interactive "P")
|
|
2442 (if arg
|
|
2443 (let ((count (prefix-numeric-value arg)))
|
|
2444 (if (listp arg)
|
|
2445 (self-insert-command 1) ;C-u always inserts just one
|
|
2446 (self-insert-command count)))
|
|
2447 (let ((pc (preceding-char))
|
|
2448 (pos (point))
|
|
2449 (pt (point))
|
|
2450 (single t))
|
|
2451 (TeX-dollar-verify)
|
|
2452 (if (= pc (string-to-char TeX-esc))
|
|
2453 (insert TeX-dollar-sign)
|
|
2454 (if (and (= pc TeX-dollar-sign)
|
|
2455 (/= (char-after (- (point) 2)) (string-to-char TeX-esc)))
|
|
2456 (progn
|
|
2457 (setq single nil)
|
|
2458 (if (and (> pos 2) (= (char-after (- pos 2)) TeX-dollar-sign))
|
|
2459 (setq pt (1- pos)) ; Doesn't echo 3rd $, if $$ already
|
|
2460 (backward-char 1)
|
|
2461 (insert TeX-dollar-sign)
|
|
2462 (goto-char (1+ pos))))
|
|
2463 (insert TeX-dollar-sign))
|
|
2464 (setq TeX-dollar-list
|
|
2465 (TeX-locate-delimiter pt TeX-dollar-sign TeX-dollar-list))
|
|
2466 (if TeX-symbol-marker
|
|
2467 (save-excursion
|
|
2468 (goto-char TeX-symbol-marker-pos)
|
|
2469 (if (and (= (preceding-char) TeX-dollar-sign)
|
|
2470 (/= (char-after (- (point) 2)) TeX-dollar-sign))
|
|
2471 (progn
|
|
2472 (backward-char 1)
|
|
2473 (if single
|
|
2474 (save-excursion
|
|
2475 (goto-char pos)
|
|
2476 (insert TeX-dollar-sign)))) ; $$foo$`$'
|
|
2477 (if (not single)
|
|
2478 (progn
|
|
2479 (insert TeX-dollar-sign) ; `$'$foo$$
|
|
2480 (backward-char 1))))
|
|
2481 (TeX-bouncing-point (if single 1 2))))))))
|
|
2482
|
|
2483 ;;; Simple Commands
|
|
2484
|
|
2485 (defun TeX-normal-mode (arg)
|
|
2486 "Remove all information about this buffer, and apply the style hooks again.
|
|
2487 Save buffer first including style information.
|
|
2488 With optional argument, also reload the style hooks."
|
|
2489 (interactive "*P")
|
|
2490 (if arg
|
|
2491 (setq TeX-style-hook-list nil
|
|
2492 BibTeX-global-style-files nil
|
|
2493 BibTeX-global-files nil
|
|
2494 TeX-global-input-files nil))
|
|
2495 (let ((TeX-auto-save t))
|
|
2496 (if (buffer-modified-p)
|
|
2497 (save-buffer)
|
|
2498 (TeX-auto-write)))
|
|
2499 (normal-mode)
|
|
2500 (TeX-update-style))
|
|
2501
|
|
2502 (defvar TeX-open-quote "``"
|
|
2503 "*String inserted by typing \\[TeX-insert-quote] to open a quotation.")
|
|
2504
|
|
2505 (defvar TeX-close-quote "''"
|
|
2506 "*String inserted by typing \\[TeX-insert-quote] to close a quotation.")
|
|
2507
|
|
2508 (defvar TeX-quote-after-quote nil
|
|
2509 "*Behaviour of \\[TeX-insert-quote]. Nil means standard behaviour;
|
|
2510 when non-nil, opening and closing quotes are inserted only after \".")
|
|
2511
|
|
2512 ;;;###autoload
|
|
2513 (defun TeX-insert-quote (arg)
|
|
2514 "Insert the appropriate quote marks for TeX.
|
|
2515 Inserts the value of `TeX-open-quote' (normally ``) or `TeX-close-quote'
|
|
2516 \(normally '') depending on the context. If `TeX-quote-after-quote'
|
|
2517 is non-nil, this insertion works only after \".
|
|
2518 With prefix argument, always inserts \" characters."
|
|
2519 (interactive "*P")
|
|
2520 (if arg
|
|
2521 (self-insert-command (prefix-numeric-value arg))
|
|
2522 (TeX-update-style)
|
|
2523 (if TeX-quote-after-quote
|
|
2524 (insert (cond ((bobp)
|
|
2525 ?\")
|
|
2526 ((not (= (preceding-char) ?\"))
|
|
2527 ?\")
|
|
2528 ((save-excursion
|
|
2529 (forward-char -1)
|
|
2530 (bobp))
|
|
2531 (delete-backward-char 1)
|
|
2532 TeX-open-quote)
|
|
2533 ((save-excursion
|
|
2534 (forward-char -2) ;;; at -1 there is double quote
|
|
2535 (looking-at "[ \t\n]\\|\\s("))
|
|
2536 (delete-backward-char 1)
|
|
2537 TeX-open-quote)
|
|
2538 (t
|
|
2539 (delete-backward-char 1)
|
|
2540 TeX-close-quote)))
|
|
2541 (insert (cond ((bobp)
|
|
2542 TeX-open-quote)
|
|
2543 ((= (preceding-char) (string-to-char TeX-esc))
|
|
2544 ?\")
|
|
2545 ((= (preceding-char) ?\")
|
|
2546 ?\")
|
|
2547 ((save-excursion
|
|
2548 (forward-char (- (length TeX-open-quote)))
|
|
2549 (looking-at (regexp-quote TeX-open-quote)))
|
|
2550 (delete-backward-char (length TeX-open-quote))
|
|
2551 ?\")
|
|
2552 ((save-excursion
|
|
2553 (forward-char (- (length TeX-close-quote)))
|
|
2554 (looking-at (regexp-quote TeX-close-quote)))
|
|
2555 (delete-backward-char (length TeX-close-quote))
|
|
2556 ?\")
|
|
2557 ((save-excursion
|
|
2558 (forward-char -1)
|
|
2559 (looking-at "[ \t\n]\\|\\s("))
|
|
2560 TeX-open-quote)
|
|
2561 (t
|
|
2562 TeX-close-quote))))))
|
|
2563
|
|
2564 ;; For the sake of BibTeX...
|
|
2565 ;;; Do not ;;;###autoload because of conflict with standard tex-mode.el.
|
|
2566 (fset 'tex-insert-quote 'TeX-insert-quote)
|
|
2567
|
|
2568 (defun TeX-insert-punctuation ()
|
|
2569 "Insert point or comma, cleaning up preceding space."
|
|
2570 (interactive)
|
|
2571 (if (TeX-looking-at-backward "\\\\/\\(}+\\)" 50)
|
|
2572 (replace-match "\\1" t))
|
|
2573 (call-interactively 'self-insert-command))
|
|
2574
|
|
2575 (defun TeX-insert-braces (arg)
|
|
2576 "Make a pair of braces around next ARG sexps and leave point inside.
|
|
2577 No argument is equivalent to zero: just insert braces and leave point
|
|
2578 between."
|
|
2579 (interactive "P")
|
|
2580 (insert TeX-grop)
|
|
2581 (save-excursion
|
|
2582 (if arg (forward-sexp (prefix-numeric-value arg)))
|
|
2583 (insert TeX-grcl)))
|
|
2584
|
|
2585 (defun TeX-goto-info-page ()
|
|
2586 "Read documentation for AUC TeX in the info system."
|
|
2587 (interactive)
|
|
2588 (require 'info)
|
|
2589 (Info-goto-node "(auctex)"))
|
|
2590
|
|
2591 ;;;###autoload
|
|
2592 (defun TeX-submit-bug-report ()
|
|
2593 "Submit via mail a bug report on AUC TeX"
|
|
2594 (interactive)
|
|
2595 (require 'reporter)
|
|
2596 (reporter-submit-bug-report
|
|
2597 "auc-tex@iesd.auc.dk"
|
|
2598 (concat "AUC TeX " AUC-TeX-version)
|
|
2599 (list 'window-system
|
|
2600 'LaTeX-version
|
|
2601 'TeX-style-path
|
|
2602 'TeX-auto-save
|
|
2603 'TeX-parse-self
|
|
2604 'TeX-master)
|
|
2605 nil nil
|
|
2606 "Remember to cover the basics, that is, what you expected to happen and
|
|
2607 what in fact did happen."))
|
|
2608
|
|
2609 ;;; Ispell Support
|
|
2610
|
|
2611 ;; The FSF ispell.el use this.
|
|
2612 (defun ispell-tex-buffer-p ()
|
|
2613 (and (boundp 'ispell-tex-p) ispell-tex-p))
|
|
2614
|
|
2615 ;; The FSF ispell.el might one day use this.
|
|
2616 (setq ispell-enable-tex-parser t)
|
|
2617
|
|
2618 (defun TeX-run-ispell (command string file)
|
|
2619 "Run ispell on current TeX buffer."
|
|
2620 (cond ((and (string-equal file (TeX-region-file))
|
|
2621 (fboundp 'ispell-region))
|
|
2622 (call-interactively 'ispell-region))
|
|
2623 ((string-equal file (TeX-region-file))
|
|
2624 (call-interactively 'spell-region))
|
|
2625 ((fboundp 'ispell-buffer)
|
|
2626 (ispell-buffer))
|
|
2627 ((fboundp 'ispell)
|
|
2628 (ispell))
|
|
2629 (t
|
|
2630 (spell-buffer))))
|
|
2631
|
|
2632 ;; Some versions of ispell 3 use this.
|
|
2633 (defvar ispell-tex-major-modes nil)
|
|
2634 (setq ispell-tex-major-modes
|
|
2635 (append '(plain-tex-mode ams-tex-mode latex-mode)
|
|
2636 ispell-tex-major-modes))
|
|
2637
|
|
2638 (provide 'tex)
|
|
2639
|
|
2640 ;;; tex.el ends here
|