GNU bug report logs - #77317
31.0.50; insert-kbd-macro RET produces elisp that does not work

Previous Next

Package: emacs;

Reported by: Adam Sjøgren <asjo <at> koldfront.dk>

Date: Thu, 27 Mar 2025 18:39:02 UTC

Severity: normal

Found in version 31.0.50

Done: Adam Sjøgren <asjo <at> koldfront.dk>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 77317 in the body.
You can then email your comments to 77317 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Thu, 27 Mar 2025 18:39:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Adam Sjøgren <asjo <at> koldfront.dk>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 27 Mar 2025 18:39:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Adam Sjøgren <asjo <at> koldfront.dk>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; insert-kbd-macro RET produces elisp that does not work
Date: Thu, 27 Mar 2025 19:37:39 +0100
If I record a macro, for instance by pressing C-x ( A B B A C-x ) I can
do M-x insert-kbd-macro RET to have elisp representing that macro
inserted in the current buffer.

If I evaluate that code and then try to execute the macro with C-x e, I
get the error: "Keyboard macros must be strings or vectors".

I was expecting the macro to be executed, inserting "ABBA".

The generated code looks like this:

    (setq last-kbd-macro
       (kmacro "A B B A"))

and if I evaluate it, *Messages* contains:

    #[256 "\301\242\302^[^\\305\300^B\306#\210\301^L\240*\207" [[65 66
     66 65] (0) "%d" kmacro-counter-format-start kmacro-counter
     execute-kbd-macro kmacro-loop-setup-function] 5 kmacro]

and pressing C-x e to execute the macro results in the above mentioned
error.

(Naming the macro and inserting it creates a defalias, which works -
it's only the last-kbd-macro case that does not work.)


In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.16.0) of 2025-03-08 built on tullinup
Repository revision: e78470fd1b2200b44dfb2465e39d7b31674bbc2a
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101007
System Description: Debian GNU/Linux trixie/sid

Configured using:
 'configure -C --with-tree-sitter --with-xinput2 --without-pgtk
 --with-native-compilation=aot'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP
NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINERAMA XINPUT2 XPM
XRANDR GTK3 ZLIB

Important settings:
  value of $LANG: en_GB.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug lisp-mnt message mailcap yank-media puny
dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg
rfc6068 epg-config gnus-util text-property-search time-date subr-x
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
mail-utils macros cl-seq cl-extra help-mode edmacro comp-run comp-common
rx kmacro byte-opt gv bytecomp byte-compile cl-loaddefs cl-lib rmc
iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd touch-screen tool-bar dnd fontset image regexp-opt
fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode
register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting cairo gtk x-toolkit xinput2 x multi-tty move-toolbar
make-network-process tty-child-frames native-compile emacs)

Memory information:
((conses 16 69445 18686) (symbols 48 6645 0) (strings 32 18633 1517)
 (string-bytes 1 595563) (vectors 16 11875)
 (vector-slots 8 161807 10397) (floats 8 30 4) (intervals 56 286 23)
 (buffers 992 12))

-- 
 "You know how everyone says you should stop and            Adam Sjøgren
  smell the roses? Well, this morning I did. *Big      asjo <at> koldfront.dk
  deal!* They smelled like a bunch of dumb flowers!
  It was the most mundane experience I've ever had!"




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Fri, 28 Mar 2025 10:58:01 GMT) Full text and rfc822 format available.

Message #8 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Adam Sjøgren <asjo <at> koldfront.dk>
Cc: 77317 <at> debbugs.gnu.org
Subject: Re: bug#77317: 31.0.50;
 insert-kbd-macro RET produces elisp that does not work
