Mercurial > hg > xemacs-beta
comparison lisp/auctex/tex-buf.el @ 24:4103f0995bd7 r19-15b95
Import from CVS: tag r19-15b95
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:51:03 +0200 |
parents | |
children | 441bb1e64a06 |
comparison
equal
deleted
inserted
replaced
23:0edd3412f124 | 24:4103f0995bd7 |
---|---|
1 ;;; tex-buf.el - External commands for AUC TeX. | |
2 ;; | |
3 ;; Maintainer: Per Abrahamsen <auc-tex@sunsite.auc.dk> | |
4 ;; Version: 9.7i | |
5 | |
6 ;; Copyright (C) 1991 Kresten Krab Thorup | |
7 ;; Copyright (C) 1993, 1996 Per Abrahamsen | |
8 ;; | |
9 ;; This program is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 1, or (at your option) | |
12 ;; any later version. | |
13 ;; | |
14 ;; This program is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 ;; | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with this program; if not, write to the Free Software | |
21 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
23 ;;; Code: | |
24 | |
25 (defvar no-doc | |
26 "This function is part of AUC TeX, but has not yet been loaded. | |
27 Full documentation will be available after autoloading the function." | |
28 "Documentation for autoload functions.") | |
29 | |
30 ;;; Customization: | |
31 | |
32 (defvar TeX-process-asynchronous (not (eq system-type 'ms-dos)) | |
33 "*Use asynchronous processes.") | |
34 | |
35 (defvar TeX-shell | |
36 (if (memq system-type '(ms-dos emx windows-nt)) | |
37 shell-file-name | |
38 "/bin/sh") | |
39 "Name of shell used to parse TeX commands.") | |
40 | |
41 (defvar TeX-shell-command-option | |
42 (cond ((memq system-type '(ms-dos emx windows-nt) ) | |
43 (cond ((boundp 'shell-command-option) | |
44 shell-command-option) | |
45 ((boundp 'shell-command-switch) | |
46 shell-command-switch) | |
47 (t | |
48 "/c"))) | |
49 (t ;Unix & EMX (Emacs 19 port to OS/2) | |
50 "-c")) | |
51 "Shell argument indicating that next argument is the command.") | |
52 | |
53 ;;; Interactive Commands | |
54 ;; | |
55 ;; The general idea is, that there is one process and process buffer | |
56 ;; associated with each master file, and one process and process buffer | |
57 ;; for running TeX on a region. Thus, if you have N master files, you | |
58 ;; can run N + 1 processes simultaneously. | |
59 ;; | |
60 ;; Some user commands operates on ``the'' process. The following | |
61 ;; algorithm determine what ``the'' process is. | |
62 ;; | |
63 ;; IF last process started was on a region | |
64 ;; THEN ``the'' process is the region process | |
65 ;; ELSE ``the'' process is the master file (of the current buffer) process | |
66 | |
67 (defun TeX-save-document (name) | |
68 "Save all files belonging to the current document. | |
69 Return non-nil if document need to be re-TeX'ed." | |
70 (interactive (list (TeX-master-file))) | |
71 (if (string-equal name "") | |
72 (setq name (TeX-master-file))) | |
73 | |
74 (TeX-check-files (concat name ".dvi") | |
75 (cons name (TeX-style-list)) | |
76 TeX-file-extensions)) | |
77 | |
78 (defun TeX-command-master () | |
79 "Run command on the current document." | |
80 (interactive) | |
81 (TeX-command (TeX-command-query (TeX-master-file)) 'TeX-master-file)) | |
82 | |
83 (defvar TeX-command-region-begin nil) | |
84 (defvar TeX-command-region-end nil) | |
85 ;; Used for marking the last region. | |
86 | |
87 (make-variable-buffer-local 'TeX-command-region-begin) | |
88 (make-variable-buffer-local 'TeX-command-region-end) | |
89 | |
90 (defun TeX-command-region (&optional old) | |
91 "Run TeX on the current region. | |
92 | |
93 Query the user for a command to run on the temporary file specified by | |
94 the variable TeX-region. If the chosen command is so marked in | |
95 TeX-command-list, and no argument (or nil) is given to the command, | |
96 the region file file be recreated with the current region. If mark is | |
97 not active, the new text in the previous used region will be used. | |
98 | |
99 If the master file for the document has a header, it is written to the | |
100 temporary file before the region itself. The document's header is all | |
101 text before TeX-header-end. | |
102 | |
103 If the master file for the document has a trailer, it is written to | |
104 the temporary file before the region itself. The document's trailer is | |
105 all text after TeX-trailer-start." | |
106 (interactive "P") | |
107 (if (and (TeX-mark-active) (not old)) | |
108 (let ((begin (min (point) (mark))) | |
109 (end (max (point) (mark)))) | |
110 (if TeX-command-region-begin | |
111 () | |
112 (setq TeX-command-region-begin (make-marker) | |
113 TeX-command-region-end (make-marker))) | |
114 (set-marker TeX-command-region-begin begin) | |
115 (set-marker TeX-command-region-end end))) | |
116 (if (null TeX-command-region-begin) | |
117 (error "Mark not set")) | |
118 (let ((begin (marker-position TeX-command-region-begin)) | |
119 (end (marker-position TeX-command-region-end))) | |
120 (TeX-region-create (TeX-region-file TeX-default-extension) | |
121 (buffer-substring begin end) | |
122 (file-name-nondirectory (buffer-file-name)) | |
123 (count-lines (save-restriction (widen) (point-min)) | |
124 begin))) | |
125 (TeX-command (TeX-command-query (TeX-region-file)) 'TeX-region-file)) | |
126 | |
127 (defun TeX-command-buffer () | |
128 "Run TeX on the current buffer. | |
129 | |
130 Query the user for a command to run on the temporary file specified by | |
131 the variable TeX-region. The region file file be recreated from the | |
132 visible part of the buffer." | |
133 (interactive) | |
134 (let ((TeX-command-region-begin (point-min-marker)) | |
135 (TeX-command-region-end (point-max-marker))) | |
136 (TeX-command-region t))) | |
137 | |
138 (defun TeX-recenter-output-buffer (line) | |
139 "Redisplay buffer of TeX job output so that most recent output can be seen. | |
140 The last line of the buffer is displayed on line LINE of the window, or | |
141 at bottom if LINE is nil." | |
142 (interactive "P") | |
143 (let ((buffer (TeX-active-buffer))) | |
144 (if buffer | |
145 (let ((old-buffer (current-buffer))) | |
146 (pop-to-buffer buffer t) | |
147 (bury-buffer buffer) | |
148 (goto-char (point-max)) | |
149 (recenter (if line | |
150 (prefix-numeric-value line) | |
151 (/ (window-height) 2))) | |
152 (pop-to-buffer old-buffer)) | |
153 (message "No process for this document.")))) | |
154 | |
155 (defun TeX-kill-job () | |
156 "Kill the currently running TeX job." | |
157 (interactive) | |
158 (let ((process (TeX-active-process))) | |
159 (if process | |
160 (kill-process process) | |
161 ;; Should test for TeX background process here. | |
162 (error "No TeX process to kill")))) | |
163 | |
164 (defun TeX-home-buffer () | |
165 "Go to the buffer where you last issued a TeX command. | |
166 If there is no such buffer, or you already are in that buffer, find | |
167 the master file." | |
168 (interactive) | |
169 (if (or (null TeX-command-buffer) | |
170 (eq TeX-command-buffer (current-buffer))) | |
171 (find-file (TeX-master-file TeX-default-extension)) | |
172 (switch-to-buffer TeX-command-buffer))) | |
173 | |
174 (defun TeX-next-error (reparse) | |
175 "Find the next error in the TeX output buffer. | |
176 Prefix by C-u to start from the beginning of the errors." | |
177 (interactive "P") | |
178 (if (null (TeX-active-buffer)) | |
179 (error "No TeX output buffer") | |
180 (funcall (TeX-process-get-variable (TeX-active-master) 'TeX-parse-function) | |
181 reparse))) | |
182 | |
183 (defun TeX-toggle-debug-boxes () | |
184 "Toggle if the debugger should display \"bad boxes\" too." | |
185 (interactive) | |
186 (cond (TeX-debug-bad-boxes | |
187 (setq TeX-debug-bad-boxes nil)) | |
188 (t | |
189 (setq TeX-debug-bad-boxes t))) | |
190 (message (concat "TeX-debug-bad-boxes: " (cond (TeX-debug-bad-boxes "on") | |
191 (t "off"))))) | |
192 | |
193 ;;; Command Query | |
194 | |
195 (defun TeX-command (name file) | |
196 "Run command NAME on the file you get by calling FILE. | |
197 | |
198 FILE is a function return a file name. It has one optional argument, | |
199 the extension to use on the file. | |
200 | |
201 Use the information in TeX-command-list to determine how to run the | |
202 command." | |
203 (setq TeX-current-process-region-p (eq file 'TeX-region-file)) | |
204 (let ((command (TeX-command-expand (nth 1 (assoc name TeX-command-list)) | |
205 file)) | |
206 (hook (nth 2 (assoc name TeX-command-list))) | |
207 (confirm (nth 3 (assoc name TeX-command-list)))) | |
208 | |
209 ;; Verify the expanded command | |
210 (if confirm | |
211 (setq command | |
212 (read-from-minibuffer (concat name " command: ") command))) | |
213 | |
214 ;; Now start the process | |
215 (TeX-process-set-variable name 'TeX-command-next TeX-command-Show) | |
216 (apply hook name command (apply file nil) nil))) | |
217 | |
218 (defun TeX-command-expand (command file &optional list) | |
219 "Expand COMMAND for FILE as described in LIST. | |
220 LIST default to TeX-expand-list." | |
221 (if (null list) | |
222 (setq list TeX-expand-list)) | |
223 (while list | |
224 (let ((case-fold-search nil) ; Do not ignore case. | |
225 (string (car (car list))) ;First element | |
226 (expansion (car (cdr (car list)))) ;Second element | |
227 (arguments (cdr (cdr (car list))))) ;Remaining elements | |
228 (while (string-match string command) | |
229 (let ((prefix (substring command 0 (match-beginning 0))) | |
230 (postfix (substring command (match-end 0)))) | |
231 (setq command (concat prefix | |
232 (cond ((TeX-function-p expansion) | |
233 (apply expansion arguments)) | |
234 ((boundp expansion) | |
235 (apply (eval expansion) arguments)) | |
236 (t | |
237 (error "Nonexpansion %s" expansion))) | |
238 postfix))))) | |
239 (setq list (cdr list))) | |
240 command) | |
241 | |
242 (defun TeX-check-files (derived originals extensions) | |
243 "Check that DERIVED is newer than any of the ORIGINALS. | |
244 Try each original with each member of EXTENSIONS, in all directories | |
245 in TeX-check-path." | |
246 (let ((found nil) | |
247 (regexp (concat "\\`\\(" | |
248 (mapconcat (function (lambda (dir) | |
249 (regexp-quote (expand-file-name dir)))) | |
250 TeX-check-path "\\|") | |
251 "\\).*\\(" | |
252 (mapconcat 'regexp-quote originals "\\|") | |
253 "\\)\\.\\(" | |
254 (mapconcat 'regexp-quote extensions "\\|") | |
255 "\\)\\'")) | |
256 (buffers (buffer-list))) | |
257 (while buffers | |
258 (let* ((buffer (car buffers)) | |
259 (name (buffer-file-name buffer))) | |
260 (setq buffers (cdr buffers)) | |
261 (if (and name (string-match regexp name)) | |
262 (progn | |
263 (and (buffer-modified-p buffer) | |
264 (or (not TeX-save-query) | |
265 (y-or-n-p (concat "Save file " | |
266 (buffer-file-name buffer) | |
267 "? "))) | |
268 (save-excursion (set-buffer buffer) (save-buffer))) | |
269 (if (file-newer-than-file-p name derived) | |
270 (setq found t)))))) | |
271 found)) | |
272 | |
273 (defvar TeX-save-query t | |
274 "*If non-nil, ask user for permission to save files before starting TeX.") | |
275 | |
276 (defun TeX-command-query (name) | |
277 "Query the user for a what TeX command to use." | |
278 (let* ((default (cond ((if (string-equal name TeX-region) | |
279 (TeX-check-files (concat name ".dvi") | |
280 (list name) | |
281 TeX-file-extensions) | |
282 (TeX-save-document (TeX-master-file))) | |
283 TeX-command-default) | |
284 ((and (eq major-mode 'latex-mode) | |
285 (TeX-check-files (concat name ".bbl") | |
286 (mapcar 'car | |
287 (LaTeX-bibliography-list)) | |
288 BibTeX-file-extensions)) | |
289 ;; We should check for bst files here as well. | |
290 TeX-command-BibTeX) | |
291 ((TeX-process-get-variable name | |
292 'TeX-command-next | |
293 TeX-command-Show)) | |
294 (TeX-command-Show))) | |
295 (completion-ignore-case t) | |
296 (answer (or TeX-command-force | |
297 (completing-read | |
298 (concat "Command: (default " default ") ") | |
299 TeX-command-list nil t)))) | |
300 ;; If the answer "latex" it will not be expanded to "LaTeX" | |
301 (setq answer (car-safe (TeX-assoc answer TeX-command-list))) | |
302 (if (and answer | |
303 (not (string-equal answer ""))) | |
304 answer | |
305 default))) | |
306 | |
307 (defvar TeX-command-next nil | |
308 "The default command next time TeX-command is invoked.") | |
309 | |
310 (make-variable-buffer-local 'TeX-command-next) | |
311 | |
312 (defun TeX-printer-query (&optional command element) | |
313 "Query the user for a printer name. | |
314 COMMAND is the default command to use if the entry for the printer in | |
315 TeX-printer-list does not itself have it specified in the ELEMENT'th | |
316 entry." | |
317 (or command (setq command TeX-print-command)) | |
318 (or element (setq element 1)) | |
319 (let ((printer (if TeX-printer-list | |
320 (let ((completion-ignore-case t)) | |
321 (completing-read (concat "Printer: (default " | |
322 TeX-printer-default ") ") | |
323 TeX-printer-list)) | |
324 ""))) | |
325 | |
326 (setq printer (or (car-safe (TeX-assoc printer TeX-printer-list)) | |
327 printer)) | |
328 (if (or (null printer) (string-equal "" printer)) | |
329 (setq printer TeX-printer-default) | |
330 (setq TeX-printer-default printer)) | |
331 | |
332 (let ((expansion (let ((entry (assoc printer TeX-printer-list))) | |
333 (if (and entry (nth element entry)) | |
334 (nth element entry) | |
335 command)))) | |
336 (if (string-match "%p" printer) | |
337 (error "Don't use %s in printer names" "%p")) | |
338 (while (string-match "%p" expansion) | |
339 (setq expansion (concat (substring expansion 0 (match-beginning 0)) | |
340 printer | |
341 (substring expansion (match-end 0))))) | |
342 expansion))) | |
343 | |
344 (defun TeX-style-check (styles) | |
345 "Check STYLES compared to the current style options." | |
346 | |
347 (let ((files (TeX-style-list))) | |
348 (while (and styles | |
349 (not (TeX-member (car (car styles)) files 'string-match))) | |
350 (setq styles (cdr styles)))) | |
351 (if styles | |
352 (nth 1 (car styles)) | |
353 "")) | |
354 | |
355 ;;; Command Hooks | |
356 | |
357 (defvar TeX-after-start-process-function nil | |
358 "Hooks to run after starting an asynchronous process. | |
359 Used by Japanese TeX to set the coding system.") | |
360 | |
361 (defvar TeX-show-compilation nil | |
362 "*If non-nil, show output of TeX compilation in other window.") | |
363 | |
364 (defun TeX-run-command (name command file) | |
365 "Create a process for NAME using COMMAND to process FILE. | |
366 Return the new process." | |
367 (let ((default TeX-command-default) | |
368 (buffer (TeX-process-buffer-name file)) | |
369 (dir (TeX-master-directory))) | |
370 (TeX-process-check file) ; Check that no process is running | |
371 (setq TeX-command-buffer (current-buffer)) | |
372 (get-buffer-create buffer) | |
373 (set-buffer buffer) | |
374 (erase-buffer) | |
375 (if dir (cd dir)) | |
376 (insert "Running `" name "' on `" file "' with ``" command "''\n") | |
377 (setq mode-name name) | |
378 (if TeX-show-compilation | |
379 (display-buffer buffer) | |
380 (message "Type `C-c C-l' to display results of compilation.")) | |
381 (setq TeX-parse-function 'TeX-parse-command) | |
382 (setq TeX-command-default default) | |
383 (setq TeX-sentinel-function | |
384 (function (lambda (process name) | |
385 (message (concat name ": done."))))) | |
386 (if TeX-process-asynchronous | |
387 (let ((process (start-process name buffer TeX-shell | |
388 TeX-shell-command-option command))) | |
389 (if TeX-after-start-process-function | |
390 (funcall TeX-after-start-process-function process)) | |
391 (TeX-command-mode-line process) | |
392 (set-process-filter process 'TeX-command-filter) | |
393 (set-process-sentinel process 'TeX-command-sentinel) | |
394 (set-marker (process-mark process) (point-max)) | |
395 (setq compilation-in-progress (cons process compilation-in-progress)) | |
396 process) | |
397 (setq mode-line-process ": run") | |
398 (set-buffer-modified-p (buffer-modified-p)) | |
399 (sit-for 0) ; redisplay | |
400 (call-process TeX-shell nil buffer nil | |
401 TeX-shell-command-option command)))) | |
402 | |
403 (defun TeX-run-format (name command file) | |
404 "Create a process for NAME using COMMAND to format FILE with TeX." | |
405 (let ((buffer (TeX-process-buffer-name file)) | |
406 (process (TeX-run-command name command file))) | |
407 ;; Hook to TeX debuger. | |
408 (save-excursion | |
409 (set-buffer buffer) | |
410 (TeX-parse-reset) | |
411 (setq TeX-parse-function 'TeX-parse-TeX) | |
412 (setq TeX-sentinel-function 'TeX-TeX-sentinel) | |
413 (if TeX-process-asynchronous | |
414 (progn | |
415 ;; Updating the mode line. | |
416 (setq TeX-current-page "[0]") | |
417 (TeX-format-mode-line process) | |
418 (set-process-filter process 'TeX-format-filter))) | |
419 process))) | |
420 | |
421 (defun TeX-run-TeX (name command file) | |
422 "Create a process for NAME using COMMAND to format FILE with TeX." | |
423 (let ((process (TeX-run-format name command file))) | |
424 (if TeX-process-asynchronous | |
425 process | |
426 (TeX-synchronous-sentinel name file process)))) | |
427 | |
428 (defun TeX-run-LaTeX (name command file) | |
429 "Create a process for NAME using COMMAND to format FILE with TeX." | |
430 (let ((process (TeX-run-format name command file))) | |
431 (setq TeX-sentinel-function 'TeX-LaTeX-sentinel) | |
432 (if TeX-process-asynchronous | |
433 process | |
434 (TeX-synchronous-sentinel name file process)))) | |
435 | |
436 (defun TeX-run-BibTeX (name command file) | |
437 "Create a process for NAME using COMMAND to format FILE with BibTeX." | |
438 (let ((process (TeX-run-command name command file))) | |
439 (setq TeX-sentinel-function 'TeX-BibTeX-sentinel) | |
440 (if TeX-process-asynchronous | |
441 process | |
442 (TeX-synchronous-sentinel name file process)))) | |
443 | |
444 (defun TeX-run-compile (name command file) | |
445 "Ignore first and third argument, start compile with second argument." | |
446 (compile command)) | |
447 | |
448 (defun TeX-run-shell (name command file) | |
449 "Ignore first and third argument, start shell-command with second argument." | |
450 (shell-command command) | |
451 (if (eq system-type 'ms-dos) | |
452 (redraw-display))) | |
453 | |
454 (defun TeX-run-discard (name command file) | |
455 "Start process with second argument, discarding its output." | |
456 (process-kill-without-query (start-process (concat name " discard") | |
457 nil TeX-shell | |
458 TeX-shell-command-option | |
459 command))) | |
460 | |
461 (defun TeX-run-dviout (name command file) | |
462 "Call process wbith second argument, discarding its output. With support | |
463 for the dviout previewer, especially when used with PC-9801 series." | |
464 (if (and (boundp 'dos-machine-type) (eq dos-machine-type 'pc98)) ;if PC-9801 | |
465 (send-string-to-terminal "\e[2J")) ; clear screen | |
466 (call-process TeX-shell (if (eq system-type 'ms-dos) "con") nil nil | |
467 TeX-shell-command-option command) | |
468 (if (eq system-type 'ms-dos) | |
469 (redraw-display))) | |
470 | |
471 (defun TeX-run-background (name command file) | |
472 "Start process with second argument, show output when and if it arrives." | |
473 (let ((dir (TeX-master-directory))) | |
474 (set-buffer (get-buffer-create "*TeX background*")) | |
475 (if dir (cd dir)) | |
476 (erase-buffer) | |
477 (let ((process (start-process (concat name " background") | |
478 nil TeX-shell | |
479 TeX-shell-command-option command))) | |
480 (if TeX-after-start-process-function | |
481 (funcall TeX-after-start-process-function process)) | |
482 (set-process-filter process 'TeX-background-filter) | |
483 (process-kill-without-query process)))) | |
484 | |
485 (defun TeX-run-interactive (name command file) | |
486 "Run TeX interactively. | |
487 Run command in a buffer (in comint-shell-mode) so that it accepts user | |
488 interaction. If you return to the file buffer after the TeX run, | |
489 Error parsing on C-x ` should work with a bit of luck." | |
490 (require 'comint) | |
491 (let ((default TeX-command-default) | |
492 (buffer (TeX-process-buffer-name file)) | |
493 (process nil) | |
494 (dir (TeX-master-directory))) | |
495 (TeX-process-check file) ; Check that no process is running | |
496 (setq TeX-command-buffer (current-buffer)) | |
497 (with-output-to-temp-buffer buffer) | |
498 (set-buffer buffer) | |
499 (if dir (cd dir)) | |
500 (insert "Running `" name "' on `" file "' with ``" command "''\n") | |
501 (comint-exec buffer name TeX-shell nil | |
502 (list TeX-shell-command-option command)) | |
503 (comint-mode) | |
504 (setq mode-name name) | |
505 (setq TeX-command-default default) | |
506 (setq process (get-buffer-process buffer)) | |
507 (if TeX-after-start-process-function | |
508 (funcall TeX-after-start-process-function process)) | |
509 (TeX-command-mode-line process) | |
510 (set-process-sentinel process 'TeX-command-sentinel) | |
511 (set-marker (process-mark process) (point-max)) | |
512 (setq compilation-in-progress (cons process compilation-in-progress)) | |
513 (TeX-parse-reset) | |
514 (setq TeX-parse-function 'TeX-parse-TeX) | |
515 (setq TeX-sentinel-function 'TeX-LaTeX-sentinel))) | |
516 | |
517 ;;; Command Sentinels | |
518 | |
519 (defun TeX-synchronous-sentinel (name file result) | |
520 "Process TeX command output buffer after the process dies." | |
521 (let* ((buffer (TeX-process-buffer file))) | |
522 (save-excursion | |
523 (set-buffer buffer) | |
524 | |
525 ;; Append post-mortem information to the buffer | |
526 (goto-char (point-max)) | |
527 (insert "\n" mode-name (if (and result (zerop result)) | |
528 " finished" " exited") " at " | |
529 (substring (current-time-string) 0 -5)) | |
530 (setq mode-line-process ": exit") | |
531 | |
532 ;; Do command specific actions. | |
533 (setq TeX-command-next TeX-command-Show) | |
534 (goto-char (point-min)) | |
535 (apply TeX-sentinel-function nil name nil) | |
536 | |
537 ;; Force mode line redisplay soon | |
538 (set-buffer-modified-p (buffer-modified-p))))) | |
539 | |
540 (defun TeX-command-sentinel (process msg) | |
541 "Process TeX command output buffer after the process dies." | |
542 (let* ((buffer (process-buffer process)) | |
543 (name (process-name process))) | |
544 (cond ((null (buffer-name buffer)) ; buffer killed | |
545 (set-process-buffer process nil) | |
546 (set-process-sentinel process nil)) | |
547 ((memq (process-status process) '(signal exit)) | |
548 (save-excursion | |
549 (set-buffer buffer) | |
550 | |
551 ;; Append post-mortem information to the buffer | |
552 (goto-char (point-max)) | |
553 (insert "\n" mode-name " " msg) | |
554 (forward-char -1) | |
555 (insert " at " | |
556 (substring (current-time-string) 0 -5)) | |
557 (forward-char 1) | |
558 | |
559 ;; Do command specific actions. | |
560 (TeX-command-mode-line process) | |
561 (setq TeX-command-next TeX-command-Show) | |
562 (goto-char (point-min)) | |
563 (apply TeX-sentinel-function process name nil) | |
564 | |
565 | |
566 ;; If buffer and mode line will show that the process | |
567 ;; is dead, we can delete it now. Otherwise it | |
568 ;; will stay around until M-x list-processes. | |
569 (delete-process process) | |
570 | |
571 ;; Force mode line redisplay soon | |
572 (set-buffer-modified-p (buffer-modified-p)))))) | |
573 (setq compilation-in-progress (delq process compilation-in-progress))) | |
574 | |
575 | |
576 (defvar TeX-sentinel-function (function (lambda (process name))) | |
577 "Hook to cleanup TeX command buffer after temination of PROCESS. | |
578 NAME is the name of the process.") | |
579 | |
580 (make-variable-buffer-local 'TeX-sentinel-function) | |
581 | |
582 (defun TeX-TeX-sentinel (process name) | |
583 "Cleanup TeX output buffer after running TeX." | |
584 (if (TeX-TeX-sentinel-check process name) | |
585 () | |
586 (message (concat name ": formatted " (TeX-current-pages))) | |
587 (setq TeX-command-next TeX-command-Show))) | |
588 | |
589 (defun TeX-current-pages () | |
590 ;; String indictating the number of pages formatted. | |
591 (cond ((null TeX-current-page) | |
592 "some pages.") | |
593 ((string-match "[^0-9]1[^0-9]" TeX-current-page) | |
594 (concat TeX-current-page " page.")) | |
595 (t | |
596 (concat TeX-current-page " pages.")))) | |
597 | |
598 (defun TeX-TeX-sentinel-check (process name) | |
599 "Cleanup TeX output buffer after running TeX. | |
600 Return nil ifs no errors were found." | |
601 (save-excursion | |
602 (goto-char (point-max)) | |
603 (if (re-search-backward "^Output written on.* (\\([0-9]+\\) page" nil t) | |
604 (setq TeX-current-page (concat "{" (TeX-match-buffer 1) "}")))) | |
605 (if process (TeX-format-mode-line process)) | |
606 (if (re-search-forward "^! " nil t) | |
607 (progn | |
608 (message (concat name " errors in `" (buffer-name) | |
609 "'. Use C-c ` to display.")) | |
610 (setq TeX-command-next TeX-command-default) | |
611 t) | |
612 (setq TeX-command-next TeX-command-Show) | |
613 nil)) | |
614 | |
615 (defun TeX-LaTeX-sentinel (process name) | |
616 "Cleanup TeX output buffer after running LaTeX." | |
617 (cond ((TeX-TeX-sentinel-check process name)) | |
618 ((and (save-excursion | |
619 (re-search-forward "^LaTeX Warning: Citation" nil t)) | |
620 (let ((current (current-buffer))) | |
621 (set-buffer TeX-command-buffer) | |
622 (prog1 (and (LaTeX-bibliography-list) | |
623 (TeX-check-files (TeX-master-file "bbl") | |
624 (TeX-style-list) | |
625 (append TeX-file-extensions | |
626 BibTeX-file-extensions))) | |
627 (set-buffer current)))) | |
628 (message (concat "You should run BibTeX to get citations right, " | |
629 (TeX-current-pages))) | |
630 (setq TeX-command-next TeX-command-BibTeX)) | |
631 ((re-search-forward "^LaTeX Warning: Label(s)" nil t) | |
632 (message (concat "You should run LaTeX again " | |
633 "to get references right, " | |
634 (TeX-current-pages))) | |
635 (setq TeX-command-next TeX-command-default)) | |
636 ((re-search-forward "^LaTeX Warning: Reference" nil t) | |
637 (message (concat name ": there were unresolved references, " | |
638 (TeX-current-pages))) | |
639 (setq TeX-command-next TeX-command-Show)) | |
640 ((re-search-forward "^LaTeX Warning: Citation" nil t) | |
641 (message (concat name ": there were unresolved citations, " | |
642 (TeX-current-pages))) | |
643 (setq TeX-command-next TeX-command-Show)) | |
644 ((re-search-forward | |
645 "^\\(\\*\\* \\)?J?I?p?\\(La\\|Sli\\)TeX\\(2e\\)? \\(Version\\|ver\\.\\|<[0-9/]*>\\)" nil t) | |
646 (message (concat name ": successfully formatted " | |
647 (TeX-current-pages))) | |
648 (setq TeX-command-next TeX-command-Show)) | |
649 (t | |
650 (message (concat name ": problems after " | |
651 (TeX-current-pages))) | |
652 (setq TeX-command-next TeX-command-default)))) | |
653 | |
654 (defun TeX-BibTeX-sentinel (process name) | |
655 "Cleanup TeX output buffer after running BibTeX." | |
656 (message "You should perhaps run LaTeX again to get citations right.") | |
657 (setq TeX-command-next TeX-command-default)) | |
658 | |
659 ;;; Process Control | |
660 | |
661 | |
662 ;; This variable is chared with `compile.el'. | |
663 (defvar compilation-in-progress nil | |
664 "List of compilation processes now running.") | |
665 | |
666 (or (assq 'compilation-in-progress minor-mode-alist) | |
667 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling") | |
668 minor-mode-alist))) | |
669 | |
670 (defun TeX-process-get-variable (name symbol &optional default) | |
671 "Return the value in the process buffer for NAME of SYMBOL. | |
672 | |
673 Return DEFAULT if the process buffer does not exist or SYMBOL is not | |
674 defined." | |
675 (let ((buffer (TeX-process-buffer name))) | |
676 (if buffer | |
677 (save-excursion | |
678 (set-buffer buffer) | |
679 (if (boundp symbol) | |
680 (eval symbol) | |
681 default)) | |
682 default))) | |
683 | |
684 (defun TeX-process-set-variable (name symbol value) | |
685 "Set the variable SYMBOL in the process buffer to VALUE. | |
686 Return nil iff no process buffer exist." | |
687 (let ((buffer (TeX-process-buffer name))) | |
688 (if buffer | |
689 (save-excursion | |
690 (set-buffer buffer) | |
691 (set symbol value) | |
692 t) | |
693 nil))) | |
694 | |
695 (defun TeX-process-check (name) | |
696 "Check if a process for the TeX document NAME already exist. | |
697 If so, give the user the choice of aborting the process or the current | |
698 command." | |
699 (let ((process (TeX-process name))) | |
700 (cond ((null process)) | |
701 ((not (eq (process-status process) 'run))) | |
702 ((yes-or-no-p (concat "Process `" | |
703 (process-name process) | |
704 "' for document `" | |
705 name | |
706 "' running, kill it? ")) | |
707 (delete-process process)) | |
708 (t | |
709 (error "Cannot have two processes for the same document"))))) | |
710 | |
711 (defun TeX-process-buffer-name (name) | |
712 "Return name of AUC TeX buffer associated with the document NAME." | |
713 (concat "*" (abbreviate-file-name (expand-file-name name)) " output*")) | |
714 | |
715 (defun TeX-process-buffer (name) | |
716 "Return the AUC TeX buffer associated with the document NAME." | |
717 (get-buffer (TeX-process-buffer-name name))) | |
718 | |
719 (defun TeX-process (name) | |
720 "Return AUC TeX process associated with the document NAME." | |
721 (and TeX-process-asynchronous | |
722 (get-buffer-process (TeX-process-buffer name)))) | |
723 | |
724 ;;; Process Filters | |
725 | |
726 (defun TeX-command-mode-line (process) | |
727 "Format the mode line for a buffer containing output from PROCESS." | |
728 (setq mode-line-process (concat ": " | |
729 (symbol-name (process-status process)))) | |
730 (set-buffer-modified-p (buffer-modified-p))) | |
731 | |
732 (defun TeX-command-filter (process string) | |
733 "Filter to process normal output." | |
734 (save-excursion | |
735 (set-buffer (process-buffer process)) | |
736 (save-excursion | |
737 (goto-char (process-mark process)) | |
738 (insert-before-markers string) | |
739 (set-marker (process-mark process) (point))))) | |
740 | |
741 (defvar TeX-current-page nil | |
742 "The page number currently being formatted, enclosed in brackets.") | |
743 | |
744 (make-variable-buffer-local 'TeX-current-page) | |
745 | |
746 (defun TeX-format-mode-line (process) | |
747 "Format the mode line for a buffer containing TeX output from PROCESS." | |
748 (setq mode-line-process (concat " " TeX-current-page ": " | |
749 (symbol-name (process-status process)))) | |
750 (set-buffer-modified-p (buffer-modified-p))) | |
751 | |
752 (defun TeX-format-filter (process string) | |
753 "Filter to process TeX output." | |
754 (save-excursion | |
755 (set-buffer (process-buffer process)) | |
756 (save-excursion | |
757 (goto-char (process-mark process)) | |
758 (insert-before-markers string) | |
759 (set-marker (process-mark process) (point))) | |
760 (save-excursion | |
761 (save-match-data | |
762 (if (re-search-backward "\\[[0-9]+\\(\\.[0-9\\.]+\\)?\\]" nil t) | |
763 (setq TeX-current-page (TeX-match-buffer 0))))) | |
764 (TeX-format-mode-line process))) | |
765 | |
766 (defvar TeX-parse-function nil | |
767 "Function to call to parse content of TeX output buffer.") | |
768 (make-variable-buffer-local 'TeX-parse-function) | |
769 | |
770 (defun TeX-background-filter (process string) | |
771 "Filter to process background output." | |
772 (let ((old-window (selected-window)) | |
773 (pop-up-windows t)) | |
774 (pop-to-buffer "*TeX background*") | |
775 (goto-char (point-max)) | |
776 (insert string) | |
777 (select-window old-window))) | |
778 | |
779 | |
780 ;;; Active Process | |
781 | |
782 (defvar TeX-current-process-region-p nil | |
783 "This variable is set to t iff the last TeX command is on a region.") | |
784 | |
785 (defun TeX-active-process () | |
786 "Return the active process for the current buffer." | |
787 (if TeX-current-process-region-p | |
788 (TeX-process (TeX-region-file)) | |
789 (TeX-process (TeX-master-file)))) | |
790 | |
791 (defun TeX-active-buffer () | |
792 "Return the buffer of the active process for this buffer." | |
793 (if TeX-current-process-region-p | |
794 (TeX-process-buffer (TeX-region-file)) | |
795 (TeX-process-buffer (TeX-master-file)))) | |
796 | |
797 (defun TeX-active-master (&optional extension) | |
798 "The master file currently being compiled." | |
799 (if TeX-current-process-region-p | |
800 (TeX-region-file extension) | |
801 (TeX-master-file extension))) | |
802 | |
803 (defvar TeX-command-buffer nil | |
804 "The buffer from where the last TeX command was issued.") | |
805 | |
806 ;;; Region File | |
807 | |
808 (defun TeX-region-create (file region original offset) | |
809 "Create a new file named FILE with the string REGION | |
810 The region is taken from ORIGINAL starting at line OFFSET. | |
811 | |
812 The current buffer and master file is searched, in order to ensure | |
813 that the TeX header and trailer information is also included. | |
814 | |
815 The OFFSET is used to provide the debugger with information about the | |
816 original file." | |
817 (let* (;; We shift buffer a lot, so we must keep track of the buffer | |
818 ;; local variables. | |
819 (header-end TeX-header-end) | |
820 (trailer-start TeX-trailer-start) | |
821 | |
822 ;; We seach for header and trailer in the master file. | |
823 (master-name (TeX-master-file TeX-default-extension)) | |
824 (master-buffer (find-file-noselect master-name)) | |
825 | |
826 ;; Attempt to disable font lock. | |
827 (font-lock-defaults-alist nil) | |
828 (font-lock-defaults nil) | |
829 (font-lock-maximum-size 0) | |
830 (font-lock-mode-hook nil) | |
831 (font-lock-auto-fontify nil) | |
832 (font-lock-mode-enable-list nil) | |
833 ;; And insert them into the FILE buffer. | |
834 (file-buffer (find-file-noselect file)) | |
835 ;; But remember original content. | |
836 original-content | |
837 | |
838 ;; We search for the header from the master file, if it is | |
839 ;; not present in the region. | |
840 (header (if (string-match header-end region) | |
841 "" | |
842 (save-excursion | |
843 (save-restriction | |
844 (set-buffer master-buffer) | |
845 (save-excursion | |
846 (save-restriction | |
847 (widen) | |
848 (goto-char (point-min)) | |
849 ;; NOTE: We use the local value of | |
850 ;; TeX-header-end from the master file. | |
851 (if (not (re-search-forward TeX-header-end nil t)) | |
852 "" | |
853 (re-search-forward "[\r\n]" nil t) | |
854 (buffer-substring (point-min) (point))))))))) | |
855 | |
856 ;; We search for the trailer from the master file, if it is | |
857 ;; not present in the region. | |
858 (trailer-offset 0) | |
859 (trailer (if (string-match trailer-start region) | |
860 "" | |
861 (save-excursion | |
862 (save-restriction | |
863 (set-buffer master-buffer) | |
864 (save-excursion | |
865 (save-restriction | |
866 (widen) | |
867 (goto-char (point-max)) | |
868 ;; NOTE: We use the local value of | |
869 ;; TeX-trailer-start from the master file. | |
870 (if (not (re-search-backward TeX-trailer-start nil t)) | |
871 "" | |
872 ;;(beginning-of-line 1) | |
873 (re-search-backward "[\r\n]" nil t) | |
874 (setq trailer-offset | |
875 (count-lines (point-min) (point))) | |
876 (buffer-substring (point) (point-max)))))))))) | |
877 (save-excursion | |
878 (set-buffer file-buffer) | |
879 (setq original-content (buffer-string)) | |
880 (erase-buffer) | |
881 (insert "\\message{ !name(" master-name ")}" | |
882 header | |
883 "\n\\message{ !name(" original ") !offset(") | |
884 (insert (int-to-string (- offset | |
885 (count-lines (point-min) (point)))) | |
886 ") }\n" | |
887 region | |
888 "\n\\message{ !name(" master-name ") !offset(") | |
889 (insert (int-to-string (- trailer-offset | |
890 (count-lines (point-min) (point)))) | |
891 ") }\n" | |
892 trailer) | |
893 (if (string-equal (buffer-string) original-content) | |
894 (set-buffer-modified-p nil) | |
895 (save-buffer 0))))) | |
896 | |
897 (defun TeX-region-file (&optional extension nondirectory) | |
898 "Return TeX-region file name with EXTENSION. | |
899 If optional second argument NONDIRECTORY is nil, do not include | |
900 the directory." | |
901 (concat (if nondirectory "" (TeX-master-directory)) | |
902 (cond ((eq extension t) | |
903 (concat TeX-region "." TeX-default-extension)) | |
904 (extension | |
905 (concat TeX-region "." extension)) | |
906 (t | |
907 TeX-region)))) | |
908 | |
909 (defvar TeX-region "_region_" | |
910 "*Base name for temporary file for use with TeX-region.") | |
911 | |
912 ;;; Parsing | |
913 | |
914 ;;; - Global Parser Variables | |
915 | |
916 (defvar TeX-error-point nil | |
917 "How far we have parsed until now.") | |
918 | |
919 (make-variable-buffer-local 'TeX-error-point) | |
920 | |
921 (defvar TeX-error-file nil | |
922 "Stack of files in which errors have occured") | |
923 | |
924 (make-variable-buffer-local 'TeX-error-file) | |
925 | |
926 (defvar TeX-error-offset nil | |
927 "Add this to any line numbers from TeX. Stack like TeX-error-file.") | |
928 | |
929 (make-variable-buffer-local 'TeX-error-offset) | |
930 | |
931 (defun TeX-parse-reset () | |
932 "Reset all variables used for parsing TeX output." | |
933 (setq TeX-error-point (point-min)) | |
934 (setq TeX-error-offset nil) | |
935 (setq TeX-error-file nil)) | |
936 | |
937 ;;; - Parsers Hooks | |
938 | |
939 (defun TeX-parse-command (reparse) | |
940 "We can't parse anything but TeX." | |
941 (error "I cannot parse %s output, sorry" | |
942 (if (TeX-active-process) | |
943 (process-name (TeX-active-process)) | |
944 "this"))) | |
945 | |
946 (defun TeX-parse-TeX (reparse) | |
947 "Find the next error produced by running TeX. | |
948 Prefix by C-u to start from the beginning of the errors. | |
949 | |
950 If the file occurs in an included file, the file is loaded (if not | |
951 already in an Emacs buffer) and the cursor is placed at the error." | |
952 | |
953 (let ((old-buffer (current-buffer))) | |
954 (pop-to-buffer (TeX-active-buffer)) | |
955 (if reparse | |
956 (TeX-parse-reset)) | |
957 (goto-char TeX-error-point) | |
958 (TeX-parse-error old-buffer))) | |
959 | |
960 ;;; - Parsing (La)TeX | |
961 | |
962 (defvar TeX-translate-location-hook nil | |
963 "List of functions to be called before showing an error or warning. | |
964 | |
965 You might want to examine and modify the free variables `file', | |
966 `offset', `line', `string', `error', and `context' from this hook.") | |
967 | |
968 (defun TeX-parse-error (old) | |
969 "Goto next error. Pop to OLD buffer if no more errors are found." | |
970 (while | |
971 (progn | |
972 (re-search-forward (concat "\\(" | |
973 "^! \\|" | |
974 "(\\|" | |
975 ")\\|" | |
976 "\\'\\|" | |
977 "!offset([---0-9]*)\\|" | |
978 "!name([^)]*)\\|" | |
979 "^.*erfull \\\\.*[0-9]*--[0-9]*\\|" | |
980 "^LaTeX Warning: .*[0-9]+\\.$" | |
981 "\\)")) | |
982 (let ((string (TeX-match-buffer 1))) | |
983 | |
984 (cond (;; TeX error | |
985 (string= string "! ") | |
986 (TeX-error) | |
987 nil) | |
988 | |
989 ;; LaTeX warning | |
990 ((string-match (concat "\\(" | |
991 "^.*erfull \\\\.*[0-9]*--[0-9]*\\|" | |
992 "^LaTeX Warning: .*[0-9]+\\.$" | |
993 "\\)") | |
994 | |
995 string) | |
996 (TeX-warning string)) | |
997 | |
998 ;; New file -- Push on stack | |
999 ((string= string "(") | |
1000 (re-search-forward "\\([^()\n \t]*\\)") | |
1001 (setq TeX-error-file | |
1002 (cons (TeX-match-buffer 1) TeX-error-file)) | |
1003 (setq TeX-error-offset (cons 0 TeX-error-offset)) | |
1004 t) | |
1005 | |
1006 ;; End of file -- Pop from stack | |
1007 ((string= string ")") | |
1008 (setq TeX-error-file (cdr TeX-error-file)) | |
1009 (setq TeX-error-offset (cdr TeX-error-offset)) | |
1010 t) | |
1011 | |
1012 ;; Hook to change line numbers | |
1013 ((string-match "!offset(\\([---0-9]*\\))" string) | |
1014 (rplaca TeX-error-offset | |
1015 (string-to-int (substring string | |
1016 (match-beginning 1) | |
1017 (match-end 1)))) | |
1018 t) | |
1019 | |
1020 ;; Hook to change file name | |
1021 ((string-match "!name(\\([^)]*\\))" string) | |
1022 (rplaca TeX-error-file (substring string | |
1023 (match-beginning 1) | |
1024 (match-end 1))) | |
1025 t) | |
1026 | |
1027 ;; No more errors. | |
1028 (t | |
1029 (message "No more errors.") | |
1030 (beep) | |
1031 (pop-to-buffer old) | |
1032 nil)))))) | |
1033 | |
1034 (defun TeX-error () | |
1035 "Display an error." | |
1036 | |
1037 (let* (;; We need the error message to show the user. | |
1038 (error (progn | |
1039 (re-search-forward "\\(.*\\)") | |
1040 (TeX-match-buffer 1))) | |
1041 | |
1042 ;; And the context for the help window. | |
1043 (context-start (point)) | |
1044 | |
1045 ;; And the line number to position the cursor. | |
1046 (line (if (re-search-forward "l\\.\\([0-9]+\\)" nil t) | |
1047 (string-to-int (TeX-match-buffer 1)) | |
1048 1)) | |
1049 ;; And a string of the context to search for. | |
1050 (string (progn | |
1051 (beginning-of-line) | |
1052 (re-search-forward " \\(\\([^ \t]*$\\)\\|\\($\\)\\)") | |
1053 (TeX-match-buffer 1))) | |
1054 | |
1055 ;; And we have now found to the end of the context. | |
1056 (context (buffer-substring context-start (progn | |
1057 (forward-line 1) | |
1058 (end-of-line) | |
1059 (point)))) | |
1060 ;; We may use these in another buffer. | |
1061 (offset (car TeX-error-offset) ) | |
1062 (file (car TeX-error-file))) | |
1063 | |
1064 ;; Remember where we was. | |
1065 (setq TeX-error-point (point)) | |
1066 | |
1067 ;; Find the error. | |
1068 (if (null file) | |
1069 (error "Error occured after last TeX file closed")) | |
1070 (run-hooks 'TeX-translate-location-hook) | |
1071 (find-file-other-window file) | |
1072 (goto-line (+ offset line)) | |
1073 (if (not (string= string " ")) | |
1074 (search-forward string nil t)) | |
1075 | |
1076 ;; Explain the error. | |
1077 (if TeX-display-help | |
1078 (TeX-help-error error context) | |
1079 (message (concat "! " error))))) | |
1080 | |
1081 (defun TeX-warning (string) | |
1082 "Display a warning for STRING. | |
1083 Return nil if we gave a report." | |
1084 | |
1085 (let* ((error (concat "** " string)) | |
1086 | |
1087 ;; bad-box is nil if this is a "LaTeX Warning" | |
1088 (bad-box (string-match "^.*erfull \\\\.*[0-9]*--[0-9]*" string)) | |
1089 ;; line-string: match 1 is beginning line, match 2 is end line | |
1090 (line-string (if bad-box " \\([0-9]*\\)--\\([0-9]*\\)" | |
1091 "on input line \\([0-9]*\\)\\.")) | |
1092 ;; word-string: match 1 is the word | |
1093 (word-string (if bad-box "[][\\W() ---]\\(\\w+\\)[][\\W() ---]*$" | |
1094 "`\\(\\w+\\)'")) | |
1095 | |
1096 ;; Get error-line (warning) | |
1097 (line (progn | |
1098 (re-search-backward line-string) | |
1099 (string-to-int (TeX-match-buffer 1)))) | |
1100 (line-end (if bad-box (string-to-int (TeX-match-buffer 2)) | |
1101 line)) | |
1102 | |
1103 ;; Find the context | |
1104 (context-start (progn (if bad-box (end-of-line) | |
1105 (beginning-of-line)) | |
1106 (point))) | |
1107 | |
1108 (context (progn | |
1109 (forward-line 1) | |
1110 (end-of-line) | |
1111 (while (equal (current-column) 79) | |
1112 (forward-line 1) | |
1113 (end-of-line)) | |
1114 (buffer-substring context-start (point)))) | |
1115 | |
1116 ;; This is where we want to be. | |
1117 (error-point (point)) | |
1118 | |
1119 ;; Now find the error word. | |
1120 (string (progn | |
1121 (re-search-backward word-string | |
1122 context-start t) | |
1123 (TeX-match-buffer 1))) | |
1124 | |
1125 ;; We might use these in another file. | |
1126 (offset (car TeX-error-offset)) | |
1127 (file (car TeX-error-file))) | |
1128 | |
1129 ;; This is where we start next time. | |
1130 (goto-char error-point) | |
1131 (setq TeX-error-point (point)) | |
1132 | |
1133 ;; Go back to TeX-buffer | |
1134 (if TeX-debug-bad-boxes | |
1135 (progn | |
1136 (run-hooks 'TeX-translate-location-hook) | |
1137 (find-file-other-window file) | |
1138 ;; Find line and string | |
1139 (goto-line (+ offset line)) | |
1140 (beginning-of-line 0) | |
1141 (let ((start (point))) | |
1142 (goto-line (+ offset line-end)) | |
1143 (end-of-line) | |
1144 (search-backward string start t) | |
1145 (search-forward string nil t)) | |
1146 ;; Display help | |
1147 (if TeX-display-help | |
1148 (TeX-help-error error (if bad-box context (concat "\n" context))) | |
1149 (message (concat "! " error))) | |
1150 nil) | |
1151 t))) | |
1152 | |
1153 ;;; - Help | |
1154 | |
1155 (defun TeX-help-error (error output) | |
1156 "Print ERROR in context OUTPUT in another window." | |
1157 | |
1158 (let ((old-buffer (current-buffer)) | |
1159 (log-file (TeX-active-master "log")) | |
1160 (TeX-error-pointer 1)) | |
1161 | |
1162 ;; Find help text entry. | |
1163 (while (not (string-match (car (nth TeX-error-pointer | |
1164 TeX-error-description-list)) | |
1165 error)) | |
1166 (setq TeX-error-pointer (+ TeX-error-pointer 1))) | |
1167 | |
1168 (pop-to-buffer (get-buffer-create "*TeX Help*")) | |
1169 (erase-buffer) | |
1170 (insert "ERROR: " error | |
1171 "\n\n--- TeX said ---" | |
1172 output | |
1173 "\n--- HELP ---\n" | |
1174 (save-excursion | |
1175 (if (and (string= (cdr (nth TeX-error-pointer | |
1176 TeX-error-description-list)) | |
1177 "No help available") | |
1178 (let* ((log-buffer (find-file-noselect log-file))) | |
1179 (set-buffer log-buffer) | |
1180 (auto-save-mode nil) | |
1181 (setq buffer-read-only t) | |
1182 (goto-line (point-min)) | |
1183 (search-forward error nil t 1))) | |
1184 (progn | |
1185 (re-search-forward "^l.") | |
1186 (re-search-forward "^ [^\n]+$") | |
1187 (forward-char 1) | |
1188 (let ((start (point))) | |
1189 (re-search-forward "^$") | |
1190 (concat "From the .log file...\n\n" | |
1191 (buffer-substring start (point))))) | |
1192 (cdr (nth TeX-error-pointer | |
1193 TeX-error-description-list))))) | |
1194 (goto-char (point-min)) | |
1195 (pop-to-buffer old-buffer))) | |
1196 | |
1197 ;;; Error Messages | |
1198 | |
1199 (defvar TeX-error-description-list | |
1200 '(("Bad \\\\line or \\\\vector argument.*" . | |
1201 "The first argument of a \\line or \\vector command, which specifies the | |
1202 slope, is illegal\.") | |
1203 | |
1204 ("Bad math environment delimiter.*" . | |
1205 "TeX has found either a math-mode-starting command such as \\[ or \\( | |
1206 when it is already in math mode, or else a math-mode-ending command | |
1207 such as \\) or \\] while in LR or paragraph mode. The problem is caused | |
1208 by either unmatched math mode delimiters or unbalanced braces\.") | |
1209 | |
1210 ("Bad use of \\\\\\\\.*" . | |
1211 "A \\\\ command appears between paragraphs, where it makes no sense. This | |
1212 error message occurs when the \\\\ is used in a centering or flushing | |
1213 environment or else in the scope of a centering or flushing | |
1214 declaration.") | |
1215 | |
1216 ("\\\\begin{[^ ]*} ended by \\\\end{[^ ]*}." . | |
1217 "LaTeX has found an \\end command that doesn't match the corresponding | |
1218 \\begin command. You probably misspelled the environment name in the | |
1219 \\end command, have an extra \\begin, or else forgot an \\end.") | |
1220 | |
1221 ("Can be used only in preamble." . | |
1222 "LaTeX has encountered, after the \\begin{document}, one of the | |
1223 following commands that should appear only in the preamble: | |
1224 \\documentstyle, \\nofiles, \\includeonly, \\makeindex, or | |
1225 \\makeglossary. The error is also caused by an extra \\begin{document} | |
1226 command.") | |
1227 | |
1228 ("Command name [^ ]* already used.*" . | |
1229 "You are using \\newcommand, \\newenvironment, \\newlength, \\newsavebox, | |
1230 or \\newtheorem to define a command or environment name that is | |
1231 already defined, or \\newcounter to define a counter that already | |
1232 exists. (Defining an environment named gnu automatically defines the | |
1233 command \\gnu.) You'll have to choose a new name or, in the case of | |
1234 \\newcommand or \\newenvironment, switch to the \\renew ... command.") | |
1235 | |
1236 ("Counter too large." . | |
1237 "Some object that is numbered with letters, probably an item in a | |
1238 enumerated list, has received a number greater than 26. Either you're | |
1239 making a very long list or you've been resetting counter values.") | |
1240 | |
1241 ("Environment [^ ]* undefined." . | |
1242 "LaTeX has encountered a \\begin command for a nonexistent environment. | |
1243 You probably misspelled the environment name. ") | |
1244 | |
1245 ("Float(s) lost." . | |
1246 "You put a figure or table environment or a \\marginpar command inside a | |
1247 parbox---either one made with a minipage environment or \\parbox | |
1248 command, or one constructed by LaTeX in making a footnote, figure, | |
1249 etc. This is an outputting error, and the offending environment or | |
1250 command may be quite a way back from the point where LaTeX discovered | |
1251 the problem. One or more figures, tables, and/or marginal notes have | |
1252 been lost, but not necessarily the one that caused the error.") | |
1253 | |
1254 ("Illegal character in array arg." . | |
1255 "There is an illegal character in the argument of an array or tabular | |
1256 environment, or in the second argument of a \\multicolumn command.") | |
1257 | |
1258 ("Missing \\\\begin{document}." . | |
1259 "LaTeX produced printed output before encountering a \\begin{document} | |
1260 command. Either you forgot the \\begin{document} command or there is | |
1261 something wrong in the preamble. The problem may be a stray character | |
1262 or an error in a declaration---for example, omitting the braces around | |
1263 an argument or forgetting the \\ in a command name.") | |
1264 | |
1265 ("Missing p-arg in array arg.*" . | |
1266 "There is a p that is not followed by an expression in braces in the | |
1267 argument of an array or tabular environment, or in the second argument | |
1268 of a \\multicolumn command.") | |
1269 | |
1270 ("Missing @-exp in array arg." . | |
1271 "There is an @ character not followed by an @-expression in the | |
1272 argument of an array or tabular environment, or in the second argument | |
1273 of a \\multicolumn command.") | |
1274 | |
1275 ("No such counter." . | |
1276 "You have specified a nonexistent counter in a \\setcounter or | |
1277 \\addtocounter command. This is probably caused by a simple typing | |
1278 error. However, if the error occurred while a file with the extension | |
1279 aux is being read, then you probably used a \\newcounter command | |
1280 outside the preamble.") | |
1281 | |
1282 ("Not in outer par mode." . | |
1283 "You had a figure or table environment or a \\marginpar command in math | |
1284 mode or inside a parbox.") | |
1285 | |
1286 ("\\\\pushtabs and \\\\poptabs don't match." . | |
1287 "LaTeX found a \\poptabs with no matching \\pushtabs, or has come to the | |
1288 \\end{tabbing} command with one or more unmatched \\pushtabs commands.") | |
1289 | |
1290 ("Something's wrong--perhaps a missing \\\\item." . | |
1291 "The most probable cause is an omitted \\item command in a list-making | |
1292 environment. It is also caused by forgetting the argument of a | |
1293 thebibliography environment.") | |
1294 | |
1295 ("Tab overflow." . | |
1296 "A \\= command has exceeded the maximum number of tab stops that LaTeX | |
1297 permits.") | |
1298 | |
1299 ("There's no line here to end." . | |
1300 "A \\newline or \\\\ command appears between paragraphs, where it makes no | |
1301 sense. If you're trying to ``leave a blank line'', use a \\vspace | |
1302 command.") | |
1303 | |
1304 ("This may be a LaTeX bug." . | |
1305 "LaTeX has become thoroughly confused. This is probably due to a | |
1306 previously detected error, but it is possible that you have found an | |
1307 error in LaTeX itself. If this is the first error message produced by | |
1308 the input file and you can't find anything wrong, save the file and | |
1309 contact the person listed in your Local Guide.") | |
1310 | |
1311 ("Too deeply nested." . | |
1312 "There are too many list-making environments nested within one another. | |
1313 How many levels of nesting are permitted may depend upon what computer | |
1314 you are using, but at least four levels are provided, which should be | |
1315 enough.") | |
1316 | |
1317 ("Too many unprocessed floats." . | |
1318 "While this error can result from having too many \\marginpar commands | |
1319 on a page, a more likely cause is forcing LaTeX to save more figures | |
1320 and tables than it has room for. When typesetting its continuous | |
1321 scroll, LaTeX saves figures and tables separately and inserts them as | |
1322 it cuts off pages. This error occurs when LaTeX finds too many figure | |
1323 and/or table environments before it is time to cut off a page, a | |
1324 problem that is solved by moving some of the environments farther | |
1325 towards the end of the input file. The error can also be caused by a | |
1326 ``logjam''---a figure or table that cannot be printed causing others | |
1327 to pile up behind it, since LaTeX will not print figures or tables out | |
1328 of order. The jam can be started by a figure or table that either is | |
1329 too large to fit on a page or won't fit where its optional placement | |
1330 argument says it must go. This is likely to happen if the argument | |
1331 does not contain a p option.") | |
1332 | |
1333 ("Undefined tab position." . | |
1334 "A \\>, \\+, \\-, or \\< command is trying to go to a nonexistent tab | |
1335 position---one not defined by a \\= command.") | |
1336 | |
1337 ("\\\\< in mid line." . | |
1338 "A \\< command appears in the middle of a line in a tabbing environment. | |
1339 This command should come only at the beginning of a line.") | |
1340 | |
1341 ("Counter too large." . | |
1342 "Footnotes are being ``numbered'' with letters or footnote symbols and | |
1343 LaTeX has run out of letters or symbols. This is probably caused by | |
1344 too many \\thanks commands.") | |
1345 | |
1346 ("Double subscript." . | |
1347 "There are two subscripts in a row in a mathematical | |
1348 formula---something like x_{2}_{3}, which makes no sense.") | |
1349 | |
1350 ("Double superscript." . | |
1351 "There are two superscripts in a row in a mathematical | |
1352 formula---something like x^{2}^{3}, which makes no sense.") | |
1353 | |
1354 ("Extra alignment tab has been changed to \\\\cr." . | |
1355 "There are too many separate items (column entries) in a single row of | |
1356 an array or tabular environment. In other words, there were too many & | |
1357 's before the end of the row. You probably forgot the \\\\ at the end of | |
1358 the preceding row.") | |
1359 | |
1360 ("Extra \\}, or forgotten \\$." . | |
1361 "The braces or math mode delimiters don't match properly. You probably | |
1362 forgot a {, \\[, \\(, or $.") | |
1363 | |
1364 ("Font [^ ]* not loaded: Not enough room left." . | |
1365 "The document uses more fonts than TeX has room for. If different parts | |
1366 of the document use different fonts, then you can get around the | |
1367 problem by processing it in parts.") | |
1368 | |
1369 ("I can't find file `.*'." . | |
1370 "TeX can't find a file that it needs. If the name of the missing file | |
1371 has the extension tex, then it is looking for an input file that you | |
1372 specified---either your main file or another file inserted with an | |
1373 \\input or \\include command. If the missing file has the extension sty | |
1374 , then you have specified a nonexistent document style or style | |
1375 option.") | |
1376 | |
1377 ("Illegal parameter number in definition of .*" . | |
1378 "This is probably caused by a \\newcommand, \\renewcommand, | |
1379 \\newenvironment, or \\renewenvironment command in which a # is used | |
1380 incorrectly. A # character, except as part of the command name \\#, | |
1381 can be used only to indicate an argument parameter, as in #2, which | |
1382 denotes the second argument. This error is also caused by nesting one | |
1383 of the above four commands inside another, or by putting a parameter | |
1384 like #2 in the last argument of a \\newenvironment or \\renewenvironment | |
1385 command.") | |
1386 | |
1387 ("Illegal unit of measure ([^ ]* inserted)." . | |
1388 "If you just got a | |
1389 | |
1390 ! Missing number, treated as zero. | |
1391 | |
1392 error, then this is part of the same problem. If not, it means that | |
1393 LaTeX was expecting a length as an argument and found a number | |
1394 instead. The most common cause of this error is writing 0 instead of | |
1395 something like 0in for a length of zero, in which case typing return | |
1396 should result in correct output. However, the error can also be caused | |
1397 by omitting a command argument.") | |
1398 | |
1399 ("Misplaced alignment tab character \\&." . | |
1400 "The special character &, which should be used only to separate items | |
1401 in an array or tabular environment, appeared in ordinary text. You | |
1402 probably meant to type \\&.") | |
1403 | |
1404 ("Missing control sequence inserted." . | |
1405 "This is probably caused by a \\newcommand, \\renewcommand, \\newlength, | |
1406 or \\newsavebox command whose first argument is not a command name.") | |
1407 | |
1408 ("Missing number, treated as zero." . | |
1409 "This is usually caused by a LaTeX command expecting but not finding | |
1410 either a number or a length as an argument. You may have omitted an | |
1411 argument, or a square bracket in the text may have been mistaken for | |
1412 the beginning of an optional argument. This error is also caused by | |
1413 putting \\protect in front of either a length command or a command such | |
1414 as \\value that produces a number.") | |
1415 | |
1416 ("Missing [{}] inserted." . | |
1417 "TeX has become confused. The position indicated by the error locator | |
1418 is probably beyond the point where the incorrect input is.") | |
1419 | |
1420 ("Missing \\$ inserted." . | |
1421 "TeX probably found a command that can be used only in math mode when | |
1422 it wasn't in math mode. Remember that unless stated otherwise, all | |
1423 the commands of Section can be used only in math mode. TeX is not in | |
1424 math mode when it begins processing the argument of a box-making | |
1425 command, even if that command is inside a math environment. This error | |
1426 also occurs if TeX encounters a blank line when it is in math mode.") | |
1427 | |
1428 ("Not a letter." . | |
1429 "Something appears in the argument of a \\hyphenation command that | |
1430 doesn't belong there.") | |
1431 | |
1432 ("Paragraph ended before [^ ]* was complete." . | |
1433 "A blank line occurred in a command argument that shouldn't contain | |
1434 one. You probably forgot the right brace at the end of an argument.") | |
1435 | |
1436 ("\\\\[^ ]*font [^ ]* is undefined .*" . | |
1437 "These errors occur when an uncommon font is used in math mode---for | |
1438 example, if you use a \\sc command in a formula inside a footnote, | |
1439 calling for a footnote-sized small caps font. This problem is solved | |
1440 by using a \\load command.") | |
1441 | |
1442 ("Font .* not found." . | |
1443 "You requested a family/series/shape/size combination that is totally | |
1444 unknown. There are two cases in which this error can occur: | |
1445 1) You used the \\size macro to select a size that is not available. | |
1446 2) If you did not do that, go to your local `wizard' and | |
1447 complain fiercely that the font selection tables are corrupted!") | |
1448 | |
1449 ("TeX capacity exceeded, sorry .*" . | |
1450 "TeX has just run out of space and aborted its execution. Before you | |
1451 panic, remember that the least likely cause of this error is TeX not | |
1452 having the capacity to process your document. It was probably an | |
1453 error in your input file that caused TeX to run out of room. The | |
1454 following discussion explains how to decide whether you've really | |
1455 exceeded TeX's capacity and, if so, what to do. If the problem is an | |
1456 error in the input, you may have to use the divide and conquer method | |
1457 described previously to locate it. LaTeX seldom runs out of space on a | |
1458 short input file, so if running it on the last few pages before the | |
1459 error indicator's position still produces the error, then there's | |
1460 almost certainly something wrong in the input file. | |
1461 | |
1462 The end of the error indicator tells what kind of space TeX ran out | |
1463 of. The more common ones are listed below, with an explanation of | |
1464 their probable causes. | |
1465 | |
1466 buffer size | |
1467 =========== | |
1468 Can be caused by too long a piece of text as the argument | |
1469 of a sectioning, \\caption, \\addcontentsline, or \\addtocontents | |
1470 command. This error will probably occur when the \\end{document} is | |
1471 being processed, but it could happen when a \\tableofcontents, | |
1472 \\listoffigures, or \\listoftables command is executed. To solve this | |
1473 problem, use a shorter optional argument. Even if you're producing a | |
1474 table of contents or a list of figures or tables, such a long entry | |
1475 won't help the reader. | |
1476 | |
1477 exception dictionary | |
1478 ==================== | |
1479 You have used \\hyphenation commands to give TeX | |
1480 more hyphenation information than it has room for. Remove some of the | |
1481 less frequently used words from the \\hyphenation commands and insert | |
1482 \\- commands instead. | |
1483 | |
1484 hash size | |
1485 ========= | |
1486 Your input file defines too many command names and/or uses | |
1487 too many cross-ref- erencing labels. | |
1488 | |
1489 input stack size | |
1490 ================ | |
1491 This is probably caused by an error in a command | |
1492 definition. For example, the following command makes a circular | |
1493 definition, defining \\gnu in terms of itself: | |
1494 | |
1495 \\newcommand{\\gnu}{a \\gnu} % This is wrong! | |
1496 | |
1497 When TeX encounters this \\gnu command, it will keep chasing its tail | |
1498 trying to figure out what \\gnu should produce, and eventually run out | |
1499 of ``input stack''. | |
1500 | |
1501 main memory size | |
1502 ================ | |
1503 This is one kind of space that TeX can run out of when processing a | |
1504 short file. There are three ways you can run TeX out of main memory | |
1505 space: (1) defining a lot of very long, complicated commands, (2) | |
1506 making an index or glossary and having too many \\index or \\glossary | |
1507 commands on a single page, and (3) creating so complicated a page of | |
1508 output that TeX can't hold all the information needed to generate it. | |
1509 The solution to the first two problems is obvious: define fewer | |
1510 commands or use fewer \\index and \\glossary commands. The third problem | |
1511 is nastier. It can be caused by large tabbing, tabular, array, and | |
1512 picture environments. TeX's space may also be filled up with figures | |
1513 and tables waiting for a place to go. To find out if you've really | |
1514 exceeded TeX's capacity in this way, put a \\clearpage command in your | |
1515 input file right before the place where TeX ran out of room and try | |
1516 running it again. If it doesn't run out of room with the \\clearpage | |
1517 command there, then you did exceed TeX's capacity. If it still runs | |
1518 out of room, then there's probably an error in your file. If TeX is | |
1519 really out of room, you must give it some help. Remember that TeX | |
1520 processes a complete paragraph before deciding whether to cut the | |
1521 page. Inserting a \\newpage command in the middle of the paragraph, | |
1522 where TeX should break the page, may save the day by letting TeX write | |
1523 the current page before processing the rest of the paragraph. (A | |
1524 \\pagebreak command won't help.) If the problem is caused by | |
1525 accumulated figures and tables, you can try to prevent them from | |
1526 accumulating---either by moving them further towards the end of the | |
1527 document or by trying to get them to come out sooner. If you are | |
1528 still writing the document, simply add a \\clearpage command and forget | |
1529 about the problem until you're ready to produce the final version. | |
1530 Changes to the input file are likely to make the problem go away. | |
1531 | |
1532 pool size | |
1533 ========= | |
1534 You probably used too many cross-ref-erencing \\labels and/or defined | |
1535 too many new command names. More precisely, the labels and command | |
1536 names that you define have too many characters, so this problem can be | |
1537 solved by using shorter names. However, the error can also be caused | |
1538 by omitting the right brace that ends the argument of either a counter | |
1539 command such as \\setcounter, or a \\newenvironment or \\newtheorem | |
1540 command. | |
1541 | |
1542 save size | |
1543 ========= | |
1544 This occurs when commands, environments, and the scopes of | |
1545 declarations are nested too deeply---for example, by having the | |
1546 argument of a \\multiput command contain a picture environment that in | |
1547 turn has a \\footnotesize declaration whose scope contains a \\multiput | |
1548 command containing a ....") | |
1549 | |
1550 ("Text line contains an invalid character." . | |
1551 "The input contains some strange character that it shouldn't. A mistake | |
1552 when creating the file probably caused your text editor to insert this | |
1553 character. Exactly what could have happened depends upon what text | |
1554 editor you used. If examining the input file doesn't reveal the | |
1555 offending character, consult the Local Guide for suggestions.") | |
1556 | |
1557 ("Undefined control sequence." . | |
1558 "TeX encountered an unknown command name. You probably misspelled the | |
1559 name. If this message occurs when a LaTeX command is being processed, | |
1560 the command is probably in the wrong place---for example, the error | |
1561 can be produced by an \\item command that's not inside a list-making | |
1562 environment. The error can also be caused by a missing \\documentstyle | |
1563 command.") | |
1564 | |
1565 ("Use of [^ ]* doesn't match its definition." . | |
1566 "It's probably one of the picture-drawing commands, and you have used | |
1567 the wrong syntax for specifying an argument. If it's \\@array that | |
1568 doesn't match its definition, then there is something wrong in an | |
1569 @-expression in the argument of an array or tabular | |
1570 environment---perhaps a fragile command that is not \\protect'ed.") | |
1571 | |
1572 ("You can't use `macro parameter character \\#' in [^ ]* mode." . | |
1573 "The special character # has appeared in ordinary text. You probably | |
1574 meant to type \\#.") | |
1575 | |
1576 ("Overfull \\\\hbox .*" . | |
1577 "Because it couldn't find a good place for a line break, TeX put more | |
1578 on this line than it should.") | |
1579 | |
1580 ("Overfull \\\\vbox .*" . | |
1581 "Because it couldn't find a good place for a page break, TeX put more | |
1582 on the page than it should. ") | |
1583 | |
1584 ("Underfull \\\\hbox .*" . | |
1585 "Check your output for extra vertical space. If you find some, it was | |
1586 probably caused by a problem with a \\\\ or \\newline command---for | |
1587 example, two \\\\ commands in succession. This warning can also be | |
1588 caused by using the sloppypar environment or \\sloppy declaration, or | |
1589 by inserting a \\linebreak command.") | |
1590 | |
1591 ("Underfull \\\\vbox .*" . | |
1592 "TeX could not find a good place to break the page, so it produced a | |
1593 page without enough text on it. ") | |
1594 | |
1595 ;; New list items should be placed here | |
1596 ;; | |
1597 ;; ("err-regexp" . "context") | |
1598 ;; | |
1599 ;; the err-regexp item should match anything | |
1600 | |
1601 (".*" . "No help available")) ; end definition | |
1602 "A list of the form (\"err-regexp\" . \"context\") used by function | |
1603 \\{TeX-help-error} to display help-text on an error message or warning. | |
1604 err-regexp should be a regular expression matching the error message | |
1605 given from TeX/LaTeX, and context should be some lines describing that | |
1606 error") | |
1607 | |
1608 (provide 'tex-buf) | |
1609 | |
1610 ;;; tex-buf.el ends here |