Very frequently I would need to perform the set of steps requiring multiple key strokes. For the same session those steps can be recorded in a keyboard macro.
An example is saving a frequently executed search/replace operation as a keyboard macro. But that macro is lost when I quit emacs.
How can I save my frequently used keyboard macro as a Lisp function?
For the sake of simplicity, I want to save the action of replacing "abc" with "def" as a function so that I can reuse it across emacs sessions.
insert-kbd-macro
. That is the answer to the question (and the rest of this answer provides additional help). – Drew Sep 24 '14 at 15:31insert-kbd-macro
depends upon whether you named it usingkmacro-name-last-macro
(as in the above answer) orname-last-kbd-macro
. – phils Oct 09 '14 at 06:06name-last-kbd-macro
format (as mentioned by @phils above) you end up with a string, not a function.fset
ting that to a symbol lets you execute the macro using M-x, but not call it from lisp (commandp
->t
,functionp
->nil
). Strangely, even calling it viacall-interactively
doesn't work (although you can useexecute-kbd-macro
to run it). – pyrocrasty Mar 12 '19 at 01:01