GNU bug report logs - #53758
28.0.91; Recursive edit during dired-do-find-regexp-and-replace breaks isearch

Previous Next

Package: emacs;

Reported by: sbaugh <at> catern.com

Date: Thu, 3 Feb 2022 19:12:02 UTC

Severity: normal

Merged with 53759, 53760, 53761

Found in version 28.0.91

Fixed in version 29.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Juri Linkov <juri <at> linkov.net>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: sbaugh <at> catern.com, 53758 <at> debbugs.gnu.org
Subject: bug#53758: 28.0.91; Recursive edit during dired-do-find-regexp-and-replace breaks isearch
Date: Mon, 07 Feb 2022 21:27:07 +0200
[Message part 1 (text/plain, inline)]
> It's referring to the comment on lines starting with 2938 and the
> subsequent code which uses 'looking-at' instead of
> replace-re-search-function.
>
> Here's that comment in full:
>
> 	  ;; Otherwise, if matching a regular expression, do the next
> 	  ;; match now, since the replacement for this match may
> 	  ;; affect whether the next match is adjacent to this one.
> 	  ;; If that match is empty, don't use it.

Thanks, now everything is clear.  Then it can be simplified by this patch:

[xref--query-replace-1.patch (text/x-diff, inline)]
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 4efa652084..f334710a28 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -843,25 +843,7 @@ xref--query-replace-1
          (continue t)
          did-it-once buf-pairs pairs
          current-beg current-end
-         ;; Counteract the "do the next match now" hack in
-         ;; `perform-replace'.  And still, it'll report that those
-         ;; matches were "filtered out" at the end.
-         (isearch-filter-predicate
-          (lambda (beg end)
-            (and current-beg
-                 (>= beg current-beg)
-                 (<= end current-end))))
-         (replace-re-search-function
-          (lambda (from &optional _bound noerror)
-            (let (found pair)
-              (while (and (not found) pairs)
-                (setq pair (pop pairs)
-                      current-beg (car pair)
-                      current-end (cdr pair))
-                (goto-char current-beg)
-                (when (re-search-forward from current-end noerror)
-                  (setq found t)))
-              found))))
+         (region-extract-function (lambda (_) pairs)))
     (while (and continue (setq buf-pairs (funcall iter :next)))
       (if did-it-once
           ;; Reuse the same window for subsequent buffers.
@@ -870,8 +852,9 @@ xref--query-replace-1
          (pop-to-buffer (car buf-pairs)))
         (setq did-it-once t))
       (setq pairs (cdr buf-pairs))
+      (goto-char (point-min))
       (setq continue
-            (perform-replace from to t t nil nil multi-query-replace-map)))
+            (perform-replace from to t t nil nil multi-query-replace-map nil nil nil t)))
     (unless did-it-once (user-error "No suitable matches here"))
     (when (and continue (not buf-pairs))
       (message "All results processed"))))
[Message part 3 (text/plain, inline)]
> I'm not sure why the result would be different between
> dired-do-find-regexp-and-replace and project-query-regexp-replace, though.

project-query-regexp-replace doesn't use xref--query-replace-1.

Actually, the reported problem is not specific to xref.
Performing replacements on a rectangular region doesn't allow
searching outside the region on recursive edit too.
So here is a general fix that covers all cases:

[isearch-filter-predicate.patch (text/x-diff, inline)]
diff --git a/lisp/replace.el b/lisp/replace.el
index 23e6483809..5add576d6b 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -3233,7 +3233,10 @@ perform-replace
 			       (last-command 'recenter-top-bottom))
 			   (recenter-top-bottom)))
 			((eq def 'edit)
-			 (let ((opos (point-marker)))
+			 (let ((opos (point-marker))
+			       (isearch-filter-predicate isearch-filter-predicate))
+			   (when region-filter
+			     (remove-function isearch-filter-predicate region-filter))
 			   (setq real-match-data (replace-match-data
 						  nil real-match-data
 						  real-match-data))

This bug report was last modified 3 years and 104 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.