Hello,

I have modified TeX-LaTeX-sentinel a bit for my uses and I think other AUCTeX 
users could benefit from these modifications. The motivation is that I wanted 
to be able to get an idea of the number of warnings and bad boxes and be able 
to see them if I explicitly call TeX-error-overview, while still being shown 
that overview if there are errors -- working with colleagues it is sometimes 
difficult to maintain a zero-warning life-style.

Attached is an incomplete patch. Here is a summary of changes:

- `TeX-error-overview-open-after-TeX-run` can have the value `errors` in which 
case only if there are errors would the TeX-error-overview open.
- When there are no errors, the number of warnings and bad boxes are always 
displayed. Also, rather than have several possible messages after compilation, 
the message is always something like:
XXX: successfully formatted {29} pages A -- B

or in some unusual cases
XXX: faced problems formatting {29} pages A -- B

where `A` is something like
(with 4 warnings and 5 bad boxes)

and `B` is something like
rerun Bibtex.
or
unresolved citations.

I find this a bit cleaner especially when I couple it with a "buffer-local" 
display rule for TeX-error-overview buffers and disable the selection of the 
error overview window when automatically opened after TeX-run.

-- Al
diff --git a/tex.el b/tex.el
index 6f8267ac..c5675f0a 100644
--- a/tex.el
+++ b/tex.el
@@ -8623,12 +8623,29 @@ Open the error overview if
 errors or warnings to show."
   (if TeX-parse-all-errors
       (TeX-parse-all-errors))
