Subject: bug#79037: 14.0.9; Fixing infinite loop with `TeX-previous-error'

From: [email-masked]
Date: Fri, 18 Jul 2025 10:19:43 -0400

Hi Arash,

Thanks for the follow-up, I've attached a minimal latex example that contains:
- an ignored warning (about a package's options)
- a non-ignored warning (missing citation label)

After compiling, the infinite loop is triggered when invoking `TeX-previous-error' after invoking `TeX-next-error'.

These are the relevant configuration options:
==
(setq TeX-debug-warnings t
      TeX-ignore-warnings #'my-ignore-TeX-warnings
      TeX-suppress-ignored-warnings t)

(defun my-ignore-TeX-warnings (type file line text &rest more)
      (let ((ref "LaTeX Warning: Reference")
            (cit "LaTeX Warning: Citation"))
         (and
            (not (string-match-p ref text))
            (not (string-match-p cit text)))))
==

Kind regards,

Bram Adams

Arash Esbati <[email-masked]> writes:

> [You don't often get email from [email-masked]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> Hi Bram,
>
> [email-masked] writes:
>
>> When `TeX-debug-warnings' and `TeX-suppress-ignored-warnings' are
>> enabled, invoking `TeX-previous-error' can lead to an infinite loop in
>> `TeX-parse-TeX'. As the `unless' condition always fails, `arg' is
>> never incremented to 0, hence the value of `TeX-error-last-visited'
>> decrements forever. There are no issues when invoking
>> `TeX-next-error'.
>>
>> The attached patch seems to fix this bug with `TeX-previous-error'.
>> [...]
>> diff --git a/tex.el b/tex.el
>> index 5a3345a..8f00bbc 100644
>> --- a/tex.el
>> +++ b/tex.el
>> @@ -9491,13 +9491,16 @@ already in an Emacs buffer) and the cursor is placed at the error."
>>                        (1- TeX-error-last-visited))
>>                      item (nth TeX-error-last-visited TeX-error-list))
>>                ;; Increase or decrease `arg' only if the warning isn't to be
>> -              ;; skipped.
>> -              (unless (TeX-error-list-skip-warning-p (nth 0 item) (nth 10 item))
>> -                ;; Note: `signum' is a function from `cl' library, do not be
>> -                ;; tempted to use it.
>> -                (setq arg (if (> arg 0)
>> -                              (1- arg)
>> -                            (1+ arg)))))
>> +              ;; skipped, or `TeX-error-last-visited' has dropped below 0
>> +              ;; with a negative `arg'.
>> +              (if (or (and (< arg 0)
>> +                           (< TeX-error-last-visited 0))
>> +                      (not (TeX-error-list-skip-warning-p (nth 0 item) (nth 10 item))))
>> +                  ;; Note: `signum' is a function from `cl' library, do not be
>> +                  ;; tempted to use it.
>> +                  (setq arg (if (> arg 0)
>> +                                (1- arg)
>> +                              (1+ arg)))))
>>              (if (< TeX-error-last-visited -1)
>>                  (setq TeX-error-last-visited -1))
>>              (cond ((or (null item)
>
> Thanks for the report and the patch.  Is it possible for you to assemble
> a small .tex file and an exact recipe how to trigger the inf-loop with
> that .tex file?  I trust your analysis is correct, but like to
> understand it better before installing it.  TIA.
>
> Best, Arash