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

From: Arash Esbati <[email-masked]>
Date: Fri, 18 Jul 2025 11:15:43 +0200

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