From unknown Wed Jun 18 23:16:34 2025 X-Loop: help-debbugs@gnu.org Subject: bug#51776: revert-buffer causes spurious scrolling when the buffer is displayed in two windows. Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 Nov 2021 21:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 51776 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 51776@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.163666571717577 (code B ref -1); Thu, 11 Nov 2021 21:22:01 +0000 Received: (at submit) by debbugs.gnu.org; 11 Nov 2021 21:21:57 +0000 Received: from localhost ([127.0.0.1]:42454 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlHW9-0004ZR-5U for submit@debbugs.gnu.org; Thu, 11 Nov 2021 16:21:57 -0500 Received: from lists.gnu.org ([209.51.188.17]:39630) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlHW6-0004ZJ-Rd for submit@debbugs.gnu.org; Thu, 11 Nov 2021 16:21:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlHW6-0005Es-Mr for bug-gnu-emacs@gnu.org; Thu, 11 Nov 2021 16:21:54 -0500 Received: from colin.muc.de ([193.149.48.1]:10421 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1mlHW4-0004ix-Qq for bug-gnu-emacs@gnu.org; Thu, 11 Nov 2021 16:21:54 -0500 Received: (qmail 23109 invoked by uid 3782); 11 Nov 2021 21:21:50 -0000 Received: from acm.muc.de (p4fe159a8.dip0.t-ipconnect.de [79.225.89.168]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 11 Nov 2021 22:21:49 +0100 Received: (qmail 9900 invoked by uid 1000); 11 Nov 2021 21:21:49 -0000 Date: Thu, 11 Nov 2021 21:21:49 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Submission-Agent: TMDA/1.3.x (Ph3nix) From: Alan Mackenzie X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.1; envelope-from=acm@muc.de; helo=mail.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.6 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.6 (--) Hello, Emacs. In the master branch: (i) emacs -Q (ii) C-x C-f ..../doc/lispref/display.texi (iii) C-x 2 ; to split the windows with a horizontal divider. (iv) Move to the "top" window (if not already there) with C-x o. (v) M-< ; to the beginning of the buffer (vi) After the line "@Chapter Emacs Display", insert a new line "@node Display2" (vii) Move to the "bottom" window with C-x o. (viii) M-> ; to the end of the buffer. (ix) Type a new last line "@cindex Help!". (x) M-x revert-buffer RET yes RET The "bottom" window now spuriously scrolls to the top of the buffer. This is a bug. -- Alan Mackenzie (Nuremberg, Germany). From unknown Wed Jun 18 23:16:34 2025 X-Loop: help-debbugs@gnu.org Subject: bug#51776: revert-buffer causes spurious scrolling when the buffer is displayed in two windows. Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 12 Nov 2021 04:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51776 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 51776@debbugs.gnu.org Received: via spool by 51776-submit@debbugs.gnu.org id=B51776.163669058527285 (code B ref 51776); Fri, 12 Nov 2021 04:17:01 +0000 Received: (at 51776) by debbugs.gnu.org; 12 Nov 2021 04:16:25 +0000 Received: from localhost ([127.0.0.1]:42850 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlNzF-000761-MC for submit@debbugs.gnu.org; Thu, 11 Nov 2021 23:16:25 -0500 Received: from colin.muc.de ([193.149.48.1]:20963 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1mlNzD-00075l-RL for 51776@debbugs.gnu.org; Thu, 11 Nov 2021 23:16:24 -0500 Received: (qmail 3615 invoked by uid 3782); 12 Nov 2021 04:16:17 -0000 Received: from acm.muc.de (p4fe15acc.dip0.t-ipconnect.de [79.225.90.204]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 12 Nov 2021 05:16:16 +0100 Received: (qmail 5497 invoked by uid 1000); 12 Nov 2021 04:16:16 -0000 Date: Fri, 12 Nov 2021 04:16:16 +0000 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On Thu, Nov 11, 2021 at 21:21:49 +0000, Alan Mackenzie wrote: > Hello, Emacs. > In the master branch: > (i) emacs -Q > (ii) C-x C-f ..../doc/lispref/display.texi > (iii) C-x 2 ; to split the windows with a horizontal divider. > (iv) Move to the "top" window (if not already there) with C-x o. > (v) M-< ; to the beginning of the buffer > (vi) After the line "@Chapter Emacs Display", insert a new line > "@node Display2" > (vii) Move to the "bottom" window with C-x o. > (viii) M-> ; to the end of the buffer. > (ix) Type a new last line "@cindex Help!". > (x) M-x revert-buffer RET yes RET > The "bottom" window now spuriously scrolls to the top of the buffer. > This is a bug. Not only is it a bug, it's an old bug. It happens in all of Emacs 27.2, 26.3, 25.3, and 24.5. -- Alan Mackenzie (Nuremberg, Germany). From unknown Wed Jun 18 23:16:34 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Alan Mackenzie Subject: bug#51776: closed (Re: bug#51776: Acknowledgement (revert-buffer causes spurious scrolling when the buffer is displayed in two windows.)) Message-ID: References: X-Gnu-PR-Message: they-closed 51776 X-Gnu-PR-Package: emacs Reply-To: 51776@debbugs.gnu.org Date: Fri, 12 Nov 2021 18:48:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1636742882-9214-1" This is a multi-part message in MIME format... ------------=_1636742882-9214-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #51776: revert-buffer causes spurious scrolling when the buffer is displaye= d in two windows. which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 51776@debbugs.gnu.org. --=20 51776: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D51776 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1636742882-9214-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 51776-done) by debbugs.gnu.org; 12 Nov 2021 18:47:43 +0000 Received: from localhost ([127.0.0.1]:45958 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlbaQ-0002Nh-IZ for submit@debbugs.gnu.org; Fri, 12 Nov 2021 13:47:42 -0500 Received: from colin.muc.de ([193.149.48.1]:44925 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1mlbaL-0002MU-JX for 51776-done@debbugs.gnu.org; Fri, 12 Nov 2021 13:47:41 -0500 Received: (qmail 85710 invoked by uid 3782); 12 Nov 2021 18:47:30 -0000 Received: from acm.muc.de (p4fe15acc.dip0.t-ipconnect.de [79.225.90.204]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 12 Nov 2021 19:47:29 +0100 Received: (qmail 31810 invoked by uid 1000); 12 Nov 2021 18:47:26 -0000 Date: Fri, 12 Nov 2021 18:47:26 +0000 To: 51776-done@debbugs.gnu.org Subject: Re: bug#51776: Acknowledgement (revert-buffer causes spurious scrolling when the buffer is displayed in two windows.) Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 51776-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Bug fixed. -- Alan Mackenzie (Nuremberg, Germany). On Thu, Nov 11, 2021 at 21:22:02 +0000, GNU bug Tracking System wrote: > Thank you for filing a new bug report with debbugs.gnu.org. > This is an automatically generated reply to let you know your message > has been received. > Your message is being forwarded to the package maintainers and other > interested parties for their attention; they will reply in due course. > Your message has been sent to the package maintainer(s): > bug-gnu-emacs@gnu.org > If you wish to submit further information on this problem, please > send it to 51776@debbugs.gnu.org. > Please do not send mail to help-debbugs@gnu.org unless you wish > to report a problem with the Bug-tracking system. > -- > 51776: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=51776 > GNU Bug Tracking System > Contact help-debbugs@gnu.org with problems ------------=_1636742882-9214-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 11 Nov 2021 21:21:57 +0000 Received: from localhost ([127.0.0.1]:42454 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlHW9-0004ZR-5U for submit@debbugs.gnu.org; Thu, 11 Nov 2021 16:21:57 -0500 Received: from lists.gnu.org ([209.51.188.17]:39630) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlHW6-0004ZJ-Rd for submit@debbugs.gnu.org; Thu, 11 Nov 2021 16:21:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlHW6-0005Es-Mr for bug-gnu-emacs@gnu.org; Thu, 11 Nov 2021 16:21:54 -0500 Received: from colin.muc.de ([193.149.48.1]:10421 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1mlHW4-0004ix-Qq for bug-gnu-emacs@gnu.org; Thu, 11 Nov 2021 16:21:54 -0500 Received: (qmail 23109 invoked by uid 3782); 11 Nov 2021 21:21:50 -0000 Received: from acm.muc.de (p4fe159a8.dip0.t-ipconnect.de [79.225.89.168]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 11 Nov 2021 22:21:49 +0100 Received: (qmail 9900 invoked by uid 1000); 11 Nov 2021 21:21:49 -0000 Date: Thu, 11 Nov 2021 21:21:49 +0000 To: bug-gnu-emacs@gnu.org Subject: revert-buffer causes spurious scrolling when the buffer is displayed in two windows. Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Submission-Agent: TMDA/1.3.x (Ph3nix) From: Alan Mackenzie X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.1; envelope-from=acm@muc.de; helo=mail.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.6 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.6 (--) Hello, Emacs. In the master branch: (i) emacs -Q (ii) C-x C-f ..../doc/lispref/display.texi (iii) C-x 2 ; to split the windows with a horizontal divider. (iv) Move to the "top" window (if not already there) with C-x o. (v) M-< ; to the beginning of the buffer (vi) After the line "@Chapter Emacs Display", insert a new line "@node Display2" (vii) Move to the "bottom" window with C-x o. (viii) M-> ; to the end of the buffer. (ix) Type a new last line "@cindex Help!". (x) M-x revert-buffer RET yes RET The "bottom" window now spuriously scrolls to the top of the buffer. This is a bug. -- Alan Mackenzie (Nuremberg, Germany). ------------=_1636742882-9214-1-- From unknown Wed Jun 18 23:16:34 2025 X-Loop: help-debbugs@gnu.org Subject: bug#51776: master 9741924: In insert_file_contents, always set windows' point markers. Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 13 Nov 2021 00:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51776 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Alan Mackenzie Cc: 51776@debbugs.gnu.org Received: via spool by 51776-submit@debbugs.gnu.org id=B51776.163676326310956 (code B ref 51776); Sat, 13 Nov 2021 00:28:02 +0000 Received: (at 51776) by debbugs.gnu.org; 13 Nov 2021 00:27:43 +0000 Received: from localhost ([127.0.0.1]:46239 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlgtS-0002qe-T9 for submit@debbugs.gnu.org; Fri, 12 Nov 2021 19:27:43 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:39770) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlgtP-0002qK-L0 for 51776@debbugs.gnu.org; Fri, 12 Nov 2021 19:27:40 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 59E2B440C78; Fri, 12 Nov 2021 19:27:33 -0500 (EST) Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 6913A440BC6; Fri, 12 Nov 2021 19:27:31 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1636763251; bh=Uvddo0PRVSq7gW8mZLN9VkdL9cAaCldSB/XY5cNSmjs=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=QeLnf9PNtvFGPTOlzTNNkN05Jy8r5NLF82+6Mq9BemhJjRTDZQGQrGWkmvSrdA4/C SWG3kuEsXcFI7GBTT2WFqKUQdFb+3c4xN+R1+HHJSZwGxiEvwL3OOyKwI8kPjzIAA+ K3u9dP8Cw3pdwzXXvyOUjXmHhZOSFen87Sat/GcahYqnv7ohgnk1Rmz/QU6bmxscTn Axmur4Zpq3Ue6v7HHIWC0xrMwpfMRo4cNHPDZ2cVAYppV1PL3Lp64OxzAd31mntijB m6T2j+lvS5XQE2P0S3E3dk6p+ejI5lJ7VlCy/KmsipCRfxQYbzqlujcLEiNN552crs GFrYnUmb6KpyQ== Received: from ceviche (unknown [45.72.128.33]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 1F79E1201B6; Fri, 12 Nov 2021 19:27:31 -0500 (EST) From: Stefan Monnier Message-ID: References: <20211112184451.21516.85178@vcs0.savannah.gnu.org> <20211112184452.6C899209C6@vcs0.savannah.gnu.org> Date: Fri, 12 Nov 2021 19:27:29 -0500 In-Reply-To: <20211112184452.6C899209C6@vcs0.savannah.gnu.org> (Alan Mackenzie's message of "Fri, 12 Nov 2021 13:44:52 -0500 (EST)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.064 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) 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). So maybe the better fix is to just change XFIXNUM (oldpos) < same_at_end into XFIXNUM (oldpos) <= same_at_end 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. ] 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); > } > } > From unknown Wed Jun 18 23:16:34 2025 X-Loop: help-debbugs@gnu.org Subject: bug#51776: master 9741924: In insert_file_contents, always set windows' point markers. 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 X-GNU-PR-Keywords: To: Stefan Monnier Cc: 51776@debbugs.gnu.org Received: via spool by 51776-submit@debbugs.gnu.org id=B51776.163680659321047 (code B ref 51776); Sat, 13 Nov 2021 12:30:02 +0000 Received: (at 51776) by debbugs.gnu.org; 13 Nov 2021 12:29:53 +0000 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 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 Received: (qmail 1280 invoked by uid 3782); 13 Nov 2021 12:29:39 -0000 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 Received: (qmail 24782 invoked by uid 1000); 13 Nov 2021 12:29:39 -0000 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 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 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).