Date: Fri, 28 Mar 2025 13:57:07 +0300
> Date: Thu, 27 Mar 2025 19:37:39 +0100
> From:  Adam Sjøgren via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> 
> If I record a macro, for instance by pressing C-x ( A B B A C-x ) I can
> do M-x insert-kbd-macro RET to have elisp representing that macro
> inserted in the current buffer.
> 
> If I evaluate that code and then try to execute the macro with C-x e, I
> get the error: "Keyboard macros must be strings or vectors".
> 
> I was expecting the macro to be executed, inserting "ABBA".
> 
> The generated code looks like this:
> 
>     (setq last-kbd-macro
>        (kmacro "A B B A"))
> 
> and if I evaluate it, *Messages* contains:
> 
>     #[256 "\301\242\302^[^\\305\300^B\306#\210\301^L\240*\207" [[65 66
>      66 65] (0) "%d" kmacro-counter-format-start kmacro-counter
>      execute-kbd-macro kmacro-loop-setup-function] 5 kmacro]
> 
> and pressing C-x e to execute the macro results in the above mentioned
> error.
> 
> (Naming the macro and inserting it creates a defalias, which works -
> it's only the last-kbd-macro case that does not work.)

The Emacs user manual says


     If you wish to save a keyboard macro for later use, you can give it a
  name using ‘C-x C-k n’ (‘kmacro-name-last-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:

       M-x insert-kbd-macro <RET> MACRONAME <RET>

  This inserts some Lisp code that, when executed later, will define the
  same macro with the same definition it has now.  (You don't need to
  understand Lisp code to do this, because ‘insert-kbd-macro’ writes the
  Lisp code for you.)  Then save the file.  You can load the file later
  with ‘load-file’ (*note Lisp Libraries::).  If the file you save in is
  your init file ‘~/.emacs’ (*note Init File::) then the macro will be
  defined each time you run Emacs.

So it sounds like this is supposed to work for macros that have been
given a name.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Fri, 28 Mar 2025 12:32:01 GMT) Full text and rfc822 format available.

Message #11 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Adam Sjøgren <asjo <at> koldfront.dk>
To: 77317 <at> debbugs.gnu.org
Cc: Eli Zaretskii <eliz <at> gnu.org>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
Date: Fri, 28 Mar 2025 13:31:32 +0100
Eli writes:

> So it sounds like this is supposed to work for macros that have been
> given a name.

If you look at the code, there is an explicit path for last-kbd-macro:

    (if (string= (symbol-name macroname) "")
	(progn
	  (setq macroname 'last-kbd-macro definition last-kbd-macro)
	  (insert "(setq "))
      (setq definition (symbol-function macroname))

      · macros.el L70-74

which to me indicates an intention of it working, even if the manual
doesn't mention the case. This code has been in macros.el since 1992,
according to git annotate.

If insert-kbd-macro was designed explicitly to not work on the
unnamed, last macro, shouldn't an error be raised or an empty macro
name be rejected, rather than code inserted?

If you try it in a version of Emacs released before 2022-04-01 saving
last-kbd-macro does work - eg Emacs 28.2 as included in Debian 12.

(Just as a side-note: the manual of Emacs 28.2 didn't mention the
possibility either.)

Maybe Stefan Monnier (Cc'd) can shed some light on this, as he
improved the named macro part of insert-kbd-macro in 2022 (c75f65442ddf):

    Also replace the old `kmacro-lambda-form` with a new `kmacro` constructor
    which takes a `key-parse` syntax, so that the code inserted with
    `insert-kbd-macro` is now more readable.

     [...]

    * lisp/macros.el (macro--string-to-vector): New function.
    (insert-kbd-macro): Use it.  Generate code using the `kmacro` constructor.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Fri, 28 Mar 2025 17:51:02 GMT) Full text and rfc822 format available.

Message #14 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Adam Sjøgren <asjo <at> koldfront.dk>
Cc: 77317 <at> debbugs.gnu.org
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
Date: Fri, 28 Mar 2025 13:50:33 -0400
> The generated code looks like this:
>
>     (setq last-kbd-macro
>        (kmacro "A B B A"))

Hmm... this is nicely readable, but indeed it bumps into the following
problem:

A keyboard macro is made of 3 elements: the sequence of events, of
course, but also a counter and format string.
The "currently installed" (aka "last") keyboard macro stores those
3 pieces of info in, respectively:

    last-kbd-macro
    kmacro-counter
    kmacro-counter-format

When saved elsewhere (e.g. in the `kmacro-ring` or in an init file),
these three elements are bundled into a single `kmacro` object.

So to avoid the error you're seeing, as the code currently stands, the
`(setq last-kbd-macro (kmacro ...))` should be replaced with either
a call to `kmacro-split-ring-element` or something which has the same
effect:

    (defun kmacro-split-ring-element (elt)
      (setq last-kbd-macro (kmacro--keys elt)
            kmacro-counter (kmacro--counter elt)
            kmacro-counter-format-start (kmacro--format elt)))

🙁

Maybe a better fix would be to "force" the user to give a name to the
macro before inserting it.

Could you explain exactly how you bumped into this problem, more
specifically what was your intention behind the use of
`insert-kbd-macro` without giving the macro a name?


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Fri, 28 Mar 2025 20:10:02 GMT) Full text and rfc822 format available.

Message #17 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Adam Sjøgren <asjo <at> koldfront.dk>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 77317 <at> debbugs.gnu.org
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
Date: Fri, 28 Mar 2025 21:09:32 +0100
Stefan writes:

> So to avoid the error you're seeing, as the code currently stands, the
> `(setq last-kbd-macro (kmacro ...))` should be replaced with either
> a call to `kmacro-split-ring-element` or something which has the same
> effect:
>
>     (defun kmacro-split-ring-element (elt)
>       (setq last-kbd-macro (kmacro--keys elt)
>             kmacro-counter (kmacro--counter elt)
>             kmacro-counter-format-start (kmacro--format elt)))
>
> 🙁

Yeah, ok, not exactly pretty.

For my use-case generating

    (setq last-kbd-macro (kmacro--keys
       (kmacro "A B B A")))

instead of:

    (setq last-kbd-macro
       (kmacro "A B B A"))

would be sufficient. I think that would be better than what happens
currently, but I can see it is not as comprehensive as also handling
the counter stuff.

How does that actually work for a named macro? If I name the macro
"hep" and insert it, I get:

    (defalias 'hep
       (kmacro "A B B A"))

Maybe that's because I didn't use any counters?

> Maybe a better fix would be to "force" the user to give a name to the
> macro before inserting it.

Better than inserting some code that doesn't work, agreed.

> Could you explain exactly how you bumped into this problem, more
> specifically what was your intention behind the use of
> `insert-kbd-macro` without giving the macro a name?

I rarely use macros, and I never use named macros (I always forget
about the possibility).

From time to time I edit a list of (spam)domains to reject, and I
often create a macro that inserts an email-address and changes the .
to [.] and deletes everything in front of the @.

Instead of recreating that macro when I edit that list, I thought
"Hey, I can probably save that macro in the file and reconstitute it
when I need it".

So I found M-x insert-kbd-macro and didn't give a name when prompted
(as the macro didn't have one), and it promisingly inserted some code,
which I tried evaluating and executing.

I wondered why it didn't work, and at first I assumed I was doing
something wrong.

Then I tried in an older Emacs and saw it generate something slightly
different, which worked, and then I looked in macros.el and found code
that seemed to specifically handle last-kbd-macro.

Which lead me to believe that it ought to work.

I can see that the manual and the code do not quite agree, but I still
think it is a nice and natural functionality that you can save the
current macro and get it back without having to name it.

With C-x e I can repeat the macro by pressing e more times. Is that
functionality present when I do M-x hep (ie run a named macro)?


  Best regards,

    Adam

-- 
 "People just generally like to disagree."                  Adam Sjøgren
                                                       asjo <at> koldfront.dk




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Fri, 28 Mar 2025 21:01:02 GMT) Full text and rfc822 format available.

Message #20 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Adam Sjøgren <asjo <at> koldfront.dk>
Cc: 77317 <at> debbugs.gnu.org
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
Date: Fri, 28 Mar 2025 16:59:56 -0400
> For my use-case generating
>
>     (setq last-kbd-macro (kmacro--keys
>        (kmacro "A B B A")))
>
> instead of:
>
>     (setq last-kbd-macro
>        (kmacro "A B B A"))

The patch below makes it emit

    (setq last-kbd-macro
          (key-parse "A B B A"))

> How does that actually work for a named macro? If I name the macro
> "hep" and insert it, I get:
>
>     (defalias 'hep
>        (kmacro "A B B A"))

Yes.

> Maybe that's because I didn't use any counters?

If you use the counter or the format, they'll appear as additional
arguments to the `kmacro` constructor.

> From time to time I edit a list of (spam)domains to reject, and I
> often create a macro that inserts an email-address and changes the .
> to [.] and deletes everything in front of the @.
>
> Instead of recreating that macro when I edit that list, I thought
> "Hey, I can probably save that macro in the file and reconstitute it
> when I need it".
>
> So I found M-x insert-kbd-macro and didn't give a name when prompted
> (as the macro didn't have one), and it promisingly inserted some code,
> which I tried evaluating and executing.

Thanks, that gives a good reason to support that functionality.

> With C-x e I can repeat the macro by pressing e more times.  Is that
> functionality present when I do M-x hep (ie run a named macro)?

No, the named macros are meant to use the "generic" repetition support,
e.g. by binding them to convenient keys or by using `C-x z`.


        Stefan


diff --git a/lisp/macros.el b/lisp/macros.el
index 64b78d1cdf4..25ea303d439 100644
--- a/lisp/macros.el
+++ b/lisp/macros.el
@@ -78,8 +78,6 @@ insert-kbd-macro
       (insert "(defalias '"))
     (prin1 macroname (current-buffer))
     (insert "\n   ")
-    (when (or (stringp definition) (vectorp definition))
-      (setq definition (kmacro (kmacro--to-vector definition))))
     (if (kmacro-p definition)
         (let ((vecdef  (kmacro--keys     definition))
               (counter (kmacro--counter definition))
@@ -93,8 +91,7 @@ insert-kbd-macro
             (insert " ")
             (prin1 format (current-buffer)))
           (insert ")"))
-      ;; FIXME: Shouldn't this signal an error?
-      (prin1 definition (current-buffer)))
+        (prin1 `(key-parse ,(key-description definition)) (current-buffer)))
     (insert ")\n")
     (if keys
         (let ((keys (or (and (symbol-function macroname)





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Fri, 28 Mar 2025 21:07:01 GMT) Full text and rfc822 format available.

Message #23 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Adam Sjøgren <asjo <at> koldfront.dk>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 77317 <at> debbugs.gnu.org
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
Date: Fri, 28 Mar 2025 22:06:53 +0100
Stefan writes:

> The patch below makes it emit
>
>     (setq last-kbd-macro
>           (key-parse "A B B A"))

That works perfectly for me - thanks!


  Best regards,

    Adam

-- 
 "How's your snow art progressing?"                         Adam Sjøgren
 "I've moved into abstraction!"                        asjo <at> koldfront.dk




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Mon, 31 Mar 2025 15:38:01 GMT) Full text and rfc822 format available.

Message #26 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Adam Sjøgren <asjo <at> koldfront.dk>
Cc: 77317 <at> debbugs.gnu.org
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
Date: Mon, 31 Mar 2025 11:36:47 -0400
>> The patch below makes it emit
>>
>>     (setq last-kbd-macro
>>           (key-parse "A B B A"))
>
> That works perfectly for me - thanks!

Pushed to `master`, thanks.


        Stefan





bug closed, send any further explanations to 77317 <at> debbugs.gnu.org and Adam Sjøgren <asjo <at> koldfront.dk> Request was from Adam Sjøgren <asjo <at> koldfront.dk> to control <at> debbugs.gnu.org. (Mon, 31 Mar 2025 16:32:05 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Thu, 17 Apr 2025 22:58:04 GMT) Full text and rfc822 format available.

Message #31 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Adam Sjøgren <asjo <at> koldfront.dk>
To: 77317 <at> debbugs.gnu.org
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
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"                               asjo <at> koldfront.dk




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Fri, 18 Apr 2025 10:35:06 GMT) Full text and rfc822 format available.

Message #34 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Adam Sjøgren <asjo <at> koldfront.dk>
Cc: 77317 <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca
Subject: Re: bug#77317: 31.0.50;
 insert-kbd-macro RET produces elisp that does not work
Date: Fri, 18 Apr 2025 13:34:35 +0300
> Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Date: Fri, 18 Apr 2025 00:57:37 +0200
> From:  Adam Sjøgren via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> --- 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.

I find this punctuation easier to read:

  MACRONAME should be a symbol; if none is given, the definition of
  `last-kdb-macro' will be inserted.

Bonus points for eliminating the passive tense:

  MACRONAME should be a symbol; if none is given, the function inserts
  the definition of `last-kdb-macro'.

Thanks.

P.S. I don't know this code well enough to tell whether the
documentation changes are factually correct/accurate.  I hope Stefan
will comment on that.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Fri, 18 Apr 2025 16:08:05 GMT) Full text and rfc822 format available.

Message #37 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Adam Sjøgren <asjo <at> koldfront.dk>
Cc: 77317 <at> debbugs.gnu.org
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
Date: Fri, 18 Apr 2025 12:06:51 -0400
> 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:

Looks OK to me.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Sun, 20 Apr 2025 16:45:01 GMT) Full text and rfc822 format available.

Message #40 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Adam Sjøgren <asjo <at> koldfront.dk>
To: 77317 <at> debbugs.gnu.org
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
Date: Sun, 20 Apr 2025 18:44:16 +0200
Thanks both, here is the updated patch:


(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
                                                       asjo <at> koldfront.dk




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Sun, 20 Apr 2025 18:59:01 GMT) Full text and rfc822 format available.

Message #43 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Adam Sjøgren <asjo <at> koldfront.dk>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 77317 <at> debbugs.gnu.org
Subject: Re: bug#77317: 31.0.50;
 insert-kbd-macro RET produces elisp that does not work
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" <bug-gnu-emacs <at> gnu.org>
> 
> 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
>                                                        asjo <at> koldfront.dk
> 
> 
> 
> 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Sun, 20 Apr 2025 19:11:01 GMT) Full text and rfc822 format available.

Message #46 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Adam Sjøgren <asjo <at> koldfront.dk>
To: 77317 <at> debbugs.gnu.org
Cc: Eli Zaretskii <eliz <at> gnu.org>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
Date: Sun, 20 Apr 2025 21:10:18 +0200
Eli writes:

>> Thanks both, here is the updated patch:
>
> Please don't elide Stefan from CC, he doesn't tread bug-gnu-emacs.

As Stefan has fixed the bug and confirmed that the documentation
change I sent looks good, as you requested, I did not think it was
necessary to bother him further, so I only sent the updated
documentation patch to the bug-tracker.

Thanks for pointing out my mistake.


  Best regards,

    Adam

-- 
 "My lack of interest in this conversation could            Adam Sjøgren
  only be described as religious in intensity."        asjo <at> koldfront.dk




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Sat, 26 Apr 2025 12:56:01 GMT) Full text and rfc822 format available.

Message #49 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Adam Sjøgren <asjo <at> koldfront.dk>
Cc: 77317 <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
Date: Sat, 26 Apr 2025 15:55:19 +0300
> From: Adam Sjøgren <asjo <at> koldfront.dk>
> Cc: Eli Zaretskii <eliz <at> gnu.org>, Stefan Monnier <monnier <at> iro.umontreal.ca>
> Date: Sun, 20 Apr 2025 21:10:18 +0200
> 
> Eli writes:
> 
> >> Thanks both, here is the updated patch:
> >
> > Please don't elide Stefan from CC, he doesn't tread bug-gnu-emacs.
> 
> As Stefan has fixed the bug and confirmed that the documentation
> change I sent looks good, as you requested, I did not think it was
> necessary to bother him further, so I only sent the updated
> documentation patch to the bug-tracker.
> 
> Thanks for pointing out my mistake.

No sweat.

Stefan, any further comments, or should I install this?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Sat, 26 Apr 2025 16:41:02 GMT) Full text and rfc822 format available.

Message #52 received at 77317 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Adam Sjøgren <asjo <at> koldfront.dk>,
 77317 <at> debbugs.gnu.org
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
Date: Sat, 26 Apr 2025 12:40:21 -0400
> Stefan, any further comments, or should I install this?

It's ready to push, AFAIC,


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77317; Package emacs. (Sun, 27 Apr 2025 06:55:01 GMT) Full text and rfc822 format available.

Message #55 received at 77317-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: asjo <at> koldfront.dk, 77317-done <at> debbugs.gnu.org
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
Date: Sun, 27 Apr 2025 09:54:27 +0300
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: Adam Sjøgren <asjo <at> koldfront.dk>,
>   77317 <at> debbugs.gnu.org
> Date: Sat, 26 Apr 2025 12:40:21 -0400
> 
> > Stefan, any further comments, or should I install this?
> 
> It's ready to push, AFAIC,

Thanks, installed on master, and closing the bug.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 25 May 2025 11:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 25 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.