Recording a macro
C-x (
<do-whatever your macro does>
C-x )
Naming a macro
From the Macros section of the Emacs Wiki:
M-x name-last-kbd-macro
Binding a macro to a key
M-x global-set-key
(... and type key and choose macro by name.)
Saving a macro for later sessions
From the EmacsWiki Macro tricks:
M-x insert-kbd-macro
(... and fill in the name of the macro.)
Then write the output to your ~/.emacsrc
, together with a key binding, like this:
(fset '<snip> (global-set-key (kbd "C-x i") 'indexterm-primary-secondary)