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

From: Stephen Berman <[email-masked]>
Date: Mon, 30 Jan 2023 09:46:49 +0100

On Mon, 30 Jan 2023 08:59:03 +0100 Robert Pluim <[email-masked]> wrote:

>>>>>> On Sun, 29 Jan 2023 16:28:44 +0100, Stephen Berman
> <[email-masked]> said:
>
>     Stephen> ... but not in your non-interactive case; so maybe this instead:
>
>     Stephen> diff --git a/lisp/keymap.el b/lisp/keymap.el
>     Stephen> index 791221f2459..48ec91d03c8 100644
>     Stephen> --- a/lisp/keymap.el
>     Stephen> +++ b/lisp/keymap.el
>     Stephen> @@ -98,6 +98,8 @@ keymap-local-set
>     Stephen>    (let ((map (current-local-map)))
>     Stephen>      (unless map
>     Stephen>        (use-local-map (setq map (make-sparse-keymap))))
>     Stephen> +    (unless (stringp key)
>     Stephen> +      (setq key (key-description key)))
>     Stephen>      (keymap-set map key command)))
>
> `keymap-global-set' has the same type of issue.

Thanks, I failed to check that.

>                                                 How about this
> instead:
>
> diff --git a/lisp/keymap.el b/lisp/keymap.el
> index 791221f2459..1a339598f0c 100644
> --- a/lisp/keymap.el
> +++ b/lisp/keymap.el
> @@ -79,7 +79,7 @@ keymap-global-set
>    (interactive
>     (let* ((menu-prompting nil)
>            (key (read-key-sequence "Set key globally: " nil t)))
> -     (list key
> +     (list (key-description key)
>             (read-command (format "Set key %s to command: "
>                                   (key-description key))))))
>    (keymap-set (current-global-map) key command))
> @@ -94,7 +94,12 @@ keymap-local-set
>  The binding goes in the current buffer's local map, which in most
>  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: ")
> +  (interactive
> +   (let* ((menu-prompting nil)
> +          (key (read-key-sequence "Set key locally: " nil t)))
> +     (list (key-description key)
> +           (read-command (format "Set key %s to command: "
> +                                 (key-description key))))))
>    (let ((map (current-local-map)))
>      (unless map
>        (use-local-map (setq map (make-sparse-keymap))))

This also DTRT, but it also gives keymap-local-set the same UI as that
of keymap-global-set, which is that at the first prompt the cursor jumps
out of the minibuffer (due to read-key-sequence), and then jumps back at
the second prompt.  I find this quite jarring (and the first time I was
quite surprised and thought I had either mistyped or there was a bug).
I would prefer it if both commands had keymap-local-set's current UI.

Steve Berman