657
|
1 ;;; tex-mode.el --- TeX, LaTeX, and SliTeX mode commands.
|
|
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
|
807
|
29 ;;; Code:
|
|
30
|
24273
|
31 ;; Pacify the byte-compiler
|
|
32 (eval-when-compile
|
|
33 (require 'compare-w)
|
|
34 (require 'skeleton))
|
|
35
|
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
|
36 (require 'shell)
|
2576
48318133e7a6
(tex-compilation-parse-errors): Added. At the moment, this would have
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
37 (require 'compile)
|
739
|
38
|
17435
|
39 (defgroup tex-file nil
|
|
40 "TeX files and directories"
|
|
41 :prefix "tex-"
|
|
42 :group 'tex)
|
|
43
|
|
44 (defgroup tex-run nil
|
|
45 "Running external commands from TeX mode"
|
|
46 :prefix "tex-"
|
|
47 :group 'tex)
|
|
48
|
|
49 (defgroup tex-view nil
|
|
50 "Viewing and printing TeX files"
|
|
51 :prefix "tex-"
|
|
52 :group 'tex)
|
85
|
53
|
957
|
54 ;;;###autoload
|
17435
|
55 (defcustom tex-shell-file-name nil
|
|
56 "*If non-nil, the shell file name to run in the subshell used to run TeX."
|
|
57 :type '(choice (const :tag "None" nil)
|
|
58 string)
|
|
59 :group 'tex-run)
|
|
60
|
|
61 ;;;###autoload
|
|
62 (defcustom tex-directory "."
|
15916
|
63 "*Directory in which temporary files are written.
|
7285
|
64 You can make this `/tmp' if your TEXINPUTS has no relative directories in it
|
739
|
65 and you don't try to apply \\[tex-region] or \\[tex-buffer] when there are
|
17435
|
66 `\\input' commands with relative directories."
|
|
67 :type 'directory
|
|
68 :group 'tex-file)
|
739
|
69
|
957
|
70 ;;;###autoload
|
17435
|
71 (defcustom tex-first-line-header-regexp nil
|
16777
|
72 "Regexp for matching a first line which `tex-region' should include.
|
|
73 If this is non-nil, it should be a regular expression string;
|
|
74 if it matches the first line of the file,
|
17435
|
75 `tex-region' always includes the first line in the TeX run."
|
|
76 :type '(choice (const :tag "None" nil)
|
|
77 regexp)
|
|
78 :group 'tex-file)
|
16777
|
79
|
|
80 ;;;###autoload
|
17435
|
81 (defcustom tex-main-file nil
|
15916
|
82 "*The main TeX source file which includes this buffer's file.
|
22847
|
83 The command `tex-file' runs TeX on the file specified by `tex-main-file'
|
|
84 if the variable is non-nil."
|
17435
|
85 :type '(choice (const :tag "None" nil)
|
|
86 file)
|
|
87 :group 'tex-file)
|
15916
|
88
|
|
89 ;;;###autoload
|
17435
|
90 (defcustom tex-offer-save t
|
|
91 "*If non-nil, ask about saving modified buffers before \\[tex-file] is run."
|
|
92 :type 'boolean
|
|
93 :group 'tex-file)
|
85
|
94
|
957
|
95 ;;;###autoload
|
17435
|
96 (defcustom tex-run-command "tex"
|
85
|
97 "*Command used to run TeX subjob.
|
24330
|
98 TeX Mode sets `tex-command' to this string.
|
|
99 See the documentation of that variable."
|
17435
|
100 :type 'string
|
|
101 :group 'tex-run)
|
85
|
102
|
957
|
103 ;;;###autoload
|
17435
|
104 (defcustom latex-run-command "latex"
|
85
|
105 "*Command used to run LaTeX subjob.
|
24330
|
106 LaTeX Mode sets `tex-command' to this string.
|
|
107 See the documentation of that variable."
|
17435
|
108 :type 'string
|
|
109 :group 'tex-run)
|
739
|
110
|
24273
|
111 ;;;###autoload
|
|
112 (defcustom slitex-run-command "slitex"
|
|
113 "*Command used to run SliTeX subjob.
|
24330
|
114 SliTeX Mode sets `tex-command' to this string.
|
|
115 See the documentation of that variable."
|
24273
|
116 :type 'string
|
|
117 :group 'tex-run)
|
|
118
|
24330
|
119 ;;;###autoload
|
|
120 (defcustom tex-start-options-string "\\nonstopmode\\input"
|
24273
|
121 "*TeX options to use when running TeX.
|
24330
|
122 These precede the input file name. If nil, TeX runs without option.
|
|
123 See the documentation of `tex-command'."
|
|
124 :type '(radio (const :tag "Interactive \(nil\)" nil)
|
|
125 (const :tag "Nonstop \(\"\\nonstopmode\\input\"\)"
|
|
126 "\\nonstopmode\\input")
|
|
127 (string :tag "String at your choice"))
|
24273
|
128 :group 'tex-run
|
|
129 :version "20.4")
|
|
130
|
739
|
131 (defvar standard-latex-block-names
|
24273
|
132 '("abstract" "array" "center" "description"
|
|
133 "displaymath" "document" "enumerate" "eqnarray"
|
|
134 "eqnarray*" "equation" "figure" "figure*"
|
|
135 "flushleft" "flushright" "itemize" "letter"
|
|
136 "list" "minipage" "picture" "quotation"
|
|
137 "quote" "slide" "sloppypar" "tabbing"
|
|
138 "table" "table*" "tabular" "tabular*"
|
|
139 "thebibliography" "theindex*" "titlepage" "trivlist"
|
|
140 "verbatim" "verbatim*" "verse")
|
739
|
141 "Standard LaTeX block names.")
|
|
142
|
957
|
143 ;;;###autoload
|
17435
|
144 (defcustom latex-block-names nil
|
739
|
145 "*User defined LaTeX block names.
|
17435
|
146 Combined with `standard-latex-block-names' for minibuffer completion."
|
|
147 :type '(repeat string)
|
|
148 :group 'tex-run)
|
85
|
149
|
957
|
150 ;;;###autoload
|
17435
|
151 (defcustom tex-bibtex-command "bibtex"
|
739
|
152 "*Command used by `tex-bibtex-file' to gather bibliographic data.
|
7285
|
153 If this string contains an asterisk (`*'), that is replaced by the file name;
|
17435
|
154 otherwise, the file name, preceded by blank, is added at the end."
|
|
155 :type 'string
|
|
156 :group 'tex-run)
|
85
|
157
|
957
|
158 ;;;###autoload
|
17435
|
159 (defcustom tex-dvi-print-command "lpr -d"
|
739
|
160 "*Command used by \\[tex-print] to print a .dvi file.
|
7285
|
161 If this string contains an asterisk (`*'), that is replaced by the file name;
|
17435
|
162 otherwise, the file name, preceded by blank, is added at the end."
|
|
163 :type 'string
|
|
164 :group 'tex-view)
|
739
|
165
|
957
|
166 ;;;###autoload
|
17435
|
167 (defcustom tex-alt-dvi-print-command "lpr -d"
|
739
|
168 "*Command used by \\[tex-print] with a prefix arg to print a .dvi file.
|
7285
|
169 If this string contains an asterisk (`*'), that is replaced by the file name;
|
|
170 otherwise, the file name, preceded by blank, is added at the end.
|
739
|
171
|
7285
|
172 If two printers are not enough of a choice, you can set the variable
|
|
173 `tex-alt-dvi-print-command' to an expression that asks what you want;
|
739
|
174 for example,
|
|
175
|
|
176 (setq tex-alt-dvi-print-command
|
|
177 '(format \"lpr -P%s\" (read-string \"Use printer: \")))
|
|
178
|
|
179 would tell \\[tex-print] with a prefix argument to ask you which printer to
|
17435
|
180 use."
|
|
181 :type '(choice (string :tag "Command")
|
|
182 (sexp :tag "Expression"))
|
|
183 :group 'tex-view)
|
85
|
184
|
957
|
185 ;;;###autoload
|
17435
|
186 (defcustom tex-dvi-view-command nil
|
7285
|
187 "*Command used by \\[tex-view] to display a `.dvi' file.
|
|
188 If this string contains an asterisk (`*'), that is replaced by the file name;
|
|
189 otherwise, the file name, preceded by blank, is added at the end.
|
739
|
190
|
|
191 This can be set conditionally so that the previewer used is suitable for the
|
|
192 window system being used. For example,
|
|
193
|
|
194 (setq tex-dvi-view-command
|
|
195 (if (eq window-system 'x) \"xdvi\" \"dvi2tty * | cat -s\"))
|
|
196
|
7285
|
197 would tell \\[tex-view] to use xdvi under X windows and to use dvi2tty
|
17435
|
198 otherwise."
|
|
199 :type '(choice (const nil) string)
|
|
200 :group 'tex-view)
|
85
|
201
|
957
|
202 ;;;###autoload
|
17435
|
203 (defcustom tex-show-queue-command "lpq"
|
739
|
204 "*Command used by \\[tex-show-print-queue] to show the print queue.
|
17435
|
205 Should show the queue(s) that \\[tex-print] puts jobs on."
|
|
206 :type 'string
|
|
207 :group 'tex-view)
|
85
|
208
|
957
|
209 ;;;###autoload
|
17435
|
210 (defcustom tex-default-mode 'plain-tex-mode
|
85
|
211 "*Mode to enter for a new file that might be either TeX or LaTeX.
|
|
212 This variable is used when it can't be determined whether the file
|
|
213 is plain TeX or LaTeX or what because the file contains no commands.
|
17435
|
214 Normally set to either `plain-tex-mode' or `latex-mode'."
|
|
215 :type 'function
|
|
216 :group 'tex)
|
85
|
217
|
957
|
218 ;;;###autoload
|
17435
|
219 (defcustom tex-open-quote "``"
|
|
220 "*String inserted by typing \\[tex-insert-quote] to open a quotation."
|
|
221 :type 'string
|
|
222 :group 'tex)
|
85
|
223
|
957
|
224 ;;;###autoload
|
17435
|
225 (defcustom tex-close-quote "''"
|
|
226 "*String inserted by typing \\[tex-insert-quote] to close a quotation."
|
|
227 :type 'string
|
|
228 :group 'tex)
|
85
|
229
|
739
|
230 (defvar tex-last-temp-file nil
|
|
231 "Latest temporary file generated by \\[tex-region] and \\[tex-buffer].
|
|
232 Deleted when the \\[tex-region] or \\[tex-buffer] is next run, or when the
|
7285
|
233 tex shell terminates.")
|
739
|
234
|
85
|
235 (defvar tex-command nil
|
24330
|
236 "*Command to run TeX.
|
|
237 If this string contains an asterisk \(`*'\), that is replaced by the file name\;
|
|
238 otherwise the \(shell-quoted\) value of `tex-start-options-string' and
|
|
239 the file name are added at the end, with blanks as separators.
|
|
240
|
|
241 In TeX, LaTeX, and SliTeX Mode this variable becomes buffer local.
|
|
242 In these modes, use \\[set-variable] if you want to change it for the
|
|
243 current buffer.")
|
85
|
244
|
|
245 (defvar tex-trailer nil
|
|
246 "String appended after the end of a region sent to TeX by \\[tex-region].")
|
|
247
|
|
248 (defvar tex-start-of-header nil
|
13248
|
249 "Regular expression used by \\[tex-region] to find start of file's header.")
|
85
|
250
|
|
251 (defvar tex-end-of-header nil
|
13248
|
252 "Regular expression used by \\[tex-region] to find end of file's header.")
|
85
|
253
|
|
254 (defvar tex-shell-cd-command "cd"
|
|
255 "Command to give to shell running TeX to change directory.
|
7285
|
256 The value of `tex-directory' is appended to this, separated by a space.")
|
85
|
257
|
|
258 (defvar tex-zap-file nil
|
|
259 "Temporary file name used for text being sent as input to TeX.
|
|
260 Should be a simple file name with no extension or directory specification.")
|
|
261
|
|
262 (defvar tex-last-buffer-texed nil
|
|
263 "Buffer which was last TeXed.")
|
|
264
|
|
265 (defvar tex-print-file nil
|
|
266 "File name that \\[tex-print] prints.
|
|
267 Set by \\[tex-region], \\[tex-buffer], and \\[tex-file].")
|
|
268
|
|
269 (defvar tex-mode-syntax-table nil
|
|
270 "Syntax table used while in TeX mode.")
|
|
271
|
18393
|
272 (defcustom latex-imenu-indent-string "."
|
|
273 "*String to add repeated in front of nested sectional units for Imenu.
|
|
274 An alternative value is \" . \", if you use a font with a narrow period."
|
|
275 :type 'string
|
|
276 :group 'tex)
|
|
277
|
15240
|
278 (defun latex-imenu-create-index ()
|
|
279 "Generates an alist for imenu from a LaTeX buffer."
|
18393
|
280 (let (i0 menu case-fold-search)
|
|
281 (save-excursion
|
|
282 ;; Find the top-most level in this file but don't allow it to be
|
|
283 ;; any deeper than "section" (which is top-level in an article).
|
|
284 (goto-char (point-min))
|
|
285 (if (search-forward-regexp "\\\\part\\*?[ \t]*{" nil t)
|
|
286 (setq i0 0)
|
|
287 (if (search-forward-regexp "\\\\chapter\\*?[ \t]*{" nil t)
|
|
288 (setq i0 1)
|
|
289 (setq i0 2)))
|
|
290
|
|
291 ;; Look for chapters and sections.
|
|
292 (goto-char (point-min))
|
|
293 (while (search-forward-regexp
|
|
294 "\\\\\\(part\\|chapter\\|section\\|subsection\\|\
|
|
295 subsubsection\\|paragraph\\|subparagraph\\)\\*?[ \t]*{" nil t)
|
|
296 (let ((start (match-beginning 0))
|
|
297 (here (point))
|
|
298 (i (cdr (assoc (buffer-substring-no-properties
|
|
299 (match-beginning 1)
|
|
300 (match-end 1))
|
|
301 '(("part" . 0) ("chapter" . 1)
|
|
302 ("section" . 2) ("subsection" . 3)
|
|
303 ("subsubsection" . 4)
|
|
304 ("paragraph" . 5) ("subparagraph" . 6))))))
|
|
305 (backward-char 1)
|
|
306 (condition-case err
|
|
307 (progn
|
|
308 ;; Using sexps allows some use of matching {...} inside
|
|
309 ;; titles.
|
|
310 (forward-sexp 1)
|
|
311 (setq menu
|
|
312 (cons (cons (concat (apply 'concat
|
|
313 (make-list
|
|
314 (max 0 (- i i0))
|
|
315 latex-imenu-indent-string))
|
|
316 (buffer-substring-no-properties
|
|
317 here (1- (point))))
|
|
318 start)
|
|
319 menu))
|
|
320 )
|
|
321 (error nil))))
|
|
322
|
|
323 ;; Look for included material.
|
|
324 (goto-char (point-min))
|
|
325 (while (search-forward-regexp
|
|
326 "\\\\\\(include\\|input\\|verbatiminput\\|bibliography\\)\
|
|
327 [ \t]*{\\([^}\n]+\\)}"
|
|
328 nil t)
|
|
329 (setq menu
|
|
330 (cons (cons (concat "<<" (buffer-substring-no-properties
|
|
331 (match-beginning 2)
|
|
332 (match-end 2))
|
|
333 (if (= (char-after (match-beginning 1)) ?b)
|
|
334 ".bbl"
|
|
335 ".tex"))
|
|
336 (match-beginning 0))
|
|
337 menu)))
|
|
338
|
|
339 ;; Look for \frontmatter, \mainmatter, \backmatter, and \appendix.
|
|
340 (goto-char (point-min))
|
|
341 (while (search-forward-regexp
|
|
342 "\\\\\\(frontmatter\\|mainmatter\\|backmatter\\|appendix\\)\\b"
|
|
343 nil t)
|
|
344 (setq menu
|
|
345 (cons (cons "--" (match-beginning 0))
|
|
346 menu)))
|
|
347
|
|
348 ;; Sort in increasing buffer position order.
|
|
349 (sort menu (function (lambda (a b) (< (cdr a) (cdr b))))))))
|
12704
|
350
|
85
|
351 (defun tex-define-common-keys (keymap)
|
7285
|
352 "Define the keys that we want defined both in TeX mode and in the TeX shell."
|
85
|
353 (define-key keymap "\C-c\C-k" 'tex-kill-job)
|
|
354 (define-key keymap "\C-c\C-l" 'tex-recenter-output-buffer)
|
|
355 (define-key keymap "\C-c\C-q" 'tex-show-print-queue)
|
|
356 (define-key keymap "\C-c\C-p" 'tex-print)
|
|
357 (define-key keymap "\C-c\C-v" 'tex-view)
|
4900
|
358
|
|
359 (define-key keymap [menu-bar tex] (cons "TeX" (make-sparse-keymap "TeX")))
|
|
360
|
|
361 (define-key keymap [menu-bar tex tex-kill-job] '("Tex Kill" . tex-kill-job))
|
4917
|
362 (define-key keymap [menu-bar tex tex-recenter-output-buffer]
|
|
363 '("Tex Recenter" . tex-recenter-output-buffer))
|
4900
|
364 (define-key keymap [menu-bar tex tex-show-print-queue]
|
|
365 '("Show Print Queue" . tex-show-print-queue))
|
4917
|
366 (define-key keymap [menu-bar tex tex-alt-print]
|
|
367 '("Tex Print (alt printer)" . tex-alt-print))
|
4900
|
368 (define-key keymap [menu-bar tex tex-print] '("Tex Print" . tex-print))
|
4917
|
369 (define-key keymap [menu-bar tex tex-view] '("Tex View" . tex-view))
|
85
|
370 )
|
|
371
|
|
372 (defvar tex-mode-map nil "Keymap for TeX mode.")
|
|
373
|
24273
|
374 (if tex-mode-map
|
85
|
375 nil
|
|
376 (setq tex-mode-map (make-sparse-keymap))
|
|
377 (tex-define-common-keys tex-mode-map)
|
|
378 (define-key tex-mode-map "\"" 'tex-insert-quote)
|
|
379 (define-key tex-mode-map "\n" 'tex-terminate-paragraph)
|
|
380 (define-key tex-mode-map "\C-c}" 'up-list)
|
|
381 (define-key tex-mode-map "\C-c{" 'tex-insert-braces)
|
|
382 (define-key tex-mode-map "\C-c\C-r" 'tex-region)
|
|
383 (define-key tex-mode-map "\C-c\C-b" 'tex-buffer)
|
|
384 (define-key tex-mode-map "\C-c\C-f" 'tex-file)
|
|
385 (define-key tex-mode-map "\C-c\C-i" 'tex-bibtex-file)
|
|
386 (define-key tex-mode-map "\C-c\C-o" 'tex-latex-block)
|
4917
|
387 (define-key tex-mode-map "\C-c\C-e" 'tex-close-latex-block)
|
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
|
388 (define-key tex-mode-map "\C-c\C-u" 'tex-goto-last-unclosed-latex-block)
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
389 (define-key tex-mode-map "\C-c\C-m" 'tex-feed-input)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
390 (define-key tex-mode-map [(control return)] 'tex-feed-input)
|
10296
|
391 (define-key tex-mode-map [menu-bar tex tex-bibtex-file]
|
|
392 '("BibTeX File" . tex-bibtex-file))
|
4917
|
393 (define-key tex-mode-map [menu-bar tex tex-validate-region]
|
|
394 '("Validate Region" . tex-validate-region))
|
24222
|
395 (define-key tex-mode-map [menu-bar tex tex-validate-buffer]
|
|
396 '("Validate Buffer" . tex-validate-buffer))
|
4917
|
397 (define-key tex-mode-map [menu-bar tex tex-region]
|
10296
|
398 '("TeX Region" . tex-region))
|
4917
|
399 (define-key tex-mode-map [menu-bar tex tex-buffer]
|
10296
|
400 '("TeX Buffer" . tex-buffer))
|
|
401 (define-key tex-mode-map [menu-bar tex tex-file] '("TeX File" . tex-file)))
|
4917
|
402
|
|
403 (put 'tex-region 'menu-enable 'mark-active)
|
|
404 (put 'tex-validate-region 'menu-enable 'mark-active)
|
|
405 (put 'tex-print 'menu-enable '(stringp tex-print-file))
|
|
406 (put 'tex-alt-print 'menu-enable '(stringp tex-print-file))
|
|
407 (put 'tex-view 'menu-enable '(stringp tex-print-file))
|
|
408 (put 'tex-recenter-output-buffer 'menu-enable '(get-buffer "*tex-shell*"))
|
|
409 (put 'tex-kill-job 'menu-enable '(tex-shell-running))
|
|
410
|
85
|
411 (defvar tex-shell-map nil
|
7285
|
412 "Keymap for the TeX shell.
|
10197
|
413 Inherits `shell-mode-map' with a few additions.")
|
85
|
414
|
14383
|
415 (defvar tex-face-alist
|
|
416 '((bold . "{\\bf ")
|
|
417 (italic . "{\\it ")
|
|
418 (bold-italic . "{\\bi ") ; hypothetical
|
|
419 (underline . "\\underline{")
|
|
420 (default . "{\\rm "))
|
|
421 "Alist of face and TeX font name for facemenu.")
|
|
422
|
|
423 (defvar tex-latex-face-alist
|
|
424 `((italic . "{\\em ")
|
|
425 ,@tex-face-alist)
|
|
426 "Alist of face and LaTeX font name for facemenu.")
|
|
427
|
85
|
428 ;;; This would be a lot simpler if we just used a regexp search,
|
|
429 ;;; but then it would be too slow.
|
256
|
430 ;;;###autoload
|
85
|
431 (defun tex-mode ()
|
|
432 "Major mode for editing files of input for TeX, LaTeX, or SliTeX.
|
|
433 Tries to determine (by looking at the beginning of the file) whether
|
7285
|
434 this file is for plain TeX, LaTeX, or SliTeX and calls `plain-tex-mode',
|
|
435 `latex-mode', or `slitex-mode', respectively. If it cannot be determined,
|
|
436 such as if there are no commands in the file, the value of `tex-default-mode'
|
|
437 says which mode to use."
|
85
|
438 (interactive)
|
|
439 (let (mode slash comment)
|
|
440 (save-excursion
|
|
441 (goto-char (point-min))
|
|
442 (while (and (setq slash (search-forward "\\" nil t))
|
|
443 (setq comment (let ((search-end (point)))
|
|
444 (save-excursion
|
|
445 (beginning-of-line)
|
|
446 (search-forward "%" search-end t))))))
|
|
447 (if (and slash (not comment))
|
10325
|
448 (setq mode (if (looking-at "documentstyle\\|documentclass\\|begin\\b\\|NeedsTeXFormat{LaTeX")
|
8553
090fb6dea9dd
(tex-mode): Allow for documentclass options when checking for SliTeX.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
449 (if (looking-at
|
090fb6dea9dd
(tex-mode): Allow for documentclass options when checking for SliTeX.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
450 "document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}")
|
85
|
451 'slitex-mode
|
|
452 'latex-mode)
|
|
453 'plain-tex-mode))))
|
|
454 (if mode (funcall mode)
|
|
455 (funcall tex-default-mode))))
|
2598
|
456
|
269
|
457 ;;;###autoload
|
2571
|
458 (defalias 'TeX-mode 'tex-mode)
|
269
|
459 ;;;###autoload
|
24330
|
460 (defalias 'plain-TeX-mode 'plain-tex-mode)
|
|
461 ;;;###autoload
|
2571
|
462 (defalias 'LaTeX-mode 'latex-mode)
|
85
|
463
|
256
|
464 ;;;###autoload
|
85
|
465 (defun plain-tex-mode ()
|
|
466 "Major mode for editing files of input for plain TeX.
|
|
467 Makes $ and } display the characters they match.
|
|
468 Makes \" insert `` when it seems to be the beginning of a quotation,
|
|
469 and '' when it appears to be the end; it inserts \" only after a \\.
|
|
470
|
|
471 Use \\[tex-region] to run TeX on the current region, plus a \"header\"
|
|
472 copied from the top of the file (containing macro definitions, etc.),
|
|
473 running TeX under a special subshell. \\[tex-buffer] does the whole buffer.
|
|
474 \\[tex-file] saves the buffer and then processes the file.
|
|
475 \\[tex-print] prints the .dvi file made by any of these.
|
|
476 \\[tex-view] previews the .dvi file made by any of these.
|
|
477 \\[tex-bibtex-file] runs bibtex on the file of the current buffer.
|
|
478
|
24222
|
479 Use \\[tex-validate-buffer] to check buffer for paragraphs containing
|
85
|
480 mismatched $'s or braces.
|
|
481
|
|
482 Special commands:
|
|
483 \\{tex-mode-map}
|
|
484
|
|
485 Mode variables:
|
|
486 tex-run-command
|
|
487 Command string used by \\[tex-region] or \\[tex-buffer].
|
|
488 tex-directory
|
|
489 Directory in which to create temporary files for TeX jobs
|
|
490 run by \\[tex-region] or \\[tex-buffer].
|
|
491 tex-dvi-print-command
|
|
492 Command string used by \\[tex-print] to print a .dvi file.
|
739
|
493 tex-alt-dvi-print-command
|
|
494 Alternative command string used by \\[tex-print] (when given a prefix
|
|
495 argument) to print a .dvi file.
|
85
|
496 tex-dvi-view-command
|
|
497 Command string used by \\[tex-view] to preview a .dvi file.
|
|
498 tex-show-queue-command
|
|
499 Command string used by \\[tex-show-print-queue] to show the print
|
|
500 queue that \\[tex-print] put your job on.
|
|
501
|
7285
|
502 Entering Plain-tex mode runs the hook `text-mode-hook', then the hook
|
|
503 `tex-mode-hook', and finally the hook `plain-tex-mode-hook'. When the
|
|
504 special subshell is initiated, the hook `tex-shell-hook' is run."
|
2588
|
505
|
85
|
506 (interactive)
|
|
507 (tex-common-initialization)
|
|
508 (setq mode-name "TeX")
|
|
509 (setq major-mode 'plain-tex-mode)
|
|
510 (setq tex-command tex-run-command)
|
13248
|
511 (setq tex-start-of-header "%\\*\\*start of header")
|
|
512 (setq tex-end-of-header "%\\*\\*end of header")
|
85
|
513 (setq tex-trailer "\\bye\n")
|
|
514 (run-hooks 'text-mode-hook 'tex-mode-hook 'plain-tex-mode-hook))
|
|
515
|
256
|
516 ;;;###autoload
|
85
|
517 (defun latex-mode ()
|
|
518 "Major mode for editing files of input for LaTeX.
|
|
519 Makes $ and } display the characters they match.
|
|
520 Makes \" insert `` when it seems to be the beginning of a quotation,
|
|
521 and '' when it appears to be the end; it inserts \" only after a \\.
|
|
522
|
|
523 Use \\[tex-region] to run LaTeX on the current region, plus the preamble
|
|
524 copied from the top of the file (containing \\documentstyle, etc.),
|
|
525 running LaTeX under a special subshell. \\[tex-buffer] does the whole buffer.
|
|
526 \\[tex-file] saves the buffer and then processes the file.
|
|
527 \\[tex-print] prints the .dvi file made by any of these.
|
|
528 \\[tex-view] previews the .dvi file made by any of these.
|
|
529 \\[tex-bibtex-file] runs bibtex on the file of the current buffer.
|
|
530
|
24222
|
531 Use \\[tex-validate-buffer] to check buffer for paragraphs containing
|
85
|
532 mismatched $'s or braces.
|
|
533
|
|
534 Special commands:
|
|
535 \\{tex-mode-map}
|
|
536
|
|
537 Mode variables:
|
|
538 latex-run-command
|
|
539 Command string used by \\[tex-region] or \\[tex-buffer].
|
|
540 tex-directory
|
|
541 Directory in which to create temporary files for LaTeX jobs
|
|
542 run by \\[tex-region] or \\[tex-buffer].
|
|
543 tex-dvi-print-command
|
|
544 Command string used by \\[tex-print] to print a .dvi file.
|
739
|
545 tex-alt-dvi-print-command
|
|
546 Alternative command string used by \\[tex-print] (when given a prefix
|
|
547 argument) to print a .dvi file.
|
85
|
548 tex-dvi-view-command
|
|
549 Command string used by \\[tex-view] to preview a .dvi file.
|
|
550 tex-show-queue-command
|
|
551 Command string used by \\[tex-show-print-queue] to show the print
|
|
552 queue that \\[tex-print] put your job on.
|
|
553
|
24273
|
554 Entering Latex mode runs the hook `text-mode-hook', then
|
7285
|
555 `tex-mode-hook', and finally `latex-mode-hook'. When the special
|
|
556 subshell is initiated, `tex-shell-hook' is run."
|
85
|
557 (interactive)
|
|
558 (tex-common-initialization)
|
|
559 (setq mode-name "LaTeX")
|
|
560 (setq major-mode 'latex-mode)
|
|
561 (setq tex-command latex-run-command)
|
13248
|
562 (setq tex-start-of-header "\\\\documentstyle\\|\\\\documentclass")
|
|
563 (setq tex-end-of-header "\\\\begin{document}")
|
85
|
564 (setq tex-trailer "\\end{document}\n")
|
5425
|
565 ;; A line containing just $$ is treated as a paragraph separator.
|
|
566 ;; A line starting with $$ starts a paragraph,
|
|
567 ;; but does not separate paragraphs if it has more stuff on it.
|
10898
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
568 (setq paragraph-start "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
569 \\\\begin\\>\\|\\\\label\\>\\|\\\\end\\>\\|\\\\\\[\\|\\\\\\]\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
570 \\\\chapter\\>\\|\\\\section\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
571 \\\\subsection\\>\\|\\\\subsubsection\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
572 \\\\paragraph\\>\\|\\\\subparagraph\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
573 \\\\item\\>\\|\\\\bibitem\\>\\|\\\\newline\\>\\|\\\\noindent\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
574 \\\\[a-z]*space\\>\\|\\\\[a-z]*skip\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
575 \\\\newpage\\>\\|\\\\[a-z]*page\\|\\\\footnote\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
576 \\\\marginpar\\>\\|\\\\parbox\\>\\|\\\\caption\\>")
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
577 (setq paragraph-separate "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$[ \t]*$\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
578 \\\\begin\\>\\|\\\\label\\>\\|\\\\end\\>\\|\\\\\\[\\|\\\\\\]\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
579 \\\\chapter\\>\\|\\\\section\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
580 \\\\subsection\\>\\|\\\\subsubsection\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
581 \\\\paragraph\\>\\|\\\\subparagraph\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
582 \\(\\\\item\\|\\\\bibitem\\|\\\\newline\\|\\\\noindent\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
583 \\\\[a-z]*space\\|\\\\[a-z]*skip\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
584 \\\\newpage\\|\\\\[a-z]*page[a-z]*\\|\\\\footnote\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
585 \\\\marginpar\\|\\\\parbox\\|\\\\caption\\)[ \t]*\\($\\|%\\)")
|
15240
|
586 (make-local-variable 'imenu-create-index-function)
|
|
587 (setq imenu-create-index-function 'latex-imenu-create-index)
|
14383
|
588 (make-local-variable 'tex-face-alist)
|
|
589 (setq tex-face-alist tex-latex-face-alist)
|
21121
|
590 (make-local-variable 'fill-nobreak-predicate)
|
|
591 (setq fill-nobreak-predicate 'latex-fill-nobreak-predicate)
|
85
|
592 (run-hooks 'text-mode-hook 'tex-mode-hook 'latex-mode-hook))
|
|
593
|
4768
|
594 ;;;###autoload
|
85
|
595 (defun slitex-mode ()
|
|
596 "Major mode for editing files of input for SliTeX.
|
|
597 Makes $ and } display the characters they match.
|
|
598 Makes \" insert `` when it seems to be the beginning of a quotation,
|
|
599 and '' when it appears to be the end; it inserts \" only after a \\.
|
|
600
|
|
601 Use \\[tex-region] to run SliTeX on the current region, plus the preamble
|
|
602 copied from the top of the file (containing \\documentstyle, etc.),
|
|
603 running SliTeX under a special subshell. \\[tex-buffer] does the whole buffer.
|
|
604 \\[tex-file] saves the buffer and then processes the file.
|
|
605 \\[tex-print] prints the .dvi file made by any of these.
|
|
606 \\[tex-view] previews the .dvi file made by any of these.
|
|
607 \\[tex-bibtex-file] runs bibtex on the file of the current buffer.
|
|
608
|
24222
|
609 Use \\[tex-validate-buffer] to check buffer for paragraphs containing
|
85
|
610 mismatched $'s or braces.
|
|
611
|
|
612 Special commands:
|
|
613 \\{tex-mode-map}
|
|
614
|
|
615 Mode variables:
|
|
616 slitex-run-command
|
|
617 Command string used by \\[tex-region] or \\[tex-buffer].
|
|
618 tex-directory
|
|
619 Directory in which to create temporary files for SliTeX jobs
|
|
620 run by \\[tex-region] or \\[tex-buffer].
|
|
621 tex-dvi-print-command
|
|
622 Command string used by \\[tex-print] to print a .dvi file.
|
739
|
623 tex-alt-dvi-print-command
|
|
624 Alternative command string used by \\[tex-print] (when given a prefix
|
|
625 argument) to print a .dvi file.
|
85
|
626 tex-dvi-view-command
|
|
627 Command string used by \\[tex-view] to preview a .dvi file.
|
|
628 tex-show-queue-command
|
|
629 Command string used by \\[tex-show-print-queue] to show the print
|
|
630 queue that \\[tex-print] put your job on.
|
|
631
|
7285
|
632 Entering SliTeX mode runs the hook `text-mode-hook', then the hook
|
|
633 `tex-mode-hook', then the hook `latex-mode-hook', and finally the hook
|
|
634 `slitex-mode-hook'. When the special subshell is initiated, the hook
|
|
635 `tex-shell-hook' is run."
|
85
|
636 (interactive)
|
|
637 (tex-common-initialization)
|
|
638 (setq mode-name "SliTeX")
|
|
639 (setq major-mode 'slitex-mode)
|
|
640 (setq tex-command slitex-run-command)
|
14383
|
641 (setq tex-start-of-header "\\\\documentstyle{slides}\\|\\\\documentclass{slides}")
|
13248
|
642 (setq tex-end-of-header "\\\\begin{document}")
|
85
|
643 (setq tex-trailer "\\end{document}\n")
|
5425
|
644 ;; A line containing just $$ is treated as a paragraph separator.
|
|
645 ;; A line starting with $$ starts a paragraph,
|
|
646 ;; but does not separate paragraphs if it has more stuff on it.
|
10898
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
647 (setq paragraph-start "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
648 \\\\begin\\>\\|\\\\label\\>\\|\\\\end\\>\\|\\\\\\[\\|\\\\\\]\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
649 \\\\chapter\\>\\|\\\\section\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
650 \\\\subsection\\>\\|\\\\subsubsection\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
651 \\\\paragraph\\>\\|\\\\subparagraph\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
652 \\\\item\\>\\|\\\\bibitem\\>\\|\\\\newline\\>\\|\\\\noindent\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
653 \\\\[a-z]*space\\>\\|\\\\[a-z]*skip\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
654 \\\\newpage\\>\\|\\\\[a-z]*page\\|\\\\footnote\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
655 \\\\marginpar\\>\\|\\\\parbox\\>\\|\\\\caption\\>")
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
656 (setq paragraph-separate "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$[ \t]*$\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
657 \\\\begin\\>\\|\\\\label\\>\\|\\\\end\\>\\|\\\\\\[\\|\\\\\\]\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
658 \\\\chapter\\>\\|\\\\section\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
659 \\\\subsection\\>\\|\\\\subsubsection\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
660 \\\\paragraph\\>\\|\\\\subparagraph\\>\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
661 \\\\item[ \t]*$\\|\\\\bibitem[ \t]*$\\|\\\\newline[ \t]*$\\|\\\\noindent[ \t]*$\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
662 \\\\[a-z]*space[ \t]*$\\|\\\\[a-z]*skip[ \t]*$\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
663 \\\\newpage[ \t]*$\\|\\\\[a-z]*page[a-z]*[ \t]*$\\|\\\\footnote[ \t]*$\\|\
|
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
664 \\\\marginpar[ \t]*$\\|\\\\parbox[ \t]*$\\|\\\\caption[ \t]*$")
|
21121
|
665 (make-local-variable 'imenu-create-index-function)
|
|
666 (setq imenu-create-index-function 'latex-imenu-create-index)
|
|
667 (make-local-variable 'tex-face-alist)
|
|
668 (setq tex-face-alist tex-latex-face-alist)
|
|
669 (make-local-variable 'fill-nobreak-predicate)
|
|
670 (setq fill-nobreak-predicate 'latex-fill-nobreak-predicate)
|
85
|
671 (run-hooks
|
|
672 'text-mode-hook 'tex-mode-hook 'latex-mode-hook 'slitex-mode-hook))
|
|
673
|
|
674 (defun tex-common-initialization ()
|
|
675 (kill-all-local-variables)
|
|
676 (use-local-map tex-mode-map)
|
|
677 (setq local-abbrev-table text-mode-abbrev-table)
|
|
678 (if (null tex-mode-syntax-table)
|
|
679 (let ((char 0))
|
|
680 (setq tex-mode-syntax-table (make-syntax-table))
|
|
681 (set-syntax-table tex-mode-syntax-table)
|
|
682 (while (< char ? )
|
|
683 (modify-syntax-entry char ".")
|
|
684 (setq char (1+ char)))
|
|
685 (modify-syntax-entry ?\C-@ "w")
|
|
686 (modify-syntax-entry ?\t " ")
|
|
687 (modify-syntax-entry ?\n ">")
|
|
688 (modify-syntax-entry ?\f ">")
|
|
689 (modify-syntax-entry ?$ "$$")
|
|
690 (modify-syntax-entry ?% "<")
|
|
691 (modify-syntax-entry ?\\ "/")
|
|
692 (modify-syntax-entry ?\" ".")
|
|
693 (modify-syntax-entry ?& ".")
|
|
694 (modify-syntax-entry ?_ ".")
|
|
695 (modify-syntax-entry ?@ "_")
|
|
696 (modify-syntax-entry ?~ " ")
|
|
697 (modify-syntax-entry ?' "w"))
|
|
698 (set-syntax-table tex-mode-syntax-table))
|
18587
|
699 ;; Regexp isearch should accept newline and formfeed as whitespace.
|
|
700 (make-local-variable 'search-whitespace-regexp)
|
|
701 (setq search-whitespace-regexp "[ \t\r\n\f]+")
|
85
|
702 (make-local-variable 'paragraph-start)
|
5262
|
703 ;; A line containing just $$ is treated as a paragraph separator.
|
10898
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
704 (setq paragraph-start "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$")
|
85
|
705 (make-local-variable 'paragraph-separate)
|
5425
|
706 ;; A line starting with $$ starts a paragraph,
|
|
707 ;; but does not separate paragraphs if it has more stuff on it.
|
10898
ebe3c755c5d9
(tex-common-initialization, latex-mode, slitex-mode): Remove ^ from
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
708 (setq paragraph-separate "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$[ \t]*$")
|
85
|
709 (make-local-variable 'comment-start)
|
|
710 (setq comment-start "%")
|
|
711 (make-local-variable 'comment-start-skip)
|
|
712 (setq comment-start-skip "\\(\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\)\\(%+ *\\)")
|
2307
|
713 (make-local-variable 'comment-indent-function)
|
|
714 (setq comment-indent-function 'tex-comment-indent)
|
5427
cde2cde50796
(tex-common-initialization): Make parse-sexp-ignore-comments t.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
715 (make-local-variable 'parse-sexp-ignore-comments)
|
cde2cde50796
(tex-common-initialization): Make parse-sexp-ignore-comments t.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
716 (setq parse-sexp-ignore-comments t)
|
85
|
717 (make-local-variable 'compare-windows-whitespace)
|
|
718 (setq compare-windows-whitespace 'tex-categorize-whitespace)
|
15513
|
719 (make-local-variable 'skeleton-further-elements)
|
|
720 (setq skeleton-further-elements
|
24273
|
721 '((indent-line-function 'indent-relative-maybe)))
|
14383
|
722 (make-local-variable 'facemenu-add-face-function)
|
|
723 (make-local-variable 'facemenu-end-add-face)
|
|
724 (make-local-variable 'facemenu-remove-face-function)
|
|
725 (setq facemenu-add-face-function
|
|
726 (lambda (face end)
|
|
727 (let ((face-text (cdr (assq face tex-face-alist))))
|
|
728 (if face-text
|
|
729 face-text
|
|
730 (error "Face %s not configured for %s mode" face mode-name))))
|
|
731 facemenu-end-add-face "}"
|
|
732 facemenu-remove-face-function t)
|
85
|
733 (make-local-variable 'tex-command)
|
|
734 (make-local-variable 'tex-start-of-header)
|
|
735 (make-local-variable 'tex-end-of-header)
|
|
736 (make-local-variable 'tex-trailer))
|
|
737
|
|
738 (defun tex-comment-indent ()
|
|
739 (if (looking-at "%%%")
|
|
740 (current-column)
|
|
741 (skip-chars-backward " \t")
|
|
742 (max (if (bolp) 0 (1+ (current-column)))
|
|
743 comment-column)))
|
|
744
|
|
745 (defun tex-categorize-whitespace (backward-limit)
|
|
746 ;; compare-windows-whitespace is set to this.
|
|
747 ;; This is basically a finite-state machine.
|
|
748 ;; Returns a symbol telling how TeX would treat
|
|
749 ;; the whitespace we are looking at: null, space, or par.
|
|
750 (let ((category 'null)
|
|
751 (not-finished t))
|
|
752 (skip-chars-backward " \t\n\f" backward-limit)
|
|
753 (while not-finished
|
|
754 (cond ((looking-at "[ \t]+")
|
|
755 (goto-char (match-end 0))
|
18931
|
756 (if (eq category 'null)
|
85
|
757 (setq category 'space)))
|
|
758 ((looking-at "\n")
|
18931
|
759 (cond ((eq category 'newline)
|
85
|
760 (setq category 'par)
|
|
761 (setq not-finished nil))
|
|
762 (t
|
|
763 (setq category 'newline) ;a strictly internal state
|
|
764 (goto-char (match-end 0)))))
|
|
765 ((looking-at "\f+")
|
|
766 (setq category 'par)
|
|
767 (setq not-finished nil))
|
|
768 (t
|
|
769 (setq not-finished nil))))
|
|
770 (skip-chars-forward " \t\n\f")
|
18931
|
771 (if (eq category 'newline)
|
85
|
772 'space ;TeX doesn't distinguish
|
|
773 category)))
|
|
774
|
|
775 (defun tex-insert-quote (arg)
|
|
776 "Insert the appropriate quote marks for TeX.
|
2836
|
777 Inserts the value of `tex-open-quote' (normally ``) or `tex-close-quote'
|
|
778 \(normally '') depending on the context. With prefix argument, always
|
85
|
779 inserts \" characters."
|
739
|
780 (interactive "*P")
|
85
|
781 (if arg
|
|
782 (self-insert-command (prefix-numeric-value arg))
|
|
783 (insert
|
|
784 (cond ((or (bobp)
|
|
785 (save-excursion
|
|
786 (forward-char -1)
|
|
787 (looking-at "\\s(\\|\\s \\|\\s>")))
|
|
788 tex-open-quote)
|
|
789 ((= (preceding-char) ?\\)
|
|
790 ?\")
|
|
791 (t
|
|
792 tex-close-quote)))))
|
|
793
|
24222
|
794 (defun tex-validate-buffer ()
|
|
795 "Check current buffer for paragraphs containing mismatched braces or $s.
|
4376
|
796 Their positions are recorded in the buffer `*Occur*'.
|
24222
|
797 To find a particular invalidity from `*Occur*', switch to that buffer
|
|
798 and type C-c C-c or click with mouse-2
|
|
799 on the line for the invalidity you want to see."
|
85
|
800 (interactive)
|
4376
|
801 (let ((buffer (current-buffer))
|
|
802 (prevpos (point-min))
|
24222
|
803 (linenum nil)
|
|
804 (num-matches 0))
|
4376
|
805 (with-output-to-temp-buffer "*Occur*"
|
|
806 (princ "Mismatches:\n")
|
|
807 (save-excursion
|
|
808 (set-buffer standard-output)
|
|
809 (occur-mode)
|
|
810 (setq occur-buffer buffer)
|
24222
|
811 (setq occur-nlines 0))
|
4376
|
812 (save-excursion
|
|
813 (goto-char (point-max))
|
85
|
814 (while (and (not (input-pending-p)) (not (bobp)))
|
15644
|
815 (let ((end (point))
|
|
816 prev-end)
|
4376
|
817 ;; Scan the previous paragraph for invalidities.
|
15644
|
818 (if (search-backward "\n\n" nil t)
|
|
819 (progn
|
|
820 (setq prev-end (point))
|
|
821 (forward-char 2))
|
|
822 (goto-char (setq prev-end (point-min))))
|
85
|
823 (or (tex-validate-region (point) end)
|
15644
|
824 (let* ((oend end)
|
|
825 (end (save-excursion (forward-line 1) (point)))
|
4376
|
826 start tem)
|
|
827 (beginning-of-line)
|
|
828 (setq start (point))
|
|
829 ;; Keep track of line number as we scan,
|
|
830 ;; in a cumulative fashion.
|
|
831 (if linenum
|
|
832 (setq linenum (- linenum (count-lines prevpos (point))))
|
|
833 (setq linenum (1+ (count-lines 1 start))))
|
|
834 (setq prevpos (point))
|
24273
|
835 ;; Mention this mismatch in *Occur*.
|
4376
|
836 ;; Since we scan from end of buffer to beginning,
|
24222
|
837 ;; add each mismatch at the beginning of *Occur*.
|
4376
|
838 (save-excursion
|
|
839 (setq tem (point-marker))
|
|
840 (set-buffer standard-output)
|
|
841 (goto-char (point-min))
|
|
842 ;; Skip "Mismatches:" header line.
|
|
843 (forward-line 1)
|
24222
|
844 (setq num-matches (1+ num-matches))
|
4376
|
845 (insert-buffer-substring buffer start end)
|
24222
|
846 (let (text-beg (text-end (point-marker)))
|
|
847 (forward-char (- start end))
|
|
848 (setq text-beg (point-marker))
|
|
849 (insert (format "%3d: " linenum))
|
|
850 (put-text-property (marker-position text-beg)
|
|
851 (- (marker-position text-end) 1)
|
|
852 'mouse-face 'highlight)
|
|
853 (put-text-property (marker-position text-beg)
|
|
854 (- (marker-position text-end) 1)
|
|
855 'occur tem)))))
|
15644
|
856 (goto-char prev-end))))
|
4376
|
857 (save-excursion
|
|
858 (set-buffer standard-output)
|
24222
|
859 (if (eq num-matches 0)
|
4376
|
860 (insert "None!\n"))
|
|
861 (if (interactive-p)
|
24222
|
862 (message "%d mismatches found" num-matches))))))
|
85
|
863
|
|
864 (defun tex-validate-region (start end)
|
|
865 "Check for mismatched braces or $'s in region.
|
|
866 Returns t if no mismatches. Returns nil and moves point to suspect
|
|
867 area if a mismatch is found."
|
|
868 (interactive "r")
|
|
869 (let ((failure-point nil) (max-possible-sexps (- end start)))
|
|
870 (save-excursion
|
|
871 (condition-case ()
|
|
872 (save-restriction
|
|
873 (narrow-to-region start end)
|
20203
|
874 ;; First check that the open and close parens balance in numbers.
|
85
|
875 (goto-char start)
|
24222
|
876 (while (<= 0 (setq max-possible-sexps (1- max-possible-sexps)))
|
20203
|
877 (forward-sexp 1))
|
|
878 ;; Now check that like matches like.
|
|
879 (goto-char start)
|
|
880 (while (progn (skip-syntax-forward "^(")
|
|
881 (not (eobp)))
|
|
882 (let ((match (matching-paren (following-char))))
|
|
883 (save-excursion
|
|
884 (forward-sexp 1)
|
|
885 (or (= (preceding-char) match)
|
|
886 (error "Mismatched parentheses"))))
|
|
887 (forward-char 1)))
|
85
|
888 (error
|
24273
|
889 (skip-syntax-forward " .>")
|
|
890 (setq failure-point (point)))))
|
85
|
891 (if failure-point
|
|
892 (progn
|
|
893 (goto-char failure-point)
|
|
894 nil)
|
|
895 t)))
|
|
896
|
|
897 (defun tex-terminate-paragraph (inhibit-validation)
|
|
898 "Insert two newlines, breaking a paragraph for TeX.
|
7285
|
899 Check for mismatched braces or $s in paragraph being terminated.
|
85
|
900 A prefix arg inhibits the checking."
|
739
|
901 (interactive "*P")
|
85
|
902 (or inhibit-validation
|
|
903 (save-excursion
|
|
904 (tex-validate-region
|
24273
|
905 (save-excursion
|
|
906 (search-backward "\n\n" nil 'move)
|
|
907 (point))
|
|
908 (point)))
|
85
|
909 (message "Paragraph being closed appears to contain a mismatch"))
|
|
910 (insert "\n\n"))
|
|
911
|
|
912 (defun tex-insert-braces ()
|
|
913 "Make a pair of braces and be poised to type inside of them."
|
739
|
914 (interactive "*")
|
85
|
915 (insert ?\{)
|
|
916 (save-excursion
|
|
917 (insert ?})))
|
|
918
|
21121
|
919 ;; This function is used as the value of fill-nobreak-predicate
|
|
920 ;; in LaTeX mode. Its job is to prevent line-breaking inside
|
|
921 ;; of a \verb construct.
|
|
922 (defun latex-fill-nobreak-predicate ()
|
|
923 (let ((opoint (point))
|
|
924 inside)
|
24273
|
925 (save-excursion
|
21121
|
926 (save-restriction
|
|
927 (beginning-of-line)
|
|
928 (narrow-to-region (point) opoint)
|
|
929 (while (re-search-forward "\\\\verb\\(.\\)" nil t)
|
|
930 (unless (re-search-forward (regexp-quote (match-string 1)) nil t)
|
|
931 (setq inside t)))))
|
|
932 inside))
|
|
933
|
85
|
934 ;;; Like tex-insert-braces, but for LaTeX.
|
15513
|
935 (define-skeleton tex-latex-block
|
|
936 "Create a matching pair of lines \\begin[OPT]{NAME} and \\end{NAME} at point.
|
85
|
937 Puts point on a blank line between them."
|
15513
|
938 (completing-read "LaTeX block name: "
|
|
939 (mapcar 'list
|
|
940 (append standard-latex-block-names
|
|
941 latex-block-names)))
|
|
942 "\\begin["
|
|
943 (skeleton-read "[options]: ") & ?\] | -1
|
|
944 ?\{
|
|
945 str
|
|
946 ?\} \n
|
|
947 _ \n
|
|
948 "\\end{" str ?\})
|
85
|
949
|
|
950 (defun tex-last-unended-begin ()
|
7285
|
951 "Leave point at the beginning of the last `\\begin{...}' that is unended."
|
85
|
952 (while (and (re-search-backward "\\(\\\\begin\\s *{\\)\\|\\(\\\\end\\s *{\\)")
|
|
953 (looking-at "\\\\end{"))
|
|
954 (tex-last-unended-begin)))
|
|
955
|
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
|
956 (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
|
957 "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
|
958 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
|
959 (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
|
960 (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
|
961 (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
|
962 (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
|
963 (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
|
964 (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
|
965 (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
|
966 (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
|
967 (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
|
968
|
85
|
969 (defun tex-close-latex-block ()
|
|
970 "Creates an \\end{...} to match the last unclosed \\begin{...}."
|
|
971 (interactive "*")
|
|
972 (let ((new-line-needed (bolp))
|
|
973 text indentation)
|
|
974 (save-excursion
|
739
|
975 (condition-case nil
|
85
|
976 (tex-last-unended-begin)
|
|
977 (error (error "Couldn't find unended \\begin")))
|
|
978 (setq indentation (current-column))
|
|
979 (re-search-forward "\\\\begin\\(\\s *{[^}\n]*}\\)")
|
|
980 (setq text (buffer-substring (match-beginning 1) (match-end 1))))
|
|
981 (indent-to indentation)
|
|
982 (insert "\\end" text)
|
|
983 (if new-line-needed (insert ?\n))))
|
|
984
|
|
985 ;;; Invoking TeX in an inferior shell.
|
|
986
|
|
987 ;;; Why use a shell instead of running TeX directly? Because if TeX
|
|
988 ;;; gets stuck, the user can switch to the shell window and type at it.
|
|
989
|
|
990 ;;; The utility functions:
|
|
991
|
7834
|
992 ;;;###autoload
|
85
|
993 (defun tex-start-shell ()
|
|
994 (save-excursion
|
739
|
995 (set-buffer
|
|
996 (make-comint
|
|
997 "tex-shell"
|
|
998 (or tex-shell-file-name (getenv "ESHELL") (getenv "SHELL") "/bin/sh")
|
5087
|
999 nil))
|
739
|
1000 (let ((proc (get-process "tex-shell")))
|
|
1001 (set-process-sentinel proc 'tex-shell-sentinel)
|
|
1002 (process-kill-without-query proc)
|
10190
2569f4d3073e
Be consistent in use of comint (instead of shell) mode.
Edward M. Reingold <reingold@emr.cs.iit.edu>
diff
changeset
|
1003 (setq comint-prompt-regexp shell-prompt-pattern)
|
10204
|
1004 (setq tex-shell-map (nconc (make-sparse-keymap) shell-mode-map))
|
739
|
1005 (tex-define-common-keys tex-shell-map)
|
|
1006 (use-local-map tex-shell-map)
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1007 (compilation-shell-minor-mode t)
|
24527
|
1008 (add-hook 'comint-input-filter-functions 'shell-directory-tracker nil t)
|
|
1009 (make-local-variable 'list-buffers-directory)
|
|
1010 (make-local-variable 'shell-dirstack)
|
|
1011 (make-local-variable 'shell-last-dir)
|
|
1012 (make-local-variable 'shell-dirtrackp)
|
739
|
1013 (run-hooks 'tex-shell-hook)
|
|
1014 (while (zerop (buffer-size))
|
10572
|
1015 (sleep-for 1)))))
|
|
1016
|
23761
|
1017 (defun tex-feed-input ()
|
|
1018 "Send input to the tex shell process.
|
|
1019 In the tex buffer this can be used to continue an interactive tex run.
|
24273
|
1020 In the tex shell buffer this command behaves like `comint-send-input'."
|
23761
|
1021 (interactive)
|
|
1022 (set-buffer (process-buffer (get-process "tex-shell")))
|
|
1023 (comint-send-input)
|
|
1024 (tex-recenter-output-buffer nil))
|
|
1025
|
10572
|
1026 (defun tex-display-shell ()
|
|
1027 "Make the TeX shell buffer visible in a window."
|
|
1028 (display-buffer (process-buffer (get-process "tex-shell")))
|
|
1029 (tex-recenter-output-buffer nil))
|
85
|
1030
|
739
|
1031 (defun tex-shell-sentinel (proc msg)
|
|
1032 (cond ((null (buffer-name (process-buffer proc)))
|
|
1033 ;; buffer killed
|
|
1034 (set-process-buffer proc nil)
|
|
1035 (tex-delete-last-temp-files))
|
|
1036 ((memq (process-status proc) '(signal exit))
|
|
1037 (tex-delete-last-temp-files))))
|
|
1038
|
|
1039 (defun tex-set-buffer-directory (buffer directory)
|
85
|
1040 "Set BUFFER's default directory to be DIRECTORY."
|
|
1041 (setq directory (file-name-as-directory (expand-file-name directory)))
|
|
1042 (if (not (file-directory-p directory))
|
|
1043 (error "%s is not a directory" directory)
|
|
1044 (save-excursion
|
|
1045 (set-buffer buffer)
|
|
1046 (setq default-directory directory))))
|
|
1047
|
5088
|
1048 (defvar tex-send-command-modified-tick 0)
|
|
1049 (make-variable-buffer-local 'tex-send-command-modified-tick)
|
|
1050
|
739
|
1051 (defun tex-send-command (command &optional file background)
|
5087
|
1052 "Send COMMAND to TeX shell process, substituting optional FILE for *.
|
2588
|
1053 Do this in background if optional BACKGROUND is t. If COMMAND has no *,
|
|
1054 FILE will be appended, preceded by a blank, to COMMAND. If FILE is nil, no
|
|
1055 substitution will be made in COMMAND. COMMAND can be any expression that
|
21314
|
1056 evaluates to a command string.
|
|
1057
|
|
1058 Return the process in which TeX is running."
|
739
|
1059 (save-excursion
|
|
1060 (let* ((cmd (eval command))
|
13399
|
1061 (proc (or (get-process "tex-shell") (error "No TeX subprocess")))
|
5262
|
1062 (buf (process-buffer proc))
|
2265
|
1063 (star (string-match "\\*" cmd))
|
5087
|
1064 (string
|
|
1065 (concat
|
|
1066 (if file
|
|
1067 (if star (concat (substring cmd 0 star)
|
|
1068 file (substring cmd (1+ star)))
|
|
1069 (concat cmd " " file))
|
|
1070 cmd)
|
|
1071 (if background "&" ""))))
|
5262
|
1072 ;; Switch to buffer before checking for subproc output in it.
|
|
1073 (set-buffer buf)
|
5088
|
1074 ;; If text is unchanged since previous tex-send-command,
|
|
1075 ;; we haven't got any output. So wait for output now.
|
5262
|
1076 (if (= (buffer-modified-tick buf) tex-send-command-modified-tick)
|
5088
|
1077 (accept-process-output proc))
|
5087
|
1078 (goto-char (process-mark proc))
|
|
1079 (insert string)
|
5088
|
1080 (comint-send-input)
|
21314
|
1081 (setq tex-send-command-modified-tick (buffer-modified-tick buf))
|
|
1082 proc)))
|
85
|
1083
|
6479
|
1084 (defun tex-delete-last-temp-files (&optional not-all)
|
|
1085 "Delete any junk files from last temp file.
|
|
1086 If NOT-ALL is non-nil, save the `.dvi' file."
|
739
|
1087 (if tex-last-temp-file
|
|
1088 (let* ((dir (file-name-directory tex-last-temp-file))
|
7536
|
1089 (list (and (file-directory-p dir)
|
|
1090 (file-name-all-completions
|
22707
|
1091 (file-name-sans-extension
|
|
1092 (file-name-nondirectory tex-last-temp-file))
|
|
1093 dir))))
|
7536
|
1094 (while list
|
6479
|
1095 (if not-all
|
|
1096 (and
|
|
1097 ;; If arg is non-nil, don't delete the .dvi file.
|
|
1098 (not (string-match "\\.dvi$" (car list)))
|
|
1099 (delete-file (concat dir (car list))))
|
|
1100 (delete-file (concat dir (car list))))
|
739
|
1101 (setq list (cdr list))))))
|
|
1102
|
741
|
1103 (add-hook 'kill-emacs-hook 'tex-delete-last-temp-files)
|
739
|
1104
|
21314
|
1105 (defvar tex-start-tex-marker nil
|
|
1106 "Marker pointing after last TeX-running command in the TeX shell buffer.")
|
|
1107
|
|
1108 (defun tex-start-tex (command file)
|
|
1109 "Start a TeX run, using COMMAND on FILE."
|
23322
|
1110 (let* ((star (string-match "\\*" command))
|
21314
|
1111 (compile-command
|
23322
|
1112 (if star
|
|
1113 (concat (substring command 0 star)
|
|
1114 (comint-quote-filename file)
|
|
1115 (substring command (1+ star)))
|
|
1116 (concat command " "
|
24330
|
1117 (if (< 0 (length tex-start-options-string))
|
|
1118 (concat
|
|
1119 (shell-quote-argument tex-start-options-string) " "))
|
23322
|
1120 (comint-quote-filename file)))))
|
21314
|
1121 (with-current-buffer (process-buffer (tex-send-command compile-command))
|
|
1122 (save-excursion
|
|
1123 (forward-line -1)
|
|
1124 (setq tex-start-tex-marker (point-marker)))
|
|
1125 (make-local-variable 'compilation-parse-errors-function)
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1126 (setq compilation-parse-errors-function 'tex-compilation-parse-errors)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1127 (compilation-forget-errors))))
|
21314
|
1128
|
|
1129 (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
|
1130 "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
|
1131 See the variable `compilation-parse-errors-function' for the interface it uses.
|
21314
|
1132
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1133 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
|
1134 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
|
1135 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
|
1136 for the error messages."
|
21314
|
1137 (require 'thingatpt)
|
|
1138 (setq compilation-error-list nil)
|
|
1139 (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
|
1140 (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
|
1141 (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
|
1142 (old-syntax-table (syntax-table))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1143 (tex-error-parse-syntax-table (copy-syntax-table (syntax-table)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1144 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
|
1145 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
|
1146 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
|
1147 (modify-syntax-entry ?\{ "_" tex-error-parse-syntax-table)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1148 (modify-syntax-entry ?\} "_" tex-error-parse-syntax-table)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1149 (modify-syntax-entry ?\[ "_" tex-error-parse-syntax-table)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1150 (modify-syntax-entry ?\] "_" tex-error-parse-syntax-table)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1151 ;; Single quotations may appear in errors
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1152 (modify-syntax-entry ?\" "_" tex-error-parse-syntax-table)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1153 ;; Don't parse previous compilations.
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1154 (setq compilation-parsing-end
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1155 (max compilation-parsing-end tex-start-tex-marker))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1156 ;; 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
|
1157 (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
|
1158 ;; Parse messages.
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1159 (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
|
1160 (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
|
1161 (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
|
1162 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
|
1163 (re-search-forward
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1164 "^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
|
1165 (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
|
1166 (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
|
1167 (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
|
1168 (filename
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1169 (save-excursion
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1170 (unwind-protect
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1171 (progn
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1172 (set-syntax-table tex-error-parse-syntax-table)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1173 (backward-up-list 1)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1174 (skip-syntax-forward "(_")
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1175 (while (not (file-readable-p
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1176 (thing-at-point 'filename)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1177 (skip-syntax-backward "(_")
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1178 (backward-up-list 1)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1179 (skip-syntax-forward "(_"))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1180 (thing-at-point 'filename))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1181 (set-syntax-table old-syntax-table))))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1182 (new-file
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1183 (or (null last-filename)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1184 (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
|
1185 (error-location
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1186 (save-excursion
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1187 (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
|
1188 (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
|
1189 (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
|
1190 (if new-file
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1191 (goto-line linenum)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1192 (goto-char last-position)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1193 (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
|
1194 ;; 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
|
1195 ;; 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
|
1196 (let ((starting-point (point)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1197 (or (re-search-forward error-text nil t)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1198 (re-search-backward
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1199 error-text
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1200 (marker-position last-position) t)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1201 (goto-char starting-point)))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1202 (point-marker))))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1203 (goto-char this-error)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1204 (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
|
1205 (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
|
1206 (>= num-errors-found
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1207 find-at-least))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1208 (and limit-search
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1209 (>= 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
|
1210 new-file)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1211 (setq found-desired t)
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1212 (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
|
1213 last-filename filename
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1214 last-linenum linenum
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1215 last-position error-location
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1216 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
|
1217 (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
|
1218 compilation-error-list))
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1219 (goto-char end-of-error)))))
|
21314
|
1220 (setq 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
|
1221 (setq compilation-error-list (nreverse compilation-error-list))
|
21314
|
1222 (message "Parsing error messages...done"))
|
|
1223
|
739
|
1224 ;;; The commands:
|
85
|
1225
|
|
1226 (defun tex-region (beg end)
|
|
1227 "Run TeX on the current region, via a temporary file.
|
|
1228 The file's name comes from the variable `tex-zap-file' and the
|
|
1229 variable `tex-directory' says where to put it.
|
|
1230
|
|
1231 If the buffer has a header, the header is given to TeX before the
|
|
1232 region itself. The buffer's header is all lines between the strings
|
|
1233 defined by `tex-start-of-header' and `tex-end-of-header' inclusive.
|
|
1234 The header must start in the first 100 lines of the buffer.
|
|
1235
|
|
1236 The value of `tex-trailer' is given to TeX as input after the region.
|
|
1237
|
|
1238 The value of `tex-command' specifies the command to use to run TeX."
|
|
1239 (interactive "r")
|
|
1240 (if (tex-shell-running)
|
|
1241 (tex-kill-job)
|
|
1242 (tex-start-shell))
|
|
1243 (or tex-zap-file
|
|
1244 (setq tex-zap-file (tex-generate-zap-file-name)))
|
16807
|
1245 ;; Temp file will be written and TeX will be run in zap-directory.
|
|
1246 ;; If the TEXINPUTS file has relative directories or if the region has
|
|
1247 ;; \input of files, this must be the same directory as the file for
|
|
1248 ;; TeX to access the correct inputs. That's why it's safest if
|
|
1249 ;; tex-directory is ".".
|
|
1250 (let* ((zap-directory
|
739
|
1251 (file-name-as-directory (expand-file-name tex-directory)))
|
16807
|
1252 (tex-out-file (concat zap-directory tex-zap-file ".tex")))
|
9450
|
1253 ;; Don't delete temp files if we do the same buffer twice in a row.
|
|
1254 (or (eq (current-buffer) tex-last-buffer-texed)
|
|
1255 (tex-delete-last-temp-files t))
|
85
|
1256 ;; Write the new temp file.
|
|
1257 (save-excursion
|
|
1258 (save-restriction
|
|
1259 (widen)
|
|
1260 (goto-char (point-min))
|
|
1261 (forward-line 100)
|
|
1262 (let ((search-end (point))
|
16807
|
1263 (default-directory zap-directory)
|
|
1264 (already-output 0))
|
85
|
1265 (goto-char (point-min))
|
16807
|
1266
|
16777
|
1267 ;; Maybe copy first line, such as `\input texinfo', to temp file.
|
|
1268 (and tex-first-line-header-regexp
|
|
1269 (looking-at tex-first-line-header-regexp)
|
24273
|
1270 (write-region (point)
|
16807
|
1271 (progn (forward-line 1)
|
|
1272 (setq already-output (point)))
|
16777
|
1273 tex-out-file nil nil))
|
|
1274
|
16807
|
1275 ;; Write out the header, if there is one,
|
|
1276 ;; and any of the specified region which extends before it.
|
|
1277 ;; But don't repeat anything already written.
|
13248
|
1278 (if (re-search-forward tex-start-of-header search-end t)
|
16807
|
1279 (let (hbeg)
|
85
|
1280 (beginning-of-line)
|
|
1281 (setq hbeg (point)) ;mark beginning of header
|
13248
|
1282 (if (re-search-forward tex-end-of-header nil t)
|
16807
|
1283 (let (hend)
|
|
1284 (forward-line 1)
|
24273
|
1285 (setq hend (point)) ;mark end of header
|
16807
|
1286 (write-region (max (min hbeg beg) already-output)
|
|
1287 hend
|
|
1288 tex-out-file
|
|
1289 (not (zerop already-output)) nil)
|
|
1290 (setq already-output hend)))))
|
|
1291
|
|
1292 ;; Write out the specified region
|
|
1293 ;; (but don't repeat anything already written).
|
|
1294 (write-region (max beg already-output) end
|
|
1295 tex-out-file
|
|
1296 (not (zerop already-output)) nil))
|
|
1297 ;; Write the trailer, if any.
|
|
1298 ;; Precede it with a newline to make sure it
|
|
1299 ;; is not hidden in a comment.
|
|
1300 (if tex-trailer
|
|
1301 (write-region (concat "\n" tex-trailer) nil
|
|
1302 tex-out-file t nil))))
|
739
|
1303 ;; Record the file name to be deleted afterward.
|
|
1304 (setq tex-last-temp-file tex-out-file)
|
24222
|
1305 (let (shell-dirtrack-verbose)
|
|
1306 (tex-send-command tex-shell-cd-command zap-directory))
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1307 ;; 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
|
1308 ;; 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
|
1309 ;; too long and can make tex crash.
|
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1310 (tex-start-tex tex-command (concat tex-zap-file ".tex"))
|
10572
|
1311 (tex-display-shell)
|
739
|
1312 (setq tex-print-file tex-out-file)
|
|
1313 (setq tex-last-buffer-texed (current-buffer))))
|
85
|
1314
|
|
1315 (defun tex-buffer ()
|
|
1316 "Run TeX on current buffer. See \\[tex-region] for more information.
|
739
|
1317 Does not save the buffer, so it's useful for trying experimental versions.
|
|
1318 See \\[tex-file] for an alternative."
|
85
|
1319 (interactive)
|
|
1320 (tex-region (point-min) (point-max)))
|
|
1321
|
|
1322 (defun tex-file ()
|
|
1323 "Prompt to save all buffers and run TeX (or LaTeX) on current buffer's file.
|
|
1324 This function is more useful than \\[tex-buffer] when you need the
|
|
1325 `.aux' file of LaTeX to have the correct name."
|
|
1326 (interactive)
|
15916
|
1327 (let ((source-file
|
24273
|
1328 (or tex-main-file
|
15916
|
1329 (if (buffer-file-name)
|
|
1330 (file-name-nondirectory (buffer-file-name))
|
|
1331 (error "Buffer does not seem to be associated with any file"))))
|
85
|
1332 (file-dir (file-name-directory (buffer-file-name))))
|
758
|
1333 (if tex-offer-save
|
741
|
1334 (save-some-buffers))
|
85
|
1335 (if (tex-shell-running)
|
|
1336 (tex-kill-job)
|
|
1337 (tex-start-shell))
|
24222
|
1338 (let (shell-dirtrack-verbose)
|
|
1339 (tex-send-command tex-shell-cd-command file-dir))
|
21314
|
1340 (tex-start-tex tex-command source-file)
|
16493
|
1341 (tex-display-shell)
|
|
1342 (setq tex-last-buffer-texed (current-buffer))
|
24129
18c751deec0d
(tex-define-common-keys): Remove key binding of tex-feed-input.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1343 (setq tex-print-file (expand-file-name source-file))))
|
85
|
1344
|
|
1345 (defun tex-generate-zap-file-name ()
|
|
1346 "Generate a unique name suitable for use as a file name."
|
|
1347 ;; Include the shell process number and host name
|
|
1348 ;; in case there are multiple shells (for same or different user).
|
23849
|
1349 ;; Dec 1998: There is a report that some versions of xdvi
|
|
1350 ;; don't work with file names that start with #.
|
24109
|
1351 (format "_TZ_%d-%s"
|
85
|
1352 (process-id (get-buffer-process "*tex-shell*"))
|
|
1353 (tex-strip-dots (system-name))))
|
|
1354
|
|
1355 (defun tex-strip-dots (s)
|
|
1356 (setq s (copy-sequence s))
|
|
1357 (while (string-match "\\." s)
|
|
1358 (aset s (match-beginning 0) ?-))
|
|
1359 s)
|
|
1360
|
|
1361 ;; This will perhaps be useful for modifying TEXINPUTS.
|
|
1362 ;; Expand each file name, separated by colons, in the string S.
|
|
1363 (defun tex-expand-files (s)
|
|
1364 (let (elts (start 0))
|
|
1365 (while (string-match ":" s start)
|
|
1366 (setq elts (cons (substring s start (match-beginning 0)) elts))
|
|
1367 (setq start (match-end 0)))
|
|
1368 (or (= start 0)
|
|
1369 (setq elts (cons (substring s start) elts)))
|
24109
|
1370 (mapconcat '(lambda (elt)
|
|
1371 (if (= (length elt) 0) elt (expand-file-name elt)))
|
|
1372 (nreverse elts) ":")))
|
85
|
1373
|
|
1374 (defun tex-shell-running ()
|
|
1375 (and (get-process "tex-shell")
|
|
1376 (eq (process-status (get-process "tex-shell")) 'run)))
|
|
1377
|
|
1378 (defun tex-kill-job ()
|
|
1379 "Kill the currently running TeX job."
|
|
1380 (interactive)
|
24273
|
1381 ;; quit-process leads to core dumps of the tex process (except if
|
|
1382 ;; coredumpsize has limit 0kb as on many environments). One would
|
|
1383 ;; like to use (kill-process proc 'lambda), however that construct
|
|
1384 ;; does not work on some systems and kills the shell itself.
|
739
|
1385 (quit-process (get-process "tex-shell") t))
|
85
|
1386
|
|
1387 (defun tex-recenter-output-buffer (linenum)
|
|
1388 "Redisplay buffer of TeX job output so that most recent output can be seen.
|
|
1389 The last line of the buffer is displayed on
|
|
1390 line LINE of the window, or centered if LINE is nil."
|
|
1391 (interactive "P")
|
|
1392 (let ((tex-shell (get-buffer "*tex-shell*"))
|
16493
|
1393 (old-buffer (current-buffer))
|
|
1394 (window))
|
85
|
1395 (if (null tex-shell)
|
|
1396 (message "No TeX output buffer")
|
16493
|
1397 (setq window (display-buffer tex-shell))
|
|
1398 (save-selected-window
|
|
1399 (select-window window)
|
|
1400 (bury-buffer tex-shell)
|
|
1401 (goto-char (point-max))
|
|
1402 (recenter (if linenum
|
|
1403 (prefix-numeric-value linenum)
|
|
1404 (/ (window-height) 2)))))))
|
85
|
1405
|
739
|
1406 (defun tex-print (&optional alt)
|
85
|
1407 "Print the .dvi file made by \\[tex-region], \\[tex-buffer] or \\[tex-file].
|
1577
|
1408 Runs the shell command defined by `tex-dvi-print-command'. If prefix argument
|
|
1409 is provided, use the alternative command, `tex-alt-dvi-print-command'."
|
739
|
1410 (interactive "P")
|
85
|
1411 (let ((print-file-name-dvi (tex-append tex-print-file ".dvi"))
|
|
1412 test-name)
|
|
1413 (if (and (not (equal (current-buffer) tex-last-buffer-texed))
|
10341
|
1414 (buffer-file-name)
|
|
1415 ;; Check that this buffer's printed file is up to date.
|
85
|
1416 (file-newer-than-file-p
|
|
1417 (setq test-name (tex-append (buffer-file-name) ".dvi"))
|
10341
|
1418 (buffer-file-name)))
|
85
|
1419 (setq print-file-name-dvi test-name))
|
739
|
1420 (if (not (file-exists-p print-file-name-dvi))
|
|
1421 (error "No appropriate `.dvi' file could be found")
|
21314
|
1422 (if (tex-shell-running)
|
|
1423 (tex-kill-job)
|
|
1424 (tex-start-shell))
|
739
|
1425 (tex-send-command
|
24273
|
1426 (if alt tex-alt-dvi-print-command tex-dvi-print-command)
|
|
1427 print-file-name-dvi t))))
|
85
|
1428
|
4917
|
1429 (defun tex-alt-print ()
|
|
1430 "Print the .dvi file made by \\[tex-region], \\[tex-buffer] or \\[tex-file].
|
10296
|
1431 Runs the shell command defined by `tex-alt-dvi-print-command'."
|
4917
|
1432 (interactive)
|
|
1433 (tex-print t))
|
|
1434
|
85
|
1435 (defun tex-view ()
|
|
1436 "Preview the last `.dvi' file made by running TeX under Emacs.
|
|
1437 This means, made using \\[tex-region], \\[tex-buffer] or \\[tex-file].
|
11617
|
1438 The variable `tex-dvi-view-command' specifies the shell command for preview.
|
|
1439 You must set that variable yourself before using this command,
|
|
1440 because there is no standard value that would generally work."
|
85
|
1441 (interactive)
|
11617
|
1442 (or tex-dvi-view-command
|
|
1443 (error "You must set `tex-dvi-view-command'"))
|
85
|
1444 (let ((tex-dvi-print-command tex-dvi-view-command))
|
|
1445 (tex-print)))
|
|
1446
|
|
1447 (defun tex-append (file-name suffix)
|
|
1448 "Append to FILENAME the suffix SUFFIX, using same algorithm TeX uses.
|
4917
|
1449 Pascal-based TeX scans for the first period, C TeX uses the last.
|
85
|
1450 No period is retained immediately before SUFFIX,
|
|
1451 so normally SUFFIX starts with one."
|
|
1452 (if (stringp file-name)
|
4917
|
1453 (let ((file (file-name-nondirectory file-name))
|
|
1454 trial-name)
|
14383
|
1455 ;; Try splitting on last period.
|
10778
|
1456 ;; The first-period split can get fooled when two files
|
|
1457 ;; named a.tex and a.b.tex are both tex'd;
|
|
1458 ;; the last-period split must be right if it matches at all.
|
4917
|
1459 (setq trial-name
|
|
1460 (concat (file-name-directory file-name)
|
|
1461 (substring file 0
|
10778
|
1462 (string-match "\\.[^.]*$" file))
|
4917
|
1463 suffix))
|
|
1464 (if (or (file-exists-p trial-name)
|
|
1465 (file-exists-p (concat trial-name ".aux"))) ;for BibTeX files
|
|
1466 trial-name
|
10778
|
1467 ;; Not found, so split on first period.
|
4917
|
1468 (concat (file-name-directory file-name)
|
|
1469 (substring file 0
|
10778
|
1470 (string-match "\\." file))
|
4917
|
1471 suffix)))
|
85
|
1472 " "))
|
|
1473
|
|
1474 (defun tex-show-print-queue ()
|
|
1475 "Show the print queue that \\[tex-print] put your job on.
|
1577
|
1476 Runs the shell command defined by `tex-show-queue-command'."
|
85
|
1477 (interactive)
|
|
1478 (if (tex-shell-running)
|
|
1479 (tex-kill-job)
|
|
1480 (tex-start-shell))
|
10572
|
1481 (tex-send-command tex-show-queue-command)
|
|
1482 (tex-display-shell))
|
85
|
1483
|
|
1484 (defun tex-bibtex-file ()
|
|
1485 "Run BibTeX on the current buffer's file."
|
|
1486 (interactive)
|
|
1487 (if (tex-shell-running)
|
|
1488 (tex-kill-job)
|
|
1489 (tex-start-shell))
|
24222
|
1490 (let (shell-dirtrack-verbose
|
|
1491 (tex-out-file
|
85
|
1492 (tex-append (file-name-nondirectory (buffer-file-name)) ""))
|
|
1493 (file-dir (file-name-directory (buffer-file-name))))
|
739
|
1494 (tex-send-command tex-shell-cd-command file-dir)
|
10572
|
1495 (tex-send-command tex-bibtex-command tex-out-file))
|
|
1496 (tex-display-shell))
|
739
|
1497
|
|
1498 (run-hooks 'tex-mode-load-hook)
|
85
|
1499
|
584
|
1500 (provide 'tex-mode)
|
|
1501
|
657
|
1502 ;;; tex-mode.el ends here
|