GNU bug report logs - #51776
revert-buffer causes spurious scrolling when the buffer is displayed in two windows.

Previous Next

Package: emacs;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Thu, 11 Nov 2021 21:22:01 UTC

Severity: normal

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 51776 in the body.
You can then email your comments to 51776 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#51776; Package emacs. (Thu, 11 Nov 2021 21:22:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alan Mackenzie <acm <at> muc.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 11 Nov 2021 21:22:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: bug-gnu-emacs <at> gnu.org
Subject: revert-buffer causes spurious scrolling when the buffer is displayed
 in two windows.
Date: Thu, 11 Nov 2021 21:21:49 +0000
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).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51776; Package emacs. (Fri, 12 Nov 2021 04:17:01 GMT) Full text and rfc822 format available.

Message #8 received at 51776 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: 51776 <at> debbugs.gnu.org
Subject: Re: bug#51776: revert-buffer causes spurious scrolling when the
 buffer is displayed in two windows.
Date: Fri, 12 Nov 2021 04:16:16 +0000
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).




Reply sent to Alan Mackenzie <acm <at> muc.de>:
You have taken responsibility. (Fri, 12 Nov 2021 18:48:02 GMT) Full text and rfc822 format available.

Notification sent to Alan Mackenzie <acm <at> muc.de>:
bug acknowledged by developer. (Fri, 12 Nov 2021 18:48:02 GMT) Full text and rfc822 format available.

Message #13 received at 51776-done <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: 51776-done <at> debbugs.gnu.org
Subject: Re: bug#51776: Acknowledgement (revert-buffer causes spurious
 scrolling when the buffer is displayed in two windows.)
Date: Fri, 12 Nov 2021 18:47:26 +0000
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 <at> gnu.org

> If you wish to submit further information on this problem, please
> send it to 51776 <at> debbugs.gnu.org.

> Please do not send mail to help-debbugs <at> 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 <at> gnu.org with problems




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51776; Package emacs. (Sat, 13 Nov 2021 00:28:02 GMT) Full text and rfc822 format available.

Message #16 received at 51776 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 51776 <at> debbugs.gnu.org
Subject: Re: master 9741924: In insert_file_contents, always set windows'
 point markers.
Date: Fri, 12 Nov 2021 19:27:29 -0500
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);
>        }
>  }
>  





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51776; Package emacs. (Sat, 13 Nov 2021 12:30:02 GMT) Full text and rfc822 format available.

Message #19 received at 51776 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 51776 <at> debbugs.gnu.org
Subject: Re: master 9741924: In insert_file_contents, always set windows'
 point markers.
Date: Sat, 13 Nov 2021 12:29:39 +0000
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).




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 12 Dec 2021 12:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 97 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.