Next: , Previous: , Up: Simple Customization   [Contents][Index]


13.1 Keyboard Macros

Keyboard macros provide a facility to turn a sequence of commands into one command.

Command: Define Keyboard Macro (bound to C-x ()
Command: End Keyboard Macro bind C-x )

Define Keyboard Macro starts the definition of a keyboard macro. The commands which are invoked up until End Keyboard Macro is invoked become the definition for the keyboard macro, thus replaying the keyboard macro is synonymous with invoking that sequence of commands.

Command: Last Keyboard Macro (bound to C-x e)

This command is the keyboard macro most recently defined; invoking it will replay the keyboard macro. The prefix argument is used as a repeat count.

Command: Define Keyboard Macro Key (bound to C-x M-(; )
Hemlock Variable: Define Keyboard Macro Key Confirm (initial value t)

This command prompts for a key before going into a mode for defining keyboard macros. After defining the macro Hemlock binds it to the key. If the key is already bound, Hemlock asks for confirmation before clobbering the binding; this prompting can be inhibited by setting Define Keyboard Macro Key Confirm to nil.

Command: Keyboard Macro Query (bound to C-x q)

This command conditionalizes the execution of a keyboard macro. When invoked during the definition of a macro, it does nothing. When the macro replays, it prompts the user for a key-event indicating what action to take. The following commands are defined:

Escape

Exit all repetitions of this keyboard macro. More than one may have been specified using a prefix argument.

Space, y

Proceed with the execution of the keyboard macro.

Delete, Backspace, n

Skip the remainder of the keyboard macro and go on to the next repetition, if any.

!

Do all remaining repetitions of the keyboard macro without prompting.

.

Complete this repetition of the macro and then exit without doing any of the remaining repetitions.

C-r

Do a recursive edit and then prompt again.

Command: Name Keyboard Macro

This command prompts for the name of a command and then makes the definition for that command the same as Last Keyboard Macro’s current definition. The command which results is not clobbered when another keyboard macro is defined, so it is possible to keep several keyboard macros around at once. The resulting command may also be bound to a key using Bind Key, in the same way any other command is.

Many keyboard macros are not for customization, but rather for one-shot use, a typical example being performing some operation on each line of a file. To add "del " to the beginning and ".*" to the end of every line in in a buffer, one could do this:

C-x ( d e l Space C-e . * C-n C-a C-x ) C-u 9 9 9 C-x e

First a keyboard macro is defined which performs the desired operation on one line, and then the keyboard macro is invoked with a large prefix argument. The keyboard macro will not actually execute that many times; when the end of the buffer is reached the C-n will get an error and abort the execution.


Next: Binding Keys, Previous: Simple Customization, Up: Simple Customization   [Contents][Index]