all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* What is a safe way to bind ESC to quit?
@ 2021-04-06 16:44 scame via Users list for the GNU Emacs text editor
  2021-04-06 17:14 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: scame via Users list for the GNU Emacs text editor @ 2021-04-06 16:44 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

I have no use for ESC as a prefix key, I don't use Emacs on terminal and
ESC ESC ESC never worked for me when emacs was hung, so I
want to use ESC for what C-g does.

I googled it and found this:

(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?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: What is a safe way to bind ESC to quit?
  2021-04-06 16:44 What is a safe way to bind ESC to quit? scame via Users list for the GNU Emacs text editor
@ 2021-04-06 17:14 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2021-04-06 17:14 UTC (permalink / raw)
  To: help-gnu-emacs

> (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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-06 17:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-06 16:44 What is a safe way to bind ESC to quit? scame via Users list for the GNU Emacs text editor
2021-04-06 17:14 ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.