diff --git a/etc/NEWS b/etc/NEWS index 5a46e7165e3..6bfecd68139 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -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. diff --git a/lisp/frame.el b/lisp/frame.el index 6c2f774709e..77080b76e4f 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -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) diff --git a/lisp/window.el b/lisp/window.el index 998568e7b82..f6f30ad6f49 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -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