emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/embark c9b26c2e18 4/4: Minor tweak to embark--narrow-to


From: ELPA Syncer
Subject: [elpa] externals/embark c9b26c2e18 4/4: Minor tweak to embark--narrow-to-target
Date: Tue, 4 Jan 2022 02:57:30 -0500 (EST)

branch: externals/embark
commit c9b26c2e18f01ae401df6a69b7a0c1a6bc44b90c
Author: Omar Antolín Camarena <omar.antolin@gmail.com>
Commit: Omar Antolín Camarena <omar.antolin@gmail.com>

    Minor tweak to embark--narrow-to-target
    
    Also move point to the beginning of the narrowed target and
    save-excursion. It's conceivable though not very likely that some use
    is discovered for the old version that doesn't go to the beginning and
    doesn't save-excursion, but it is very unlikely.
---
 embark.el | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/embark.el b/embark.el
index d7e7d53929..30b597008a 100644
--- a/embark.el
+++ b/embark.el
@@ -3711,12 +3711,18 @@ and leaves the point to the left of it."
   (deactivate-mark t))
 
 (cl-defun embark--narrow-to-target (&key action bounds &allow-other-keys)
+  "Narrow buffer to target if its BOUNDS are known.
+Intended for use as an Embark pre-action hook.  This function
+advises ACTION to narrow to the given BOUNDS prior to running.
+The advice is self-removing so it only affects ACTION once."
   (when (and (consp bounds) (symbolp action))
     (cl-labels ((with-restriction (fn &rest args)
-                  (save-restriction
-                    (narrow-to-region (car bounds) (cdr bounds))
-                    (unwind-protect (apply fn args)
-                      (advice-remove action #'with-restriction)))))
+                  (save-excursion
+                    (save-restriction
+                      (narrow-to-region (car bounds) (cdr bounds))
+                      (goto-char (car bounds))
+                      (unwind-protect (apply fn args)
+                        (advice-remove action #'with-restriction))))))
       (advice-add action :around #'with-restriction))))
 
 (defun embark--allow-edit (&rest _)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]