New commands other-window-prefix (C-x 4 4) and other-frame-prefix (C-x 5 5)

* 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'.
This commit is contained in:
Juri Linkov 2020-06-22 02:17:02 +03:00
parent a1686c00d0
commit ba8370bc38
3 changed files with 63 additions and 0 deletions

View file

@ -115,6 +115,14 @@ setting the variable 'auto-save-visited-mode' buffer-locally to nil.
* 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.

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

View 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