File: kmacro.el.html
The kmacro package provides the user interface to Emacs's basic keyboard macro functionality. With kmacro, two function keys are dedicated to keyboard macros, by default F3 and F4.
Note: The traditional bindings C-x (, C-x ), and C-x e are still supported, but for some users these bindings are too hard to type to be really useful for doing small repeated tasks.
To start defining a keyboard macro, use F3. To end the macro, use F4, and to call the macro also use F4. This makes it very easy to repeat a macro immediately after defining it.
You can call the macro repeatedly by pressing F4 multiple times, or you can give a numeric prefix argument specifying the number of times to repeat the macro. Macro execution automatically terminates when point reaches the end of the buffer or if an error is signaled by ringing the bell.
When you define a macro with F3/F4, it is automatically added to the head of the "keyboard macro ring", and F4 actually executes the first element of the macro ring.
Note: an empty macro is never added to the macro ring.
You can execute the second element on the macro ring with C-u F4 or C-x C-k C-l, you can use C-x C-k C-p and C-x C-k C-n to cycle through the macro ring, and you can swap the first and second elements with C-x C-k C-t. To delete the first element in the macro ring, use C-x C-k C-d.
You can also use C-x C-k C-s to start a macro, and C-x C-k C-k to end it; then use C-k to execute it immediately, or C-x C-k C-k to execute it later.
In general, immediately after using C-x C-k followed by one of C-k, C-l, C-p, or C-n, you can further cycle the macro ring using C-p or C-n, execute the first or second macro using C-k or C-l, delete the head macro with C-d, or edit the current macro with C-e without repeating the C-x C-k prefix.
If you enter F3 while defining the macro, the numeric value of
kmacro-counter is inserted using the kmacro-counter-format, and
kmacro-counter is incremented by 1 (or the numeric prefix value
of F3).
The initial value of kmacro-counter is 0, or the numeric prefix
value given to F3 when starting the macro.
Now, each time you call the macro using F4, the current
value of kmacro-counter is inserted and incremented, making it
easy to insert incremental numbers in the buffer.
Example:
The following sequence: M-5 F3 x M-2 F3 y F4 F4 F4 F4
inserts the following string: x5yx7yx9yx11y
A macro can also be called using a mouse click, default S-mouse-3. This calls the macro at the point where you click the mouse.
You can edit the last macro using C-x C-k C-e.
You can append to the last macro using C-u F3.
You can set the macro counter using C-x C-k C-c, add to it using C-x C-k C-a, and you can set the macro counter format with C-x C-k C-f.
The following key bindings are performed:
Normal While defining macro
--------------------------- ------------------------------
f3 Define macro Insert current counter value
Prefix arg specifies initial and increase counter by prefix
counter value (default 0) (default increment: 1)
C-u f3 APPENDs to last macro
f4 Call last macro End macro
Prefix arg specifies number
of times to execute macro.
C-u f4 Swap last and head of macro ring.
S-mouse-3 Set point at click and End macro and execute macro at
execute last macro. click.
Defined variables (22)
kmacro-call-mouse-event | The mouse event used by kmacro to call a macro. |
kmacro-call-repeat-key | Allow repeating macro call using last key or a specific key. |
kmacro-call-repeat-with-arg | Repeat macro call with original arg when non-nil; repeat once if nil. |
kmacro-counter | Current keyboard macro counter. |
kmacro-counter-format | Current keyboard macro counter format. |
kmacro-counter-format-start | Macro format at start of macro execution. |
kmacro-counter-value-start | Macro counter at start of macro execution. |
kmacro-execute-before-append | Controls whether appending to a macro starts by executing the macro. |
kmacro-initial-counter-value | Initial counter value for the next keyboard macro to be defined. |
kmacro-keymap | Keymap for keyboard macro commands. |
kmacro-last-counter | Last counter inserted by key macro. |
kmacro-menu--deletion-flags | Alist of entries flagged for deletion. |
kmacro-menu--marks | Alist of entries marked for copying and duplication. |
kmacro-menu-mode-abbrev-table | Abbrev table for ‘kmacro-menu-mode’. |
kmacro-menu-mode-hook | Hook run after entering ‘kmacro-menu-mode’. |
kmacro-menu-mode-map | Keymap for ‘kmacro-menu-mode’. |
kmacro-menu-mode-syntax-table | Syntax table for ‘kmacro-menu-mode’. |
kmacro-repeat-no-prefix | Allow repeating certain macro commands without entering the C-x C-k prefix. |
kmacro-ring | The keyboard macro ring. |
kmacro-ring-max | Maximum number of keyboard macros to save in macro ring. |
kmacro-step-edit-map | Keymap that defines the responses to questions in ‘kmacro-step-edit-macro’. |
kmacro-step-edit-mini-window-height | Override ‘max-mini-window-height’ when step edit keyboard macro. |
Defined functions (91)
Defined faces (3)
kmacro-menu-flagged | Face used for keyboard macros flagged for deletion. |
kmacro-menu-mark | Face used for the Keyboard Macro Menu marks. |
kmacro-menu-marked | Face used for keyboard macros marked for duplication. |