branch: externals/auctex
commit 7ea85682098b831eb5d04b9be4c780ed8ab56e8c
Author: Paul Nelson <ultr...@gmail.com>
Commit: Arash Esbati <ar...@gnu.org>

    Add new custom option `preview-protect-point'
    
    * preview.el.in (preview-protect-point): New custom option.
    (preview-parse-messages): Use it.
    * doc/preview-latex.texi (The Emacs interface): Document it.
    (bug#70442)
---
 doc/preview-latex.texi |  4 ++++
 preview.el.in          | 18 +++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/doc/preview-latex.texi b/doc/preview-latex.texi
index 4aba7cb5e5..07adc2a989 100644
--- a/doc/preview-latex.texi
+++ b/doc/preview-latex.texi
@@ -668,6 +668,10 @@ when this is needed is in
 accordingly @code{split} is one entry in
 @code{preview-inner-environments}.
 
+@item preview-protect-point
+This boolean variable determines whether previews generated on top of the
+current point should be temporarily opened.  Default value is @code{nil}.
+
 @end vtable
 
 @node The preview images, Misplaced previews, The Emacs interface, For 
advanced users
diff --git a/preview.el.in b/preview.el.in
index d060174c74..0cacbfcdb5 100644
--- a/preview.el.in
+++ b/preview.el.in
@@ -3278,6 +3278,13 @@ beginning of the overlay.  This is intended to be used 
in conjunction
 with `preview-preprocess-function' when the latter introduces
 significant modifications.")
 
+(defcustom preview-protect-point nil
+  "Temporarily open new previews that would obscure point.
+If non-nil, then any new preview whose bounds contain point is
+temporarily opened, as if the user had entered it via movement commands."
+  :group 'preview-appearance
+  :type 'boolean)
+
 (defvar preview-locating-previews-message "locating previews...")
 
 (defun preview-parse-messages (open-closure)
@@ -3298,6 +3305,7 @@ call, and in its CDR the final stuff for the placement 
hook."
           (run-buffer (current-buffer))
           (run-directory default-directory)
           tempdir
+          point-current
           close-data
           open-data
           fast-hook
@@ -3520,6 +3528,7 @@ name(\\([^)]+\\))\\)\\|\
                   (setq lfile file))
                 (save-excursion
                   (save-restriction
+                    (setq point-current (point))
                     (widen)
                     ;; a fast hook might have positioned us already:
                     (if (number-or-marker-p string)
@@ -3618,7 +3627,14 @@ name(\\([^)]+\\))\\)\\|\
                                            (cons lcounters counters)
                                            tempdir
                                            (cdr open-data))))
-                                (setq close-data (nconc ovl close-data)))
+                                (setq close-data (nconc ovl close-data))
+                                (when (and preview-protect-point
+                                           (<= region-beg point-current)
+                                           (< point-current region-end))
+                                  ;; Temporarily open the preview if it
+                                  ;; would bump the point.
+                                  (preview-toggle (car ovl))
+                                  (push (car ovl) preview-temporary-opened)))
                             (with-current-buffer run-buffer
                               (preview-log-error
                                (list 'error

Reply via email to