Subject: Re: bug#61700: 30.0.50; insert-kbd-macro fails for named macro but not last macro

From: Robert Pluim <[email-masked]>
Date: Thu, 23 Feb 2023 10:21:05 +0100

>>>>> On Tue, 21 Feb 2023 17:18:16 -0800, Josh Moller-Mara <[email-masked]> said:

    Josh> Using “M-x insert-kbd-macro” can insert an incorrect kmacro form for a
    Josh> named macro, while still correctly inserting the “last-kbd-macro”.

    Josh> To see this, we’ll define a macro that simply inserts the HTML string
    Josh> “<b>hello</b>” (press F3, type the previous string, then press F4).
    Josh> We’ll name this macro “bold-hello” using “C-x C-k n”.

    Josh> Inserting the definition to the last macro (using “M-x insert-kbd-macro”
    Josh> and leaving the prompt blank) returns:

    Josh> (setq last-kbd-macro
    Josh>    (kmacro "< b > H e l l o < / b >"))

    Josh> Inserting the definition to “bold-hello” (using “M-x insert-kbd-macro”
    Josh> and typing “bold-hello” at the prompt) returns:

    Josh> (defalias 'bold-hello
    Josh>    (kmacro "<b> H e l l o < / b >"))

    Josh> Notice the difference in “< b >” vs “<b>”.  The “bold-hello” command
    Josh> doesn’t work, printing the message:

    Josh> “After 0 kbd macro iterations: Keyboard macro terminated by a command ringing the bell”

    Josh> I think this may have to do with the use of “key-parse” in “kmacro” (see
    Josh> “(find-function 'kmacro)”).

    Josh> (key-parse "<b>hello</b>") returns
    Josh> “[b 104 101 108 108 111 60 47 98 62]”
    Josh> but
    Josh> (macro--string-to-vector "<b>hello</b>") returns
    Josh> “[60 98 62 104 101 108 108 111 60 47 98 62]”

    Josh> The latter form is used in “insert-kbd-macro” when inserting
    Josh> “last-kbd-macro”.

This fails in emacs-29 as well. Stefan, you rewrote this code to
use oclosures, any ideas? I guess we could just use
macro--string-to-vector in both cases, but youʼre the expert here :-)

    Josh> You can also quickly replicate the issue by evaluating the following
    Josh> form:

    Josh> (progn
    Josh>   (setq last-kbd-macro "<b>hello</b>")
    Josh>   (kmacro-name-last-macro 'bold-hello)
    Josh>   (let ((temp-buffer (generate-new-buffer "*macros*")))
    Josh>     (with-current-buffer temp-buffer
    Josh>       (insert-kbd-macro (intern ""))
    Josh>       (insert-kbd-macro 'bold-hello))
    Josh>     (display-buffer temp-buffer)))

Robert
--