Emacs window management tweaking
I didn’t sleep well last night (it was too hot and humid for what I’m used to), so as a way to quiet my brain down, I turned to Emacs tweaking as always. This time, something that’s been driving me nuts for a while: Emacs' way of managing windows.
By default, Emacs' usage of windows doesn’t make sense to me. New windows open in seemingly random places, and modes that are supposed to help with the current buffer (like help for example) start out of focus, meaning you have to switch to them (C-x b
) to scroll and read. When using several windows, this mess can quickly get out of hand.
To organize Emacs windows the way I want them to, I need to play around with display-buffer-alist
. By default, its value is nil
— meaning Emacs does what it does by default.
Micky has a good article explaining how Emacs prioritizes its windows by default and how display-buffer-alist
works, while Port has a helpful visual tutorial with examples.
I like how Prot explains that an alist is a “list of lists,” so what we’re working with here is giving Emacs lists as guides as to how to display its windows. The way it works for each list is basically:
- Define what is the “trigger” for a rule
- Define what guides or functions to follow for that trigger
- Define additional parameters (additional “tweaks”)
Here’s what I have so far:
(setq display-buffer-alist
'(
;; trigger: when the major mode is dired-mode:
((derived-mode . dired-mode)
;; guides: show me the above (dired) in a side window:
(display-buffer-in-side-window)
;; paramaters: what side? right. How wide? .80:
(side . right)
(window-width . 80)
))
)
This works, but it has a couple of functional problems.
-
In general, I prefer Dired to open to the right. I want to open another Dired window. In that case, I want it to open under the existing dired window. I usually open two Dired windows when I work with dwim for file functions, like renaming/moving files from one place to another. I doubt I’ll need to open three dired windows, but if I do, the idea should be the same: keep opening more Dired windows under the existing Dired windows.
-
The width is fixed, and I find .80 to be OK, but sometimes, this is too much, especially when the overall Emacs window (the frame) is already small. If I call Dired, I want Emacs to increase the size of the entire frame if it’s under a certain size.
-
I want to make sure Dired doesn’t delete or occupy other existing Dired windows, since that defeats the purpose of working with dwim. Each Dired window should have its own window, as I stated above: the first to the right, and the rest under the existing ones.
I’ve already been watching videos and reading for an hour and a half, and I’m getting sleepy again, so I think I’ll attempt to fill my sleep bank some more.