unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: What is a safe way to bind ESC to quit?
Date: Tue, 06 Apr 2021 13:14:04 -0400	[thread overview]
Message-ID: <jwvczv7e4c7.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: q0Ro3W-kRav4NflGhC_sOeZMCDs0Eqs80TdP17y1-E4uRn9BxiFqGdBnPyaHsTc4n7soixZtS9goG2gKFz_gyDvTMDlXuyxyAdjoHouXc0k=@protonmail.com

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




      reply	other threads:[~2021-04-06 17:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvczv7e4c7.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).