From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#51814: follow-scroll-down leaves point in wrong place in a corner case. Date: Sat, 13 Nov 2021 17:46:18 +0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37134"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de To: 51814@debbugs.gnu.org, juri@linkov.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 13 18:47:09 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mlx7N-0009TI-LL for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 13 Nov 2021 18:47:09 +0100 Original-Received: from localhost ([::1]:35216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mlx7M-0000P6-K7 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 13 Nov 2021 12:47:08 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:41216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlx7G-0000Ov-6x for bug-gnu-emacs@gnu.org; Sat, 13 Nov 2021 12:47:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36459) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mlx7F-0000re-Um for bug-gnu-emacs@gnu.org; Sat, 13 Nov 2021 12:47:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mlx7F-0003rO-NB for bug-gnu-emacs@gnu.org; Sat, 13 Nov 2021 12:47:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 13 Nov 2021 17:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 51814 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org, Juri Linkov Original-Received: via spool by submit@debbugs.gnu.org id=B.163682560314805 (code B ref -1); Sat, 13 Nov 2021 17:47:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 13 Nov 2021 17:46:43 +0000 Original-Received: from localhost ([127.0.0.1]:48005 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlx6x-0003qj-7T for submit@debbugs.gnu.org; Sat, 13 Nov 2021 12:46:43 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:36868) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlx6s-0003qY-HC for submit@debbugs.gnu.org; Sat, 13 Nov 2021 12:46:41 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:41116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlx6s-0000OD-9D for bug-gnu-emacs@gnu.org; Sat, 13 Nov 2021 12:46:38 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:25292 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1mlx6p-0000o0-Rs for bug-gnu-emacs@gnu.org; Sat, 13 Nov 2021 12:46:38 -0500 Original-Received: (qmail 10966 invoked by uid 3782); 13 Nov 2021 17:46:19 -0000 Original-Received: from acm.muc.de (p4fe15fc7.dip0.t-ipconnect.de [79.225.95.199]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 13 Nov 2021 18:46:19 +0100 Original-Received: (qmail 27491 invoked by uid 1000); 13 Nov 2021 17:46:18 -0000 Content-Disposition: inline X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.1; envelope-from=acm@muc.de; helo=mail.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:219822 Archived-At: 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).