\f
/* Simple Keymap mutators and accessors. */
+static Lisp_Object
+possibly_translate_key_sequence (Lisp_Object key, ptrdiff_t *length)
+{
+ if (VECTORP (key) && ASIZE (key) == 1 && STRINGP (AREF (key, 0)))
+ {
+ /* KEY is on the ["C-c"] format, so translate to internal
+ format. */
+ if (NILP (Ffboundp (Qkbd_valid_p)))
+ xsignal2 (Qerror,
+ build_string ("`kbd-valid-p' is not defined, so this syntax can't be used: %s"),
+ key);
+ if (NILP (call1 (Qkbd_valid_p, AREF (key, 0))))
+ xsignal2 (Qerror, build_string ("Invalid `kbd' syntax: %S"), key);
+ key = call1 (Qkbd, AREF (key, 0));
+ *length = CHECK_VECTOR_OR_STRING (key);
+ if (*length == 0)
+ xsignal2 (Qerror, build_string ("Invalid `kbd' syntax: %S"), key);
+ }
+
+ return key;
+}
+
/* GC is possible in this function if it autoloads a keymap. */
DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0,
def = tmp;
}
- if (VECTORP (key) && ASIZE (key) == 1 && STRINGP (AREF (key, 0)))
- {
- /* KEY is on the ["C-c"] format, so translate to internal
- format. */
- if (NILP (Ffboundp (Qkbd_valid_p)))
- xsignal2 (Qerror,
- build_string ("`kbd-valid-p' is not defined, so this syntax can't be used: %s"),
- key);
- if (NILP (call1 (Qkbd_valid_p, AREF (key, 0))))
- xsignal2 (Qerror, build_string ("Invalid `kbd' syntax: %S"), key);
- key = call1 (Qkbd, AREF (key, 0));
- length = CHECK_VECTOR_OR_STRING (key);
- if (length == 0)
- xsignal2 (Qerror, build_string ("Invalid `kbd' syntax: %S"), key);
- }
+ key = possibly_translate_key_sequence (key, &length);
ptrdiff_t idx = 0;
while (1)
if (length == 0)
return keymap;
+ key = possibly_translate_key_sequence (key, &length);
+
ptrdiff_t idx = 0;
while (1)
{
(should (equal (single-key-description 'C-s-home)
"C-s-<home>")))
+(ert-deftest keymap-test-lookups ()
+ (should (eq (lookup-key (current-global-map) "\C-x\C-f") 'find-file))
+ (should (eq (lookup-key (current-global-map) [(control x) (control f)])
+ 'find-file))
+ (should (eq (lookup-key (current-global-map) ["C-x C-f"]) 'find-file))
+ (should (eq (lookup-key (current-global-map) [?\C-x ?\C-f]) 'find-file)))
+
(provide 'keymap-tests)
;;; keymap-tests.el ends here