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

From: Eli Zaretskii <[email-masked]>
Date: Mon, 01 Oct 2018 16:52:40 +0300

> Date: Mon, 1 Oct 2018 12:59:22 +0000
> Cc: [email-masked]
> From: Alan Mackenzie <[email-masked]>
> 
> > > 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.
> 
> I have the feeling we're at cross purposes somehow, here.  I think the
> display engine, by itself, is only ever going to be scrolling the
> selected window.

I'm saying that by using window-scroll-functions you can catch _any_
scrolling, and control what happens when the display engine wants to
scroll.

But I'm not selling anything.  You said many times that you wished the
display engine did part of the job in follow-mode, and that
follow-mode could use some help from the display engine.  I think by
using window-scroll-functions you can get some of that, but if you
don't see how, it's fine with me.

> > > 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).
> 
> That sounds very strange.  Where would the difficulty lie in the display
> engine doing (forward-line -1) rather than the Lisp code?

forward-line goes back one physical line, not one screen line.

It isn't rocket science to start with the largest buffer position in
the window, it's just a bit more complicated, so if we can start from
the beginning of the screen line, it will make the job very easy.