embark
embark copied to clipboard
Keep the focus in the minibuffer for non-exiting actions
When I am pressing C-. o on a buffer, the buffer opens in another window and the focus moves there. I would prefer if the focus stays in the minibuffer. Is the current behavior intentional?
It is intentional. :( See #152, particularly this comment and the linked commit. We can discuss this again with @jakanakaevangeli who suggested that behavior in the first place.
To be explicit the behavior is as follows: that if the action selects a different window from the window it is called in, then that selected stays selected after embark-act, otherwise if the action sticks to the target window, then the calling window (the minibuffer usually) keeps focus.
I guess this means you can work around this undesired behavior by simply rebinding o from find-file-other-window to something like (lambda (file) (interactive "fFile: ") (display-buffer (find-file-noselect file))), which does not select the window.
Ah okay, I see. If the action selects it should keep its selection. I am actually unsure which behavior feels more consistent if one considers all the actions. Keeping the focus always in the minibuffer is consistent. Maybe this should be a configuration option, I don't know.
The workaround you propose is good, but I like it so much that Embark just reuses the plain old stuff we already have :)
Oh, I wrote the work around thinking you meant o for files, but rereading I see you meant buffers. Even easier then: rebind o from switch-to-buffer-other-window to just display-buffer (which is a command, perhaps surprisingly: I expected it to be a non-interactive function).
And we can of course discuss if a configuration variable is appropriate to pick between the current behavior and the "always restore focus" behavior. Would a global choice be enough or would it need to finer-grained, per action?
I also expected display-buffer to be a function!? But does it always do the right thing? I mean display-buffer is configurable so it could do anything?
Would a global choice be enough or would it need to finer-grained, per action?
Global is good enough since on the per action level we can simply replace the action with something else.
display-buffer is not only a command, it even has a default keybinding, C-x 4 C-o! 😮
I also expected display-buffer to be a function!? But does it always do the right thing? I mean display-buffer is configurable so it could do anything?
Right, but internally switch-to-window-other-buffer and find-file-other-buffer probably just wind up calling display-buffer indirectly, so whatever display-buffer does is what we are used to.
As I see it, there are four cases to consider:
- Non-quitting embark-act from the minibuffer
- Quitting embark-act from the minibuffer
- embark-act from an embark-collect buffer
- embark-act from an ordinary buffer
To give my opinion, I personally feel like for 2 - 4 the current behaviour is fine. You can choose between display-buffer and switch-to-buffer-other-window, like choosing between C-o and o in a dired buffer, I think that is nice.
As for 1), I kind of want to keep it as is, to keep it consistent with 2 - 4.
I didn't know about C-o in dired buffers! I'm glad you mentioned it.
I would like to second the desire for a global configuration variable that keeps the focus on the minibuffer by default. It's useful for using embark-act without quitting as a preview. Another option could be to create an embark-preview function that does this, which wouldn't break the focus semantics in all the different options.