Hi Arash,

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

Thanks, best,

Paul
From 9d3266304f62fa3b21751b27200aab17454add6c Mon Sep 17 00:00:00 2001
From: Paul Nelson <ultrono@gmail.com>
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/bug-auctex@gnu.org/msg04327.html.
---
 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/bug-auctex@gnu.org/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)
   (preview-generate-preview (TeX-region-file)
                             (preview-do-replacements
                              (TeX-command-expand
-- 
2.39.3 (Apple Git-145)

_______________________________________________
bug-auctex mailing list
bug-auctex@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-auctex

Reply via email to