From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#51776: master 9741924: In insert_file_contents, always set windows' point markers. Date: Sat, 13 Nov 2021 12:29:39 +0000 Message-ID: References: <20211112184451.21516.85178@vcs0.savannah.gnu.org> <20211112184452.6C899209C6@vcs0.savannah.gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33018"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 51776@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 13 13:30:11 2021 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 1mlsAd-0008Sw-92 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 13 Nov 2021 13:30:11 +0100 Original-Received: from localhost ([::1]:35432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mlsAb-00069Z-RN for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 13 Nov 2021 07:30:09 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlsAV-00069C-94 for bug-gnu-emacs@gnu.org; Sat, 13 Nov 2021 07:30:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35146) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mlsAU-0004LC-VM for bug-gnu-emacs@gnu.org; Sat, 13 Nov 2021 07:30:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mlsAU-0005UF-Mu for bug-gnu-emacs@gnu.org; Sat, 13 Nov 2021 07:30:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 13 Nov 2021 12:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51776 X-GNU-PR-Package: emacs Original-Received: via spool by 51776-submit@debbugs.gnu.org id=B51776.163680659321047 (code B ref 51776); Sat, 13 Nov 2021 12:30:02 +0000 Original-Received: (at 51776) by debbugs.gnu.org; 13 Nov 2021 12:29:53 +0000 Original-Received: from localhost ([127.0.0.1]:46692 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlsAK-0005TP-Sj for submit@debbugs.gnu.org; Sat, 13 Nov 2021 07:29:53 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:17104 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1mlsAE-0005T3-MD for 51776@debbugs.gnu.org; Sat, 13 Nov 2021 07:29:51 -0500 Original-Received: (qmail 1280 invoked by uid 3782); 13 Nov 2021 12:29:39 -0000 Original-Received: from acm.muc.de (p4fe15fc7.dip0.t-ipconnect.de [79.225.95.199]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 13 Nov 2021 13:29:39 +0100 Original-Received: (qmail 24782 invoked by uid 1000); 13 Nov 2021 12:29:39 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de 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:219808 Archived-At: On Fri, Nov 12, 2021 at 19:27:29 -0500, Stefan Monnier wrote: > Hi Alan, > Alan Mackenzie [2021-11-12 13:44:52] wrote: > > In insert_file_contents, always set windows' point markers. > > This fixes bug #51776. > > * src/fileio.c (restore_window_points): Restore a w->mpoint even > > when that marker originally pointed into the unchanged area near > > BOB or EOB. This prevents that window's point being moved a long > > way from its starting place due to the removal of the central part > > of the buffer by insert_file_contents. > Hmm... my understanding of the code says that if `oldppos <= same_at_beg` then > your change is harmless but unnecessary because the marker > is still at `oldpos` anyway. > But when `oldppos > same_at_beg` your change is harmful because the > marker has properly preserved its exact position in the text whereas > your code will arbitrarily move it to `oldpos` (which is even > potentially past Z if the revert shortened the buffer). Er, yes, you're right. Thanks! > So maybe the better fix is to just change > XFIXNUM (oldpos) < same_at_end > into > XFIXNUM (oldpos) <= same_at_end Indeed. > Or am I missing something? > [ Not sure what we should do when `oldpos == same_at_beg == same_at_end`, OTOH. > I suspect staying at `same_at_beg` might be the better choice in that > case. ] That case is harmless, because it just means that after the reversion, point stays where it was (before the re-inserted middle) rather than where it was (after the re-inserted middle). I'll correct this patch. > Stefan > > src/fileio.c | 9 ++++++--- > > 1 file changed, 6 insertions(+), 3 deletions(-) > > > > diff --git a/src/fileio.c b/src/fileio.c > > index 3c13d3f..a7b1649 100644 > > --- a/src/fileio.c > > +++ b/src/fileio.c > > @@ -3827,6 +3827,7 @@ restore_window_points (Lisp_Object window_markers, ptrdiff_t inserted, > > Lisp_Object car = XCAR (window_markers); > > Lisp_Object marker = XCAR (car); > > Lisp_Object oldpos = XCDR (car); > > + ptrdiff_t newpos; > > if (MARKERP (marker) && FIXNUMP (oldpos) > > && XFIXNUM (oldpos) > same_at_start > > && XFIXNUM (oldpos) < same_at_end) > > @@ -3834,10 +3835,12 @@ restore_window_points (Lisp_Object window_markers, ptrdiff_t inserted, > > ptrdiff_t oldsize = same_at_end - same_at_start; > > ptrdiff_t newsize = inserted; > > double growth = newsize / (double)oldsize; > > - ptrdiff_t newpos > > - = same_at_start + growth * (XFIXNUM (oldpos) - same_at_start); > > - Fset_marker (marker, make_fixnum (newpos), Qnil); > > + newpos = same_at_start > > + + growth * (XFIXNUM (oldpos) - same_at_start); > > } > > + else > > + newpos = XFIXNUM (oldpos); > > + Fset_marker (marker, make_fixnum (newpos), Qnil); > > } > > } > > -- Alan Mackenzie (Nuremberg, Germany).