]> git.eshelyaron.com Git - emacs.git/commitdiff
New commands other-window-prefix (C-x 4 4) and other-frame-prefix (C-x 5 5)
authorJuri Linkov <juri@linkov.net>
Sun, 21 Jun 2020 23:17:02 +0000 (02:17 +0300)
committerJuri Linkov <juri@linkov.net>
Sun, 21 Jun 2020 23:17:02 +0000 (02:17 +0300)
* lisp/window.el (other-window-prefix, same-window-prefix): New commands.
(ctl-x-4-map): Bind 'C-x 4 4' to 'other-window-prefix'.  (Bug#41691)

* lisp/frame.el (other-frame-prefix): New command.
(ctl-x-5-map): Bind 'C-x 5 5' to 'other-frame-prefix'.

etc/NEWS
lisp/frame.el
lisp/window.el

index 5a46e7165e3c5d9ec67c5d4b99a9f474f72db34d..6bfecd681396b1bb687837a41441e1e5ba2ba5d7 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -115,6 +115,14 @@ setting the variable 'auto-save-visited-mode' buffer-locally to nil.
 \f
 * Changes in Specialized Modes and Packages in Emacs 28.1
 
+** Windows
+
+*** The key prefix 'C-x 4 4' displays next command buffer in a new window.
+
+** Frames
+
+*** The key prefix 'C-x 5 5' displays next command buffer in a new frame.
+
 ** Tab Bars
 
 *** The key prefix 'C-x t t' displays next command buffer in a new tab.
index 6c2f774709e54ca537d1b1dc632594106c071b85..77080b76e4fd79f62e8ec0fb9a98a5d9315a2804 100644 (file)
@@ -1070,6 +1070,22 @@ that variable should be nil."
       (setq arg (1+ arg)))
     (select-frame-set-input-focus frame)))
 
+(defun other-frame-prefix ()
+  "Display the buffer of the next command in a new frame.
+The next buffer is the buffer displayed by the next command invoked
+immediately after this command (ignoring reading from the minibuffer).
+Creates a new frame before displaying the buffer.
+When `switch-to-buffer-obey-display-actions' is non-nil,
+`switch-to-buffer' commands are also supported."
+  (interactive)
+  (display-buffer-override-next-command
+   (lambda (buffer alist)
+     (cons (display-buffer-pop-up-frame
+            buffer (append '((inhibit-same-window . t))
+                           alist))
+           'frame)))
+  (message "Display next command buffer in a new frame..."))
+
 (defun iconify-or-deiconify-frame ()
   "Iconify the selected frame, or deiconify if it's currently an icon."
   (interactive)
@@ -2697,6 +2713,7 @@ See also `toggle-frame-maximized'."
 (define-key ctl-x-5-map "1" 'delete-other-frames)
 (define-key ctl-x-5-map "0" 'delete-frame)
 (define-key ctl-x-5-map "o" 'other-frame)
+(define-key ctl-x-5-map "5" 'other-frame-prefix)
 (define-key global-map [f11] 'toggle-frame-fullscreen)
 (define-key global-map [(meta f10)] 'toggle-frame-maximized)
 (define-key esc-map    [f10]        'toggle-frame-maximized)
index 998568e7b82825c134a2fa73bbe61fa84d01809f..f6f30ad6f493e0620c7c579f244242486ba20de0 100644 (file)
@@ -4005,6 +4005,43 @@ always effectively nil."
        ;; Always return nil.
        nil))))
 
+(defun other-window-prefix ()
+  "Display the buffer of the next command in a new window.
+The next buffer is the buffer displayed by the next command invoked
+immediately after this command (ignoring reading from the minibuffer).
+Creates a new window before displaying the buffer.
+When `switch-to-buffer-obey-display-actions' is non-nil,
+`switch-to-buffer' commands are also supported."
+  (interactive)
+  (display-buffer-override-next-command
+   (lambda (buffer alist)
+     (let ((alist (append '((inhibit-same-window . t)) alist))
+           window type)
+       (if (setq window (display-buffer-pop-up-window buffer alist))
+           (setq type 'window)
+         (setq window (display-buffer-use-some-window buffer alist)
+               type 'reuse))
+       (cons window type))))
+  (message "Display next command buffer in a new window..."))
+
+(defun same-window-prefix ()
+  "Display the buffer of the next command in the same window.
+The next buffer is the buffer displayed by the next command invoked
+immediately after this command (ignoring reading from the minibuffer).
+Even when the default rule should display the buffer in a new window,
+force its display in the already selected window.
+When `switch-to-buffer-obey-display-actions' is non-nil,
+`switch-to-buffer' commands are also supported."
+  (interactive)
+  (display-buffer-override-next-command
+   (lambda (buffer alist)
+     (setq alist (append '((inhibit-same-window . nil)) alist))
+     (cons (or
+            (display-buffer-same-window buffer alist)
+            (display-buffer-use-some-window buffer alist))
+           'reuse)))
+  (message "Display next command buffer in the same window..."))
+
 ;; This should probably return non-nil when the selected window is part
 ;; of an atomic window whose root is the frame's root window.
 (defun one-window-p (&optional nomini all-frames)
@@ -10124,5 +10161,6 @@ displaying that processes's buffer."
 (define-key ctl-x-map "-" 'shrink-window-if-larger-than-buffer)
 (define-key ctl-x-map "+" 'balance-windows)
 (define-key ctl-x-4-map "0" 'kill-buffer-and-window)
+(define-key ctl-x-4-map "4" 'other-window-prefix)
 
 ;;; window.el ends here