reddit / emacs

Wrangling windows

quasi_qua_quasi · 2022-08-24 05:58
I find it pretty unintuitive how magit, vterm, rg, and other commands that want to open a new window will interact with a multi-window setup. Sometimes they'll use an existing window, sometimes they'll make a new one. I prefer having things be predictable: terminals always go *here*, search results go *there*, and so on. I was looking for ways to tame this, and I found [purpose](https://github.com/bmag/emacs-purpose), [popper](https://github.com/karthink/popper), [shackle](https://depp.brause.cc/shackle/), and of course, directly hacking on `display-buffer-alist`. I also found `winner-undo`, which is nice, but I'd like to prevent things from getting messy rather than letting them get bad and then undoing them. And there doesn't seem to be a 'modern' clean approach; i.e., there's no window management equivalent of corfu. (Maybe this is an excuse for me to get my toes wet in actual emacs package development; purpose is probably the closest, but I don't like how it works by advising everything...)
nv-elisp · 2022-08-24 06:27
> And there doesn't seem to be a 'modern' clean approach Be more specific about what you mean by modern and clean. What features are missing from the packages you've listed? Have you tried them all?
draxil · 2022-08-24 06:46
I found shackle to solve this nicely. Perhaps you should describe how the existing tools don't meet your need more clearly?
_viz_ · 2022-08-24 06:52
I've come to the conclusion that " modern " is a convenient fallback term people use when things don't go their way.
quasi_qua_quasi · 2022-08-24 06:58
- shackle requires me to explicitly write rules, as opposed to purpose's e.g. `purpose-toggle-window-purpose-dedicated` which I can keybind to tweak window management on the fly. - purpose hasn't had any commits in a year, and it seems to work by heavy use of advice as opposed to display-buffer-alist, which feels 'gross' in a vague indefinable way. - popper seeems to be focused on getting windows out of the way; some windows I might want to keep on screen. But this is also me asking what other people have used: I haven't actually *tried* any of these, and I just wanted to check if there was any overwhelming "oh yeah everyone uses X these days". By "modern" I maybe more meant "fits the general emacs style", using built-in features rather than reinventing the wheel, avoiding mutable global state where not necessary, nicely documented, and so on. cc /u/draxil
draxil · 2022-08-24 07:11
I see. I got by with shackle by having a default rule I liked (reusing the "other" window) and then a few rules to shackle things like vterm and my tests popup to a bottom window. I combine this with popper to get the lesser windows to go away / come back on an easy key-press. My setup is pretty light but does the trick enough for me not to care. Sounds like maybe you want a clean rewrite of purpose that actually sees maintenance? I must checkout purpose as I have never looked at it.
mickeyp · 2022-08-24 07:26
I've got an article coming out on this very subject Soon(tm). But for now, I'll say this: a lot of third-party packages are broken and do not handle windows properly. Many will happily call out to niche functions or forcibly set dedicated, etc. without asking first. **This is wrong**. But there is nothing you can do to prevent this --- even if you follow the rules. Modifying `display-buffer-alist` or `display-buffer-base-action` is the correct way for users to control buffer display and window rules, even if a coterie of packages (internal or external) don't listen.
quasi_qua_quasi · 2022-08-24 08:34
Please let me know when it's out! DM me, ping me if you post it here, whatever.
quasi_qua_quasi · 2022-08-24 08:35
Yeah, I was considering doing my own version of purpose (or maybe fork it). Though maybe i can just do something super lightweight like you said. It's not something worth spending a *lot* of time on, imo.
karthink · 2022-08-24 15:34
By default, Popper grudgingly installs a single rule in `display-buffer-alist`, but this is easy to disable with a flag. Poppper provides a quick way to bring up, cycle through and dismiss certain buffers, and it really doesn't want to be in the business of managing window placement. So it should work with any `display-buffer-alist` configuration, or with any package that handles window placement the correct way. I had a look at Purpose's code, and it seems like this behavior is something you can easily replicate with a good `display-buffer-alist` specification, or with Shackle.
HM0880 · 2022-08-24 15:54
I like this. "Beautiful web design" usually means "thin fonts, low contrast, and inefficient to navigate."
_viz_ · 2022-08-24 16:04
I think an emphasis on "horrible low contrast dark theme" is direly needed but YMMV.
karthink · 2022-08-24 18:00
On the flip side, I'm tired of raising issues on the use of `switch-to-buffer` in third-party packages, which completely bypasses `display-buffer-alist`. About half the bug reports I receive for Popper -- which fully respects `display-buffer` preferences -- involve the use of hardcoded `switch-to-buffer` calls in other packages, which I can't fix. (Asking the user to set `switch-to-buffer-obey-display-actions` usually breaks something else.) Honestly the package linter should issue a warning if it sees `switch-to-buffer` in package code. Even the documentation for the command suggests using `set-buffer` and `pop-to-buffer-same-window` in non-interactive contexts.
_oats · 2022-08-24 18:32
I am very much looking forward to this article!
nv-elisp · 2022-08-24 19:14
> By "modern" I maybe more meant "fits the general emacs style", using built-in features rather than reinventing the wheel, avoiding mutable global state where not necessary, nicely documented, and so on. I wouldn't go as far as to say there is a "general emacs style". There's tons of mutable global state in any given Emacs session. There are also packages which duplicate effort in slightly different ways. It's definitely not a "there's one way to do things" environment, and it's better for it. It encourages experimentation. There's a certain irony to saying "I wish these other packages would do things 'The Emacs Way', but they don't, so I guess I'll just write my own." Not saying you shouldn't, it just doesn't jibe with what you're describing.
rswgnu · 2022-08-25 00:18
If you use Hyperbole’s Action Key to display information, i.e. any kind of implicit or explicit link referent, like a filename in Dired, then it uses an option, hpath:display-where that lets you determine whether to use the selected window, another window, another frame or a new frame. This together with the keyboard-macro like automation of windows and frames that Hyperbole’s HyControl subsystem provides lets you control your display rapidly and efficiently however you like. It’s not new but it keeps on working.
quasi_qua_quasi · 2022-08-25 01:59
> There's tons of mutable global state in any given Emacs session. Yeah, fair. I guess that was more part of my "clean" adjective; I think it's fine to have some things be global, but the fact that match state is global is bizarre.
quasi_qua_quasi · 2022-08-25 01:59
Just advise it to check if it's interactive and fall back to set-buffer if not... (oh god /s)
quote-only-eeee · 2022-08-27 00:56
Seconding this. Shackle is an incredibly well-working solution to this problem. The rules are very easy to define, and it makes pop-up windows 100% predictable.