Function: TeX-find-display-help

TeX-find-display-help is a byte-compiled function defined in tex.el.

Signature

(TeX-find-display-help TYPE FILE LINE ERROR OFFSET CONTEXT STRING LINE-END BAD-BOX ERROR-POINT IGNORE)

Documentation

Find the error and display the help.

For a description of arguments, see TeX-error-list. IGNORE value is not used here.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/tex.el
(defun TeX-find-display-help (type file line error offset context string
                                   line-end _bad-box error-point _ignore)
  "Find the error and display the help.

For a description of arguments, see `TeX-error-list'.  IGNORE
value is not used here."
  ;; Go back to TeX-buffer
  (let ((runbuf (TeX-active-buffer))
        (master (with-current-buffer TeX-command-buffer
                  (expand-file-name (TeX-master-file))))
        (command-buffer TeX-command-buffer)
        (TeX-translate-location-file file)
        (TeX-translate-location-line line)
        (TeX-translate-location-error error)
        (TeX-translate-location-offset offset)
        (TeX-translate-location-context context)
        (TeX-translate-location-string string)
        error-file-buffer)

    (run-hooks 'TeX-translate-location-hook)

    (if TeX-translate-location-file
        (progn
          (setq error-file-buffer
                (find-file
                 (expand-file-name TeX-translate-location-file
                                   (file-name-directory master))))
          ;; Use the major mode of `TeX-command-buffer' when visiting
          ;; the error point.
          (if (eq major-mode (default-value 'major-mode))
              (funcall (buffer-local-value 'major-mode command-buffer)))
          ;; Set the value of `TeX-command-buffer' in the next file
          ;; with an error to be displayed to the value it has in the
          ;; current buffer.
          (setq-local TeX-command-buffer command-buffer)

          ;; Find the location of the error or warning.
          (let ((narrowed (buffer-narrowed-p))
                (visible-min (point-min))
                (visible-max (point-max))
                target-pos)
            (when TeX-translate-location-line
              (save-restriction
                (widen)
                (goto-char (point-min))
                (forward-line (+ TeX-translate-location-offset
                                 TeX-translate-location-line -1))
                (if (equal type 'error)
                    ;; Error.
                    (unless (string= TeX-translate-location-string " ")
                      (search-forward TeX-translate-location-string nil t))
                  ;; Warning or bad box.
                  (beginning-of-line 0)
                  (let ((start (point)))
                    (goto-char (point-min))
                    (forward-line (+ TeX-translate-location-offset
                                     line-end -1))
                    (end-of-line)
                    (when TeX-translate-location-string
                      (search-backward TeX-translate-location-string start t)
                      (search-forward TeX-translate-location-string nil t))))
                (setq target-pos (point))))
            (when (and target-pos narrowed
                       (not (<= visible-min target-pos visible-max)))
              ;; The error lies outside the restriction, so widen first.
              (widen))
            (when target-pos
              (goto-char target-pos))))
      ;; When the file cannot be determined stay here but issue a
      ;; warning.
      (message "Could not determine file for %s"
               (if (eq type 'error) "error" "warning"))
      (beep))

    ;; Display the help.
    (cond ((eq TeX-display-help 'expert)
           (TeX-pop-to-buffer runbuf nil t)
           (goto-char error-point)
           (if error-file-buffer
               (TeX-pop-to-buffer error-file-buffer nil t)))
          (TeX-display-help
           (TeX-help-error
            TeX-translate-location-error
            (if (equal type 'warning)
                (concat "\n" TeX-translate-location-context)
              TeX-translate-location-context)
            runbuf type))
          (t
           (message "! %s" TeX-translate-location-error)))))