unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: sbaugh@catern.com, 53758@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	[thread overview]
Message-ID: <86zgn2lbty.fsf@mail.linkov.net> (raw)
In-Reply-To: <48a0ada9-c386-aca8-e3f4-ecece9defee5@yandex.ru> (Dmitry Gutov's message of "Mon, 7 Feb 2022 05:03:38 +0200")

[-- Attachment #1: Type: text/plain, Size: 497 bytes --]

> 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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: xref--query-replace-1.patch --]
[-- Type: text/x-diff, Size: 1848 bytes --]

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"))))

[-- Attachment #3: Type: text/plain, Size: 420 bytes --]


> 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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: isearch-filter-predicate.patch --]
[-- Type: text/x-diff, Size: 595 bytes --]

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))

  reply	other threads:[~2022-02-07 19:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 19:11 bug#53758: 28.0.91; Recursive edit during dired-do-find-regexp-and-replace breaks isearch sbaugh
2022-02-06 17:44 ` Juri Linkov
2022-02-07  3:03   ` Dmitry Gutov
2022-02-07 19:27     ` Juri Linkov [this message]
2022-02-07 21:12       ` Dmitry Gutov
2022-02-08  7:43         ` Juri Linkov
2022-02-08 16:12           ` Dmitry Gutov
2022-02-08 19:35             ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86zgn2lbty.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=53758@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=sbaugh@catern.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).