[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: master f3aa648: Make `lookup-key' understand the new key sequence sy
From: |
Stefan Monnier |
Subject: |
Re: master f3aa648: Make `lookup-key' understand the new key sequence syntax |
Date: |
Tue, 19 Oct 2021 08:45:37 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
I think your `possibly_translate_key_sequence` should be extended to
cover the XEmacs format as well, And it should be exported to ELisp.
And I'd argue it should also convert strings to vectors.
Oh and also convert [M-C-next] to [C-M-next].
WDYT?
Stefan
> +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,
> @@ -1084,21 +1106,7 @@ binding KEY to DEF is added at the front of KEYMAP.
> */)
> 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)
> @@ -1229,6 +1237,8 @@ recognize the default bindings, just as
> `read-key-sequence' does. */)
> if (length == 0)
> return keymap;
>
> + key = possibly_translate_key_sequence (key, &length);
> +
> ptrdiff_t idx = 0;
> while (1)
> {
> diff --git a/test/src/keymap-tests.el b/test/src/keymap-tests.el
> index 68b42c3..13f47b4 100644
> --- a/test/src/keymap-tests.el
> +++ b/test/src/keymap-tests.el
> @@ -317,6 +317,13 @@ g .. h foo
> (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
- Re: master f3aa648: Make `lookup-key' understand the new key sequence syntax,
Stefan Monnier <=