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)

Drew
  • 75,699
  • 9
  • 109
  • 225
John Doe
  • 159
  • 6

1 Answers1

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.

Drew
  • 75,699
  • 9
  • 109
  • 225