From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#34525: replace-regexp missing some matches Date: Thu, 28 Feb 2019 21:54:14 +0000 Message-ID: <20190228215414.GE4686@ACM> References: <20190224210058.GB21808@ACM> <83mumjmxv6.fsf@gnu.org> <20190226135048.GA19653@ACM> <20190227142251.GB4772@ACM> <838sy1kwxo.fsf@gnu.org> <20190227173132.GG4772@ACM> <83zhqhjea1.fsf@gnu.org> <20190228105025.GB4686@ACM> <83k1hjkdzb.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="10744"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: daniel.lopez999@gmail.com, monnier@IRO.UMontreal.CA, 34525@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Feb 28 23:00:28 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 1gzTj7-0002az-1g for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Feb 2019 23:00:25 +0100 Original-Received: from localhost ([127.0.0.1]:47069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzTj6-0005U4-3W for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Feb 2019 17:00:24 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:41150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzTiv-0005Rn-Jj for bug-gnu-emacs@gnu.org; Thu, 28 Feb 2019 17:00:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzTiu-0007jC-8B for bug-gnu-emacs@gnu.org; Thu, 28 Feb 2019 17:00:13 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42061) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzTik-0007MP-Ei; Thu, 28 Feb 2019 17:00:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gzTik-0001iT-5p; Thu, 28 Feb 2019 17:00:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Thu, 28 Feb 2019 22:00: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.15513911576515 (code B ref 34525); Thu, 28 Feb 2019 22:00:02 +0000 Original-Received: (at 34525) by debbugs.gnu.org; 28 Feb 2019 21:59:17 +0000 Original-Received: from localhost ([127.0.0.1]:55605 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gzTi1-0001h1-6E for submit@debbugs.gnu.org; Thu, 28 Feb 2019 16:59:17 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:61836 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1gzThy-0001gr-K6 for 34525@debbugs.gnu.org; Thu, 28 Feb 2019 16:59:15 -0500 Original-Received: (qmail 4624 invoked by uid 3782); 28 Feb 2019 21:59:11 -0000 Original-Received: from acm.muc.de (p4FE15DA7.dip0.t-ipconnect.de [79.225.93.167]) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 28 Feb 2019 22:59:09 +0100 Original-Received: (qmail 32670 invoked by uid 1000); 28 Feb 2019 21:54:14 -0000 Content-Disposition: inline In-Reply-To: <83k1hjkdzb.fsf@gnu.org> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de 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:155913 Archived-At: Hello, Eli. On Thu, Feb 28, 2019 at 19:41:12 +0200, Eli Zaretskii wrote: > > Date: Thu, 28 Feb 2019 10:50:25 +0000 > > Cc: daniel.lopez999@gmail.com, 34525@debbugs.gnu.org > > From: Alan Mackenzie > > (i) Calculate ->position's in previous_interval and next_interval, as my > > tentative patch already does. > > (ii) Calculate the ->position's in update_interval, on moving to > > parents. > > (iii) Do away with update_interval, replacing it in syntax.c with > > previous/next_interval in while loops. > > In (i), the convention for ->position would be that it is valid for the > > target interval together with all its parents. In (ii) and (iii), it > > would only be valid in the final target intervals found by navigation. > > I think this should be explicitly stated in a comment in struct > > interval. Done. > > So, where do we go from here? If it were up to me, I would probably > > chose (i), simply because it's already been done, but I've no strong > > feelings over it. > I prefer not to do (i) because it has much wider implications than > needed. Either (ii) or (iii) are okay with me. The former seems to > be simpler, so I tend to favor it slightly. OK, I enclose a patch which codes up (ii). As a matter of interest, it seems to run a little faster on my benchmark of scrolling through xdisp.c than the version without the fix. And it fixes the OP's bug. :-) diff --git a/src/intervals.c b/src/intervals.c index 524bb944e5..2ed913d5fb 100644 --- a/src/intervals.c +++ b/src/intervals.c @@ -713,11 +713,21 @@ previous_interval (register INTERVAL interval) return NULL; } -/* Find the interval containing POS given some non-NULL INTERVAL - in the same tree. Note that we need to update interval->position - if we go down the tree. - To speed up the process, we assume that the ->position of - I and all its parents is already uptodate. */ +/* Set the ->position field of I's parent, based on I->position. */ +#define SET_PARENT_POSITION(i) \ + if (AM_LEFT_CHILD (i)) \ + INTERVAL_PARENT (i)->position = \ + i->position + TOTAL_LENGTH (i) - LEFT_TOTAL_LENGTH (i); \ + else \ + INTERVAL_PARENT (i)->position = \ + i->position - LEFT_TOTAL_LENGTH (i) \ + - LENGTH (INTERVAL_PARENT (i)) + +/* Find the interval containing POS given some non-NULL INTERVAL in + the same tree. Note that we update interval->position in each + interval we traverse, assuming it is already correctly set for the + argument I. We don't assume that any other interval already has a + correctly set ->position. */ INTERVAL update_interval (register INTERVAL i, ptrdiff_t pos) { @@ -738,7 +748,10 @@ update_interval (register INTERVAL i, ptrdiff_t pos) else if (NULL_PARENT (i)) error ("Point before start of properties"); else - i = INTERVAL_PARENT (i); + { + SET_PARENT_POSITION (i); + i = INTERVAL_PARENT (i); + } continue; } else if (pos >= INTERVAL_LAST_POS (i)) @@ -753,7 +766,10 @@ update_interval (register INTERVAL i, ptrdiff_t pos) else if (NULL_PARENT (i)) error ("Point %"pD"d after end of properties", pos); else - i = INTERVAL_PARENT (i); + { + SET_PARENT_POSITION (i); + i = INTERVAL_PARENT (i); + } continue; } else diff --git a/src/intervals.h b/src/intervals.h index 9c5adf33a1..7608800116 100644 --- a/src/intervals.h +++ b/src/intervals.h @@ -31,11 +31,15 @@ struct interval /* The first group of entries deal with the tree structure. */ ptrdiff_t total_length; /* Length of myself and both children. */ ptrdiff_t position; /* Cache of interval's character position. */ - /* This field is usually updated - simultaneously with an interval - traversal, there is no guarantee - that it is valid for a random - interval. */ + /* This field is valid for the final + target interval returned by + find_interval, next_interval, + previous_interval and + update_interval. It cannot be + depended upon for any intermediate + intevals traversed by these + functions, or any other + interval. */ struct interval *left; /* Intervals which precede me. */ struct interval *right; /* Intervals which succeed me. */ diff --git a/src/pdumper.c b/src/pdumper.c index f9638d4357..3aea4ab0d6 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -2065,7 +2065,7 @@ dump_interval_tree (struct dump_context *ctx, INTERVAL tree, dump_off parent_offset) { -#if CHECK_STRUCTS && !defined (HASH_interval_9110163DA0) +#if CHECK_STRUCTS && !defined (HASH_interval_70865541E2) # error "interval changed. See CHECK_STRUCTS comment." #endif // TODO: output tree breadth-first? diff --git a/src/syntax.c b/src/syntax.c index 4616ae296f..faea1432cb 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -340,20 +340,6 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init, invalidate = false; if (!i) return; - /* interval_of updates only ->position of the return value, so - update the parents manually to speed up update_interval. */ - while (!NULL_PARENT (i)) - { - if (AM_RIGHT_CHILD (i)) - INTERVAL_PARENT (i)->position = i->position - - LEFT_TOTAL_LENGTH (i) + TOTAL_LENGTH (i) /* right end */ - - TOTAL_LENGTH (INTERVAL_PARENT (i)) - + LEFT_TOTAL_LENGTH (INTERVAL_PARENT (i)); - else - INTERVAL_PARENT (i)->position = i->position - LEFT_TOTAL_LENGTH (i) - + TOTAL_LENGTH (i); - i = INTERVAL_PARENT (i); - } i = gl_state.forward_i; gl_state.b_property = i->position - gl_state.offset; gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset; I've just noticed a typo in one of the comments in intervals.h, so the above can't be final. Sorry. -- Alan Mackenzie (Nuremberg, Germany).