emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 898cdc6: Run scroll/recenter commands from minibuffer in original


From: Juri Linkov
Subject: master 898cdc6: Run scroll/recenter commands from minibuffer in original window (bug#38076)
Date: Sat, 9 Nov 2019 16:32:55 -0500 (EST)

branch: master
commit 898cdc67f19ca15f4ac2b447adf350188baef604
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>

    Run scroll/recenter commands from minibuffer in original window (bug#38076)
    
    * lisp/minibuffer.el (with-minibuffer-selected-window): New macro.
    (minibuffer-recenter-top-bottom, minibuffer-scroll-up-command)
    (minibuffer-scroll-down-command, minibuffer-scroll-other-window):
    (minibuffer-scroll-other-window-down): New commands.
    (minibuffer-local-map): Remap recenter/scroll symbols to their
    minibuffer wrappers: recenter-top-bottom to minibuffer-recenter-top-bottom.
    
    * src/window.c (Fother_window_for_scrolling): Use 'lambda' value for
    MINIBUF arg of Fnext_window, so minibuffer-scroll-other-window and
    minibuffer-scroll-other-window-down doesn't try to scroll the
    minibuffer window.
---
 etc/NEWS           |  3 +++
 lisp/minibuffer.el | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 src/window.c       |  4 ++--
 3 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 61b9f93..4e6a70f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -710,6 +710,9 @@ list the contents of such directories when completing file 
names.
 
 ** Minibuffer
 
+*** Scrolling and recentering commands in the minibuffer are invoked
+on the original window (that was selected before activating the minibuffer).
+
 +++
 *** A new user option, 'minibuffer-beginning-of-buffer-movement', has
 been introduced to allow controlling how the 'M-<' command works in
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 5b993e7..2b13438 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2236,6 +2236,13 @@ The completion method is determined by 
`completion-at-point-functions'."
 (let ((map minibuffer-local-map))
   (define-key map "\C-g" 'abort-recursive-edit)
   (define-key map "\M-<" 'minibuffer-beginning-of-buffer)
+
+  (define-key map [remap recenter-top-bottom] 'minibuffer-recenter-top-bottom)
+  (define-key map [remap scroll-up-command] 'minibuffer-scroll-up-command)
+  (define-key map [remap scroll-down-command] 'minibuffer-scroll-down-command)
+  (define-key map [remap scroll-other-window] 'minibuffer-scroll-other-window)
+  (define-key map [remap scroll-other-window-down] 
'minibuffer-scroll-other-window-down)
+
   (define-key map "\r" 'exit-minibuffer)
   (define-key map "\n" 'exit-minibuffer))
 
@@ -3671,6 +3678,46 @@ Otherwise move to the start of the buffer."
   (when (and arg (not (consp arg)))
     (forward-line 1)))
 
+(defmacro with-minibuffer-selected-window (&rest body)
+  "Execute the forms in BODY from the minibuffer in its original window.
+When used in a minibuffer window, select the window selected just before
+the minibuffer was activated, and execute the forms."
+  (declare (indent 0) (debug t))
+  `(let ((window (minibuffer-selected-window)))
+     (when window
+       (with-selected-window window
+         ,@body))))
+
+(defun minibuffer-recenter-top-bottom (&optional arg)
+  "Run `recenter-top-bottom' from the minibuffer in its original window."
+  (interactive "P")
+  (with-minibuffer-selected-window
+    (recenter-top-bottom arg)))
+
+(defun minibuffer-scroll-up-command (&optional arg)
+  "Run `scroll-up-command' from the minibuffer in its original window."
+  (interactive "^P")
+  (with-minibuffer-selected-window
+    (scroll-up-command arg)))
+
+(defun minibuffer-scroll-down-command (&optional arg)
+  "Run `scroll-down-command' from the minibuffer in its original window."
+  (interactive "^P")
+  (with-minibuffer-selected-window
+    (scroll-down-command arg)))
+
+(defun minibuffer-scroll-other-window (&optional arg)
+  "Run `scroll-other-window' from the minibuffer in its original window."
+  (interactive "P")
+  (with-minibuffer-selected-window
+    (scroll-other-window arg)))
+
+(defun minibuffer-scroll-other-window-down (&optional arg)
+  "Run `scroll-other-window-down' from the minibuffer in its original window."
+  (interactive "^P")
+  (with-minibuffer-selected-window
+    (scroll-other-window-down arg)))
+
 (provide 'minibuffer)
 
 ;;; minibuffer.el ends here
diff --git a/src/window.c b/src/window.c
index e122649..1984a54 100644
--- a/src/window.c
+++ b/src/window.c
@@ -6253,12 +6253,12 @@ followed by all visible frames on the current terminal. 
 */)
     {
       /* Nothing specified; look for a neighboring window on the same
         frame.  */
-      window = Fnext_window (selected_window, Qnil, Qnil);
+      window = Fnext_window (selected_window, Qlambda, Qnil);
 
       if (EQ (window, selected_window))
        /* That didn't get us anywhere; look for a window on another
            visible frame on the current terminal.  */
-        window = Fnext_window (window, Qnil, Qvisible);
+        window = Fnext_window (window, Qlambda, Qvisible);
     }
 
   CHECK_LIVE_WINDOW (window);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]