[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What is a safe way to bind ESC to quit?
From: |
Stefan Monnier |
Subject: |
Re: What is a safe way to bind ESC to quit? |
Date: |
Tue, 06 Apr 2021 13:14:04 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> (define-key key-translation-map (kbd "ESC") (kbd "C-g"))
>
> It seems to work, but I'm curious: is this the best way to do it?
You might want to try
(define-key input-decode-map [escape] [?\C-g])
Which will make C-[ (aka ESC) free for other uses.
(`escape` is the GUI event which is remapped to ESC by
`function-key-map` when no binding is found for it).
Also, the above won't help you interrupt code with `escape` while
it's running. You might also want to check `set-quit-char` for that.
And I suspect that after you've investigated all this, you may want to
`M-x report-emacs-bug` to complain about the limitations of what is
currently possible.
[ Tho most likely, these will just boil down to the comment found in
src/keyboard.c:
/* Character that causes a quit. Normally C-g.
If we are running on an ordinary terminal, this must be an ordinary
ASCII char, since we want to make it our interrupt character.
If we are not running on an ordinary terminal, it still needs to be
an ordinary ASCII char. This character needs to be recognized in
the input interrupt handler. At this point, the keystroke is
represented as a struct input_event, while the desired quit
character is specified as a lispy event. The mapping from struct
input_events to lispy events cannot run in an interrupt handler,
and the reverse mapping is difficult for anything but ASCII
keystrokes.
FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
ASCII character. */
int quit_char;
]
Stefan