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.

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: Adam Sjøgren <asjo <at> koldfront.dk>
Cc: 77317 <at> debbugs.gnu.org
Subject: 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.





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.