1

I have M-x (and also my menu key) mapped to the command helm-M-x.

How to write an elisp function or how to configure emacs so that M-x (and the menu key) performs as C-g when the minibuffer is open.

the goal is then to make M-x (and the menu key) a toggle on/off feature.

2
  • I didn't even know that existed. I assume this is disabled by default. So let's say I don't need this feature. Now why do I want this : I guess it feels natural to open and "close" something with the same button. and I find myself too often trying to C-g (which I don't find ergonomic).
    – VinD
    Jan 15 '20 at 23:57
  • Good answer. And thanks for putting that motivation in the question itself.
    – Drew
    Jan 16 '20 at 0:26
1

For reasons @Drew pointed out, this is not necessarily a good idea. However, if you really want to do it, you can simply bind exit-minibuffer to M-x in the minibuffer-local-map which is the keymap used when in the minibuffer.

You can find information on minibuffer key maps here: https://www.gnu.org/software/emacs/manual/html_node/emacs/Minibuffer-Maps.html

(define-key minibuffer-local-map (kbd "M-x") 'exit-minibuffer)
2
  • By the way, is there a symbol (variable/function) to use to know if the mini buffer is currently open or not ? (sorry but I'm really a beginner with emacs)
    – VinD
    Jan 16 '20 at 0:05
  • OP: Function active-minibuffer-window.
    – Drew
    Jan 16 '20 at 0:28

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.