Once you have defined a keyboard macro, you can bind it to a z
key sequence with the Z K (calc-user-define-kbd-macro
) command.
This command prompts first for a key, then for a command name. For
example, if you type C-x ( n TAB n TAB C-x ) you will
define a keyboard macro which negates the top two numbers on the stack
(TAB swaps the top two stack elements). Now you can type
Z K n RET to define this keyboard macro onto the z n key
sequence. The default command name (if you answer the second prompt with
just the RET key as in this example) will be something like
`calc-User-n'. The keyboard macro will now be available as both
z n and M-x calc-User-n. You can backspace and enter a more
descriptive command name if you wish.
Macros defined by Z K act like single commands; they are executed in the same way as by the X key. If you wish to define the macro as a standard no-frills Emacs macro (to be executed as if by C-x e), give a negative prefix argument to Z K.
Once you have bound your keyboard macro to a key, you can use Z P to register it permanently with Emacs. See section Creating User Keys.
The Z E (calc-user-define-edit
) command on a key that has
been defined by a keyboard macro tries to use the edit-kbd-macro
command to edit the macro. This command may be found in the
`macedit' package, a copy of which comes with Calc. It decomposes
the macro definition into full Emacs command names, like calc-pop
and calc-add
. Type M-# M-# to finish editing and update
the definition stored on the key, or, to cancel the edit, type
M-# x.
If you give a negative numeric prefix argument to Z E, the keyboard
macro is edited in spelled-out keystroke form. For example, the editing
buffer might contain the nine characters `1 RET 2 +'. When you press
M-# M-#, the read-kbd-macro
feature of the `macedit'
package is used to reinterpret these key names. The
notations RET
, LFD
, TAB
, SPC
, DEL
, and
NUL
must be written in all uppercase, as must the prefixes C-
and M-
. Spaces and line breaks are ignored. Other characters are
copied verbatim into the keyboard macro. Basically, the notation is the
same as is used in all of this manual's examples, except that the manual
takes some liberties with spaces: When we say ' [1 2 3] RET, we take
it for granted that it is clear we really mean ' [1 SPC 2 SPC 3] RET,
which is what read-kbd-macro
wants to see.
If `macedit' is not available, Z E edits the keyboard macro in "raw" form; the editing buffer simply contains characters like `1^M2+' (here `^M' represents the carriage-return character). Editing in this mode, you will have to use C-q to enter new control characters into the buffer.
The M-# m (read-kbd-macro
) command reads an Emacs "region"
of spelled-out keystrokes and defines it as the current keyboard macro.
It is a convenient way to define a keyboard macro that has been stored
in a file, or to define a macro without executing it at the same time.
The M-# m command works only if `macedit' is present.