Subject: Re: bug#62445: 13.1.10; bug in preview-region applied to repeated math environments

From: Arash Esbati <[email-masked]>
Date: Mon, 08 Apr 2024 14:44:04 +0200

Hi Paul,

Paul Nelson <[email-masked]> writes:

> OK, very well.  Please find attached my best attempt at a patch for
> this (any feedback or corrections welcome).

Thanks.  I have 2 questions, see below:

> From 9d3266304f62fa3b21751b27200aab17454add6c Mon Sep 17 00:00:00 2001
> From: Paul Nelson <[email-masked]>
> Date: Mon, 8 Apr 2024 13:11:52 +0200
> Subject: [PATCH] fix bug with preview-region applied to repeated math
>  environments
>
> See https://www.mail-archive.com/[email-masked]/msg04327.html.

Can you try to adjust the commit message as described here:

  https://git.savannah.gnu.org/cgit/emacs.git/tree/CONTRIBUTE#n172

If not, I will try to fix that afterwards.

> ---
>  preview.el.in | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/preview.el.in b/preview.el.in
> index 09836d9..72c5e58 100644
> --- a/preview.el.in
> +++ b/preview.el.in
> @@ -3268,6 +3268,8 @@ Return a new string."
>      (setq result (concat result string))
>      result))
>  
> +(defvar-local preview--region-begin nil)
> +
>  (defun preview-parse-messages (open-closure)
>    "Turn all preview snippets into overlays.
>  This parses the pseudo error messages from the preview
> @@ -3538,6 +3540,14 @@ name(\\([^)]+\\))\\)\\|\
>                          (goto-char (point-min))
>                          (forward-line (1- line)))
>                        (setq lpoint (point))
> +
> +                      ;; The following addresses the bug described at
> +                      ;; https://www.mail-archive.com/[email-masked]/msg04327.html
> +                      (and preview--region-begin
> +                           (< (point)
> +                              preview--region-begin)
> +                           (goto-char preview--region-begin))
> +
>                        (cond
>                         ((search-forward (concat string after-string)
>                                          (line-end-position) t)
> @@ -4033,6 +4043,7 @@ stored in `preview-dumped-alist'."
>                           "<none>")
>                         (TeX-current-offset begin)))
>    (setq TeX-current-process-region-p t)
> +  (setq-local preview--region-begin begin)

Why `setq-local'?  You define `preview--region-begin' with
`defvar-local', why not just `setq' it?

Best, arash