diff options
| author | Lars Ingebrigtsen | 2021-10-19 05:07:51 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-10-19 05:07:51 +0200 |
| commit | f3aa648093a70c8ed15e764863a16fdf7126cdc4 (patch) | |
| tree | 5ae07cc4cdf169764733939c64052a5feb7b5c68 /src | |
| parent | 5c996471babfca2ac54591f7182d31fe7df151f0 (diff) | |
| download | emacs-f3aa648093a70c8ed15e764863a16fdf7126cdc4.tar.gz emacs-f3aa648093a70c8ed15e764863a16fdf7126cdc4.zip | |
Make `lookup-key' understand the new key sequence syntax
* src/keymap.c (possibly_translate_key_sequence): Factored out
into own function.
(Fdefine_key):
(Flookup_key): Use it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/keymap.c | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/keymap.c b/src/keymap.c index 60e736efc71..ca1dbe368ea 100644 --- a/src/keymap.c +++ b/src/keymap.c | |||
| @@ -1024,6 +1024,28 @@ is not copied. */) | |||
| 1024 | 1024 | ||
| 1025 | /* Simple Keymap mutators and accessors. */ | 1025 | /* Simple Keymap mutators and accessors. */ |
| 1026 | 1026 | ||
| 1027 | static Lisp_Object | ||
| 1028 | possibly_translate_key_sequence (Lisp_Object key, ptrdiff_t *length) | ||
| 1029 | { | ||
| 1030 | if (VECTORP (key) && ASIZE (key) == 1 && STRINGP (AREF (key, 0))) | ||
| 1031 | { | ||
| 1032 | /* KEY is on the ["C-c"] format, so translate to internal | ||
| 1033 | format. */ | ||
| 1034 | if (NILP (Ffboundp (Qkbd_valid_p))) | ||
| 1035 | xsignal2 (Qerror, | ||
| 1036 | build_string ("`kbd-valid-p' is not defined, so this syntax can't be used: %s"), | ||
| 1037 | key); | ||
| 1038 | if (NILP (call1 (Qkbd_valid_p, AREF (key, 0)))) | ||
| 1039 | xsignal2 (Qerror, build_string ("Invalid `kbd' syntax: %S"), key); | ||
| 1040 | key = call1 (Qkbd, AREF (key, 0)); | ||
| 1041 | *length = CHECK_VECTOR_OR_STRING (key); | ||
| 1042 | if (*length == 0) | ||
| 1043 | xsignal2 (Qerror, build_string ("Invalid `kbd' syntax: %S"), key); | ||
| 1044 | } | ||
| 1045 | |||
| 1046 | return key; | ||
| 1047 | } | ||
| 1048 | |||
| 1027 | /* GC is possible in this function if it autoloads a keymap. */ | 1049 | /* GC is possible in this function if it autoloads a keymap. */ |
| 1028 | 1050 | ||
| 1029 | DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0, | 1051 | DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0, |
| @@ -1084,21 +1106,7 @@ binding KEY to DEF is added at the front of KEYMAP. */) | |||
| 1084 | def = tmp; | 1106 | def = tmp; |
| 1085 | } | 1107 | } |
| 1086 | 1108 | ||
| 1087 | if (VECTORP (key) && ASIZE (key) == 1 && STRINGP (AREF (key, 0))) | 1109 | key = possibly_translate_key_sequence (key, &length); |
| 1088 | { | ||
| 1089 | /* KEY is on the ["C-c"] format, so translate to internal | ||
| 1090 | format. */ | ||
| 1091 | if (NILP (Ffboundp (Qkbd_valid_p))) | ||
| 1092 | xsignal2 (Qerror, | ||
| 1093 | build_string ("`kbd-valid-p' is not defined, so this syntax can't be used: %s"), | ||
| 1094 | key); | ||
| 1095 | if (NILP (call1 (Qkbd_valid_p, AREF (key, 0)))) | ||
| 1096 | xsignal2 (Qerror, build_string ("Invalid `kbd' syntax: %S"), key); | ||
| 1097 | key = call1 (Qkbd, AREF (key, 0)); | ||
| 1098 | length = CHECK_VECTOR_OR_STRING (key); | ||
| 1099 | if (length == 0) | ||
| 1100 | xsignal2 (Qerror, build_string ("Invalid `kbd' syntax: %S"), key); | ||
| 1101 | } | ||
| 1102 | 1110 | ||
| 1103 | ptrdiff_t idx = 0; | 1111 | ptrdiff_t idx = 0; |
| 1104 | while (1) | 1112 | while (1) |
| @@ -1229,6 +1237,8 @@ recognize the default bindings, just as `read-key-sequence' does. */) | |||
| 1229 | if (length == 0) | 1237 | if (length == 0) |
| 1230 | return keymap; | 1238 | return keymap; |
| 1231 | 1239 | ||
| 1240 | key = possibly_translate_key_sequence (key, &length); | ||
| 1241 | |||
| 1232 | ptrdiff_t idx = 0; | 1242 | ptrdiff_t idx = 0; |
| 1233 | while (1) | 1243 | while (1) |
| 1234 | { | 1244 | { |