From: Mark Wooding Date: Mon, 2 May 2022 11:52:20 +0000 (+0100) Subject: dot/emacs, el/dot-emacs.el: New gadget to force window selection. X-Git-Url: https://git.distorted.org.uk/~mdw/profile/commitdiff_plain/4ebbf6a71a9ddff39cdb512c3aa4c0bbe59578b2 dot/emacs, el/dot-emacs.el: New gadget to force window selection. I'm fed up with Emacs `display-buffer', which seems carefully designed to read my mind and choose the least convenient possible window display a buffer in. Introduce a new command `mdw-designate-window', bound to `C-c w SPC', which marks a window as being the target for the next buffer shown by `display-buffer' when its caller doesn't have a better plan. This leaves alone things like Magit popups, which already know that they want to go at the bottom of the current window (and that's fine). --- diff --git a/dot/emacs b/dot/emacs index 3967646..220fdd4 100644 --- a/dot/emacs +++ b/dot/emacs @@ -766,6 +766,7 @@ (global-set-key [?\C-c ?v ?i] 'vm-visit-imap-folder) (global-set-key [?\C-c ?v ?m] 'vm-visit-folder) (global-set-key [?\C-c ?v ?v] 'mdw-auto-revert) + (global-set-key [?\C-c ?w ? ] 'mdw-designate-window) (global-set-key [?\C-c ?w ?b] 'w3m-bookmark-view) (global-set-key [?\C-c ?w ?c] 'mdw-set-frame-colour) (global-set-key [?\C-c ?w ?d] 'mdw-divvy-window) diff --git a/el/dot-emacs.el b/el/dot-emacs.el index 8b4f8f8..c7849f3 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -644,6 +644,34 @@ Evil key bindings are defined in `mdw-evil-keymap-keys'." ;; Some hacks to do with window placement. +(defvar mdw-designated-window nil + "The window chosen by `mdw-designate-window', or nil.") + +(defun mdw-designate-window (cancel) + "Use the selected window for the next pop-up buffer. +With a prefix argument, clear the designated window." + (interactive "P") + (cond (cancel + (setq mdw-designated-window nil) + (message "Window designation cleared.")) + (t + (setq mdw-designated-window (selected-window)) + (message "Window designated.")))) + +(defun mdw-display-buffer-in-designated-window (buffer alist) + "Display function to use the designated window." + (prog1 mdw-designated-window + (when mdw-designated-window + (select-window mdw-designated-window) + (switch-to-buffer buffer nil t)) + (setq mdw-designated-window nil))) + +(setq display-buffer-base-action + (let* ((action display-buffer-base-action) + (funcs (car action)) + (alist (cdr action))) + (cons (cons 'mdw-display-buffer-in-designated-window funcs) alist))) + (defun mdw-clobber-other-windows-showing-buffer (buffer-or-name) "Arrange that no windows on other frames are showing BUFFER-OR-NAME." (interactive "bBuffer: ")