1 |
@c This is part of the Emacs manual. |
@c This is part of the Emacs manual. |
2 |
@c Copyright (C) 1985,86,87,93,94,95,97,2000,2001,2002,2003 |
@c Copyright (C) 1985,86,87,93,94,95,97,2000,2001,2002,2003,2004 |
3 |
@c Free Software Foundation, Inc. |
@c Free Software Foundation, Inc. |
4 |
@c See file emacs.texi for copying conditions. |
@c See file emacs.texi for copying conditions. |
5 |
@node Keyboard Macros, Files, Fixit, Top |
@node Keyboard Macros, Files, Fixit, Top |
165 |
a consequence it re-executes the macro as previously defined. |
a consequence it re-executes the macro as previously defined. |
166 |
|
|
167 |
You can also add to the end of the definition of the last keyboard |
You can also add to the end of the definition of the last keyboard |
168 |
macro without re-execuing it by typing @kbd{C-u C-u C-x (}. |
macro without re-executing it by typing @kbd{C-u C-u C-x (}. |
169 |
|
|
170 |
The variable @code{kmacro-execute-before-append} specifies whether |
The variable @code{kmacro-execute-before-append} specifies whether |
171 |
a single @kbd{C-u} prefix causes the existing macro to be re-executed |
a single @kbd{C-u} prefix causes the existing macro to be re-executed |
179 |
beginning of the line and then executing the macro. |
beginning of the line and then executing the macro. |
180 |
|
|
181 |
@node Keyboard Macro Ring |
@node Keyboard Macro Ring |
182 |
@section Where previous keyboard macros are saved |
@section The Keyboard Macro Ring |
183 |
|
|
184 |
All defined keyboard macros are recorded in the ``keyboard macro ring'', |
All defined keyboard macros are recorded in the ``keyboard macro ring'', |
185 |
a list of sequences of keys. There is only one keyboard macro ring, |
a list of sequences of keys. There is only one keyboard macro ring, |
218 |
in the echo area. You can continue to rotate the macro ring |
in the echo area. You can continue to rotate the macro ring |
219 |
immediately by repeating just @kbd{C-n} and @kbd{C-p} until the |
immediately by repeating just @kbd{C-n} and @kbd{C-p} until the |
220 |
desired macro is at the head of the ring. To execute the new macro |
desired macro is at the head of the ring. To execute the new macro |
221 |
ring head immediately, just type @kbd{C-k}. |
ring head immediately, just type @kbd{C-k}. |
222 |
|
|
223 |
|
Note that Emacs treats the head of the macro ring as the ``last |
224 |
|
defined keyboard macro''. For instance, it is the keyboard macro that |
225 |
|
@kbd{C-x e} will execute. |
226 |
|
|
227 |
@findex kmacro-view-macro-repeat |
@findex kmacro-view-macro-repeat |
228 |
@kindex C-x C-k C-v |
@kindex C-x C-k C-v |
261 |
executes the previous (rather than the head) element on the macro ring. |
executes the previous (rather than the head) element on the macro ring. |
262 |
|
|
263 |
@node Keyboard Macro Counter |
@node Keyboard Macro Counter |
264 |
@section Inserting incrementing numbers in macros |
@section The Keyboard Macro Counter |
265 |
|
|
266 |
Each keyboard macro has an associated counter which is automatically |
Each keyboard macro has an associated counter which is automatically |
267 |
incremented on every repetition of the keyboard macro. Normally, the |
incremented on every repetition of the keyboard macro. Normally, the |
268 |
macro counter is initialized to 0 when you start defining the macro, |
macro counter is initialized to 0 when you start defining the macro, |
269 |
and incremented by 1 after each insertion of the counter value; |
and incremented by 1 after each insertion of the counter value; |
270 |
that is, if you insert the macro counter twice while defining the |
that is, if you insert the macro counter twice while defining the |
271 |
macro, it will be incremented by 2 time for each repetition of the |
macro, the counter will increase by 2 on each repetition of the macro. |
|
macro. |
|
272 |
|
|
273 |
@findex kmacro-insert-counter |
@findex kmacro-insert-counter |
274 |
@kindex C-x C-k C-i |
@kindex C-x C-k C-i |
364 |
@findex name-last-kbd-macro |
@findex name-last-kbd-macro |
365 |
@kindex C-x C-k n |
@kindex C-x C-k n |
366 |
If you wish to save a keyboard macro for later use, you can give it |
If you wish to save a keyboard macro for later use, you can give it |
367 |
a name using @kbd{C-x C-k n} (@code{name-last-kbd-macro}). |
a name using @kbd{C-x C-k n} (@code{name-last-kbd-macro}). |
368 |
This reads a name as an argument using the minibuffer and defines that name |
This reads a name as an argument using the minibuffer and defines that |
369 |
to execute the macro. The macro name is a Lisp symbol, and defining it in |
name to execute the last keyboard macro, in its current form. (If you |
370 |
this way makes it a valid command name for calling with @kbd{M-x} or for |
later add to the definition of this macro, that does not alter the |
371 |
binding a key to with @code{global-set-key} (@pxref{Keymaps}). If you |
name's definition as a macro.) The macro name is a Lisp symbol, and |
372 |
specify a name that has a prior definition other than another keyboard |
defining it in this way makes it a valid command name for calling with |
373 |
macro, an error message is shown and nothing is changed. |
@kbd{M-x} or for binding a key to with @code{global-set-key} |
374 |
|
(@pxref{Keymaps}). If you specify a name that has a prior definition |
375 |
|
other than a keyboard macro, an error message is shown and nothing is |
376 |
|
changed. |
377 |
|
|
378 |
@cindex binding keyboard macros |
@cindex binding keyboard macros |
379 |
@findex kmacro-bind-to-key |
@findex kmacro-bind-to-key |
380 |
@kindex C-x C-k b |
@kindex C-x C-k b |
381 |
Rather than giving a keyboard macro a name, you can bind it to a |
You can also bind the last keyboard macro to a key, using |
382 |
key using @kbd{C-x C-k b} (@code{kmacro-bind-to-key}) followed by the |
@kbd{C-x C-k b} (@code{kmacro-bind-to-key}) followed by the |
383 |
key sequence you want the keyboard macro to be bound to. You can |
key sequence you want the keyboard macro to be bound to. You can |
384 |
bind to any key sequence in the global keymap, but since most key |
bind to any key sequence in the global keymap, but since most key |
385 |
sequences already have other bindings, you should select the key |
sequences already have other bindings, you should select the key |
386 |
sequence carefylly. If you try to bind to a key sequence with an |
sequence carefully. If you try to bind to a key sequence with an |
387 |
existing binding (in any keymap), you will be asked if you really |
existing binding (in any keymap), you will be asked if you really |
388 |
want to replace the existing binding of that key. |
want to replace the existing binding of that key. |
389 |
|
|
420 |
macro will be defined each time you run Emacs. |
macro will be defined each time you run Emacs. |
421 |
|
|
422 |
If you give @code{insert-kbd-macro} a numeric argument, it makes |
If you give @code{insert-kbd-macro} a numeric argument, it makes |
423 |
additional Lisp code to record the keys (if any) that you have bound to the |
additional Lisp code to record the keys (if any) that you have bound |
424 |
keyboard macro, so that the macro will be reassigned the same keys when you |
to @var{macroname}, so that the macro will be reassigned the same keys |
425 |
load the file. |
when you load the file. |
426 |
|
|
427 |
@node Edit Keyboard Macro |
@node Edit Keyboard Macro |
428 |
@section Interactively executing and editing a keyboard macro |
@section Editing a Keyboard Macro |
429 |
|
|
430 |
@findex kmacro-edit-macro |
@findex kmacro-edit-macro |
431 |
@kindex C-x C-k C-e |
@kindex C-x C-k C-e |
449 |
@kbd{C-x C-k l} (@code{kmacro-edit-lossage}). |
@kbd{C-x C-k l} (@code{kmacro-edit-lossage}). |
450 |
|
|
451 |
@node Keyboard Macro Step-Edit |
@node Keyboard Macro Step-Edit |
452 |
@section Interactively executing and editing a keyboard macro |
@section Stepwise Editing a Keyboard Macro |
453 |
|
|
454 |
@findex kmacro-step-edit-macro |
@findex kmacro-step-edit-macro |
455 |
@kindex C-x C-k SPC |
@kindex C-x C-k SPC |
456 |
You can interactively and stepwise replay and edit the last keyboard |
You can interactively and stepwise replay and edit the last keyboard |
457 |
macro one command at a time by typing @kbd{C-x C-k SPC} |
macro one command at a time by typing @kbd{C-x C-k SPC} |
458 |
(@code{kmacro-step-edit-macro}). Unless you quit the macro using |
(@code{kmacro-step-edit-macro}). Unless you quit the macro using |
459 |
@kbd{q} or @kbd{C-g}, the edited macro replaces the last macro on the |
@kbd{q} or @kbd{C-g}, the edited macro replaces the last macro on the |
460 |
macro ring. |
macro ring. |