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

From: Adam Sjøgren <[email-masked]>
Date: Fri, 18 Apr 2025 00:57:37 +0200

I just remembered that it might be useful to update the documentation
of insert-kdb-macro as well; here's a draft for your consideration:

(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..066a2ec1f4b 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 definition of
+last-kdb-macro will be inserted.
 Optional second arg KEYS means also record the keys it is on
 \(this is the prefix argument, when calling interactively).
 
-- 
2.40.1

-- 
 "Favours for the ungrateful                                Adam Sjøgren
  Unqualified & hateful"                               [email-masked]