Subject: bug#55065: 13.0.11; compilation reports errors, but TeX-next-error says no errors

From: Ikumi Keita <[email-masked]>
Date: Mon, 25 Apr 2022 22:24:13 +0900

Hi Miguel and all,

>>>>> "Miguel V. S. Frasson" <[email-masked]> writes:
> I am editing a simple text with actually no errors. Compilation reports
> errors (what is annoying) but TeX-next-error says "No more errors."

> MWE:

> \documentclass{article}
> \begin{document}
> Bla :123:
> blablabla-blablabla blablabla-blablabla
> blablabla-blablabla blablabla-blablabla.
> \end{document}

> Investigating, in tex-buf.el one reads:

>   (if (re-search-forward "^\\(!\\|.*:[0-9]+:\\) " nil t)
>       (progn
>         (message "%s errors in `%s'. Use %s to display." name (buffer-name)
>                  (substitute-command-keys
>                   "\\<TeX-mode-map>\\[TeX-next-error]"))

> so error message can be triggered as easily as if input has a string like
> ":0: " that can go to log if that line has a bad break, like in MWE.

Thanks for the report with simple MWE. I can confirm the behavior.

To developers:
(1) I think the attached patch circumvents this issue. However,
    `TeX-parse-error' contains similar loose treatments for other
    messages from (La)TeX. Should we add refinements to the rest of the
    function as well? 
(2) (This item isn't related to my patch; it has persisted with AUCTeX
     for fairly long period.)
    Looking at the regexp used in `TeX-parse-error', the parts "Hook
    to change line numbers" and "Hook to change file name" are not
    actually matched because preceding alternative parts "New file" and
    "End of file" match instead. Thus the accompanying codes at later
    part of the function never run, IIUC:
----------------------------------------------------------------------
         ;; Hook to change line numbers
         ((match-beginning 5)
          (setq TeX-error-offset
                (list (string-to-number (TeX-match-buffer 5))))
          t)

         ;; Hook to change file name
         ((match-beginning 6)
	 [...]
----------------------------------------------------------------------
    Is that OK? Or am I missing something?

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

>From 573c5b0272a2b65e634bd02ecd814a301005da3a Mon Sep 17 00:00:00 2001
From: Ikumi Keita <[email-masked]>
Date: Mon, 25 Apr 2022 00:19:46 +0900
Subject: [PATCH] Be more robust against false positive

* tex.el (TeX-TeX-sentinel-check,TeX-parse-error): Check whether
"file" really exists.  If not, ignore it.
---
 tex.el | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/tex.el b/tex.el
index 747753b3..fd59bf79 100644
--- a/tex.el
+++ b/tex.el
@@ -8256,7 +8256,12 @@ Return nil only if no errors were found."
                       (match-string 1 output-file)
                     "dvi")))))))
   (if process (TeX-format-mode-line process))
-  (if (re-search-forward "^\\(!\\|.*:[0-9]+:\\) " nil t)
+  (if (catch 'found
+        (while (re-search-forward "^\\(?:!\\|\\(.+?\\):[0-9]+:\\) " nil t)
+          (if (or (not (match-beginning 1))
+                  ;; Ignore non-error warning. (bug#55065)
+                  (file-exists-p (TeX-match-buffer 1)))
+              (throw 'found t))))
       (progn
         (message "%s errors in `%s'. Use %s to display." name (buffer-name)
                  (substitute-command-keys
@@ -8269,6 +8274,7 @@ Return nil only if no errors were found."
                                             'TeX-current-master))
                          t))
         t)
+    (goto-char (point-min))
     (let (dvi2pdf)
         (if (with-current-buffer TeX-command-buffer
            (and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI))))
@@ -9272,7 +9278,7 @@ Return non-nil if an error or warning is found."
   (let ((regexp
          (concat
           ;; TeX error
-          "^\\(!\\|\\(.*?\\):[0-9]+:\\) \\|"
+          "^\\(!\\|\\(.+?\\):[0-9]+:\\) \\|"
           ;; New file
           "(\n?\\([^\n()]+\\)\\|"
           ;; End of file.
@@ -9301,7 +9307,10 @@ Return non-nil if an error or warning is found."
             (TeX-pop-to-buffer old))
           nil)
          ;; TeX error
-         ((match-beginning 1)
+         ((and (match-beginning 1)
+               (or (not (match-beginning 2))
+                   ;; Ignore non-error warning. (bug#55065)
+                   (file-exists-p (TeX-match-buffer 2))))
           (when (match-beginning 2)
             (unless TeX-error-file
               (push nil TeX-error-file)
-- 
2.35.1