From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#34525: replace-regexp missing some matches Date: Wed, 27 Feb 2019 12:41:04 -0500 Message-ID: References: <20190220185850.GB9655@ACM> <83lg2agt0j.fsf@gnu.org> <20190220213003.GC9655@ACM> <83bm35hkqo.fsf@gnu.org> <20190224173746.GA21808@ACM> <83mumlnk8y.fsf@gnu.org> <20190224210058.GB21808@ACM> <83mumjmxv6.fsf@gnu.org> <20190226135048.GA19653@ACM> <20190227142251.GB4772@ACM> <838sy1kwxo.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="70324"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Alan Mackenzie , daniel.lopez999@gmail.com, 34525@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Feb 27 18:42:53 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gz3EK-000ICF-7l for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Feb 2019 18:42:52 +0100 Original-Received: from localhost ([127.0.0.1]:48216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gz3EJ-0000q7-5V for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Feb 2019 12:42:51 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:56919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gz3Dj-0000U8-KL for bug-gnu-emacs@gnu.org; Wed, 27 Feb 2019 12:42:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gz3Di-0001L6-94 for bug-gnu-emacs@gnu.org; Wed, 27 Feb 2019 12:42:15 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40757) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gz3DW-0001D6-8C; Wed, 27 Feb 2019 12:42:06 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gz3DW-00064m-4B; Wed, 27 Feb 2019 12:42:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Wed, 27 Feb 2019 17:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34525 X-GNU-PR-Package: emacs,cc-mode Original-Received: via spool by 34525-submit@debbugs.gnu.org id=B34525.155128926923293 (code B ref 34525); Wed, 27 Feb 2019 17:42:02 +0000 Original-Received: (at 34525) by debbugs.gnu.org; 27 Feb 2019 17:41:09 +0000 Original-Received: from localhost ([127.0.0.1]:54301 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gz3Cf-00063b-6f for submit@debbugs.gnu.org; Wed, 27 Feb 2019 12:41:09 -0500 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:49163) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gz3Cd-00063T-5I for 34525@debbugs.gnu.org; Wed, 27 Feb 2019 12:41:08 -0500 Original-Received: from fmsmemgm.homelinux.net (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id x1RHf5ip009282; Wed, 27 Feb 2019 12:41:05 -0500 Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id D4E1EAE0E9; Wed, 27 Feb 2019 12:41:04 -0500 (EST) In-Reply-To: <838sy1kwxo.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 27 Feb 2019 18:39:31 +0200") X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6492=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6492> : inlines <7025> : streams <1814271> : uri <2803186> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:155863 Archived-At: > next_interval and previous_interval are used extensively, so I'm > having hard time believing that they have such a blatant bug. I'm also wondering why this hasn't bitten us long ago, but the behavior in the original bug-report is definitely weird. E.g. I reproduced the bug using the lower-level (while (re-search-forward RE) (replace-match)), and then added (how-many RE) calls before re-search-forward and before replace-match: these should always differ by 1 (since one occurrence of RE was skipped by re-search-forward), but they often didn't (even though there was no buffer modifications between the two how-many calls). AFAICT the only place where the missing updates can bite us is when we call update_interval, since it seems to be the only function that relies on all parents having the ->position field correctly set. update_interval is only called from update_syntax_table. I'm actually wondering whether we should keep update_interval at all: AFAICT update_syntax_table is almost always called "sequentially". I.e. the new `charpos` is right next to the old one. So a while loop with next_interval/previous_interval should be just as efficient in practice: a loop of next_interval/previous_interval has basically a complexity O(n) where `n` is the distance we move, whereas update_interval has complexity O(log n), so if `n` is almost always 1 the difference doesn't matter. Stefan