From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Ctrl-[ ? Date: Fri, 07 Jun 2019 18:04:11 -0400 Message-ID: References: <08AC8151-5911-40FA-8B20-818B839D00AB@traduction-libre.org> <20190606134205.GB14057@tuxteam.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="223831"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jun 08 00:23:40 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hZNGt-000w4W-2X for geh-help-gnu-emacs@m.gmane.org; Sat, 08 Jun 2019 00:23:39 +0200 Original-Received: from localhost ([::1]:53794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hZNGr-0004S7-HU for geh-help-gnu-emacs@m.gmane.org; Fri, 07 Jun 2019 18:23:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49825) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hZMyP-0008Rz-0C for help-gnu-emacs@gnu.org; Fri, 07 Jun 2019 18:04:34 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hZMyM-0006cD-Dw for help-gnu-emacs@gnu.org; Fri, 07 Jun 2019 18:04:32 -0400 Original-Received: from [195.159.176.226] (port=53472 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hZMyK-0006VB-CL for help-gnu-emacs@gnu.org; Fri, 07 Jun 2019 18:04:30 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1hZMyA-000b7o-1W for help-gnu-emacs@gnu.org; Sat, 08 Jun 2019 00:04:18 +0200 X-Injected-Via-Gmane: http://gmane.org/ Cancel-Lock: sha1:IfjgKMc7pi2XW975EN0vZfRhE+g= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 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.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:120822 Archived-At: > See also https://emacs.stackexchange.com/questions/17509 where I show > some other possibility (tho in the context of `tab` vs `C-i` vs TAB, but > which is exactly the same problem). FWIW, the patch below introduces a much more clear separation between C-i and TAB and other such things, by distinguishing "control modifier plus a char" events from the 32 "ASCII control chars". It introduces various questions about how to print and read those control thingies in Elisp and in user interactions. But at least, for a quick 30 seconds test, it seems to handle the simple cases. Stefan diff --git a/lisp/bindings.el b/lisp/bindings.el index 36044ab65d..22af38aeef 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -822,7 +822,7 @@ right-char see." (interactive "^p") (if visual-order-cursor-movement - (dotimes (i (if (numberp n) (abs n) 1)) + (dotimes (_ (if (numberp n) (abs n) 1)) (move-point-visually (if (and (numberp n) (< n 0)) -1 1))) (if (eq (current-bidi-paragraph-direction) 'left-to-right) (forward-char n) @@ -840,7 +840,7 @@ left-char see." (interactive "^p") (if visual-order-cursor-movement - (dotimes (i (if (numberp n) (abs n) 1)) + (dotimes (_ (if (numberp n) (abs n) 1)) (move-point-visually (if (and (numberp n) (< n 0)) 1 -1))) (if (eq (current-bidi-paragraph-direction) 'left-to-right) (backward-char n) @@ -1430,6 +1430,14 @@ ctl-x-4-map (define-key special-event-map [sigusr1] 'ignore) (define-key special-event-map [sigusr2] 'ignore) +;;;; For merge-ASCII-control-and-CTRL-modifier +(dotimes (ascii-ctrl 32) + (let* ((PLAIN-ctrl (+ 64 ascii-ctrl (ash 1 26)))) + (dolist (mod (list 0 (ash 1 27))) ;With or without meta + (dolist (off (list 0 32)) ;Upper and lowercase + (define-key function-key-map (vector (+ PLAIN-ctrl off mod)) + (vector (+ ascii-ctrl mod))))))) + ;; Don't look for autoload cookies in this file. ;; Local Variables: ;; no-update-autoloads: t diff --git a/lisp/simple.el b/lisp/simple.el index 35022efdf4..184927c928 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -8817,7 +8817,7 @@ event-apply-modifier LSHIFTBY is the numeric value of this modifier, in keyboard events. PREFIX is the string that represents this modifier in an event type symbol." (if (numberp event) - (cond ((eq symbol 'control) + (cond ((and (eq symbol 'control) merge-ASCII-control-and-CTRL-modifier) (if (<= 64 (upcase event) 95) (- (upcase event) 64) (logior (ash 1 lshiftby) event))) diff --git a/src/keyboard.c b/src/keyboard.c index 35557e226c..9c92a7ccfd 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -2009,7 +2009,7 @@ make_ctrl_char (int c) /* Save the upper bits here. */ int upper = c & ~0177; - if (! ASCII_CHAR_P (c)) + if (! ASCII_CHAR_P (c) || !merge_ascii_control_and_ctrl_modifier) return c |= ctrl_modifier; c &= 0177; @@ -11811,6 +11811,11 @@ This inhibits recording input events for the purposes of keyboard macros, dribble file, and `recent-keys'. Internal use only. */); + DEFVAR_BOOL ("merge-ASCII-control-and-CTRL-modifier", + merge_ascii_control_and_ctrl_modifier, + doc: /* When non-nil, C-i is the same as TAB. */); + merge_ascii_control_and_ctrl_modifier = false; + pdumper_do_now_and_after_load (syms_of_keyboard_for_pdumper); } diff --git a/src/keymap.c b/src/keymap.c index 78cd7d2990..16afdefab0 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -2130,8 +2130,9 @@ push_key_description (EMACS_INT ch, char *p) c -= alt_modifier; } if ((c & ctrl_modifier) != 0 - || (c2 < ' ' && c2 != 27 && c2 != '\t' && c2 != Ctl ('M')) - || tab_as_ci) + || (merge_ascii_control_and_ctrl_modifier + && ((c2 < ' ' && c2 != 27 && c2 != '\t' && c2 != Ctl ('M')) + || tab_as_ci))) { *p++ = 'C'; *p++ = '-'; @@ -2169,11 +2170,7 @@ push_key_description (EMACS_INT ch, char *p) *p++ = 'S'; *p++ = 'C'; } - else if (tab_as_ci) - { - *p++ = 'i'; - } - else if (c == '\t') + else if (c == '\t' && merge_ascii_control_and_ctrl_modifier) { *p++ = 'T'; *p++ = 'A'; @@ -2187,7 +2184,11 @@ push_key_description (EMACS_INT ch, char *p) } else { - /* `C-' already added above. */ + if (!merge_ascii_control_and_ctrl_modifier) + { + *p++ = '\\'; + *p++ = '^'; + } if (c > 0 && c <= Ctl ('Z')) *p++ = c + 0140; else