17.2.1 Naming Keyboard Macros

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 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 edmacro package
edit the macro. Type C-c C-c to finish editing and update
the definition stored on the key, or, to cancel the edit, kill the
buffer with C-x k.
The special characters RET, LFD, TAB, SPC,
DEL, and NUL must be entered as these three character
sequences, 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.

The C-x * 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.