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: Tue, 03 May 2022 10:10:10 +0300 Organization: LINKOV.NET Message-ID: <861qxb6qvh.fsf@mail.linkov.net> References: <865ynnl9f0.fsf_-_@mail.linkov.net> <86pmlvju2c.fsf@mail.linkov.net> <86o80ju6qx.fsf@mail.linkov.net> 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="26823"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) To: 54733@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 03 10:16:55 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 1nlniJ-0006p8-6F for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 03 May 2022 10:16:55 +0200 Original-Received: from localhost ([::1]:38772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlniH-0006WG-QG for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 03 May 2022 04:16:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlmhW-0004bX-Qo for bug-gnu-emacs@gnu.org; Tue, 03 May 2022 03:12:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlmhV-0000mw-Tn for bug-gnu-emacs@gnu.org; Tue, 03 May 2022 03:12:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nlmhV-0006Sz-KE for bug-gnu-emacs@gnu.org; Tue, 03 May 2022 03:12:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 03 May 2022 07:12:01 +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.165156187124797 (code B ref 54733); Tue, 03 May 2022 07:12:01 +0000 Original-Received: (at 54733) by debbugs.gnu.org; 3 May 2022 07:11:11 +0000 Original-Received: from localhost ([127.0.0.1]:38565 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nlmgg-0006Rs-Lo for submit@debbugs.gnu.org; Tue, 03 May 2022 03:11:10 -0400 Original-Received: from relay8-d.mail.gandi.net ([217.70.183.201]:32909) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nlmga-0006RI-MD for 54733@debbugs.gnu.org; Tue, 03 May 2022 03:11:09 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 291761BF20F for <54733@debbugs.gnu.org>; Tue, 3 May 2022 07:10:57 +0000 (UTC) In-Reply-To: <86o80ju6qx.fsf@mail.linkov.net> (Juri Linkov's message of "Fri, 29 Apr 2022 20:41:42 +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:231306 Archived-At: --=-=-= Content-Type: text/plain >>> So now we have two cases that require fixing perform-replace. >> >> To be able to redesign the match-again part of perform-replace, >> there is a need to have a test suite that will confirm nothing >> is broken after redesign. So I pushed a new test in replace-tests.el. > > The need to have `looking-at` in `perform-replace` is explained > in the commit message of 5632eb272c7. So now added it to replace-tests. The only way to fix all reported problems is to always use search functions in perform-replace: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=perform-replace-match-again.patch diff --git a/lisp/replace.el b/lisp/replace.el index 81282deb14..7fbaa93ead 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -3013,9 +3013,10 @@ perform-replace (setq match-again (and nonempty-match (or (not regexp-flag) - (and (if backward - (looking-back search-string nil) - (looking-at search-string)) + (and (save-excursion + (replace-search search-string limit + regexp-flag delimited-flag + case-fold-search backward)) (let ((match (match-data))) (and (/= (nth 0 match) (nth 1 match)) match)))))) @@ -3298,8 +3299,12 @@ perform-replace ;; decide whether the search string ;; can match again just after this match. (if (and regexp-flag nonempty-match) - (setq match-again (and (looking-at search-string) - (match-data))))) + (setq match-again + (and (save-window-excursion + (replace-search search-string limit + regexp-flag delimited-flag + case-fold-search backward)) + (match-data))))) ;; Edit replacement. ((eq def 'edit-replacement) (setq real-match-data (replace-match-data diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el index ef1e5c3eaf..f7a2e043ff 100644 --- a/test/lisp/replace-tests.el +++ b/test/lisp/replace-tests.el @@ -472,8 +472,7 @@ query-replace-search-function-tests found))) (tests '( - ;; FIXME: this test should pass after fixing bug#54733: - ;; ("aaaa" "C-M-% .* RET 1 RET !" "1a1a") + ("aaaa" "C-M-% .* RET 1 RET !" "1a1a") ))) (query-replace--run-tests tests))) @@ -485,8 +484,7 @@ perform-replace-tests ;; Test case from commit 5632eb272c7 ("a a a " "\\ba " "c" nil t nil nil nil nil nil nil nil "ccc") ; not "ca c" ;; The same with region inside the second match - ;; FIXME: this test should pass after fixing bug#54733: - ;; ("a a a " "\\ba " "c" nil t nil nil nil 1 4 nil nil "ca a ") + ("a a a " "\\ba " "c" nil t nil nil nil 1 4 nil nil "ca a ") )) (defun perform-replace--run-tests (tests) diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 6e763eef01..981f51c30a 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -856,14 +856,6 @@ 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) --=-=-=--