Subject: bug#61149: 29.0.60; keymap-local-set rejects key sequences

From: Stephen Berman <[email-masked]>
Date: Sun, 29 Jan 2023 15:35:22 +0100

On Sun, 29 Jan 2023 15:44:44 +0200 Eli Zaretskii <[email-masked]> wrote:

> To reproduce:
>
>   emacs -Q
>   M-x keymap-local-set
>   C-c .
>   forward-line RET
>
> Observe the error message:
>
>   [3 46] is not a valid key definition; see ‘key-valid-p’
>
> (The error message comes from keymap--check.)
>
> To type the key sequence, I actually pressed Ctrl and typed 'c', then
> released Ctrl and typed '.'.  Isn't that what one is supposed to use?
>
> So the above basically makes keymap-local-set useless, or am I missing
> something?  The following does work:
>
>   M-: (keymap-local-set "C-c ." 'forward-line) RET
>
> However, I could find no way of typing the string "C-c ." at the
> prompt of keymap-local-set.

This patch seems to DTRT:

diff --git a/lisp/keymap.el b/lisp/keymap.el
index 791221f2459..9643dce5f9c 100644
--- a/lisp/keymap.el
+++ b/lisp/keymap.el
@@ -95,7 +95,8 @@ keymap-local-set
 cases is shared with all other buffers in the same major mode."
   (declare (compiler-macro (lambda (form) (keymap--compile-check key) form)))
   (interactive "KSet key locally: \nCSet key %s locally to command: ")
-  (let ((map (current-local-map)))
+  (let ((map (current-local-map))
+	(key (key-description key)))
     (unless map
       (use-local-map (setq map (make-sparse-keymap))))
     (keymap-set map key command)))

Steve Berman