1

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))
user27075
  • 488
  • 3
  • 11
  • What if the selected window is the bottom window? – phils Apr 26 '22 at 08:20
  • @phils then i would like it to be used. the idea is that my bottom corner window is for temp stuff, and i don't want my two full-height windows to be taken up by temp stuff. – user27075 Apr 26 '22 at 09:26
  • Have you inverted "vertically" and "horizontally" in your question? (Check the actual command names.) – phils Apr 26 '22 at 09:38
  • FWIW I suspect the answer is to write a custom display action. You can use the code for any somewhat-similar existing action as a starting point. – phils Apr 26 '22 at 09:41
  • @phils wow yes i have inverted them, damn and i thought i was really really trying to bend my mind to emacs terminology – user27075 Apr 26 '22 at 09:54
  • All good -- those particular names are quite ambiguous (I always have to double-check them). I suggest you edit your question text to correct them, though. – phils Apr 26 '22 at 18:56

0 Answers0