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: Wed, 22 Jun 2022 10:36:39 +0300 Organization: LINKOV.NET Message-ID: <86r13h6syo.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> <861qvhj3j4.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36312"; 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 Wed Jun 22 09:53:16 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 1o3vAp-0009Gi-3N for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Jun 2022 09:53:15 +0200 Original-Received: from localhost ([::1]:43004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3vAn-0001qb-9D for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Jun 2022 03:53:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37758) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3vAc-0001pN-AF for bug-gnu-emacs@gnu.org; Wed, 22 Jun 2022 03:53:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39985) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o3vAc-00029U-1d for bug-gnu-emacs@gnu.org; Wed, 22 Jun 2022 03:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o3vAc-0008PX-0b for bug-gnu-emacs@gnu.org; Wed, 22 Jun 2022 03:53: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: Wed, 22 Jun 2022 07:53: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.165588434032266 (code B ref 54733); Wed, 22 Jun 2022 07:53:01 +0000 Original-Received: (at 54733) by debbugs.gnu.org; 22 Jun 2022 07:52:20 +0000 Original-Received: from localhost ([127.0.0.1]:33881 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o3v9v-0008OM-RG for submit@debbugs.gnu.org; Wed, 22 Jun 2022 03:52:20 -0400 Original-Received: from relay8-d.mail.gandi.net ([217.70.183.201]:36005) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o3v9s-0008Nl-CN for 54733@debbugs.gnu.org; Wed, 22 Jun 2022 03:52:17 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 483611BF209; Wed, 22 Jun 2022 07:52:08 +0000 (UTC) In-Reply-To: <861qvhj3j4.fsf@mail.linkov.net> (Juri Linkov's message of "Tue, 21 Jun 2022 20:55:19 +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:235005 Archived-At: >>> + (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. > > I'm afraid that prepending "\\=" might break a complex regexp somehow. Another variant without modifying the original regexp is still to call replace-search, but afterwards check if it stayed at the old position with something like (let ((old-pos (point))) (and (replace-search ...) (eq (match-beginning 0) old-pos))) Less efficient, but looking-at is a real problem since it's incompatible with search functions. This is one of the problems faced in bug#14013 where isearch matches `C-M-r ^' outside of positions handled by the search function because `isearch-search-and-update' uses a hack with looking-at. This is a long-standing flaw in isearch that needs to be fixed. Any uses of looking-at in search/replace should be substituted with an equivalent code that relies on the search function.