all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: 51814@debbugs.gnu.org, juri@linkov.net
Cc: acm@muc.de
Subject: bug#51814: follow-scroll-down leaves point in wrong place in a corner case.
Date: Sat, 13 Nov 2021 17:46:18 +0000	[thread overview]
Message-ID: <YY/56vy2K2d+fZye@ACM> (raw)

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).





             reply	other threads:[~2021-11-13 17:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-13 17:46 Alan Mackenzie [this message]
2021-11-13 17:58 ` bug#51814: follow-scroll-down leaves point in wrong place in a corner case Juri Linkov
2021-11-13 18:42   ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YY/56vy2K2d+fZye@ACM \
    --to=acm@muc.de \
    --cc=51814@debbugs.gnu.org \
    --cc=juri@linkov.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.