GNU bug report logs - #51814
follow-scroll-down leaves point in wrong place in a corner case.

Previous Next

Package: emacs;

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

Date: Sat, 13 Nov 2021 17:47: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 51814 in the body.
You can then email your comments to 51814 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#51814; Package emacs. (Sat, 13 Nov 2021 17:47: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. (Sat, 13 Nov 2021 17:47:01 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, Juri Linkov <juri <at> linkov.net>
Cc: acm <at> muc.de
Subject: follow-scroll-down leaves point in wrong place in a corner case.
Date: Sat, 13 Nov 2021 17:46:18 +0000
Hello, Juri and Emacs.

On the emacs-28 branch and master.

This bug is a corner case, noted but not fixed in bug #51590.

From a post in that bug thread:

[*] There is a situation which is not new, where if the buffer is too
short to fill all the windows, and it is already scrolled up far,
follow-scroll-down will scroll a correct amount, but leave point in a
random position.

I believe the following patch fixes this.  Juri, could you try it out,
please.

As a test buffer,
(i) open elisp.info in a default GUI window (34 lines);
(ii) C-x 3 ; split it with a vertical divider.
(iii) ] ; Move to next page in manual, "Introduction".
(iv) M-x follow-mode.
(v) C-u 20 C-v ; scroll-up a significant amount.

(vi) Move point to the line beginning "* Caveats".
(vii) M-x follow-scroll-down.

Note that point is in a random place.  This is a bug.

The cause of the bug is that the current code is "optimised" for the case
where there are enough buffer lines above point to scroll a full
follow-page, yet neglects the case where this doesn't hold.  The patch
does away with this optimisation.


diff --git a/lisp/follow.el b/lisp/follow.el
index 2ca2c1f17b..3761275bbf 100644
--- a/lisp/follow.el
+++ b/lisp/follow.el
@@ -669,24 +669,30 @@ follow-scroll-down
         (t
 	 (let* ((orig-point (point))
                 (windows (follow-all-followers))
-		(win (car (reverse windows)))
-		(start (window-start (car windows))))
+		(start (window-start (car windows)))
+                (lines 0))
 	   (if (eq start (point-min))
 	       (if (or (null scroll-error-top-bottom)
 		       (bobp))
 		   (signal 'beginning-of-buffer nil)
 		 (goto-char (point-min)))
-	     (select-window win)
-	     (goto-char start)
-	     (vertical-motion (- (- (window-height win)
-				    (if header-line-format 2 1) ; always mode-line
-				    (if tab-line-format 1 0)
-                                    next-screen-context-lines)))
-	     (set-window-start win (point))
-             (if (< orig-point (window-end win t))
-                 (goto-char orig-point)
-               (goto-char start)
-	       (vertical-motion (- next-screen-context-lines 1)))
+             (select-window (car windows))
+             (dolist (win windows)
+               (setq lines
+                     (+ lines
+                        (- (window-height win)
+                           (if header-line-format 2 1) ; Count mode-line, too.
+                           (if tab-line-format 1 0)))))
+             (setq lines (- lines next-screen-context-lines))
+             (goto-char start)
+             (let ((at-top (> (vertical-motion (- lines)) (- lines))))
+               (set-window-start (car windows) (point))
+               (if at-top
+                   (goto-char orig-point)
+                 (goto-char start)
+                 (vertical-motion (- next-screen-context-lines 1))
+                 (if (< orig-point (point))
+                     (goto-char orig-point))))
 	     (setq follow-internal-force-redisplay t))))))
 (put 'follow-scroll-down 'scroll-command t)
 

-- 
Alan Mackenzie (Nuremberg, Germany).




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

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

From: Juri Linkov <juri <at> linkov.net>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 51814 <at> debbugs.gnu.org
Subject: Re: bug#51814: follow-scroll-down leaves point in wrong place in a
 corner case.
Date: Sat, 13 Nov 2021 19:58:12 +0200
> I believe the following patch fixes this.  Juri, could you try it out,
> please.
>
> As a test buffer,
> (i) open elisp.info in a default GUI window (34 lines);
> (ii) C-x 3 ; split it with a vertical divider.
> (iii) ] ; Move to next page in manual, "Introduction".
> (iv) M-x follow-mode.
> (v) C-u 20 C-v ; scroll-up a significant amount.
>
> (vi) Move point to the line beginning "* Caveats".
> (vii) M-x follow-scroll-down.
>
> Note that point is in a random place.  This is a bug.

Thanks, I confirm this bug is fixed with your patch.
I've tested it with and without tab-line-mode in Info
with the header line.




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

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

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

From: Alan Mackenzie <acm <at> muc.de>
To: Juri Linkov <juri <at> linkov.net>
Cc: 51814-done <at> debbugs.gnu.org
Subject: Re: bug#51814: follow-scroll-down leaves point in wrong place in a
 corner case.
Date: Sat, 13 Nov 2021 18:42:29 +0000
Hello, Juri

On Sat, Nov 13, 2021 at 19:58:12 +0200, Juri Linkov wrote:
> > I believe the following patch fixes this.  Juri, could you try it out,
> > please.

> > As a test buffer,
> > (i) open elisp.info in a default GUI window (34 lines);
> > (ii) C-x 3 ; split it with a vertical divider.
> > (iii) ] ; Move to next page in manual, "Introduction".
> > (iv) M-x follow-mode.
> > (v) C-u 20 C-v ; scroll-up a significant amount.

> > (vi) Move point to the line beginning "* Caveats".
> > (vii) M-x follow-scroll-down.

> > Note that point is in a random place.  This is a bug.

> Thanks, I confirm this bug is fixed with your patch.
> I've tested it with and without tab-line-mode in Info
> with the header line.

Thanks for the testing!  I've committed the patch to the emacs-28
branch, and I'm closing the bug with this post.

-- 
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:05 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.