38412
|
1 ;;; tex-mode.el --- TeX, LaTeX, and SliTeX mode commands
|
657
|
2
|
24330
|
3 ;; Copyright (C) 1985, 86, 89, 92, 94, 95, 96, 97, 98, 1999
|
17435
|
4 ;; Free Software Foundation, Inc.
|
840
|
5
|
10215
|
6 ;; Maintainer: FSF
|
814
|
7 ;; Keywords: tex
|
807
|
8
|
739
|
9 ;; Contributions over the years by William F. Schelter, Dick King,
|
10215
|
10 ;; Stephen Gildea, Michael Prange, Jacob Gore, and Edward M. Reingold.
|
739
|
11
|
85
|
12 ;; This file is part of GNU Emacs.
|
|
13
|
|
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
15 ;; it under the terms of the GNU General Public License as published by
|
807
|
16 ;; the Free Software Foundation; either version 2, or (at your option)
|
85
|
17 ;; any later version.
|
|
18
|
|
19 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 ;; GNU General Public License for more details.
|
|
23
|
|
24 ;; You should have received a copy of the GNU General Public License
|
14383
|
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
27 ;; Boston, MA 02111-1307, USA.
|
85
|
28
|
38412
|
29 ;;; Commentary:
|
|
30
|
807
|
31 ;;; Code:
|
|
32
|
24273
|
33 ;; Pacify the byte-compiler
|
|
34 (eval-when-compile
|
|
35 (require 'compare-w)
|
32479
|
36 (require 'cl)
|
24273
|
37 (require 'skeleton))
|
|
38
|
6632
652dc23b83fd
(tex-start-shell): Use shell-mode-map (instead of comint-mode-map) because
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
39 (require 'shell)
|
2576
48318133e7a6
(tex-compilation-parse-errors): Added. At the moment, this would have
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
40 (require 'compile)
|
739
|
41
|
17435
|
42 (defgroup tex-file nil
|
|
43 "TeX files and directories"
|
|
44 :prefix "tex-"
|
|
45 :group 'tex)
|
|
46
|
|
47 (defgroup tex-run nil
|
|
48 "Running external commands from TeX mode"
|
|
49 :prefix "tex-"
|
|
50 :group 'tex)
|
|
51
|
|
52 (defgroup tex-view nil
|
|
53 "Viewing and printing TeX files"
|
|
54 :prefix "tex-"
|
|
55 :group 'tex)
|
85
|
56
|
957
|
57 ;;;###autoload
|
17435
|
58 (defcustom tex-shell-file-name nil
|
|
59 "*If non-nil, the shell file name to run in the subshell used to run TeX."
|
|
60 :type '(choice (const :tag "None" nil)
|
|
61 string)
|
|
62 :group 'tex-run)
|
|
63
|
|
64 ;;;###autoload
|
|
65 (defcustom tex-directory "."
|
15916
|
66 "*Directory in which temporary files are written.
|
7285
|
67 You can make this `/tmp' if your TEXINPUTS has no relative directories in it
|
739
|
68 and you don't try to apply \\[tex-region] or \\[tex-buffer] when there are
|
17435
|
69 `\\input' commands with relative directories."
|
|
70 :type 'directory
|
|
71 :group 'tex-file)
|
739
|
72
|
957
|
73 ;;;###autoload
|
17435
|
74 (defcustom tex-first-line-header-regexp nil
|
16777
|
75 "Regexp for matching a first line which `tex-region' should include.
|
|
76 If this is non-nil, it should be a regular expression string;
|
|
77 if it matches the first line of the file,
|
17435
|
78 `tex-region' always includes the first line in the TeX run."
|
|
79 :type '(choice (const :tag "None" nil)
|
|
80 regexp)
|
|
81 :group 'tex-file)
|
16777
|
82
|
|
83 ;;;###autoload
|
17435
|
84 (defcustom tex-main-file nil
|
15916
|
85 "*The main TeX source file which includes this buffer's file.
|
22847
|
86 The command `tex-file' runs TeX on the file specified by `tex-main-file'
|
|
87 if the variable is non-nil."
|
17435
|
88 :type '(choice (const :tag "None" nil)
|
|
89 file)
|
|
90 :group 'tex-file)
|
15916
|
91
|
|
92 ;;;###autoload
|
17435
|
93 (defcustom tex-offer-save t
|
|
94 "*If non-nil, ask about saving modified buffers before \\[tex-file] is run."
|
|
95 :type 'boolean
|
|
96 :group 'tex-file)
|
85
|
97
|
957
|
98 ;;;###autoload
|
17435
|
99 (defcustom tex-run-command "tex"
|
85
|
100 "*Command used to run TeX subjob.
|
24330
|
101 TeX Mode sets `tex-command' to this string.
|
|
102 See the documentation of that variable."
|
17435
|
103 :type 'string
|
|
104 :group 'tex-run)
|
85
|
105
|
957
|
106 ;;;###autoload
|
17435
|
107 (defcustom latex-run-command "latex"
|
85
|
108 "*Command used to run LaTeX subjob.
|
24330
|
109 LaTeX Mode sets `tex-command' to this string.
|
|
110 See the documentation of that variable."
|
17435
|
111 :type 'string
|
|
112 :group 'tex-run)
|
739
|
113
|
24273
|
114 ;;;###autoload
|
|
115 (defcustom slitex-run-command "slitex"
|
|
116 "*Command used to run SliTeX subjob.
|
24330
|
117 SliTeX Mode sets `tex-command' to this string.
|
|
118 See the documentation of that variable."
|
24273
|
119 :type 'string
|
|
120 :group 'tex-run)
|
|
121
|
24330
|
122 ;;;###autoload
|
|
123 (defcustom tex-start-options-string "\\nonstopmode\\input"
|
24273
|
124 "*TeX options to use when running TeX.
|
24330
|
125 These precede the input file name. If nil, TeX runs without option.
|
|
126 See the documentation of `tex-command'."
|
|
127 :type '(radio (const :tag "Interactive \(nil\)" nil)
|
|
128 (const :tag "Nonstop \(\"\\nonstopmode\\input\"\)"
|
|
129 "\\nonstopmode\\input")
|
|
130 (string :tag "String at your choice"))
|
24273
|
131 :group 'tex-run
|
|
132 :version "20.4")
|
|
133
|
739
|
134 (defvar standard-latex-block-names
|
33363
|
135 '("abstract" "array" "center" "description"
|
|
136 "displaymath" "document" "enumerate" "eqnarray"
|
|
137 "eqnarray*" "equation" "figure" "figure*"
|
|
138 "flushleft" "flushright" "itemize" "letter"
|
|
139 "list" "minipage" "picture" "quotation"
|
|
140 "quote" "slide" "sloppypar" "tabbing"
|
|
141 "table" "table*" "tabular" "tabular*"
|
|
142 "thebibliography" "theindex*" "titlepage" "trivlist"
|
|
143 "verbatim" "verbatim*" "verse" "math")
|
739
|
144 "Standard LaTeX block names.")
|
|
145
|
957
|
146 ;;;###autoload
|
17435
|
147 (defcustom latex-block-names nil
|
739
|
148 "*User defined LaTeX block names.
|
17435
|
149 Combined with `standard-latex-block-names' for minibuffer completion."
|
|
150 :type '(repeat string)
|
|
151 :group 'tex-run)
|
85
|
152
|
957
|
153 ;;;###autoload
|
17435
|
154 (defcustom tex-bibtex-command "bibtex"
|
739
|
155 "*Command used by `tex-bibtex-file' to gather bibliographic data.
|
7285
|
156 If this string contains an asterisk (`*'), that is replaced by the file name;
|
17435
|
157 otherwise, the file name, preceded by blank, is added at the end."
|
|
158 :type 'string
|
|
159 :group 'tex-run)
|
85
|
160
|
957
|
161 ;;;###autoload
|
17435
|
162 (defcustom tex-dvi-print-command "lpr -d"
|
739
|
163 "*Command used by \\[tex-print] to print a .dvi file.
|
7285
|
164 If this string contains an asterisk (`*'), that is replaced by the file name;
|
17435
|
165 otherwise, the file name, preceded by blank, is added at the end."
|
|
166 :type 'string
|
|
167 :group 'tex-view)
|
739
|
168
|
957
|
169 ;;;###autoload
|
17435
|
170 (defcustom tex-alt-dvi-print-command "lpr -d"
|
739
|
171 "*Command used by \\[tex-print] with a prefix arg to print a .dvi file.
|
7285
|
172 If this string contains an asterisk (`*'), that is replaced by the file name;
|
|
173 otherwise, the file name, preceded by blank, is added at the end.
|
739
|
174
|
7285
|
175 If two printers are not enough of a choice, you can set the variable
|
|
176 `tex-alt-dvi-print-command' to an expression that asks what you want;
|
739
|
177 for example,
|
|
178
|
|
179 (setq tex-alt-dvi-print-command
|
|
180 '(format \"lpr -P%s\" (read-string \"Use printer: \")))
|
|
181
|
|
182 would tell \\[tex-print] with a prefix argument to ask you which printer to
|
17435
|
183 use."
|
|
184 :type '(choice (string :tag "Command")
|
|
185 (sexp :tag "Expression"))
|
|
186 :group 'tex-view)
|
85
|
187
|
957
|
188 ;;;###autoload
|
17435
|
189 (defcustom tex-dvi-view-command nil
|
7285
|
190 "*Command used by \\[tex-view] to display a `.dvi' file.
|
|
191 If this string contains an asterisk (`*'), that is replaced by the file name;
|
|
192 otherwise, the file name, preceded by blank, is added at the end.
|
739
|
193
|
|
194 This can be set conditionally so that the previewer used is suitable for the
|
|
195 window system being used. For example,
|
|
196
|
|
197 (setq tex-dvi-view-command
|
|
198 (if (eq window-system 'x) \"xdvi\" \"dvi2tty * | cat -s\"))
|
|
199
|
7285
|
200 would tell \\[tex-view] to use xdvi under X windows and to use dvi2tty
|
17435
|
201 otherwise."
|
|
202 :type '(choice (const nil) string)
|
|
203 :group 'tex-view)
|
85
|
204
|
957
|
205 ;;;###autoload
|
17435
|
206 (defcustom tex-show-queue-command "lpq"
|
739
|
207 "*Command used by \\[tex-show-print-queue] to show the print queue.
|
17435
|
208 Should show the queue(s) that \\[tex-print] puts jobs on."
|
|
209 :type 'string
|
|
210 :group 'tex-view)
|
85
|
211
|
957
|
212 ;;;###autoload
|
26270
|
213 (defcustom tex-default-mode 'latex-mode
|
85
|
214 "*Mode to enter for a new file that might be either TeX or LaTeX.
|
|
215 This variable is used when it can't be determined whether the file
|
|
216 is plain TeX or LaTeX or what because the file contains no commands.
|
17435
|
217 Normally set to either `plain-tex-mode' or `latex-mode'."
|
|
218 :type 'function
|
|
219 :group 'tex)
|
85
|
220
|
957
|
221 ;;;###autoload
|
17435
|
222 (defcustom tex-open-quote "``"
|
|
223 "*String inserted by typing \\[tex-insert-quote] to open a quotation."
|
|
224 :type 'string
|
|
225 :group 'tex)
|
85
|
226
|
957
|
227 ;;;###autoload
|
17435
|
228 (defcustom tex-close-quote "''"
|
|
229 "*String inserted by typing \\[tex-insert-quote] to close a quotation."
|
|
230 :type 'string
|
|
231 :group 'tex)
|
85
|
232
|
739
|
233 (defvar tex-last-temp-file nil
|
|
234 "Latest temporary file generated by \\[tex-region] and \\[tex-buffer].
|
|
235 Deleted when the \\[tex-region] or \\[tex-buffer] is next run, or when the
|
7285
|
236 tex shell terminates.")
|
739
|
237
|
85
|
238 (defvar tex-command nil
|
24330
|
239 "*Command to run TeX.
|
|
240 If this string contains an asterisk \(`*'\), that is replaced by the file name\;
|
|
241 otherwise the \(shell-quoted\) value of `tex-start-options-string' and
|
|
242 the file name are added at the end, with blanks as separators.
|
|
243
|
|
244 In TeX, LaTeX, and SliTeX Mode this variable becomes buffer local.
|
|
245 In these modes, use \\[set-variable] if you want to change it for the
|
|
246 current buffer.")
|
85
|
247
|
|
248 (defvar tex-trailer nil
|
|
249 "String appended after the end of a region sent to TeX by \\[tex-region].")
|
|
250
|
|
251 (defvar tex-start-of-header nil
|
13248
|
252 "Regular expression used by \\[tex-region] to find start of file's header.")
|
85
|
253
|
|
254 (defvar tex-end-of-header nil
|
13248
|
255 "Regular expression used by \\[tex-region] to find end of file's header.")
|
85
|
256
|
|
257 (defvar tex-shell-cd-command "cd"
|
|
258 "Command to give to shell running TeX to change directory.
|
7285
|
259 The value of `tex-directory' is appended to this, separated by a space.")
|
85
|
260
|
|
261 (defvar tex-zap-file nil
|
|
262 "Temporary file name used for text being sent as input to TeX.
|
|
263 Should be a simple file name with no extension or directory specification.")
|
|
264
|
|
265 (defvar tex-last-buffer-texed nil
|
|
266 "Buffer which was last TeXed.")
|
|
267
|
|
268 (defvar tex-print-file nil
|
|
269 "File name that \\[tex-print] prints.
|
|
270 Set by \\[tex-region], \\[tex-buffer], and \\[tex-file].")
|
|
271
|
32479
|
272 (easy-mmode-defsyntax tex-mode-syntax-table
|
|
273 '((?% . "<")
|
|
274 (?\n . ">")
|
|
275 (?\f . ">")
|
|
276 (?\C-@ . "w")
|
|
277 (?' . "w")
|
|
278 (?@ . "_")
|
|
279 (?* . "_")
|
|
280 (?\t . " ")
|
|
281 (?~ . " ")
|
|
282 (?$ . "$$")
|
|
283 (?\\ . "/")
|
|
284 (?\" . ".")
|
|
285 (?& . ".")
|
37896
|
286 (?_ . ".")
|
|
287 (?^ . "."))
|
85
|
288 "Syntax table used while in TeX mode.")
|
32045
|
289
|
|
290 ;;;;
|
|
291 ;;;; Imenu support
|
|
292 ;;;;
|
85
|
293
|
31968
|
294 (defcustom latex-imenu-indent-string ". "
|
18393
|
295 "*String to add repeated in front of nested sectional units for Imenu.
|
|
296 An alternative value is \" . \", if you use a font with a narrow period."
|
|
297 :type 'string
|
|
298 :group 'tex)
|
|
299
|
31968
|
300 (defvar latex-section-alist
|
|
301 '(("part" . 0) ("chapter" . 1)
|
|
302 ("section" . 2) ("subsection" . 3)
|
|
303 ("subsubsection" . 4)
|
|
304 ("paragraph" . 5) ("subparagraph" . 6)))
|
|
305
|
32045
|
306 (defvar latex-metasection-list
|
|
307 '("documentstyle" "documentclass"
|
|
308 "begin{document}" "end{document}"
|
|
309 "appendix" "frontmatter" "mainmatter" "backmatter"))
|
|
310
|
15240
|
311 (defun latex-imenu-create-index ()
|
32045
|
312 "Generate an alist for imenu from a LaTeX buffer."
|
|
313 (let ((section-regexp
|
|
314 (concat "\\\\" (regexp-opt (mapcar 'car latex-section-alist) t)
|
|
315 "\\*?[ \t]*{"))
|
|
316 (metasection-regexp
|
|
317 (concat "\\\\" (regexp-opt latex-metasection-list t)))
|
|
318 i0 menu case-fold-search)
|
18393
|
319 (save-excursion
|
|
320 ;; Find the top-most level in this file but don't allow it to be
|
|
321 ;; any deeper than "section" (which is top-level in an article).
|
|
322 (goto-char (point-min))
|
|
323 (if (search-forward-regexp "\\\\part\\*?[ \t]*{" nil t)
|
|
324 (setq i0 0)
|
|
325 (if (search-forward-regexp "\\\\chapter\\*?[ \t]*{" nil t)
|
|
326 (setq i0 1)
|
|
327 (setq i0 2)))
|
|
328
|
|
329 ;; Look for chapters and sections.
|
|
330 (goto-char (point-min))
|
32045
|
331 (while (search-forward-regexp section-regexp nil t)
|
18393
|
332 (let ((start (match-beginning 0))
|
|
333 (here (point))
|
|
334 (i (cdr (assoc (buffer-substring-no-properties
|
|
335 (match-beginning 1)
|
|
336 (match-end 1))
|
31968
|
337 latex-section-alist))))
|
18393
|
338 (backward-char 1)
|
|
339 (condition-case err
|
|
340 (progn
|
|
341 ;; Using sexps allows some use of matching {...} inside
|
|
342 ;; titles.
|
|
343 (forward-sexp 1)
|
31968
|
344 (push (cons (concat (apply 'concat
|
|
345 (make-list
|
|
346 (max 0 (- i i0))
|
|
347 latex-imenu-indent-string))
|
|
348 (buffer-substring-no-properties
|
|
349 here (1- (point))))
|
|
350 start)
|
|
351 menu))
|
18393
|
352 (error nil))))
|
|
353
|
|
354 ;; Look for included material.
|
|
355 (goto-char (point-min))
|
|
356 (while (search-forward-regexp
|
|
357 "\\\\\\(include\\|input\\|verbatiminput\\|bibliography\\)\
|
32045
|
358 \[ \t]*{\\([^}\n]+\\)}"
|
18393
|
359 nil t)
|
32045
|
360 (push (cons (concat "<<" (buffer-substring-no-properties
|
|
361 (match-beginning 2)
|
|
362 (match-end 2))
|
|
363 (if (= (char-after (match-beginning 1)) ?b)
|
|
364 ".bbl"
|
|
365 ".tex"))
|
|
366 (match-beginning 0))
|
|
367 menu))
|
18393
|
368
|
|
369 ;; Look for \frontmatter, \mainmatter, \backmatter, and \appendix.
|
|
370 (goto-char (point-min))
|
32045
|
371 (while (search-forward-regexp metasection-regexp nil t)
|
|
372 (push (cons "--" (match-beginning 0)) menu))
|
18393
|
373
|
|
374 ;; Sort in increasing buffer position order.
|
|
375 (sort menu (function (lambda (a b) (< (cdr a) (cdr b))))))))
|
32045
|
376
|
|
377 ;;;;
|
|
378 ;;;; Outline support
|
|
379 ;;;;
|
12704
|
380
|
32045
|
381 (defvar latex-outline-regexp
|
|
382 (concat "\\\\"
|
|
383 (regexp-opt (append latex-metasection-list
|
|
384 (mapcar 'car latex-section-alist)) t)))
|
|
385
|
|
386 (defun latex-outline-level ()
|
|
387 (if (looking-at latex-outline-regexp)
|
|
388 (1+ (or (cdr (assoc (match-string 1) latex-section-alist)) -1))
|
|
389 1000))
|
|
390
|
|
391 ;;;;
|
|
392 ;;;; Font-Lock support
|
|
393 ;;;;
|
|
394
|
|
395 ;(defvar tex-font-lock-keywords
|
|
396 ; ;; Regexps updated with help from Ulrik Dickow <dickow@nbi.dk>.
|
|
397 ; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
|
|
398 ; 2 font-lock-function-name-face)
|
|
399 ; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
|
|
400 ; 2 font-lock-constant-face)
|
|
401 ; ;; It seems a bit dubious to use `bold' and `italic' faces since we might
|
|
402 ; ;; not be able to display those fonts.
|
|
403 ; ("{\\\\bf\\([^}]+\\)}" 1 'bold keep)
|
|
404 ; ("{\\\\\\(em\\|it\\|sl\\)\\([^}]+\\)}" 2 'italic keep)
|
|
405 ; ("\\\\\\([a-zA-Z@]+\\|.\\)" . font-lock-keyword-face)
|
|
406 ; ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face keep))
|
|
407 ; ;; Rewritten and extended for LaTeX2e by Ulrik Dickow <dickow@nbi.dk>.
|
|
408 ; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
|
|
409 ; 2 font-lock-function-name-face)
|
|
410 ; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
|
|
411 ; 2 font-lock-constant-face)
|
|
412 ; ("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face)
|
|
413 ; "\\\\\\([a-zA-Z@]+\\|.\\)"
|
|
414 ; ;; It seems a bit dubious to use `bold' and `italic' faces since we might
|
|
415 ; ;; not be able to display those fonts.
|
|
416 ; ;; LaTeX2e: \emph{This is emphasized}.
|
|
417 ; ("\\\\emph{\\([^}]+\\)}" 1 'italic keep)
|
|
418 ; ;; LaTeX2e: \textbf{This is bold}, \textit{...}, \textsl{...}
|
|
419 ; ("\\\\text\\(\\(bf\\)\\|it\\|sl\\){\\([^}]+\\)}"
|
|
420 ; 3 (if (match-beginning 2) 'bold 'italic) keep)
|
|
421 ; ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for tables.
|
|
422 ; ("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)"
|
|
423 ; 3 (if (match-beginning 2) 'bold 'italic) keep))
|
|
424
|
|
425 ;; Rewritten with the help of Alexandra Bac <abac@welcome.disi.unige.it>.
|
|
426 (defconst tex-font-lock-keywords-1
|
|
427 (eval-when-compile
|
|
428 (let* (;; Names of commands whose arg should be fontified as heading, etc.
|
|
429 (headings (regexp-opt
|
|
430 '("title" "begin" "end" "chapter" "part"
|
|
431 "section" "subsection" "subsubsection"
|
|
432 "paragraph" "subparagraph" "subsubparagraph"
|
|
433 "newcommand" "renewcommand" "newenvironment"
|
|
434 "newtheorem")
|
|
435 t))
|
|
436 (variables (regexp-opt
|
|
437 '("newcounter" "newcounter*" "setcounter" "addtocounter"
|
|
438 "setlength" "addtolength" "settowidth")
|
|
439 t))
|
|
440 (includes (regexp-opt
|
|
441 '("input" "include" "includeonly" "bibliography"
|
|
442 "epsfig" "psfig" "epsf" "nofiles" "usepackage"
|
37896
|
443 "documentstyle" "documentclass" "verbatiminput"
|
32045
|
444 "includegraphics" "includegraphics*")
|
|
445 t))
|
|
446 ;; Miscellany.
|
|
447 (slash "\\\\")
|
37896
|
448 (opt " *\\(\\[[^]]*\\] *\\)*")
|
|
449 ;; This would allow highlighting \newcommand\CMD but requires
|
|
450 ;; adapting subgroup numbers below.
|
|
451 ;; (arg "\\(?:{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)\\|\\\\[a-z*]+\\)"))
|
33789
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
452 (arg "{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)"))
|
32045
|
453 (list
|
|
454 ;; Heading args.
|
|
455 (list (concat slash headings "\\*?" opt arg)
|
33472
|
456 ;; If ARG ends up matching too much (if the {} don't match, f.ex)
|
|
457 ;; jit-lock will do funny things: when updating the buffer
|
|
458 ;; the re-highlighting is only done locally so it will just
|
|
459 ;; match the local line, but defer-contextually will
|
|
460 ;; match more lines at a time, so ARG will end up matching
|
|
461 ;; a lot more, which might suddenly include a comment
|
|
462 ;; so you get things highlighted bold when you type them
|
|
463 ;; but they get turned back to normal a little while later
|
|
464 ;; because "there's already a face there".
|
|
465 ;; Using `keep' works around this un-intuitive behavior as well
|
37896
|
466 ;; as improves the behavior in the very rare case where you do
|
|
467 ;; have a comment in ARG.
|
33472
|
468 3 'font-lock-function-name-face 'keep)
|
37896
|
469 (list (concat slash "\\(re\\)?newcommand\\** *\\(\\\\[A-Za-z@]+\\)")
|
|
470 2 'font-lock-function-name-face 'keep)
|
32045
|
471 ;; Variable args.
|
37896
|
472 (list (concat slash variables " *" arg) 2 'font-lock-variable-name-face)
|
32045
|
473 ;; Include args.
|
|
474 (list (concat slash includes opt arg) 3 'font-lock-builtin-face)
|
|
475 ;; Definitions. I think.
|
37896
|
476 '("^[ \t]*\\\\def *\\\\\\(\\(\\w\\|@\\)+\\)"
|
33472
|
477 1 font-lock-function-name-face))))
|
32045
|
478 "Subdued expressions to highlight in TeX modes.")
|
|
479
|
|
480 (defconst tex-font-lock-keywords-2
|
|
481 (append tex-font-lock-keywords-1
|
|
482 (eval-when-compile
|
|
483 (let* (;;
|
|
484 ;; Names of commands whose arg should be fontified with fonts.
|
33789
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
485 (bold (regexp-opt '("textbf" "textsc" "textup"
|
32045
|
486 "boldsymbol" "pmb") t))
|
33789
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
487 (italic (regexp-opt '("textit" "textsl" "emph") t))
|
32045
|
488 (type (regexp-opt '("texttt" "textmd" "textrm" "textsf") t))
|
|
489 ;;
|
|
490 ;; Names of commands whose arg should be fontified as a citation.
|
|
491 (citations (regexp-opt
|
|
492 '("label" "ref" "pageref" "vref" "eqref"
|
37896
|
493 "cite" "nocite" "index" "glossary" "bibitem"
|
33789
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
494 ;; These are text, rather than citations.
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
495 ;; "caption" "footnote" "footnotemark" "footnotetext"
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
496 )
|
32045
|
497 t))
|
|
498 ;;
|
|
499 ;; Names of commands that should be fontified.
|
|
500 (specials (regexp-opt
|
37896
|
501 '("\\" "\\*" ;; "-"
|
32045
|
502 "linebreak" "nolinebreak" "pagebreak" "nopagebreak"
|
|
503 "newline" "newpage" "clearpage" "cleardoublepage"
|
|
504 "displaybreak" "allowdisplaybreaks" "enlargethispage")
|
|
505 t))
|
|
506 (general "\\([a-zA-Z@]+\\**\\|[^ \t\n]\\)")
|
|
507 ;;
|
|
508 ;; Miscellany.
|
|
509 (slash "\\\\")
|
37896
|
510 (opt " *\\(\\[[^]]*\\] *\\)*")
|
33789
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
511 (arg "{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)"))
|
32045
|
512 (list
|
|
513 ;;
|
|
514 ;; Citation args.
|
|
515 (list (concat slash citations opt arg) 3 'font-lock-constant-face)
|
|
516 ;;
|
37896
|
517 ;; Text between `` quotes ''.
|
|
518 (cons (concat (regexp-opt `("``" "\"<" "\"`" "<<" "��") t)
|
|
519 "[^'\">��]+" ;a bit pessimistic
|
|
520 (regexp-opt `("''" "\">" "\"'" ">>" "��") t))
|
|
521 'font-lock-string-face)
|
|
522 ;;
|
32045
|
523 ;; Command names, special and general.
|
|
524 (cons (concat slash specials) 'font-lock-warning-face)
|
|
525 (concat slash general)
|
|
526 ;;
|
|
527 ;; Font environments. It seems a bit dubious to use `bold' etc. faces
|
|
528 ;; since we might not be able to display those fonts.
|
37896
|
529 (list (concat slash bold " *" arg) 2 '(quote bold) 'append)
|
|
530 (list (concat slash italic " *" arg) 2 '(quote italic) 'append)
|
33789
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
531 ;; (list (concat slash type arg) 2 '(quote bold-italic) 'append)
|
32045
|
532 ;;
|
|
533 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for tables.
|
|
534 (list (concat "\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>"
|
|
535 "\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)")
|
33472
|
536 3 '(if (match-beginning 2) 'bold 'italic) 'append)))))
|
32045
|
537 "Gaudy expressions to highlight in TeX modes.")
|
|
538
|
|
539 (defvar tex-font-lock-keywords tex-font-lock-keywords-1
|
|
540 "Default expressions to highlight in TeX modes.")
|
|
541
|
33472
|
542
|
|
543 (defface tex-math-face
|
|
544 '((t :inherit font-lock-string-face))
|
|
545 "Face used to highlight TeX math expressions.")
|
|
546 (defvar tex-math-face 'tex-math-face)
|
|
547
|
|
548 ;; Use string syntax but math face for $...$.
|
|
549 (defun tex-font-lock-syntactic-face-function (state)
|
|
550 (if (nth 3 state) tex-math-face font-lock-comment-face))
|
|
551
|
32045
|
552
|
85
|
553 (defun tex-define-common-keys (keymap)
|
7285
|
554 "Define the keys that we want defined both in TeX mode and in the TeX shell."
|
85
|
555 (define-key keymap "\C-c\C-k" 'tex-kill-job)
|
|
556 (define-key keymap "\C-c\C-l" 'tex-recenter-output-buffer)
|
|
557 (define-key keymap "\C-c\C-q" 'tex-show-print-queue)
|
|
558 (define-key keymap "\C-c\C-p" 'tex-print)
|
|
559 (define-key keymap "\C-c\C-v" 'tex-view)
|
4900
|
560
|
|
561 (define-key keymap [menu-bar tex] (cons "TeX" (make-sparse-keymap "TeX")))
|
|
562
|
33472
|
563 (define-key keymap [menu-bar tex tex-kill-job]
|
|
564 '(menu-item "Tex Kill" tex-kill-job :enable (tex-shell-running)))
|
4917
|
565 (define-key keymap [menu-bar tex tex-recenter-output-buffer]
|
33472
|
566 '(menu-item "Tex Recenter" tex-recenter-output-buffer
|
|
567 :enable (get-buffer "*tex-shell*")))
|
4900
|
568 (define-key keymap [menu-bar tex tex-show-print-queue]
|
|
569 '("Show Print Queue" . tex-show-print-queue))
|
4917
|
570 (define-key keymap [menu-bar tex tex-alt-print]
|
33472
|
571 '(menu-item "Tex Print (alt printer)" tex-alt-print
|
|
572 :enable (stringp tex-print-file)))
|
|
573 (define-key keymap [menu-bar tex tex-print]
|
|
574 '(menu-item "Tex Print" tex-print :enable (stringp tex-print-file)))
|
|
575 (define-key keymap [menu-bar tex tex-view]
|
|
576 '(menu-item "Tex View" tex-view :enable (stringp tex-print-file))))
|
85
|
577
|
33472
|
578 (defvar tex-mode-map
|
|
579 (let ((map (make-sparse-keymap)))
|
37896
|
580 (set-keymap-parent map text-mode-map)
|
33472
|
581 (tex-define-common-keys map)
|
|
582 (define-key map "\"" 'tex-insert-quote)
|
|
583 (define-key map "(" 'skeleton-pair-insert-maybe)
|
|
584 (define-key map "{" 'skeleton-pair-insert-maybe)
|
|
585 (define-key map "[" 'skeleton-pair-insert-maybe)
|
|
586 (define-key map "$" 'skeleton-pair-insert-maybe)
|
|
587 (define-key map "\n" 'tex-terminate-paragraph)
|
37896
|
588 (define-key map "\t" 'indent-for-tab-command)
|
33472
|
589 (define-key map "\M-\r" 'latex-insert-item)
|
|
590 (define-key map "\C-c}" 'up-list)
|
|
591 (define-key map "\C-c{" 'tex-insert-braces)
|
|
592 (define-key map "\C-c\C-r" 'tex-region)
|
|
593 (define-key map "\C-c\C-b" 'tex-buffer)
|
|
594 (define-key map "\C-c\C-f" 'tex-file)
|
|
595 (define-key map "\C-c\C-i" 'tex-bibtex-file)
|
|
596 (define-key map "\C-c\C-o" 'tex-latex-block)
|
|
597 (define-key map "\C-c\C-e" 'tex-close-latex-block)
|
|
598 (define-key map "\C-c\C-u" 'tex-goto-last-unclosed-latex-block)
|
|
599 (define-key map "\C-c\C-m" 'tex-feed-input)
|
|
600 (define-key map [(control return)] 'tex-feed-input)
|
|
601 (define-key map [menu-bar tex tex-bibtex-file]
|
|
602 '("BibTeX File" . tex-bibtex-file))
|
|
603 (define-key map [menu-bar tex tex-validate-region]
|
|
604 '(menu-item "Validate Region" tex-validate-region :enable mark-active))
|
|
605 (define-key map [menu-bar tex tex-validate-buffer]
|
|
606 '("Validate Buffer" . tex-validate-buffer))
|
|
607 (define-key map [menu-bar tex tex-region]
|
|
608 '(menu-item "TeX Region" tex-region :enable mark-active))
|
|
609 (define-key map [menu-bar tex tex-buffer]
|
|
610 '("TeX Buffer" . tex-buffer))
|
|
611 (define-key map [menu-bar tex tex-file] '("TeX File" . tex-file))
|
|
612 map)
|
37896
|
613 "Keymap shared by TeX modes.")
|
|
614
|
|
615 (defvar latex-mode-map
|
|
616 (let ((map (make-sparse-keymap)))
|
|
617 (set-keymap-parent map tex-mode-map)
|
|
618 map)
|
|
619 "Keymap for `latex-mode'. See also `tex-mode-map'.")
|
|
620
|
|
621 (defvar plain-tex-mode-map
|
|
622 (let ((map (make-sparse-keymap)))
|
|
623 (set-keymap-parent map tex-mode-map)
|
|
624 map)
|
|
625 "Keymap for `plain-tex-mode'. See also `tex-mode-map'.")
|
4917
|
626
|
31968
|
627 (defvar tex-shell-map
|
|
628 (let ((m (make-sparse-keymap)))
|
|
629 (set-keymap-parent m shell-mode-map)
|
|
630 (tex-define-common-keys m)
|
|
631 m)
|
7285
|
632 "Keymap for the TeX shell.
|
10197
|
633 Inherits `shell-mode-map' with a few additions.")
|
85
|
634
|
14383
|
635 (defvar tex-face-alist
|
|
636 '((bold . "{\\bf ")
|
|
637 (italic . "{\\it ")
|
|
638 (bold-italic . "{\\bi ") ; hypothetical
|
|
639 (underline . "\\underline{")
|
|
640 (default . "{\\rm "))
|
|
641 "Alist of face and TeX font name for facemenu.")
|
|
642
|
|
643 (defvar tex-latex-face-alist
|
|
644 `((italic . "{\\em ")
|
|
645 ,@tex-face-alist)
|
|
646 "Alist of face and LaTeX font name for facemenu.")
|
|
647
|
37896
|
648 ;; This would be a lot simpler if we just used a regexp search,
|
|
649 ;; but then it would be too slow.
|
256
|
650 ;;;###autoload
|
85
|
651 (defun tex-mode ()
|
|
652 "Major mode for editing files of input for TeX, LaTeX, or SliTeX.
|
|
653 Tries to determine (by looking at the beginning of the file) whether
|
7285
|
654 this file is for plain TeX, LaTeX, or SliTeX and calls `plain-tex-mode',
|
|
655 `latex-mode', or `slitex-mode', respectively. If it cannot be determined,
|
|
656 such as if there are no commands in the file, the value of `tex-default-mode'
|
|
657 says which mode to use."
|
85
|
658 (interactive)
|
31968
|
659 (let ((mode tex-default-mode) slash comment)
|
85
|
660 (save-excursion
|
|
661 (goto-char (point-min))
|
|
662 (while (and (setq slash (search-forward "\\" nil t))
|
|
663 (setq comment (let ((search-end (point)))
|
|
664 (save-excursion
|
|
665 (beginning-of-line)
|
|
666 (search-forward "%" search-end t))))))
|
33472
|
667 (when (and slash (not comment))
|
|
668 (setq mode
|
|
669 (if (looking-at
|
|
670 (eval-when-compile
|
|
671 (concat
|
|
672 (regexp-opt '("documentstyle" "documentclass"
|
|
673 "begin" "section" "part" "chapter") 'words)
|
|
674 "\\|NeedsTeXFormat{LaTeX")))
|
|
675 (if (looking-at
|
|
676 "document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}")
|
|
677 'slitex-mode
|
|
678 'latex-mode)
|
|
679 'plain-tex-mode))))
|
31968
|
680 (funcall mode)))
|
2598
|
681
|
269
|
682 ;;;###autoload
|
2571
|
683 (defalias 'TeX-mode 'tex-mode)
|
269
|
684 ;;;###autoload
|
24330
|
685 (defalias 'plain-TeX-mode 'plain-tex-mode)
|
|
686 ;;;###autoload
|
2571
|
687 (defalias 'LaTeX-mode 'latex-mode)
|
85
|
688
|
256
|
689 ;;;###autoload
|
31968
|
690 (define-derived-mode plain-tex-mode text-mode "TeX"
|
85
|
691 "Major mode for editing files of input for plain TeX.
|
|
692 Makes $ and } display the characters they match.
|
|
693 Makes \" insert `` when it seems to be the beginning of a quotation,
|
|
694 and '' when it appears to be the end; it inserts \" only after a \\.
|
|
695
|
|
696 Use \\[tex-region] to run TeX on the current region, plus a \"header\"
|
|
697 copied from the top of the file (containing macro definitions, etc.),
|
|
698 running TeX under a special subshell. \\[tex-buffer] does the whole buffer.
|
|
699 \\[tex-file] saves the buffer and then processes the file.
|
|
700 \\[tex-print] prints the .dvi file made by any of these.
|
|
701 \\[tex-view] previews the .dvi file made by any of these.
|
|
702 \\[tex-bibtex-file] runs bibtex on the file of the current buffer.
|
|
703
|
24222
|
704 Use \\[tex-validate-buffer] to check buffer for paragraphs containing
|
85
|
705 mismatched $'s or braces.
|
|
706
|
|
707 Special commands:
|
37896
|
708 \\{plain-tex-mode-map}
|
85
|
709
|
|
710 Mode variables:
|
|
711 tex-run-command
|
|
712 Command string used by \\[tex-region] or \\[tex-buffer].
|
|
713 tex-directory
|
|
714 Directory in which to create temporary files for TeX jobs
|
|
715 run by \\[tex-region] or \\[tex-buffer].
|
|
716 tex-dvi-print-command
|
|
717 Command string used by \\[tex-print] to print a .dvi file.
|
739
|
718 tex-alt-dvi-print-command
|
|
719 Alternative command string used by \\[tex-print] (when given a prefix
|
|
720 argument) to print a .dvi file.
|
85
|
721 tex-dvi-view-command
|
|
722 Command string used by \\[tex-view] to preview a .dvi file.
|
|
723 tex-show-queue-command
|
|
724 Command string used by \\[tex-show-print-queue] to show the print
|
|
725 queue that \\[tex-print] put your job on.
|
|
726
|
7285
|
727 Entering Plain-tex mode runs the hook `text-mode-hook', then the hook
|
|
728 `tex-mode-hook', and finally the hook `plain-tex-mode-hook'. When the
|
|
729 special subshell is initiated, the hook `tex-shell-hook' is run."
|
85
|
730 (tex-common-initialization)
|
|
731 (setq tex-command tex-run-command)
|
13248
|
732 (setq tex-start-of-header "%\\*\\*start of header")
|
|
733 (setq tex-end-of-header "%\\*\\*end of header")
|
85
|
734 (setq tex-trailer "\\bye\n")
|
31968
|
735 (run-hooks 'tex-mode-hook))
|
85
|
736
|
256
|
737 ;;;###autoload
|
31968
|
738 (define-derived-mode latex-mode text-mode "LaTeX"
|
85
|
739 "Major mode for editing files of input for LaTeX.
|
|
740 Makes $ and } display the characters they match.
|
|
741 Makes \" insert `` when it seems to be the beginning of a quotation,
|
|
742 and '' when it appears to be the end; it inserts \" only after a \\.
|
|
743
|
|
744 Use \\[tex-region] to run LaTeX on the current region, plus the preamble
|
|
745 copied from the top of the file (containing \\documentstyle, etc.),
|
|
746 running LaTeX under a special subshell. \\[tex-buffer] does the whole buffer.
|
|
747 \\[tex-file] saves the buffer and then processes the file.
|
|
748 \\[tex-print] prints the .dvi file made by any of these.
|
|
749 \\[tex-view] previews the .dvi file made by any of these.
|
|
750 \\[tex-bibtex-file] runs bibtex on the file of the current buffer.
|
|
751
|
24222
|
752 Use \\[tex-validate-buffer] to check buffer for paragraphs containing
|
85
|
753 mismatched $'s or braces.
|
|
754
|
|
755 Special commands:
|
37896
|
756 \\{latex-mode-map}
|
85
|
757
|
|
758 Mode variables:
|
|
759 latex-run-command
|
|
760 Command string used by \\[tex-region] or \\[tex-buffer].
|
|
761 tex-directory
|
|
762 Directory in which to create temporary files for LaTeX jobs
|
|
763 run by \\[tex-region] or \\[tex-buffer].
|
|
764 tex-dvi-print-command
|
|
765 Command string used by \\[tex-print] to print a .dvi file.
|
739
|
766 tex-alt-dvi-print-command
|
|
767 Alternative command string used by \\[tex-print] (when given a prefix
|
|
768 argument) to print a .dvi file.
|
85
|
769 tex-dvi-view-command
|
|
770 Command string used by \\[tex-view] to preview a .dvi file.
|
|
771 tex-show-queue-command
|
|
772 Command string used by \\[tex-show-print-queue] to show the print
|
|
773 queue that \\[tex-print] put your job on.
|
|
774
|
24273
|
775 Entering Latex mode runs the hook `text-mode-hook', then
|
7285
|
776 `tex-mode-hook', and finally `latex-mode-hook'. When the special
|
|
777 subshell is initiated, `tex-shell-hook' is run."
|
85
|
778 (tex-common-initialization)
|
|
779 (setq tex-command latex-run-command)
|
33363
|
780 (setq tex-start-of-header "\\\\document\\(style\\|class\\)")
|
|
781 (setq tex-end-of-header "\\\\begin\\s-*{document}")
|
|
782 (setq tex-trailer "\\end\\s-*{document}\n")
|
5425
|
783 ;; A line containing just $$ is treated as a paragraph separator.
|
|
784 ;; A line starting with $$ starts a paragraph,
|
|
785 ;; but does not separate paragraphs if it has more stuff on it.
|
31968
|
786 (setq paragraph-start
|
33363
|
787 (concat "[\f%]\\|[ \t]*\\($\\|\\$\\$\\|"
|
31968
|
788 "\\\\[][]\\|"
|
|
789 "\\\\" (regexp-opt (append
|
|
790 (mapcar 'car latex-section-alist)
|
|
791 '("begin" "label" "end"
|
|
792 "item" "bibitem" "newline" "noindent"
|
|
793 "newpage" "footnote" "marginpar"
|
|
794 "parbox" "caption")) t)
|
|
795 "\\>\\|\\\\[a-z]*" (regexp-opt '("space" "skip" "page") t)
|
33363
|
796 "\\>\\)"))
|
31968
|
797 (setq paragraph-separate
|
33363
|
798 (concat "[\f%]\\|[ \t]*\\($\\|"
|
31968
|
799 "\\\\[][]\\|"
|
|
800 "\\\\" (regexp-opt (append
|
|
801 (mapcar 'car latex-section-alist)
|
|
802 '("begin" "label" "end" )) t)
|
|
803 "\\>\\|\\\\\\(" (regexp-opt '("item" "bibitem" "newline"
|
|
804 "noindent" "newpage" "footnote"
|
|
805 "marginpar" "parbox" "caption"))
|
33363
|
806 "\\|\\$\\$\\|[a-z]*\\(space\\|skip\\|page[a-z]*\\)"
|
|
807 "\\>\\)[ \t]*\\($\\|%\\)\\)"))
|
31968
|
808 (set (make-local-variable 'imenu-create-index-function)
|
|
809 'latex-imenu-create-index)
|
|
810 (set (make-local-variable 'tex-face-alist) tex-latex-face-alist)
|
|
811 (set (make-local-variable 'fill-nobreak-predicate)
|
|
812 'latex-fill-nobreak-predicate)
|
32479
|
813 (set (make-local-variable 'indent-line-function) 'latex-indent)
|
33363
|
814 (set (make-local-variable 'fill-indent-according-to-mode) t)
|
31968
|
815 (set (make-local-variable 'outline-regexp) latex-outline-regexp)
|
|
816 (set (make-local-variable 'outline-level) 'latex-outline-level)
|
32045
|
817 (set (make-local-variable 'forward-sexp-function) 'latex-forward-sexp)
|
37896
|
818 (set (make-local-variable 'skeleton-end-hook) nil)
|
31968
|
819 (run-hooks 'tex-mode-hook))
|
85
|
820
|
4768
|
821 ;;;###autoload
|
31968
|
822 (define-derived-mode slitex-mode latex-mode "SliTeX"
|
85
|
823 "Major mode for editing files of input for SliTeX.
|
|
824 Makes $ and } display the characters they match.
|
|
825 Makes \" insert `` when it seems to be the beginning of a quotation,
|
|
826 and '' when it appears to be the end; it inserts \" only after a \\.
|
|
827
|
|
828 Use \\[tex-region] to run SliTeX on the current region, plus the preamble
|
|
829 copied from the top of the file (containing \\documentstyle, etc.),
|
|
830 running SliTeX under a special subshell. \\[tex-buffer] does the whole buffer.
|
|
831 \\[tex-file] saves the buffer and then processes the file.
|
|
832 \\[tex-print] prints the .dvi file made by any of these.
|
|
833 \\[tex-view] previews the .dvi file made by any of these.
|
|
834 \\[tex-bibtex-file] runs bibtex on the file of the current buffer.
|
|
835
|
24222
|
836 Use \\[tex-validate-buffer] to check buffer for paragraphs containing
|
85
|
837 mismatched $'s or braces.
|
|
838
|
|
839 Special commands:
|
37896
|
840 \\{slitex-mode-map}
|
85
|
841
|
|
842 Mode variables:
|
|
843 slitex-run-command
|
|
844 Command string used by \\[tex-region] or \\[tex-buffer].
|
|
845 tex-directory
|
|
846 Directory in which to create temporary files for SliTeX jobs
|
|
847 run by \\[tex-region] or \\[tex-buffer].
|
|
848 tex-dvi-print-command
|
|
849 Command string used by \\[tex-print] to print a .dvi file.
|
739
|
850 tex-alt-dvi-print-command
|
|
851 Alternative command string used by \\[tex-print] (when given a prefix
|
|
852 argument) to print a .dvi file.
|
85
|
853 tex-dvi-view-command
|
|
854 Command string used by \\[tex-view] to preview a .dvi file.
|
|
855 tex-show-queue-command
|
|
856 Command string used by \\[tex-show-print-queue] to show the print
|
|
857 queue that \\[tex-print] put your job on.
|
|
858
|
7285
|
859 Entering SliTeX mode runs the hook `text-mode-hook', then the hook
|
|
860 `tex-mode-hook', then the hook `latex-mode-hook', and finally the hook
|
|
861 `slitex-mode-hook'. When the special subshell is initiated, the hook
|
|
862 `tex-shell-hook' is run."
|
85
|
863 (setq tex-command slitex-run-command)
|
31968
|
864 (setq tex-start-of-header "\\\\documentstyle{slides}\\|\\\\documentclass{slides}"))
|
85
|
865
|
|
866 (defun tex-common-initialization ()
|
32479
|
867 (set-syntax-table tex-mode-syntax-table)
|
18587
|
868 ;; Regexp isearch should accept newline and formfeed as whitespace.
|
31968
|
869 (set (make-local-variable 'search-whitespace-regexp) "[ \t\r\n\f]+")
|
5262
|
870 ;; A line containing just $$ is treated as a paragraph separator.
|
31968
|
871 (set (make-local-variable 'paragraph-start)
|
|
872 "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$")
|
5425
|
873 ;; A line starting with $$ starts a paragraph,
|
|
874 ;; but does not separate paragraphs if it has more stuff on it.
|
31968
|
875 (set (make-local-variable 'paragraph-separate)
|
|
876 "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$[ \t]*$")
|
|
877 (set (make-local-variable 'comment-start) "%")
|
|
878 (set (make-local-variable 'comment-add) 1)
|
|
879 (set (make-local-variable 'comment-start-skip)
|
|
880 "\\(\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\)\\(%+ *\\)")
|
|
881 (set (make-local-variable 'parse-sexp-ignore-comments) t)
|
|
882 (set (make-local-variable 'compare-windows-whitespace)
|
|
883 'tex-categorize-whitespace)
|
|
884 (set (make-local-variable 'facemenu-add-face-function)
|
|
885 (lambda (face end)
|
|
886 (let ((face-text (cdr (assq face tex-face-alist))))
|
|
887 (if face-text
|
|
888 face-text
|
|
889 (error "Face %s not configured for %s mode" face mode-name)))))
|
|
890 (set (make-local-variable 'facemenu-end-add-face) "}")
|
|
891 (set (make-local-variable 'facemenu-remove-face-function) t)
|
|
892 (set (make-local-variable 'font-lock-defaults)
|
|
893 '((tex-font-lock-keywords
|
|
894 tex-font-lock-keywords-1 tex-font-lock-keywords-2)
|
|
895 nil nil ((?$ . "\"")) nil
|
|
896 ;; Who ever uses that anyway ???
|
33472
|
897 (font-lock-mark-block-function . mark-paragraph)
|
|
898 (font-lock-syntactic-face-function
|
|
899 . tex-font-lock-syntactic-face-function)))
|
85
|
900 (make-local-variable 'tex-command)
|
|
901 (make-local-variable 'tex-start-of-header)
|
|
902 (make-local-variable 'tex-end-of-header)
|
|
903 (make-local-variable 'tex-trailer))
|
|
904
|
|
905 (defun tex-categorize-whitespace (backward-limit)
|
|
906 ;; compare-windows-whitespace is set to this.
|
|
907 ;; This is basically a finite-state machine.
|
|
908 ;; Returns a symbol telling how TeX would treat
|
|
909 ;; the whitespace we are looking at: null, space, or par.
|
|
910 (let ((category 'null)
|
|
911 (not-finished t))
|
|
912 (skip-chars-backward " \t\n\f" backward-limit)
|
|
913 (while not-finished
|
|
914 (cond ((looking-at "[ \t]+")
|
|
915 (goto-char (match-end 0))
|
18931
|
916 (if (eq category 'null)
|
85
|
917 (setq category 'space)))
|
|
918 ((looking-at "\n")
|
18931
|
919 (cond ((eq category 'newline)
|
85
|
920 (setq category 'par)
|
|
921 (setq not-finished nil))
|
|
922 (t
|
|
923 (setq category 'newline) ;a strictly internal state
|
|
924 (goto-char (match-end 0)))))
|
|
925 ((looking-at "\f+")
|
|
926 (setq category 'par)
|
|
927 (setq not-finished nil))
|
|
928 (t
|
|
929 (setq not-finished nil))))
|
|
930 (skip-chars-forward " \t\n\f")
|
18931
|
931 (if (eq category 'newline)
|
85
|
932 'space ;TeX doesn't distinguish
|
|
933 category)))
|
|
934
|
|
935 (defun tex-insert-quote (arg)
|
|
936 "Insert the appropriate quote marks for TeX.
|
2836
|
937 Inserts the value of `tex-open-quote' (normally ``) or `tex-close-quote'
|
|
938 \(normally '') depending on the context. With prefix argument, always
|
85
|
939 inserts \" characters."
|
739
|
940 (interactive "*P")
|
85
|
941 (if arg
|
|
942 (self-insert-command (prefix-numeric-value arg))
|
|
943 (insert
|
33472
|
944 (cond ((= (preceding-char) ?\\) ?\")
|
|
945 ((memq (char-syntax (preceding-char)) '(?\( ?> ?\ )) tex-open-quote)
|
|
946 (t tex-close-quote)))))
|
85
|
947
|
24222
|
948 (defun tex-validate-buffer ()
|
|
949 "Check current buffer for paragraphs containing mismatched braces or $s.
|
4376
|
950 Their positions are recorded in the buffer `*Occur*'.
|
24222
|
951 To find a particular invalidity from `*Occur*', switch to that buffer
|
|
952 and type C-c C-c or click with mouse-2
|
|
953 on the line for the invalidity you want to see."
|
85
|
954 (interactive)
|
4376
|
955 (let ((buffer (current-buffer))
|
|
956 (prevpos (point-min))
|
24222
|
957 (linenum nil)
|
|
958 (num-matches 0))
|
4376
|
959 (with-output-to-temp-buffer "*Occur*"
|
|
960 (princ "Mismatches:\n")
|
|
961 (save-excursion
|
|
962 (set-buffer standard-output)
|
|
963 (occur-mode)
|
|
964 (setq occur-buffer buffer)
|
24222
|
965 (setq occur-nlines 0))
|
4376
|
966 (save-excursion
|
|
967 (goto-char (point-max))
|
85
|
968 (while (and (not (input-pending-p)) (not (bobp)))
|
15644
|
969 (let ((end (point))
|
|
970 prev-end)
|
4376
|
971 ;; Scan the previous paragraph for invalidities.
|
15644
|
972 (if (search-backward "\n\n" nil t)
|
|
973 (progn
|
|
974 (setq prev-end (point))
|
|
975 (forward-char 2))
|
|
976 (goto-char (setq prev-end (point-min))))
|
85
|
977 (or (tex-validate-region (point) end)
|
15644
|
978 (let* ((oend end)
|
|
979 (end (save-excursion (forward-line 1) (point)))
|
4376
|
980 start tem)
|
|
981 (beginning-of-line)
|
|
982 (setq start (point))
|
|
983 ;; Keep track of line number as we scan,
|
|
984 ;; in a cumulative fashion.
|
|
985 (if linenum
|
|
986 (setq linenum (- linenum (count-lines prevpos (point))))
|
|
987 (setq linenum (1+ (count-lines 1 start))))
|
|
988 (setq prevpos (point))
|
24273
|
989 ;; Mention this mismatch in *Occur*.
|
4376
|
990 ;; Since we scan from end of buffer to beginning,
|
24222
|
991 ;; add each mismatch at the beginning of *Occur*.
|
4376
|
992 (save-excursion
|
|
993 (setq tem (point-marker))
|
|
994 (set-buffer standard-output)
|
|
995 (goto-char (point-min))
|
|
996 ;; Skip "Mismatches:" header line.
|
|
997 (forward-line 1)
|
24222
|
998 (setq num-matches (1+ num-matches))
|
4376
|
999 (insert-buffer-substring buffer start end)
|
24222
|
1000 (let (text-beg (text-end (point-marker)))
|
|
1001 (forward-char (- start end))
|
|
1002 (setq text-beg (point-marker))
|
|
1003 (insert (format "%3d: " linenum))
|
38083
|
1004 (add-text-properties
|
|
1005 text-beg (- text-end 1)
|
|
1006 '(mouse-face highlight
|
|
1007 help-echo "mouse-2: go to this invalidity"))
|
33789
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1008 (put-text-property text-beg (- text-end 1)
|
24222
|
1009 'occur tem)))))
|
15644
|
1010 (goto-char prev-end))))
|
33472
|
1011 (with-current-buffer standard-output
|
24222
|
1012 (if (eq num-matches 0)
|
4376
|
1013 (insert "None!\n"))
|
|
1014 (if (interactive-p)
|
24222
|
1015 (message "%d mismatches found" num-matches))))))
|
85
|
1016
|
|
1017 (defun tex-validate-region (start end)
|
|
1018 "Check for mismatched braces or $'s in region.
|
|
1019 Returns t if no mismatches. Returns nil and moves point to suspect
|
|
1020 area if a mismatch is found."
|
|
1021 (interactive "r")
|
|
1022 (let ((failure-point nil) (max-possible-sexps (- end start)))
|
|
1023 (save-excursion
|
|
1024 (condition-case ()
|
|
1025 (save-restriction
|
|
1026 (narrow-to-region start end)
|
20203
|
1027 ;; First check that the open and close parens balance in numbers.
|
85
|
1028 (goto-char start)
|
24222
|
1029 (while (<= 0 (setq max-possible-sexps (1- max-possible-sexps)))
|
20203
|
1030 (forward-sexp 1))
|
|
1031 ;; Now check that like matches like.
|
|
1032 (goto-char start)
|
|
1033 (while (progn (skip-syntax-forward "^(")
|
|
1034 (not (eobp)))
|
|
1035 (let ((match (matching-paren (following-char))))
|
|
1036 (save-excursion
|
|
1037 (forward-sexp 1)
|
|
1038 (or (= (preceding-char) match)
|
|
1039 (error "Mismatched parentheses"))))
|
|
1040 (forward-char 1)))
|
85
|
1041 (error
|
24273
|
1042 (skip-syntax-forward " .>")
|
|
1043 (setq failure-point (point)))))
|
33472
|
1044 (if failure-point (goto-char failure-point))
|
|
1045 (not failure-point)))
|
85
|
1046
|
|
1047 (defun tex-terminate-paragraph (inhibit-validation)
|
|
1048 "Insert two newlines, breaking a paragraph for TeX.
|
7285
|
1049 Check for mismatched braces or $s in paragraph being terminated.
|
85
|
1050 A prefix arg inhibits the checking."
|
739
|
1051 (interactive "*P")
|
85
|
1052 (or inhibit-validation
|
|
1053 (save-excursion
|
|
1054 (tex-validate-region
|
24273
|
1055 (save-excursion
|
|
1056 (search-backward "\n\n" nil 'move)
|
|
1057 (point))
|
|
1058 (point)))
|
85
|
1059 (message "Paragraph being closed appears to contain a mismatch"))
|
|
1060 (insert "\n\n"))
|
|
1061
|
|
1062 (defun tex-insert-braces ()
|
|
1063 "Make a pair of braces and be poised to type inside of them."
|
739
|
1064 (interactive "*")
|
85
|
1065 (insert ?\{)
|
|
1066 (save-excursion
|
|
1067 (insert ?})))
|
|
1068
|
21121
|
1069 ;; This function is used as the value of fill-nobreak-predicate
|
|
1070 ;; in LaTeX mode. Its job is to prevent line-breaking inside
|
|
1071 ;; of a \verb construct.
|
|
1072 (defun latex-fill-nobreak-predicate ()
|
|
1073 (let ((opoint (point))
|
|
1074 inside)
|
24273
|
1075 (save-excursion
|
21121
|
1076 (save-restriction
|
|
1077 (beginning-of-line)
|
|
1078 (narrow-to-region (point) opoint)
|
|
1079 (while (re-search-forward "\\\\verb\\(.\\)" nil t)
|
|
1080 (unless (re-search-forward (regexp-quote (match-string 1)) nil t)
|
|
1081 (setq inside t)))))
|
|
1082 inside))
|
|
1083
|
32045
|
1084 (defvar latex-block-default "enumerate")
|
|
1085
|
37896
|
1086 ;; Like tex-insert-braces, but for LaTeX.
|
15513
|
1087 (define-skeleton tex-latex-block
|
|
1088 "Create a matching pair of lines \\begin[OPT]{NAME} and \\end{NAME} at point.
|
85
|
1089 Puts point on a blank line between them."
|
32045
|
1090 (let ((choice (completing-read (format "LaTeX block name [%s]: "
|
|
1091 latex-block-default)
|
|
1092 (mapcar 'list
|
|
1093 (append standard-latex-block-names
|
|
1094 latex-block-names))
|
|
1095 nil nil nil nil latex-block-default)))
|
|
1096 (setq latex-block-default choice)
|
|
1097 (unless (or (member choice standard-latex-block-names)
|
|
1098 (member choice latex-block-names))
|
|
1099 ;; Remember new block names for later completion.
|
|
1100 (push choice latex-block-names))
|
|
1101 choice)
|
37896
|
1102 \n "\\begin{" str ?\}
|
32045
|
1103 ?\[ (skeleton-read "[options]: ") & ?\] | -1
|
33363
|
1104 > \n _ \n
|
37896
|
1105 "\\end{" str ?\} > \n)
|
32045
|
1106
|
32479
|
1107 (define-skeleton latex-insert-item
|
|
1108 "Insert a \item macro."
|
|
1109 nil
|
37896
|
1110 \n "\\item " >)
|
32479
|
1111
|
32045
|
1112
|
|
1113 ;;;;
|
|
1114 ;;;; LaTeX syntax navigation
|
|
1115 ;;;;
|
85
|
1116
|
|
1117 (defun tex-last-unended-begin ()
|
7285
|
1118 "Leave point at the beginning of the last `\\begin{...}' that is unended."
|
32045
|
1119 (while (and (re-search-backward "\\\\\\(begin\\|end\\)\\s *{")
|
|
1120 (looking-at "\\\\end"))
|
85
|
1121 (tex-last-unended-begin)))
|
|
1122
|
32045
|
1123 (defun tex-next-unmatched-end ()
|
|
1124 "Leave point at the end of the next `\\end' that is unended."
|
|
1125 (while (and (re-search-forward "\\\\\\(begin\\|end\\)\\s *{[^}]+}")
|
32479
|
1126 (save-excursion (goto-char (match-beginning 0))
|
|
1127 (looking-at "\\\\begin")))
|
32045
|
1128 (tex-next-unmatched-end)))
|
|
1129
|
7297
a480d11d5594
(tex-goto-last-unclosed-latex-block): New function. Bound to C-c C-u in
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1130 (defun tex-goto-last-unclosed-latex-block ()
|
a480d11d5594
(tex-goto-last-unclosed-latex-block): New function. Bound to C-c C-u in
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1131 "Move point to the last unclosed \\begin{...}.
|
a480d11d5594
(tex-goto-last-unclosed-latex-block): New function. Bound to C-c C-u in
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1132 Mark is left at original location."
|
a480d11d5594
(tex-goto-last-unclosed-latex-block): New function. Bound to C-c C-u in
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1133 (interactive)
|
a480d11d5594
(tex-goto-last-unclosed-latex-block): New function. Bound to C-c C-u in
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1134 (let ((spot))
|
a480d11d5594
(tex-goto-last-unclosed-latex-block): New function. Bound to C-c C-u in
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1135 (save-excursion
|
a480d11d5594
(tex-goto-last-unclosed-latex-block): New function. Bound to C-c C-u in
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1136 (condition-case nil
|
a480d11d5594
(tex-goto-last-unclosed-latex-block): New function. Bound to C-c C-u in
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1137 (tex-last-unended-begin)
|
a480d11d5594
(tex-goto-last-unclosed-latex-block): New function. Bound to C-c C-u in
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1138 (error (error "Couldn't find unended \\begin")))
|
a480d11d5594
(tex-goto-last-unclosed-latex-block): New function. Bound to C-c C-u in
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1139 (setq spot (point)))
|
a480d11d5594
(tex-goto-last-unclosed-latex-block): New function. Bound to C-c C-u in
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1140 (push-mark)
|
a480d11d5594
(tex-goto-last-unclosed-latex-block): New function. Bound to C-c C-u in
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1141 (goto-char spot)))
|
a480d11d5594
(tex-goto-last-unclosed-latex-block): New function. Bound to C-c C-u in
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1142
|
32045
|
1143 (defun latex-backward-sexp-1 ()
|
|
1144 "Like (backward-sexp 1) but aware of multi-char elements."
|
|
1145 (let ((pos (point))
|
|
1146 (forward-sexp-function))
|
|
1147 (backward-sexp 1)
|
|
1148 (if (looking-at "\\\\begin\\>")
|
|
1149 (signal 'scan-error
|
|
1150 (list "Containing expression ends prematurely"
|
|
1151 (point) (prog1 (point) (goto-char pos))))
|
|
1152 (when (eq (char-after) ?{)
|
|
1153 (let ((newpos (point)))
|
|
1154 (when (ignore-errors (backward-sexp 1) t)
|
|
1155 (if (looking-at "\\\\end\\>")
|
|
1156 (tex-last-unended-begin)
|
|
1157 (goto-char newpos))))))))
|
|
1158
|
|
1159 (defun latex-forward-sexp-1 ()
|
|
1160 "Like (forward-sexp 1) but aware of multi-char elements."
|
|
1161 (let ((pos (point))
|
|
1162 (forward-sexp-function))
|
|
1163 (forward-sexp 1)
|
|
1164 (let ((newpos (point)))
|
|
1165 (skip-syntax-backward "/w")
|
|
1166 (cond
|
|
1167 ((looking-at "\\\\end\\>")
|
|
1168 (signal 'scan-error
|
|
1169 (list "Containing expression ends prematurely"
|
|
1170 (point)
|
|
1171 (prog1
|
|
1172 (progn (ignore-errors (forward-sexp 2)) (point))
|
|
1173 (goto-char pos)))))
|
|
1174 ((looking-at "\\\\begin\\>")
|
|
1175 (goto-char (match-end 0))
|
|
1176 (tex-next-unmatched-end))
|
|
1177 (t (goto-char newpos))))))
|
|
1178
|
|
1179 (defun latex-forward-sexp (&optional arg)
|
|
1180 "Like `forward-sexp' but aware of multi-char elements."
|
|
1181 (interactive "P")
|
|
1182 (unless arg (setq arg 1))
|
|
1183 (let ((pos (point)))
|
|
1184 (condition-case err
|
|
1185 (while (/= arg 0)
|
|
1186 (setq arg
|
|
1187 (if (> arg 0)
|
|
1188 (progn (latex-forward-sexp-1) (1- arg))
|
|
1189 (progn (latex-backward-sexp-1) (1+ arg)))))
|
|
1190 (scan-error
|
|
1191 (goto-char pos)
|
|
1192 (signal (car err) (cdr err))))))
|
|
1193
|
32479
|
1194 (defun latex-syntax-after ()
|
|
1195 "Like (char-syntax (char-after)) but aware of multi-char elements."
|
37896
|
1196 (if (looking-at "\\\\end\\>") ?\) (char-syntax (following-char))))
|
32479
|
1197
|
|
1198 (defun latex-skip-close-parens ()
|
|
1199 "Like (skip-syntax-forward \" )\") but aware of multi-char elements."
|
|
1200 (let ((forward-sexp-function nil))
|
|
1201 (while (progn (skip-syntax-forward " )")
|
|
1202 (looking-at "\\\\end\\>"))
|
|
1203 (forward-sexp 2))))
|
|
1204
|
|
1205 (defun latex-down-list ()
|
|
1206 "Like (down-list 1) but aware of multi-char elements."
|
|
1207 (forward-comment (point-max))
|
|
1208 (let ((forward-sexp-function nil))
|
|
1209 (if (not (looking-at "\\\\begin\\>"))
|
|
1210 (down-list 1)
|
|
1211 (forward-sexp 1)
|
|
1212 ;; Skip arguments.
|
|
1213 (while (looking-at "[ \t]*\\s(") (forward-sexp)))))
|
|
1214
|
85
|
1215 (defun tex-close-latex-block ()
|
|
1216 "Creates an \\end{...} to match the last unclosed \\begin{...}."
|
|
1217 (interactive "*")
|
|
1218 (let ((new-line-needed (bolp))
|
|
1219 text indentation)
|
|
1220 (save-excursion
|
739
|
1221 (condition-case nil
|
85
|
1222 (tex-last-unended-begin)
|
|
1223 (error (error "Couldn't find unended \\begin")))
|
|
1224 (setq indentation (current-column))
|
|
1225 (re-search-forward "\\\\begin\\(\\s *{[^}\n]*}\\)")
|
|
1226 (setq text (buffer-substring (match-beginning 1) (match-end 1))))
|
|
1227 (indent-to indentation)
|
|
1228 (insert "\\end" text)
|
|
1229 (if new-line-needed (insert ?\n))))
|
37896
|
1230
|
|
1231 (defconst tex-discount-args-cmds
|
|
1232 '("begin" "end" "input" "special" "cite" "ref" "include" "includeonly"
|
|
1233 "documentclass" "usepackage" "label")
|
|
1234 "TeX commands whose arguments should not be counted as text.")
|
|
1235
|
|
1236 (defun tex-count-words (begin end)
|
|
1237 "Count the number of words in the buffer."
|
|
1238 (interactive
|
|
1239 (if (and transient-mark-mode mark-active)
|
|
1240 (list (region-beginning) (region-end))
|
|
1241 (list (point-min) (point-max))))
|
|
1242 ;; TODO: skip comments and math and maybe some environments.
|
|
1243 (save-excursion
|
|
1244 (goto-char begin)
|
|
1245 (let ((count 0))
|
|
1246 (while (and (< (point) end) (re-search-forward "\\<" end t))
|
|
1247 (if (not (eq (char-syntax (preceding-char)) ?/))
|
|
1248 (progn
|
|
1249 ;; Don't count single-char words.
|
|
1250 (unless (looking-at ".\\>") (incf count))
|
|
1251 (forward-char 1))
|
|
1252 (let ((cmd
|
|
1253 (buffer-substring-no-properties
|
|
1254 (point) (progn (when (zerop (skip-chars-forward "a-zA-Z@"))
|
|
1255 (forward-char 1))
|
|
1256 (point)))))
|
|
1257 (when (member cmd tex-discount-args-cmds)
|
|
1258 (skip-chars-forward "*")
|
|
1259 (forward-comment (point-max))
|
|
1260 (when (looking-at "\\[")
|
|
1261 (forward-sexp 1)
|
|
1262 (forward-comment (point-max)))
|
|
1263 (if (not (looking-at "{"))
|
|
1264 (forward-char 1)
|
|
1265 (forward-sexp 1))))))
|
|
1266 (message "%s words" count))))
|
37942
|
1267
|
|
1268
|
85
|
1269
|
|
1270 ;;; Invoking TeX in an inferior shell.
|
|
1271
|
37896
|
1272 ;; Why use a shell instead of running TeX directly? Because if TeX
|
|
1273 ;; gets stuck, the user can switch to the shell window and type at it.
|
85
|
1274
|
37896
|
1275 ;; The utility functions:
|
85
|
1276
|
33472
|
1277 (define-derived-mode tex-shell shell-mode "TeX-Shell"
|
|
1278 (compilation-shell-minor-mode t))
|
|
1279
|
7834
|
1280 ;;;###autoload
|
85
|
1281 (defun tex-start-shell ()
|
31968
|
1282 (with-current-buffer
|
|
1283 (make-comint
|
|
1284 "tex-shell"
|
34139
|
1285 (or tex-shell-file-name (getenv "ESHELL") shell-file-name)
|
31968
|
1286 nil)
|
739
|
1287 (let ((proc (get-process "tex-shell")))
|
|
1288 (set-process-sentinel proc 'tex-shell-sentinel)
|
|
1289 (process-kill-without-query proc)
|
33472
|
1290 (tex-shell)
|
739
|
1291 (while (zerop (buffer-size))
|
10572
|
1292 (sleep-for 1)))))
|
|
1293
|
23761
|
1294 (defun tex-feed-input ()
|
|
1295 "Send input to the tex shell process.
|
|
1296 In the tex buffer this can be used to continue an interactive tex run.
|
24273
|
1297 In the tex shell buffer this command behaves like `comint-send-input'."
|
23761
|
1298 (interactive)
|
37942
|
1299 (set-buffer (tex-shell-buf))
|
23761
|
1300 (comint-send-input)
|
|
1301 (tex-recenter-output-buffer nil))
|
|
1302
|
10572
|
1303 (defun tex-display-shell ()
|
|
1304 "Make the TeX shell buffer visible in a window."
|
37942
|
1305 (display-buffer (tex-shell-buf))
|
10572
|
1306 (tex-recenter-output-buffer nil))
|
85
|
1307
|
739
|
1308 (defun tex-shell-sentinel (proc msg)
|
|
1309 (cond ((null (buffer-name (process-buffer proc)))
|
|
1310 ;; buffer killed
|
|
1311 (set-process-buffer proc nil)
|
|
1312 (tex-delete-last-temp-files))
|
|
1313 ((memq (process-status proc) '(signal exit))
|
|
1314 (tex-delete-last-temp-files))))
|
|
1315
|
|
1316 (defun tex-set-buffer-directory (buffer directory)
|
85
|
1317 "Set BUFFER's default directory to be DIRECTORY."
|
|
1318 (setq directory (file-name-as-directory (expand-file-name directory)))
|
|
1319 (if (not (file-directory-p directory))
|
|
1320 (error "%s is not a directory" directory)
|
|
1321 (save-excursion
|
|
1322 (set-buffer buffer)
|
|
1323 (setq default-directory directory))))
|
|
1324
|
5088
|
1325 (defvar tex-send-command-modified-tick 0)
|
|
1326 (make-variable-buffer-local 'tex-send-command-modified-tick)
|
|
1327
|
33472
|
1328 (defun tex-shell-proc ()
|
37942
|
1329 (or (tex-shell-running) (error "No TeX subprocess")))
|
33472
|
1330 (defun tex-shell-buf ()
|
|
1331 (process-buffer (tex-shell-proc)))
|
37942
|
1332 (defun tex-shell-buf-no-error ()
|
|
1333 (let ((proc (tex-shell-running)))
|
|
1334 (and proc (process-buffer proc))))
|
33472
|
1335
|
739
|
1336 (defun tex-send-command (command &optional file background)
|
5087
|
1337 "Send COMMAND to TeX shell process, substituting optional FILE for *.
|
2588
|
1338 Do this in background if optional BACKGROUND is t. If COMMAND has no *,
|
|
1339 FILE will be appended, preceded by a blank, to COMMAND. If FILE is nil, no
|
|
1340 substitution will be made in COMMAND. COMMAND can be any expression that
|
21314
|
1341 evaluates to a command string.
|
|
1342
|
|
1343 Return the process in which TeX is running."
|
739
|
1344 (save-excursion
|
|
1345 (let* ((cmd (eval command))
|
33472
|
1346 (proc (tex-shell-proc))
|
5262
|
1347 (buf (process-buffer proc))
|
2265
|
1348 (star (string-match "\\*" cmd))
|
5087
|
1349 (string
|
|
1350 (concat
|
|
1351 (if file
|
|
1352 (if star (concat (substring cmd 0 star)
|
|
1353 file (substring cmd (1+ star)))
|
|
1354 (concat cmd " " file))
|
|
1355 cmd)
|
|
1356 (if background "&" ""))))
|
5262
|
1357 ;; Switch to buffer before checking for subproc output in it.
|
|
1358 (set-buffer buf)
|
5088
|
1359 ;; If text is unchanged since previous tex-send-command,
|
|
1360 ;; we haven't got any output. So wait for output now.
|
5262
|
1361 (if (= (buffer-modified-tick buf) tex-send-command-modified-tick)
|
5088
|
1362 (accept-process-output proc))
|
5087
|
1363 (goto-char (process-mark proc))
|
|
1364 (insert string)
|
5088
|
1365 (comint-send-input)
|
21314
|
1366 (setq tex-send-command-modified-tick (buffer-modified-tick buf))
|
|
1367 proc)))
|
85
|
1368
|
6479
|
1369 (defun tex-delete-last-temp-files (&optional not-all)
|
|
1370 "Delete any junk files from last temp file.
|
|
1371 If NOT-ALL is non-nil, save the `.dvi' file."
|
739
|
1372 (if tex-last-temp-file
|
|
1373 (let* ((dir (file-name-directory tex-last-temp-file))
|
7536
|
1374 (list (and (file-directory-p dir)
|
|
1375 (file-name-all-completions
|
22707
|
1376 (file-name-sans-extension
|
|
1377 (file-name-nondirectory tex-last-temp-file))
|
|
1378 dir))))
|
7536
|
1379 (while list
|
6479
|
1380 (if not-all
|
|
1381 (and
|
|
1382 ;; If arg is non-nil, don't delete the .dvi file.
|
|
1383 (not (string-match "\\.dvi$" (car list)))
|
|
1384 (delete-file (concat dir (car list))))
|
|
1385 (delete-file (concat dir (car list))))
|
739
|
1386 (setq list (cdr list))))))
|
|
1387
|
741
|
1388 (add-hook 'kill-emacs-hook 'tex-delete-last-temp-files)
|
739
|
1389
|
33363
|
1390 (defun tex-guess-main-file (&optional all)
|
|
1391 "Find a likely `tex-main-file'.
|
|
1392 Looks for hints in other buffers in the same directory or in
|
|
1393 ALL other buffers."
|
|
1394 (let ((dir default-directory)
|
|
1395 (header-re tex-start-of-header))
|
|
1396 (catch 'found
|
|
1397 ;; Look for a buffer with `tex-main-file' set.
|
|
1398 (dolist (buf (if (consp all) all (buffer-list)))
|
|
1399 (with-current-buffer buf
|
|
1400 (when (and (or all (equal dir default-directory))
|
|
1401 (stringp tex-main-file))
|
|
1402 (throw 'found (expand-file-name tex-main-file)))))
|
|
1403 ;; Look for a buffer containing the magic `tex-start-of-header'.
|
|
1404 (dolist (buf (if (consp all) all (buffer-list)))
|
|
1405 (with-current-buffer buf
|
|
1406 (when (and (or all (equal dir default-directory))
|
|
1407 buffer-file-name
|
|
1408 ;; (or (easy-mmode-derived-mode-p 'latex-mode)
|
|
1409 ;; (easy-mmode-derived-mode-p 'plain-tex-mode))
|
|
1410 (save-excursion
|
|
1411 (goto-char (point-min))
|
|
1412 (re-search-forward header-re 10000 t)))
|
|
1413 (throw 'found (expand-file-name buffer-file-name))))))))
|
|
1414
|
34139
|
1415 (defun tex-main-file ()
|
|
1416 "Return the relative name of the main file."
|
33472
|
1417 (let* ((file (or tex-main-file
|
|
1418 ;; Compatibility with AUCTeX.
|
|
1419 (and (boundp 'TeX-master) (stringp TeX-master)
|
|
1420 (set (make-local-variable 'tex-main-file) TeX-master))
|
|
1421 ;; Try to guess the main file.
|
|
1422 (if (not buffer-file-name)
|
|
1423 (error "Buffer is not associated with any file")
|
|
1424 (file-relative-name
|
|
1425 (if (save-excursion
|
|
1426 (goto-char (point-min))
|
|
1427 (re-search-forward tex-start-of-header 10000 t))
|
|
1428 ;; This is the main file.
|
|
1429 buffer-file-name
|
|
1430 ;; This isn't the main file, let's try to find better,
|
|
1431 (or (tex-guess-main-file)
|
|
1432 ;; (tex-guess-main-file t)
|
34139
|
1433 buffer-file-name)))))))
|
|
1434 (if (file-exists-p file) file (concat file ".tex"))))
|
33363
|
1435
|
31968
|
1436
|
|
1437 (defun tex-start-tex (command file &optional dir)
|
21314
|
1438 "Start a TeX run, using COMMAND on FILE."
|
23322
|
1439 (let* ((star (string-match "\\*" command))
|
21314
|
1440 (compile-command
|
23322
|
1441 (if star
|
|
1442 (concat (substring command 0 star)
|
|
1443 (comint-quote-filename file)
|
|
1444 (substring command (1+ star)))
|
|
1445 (concat command " "
|
24330
|
1446 (if (< 0 (length tex-start-options-string))
|
|
1447 (concat
|
|
1448 (shell-quote-argument tex-start-options-string) " "))
|
23322
|
1449 (comint-quote-filename file)))))
|
33472
|
1450 (tex-send-tex-command compile-command dir)))
|
|
1451
|
|
1452 (defun tex-send-tex-command (cmd &optional dir)
|
37942
|
1453 (unless (or (equal dir (let ((buf (tex-shell-buf-no-error)))
|
|
1454 (and buf (with-current-buffer buf
|
|
1455 default-directory))))
|
33472
|
1456 (not dir))
|
|
1457 (let (shell-dirtrack-verbose)
|
|
1458 (tex-send-command tex-shell-cd-command dir)))
|
|
1459 (with-current-buffer (process-buffer (tex-send-command cmd))
|
|
1460 (make-local-variable 'compilation-parse-errors-function)
|
|
1461 (setq compilation-parse-errors-function 'tex-compilation-parse-errors)
|
|
1462 (setq compilation-last-buffer (current-buffer))
|
|
1463 (compilation-forget-errors)
|
33789
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1464 ;; Don't parse previous compilations.
|
33472
|
1465 (set-marker compilation-parsing-end (1- (point-max))))
|
|
1466 (tex-display-shell)
|
|
1467 (setq tex-last-buffer-texed (current-buffer)))
|
21314
|
1468
|
33789
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1469 (defvar tex-error-parse-syntax-table
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1470 (let ((st (make-syntax-table)))
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1471 (modify-syntax-entry ?\( "()" st)
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1472 (modify-syntax-entry ?\) ")(" st)
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1473 (modify-syntax-entry ?\\ "\\" st)
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1474 (modify-syntax-entry ?\{ "_" st)
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1475 (modify-syntax-entry ?\} "_" st)
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1476 (modify-syntax-entry ?\[ "_" st)
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1477 (modify-syntax-entry ?\] "_" st)
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1478 ;; Single quotations may appear in errors
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1479 (modify-syntax-entry ?\" "_" st)
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1480 st)
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1481 "Syntax-table used while parsing TeX error messages.")
|
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1482
|
21314
|
1483 (defun tex-compilation-parse-errors (limit-search find-at-least)
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1484 "Parse the current buffer as TeX error messages.
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1485 See the variable `compilation-parse-errors-function' for the interface it uses.
|
21314
|
1486
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1487 This function parses only the last TeX compilation.
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1488 It works on TeX compilations only. It is necessary for that purpose,
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1489 since TeX does not put file names and line numbers on the same line as
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1490 for the error messages."
|
21314
|
1491 (require 'thingatpt)
|
|
1492 (setq compilation-error-list nil)
|
|
1493 (message "Parsing error messages...")
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1494 (let ((default-directory ; Perhaps dir has changed meanwhile.
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1495 (file-name-directory (buffer-file-name tex-last-buffer-texed)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1496 found-desired (num-errors-found 0)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1497 last-filename last-linenum last-position
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1498 begin-of-error end-of-error)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1499 ;; Don't reparse messages already seen at last parse.
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1500 (goto-char compilation-parsing-end)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1501 ;; Parse messages.
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1502 (while (and (not (or found-desired (eobp)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1503 (prog1 (re-search-forward "^! " nil 'move)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1504 (setq begin-of-error (match-beginning 0)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1505 end-of-error (match-end 0)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1506 (re-search-forward
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1507 "^l\\.\\([0-9]+\\) \\(\\.\\.\\.\\)?\\(.*\\)$" nil 'move))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1508 (let* ((this-error (set-marker (make-marker) begin-of-error))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1509 (linenum (string-to-int (match-string 1)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1510 (error-text (regexp-quote (match-string 3)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1511 (filename
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1512 (save-excursion
|
32479
|
1513 (with-syntax-table tex-error-parse-syntax-table
|
|
1514 (backward-up-list 1)
|
|
1515 (skip-syntax-forward "(_")
|
|
1516 (while (not (file-readable-p (thing-at-point 'filename)))
|
|
1517 (skip-syntax-backward "(_")
|
|
1518 (backward-up-list 1)
|
|
1519 (skip-syntax-forward "(_"))
|
|
1520 (thing-at-point 'filename))))
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1521 (new-file
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1522 (or (null last-filename)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1523 (not (string-equal last-filename filename))))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1524 (error-location
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1525 (save-excursion
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1526 (if (equal filename (concat tex-zap-file ".tex"))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1527 (set-buffer tex-last-buffer-texed)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1528 (set-buffer (find-file-noselect filename)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1529 (if new-file
|
33789
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1530 (progn (goto-line linenum) (setq last-position nil))
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1531 (goto-char last-position)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1532 (forward-line (- linenum last-linenum)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1533 ;; first try a forward search for the error text,
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1534 ;; then a backward search limited by the last error.
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1535 (let ((starting-point (point)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1536 (or (re-search-forward error-text nil t)
|
33789
3cb3c23bbe84
(tex-font-lock-keywords-1): Fix ARG regexp to skip quoted braces.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1537 (re-search-backward error-text last-position t)
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1538 (goto-char starting-point)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1539 (point-marker))))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1540 (goto-char this-error)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1541 (if (and compilation-error-list
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1542 (or (and find-at-least
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1543 (>= num-errors-found
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1544 find-at-least))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1545 (and limit-search
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1546 (>= end-of-error limit-search)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1547 new-file)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1548 (setq found-desired t)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1549 (setq num-errors-found (1+ num-errors-found)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1550 last-filename filename
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1551 last-linenum linenum
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1552 last-position error-location
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1553 compilation-error-list ; Add the new error
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1554 (cons (cons this-error error-location)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1555 compilation-error-list))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1556 (goto-char end-of-error)))))
|
25414
|
1557 (set-marker compilation-parsing-end (point))
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1558 (setq compilation-error-list (nreverse compilation-error-list))
|
21314
|
1559 (message "Parsing error messages...done"))
|
|
1560
|
739
|
1561 ;;; The commands:
|
85
|
1562
|
|
1563 (defun tex-region (beg end)
|
|
1564 "Run TeX on the current region, via a temporary file.
|
|
1565 The file's name comes from the variable `tex-zap-file' and the
|
|
1566 variable `tex-directory' says where to put it.
|
|
1567
|
|
1568 If the buffer has a header, the header is given to TeX before the
|
|
1569 region itself. The buffer's header is all lines between the strings
|
|
1570 defined by `tex-start-of-header' and `tex-end-of-header' inclusive.
|
|
1571 The header must start in the first 100 lines of the buffer.
|
|
1572
|
|
1573 The value of `tex-trailer' is given to TeX as input after the region.
|
|
1574
|
|
1575 The value of `tex-command' specifies the command to use to run TeX."
|
|
1576 (interactive "r")
|
|
1577 (if (tex-shell-running)
|
|
1578 (tex-kill-job)
|
|
1579 (tex-start-shell))
|
|
1580 (or tex-zap-file
|
|
1581 (setq tex-zap-file (tex-generate-zap-file-name)))
|
16807
|
1582 ;; Temp file will be written and TeX will be run in zap-directory.
|
|
1583 ;; If the TEXINPUTS file has relative directories or if the region has
|
|
1584 ;; \input of files, this must be the same directory as the file for
|
|
1585 ;; TeX to access the correct inputs. That's why it's safest if
|
|
1586 ;; tex-directory is ".".
|
|
1587 (let* ((zap-directory
|
739
|
1588 (file-name-as-directory (expand-file-name tex-directory)))
|
31968
|
1589 (tex-out-file (expand-file-name (concat tex-zap-file ".tex")
|
|
1590 zap-directory)))
|
9450
|
1591 ;; Don't delete temp files if we do the same buffer twice in a row.
|
|
1592 (or (eq (current-buffer) tex-last-buffer-texed)
|
|
1593 (tex-delete-last-temp-files t))
|
85
|
1594 ;; Write the new temp file.
|
|
1595 (save-excursion
|
|
1596 (save-restriction
|
|
1597 (widen)
|
|
1598 (goto-char (point-min))
|
|
1599 (forward-line 100)
|
|
1600 (let ((search-end (point))
|
16807
|
1601 (default-directory zap-directory)
|
|
1602 (already-output 0))
|
85
|
1603 (goto-char (point-min))
|
16807
|
1604
|
16777
|
1605 ;; Maybe copy first line, such as `\input texinfo', to temp file.
|
|
1606 (and tex-first-line-header-regexp
|
|
1607 (looking-at tex-first-line-header-regexp)
|
24273
|
1608 (write-region (point)
|
16807
|
1609 (progn (forward-line 1)
|
|
1610 (setq already-output (point)))
|
16777
|
1611 tex-out-file nil nil))
|
|
1612
|
16807
|
1613 ;; Write out the header, if there is one,
|
|
1614 ;; and any of the specified region which extends before it.
|
|
1615 ;; But don't repeat anything already written.
|
13248
|
1616 (if (re-search-forward tex-start-of-header search-end t)
|
16807
|
1617 (let (hbeg)
|
85
|
1618 (beginning-of-line)
|
|
1619 (setq hbeg (point)) ;mark beginning of header
|
13248
|
1620 (if (re-search-forward tex-end-of-header nil t)
|
16807
|
1621 (let (hend)
|
|
1622 (forward-line 1)
|
24273
|
1623 (setq hend (point)) ;mark end of header
|
16807
|
1624 (write-region (max (min hbeg beg) already-output)
|
|
1625 hend
|
|
1626 tex-out-file
|
|
1627 (not (zerop already-output)) nil)
|
|
1628 (setq already-output hend)))))
|
|
1629
|
|
1630 ;; Write out the specified region
|
|
1631 ;; (but don't repeat anything already written).
|
|
1632 (write-region (max beg already-output) end
|
|
1633 tex-out-file
|
|
1634 (not (zerop already-output)) nil))
|
|
1635 ;; Write the trailer, if any.
|
|
1636 ;; Precede it with a newline to make sure it
|
|
1637 ;; is not hidden in a comment.
|
|
1638 (if tex-trailer
|
|
1639 (write-region (concat "\n" tex-trailer) nil
|
|
1640 tex-out-file t nil))))
|
739
|
1641 ;; Record the file name to be deleted afterward.
|
|
1642 (setq tex-last-temp-file tex-out-file)
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1643 ;; Use a relative file name here because (1) the proper dir
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1644 ;; is already current, and (2) the abs file name is sometimes
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1645 ;; too long and can make tex crash.
|
31968
|
1646 (tex-start-tex tex-command (concat tex-zap-file ".tex") zap-directory)
|
|
1647 (setq tex-print-file tex-out-file)))
|
85
|
1648
|
|
1649 (defun tex-buffer ()
|
|
1650 "Run TeX on current buffer. See \\[tex-region] for more information.
|
739
|
1651 Does not save the buffer, so it's useful for trying experimental versions.
|
|
1652 See \\[tex-file] for an alternative."
|
85
|
1653 (interactive)
|
|
1654 (tex-region (point-min) (point-max)))
|
|
1655
|
|
1656 (defun tex-file ()
|
|
1657 "Prompt to save all buffers and run TeX (or LaTeX) on current buffer's file.
|
|
1658 This function is more useful than \\[tex-buffer] when you need the
|
|
1659 `.aux' file of LaTeX to have the correct name."
|
|
1660 (interactive)
|
31968
|
1661 (let* ((source-file (tex-main-file))
|
34139
|
1662 (file-dir (file-name-directory (expand-file-name source-file))))
|
758
|
1663 (if tex-offer-save
|
741
|
1664 (save-some-buffers))
|
85
|
1665 (if (tex-shell-running)
|
|
1666 (tex-kill-job)
|
|
1667 (tex-start-shell))
|
31968
|
1668 (tex-start-tex tex-command source-file file-dir)
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1669 (setq tex-print-file (expand-file-name source-file))))
|
85
|
1670
|
|
1671 (defun tex-generate-zap-file-name ()
|
|
1672 "Generate a unique name suitable for use as a file name."
|
|
1673 ;; Include the shell process number and host name
|
|
1674 ;; in case there are multiple shells (for same or different user).
|
23849
|
1675 ;; Dec 1998: There is a report that some versions of xdvi
|
|
1676 ;; don't work with file names that start with #.
|
24109
|
1677 (format "_TZ_%d-%s"
|
85
|
1678 (process-id (get-buffer-process "*tex-shell*"))
|
34139
|
1679 (subst-char-in-string ?. ?- (system-name))))
|
85
|
1680
|
|
1681 ;; This will perhaps be useful for modifying TEXINPUTS.
|
|
1682 ;; Expand each file name, separated by colons, in the string S.
|
|
1683 (defun tex-expand-files (s)
|
|
1684 (let (elts (start 0))
|
|
1685 (while (string-match ":" s start)
|
|
1686 (setq elts (cons (substring s start (match-beginning 0)) elts))
|
|
1687 (setq start (match-end 0)))
|
|
1688 (or (= start 0)
|
|
1689 (setq elts (cons (substring s start) elts)))
|
30888
|
1690 (mapconcat (lambda (elt)
|
|
1691 (if (= (length elt) 0) elt (expand-file-name elt)))
|
24109
|
1692 (nreverse elts) ":")))
|
85
|
1693
|
|
1694 (defun tex-shell-running ()
|
36105
|
1695 (let ((proc (get-process "tex-shell")))
|
37942
|
1696 (when proc
|
|
1697 (if (and (eq (process-status proc) 'run)
|
|
1698 (buffer-live-p (process-buffer proc)))
|
|
1699 ;; return the TeX process on success
|
|
1700 proc
|
|
1701 ;; get rid of the process permanently
|
|
1702 ;; this should get rid of the annoying w32 problem with
|
|
1703 ;; dead tex-shell buffer and live process
|
|
1704 (delete-process proc)))))
|
85
|
1705
|
|
1706 (defun tex-kill-job ()
|
|
1707 "Kill the currently running TeX job."
|
|
1708 (interactive)
|
37942
|
1709 ;; `quit-process' leads to core dumps of the tex process (except if
|
24273
|
1710 ;; coredumpsize has limit 0kb as on many environments). One would
|
|
1711 ;; like to use (kill-process proc 'lambda), however that construct
|
|
1712 ;; does not work on some systems and kills the shell itself.
|
37942
|
1713 (let ((proc (get-process "tex-shell")))
|
|
1714 (when proc (quit-process proc t))))
|
85
|
1715
|
|
1716 (defun tex-recenter-output-buffer (linenum)
|
|
1717 "Redisplay buffer of TeX job output so that most recent output can be seen.
|
|
1718 The last line of the buffer is displayed on
|
|
1719 line LINE of the window, or centered if LINE is nil."
|
|
1720 (interactive "P")
|
|
1721 (let ((tex-shell (get-buffer "*tex-shell*"))
|
16493
|
1722 (old-buffer (current-buffer))
|
|
1723 (window))
|
85
|
1724 (if (null tex-shell)
|
|
1725 (message "No TeX output buffer")
|
16493
|
1726 (setq window (display-buffer tex-shell))
|
|
1727 (save-selected-window
|
|
1728 (select-window window)
|
|
1729 (bury-buffer tex-shell)
|
|
1730 (goto-char (point-max))
|
|
1731 (recenter (if linenum
|
|
1732 (prefix-numeric-value linenum)
|
|
1733 (/ (window-height) 2)))))))
|
85
|
1734
|
739
|
1735 (defun tex-print (&optional alt)
|
85
|
1736 "Print the .dvi file made by \\[tex-region], \\[tex-buffer] or \\[tex-file].
|
1577
|
1737 Runs the shell command defined by `tex-dvi-print-command'. If prefix argument
|
|
1738 is provided, use the alternative command, `tex-alt-dvi-print-command'."
|
739
|
1739 (interactive "P")
|
85
|
1740 (let ((print-file-name-dvi (tex-append tex-print-file ".dvi"))
|
|
1741 test-name)
|
|
1742 (if (and (not (equal (current-buffer) tex-last-buffer-texed))
|
10341
|
1743 (buffer-file-name)
|
|
1744 ;; Check that this buffer's printed file is up to date.
|
85
|
1745 (file-newer-than-file-p
|
|
1746 (setq test-name (tex-append (buffer-file-name) ".dvi"))
|
10341
|
1747 (buffer-file-name)))
|
85
|
1748 (setq print-file-name-dvi test-name))
|
739
|
1749 (if (not (file-exists-p print-file-name-dvi))
|
|
1750 (error "No appropriate `.dvi' file could be found")
|
21314
|
1751 (if (tex-shell-running)
|
|
1752 (tex-kill-job)
|
|
1753 (tex-start-shell))
|
739
|
1754 (tex-send-command
|
24273
|
1755 (if alt tex-alt-dvi-print-command tex-dvi-print-command)
|
|
1756 print-file-name-dvi t))))
|
85
|
1757
|
4917
|
1758 (defun tex-alt-print ()
|
|
1759 "Print the .dvi file made by \\[tex-region], \\[tex-buffer] or \\[tex-file].
|
10296
|
1760 Runs the shell command defined by `tex-alt-dvi-print-command'."
|
4917
|
1761 (interactive)
|
|
1762 (tex-print t))
|
|
1763
|
85
|
1764 (defun tex-view ()
|
|
1765 "Preview the last `.dvi' file made by running TeX under Emacs.
|
|
1766 This means, made using \\[tex-region], \\[tex-buffer] or \\[tex-file].
|
11617
|
1767 The variable `tex-dvi-view-command' specifies the shell command for preview.
|
|
1768 You must set that variable yourself before using this command,
|
|
1769 because there is no standard value that would generally work."
|
85
|
1770 (interactive)
|
11617
|
1771 (or tex-dvi-view-command
|
|
1772 (error "You must set `tex-dvi-view-command'"))
|
85
|
1773 (let ((tex-dvi-print-command tex-dvi-view-command))
|
|
1774 (tex-print)))
|
|
1775
|
|
1776 (defun tex-append (file-name suffix)
|
|
1777 "Append to FILENAME the suffix SUFFIX, using same algorithm TeX uses.
|
4917
|
1778 Pascal-based TeX scans for the first period, C TeX uses the last.
|
85
|
1779 No period is retained immediately before SUFFIX,
|
|
1780 so normally SUFFIX starts with one."
|
|
1781 (if (stringp file-name)
|
4917
|
1782 (let ((file (file-name-nondirectory file-name))
|
|
1783 trial-name)
|
14383
|
1784 ;; Try splitting on last period.
|
10778
|
1785 ;; The first-period split can get fooled when two files
|
|
1786 ;; named a.tex and a.b.tex are both tex'd;
|
|
1787 ;; the last-period split must be right if it matches at all.
|
4917
|
1788 (setq trial-name
|
|
1789 (concat (file-name-directory file-name)
|
|
1790 (substring file 0
|
10778
|
1791 (string-match "\\.[^.]*$" file))
|
4917
|
1792 suffix))
|
|
1793 (if (or (file-exists-p trial-name)
|
|
1794 (file-exists-p (concat trial-name ".aux"))) ;for BibTeX files
|
|
1795 trial-name
|
10778
|
1796 ;; Not found, so split on first period.
|
4917
|
1797 (concat (file-name-directory file-name)
|
|
1798 (substring file 0
|
10778
|
1799 (string-match "\\." file))
|
4917
|
1800 suffix)))
|
85
|
1801 " "))
|
|
1802
|
|
1803 (defun tex-show-print-queue ()
|
|
1804 "Show the print queue that \\[tex-print] put your job on.
|
1577
|
1805 Runs the shell command defined by `tex-show-queue-command'."
|
85
|
1806 (interactive)
|
|
1807 (if (tex-shell-running)
|
|
1808 (tex-kill-job)
|
|
1809 (tex-start-shell))
|
10572
|
1810 (tex-send-command tex-show-queue-command)
|
|
1811 (tex-display-shell))
|
85
|
1812
|
|
1813 (defun tex-bibtex-file ()
|
|
1814 "Run BibTeX on the current buffer's file."
|
|
1815 (interactive)
|
|
1816 (if (tex-shell-running)
|
|
1817 (tex-kill-job)
|
|
1818 (tex-start-shell))
|
24222
|
1819 (let (shell-dirtrack-verbose
|
|
1820 (tex-out-file
|
85
|
1821 (tex-append (file-name-nondirectory (buffer-file-name)) ""))
|
|
1822 (file-dir (file-name-directory (buffer-file-name))))
|
739
|
1823 (tex-send-command tex-shell-cd-command file-dir)
|
10572
|
1824 (tex-send-command tex-bibtex-command tex-out-file))
|
|
1825 (tex-display-shell))
|
32479
|
1826
|
|
1827 ;;;;
|
|
1828 ;;;; LaTeX indentation
|
|
1829 ;;;;
|
|
1830
|
|
1831 (defvar tex-indent-allhanging t)
|
|
1832 (defvar tex-indent-arg 4)
|
|
1833 (defvar tex-indent-basic 2)
|
|
1834 (defvar tex-indent-item tex-indent-basic)
|
|
1835 (defvar tex-indent-item-re "\\\\\\(bib\\)?item\\>")
|
|
1836
|
|
1837 (easy-mmode-defsyntax tex-latex-indent-syntax-table
|
33363
|
1838 '((?$ . ".")
|
|
1839 (?\( . ".")
|
|
1840 (?\) . "."))
|
32479
|
1841 "Syntax table used while computing indentation."
|
|
1842 :copy tex-mode-syntax-table)
|
|
1843
|
|
1844 (defun latex-indent (&optional arg)
|
|
1845 (with-syntax-table tex-latex-indent-syntax-table
|
|
1846 ;; TODO: Rather than ignore $, we should try to be more clever about it.
|
|
1847 (let ((indent
|
|
1848 (save-excursion
|
|
1849 (beginning-of-line)
|
|
1850 (latex-find-indent))))
|
|
1851 (if (< indent 0) (setq indent 0))
|
|
1852 (if (<= (current-column) (current-indentation))
|
|
1853 (indent-line-to indent)
|
|
1854 (save-excursion (indent-line-to indent))))))
|
|
1855
|
|
1856 (defun latex-find-indent (&optional virtual)
|
|
1857 "Find the proper indentation of text after point.
|
|
1858 VIRTUAL if non-nil indicates that we're only trying to find the indentation
|
|
1859 in order to determine the indentation of something else.
|
|
1860 There might be text before point."
|
|
1861 (save-excursion
|
|
1862 (skip-chars-forward " \t")
|
|
1863 (or
|
|
1864 ;; Trust the current indentation, if such info is applicable.
|
|
1865 (and virtual (>= (current-indentation) (current-column))
|
|
1866 (current-indentation))
|
|
1867 ;; Put leading close-paren where the matching open brace would be.
|
|
1868 (and (eq (latex-syntax-after) ?\))
|
|
1869 (ignore-errors
|
|
1870 (save-excursion
|
|
1871 (latex-skip-close-parens)
|
|
1872 (latex-backward-sexp-1)
|
|
1873 (latex-find-indent 'virtual))))
|
|
1874 ;; Default (maybe an argument)
|
|
1875 (let ((pos (point))
|
|
1876 (char (char-after))
|
|
1877 ;; Outdent \item if necessary.
|
|
1878 (indent (if (looking-at tex-indent-item-re) (- tex-indent-item) 0))
|
|
1879 up-list-pos)
|
|
1880 ;; Find the previous point which determines our current indentation.
|
|
1881 (condition-case err
|
|
1882 (progn
|
|
1883 (latex-backward-sexp-1)
|
|
1884 (while (> (current-column) (current-indentation))
|
|
1885 (latex-backward-sexp-1)))
|
|
1886 (scan-error
|
|
1887 (setq up-list-pos (nth 2 err))))
|
37952
|
1888 (cond
|
|
1889 ((= (point-min) pos) 0) ; We're really just indenting the first line.
|
|
1890 ((integerp up-list-pos)
|
|
1891 ;; Have to indent relative to the open-paren.
|
|
1892 (goto-char up-list-pos)
|
|
1893 (if (and (not tex-indent-allhanging)
|
|
1894 (> pos (progn (latex-down-list)
|
|
1895 (forward-comment (point-max))
|
|
1896 (point))))
|
|
1897 ;; Align with the first element after the open-paren.
|
|
1898 (current-column)
|
|
1899 ;; We're the first element after a hanging brace.
|
|
1900 (goto-char up-list-pos)
|
|
1901 (+ indent tex-indent-basic (latex-find-indent 'virtual))))
|
|
1902 ;; We're now at the "beginning" of a line.
|
|
1903 ((not (and (not virtual) (eq (char-after) ?\\)))
|
|
1904 ;; Nothing particular here: just keep the same indentation.
|
|
1905 (+ indent (current-column)))
|
|
1906 ;; We're now looking at a macro call.
|
|
1907 ((looking-at tex-indent-item-re)
|
|
1908 ;; Indenting relative to an item, have to re-add the outdenting.
|
|
1909 (+ indent (current-column) tex-indent-item))
|
|
1910 (t
|
|
1911 (let ((col (current-column)))
|
|
1912 (if (not (eq (char-syntax char) ?\())
|
|
1913 ;; If the first char was not an open-paren, there's
|
|
1914 ;; a risk that this is really not an argument to the
|
|
1915 ;; macro at all.
|
|
1916 (+ indent col)
|
|
1917 (forward-sexp 1)
|
|
1918 (if (< (line-end-position)
|
|
1919 (save-excursion (forward-comment (point-max))
|
|
1920 (point)))
|
|
1921 ;; we're indenting the first argument.
|
|
1922 (min (current-column) (+ tex-indent-arg col))
|
|
1923 (skip-syntax-forward " ")
|
|
1924 (current-column))))))))))
|
739
|
1925
|
|
1926 (run-hooks 'tex-mode-load-hook)
|
85
|
1927
|
584
|
1928 (provide 'tex-mode)
|
|
1929
|
657
|
1930 ;;; tex-mode.el ends here
|