1

Attempting to bind M-ESC M-ESC in the global map to a command:

(global-set-key (kbd "M-ESC M-ESC") #'my-command)

results in the following:

Debugger entered--Lisp error: (error "Key sequence M-ESC M-ESC starts with non-prefix key M-ESC ESC")

I supposed this is due to meta-prefix-char being ESC by default, so M-<char> gets translated into ESC-<char>. Therefore, M-ESC M-ESC is ESC ESC ESC ESC, and ESC ESC ESC is already bound to keyboard-escape-quit.

Is there a safe way to separate the Meta and ESC keys so a binding like M-ESC M-ESC is possible? If so, how?

  • @Drew What do you mean? – Tianxiang Xiong Feb 24 '17 at 18:38
  • Done. It's simple: (global-set-key (kbd "M-ESC M-ESC") #'my-command) – Tianxiang Xiong Feb 24 '17 at 23:32
  • This is similar to trying to bind (kbd "ESC ESC ESC ESC"), which tells you that ESC ESC ESC is not a prefix key. It's not a prefix key because it is not bound to a keymap. See (elisp) Prefix Keys. – Drew Feb 24 '17 at 23:42
2

It's not a prefix key because it is not bound to a keymap. See (elisp) Prefix Keys.

Try this:

(define-prefix-command 'foo)
(global-set-key (kbd "M-ESC") 'foo)
(global-set-key (kbd "M-ESC M-ESC") 'forward-char)
  • Cool, but now ESC ESC ESC is no longer bound to keyboard-escape-quit. – Tianxiang Xiong Feb 24 '17 at 23:57
  • Yes. And that's one reason that we don't recommend that you bind ESC in such ways. ESC is kind of hard-coded to do some pretty important things in Emacs. So while you can rebind things you probably don't necessarily want to do it. – Drew Feb 24 '17 at 23:59
  • Does meta-prefix-char have a role to play here? Maybe changing it to something else will allow us to bind M-ESC to a prefix map and still keep ESC ESC ESC? – Tianxiang Xiong Feb 25 '17 at 0:49
  • Yes, it will, but I don't recommend that. You can certainly try it. But be aware of the consequences. See (elisp) Functions for Key Lookup. – Drew Feb 25 '17 at 1:36
0

Is there a safe way to separate the Meta and ESC keys so a binding like M-ESC M-ESC is possible? If so, how?

You could bind <escape> instead:

(define-key global-map (kbd "M-<escape>  M-<escape>") #'my-command)

This only works in a GUI frame though.

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.