2

Some commands use Emacs' minibuffer to prompt for input.

I occasionally do something which moves the focus to another window and away from the minibuffer. In these cases I cycle windows with C-x o until I regain focus on the echo area or point and click with the mouse.

What's the Emacs command to immediately focus the minibuffer or prompt?

Writing the Elisp to automate this action should be trivial but I'd rather use a built-in command or function if one's available.

  • On selecting window, there is nothing special about minibuffer's window. If you are not satisfied with C-x o or the mouse, you should consider tweaking your window-selecting workflow, such as bind a short key or try ace-window. – xuchunyang Jun 27 '18 at 21:07
  • Thanks, I used ace-window for a while and it was great! I'm using windmove with good results. I'll return to ace eventually but now I need a vanilla configuration which can be shared across many different hosts. – metaturso Jun 27 '18 at 21:37
3

I prefer to select a window in a particular direction -- that way, I don't have to "cycle" through too many windows. That being said, here is a repost from Emacs wiki -- "The following command returns the focus to the minibuffer, no matter which window is currently selected.":   https://www.emacswiki.org/emacs/MiniBuffer#minibuffer

(defun switch-to-minibuffer ()
  "Switch to minibuffer window."
  (interactive)
  (if (active-minibuffer-window)
      (select-window (active-minibuffer-window))
    (error "Minibuffer is not active")))

(global-set-key "\C-co" 'switch-to-minibuffer) ;; Bind to `C-c o'
  • Well now that spoiled all the fun! I thought of using minibuffer-prompt but I suppose it won't make much difference since I'll bind it to a key. – metaturso Jun 27 '18 at 21:46
  • Actually, it selects the window, but it doesn't necessarily put the input focus there. If the focus has switched to another frame where that minibuffer is not present (e.g. no minibuffer window, because another frame has that frame's minibuffer window) then it won't be focused. IOW, you may need to use select-frame-set-input-focus. – Drew Jun 27 '18 at 22:12
  • I wrote my own DWIM other-window-or-prompt gist.github.com/metaturso/0ce41b515fc32718b5c0ea3cf75d8269. Feel free to add comments to the gist. Honestly I prefer my own version over Emacs Wiki's. – metaturso Jun 27 '18 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.