3

I often create and save elaborate keyboard macros that I wish to use later, and hope to be prompted for the proper context to use them. I note that if I manually write a function to use as a command I can have a doc string

(defun my-handy-command ()
  "Some helpful guidance on when to use this"

However keyboard macros get saved as

(fset `my-named-kbd-macro
  (kmacro-lambda-form 

can I supply a docstring somehow. If I can't apply a docstring to fset what is the quickest and easiest way to go from a recorded keyboard macro to a usable emacs command with a docstring?

1 Answer 1

4

You can use defalias instead of fset. You use it like fset but it takes a docstring as third argument.

eg:

(defalias 'pastebelow
  (kmacro-lambda-form [?y ?y ?p] 0 "%d")
  "This is my keyboard macro.")

for Emacs version < 29

or

(defalias 'pastebelow
  (kmacro "y y p")
  "This is my keyboard macro.")

for Emacs version >= 29.

(y y p because I am an evil user).

Of course you can use M-x insert-kbd-macro after saving it with kmacro-name-last-macro (C-x C-k n).

2
  • defalias worked as advertised and I am using it now. I am however hesitant to accept your answer because I cannot reproduce your example. When I evaluate it I get an error on the line (kmacro "y y p") Debugger entered--Lisp error: (void-function kmacro) (kmacro "y y p") ... If you can clarify why that doesn't work for my version, or what I'm doing wrong or fix up your example, I will accept your answer. Commented Dec 1, 2022 at 18:23
  • Ah, I see. I am using Emacs 29, I did not know this worked differently in Emacs < 29. I have updated the answer. Thanks! Commented Dec 1, 2022 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.