5

How can I tell emacs that one key press of <f12> should terminate the minibuffer, like C-g does by default?

I tried in scratch buffer:

(global-set-key (kbd "<f12>") 'keyboard-quit)

but if I go M-x woopswrongcommand <f12> i'm still stuck in the minibuffer.

(I tested this on emacs 27, started with -Q)

1 Answer 1

5

You want to bind keys for the minibuffer in a minibuffer keymap. If you want a key to work in all minibuffers then bind it in keymap minibuffer-local-map:

(define-key minibuffer-local-map (kbd "<f12>") 'abort-recursive-edit)

And C-g in the minibuffer is bound to abort-recursive-edit, not keyboard-quit. So if you want to quit the minibuffer then bind your key to abort-recursive-edit.

You can easily see this binding of C-g and other minibuffer keys if you either have an Emacs 28 prerelease build or you use library help-fns+.el. Those give you command describe-keymap, which help-fns+.el binds to C-h M-k.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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