Subject: bug#23347: 25.0.92; Follow mode scrolling broken -- scrolls only one page

From: Anders Lindgren <[email-masked]>
Date: Tue, 26 Apr 2016 15:08:31 +0200

Hi!

I just tested this and I can confirm that it works, as far as I can tell!

I tested the "old" scroll functions `follow-scroll-up' and `-down' and now
they scroll the entire display, hence the bug I initially reported is fixed.

I tested with positive and negative numerical arguments and the
corresponding number of lines were scrolled, in the correct direction.

I tested the new "window" scroll functions and they work as well -- with
and without arguments.

I noticed some area where this could be improved upon, however they are
minor and I think we should address them after the emacs-25 release:

+ The new "window" scroll functions scroll almost a window. The effect is
that normally the point is moved from one window to the next. However, if
the cursor is at the bottom of a window the user do a
`follow-scroll-up-window', the point ens up at the top of the same window,
which could be a bit confusing. (In other words, skip the
`next-screen-context-lines' part. When using Follow mode, there is enough
context anyway.)

+ Now both `follow-scroll-up' and `follow-scroll-up-window' scroll ARG
lines when presented with an argument. It would be nice if either one of
them could scroll ARG windows instead. (Where "one window" could be seen as
the number of lines of the current window.) I think it would make most
sense to apply this change to `follow-scroll-up'.

+ Documentation:

In `follow-scroll-up-window' -- we should mention the difference is
compared to `scroll-up' (that the point isn't moved, if it can be displayed
in another window).

In `follow-scroll-up' -- Make it clear what the difference between this and
`follow-scroll-up-window' is (that it scroll the entire display).

Finally -- Many, many thanks for all the work you have put into this!

    -- Anders

On Tue, Apr 26, 2016 at 1:51 PM, Alan Mackenzie <[email-masked]> wrote:

> Hello, Anders.
>
> On Sun, Apr 24, 2016 at 05:37:57PM +0200, Anders Lindgren wrote:
> > Hi!
>
> > Agreed. All three scroll commands (non-follow-mode scroll, scroll one
> page,
> > and scroll N pages) are useful.
>
> [ .... ]
>
> > Yes, I agree, `page' isn't a good choice.
>
> > What about `follow-scroll-up-keep-point'? That way it would be clear what
> > the difference is between it and the normal scroll command.
>
> > If I would have designed Follow mode today, I probably would have used
> your
> > name, `follow-scroll-up-window', and named the N-page scroll
> > `follow-scroll-up-window-group'.
>
> I've just used `follow-scroll-up-window' and
> `follow-scroll-down-window'.  At least, for now.
>
> [ .... ]
>
> > Anyway, here is what I think we can agree on:
> > > 1. `follow-scroll-up/down' should scroll by N windows.
> > > 2. There need to be commands in follow.el that scroll by 1 window as is
> > >   done by the current `follow-scroll-up/down'.  You have suggested the
> > >   name `follow-scroll-up/down-one-page'.  I have countered with
> > >   `follow-scroll-up/down-window'.
>
> > > If we can agree, I'm willing to amend follow.el.  I think it's probably
> > > too late for this fix to make it into Emacs 25.1, though.
> > >
>
> > Well, give it a try. Feel free to pick a suitable name. If we come up
> with
> > a clean solution quickly John might accept it.
>
> OK.  I had one or two minor problems with follow-scroll-up/down with a
> non-nil ARG.  In the end, I just extracted functionality from
> follow-scroll-up/down-window into separate functions, and called those
> from all four scrolling functions.
>
> Anyway, here is the patch I've come up with.  Could you review it and
> test it, please.  Thanks!
>
>
> diff --git a/lisp/follow.el b/lisp/follow.el
> index 5801f79..3e23247 100644
> --- a/lisp/follow.el
> +++ b/lisp/follow.el
> @@ -532,6 +532,80 @@ follow-get-scrolled-point
>  ;; position...  (This would also be corrected if we would have had a
>  ;; good redisplay abstraction.)
>
> +(defun follow-scroll-up-arg (arg)
> +  "Scroll the text in a follow mode window chain up by ARG lines.
> +If ARG is nil, scroll the size of the current window.
> +
> +This is an internal function for `follow-scroll-up' and
> +`follow-scroll-up-window'."
> +  (let ((opoint (point))  (owin (selected-window)))
> +    (while
> +        ;; If we are too near EOB, try scrolling the previous window.
> +        (condition-case nil (progn (scroll-up arg) nil)
> +          (end-of-buffer
> +           (condition-case nil (progn (follow-previous-window) t)
> +             (error
> +              (select-window owin)
> +              (goto-char opoint)
> +              (signal 'end-of-buffer nil))))))
> +    (unless (and scroll-preserve-screen-position
> +                 (get this-command 'scroll-command))
> +      (goto-char opoint))
> +    (setq follow-fixed-window t)))
> +
> +(defun follow-scroll-down-arg (arg)
> +  "Scroll the text in a follow mode window chain down by ARG lines.
> +If ARG is nil, scroll the size of the current window.
> +
> +This is an internal function for `follow-scroll-down' and
> +`follow-scroll-down-window'."
> +  (let ((opoint (point)))
> +    (scroll-down arg)
> +    (unless (and scroll-preserve-screen-position
> +                 (get this-command 'scroll-command))
> +      (goto-char opoint))
> +    (setq follow-fixed-window t)))
> +
> +;;;###autoload
> +(defun follow-scroll-up-window (&optional arg)
> +  "Scroll text in a Follow mode window up by that window's size.
> +The other windows in the window chain will scroll synchronously.
> +
> +If called with no ARG, the `next-screen-context-lines' last lines of
> +the window will be visible after the scroll.
> +
> +If called with an argument, scroll ARG lines up.
> +Negative ARG means scroll downward.
> +
> +Works like `scroll-up' when not in Follow mode."
> +  (interactive "P")
> +  (cond ((not follow-mode)
> +        (scroll-up arg))
> +       ((eq arg '-)
> +        (follow-scroll-down-window))
> +       (t (follow-scroll-up-arg arg))))
> +(put 'follow-scroll-up-window 'scroll-command t)
> +
> +;;;###autoload
> +(defun follow-scroll-down-window (&optional arg)
> +  "Scroll text in a Follow mode window down by that window's size.
> +The other windows in the window chain will scroll synchronously.
> +
> +If called with no ARG, the `next-screen-context-lines' top lines of
> +the window in the chain will be visible after the scroll.
> +
> +If called with an argument, scroll ARG lines down.
> +Negative ARG means scroll upward.
> +
> +Works like `scroll-down' when not in Follow mode."
> +  (interactive "P")
> +  (cond ((not follow-mode)
> +        (scroll-down arg))
> +       ((eq arg '-)
> +        (follow-scroll-up-window))
> +       (t (follow-scroll-down-arg arg))))
> +(put 'follow-scroll-down-window 'scroll-command t)
> +
>  ;;;###autoload
>  (defun follow-scroll-up (&optional arg)
>    "Scroll text in a Follow mode window chain up.
> @@ -546,23 +620,18 @@ follow-scroll-up
>    (interactive "P")
>    (cond ((not follow-mode)
>          (scroll-up arg))
> -       ((eq arg '-)
> -        (follow-scroll-down))
> -       (t
> -        (let ((opoint (point))  (owin (selected-window)))
> -          (while
> -              ;; If we are too near EOB, try scrolling the previous
> window.
> -              (condition-case nil (progn (scroll-up arg) nil)
> -                (end-of-buffer
> -                 (condition-case nil (progn (follow-previous-window) t)
> -                   (error
> -                    (select-window owin)
> -                    (goto-char opoint)
> -                    (signal 'end-of-buffer nil))))))
> -          (unless (and scroll-preserve-screen-position
> -                       (get this-command 'scroll-command))
> -            (goto-char opoint))
> -          (setq follow-fixed-window t)))))
> +       (arg (follow-scroll-up-arg arg))
> +        (t
> +        (let* ((windows (follow-all-followers))
> +               (end (window-end (car (reverse windows)))))
> +          (if (eq end (point-max))
> +              (signal 'end-of-buffer nil)
> +            (select-window (car windows))
> +            ;; `window-end' might return nil.
> +            (if end
> +                (goto-char end))
> +            (vertical-motion (- next-screen-context-lines))
> +            (set-window-start (car windows) (point)))))))
>  (put 'follow-scroll-up 'scroll-command t)
>
>  ;;;###autoload
> @@ -579,15 +648,22 @@ follow-scroll-down
>    (interactive "P")
>    (cond ((not follow-mode)
>          (scroll-down arg))
> -       ((eq arg '-)
> -        (follow-scroll-up))
> -       (t
> -        (let ((opoint (point)))
> -          (scroll-down arg)
> -          (unless (and scroll-preserve-screen-position
> -                       (get this-command 'scroll-command))
> -            (goto-char opoint))
> -          (setq follow-fixed-window t)))))
> +       (arg (follow-scroll-down-arg arg))
> +        (t
> +        (let* ((windows (follow-all-followers))
> +               (win (car (reverse windows)))
> +               (start (window-start (car windows))))
> +          (if (eq start (point-min))
> +              (signal 'beginning-of-buffer nil)
> +            (select-window win)
> +            (goto-char start)
> +            (vertical-motion (- (- (window-height win)
> +                                   (if header-line-format 2 1)
> +                                   next-screen-context-lines)))
> +            (set-window-start win (point))
> +            (goto-char start)
> +            (vertical-motion (- next-screen-context-lines 1))
> +            (setq follow-internal-force-redisplay t))))))
>  (put 'follow-scroll-down 'scroll-command t)
>
>  (declare-function comint-adjust-point "comint" (window))
>
>
> >     -- Anders
>
> --
> Alan Mackenzie (Nuremberg, Germany).
>