I am trying to tame display-buffer
to achieve the following behavior: if I have a frame split once horizontally and then run a function that creates a third window (like help, magit, or similar) I would like it to appear below the selected window only, not in the other existing window, and not across the bottom of the whole frame. But if a third window has already been added to the layout, I would like emacs to reuse it (even if a different function is called later), rather than splitting below it again.
I have tried customizing display-buffer-base-action
as follows, to no avail:
(customize-set-variable
'display-buffer-base-action
'((display-buffer-reuse-window display-buffer-below-selected)
This splits below, but doesn't always reuse a window if it already exists. If i run another function that creates a window (like call a second help function), my third window is split again, creating 2 windows that are 1/4 of frame height.
display-buffer-at-bottom
is also not what I want, as that displays a window across the bottom of the whole frame.
i also tried setting an action alist like so, hoping to prevent further splitting:
(customize-set-variable
'display-buffer-base-action
'((display-buffer-reuse-window display-buffer-below-selected)
(window-min-height . 4)))
This has no effect, so maybe I'm using it wrong.
Basically using below-selected
at all seems to take over too much. Is there a way to only split vertically once, then prefer reusing the window, regardless of whether the function called runs a different mode or not? I thought reuse-window
would take precedence if it precedes below-selected
in the function list.
I also tried setting display-buffer-alist
, matching buffer names to the same two action functions, but in that case, a window will still be split again if the function I call creates a buffer with a different name/mode.
To date I have only ever gotten around this by using two frames rather one split frame, as then all splitting below just works with no customization.
EDIT: the following code from https://e17i.github.io/articles-emacs-display-1/ almost does the job (though it is unclear why to me why it would ever split below):
custom-set-variables
'(display-buffer-base-action
'((display-buffer--maybe-same-window display-buffer-reuse-window display-buffer--maybe-pop-up-frame-or-window display-buffer-in-previous-window display-buffer-below-selected display-buffer-at-bottom display-buffer-pop-up-frame)))
'(window-min-height 18)
'(window-min-width 40))