From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#44070: 28.0.50; Minibuffer display "jumps" upon minor edit Date: Sun, 18 Oct 2020 18:09:55 -0400 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15642"; mail-complaints-to="usenet@ciao.gmane.io" To: 44070@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 19 00:11:38 2020 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 1kUGtu-0003yf-8g for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 19 Oct 2020 00:11:38 +0200 Original-Received: from localhost ([::1]:50476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kUGtt-0003VL-Bh for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Oct 2020 18:11:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUGtL-0003Uf-8Y for bug-gnu-emacs@gnu.org; Sun, 18 Oct 2020 18:11:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55947) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kUGtK-00042r-3d for bug-gnu-emacs@gnu.org; Sun, 18 Oct 2020 18:11:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kUGtJ-0006Wl-N3 for bug-gnu-emacs@gnu.org; Sun, 18 Oct 2020 18:11:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 18 Oct 2020 22:11:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 44070 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.160305902225040 (code B ref -1); Sun, 18 Oct 2020 22:11:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Oct 2020 22:10:22 +0000 Original-Received: from localhost ([127.0.0.1]:39260 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kUGsc-0006Vk-S5 for submit@debbugs.gnu.org; Sun, 18 Oct 2020 18:10:22 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:38820) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kUGsX-0006VT-VF for submit@debbugs.gnu.org; Sun, 18 Oct 2020 18:10:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUGsX-0003D8-Qf for bug-gnu-emacs@gnu.org; Sun, 18 Oct 2020 18:10:13 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:6951) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUGsS-0003gK-4f for bug-gnu-emacs@gnu.org; Sun, 18 Oct 2020 18:10:12 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 247B180855 for ; Sun, 18 Oct 2020 18:10:07 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 716208058D for ; Sun, 18 Oct 2020 18:10:05 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1603059005; bh=tV4mWo83zRkyuV3xth6bDg2BLUu7CnRs0rS/DcMaHSo=; h=From:To:Subject:Date:From; b=A1JDMkNGhIH1hdmCbzAUkdnAzOeS13+VnL3vCVAL+jq2eiGBryAPai2WhFbZl7ckS 8EVMtPpPjUSK2z70Cj4lB43+0+C2byC8NCu0EWLrSUeEIpYWzg+yb6DNxJzMUQkpNm MrefCrthIy4QBbKiVvzmohGPDFMD7FLfymzWg1BmbJNkqhdlFiOsYbm1afI7lQkhU0 wqeSJwrl2tvORk/i+djurgvruj4BxYmmC0Bzq6+E3nUl1ksQioKy5pJmxpJTyl14KO KOK5kl7L01f7LYnJ1FxGncNG1xxnHL5tzDHHGcnUZdcFddZesdAP89HpRzwES8fnV1 E1BeX/8duQFfQ== Original-Received: from alfajor (unknown [157.52.9.240]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 5564812005C for ; Sun, 18 Oct 2020 18:10:05 -0400 (EDT) Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/18 16:15:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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:190922 Archived-At: Package: Emacs Version: 28.0.50 Step 1: % emacs -Q M-: a C-u 20 C-q C-j abc You should now have "abc" on the last line of the miniwindow with the prompt scrolled out of view. So far so good. Step 2: M-< M-> We scroll to the beginning and back to the end. Now "abc" is not quite on the last line of the miniwindow, more specifically there should be 2 empty lines left after "abc". The behavior is slightly different if instead of `end-of-buffer` we use (goto-char (point-max)), but the problem at step 3 remains: Step 3: DEL This is the surprising part: this simple edit causes the minibuffer to be "rescrolled" so that the resulting "ab" is now again placed on the very last line of the miniwindow. The same thing happens with any other simple edit because any buffer modification triggers a call to `resize_mini_window`, which will always try to arrange to see a maximum of text. Not sure if it's better to fix this by changing step 2 or by changing step 3, but the patch below fixes it by changing step 2. WDYT? Stefan diff --git a/lisp/simple.el b/lisp/simple.el index d6fce922c4..41aba2ddc3 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -1129,7 +1129,7 @@ end-of-buffer ;; If the end of the buffer is not already on the screen, ;; then scroll specially to put it near, but not at, the bottom. (overlay-recenter (point)) - (recenter -3)))) + (recenter (if (window-minibuffer-p) -1 -3))))) (defcustom delete-active-region t "Whether single-char deletion commands delete an active region. diff --git a/src/xdisp.c b/src/xdisp.c index 5a62cd6eb5..c1105df3fc 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -18820,6 +18820,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) /* Try to scroll by specified few lines. */ if ((0 < scroll_conservatively + || MINI_WINDOW_P (w) || 0 < emacs_scroll_step || temp_scroll_step || NUMBERP (BVAR (current_buffer, scroll_up_aggressively)) @@ -18830,7 +18831,9 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) /* The function returns -1 if new fonts were loaded, 1 if successful, 0 if not successful. */ int ss = try_scrolling (window, just_this_one_p, - scroll_conservatively, + (MINI_WINDOW_P (w) + ? SCROLL_LIMIT + 1 + : scroll_conservatively), emacs_scroll_step, temp_scroll_step, last_line_misfit); switch (ss) diff --git a/test/src/xdisp-tests.el b/test/src/xdisp-tests.el index 95c39dacc3..d513f5beba 100644 --- a/test/src/xdisp-tests.el +++ b/test/src/xdisp-tests.el @@ -21,34 +21,55 @@ (require 'ert) +(defmacro xdisp-tests--in-minibuffer (&rest body) + (declare (debug t) (indent 0)) + `(catch 'result + (minibuffer-with-setup-hook + (lambda () + (let ((redisplay-skip-initial-frame nil) + (executing-kbd-macro nil)) ;Don't skip redisplay + (throw 'result (progn . ,body)))) + (let ((executing-kbd-macro t)) ;Force real minibuffer in `read-string'. + (read-string "toto: "))))) + (ert-deftest xdisp-tests--minibuffer-resizing () ;; bug#43519 - ;; FIXME: This test returns success when run in batch but - ;; it's only a lucky accident: it also returned success - ;; when bug#43519 was not fixed. (should (equal t - (catch 'result - (minibuffer-with-setup-hook - (lambda () - (insert "hello") - (let ((ol (make-overlay (point) (point))) - (redisplay-skip-initial-frame nil) - (max-mini-window-height 1) - (text "askdjfhaklsjdfhlkasjdfhklasdhflkasdhflkajsdhflkashdfkljahsdlfkjahsdlfkjhasldkfhalskdjfhalskdfhlaksdhfklasdhflkasdhflkasdhflkajsdhklajsdgh")) - ;; (save-excursion (insert text)) - ;; (sit-for 2) - ;; (delete-region (point) (point-max)) - (put-text-property 0 1 'cursor t text) - (overlay-put ol 'after-string text) - (let ((executing-kbd-macro nil)) ;Don't skip redisplay - (redisplay 'force)) - (throw 'result - ;; Make sure we do the see "hello" text. - (prog1 (equal (window-start) (point-min)) - ;; (list (window-start) (window-end) (window-width)) - (delete-overlay ol))))) - (let ((executing-kbd-macro t)) ;Force real minibuffer in `read-string'. - (read-string "toto: "))))))) + (xdisp-tests--in-minibuffer + (insert "hello") + (let ((ol (make-overlay (point) (point))) + (max-mini-window-height 1) + (text "askdjfhaklsjdfhlkasjdfhklasdhflkasdhflkajsdhflkashdfkljahsdlfkjahsdlfkjhasldkfhalskdjfhalskdfhlaksdhfklasdhflkasdhflkasdhflkajsdhklajsdgh")) + ;; (save-excursion (insert text)) + ;; (sit-for 2) + ;; (delete-region (point) (point-max)) + (put-text-property 0 1 'cursor t text) + (overlay-put ol 'after-string text) + (redisplay 'force) + ;; Make sure we do the see "hello" text. + (prog1 (equal (window-start) (point-min)) + ;; (list (window-start) (window-end) (window-width)) + (delete-overlay ol))))))) + +(ert-deftest xdisp-tests--minibuffer-scroll () ;; bug#43519 + (let ((posns + (xdisp-tests--in-minibuffer + (let ((max-mini-window-height 4)) + (dotimes (_ 80) (insert "\nhello")) + (beginning-of-buffer) + (redisplay 'force) + (end-of-buffer) + ;; A simple edit like removing the last `o' shouldn't cause + ;; the rest of the minibuffer's text to move. + (list + (progn (redisplay 'force) (window-start)) + (progn (delete-char -1) + (redisplay 'force) (window-start)) + (progn (goto-char (point-min)) (redisplay 'force) + (goto-char (point-max)) (redisplay 'force) + (window-start))))))) + (should (equal (nth 0 posns) (nth 1 posns))) + (should (equal (nth 1 posns) (nth 2 posns))))) ;;; xdisp-tests.el ends here