[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Ctrl-[ ?
From: |
Stefan Monnier |
Subject: |
Re: Ctrl-[ ? |
Date: |
Fri, 07 Jun 2019 18:04:11 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
> 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
- Re: Ctrl-[ ?, (continued)
- Re: Ctrl-[ ?, Jean-Christophe Helary, 2019/06/06
- Re: Ctrl-[ ?, Stefan Monnier, 2019/06/06
- Re: Ctrl-[ ?, Jean-Christophe Helary, 2019/06/06
- Re: Ctrl-[ ?, Noam Postavsky, 2019/06/06
- Re: Ctrl-[ ?, Jean-Christophe Helary, 2019/06/06
- Re: Ctrl-[ ?, Noam Postavsky, 2019/06/06
- Re: Ctrl-[ ?, Jean-Christophe Helary, 2019/06/06
- Re: Ctrl-[ ?, Eli Zaretskii, 2019/06/07
- Re: Ctrl-[ ?, Noam Postavsky, 2019/06/07
- Re: Ctrl-[ ?, Jean-Christophe Helary, 2019/06/07
- Re: Ctrl-[ ?,
Stefan Monnier <=
- Re: Ctrl-[ ?, Eli Zaretskii, 2019/06/08
- Re: Ctrl-[ ?, Stefan Monnier, 2019/06/08
Re: Ctrl-[ ?, Emanuel Berg, 2019/06/06
- Re: Ctrl-[ ?, Jean-Christophe Helary, 2019/06/07
- Re: Ctrl-[ ?, Eli Zaretskii, 2019/06/07
- Re: Ctrl-[ ?, Óscar Fuentes, 2019/06/07
- Re: Ctrl-[ ?, Eli Zaretskii, 2019/06/07
- Re: Ctrl-[ ?, Jean-Christophe Helary, 2019/06/07