diff options
| -rw-r--r-- | lisp/textmodes/tex-mode.el | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index 2f8207070ea..0bd135aaebc 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | ;; Keywords: tex | 6 | ;; Keywords: tex |
| 7 | 7 | ||
| 8 | ;; Contributions over the years by William F. Schelter, Dick King, | 8 | ;; Contributions over the years by William F. Schelter, Dick King, |
| 9 | ;; Stephen Gildea, Michael Prange, and Edward M. Reingold. | 9 | ;; Stephen Gildea, Michael Prange, and Jacob Gore. |
| 10 | 10 | ||
| 11 | ;; This file is part of GNU Emacs. | 11 | ;; This file is part of GNU Emacs. |
| 12 | 12 | ||
| @@ -28,6 +28,7 @@ | |||
| 28 | 28 | ||
| 29 | ;; This was a pain. Now, make-comint should autoload comint. | 29 | ;; This was a pain. Now, make-comint should autoload comint. |
| 30 | ;; (require 'comint) | 30 | ;; (require 'comint) |
| 31 | (require 'compile) | ||
| 31 | 32 | ||
| 32 | ;;;###autoload | 33 | ;;;###autoload |
| 33 | (defvar tex-shell-file-name nil | 34 | (defvar tex-shell-file-name nil |
| @@ -608,6 +609,81 @@ Puts point on a blank line between them." | |||
| 608 | (insert "\\end" text) | 609 | (insert "\\end" text) |
| 609 | (if new-line-needed (insert ?\n)))) | 610 | (if new-line-needed (insert ?\n)))) |
| 610 | 611 | ||
| 612 | (defun tex-compilation-parse-errors () | ||
| 613 | "Parse the current buffer as error messages. | ||
| 614 | This makes a list of error descriptors, compilation-error-list. | ||
| 615 | For each source-file, line-number pair in the buffer, | ||
| 616 | the source file is read in, and the text location is saved in | ||
| 617 | compilation-error-list. The function next-error, assigned to | ||
| 618 | \\[next-error], takes the next error off the list and visits its location. | ||
| 619 | |||
| 620 | This function works on TeX compilations only. It is necessary for | ||
| 621 | that purpose, since TeX does not put file names on the same line as | ||
| 622 | line numbers for the errors." | ||
| 623 | (setq compilation-error-list nil) | ||
| 624 | (message "Parsing error messages...") | ||
| 625 | (modify-syntax-entry ?\{ "_") | ||
| 626 | (modify-syntax-entry ?\} "_") | ||
| 627 | (modify-syntax-entry ?\[ "_") | ||
| 628 | (modify-syntax-entry ?\] "_") | ||
| 629 | (make-variable-buffer-local 'compilation-error-regexp) | ||
| 630 | (setq compilation-error-regexp "^l\.[0-9]+ ") | ||
| 631 | (let (text-buffer | ||
| 632 | last-filename last-linenum) | ||
| 633 | ;; Don't reparse messages already seen at last parse. | ||
| 634 | (goto-char compilation-parsing-end) | ||
| 635 | ;; Don't parse the first two lines as error messages. | ||
| 636 | ;; This matters for grep. | ||
| 637 | (if (bobp) | ||
| 638 | (forward-line 2)) | ||
| 639 | (while (re-search-forward compilation-error-regexp nil t) | ||
| 640 | (let (linenum filename | ||
| 641 | error-marker text-marker) | ||
| 642 | ;; Extract file name and line number from error message. | ||
| 643 | ;; Line number is 2 away from beginning of line: "l.23" | ||
| 644 | (beginning-of-line) | ||
| 645 | (goto-char (+ (point) 2)) | ||
| 646 | (setq linenum (read (current-buffer))) | ||
| 647 | ;; The file is the one that was opened last and is still open. | ||
| 648 | ;; We need to find the last open parenthesis. | ||
| 649 | (insert ?\)) | ||
| 650 | (backward-sexp) | ||
| 651 | (forward-char) | ||
| 652 | (setq filename (compilation-grab-filename)) | ||
| 653 | ;; Locate the erring file and line. | ||
| 654 | (if (and (equal filename last-filename) | ||
| 655 | (= linenum last-linenum)) | ||
| 656 | nil | ||
| 657 | (skip-chars-backward "^(") | ||
| 658 | (backward-char) | ||
| 659 | (forward-sexp) | ||
| 660 | (backward-delete-char 1) | ||
| 661 | (setq error-marker (point-marker)) | ||
| 662 | ;; text-buffer gets the buffer containing this error's file. | ||
| 663 | (if (not (equal filename last-filename)) | ||
| 664 | (setq text-buffer | ||
| 665 | (and (file-exists-p (setq last-filename filename)) | ||
| 666 | (find-file-noselect filename)) | ||
| 667 | last-linenum 0)) | ||
| 668 | (if text-buffer | ||
| 669 | ;; Go to that buffer and find the erring line. | ||
| 670 | (save-excursion | ||
| 671 | (set-buffer text-buffer) | ||
| 672 | (if (zerop last-linenum) | ||
| 673 | (progn | ||
| 674 | (goto-char 1) | ||
| 675 | (setq last-linenum 1))) | ||
| 676 | (forward-line (- linenum last-linenum)) | ||
| 677 | (setq last-linenum linenum) | ||
| 678 | (setq text-marker (point-marker)) | ||
| 679 | (setq compilation-error-list | ||
| 680 | (cons (list error-marker text-marker) | ||
| 681 | compilation-error-list))))) | ||
| 682 | (forward-line 1))) | ||
| 683 | (setq compilation-parsing-end (point-max))) | ||
| 684 | (message "Parsing error messages...done") | ||
| 685 | (setq compilation-error-list (nreverse compilation-error-list))) | ||
| 686 | |||
| 611 | ;;; Invoking TeX in an inferior shell. | 687 | ;;; Invoking TeX in an inferior shell. |
| 612 | 688 | ||
| 613 | ;;; Why use a shell instead of running TeX directly? Because if TeX | 689 | ;;; Why use a shell instead of running TeX directly? Because if TeX |