(emacs)Save Kbd Macro


Next: Kbd Macro Query Prev: Basic Kbd Macro Up: Keyboard Macros

Naming and Saving Keyboard Macros
---------------------------------

   If you wish to save a keyboard macro for longer than until you
define the next one, you must give it a name using `M-x
name-last-kbd-macro'.  This reads a name as an argument using the
minibuffer and defines that name to execute the macro.  The macro name
is a Lisp symbol, and defining it in this way makes it a valid command
name for calling with `M-x' or for binding a key to with
`global-set-key' (Note: Keymaps.).  If you specify a name that has a
prior definition other than another keyboard macro, an error message is
printed and nothing is changed.

   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 need not
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.

   If you give `insert-kbd-macro' a prefix argument, it makes
additional Lisp code to record the keys (if any) that you have bound to
the keyboard macro, so that the macro will be reassigned the same keys
when you load the file.


automatically generated by info2www