Subject: bug#32874: Unwanted scrolling in edebug `f' command when follow-mode is active

From: Eli Zaretskii <[email-masked]>
Date: Sun, 30 Sep 2018 20:17:46 +0300

> Date: Sun, 30 Sep 2018 15:36:46 +0000
> Cc: [email-masked]
> From: Alan Mackenzie <[email-masked]>
> 
> > > I've had a look at window-scroll-functions, but I can't see what you
> > > must be seeing.  Currently, the documentation warns against trying to
> > > influence the scrolling, saying "it probably won't work anyway".
> 
> > But you don't want to scroll yourself, you just want to switch the
> > selected window and move point so that Emacs won't need to scroll.
> 
> > AFAIU, follow-mode wants to kick in when point goes off the selected
> > window.  And the call to window-scroll-functions is exactly the place
> > where the display engine decides it needs to scroll the window, but
> > didn't actually scroll it yet.  So that looks like a good place to have
> > follow-mode do its thing.  We might need to add some simple facility
> > for follow-mode to use, so that it could signal the display engine not
> > to scroll the window.  Other than that, I think this possibility is
> > worth exploring.
> 
> Follow-mode also needs to be active on explicit scrolling commands such
> as C-v.  Also, after inserting a newline, subsequent windows need to be
> scrolled down.  After either of these, follow-mode laboriously starts
> determining where all its windows have to start and end.  There's nothing
> in the display engine to help in this process.

I'm not sure you are right, since all of the situations you describe
go through the function try_scrolling, which calls
window-scroll-functions.

> > > Maybe it would be relatively simple to introduce new functionality.
> > > Something like "scroll window so that window-end gets the given value".
> 
> > I'm not sure I understand how this could help follow-mode.  Please
> > elaborate.
> 
> Currently when a middle or right hand window gets scrolled for any
> reason, follow-mode has to determine how to scroll windows to the left of
> it.  It does this by making a first guess at a window-start, does
> set-window-start, then moves forward through the window to see how close
> window-end is to where it needs to be.  If it's a line off, a different
> starting position is chosen, and so on, until window-start gets correctly
> placed.
> 
> If there were a function set-window-end, the display engine itself could
> move back over the text lines to find window-start far more efficiently
> and directly than follow-mode can.

It should be very easy to write such a function, provided that you can
pass it as argument the buffer position of the beginning of the last
line in the window (not the end of that line).