Subject: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that does not work

From: Eli Zaretskii <[email-masked]>
Date: Sun, 20 Apr 2025 21:58:04 +0300

> Date: Sun, 20 Apr 2025 18:44:16 +0200
> From:  Adam Sjøgren via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> Thanks both, here is the updated patch:

Please don't elide Stefan from CC, he doesn't tread bug-gnu-emacs.

> (insert-kbd-macro): document saving last-kbd-macro.
> 
> (Save Keyboard Macro): Mention how to save last-kbd-macro.
> 
> * lisp/macros.el (insert-kbd-macro): Update documentation of what
> happens when no macro name is supplied.
> 
> * doc/emacs/kmacro.texi (Save Keyboard Macro): Document saving
> last-kbd-macro.
> ---
>  doc/emacs/kmacro.texi | 9 ++++++---
>  lisp/macros.el        | 3 ++-
>  2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/doc/emacs/kmacro.texi b/doc/emacs/kmacro.texi
> index 62f275de259..09c6c5d4675 100644
> --- a/doc/emacs/kmacro.texi
> +++ b/doc/emacs/kmacro.texi
> @@ -472,9 +472,9 @@ Save Keyboard Macro
>  will bind the last keyboard macro to the key sequence @kbd{C-x C-k 4}.
>  
>  @findex insert-kbd-macro
> -  Once a macro has a command name, you can save its definition in a file.
> -Then it can be used in another editing session.  First, visit the file
> -you want to save the definition in.  Then use this command:
> +  You can save a macro's definition in a file.  Then it can be used in
> +another editing session.  First, visit the file you want to save the
> +definition in.  Then use this command:
>  
>  @example
>  M-x insert-kbd-macro @key{RET} @var{macroname} @key{RET}
> @@ -494,6 +494,9 @@ Save Keyboard Macro
>  to @var{macroname}, so that the macro will be reassigned the same keys
>  when you load the file.
>  
> +  If you do not give @code{insert-kbd-macro} a macro name, it will
> +insert Lisp code to restore the @code{last-kdb-macro}.
> +
>  @node Edit Keyboard Macro
>  @section Editing a Keyboard Macro
>  
> diff --git a/lisp/macros.el b/lisp/macros.el
> index fe79fe10f98..59554773629 100644
> --- a/lisp/macros.el
> +++ b/lisp/macros.el
> @@ -49,7 +49,8 @@ macros--insert-vector-macro
>  ;;;###autoload
>  (defun insert-kbd-macro (macroname &optional keys)
>    "Insert in buffer the definition of kbd macro MACRONAME, as Lisp code.
> -MACRONAME should be a symbol.
> +MACRONAME should be a symbol; if none is given, the function inserts
> +the definition of `last-kdb-macro'.
>  Optional second arg KEYS means also record the keys it is on
>  \(this is the prefix argument, when calling interactively).
>  
> -- 
> 2.40.1
> 
> -- 
>  "Rikstäckande rajtan-tajtan med Anders och Måns"           Adam Sjøgren
>                                                        [email-masked]
> 
> 
> 
>