-(defvar tex-error-parse-syntax-table
- (let ((st (make-syntax-table)))
- (modify-syntax-entry ?\( "()" st)
- (modify-syntax-entry ?\) ")(" st)
- (modify-syntax-entry ?\\ "\\" st)
- (modify-syntax-entry ?\{ "_" st)
- (modify-syntax-entry ?\} "_" st)
- (modify-syntax-entry ?\[ "_" st)
- (modify-syntax-entry ?\] "_" st)
- ;; Single quotations may appear in errors
- (modify-syntax-entry ?\" "_" st)
- st)
- "Syntax-table used while parsing TeX error messages.")
-
-(defun tex-compilation-parse-errors (limit-search find-at-least)
- "Parse the current buffer as TeX error messages.
-See the variable `compilation-parse-errors-function' for the interface it uses.
-
-This function parses only the last TeX compilation.
-It works on TeX compilations only. It is necessary for that purpose,
-since TeX does not put file names and line numbers on the same line as
-for the error messages."
- (require 'thingatpt)
- (setq compilation-error-list nil)
- (let ((default-directory ; Perhaps dir has changed meanwhile.
- (file-name-directory (buffer-file-name tex-last-buffer-texed)))
- found-desired (num-errors-found 0)
- last-filename last-linenum last-position
- begin-of-error end-of-error errfilename)
- ;; Don't reparse messages already seen at last parse.
- (goto-char compilation-parsing-end)
- ;; Parse messages.
- (while (and (not (or found-desired (eobp)))
- ;; First alternative handles the newer --file-line-error style:
- ;; ./test2.tex:14: Too many }'s.
- ;; Second handles the old-style:
- ;; ! Too many }'s.
- (prog1 (re-search-forward
- "^\\(?:\\([^:\n]+\\):[[:digit:]]+:\\|!\\) " nil 'move)
- (setq begin-of-error (match-beginning 0)
- end-of-error (match-end 0)
- errfilename (match-string 1)))
- (re-search-forward
- "^l\\.\\([0-9]+\\) \\(\\.\\.\\.\\)?\\(.*\\)$" nil 'move))
- (let* ((this-error (copy-marker begin-of-error))
- (linenum (string-to-number (match-string 1)))
- (error-text (regexp-quote (match-string 3)))
- try-filename
- (filename
- ;; Prefer --file-liner-error filename if we have it.
- (or errfilename
- (save-excursion
- (with-syntax-table tex-error-parse-syntax-table
- (backward-up-list 1)
- (skip-syntax-forward "(_")
- (while (not
- (and (setq try-filename (thing-at-point
- 'filename))
- (not (string= "" try-filename))
- (file-readable-p try-filename)))
- (skip-syntax-backward "(_")
- (backward-up-list 1)
- (skip-syntax-forward "(_"))
- (thing-at-point 'filename)))))
- (new-file
- (or (null last-filename)
- (not (string-equal last-filename filename))))
- (error-location
- (with-current-buffer
- (if (equal filename (concat tex-zap-file ".tex"))
- tex-last-buffer-texed
- (find-file-noselect filename))
- (save-excursion
- (if new-file
- (progn
- (goto-char (point-min))
- (forward-line (1- linenum))
- (setq last-position nil))
- (goto-char last-position)
- (forward-line (- linenum last-linenum)))
- ;; first try a forward search for the error text,
- ;; then a backward search limited by the last error.
- (let ((starting-point (point)))
- (or (re-search-forward error-text nil t)
- (re-search-backward error-text last-position t)
- (goto-char starting-point)))
- (point-marker)))))
- (goto-char this-error)
- (if (and compilation-error-list
- (or (and find-at-least
- (>= num-errors-found
- find-at-least))
- (and limit-search
- (>= end-of-error limit-search)))
- new-file)
- (setq found-desired t)
- (setq num-errors-found (1+ num-errors-found)
- last-filename filename
- last-linenum linenum
- last-position error-location
- compilation-error-list ; Add the new error
- (cons (cons this-error error-location)
- compilation-error-list))
- (goto-char end-of-error)))))
- (set-marker compilation-parsing-end (point))
- (setq compilation-error-list (nreverse compilation-error-list)))
-\f