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#54733: Match again in perform-replace Date: Thu, 30 Jun 2022 20:52:10 +0300 Organization: LINKOV.NET Message-ID: <86mtdut4xh.fsf@mail.linkov.net> References: <865ynnl9f0.fsf_-_@mail.linkov.net> <86pmlvju2c.fsf@mail.linkov.net> <86o80ju6qx.fsf@mail.linkov.net> <861qxb6qvh.fsf@mail.linkov.net> <9d54db84-77ba-6453-dcfa-864a7c05e692@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="29259"; 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: 54733@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 30 20:03:44 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 1o6yVz-0007UM-Vq for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 30 Jun 2022 20:03:43 +0200 Original-Received: from localhost ([::1]:33480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6yVz-0000PP-2z for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 30 Jun 2022 14:03:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6yVL-0008DS-AL for bug-gnu-emacs@gnu.org; Thu, 30 Jun 2022 14:03:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41669) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6yVK-00062z-VD for bug-gnu-emacs@gnu.org; Thu, 30 Jun 2022 14:03:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o6yVK-0002Nb-Sq for bug-gnu-emacs@gnu.org; Thu, 30 Jun 2022 14:03:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 30 Jun 2022 18:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54733 X-GNU-PR-Package: emacs Original-Received: via spool by 54733-submit@debbugs.gnu.org id=B54733.16566121539098 (code B ref 54733); Thu, 30 Jun 2022 18:03:02 +0000 Original-Received: (at 54733) by debbugs.gnu.org; 30 Jun 2022 18:02:33 +0000 Original-Received: from localhost ([127.0.0.1]:35565 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o6yUq-0002Mg-Pf for submit@debbugs.gnu.org; Thu, 30 Jun 2022 14:02:33 -0400 Original-Received: from relay10.mail.gandi.net ([217.70.178.230]:49017) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o6yUi-0002M9-Lx for 54733@debbugs.gnu.org; Thu, 30 Jun 2022 14:02:26 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 9749D240005; Thu, 30 Jun 2022 18:02:17 +0000 (UTC) In-Reply-To: <9d54db84-77ba-6453-dcfa-864a7c05e692@yandex.ru> (Dmitry Gutov's message of "Tue, 21 Jun 2022 02:59:06 +0300") 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:235743 Archived-At: --=-=-= Content-Type: text/plain Hi Dmitry, > Thanks for working on this. > >> + (replace-search search-string limit >> + regexp-flag delimited-flag >> + case-fold-search backward)) > > I don't know this code too well, but perhaps SEARCH_STRING here should be > anchored with something like "\\=" at the beginning? > > Otherwise the search can succeed here even if the next match is not > here. Not sure how important that is, though. Stefan confirmed that "\\=" is reliable. Thanks for the suggestion. Now everything is ready. Please try the latest patch in bug#14013 together with the patch for xref.el below. I've tested with your test cases from bug#53758, and everything works well. >> - ;; 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)))) > > Please note that we'll likely have to keep this code here for a number of > Emacs releases. So the patch should be tested with both versions: with this > code present and with it removed, to ensure present and future > compatibility. I guess this might need more conditionals like (>= emacs-major-version 29). --=-=-= 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 0213ab3cc5..9b4adffa41 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -858,29 +858,9 @@ xref--outdated-p ;; FIXME: Write a nicer UI. (defun xref--query-replace-1 (from to iter) - (let* ((query-replace-lazy-highlight nil) - (continue t) + (let* ((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. @@ -889,8 +869,10 @@ 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")))) --=-=-=--