+
+  (let ((counts (make-hash-table))
+        rerun-msg)
+    (mapc (lambda (entry)
+            (let ((type (nth 0 entry)))
+              (puthash
+               type
+               (1+ (gethash type counts 0))
+               counts)))
+          TeX-error-list)
+
     (if (and (with-current-buffer TeX-command-buffer
-             TeX-error-overview-open-after-TeX-run)
+               (and TeX-error-overview-open-after-TeX-run
+                    (or (not (eq TeX-error-overview-open-after-TeX-run
+                                 'errors))
+                        (gethash 'error counts))))
              (TeX-error-overview-make-entries
               (TeX-master-directory) (TeX-active-buffer)))
         (TeX-error-overview))
-  (cond ((TeX-TeX-sentinel-check process name))
+
+    (setq TeX-command-next nil)
+    (unless (TeX-TeX-sentinel-check process name)
+      (cond
        ((and (save-excursion
                (re-search-forward
                 "^Package biblatex Warning: Please (re)run Biber on the file"
@@ -8640,9 +8657,9 @@ errors or warnings to show."
                                      (append TeX-file-extensions
                                              BibTeX-file-extensions
                                              TeX-Biber-file-extensions)))))
-         (message "%s%s" "You should run Biber to get citations right, "
-                  (TeX-current-pages))
-         (setq TeX-command-next (with-current-buffer TeX-command-buffer
+        (setq rerun-msg "run Biber")
+        (setq TeX-command-next
+              (with-current-buffer TeX-command-buffer
                 TeX-command-Biber)))
        ((and (save-excursion
                (re-search-forward
@@ -8654,96 +8671,89 @@ errors or warnings to show."
                                      (append TeX-file-extensions
                                              BibTeX-file-extensions
                                              TeX-Biber-file-extensions)))))
-         (message "%s%s" "You should run BibTeX to get citations right, "
-                  (TeX-current-pages))
+        (setq rerun-msg "run BibTeX")
         (setq TeX-command-next (with-current-buffer TeX-command-buffer
                                  TeX-command-BibTeX)))
        ((re-search-forward "Package biblatex Warning: Please rerun LaTeX" nil t)
-         (message "%s%s" "You should run LaTeX again, " (TeX-current-pages))
+        (setq rerun-msg "run LaTeX")
         (setq TeX-command-next TeX-command-default))
        ((re-search-forward "^(biblatex)\\W+Page breaks have changed" nil t)
-         (message "%s%s" "You should run LaTeX again - page breaks have changed, "
-                  (TeX-current-pages))
+        (setq rerun-msg "rerun LaTeX for page breaks")
         (setq TeX-command-next TeX-command-default))
        ((re-search-forward "^\\(?:LaTeX Warning: Label(s)\\|\
 Package natbib Warning: Citation(s)\\)" nil t)
-         (message "%s%s" "You should run LaTeX again to get references right, "
-                  (TeX-current-pages))
+        (setq rerun-msg "rerun LaTeX for references")
         (setq TeX-command-next TeX-command-default))
        ((re-search-forward
          "^\\(?:(rerunfilecheck)\\|Package hyperref Warning:\\)\\W+\
 Rerun to get outlines right" nil t)
-         (message "%s%s" "You should run LaTeX again to get outlines right, "
-                  (TeX-current-pages))
+        (setq rerun-msg "rerun LaTeX for outlines")
         (setq TeX-command-next TeX-command-default))
        ((re-search-forward "^LaTeX Warning: Reference" nil t)
-         (message "%s%s%s" name ": there were unresolved references, "
-                  (TeX-current-pages))
-         (let (dvi2pdf)
-           (if (with-current-buffer TeX-command-buffer
-                 (and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI))))
-               (setq TeX-command-next dvi2pdf)
-             (setq TeX-command-next TeX-command-Show))))
+        (setq rerun-msg "unresolved references"))
        ((re-search-forward "^\\(?:LaTeX Warning: Citation\\|\
 Package natbib Warning:.*undefined citations\\)" nil t)
-         (message "%s%s%s" name ": there were unresolved citations, "
-                  (TeX-current-pages))
-         (let (dvi2pdf)
-           (if (with-current-buffer TeX-command-buffer
-                 (and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI))))
-               (setq TeX-command-next dvi2pdf)
-             (setq TeX-command-next TeX-command-Show))))
+        (setq rerun-msg "unresolved citations"))
        ((re-search-forward "^No file .*\\.\\(toc\\|lof\\|lot\\)\\.$" nil t)
-         (message "%s" (concat "You should run LaTeX again to get "
-                               (upcase (match-string-no-properties 1))
-                               " right"))
+        (setq rerun-msg (concat "run LaTeX for "
+                                (upcase (match-string-no-properties 1))))
         (setq TeX-command-next TeX-command-default))
        ((re-search-forward "Package longtable Warning: Table widths have \
 changed\\. Rerun LaTeX\\." nil t)
-         (message
-          "%s" "You should run LaTeX again to get table formatting right")
+        (setq rerun-msg "rerun LaTeX for table formatting")
         (setq TeX-command-next TeX-command-default))
        ((re-search-forward "^hf-TikZ Warning: Mark '.*' changed\\. \
 Rerun to get mark in right position\\." nil t)
-         (message
-          "%s" "You should run LaTeX again to get TikZ marks in right position")
+        (setq rerun-msg "rerun LaTeX for TikZ marks")
         (setq TeX-command-next TeX-command-default))
        ((re-search-forward "^Package Changebar Warning: \
 Changebar info has changed." nil t)
-         (message
-          "%s" "You should run LaTeX again to get the change bars right")
-         (setq TeX-command-next TeX-command-default))
-        ((re-search-forward "^LaTeX Warning: Endnotes may have changed. \
-Rerun to get them right" nil t)
-         (message
-          "%s" "You should run LaTeX again to get the endnotes right")
+        (setq rerun-msg "rerun LaTeX for endnotes")
         (setq TeX-command-next TeX-command-default))
        ((re-search-forward "^\\* xsim warning: \"rerun\"" nil t)
-         (message
-          "%s" "You should run LaTeX again to synchronize exercise properties")
-         (setq TeX-command-next TeX-command-default))
-        ((re-search-forward
-          TeX-LaTeX-sentinel-banner-regexp nil t)
+        (setq rerun-msg "rerun LaTeX for exercise properties")
+        (setq TeX-command-next TeX-command-default)))
+
       (let* ((warnings (and TeX-debug-warnings
                             (TeX-LaTeX-sentinel-has-warnings)))
              (bad-boxes (and TeX-debug-bad-boxes
                              (TeX-LaTeX-sentinel-has-bad-boxes)))
-                (add-info (when (or warnings bad-boxes)
+             (add-info (if (or warnings bad-boxes)
                            (concat " (with "
-                                    (when warnings "warnings")
+                                   (when warnings
+                                     (propertize
+                                      (format "%d warnings"
+                                              (gethash 'warning counts 0))
+                                      'face
+                                      'TeX-error-description-warning))
                                    (when (and warnings bad-boxes) " and ")
-                                    (when bad-boxes "bad boxes")
-                                    ")"))))
-           (message "%s" (concat name ": successfully formatted "
-                                 (TeX-current-pages) add-info)))
+                                   (when bad-boxes
+                                     (propertize
+                                      (format "%d bad boxes"
+                                              (gethash 'bad-box counts 0))
+                                      'face
+                                      'TeX-error-description-warning))
+                                   ")")
+                         ""))
+             (msg (format "%s: %%s %s%s%s"
+                          name
+                          (TeX-current-pages)
+                          add-info
+                          (if rerun-msg
+                              (concat " -- " rerun-msg)
+                            ""))))
+        (if (re-search-forward TeX-LaTeX-sentinel-banner-regexp nil t)
+            (progn
+              (message msg "successfully formatted")
+              (unless TeX-command-next
                 (let (dvi2pdf)
                   (if (with-current-buffer TeX-command-buffer
                         (and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI))))
                       (setq TeX-command-next dvi2pdf)
-             (setq TeX-command-next TeX-command-Show))))
-        (t
-         (message "%s%s%s" name ": problems after " (TeX-current-pages))
-         (setq TeX-command-next TeX-command-default)))
+                    (setq TeX-command-next TeX-command-Show)))))
+          (message msg "faced problems formatting")
+          (unless TeX-command-next
+            (setq TeX-command-next TeX-command-default)))))
 
     ;; Check whether the idx file changed.
     (let (idx-file)
@@ -8770,7 +8780,7 @@ Rerun to get them right" nil t)
       (run-hook-with-args 'TeX-after-compilation-finished-functions
                           (with-current-buffer TeX-command-buffer
                             (expand-file-name
-                           (TeX-active-master (TeX-output-extension)))))))
+                             (TeX-active-master (TeX-output-extension))))))))
 
 ;; should go into latex.el? --pg
 (defun TeX-BibTeX-sentinel (_process _name)

Reply via email to