From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: What is a safe way to bind ESC to quit? Date: Tue, 06 Apr 2021 13:14:04 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11482"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:r/+/k0fYer4A5z6NLe98J1PghAk= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 06 19:17:25 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lTpKO-0002pv-HC for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 06 Apr 2021 19:17:24 +0200 Original-Received: from localhost ([::1]:51620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lTpKN-0007Vc-Ij for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 06 Apr 2021 13:17:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lTpHK-0006dx-RK for help-gnu-emacs@gnu.org; Tue, 06 Apr 2021 13:14:14 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]:42466) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lTpHJ-0007Z6-B6 for help-gnu-emacs@gnu.org; Tue, 06 Apr 2021 13:14:14 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lTpHG-0009Dy-PS for help-gnu-emacs@gnu.org; Tue, 06 Apr 2021 19:14:10 +0200 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:128868 Archived-At: > (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