From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#51776: master 9741924: In insert_file_contents, always set windows' point markers. Date: Fri, 12 Nov 2021 19:27:29 -0500 Message-ID: References: <20211112184451.21516.85178@vcs0.savannah.gnu.org> <20211112184452.6C899209C6@vcs0.savannah.gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33818"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 51776@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 13 01:28:10 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 1mlgtt-0008aT-Ut for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 13 Nov 2021 01:28:10 +0100 Original-Received: from localhost ([::1]:52894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mlgts-0005h5-Rm for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 12 Nov 2021 19:28:08 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50244) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlgtn-0005gw-2V for bug-gnu-emacs@gnu.org; Fri, 12 Nov 2021 19:28:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34695) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mlgtm-0007nl-QP for bug-gnu-emacs@gnu.org; Fri, 12 Nov 2021 19:28:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mlgtm-0002rJ-Hb for bug-gnu-emacs@gnu.org; Fri, 12 Nov 2021 19:28:02 -0500 X-Loop: help-debbugs@gnu.org 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 Original-Received: via spool by 51776-submit@debbugs.gnu.org id=B51776.163676326310956 (code B ref 51776); Sat, 13 Nov 2021 00:28:02 +0000 Original-Received: (at 51776) by debbugs.gnu.org; 13 Nov 2021 00:27:43 +0000 Original-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 Original-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 Original-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) Original-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== Original-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) In-Reply-To: <20211112184452.6C899209C6@vcs0.savannah.gnu.org> (Alan Mackenzie's message of "Fri, 12 Nov 2021 13:44:52 -0500 (EST)") 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:219795 Archived-At: 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); > } > } >