From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs 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 Organization: LINKOV.NET Message-ID: <86zgn2lbty.fsf@mail.linkov.net> References: <87mtj7yddd.fsf@earth.mail-host-address-is-not-set> <867da8x7v1.fsf@mail.linkov.net> <48a0ada9-c386-aca8-e3f4-ecece9defee5@yandex.ru> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24996"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: sbaugh@catern.com, 53758@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 07 20:35:33 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nH9nR-0006HB-LC for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 07 Feb 2022 20:35:33 +0100 Original-Received: from localhost ([::1]:53496 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH9nO-0000pt-IB for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 07 Feb 2022 14:35:30 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:48122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH9h8-0005AR-Oi for bug-gnu-emacs@gnu.org; Mon, 07 Feb 2022 14:29:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49889) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nH9h8-0001eD-DT for bug-gnu-emacs@gnu.org; Mon, 07 Feb 2022 14:29:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nH9h7-0007Lb-W8 for bug-gnu-emacs@gnu.org; Mon, 07 Feb 2022 14:29:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 07 Feb 2022 19:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53758 X-GNU-PR-Package: emacs Original-Received: via spool by 53758-submit@debbugs.gnu.org id=B53758.164426213228226 (code B ref 53758); Mon, 07 Feb 2022 19:29:01 +0000 Original-Received: (at 53758) by debbugs.gnu.org; 7 Feb 2022 19:28:52 +0000 Original-Received: from localhost ([127.0.0.1]:43786 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nH9gx-0007LC-Tf for submit@debbugs.gnu.org; Mon, 07 Feb 2022 14:28:52 -0500 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:54433) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nH9gt-0007Kv-PW for 53758@debbugs.gnu.org; Mon, 07 Feb 2022 14:28:50 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id EFFFD40002; Mon, 7 Feb 2022 19:28:39 +0000 (UTC) In-Reply-To: <48a0ada9-c386-aca8-e3f4-ecece9defee5@yandex.ru> (Dmitry Gutov's message of "Mon, 7 Feb 2022 05:03:38 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:226279 Archived-At: --=-=-= Content-Type: text/plain > 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=xref--query-replace-1.patch 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")))) --=-=-= Content-Type: text/plain > 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=isearch-filter-predicate.patch 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)) --=-=-=--