embark icon indicating copy to clipboard operation
embark copied to clipboard

Keep the focus in the minibuffer for non-exiting actions

Open minad opened this issue 4 years ago • 14 comments

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?

minad avatar Apr 29 '21 23:04 minad

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.

oantolin avatar Apr 29 '21 23:04 oantolin

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.

oantolin avatar Apr 29 '21 23:04 oantolin

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.

oantolin avatar Apr 29 '21 23:04 oantolin

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.

minad avatar Apr 29 '21 23:04 minad

The workaround you propose is good, but I like it so much that Embark just reuses the plain old stuff we already have :)

minad avatar Apr 29 '21 23:04 minad

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).

oantolin avatar Apr 29 '21 23:04 oantolin

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?

oantolin avatar Apr 29 '21 23:04 oantolin

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?

minad avatar Apr 29 '21 23:04 minad

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.

minad avatar Apr 29 '21 23:04 minad

display-buffer is not only a command, it even has a default keybinding, C-x 4 C-o! 😮

oantolin avatar Apr 29 '21 23:04 oantolin

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.

oantolin avatar Apr 29 '21 23:04 oantolin

As I see it, there are four cases to consider:

  1. Non-quitting embark-act from the minibuffer
  2. Quitting embark-act from the minibuffer
  3. embark-act from an embark-collect buffer
  4. 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.

jakanakaevangeli avatar Apr 30 '21 00:04 jakanakaevangeli

I didn't know about C-o in dired buffers! I'm glad you mentioned it.

oantolin avatar Apr 30 '21 00:04 oantolin

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.

iyefrat avatar May 07 '21 20:05 iyefrat