emacs-diffs
[Top][All Lists]
Advanced

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

master da8277a: * lisp/replace.el (perform-replace): Use 'remove-functio


From: Juri Linkov
Subject: master da8277a: * lisp/replace.el (perform-replace): Use 'remove-function' (bug#49963).
Date: Wed, 11 Aug 2021 03:06:56 -0400 (EDT)

branch: master
commit da8277abc19d6eb1ac5a15273daca03f4237294b
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    * lisp/replace.el (perform-replace): Use 'remove-function' (bug#49963).
    
    Don't let-bind the value of 'isearch-filter-predicate' to protect
    from changing the global value, since with a buffer-local value
    it still changes the global value.  So after using 'add-function' on the
    global value of 'isearch-filter-predicate', call 'remove-function' to remove
    'region-filter' from the global value in 'unwind-protect'.
---
 lisp/replace.el | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/lisp/replace.el b/lisp/replace.el
index 1d6f091..69bdfe1 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2765,9 +2765,7 @@ characters."
 
          ;; If non-nil, it is marker saying where in the buffer to stop.
          (limit nil)
-         ;; Use local binding in add-function below.
-         (isearch-filter-predicate isearch-filter-predicate)
-         (region-bounds nil)
+         (region-filter nil)
 
          ;; Data for the next match.  If a cons, it has the same format as
          ;; (match-data); otherwise it is t if a match is possible at point.
@@ -2791,21 +2789,22 @@ characters."
 
     ;; Unless a single contiguous chunk is selected, operate on multiple 
chunks.
     (when region-noncontiguous-p
-      (setq region-bounds
-            (mapcar (lambda (position)
-                      (cons (copy-marker (car position))
-                            (copy-marker (cdr position))))
-                    (funcall region-extract-function 'bounds)))
-      (add-function :after-while isearch-filter-predicate
-                    (lambda (start end)
-                      (delq nil (mapcar
-                                 (lambda (bounds)
-                                   (and
-                                    (>= start (car bounds))
-                                    (<= start (cdr bounds))
-                                    (>= end   (car bounds))
-                                    (<= end   (cdr bounds))))
-                                 region-bounds)))))
+      (let ((region-bounds
+             (mapcar (lambda (position)
+                       (cons (copy-marker (car position))
+                             (copy-marker (cdr position))))
+                     (funcall region-extract-function 'bounds))))
+        (setq region-filter
+              (lambda (start end)
+                (delq nil (mapcar
+                           (lambda (bounds)
+                             (and
+                              (>= start (car bounds))
+                              (<= start (cdr bounds))
+                              (>= end   (car bounds))
+                              (<= end   (cdr bounds))))
+                           region-bounds))))
+        (add-function :after-while isearch-filter-predicate region-filter)))
 
     ;; If region is active, in Transient Mark mode, operate on region.
     (if backward
@@ -3238,7 +3237,9 @@ characters."
                 (setq next-replacement-replaced nil
                       search-string-replaced    nil
                       last-was-act-and-show     nil))))))
-      (replace-dehighlight))
+      (replace-dehighlight)
+      (when region-filter
+        (remove-function isearch-filter-predicate region-filter)))
     (or unread-command-events
        (message (ngettext "Replaced %d occurrence%s"
                           "Replaced %d occurrences%s"



reply via email to

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