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