]> code.delx.au - gnu-emacs/blobdiff - man/kmacro.texi
(nnmail-active-file-coding-system, gnus-original-article-buffer,
[gnu-emacs] / man / kmacro.texi
index be2b520fc597fa814b97cba47efd2fd82a29d620..0693eefca5431aa484d04086052c87747f7380f3 100644 (file)
@@ -1,6 +1,6 @@
 @c This is part of the Emacs manual.
-@c Copyright (C) 1985,86,87,93,94,95,97,2000,2001,2002,2003
-@c  Free Software Foundation, Inc.
+@c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2000, 2001,
+@c   2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 @c See file emacs.texi for copying conditions.
 @node Keyboard Macros, Files, Fixit, Top
 @chapter Keyboard Macros
@@ -38,7 +38,8 @@ intelligent or general.  For such things, Lisp must be used.
 * Keyboard Macro Query::     Making keyboard macros do different things each time.
 * Save Keyboard Macro::      Giving keyboard macros names; saving them in files.
 * Edit Keyboard Macro::      Editing keyboard macros.
-* Keyboard Macro Step-Edit::   Interactively executing and editing a keyboard macro.
+* Keyboard Macro Step-Edit:: Interactively executing and editing a keyboard
+                               macro.
 @end menu
 
 @node Basic Keyboard Macro
@@ -46,6 +47,7 @@ intelligent or general.  For such things, Lisp must be used.
 
 @table @kbd
 @item C-x (
+@itemx @key{F3}
 Start defining a keyboard macro (@code{kmacro-start-macro}).
 @item C-x )
 End the definition of a keyboard macro (@code{kmacro-end-macro}).
@@ -53,6 +55,10 @@ End the definition of a keyboard macro (@code{kmacro-end-macro}).
 Execute the most recent keyboard macro (@code{kmacro-end-and-call-macro}).
 First end the definition of the keyboard macro, if currently defining it.
 To immediately execute the keyboard macro again, just repeat the @kbd{e}.
+@item @key{F4}
+If a keyboard macro is being defined, end the definition; otherwise,
+execute the most recent keyboard macro
+(@code{kmacro-end-or-call-macro}).
 @item C-u C-x (
 Re-execute last keyboard macro, then add more keys to its definition.
 @item C-u C-u C-x (
@@ -62,7 +68,7 @@ When this point is reached during macro execution, ask for confirmation
 (@code{kbd-macro-query}).
 @item C-x C-k n
 Give a command name (for the duration of the session) to the most
-recently defined keyboard macro (@code{name-last-kbd-macro}).
+recently defined keyboard macro (@code{kmacro-name-last-macro}).
 @item C-x C-k b
 Bind the most recently defined keyboard macro to a key sequence (for
 the duration of the session) (@code{kmacro-bind-to-key}).
@@ -71,7 +77,7 @@ Insert in the buffer a keyboard macro's definition, as Lisp code.
 @item C-x C-k e
 Edit a previously defined keyboard macro (@code{edit-kbd-macro}).
 @item C-x C-k r
-Run the last keyboard macro on each complete line in the region
+Run the last keyboard macro on each line that begins in the region
 (@code{apply-macro-to-region-lines}).
 @end table
 
@@ -120,10 +126,9 @@ of zero to @kbd{C-x e} or @kbd{C-x )} means repeat the macro
 indefinitely (until it gets an error or you type @kbd{C-g} or, on
 MS-DOS, @kbd{C-@key{BREAK}}).
 
-@kindex C-x C-k C-s
-@kindex C-x C-k C-k
-Alternatively, you can use @kbd{C-x C-k C-s} to start a keyboard macro,
-and @kbd{C-x C-k C-k...} to end and execute it.
+  The key @key{F4} is like a combination of @kbd{C-x )} and @kbd{C-x
+e}.  If you're defining a macro, @key{F4} ends the definition.
+Otherwise it executes the last macro.
 
   If you wish to repeat an operation at regularly spaced places in the
 text, define a macro and include as part of the macro the commands to move
@@ -165,7 +170,7 @@ to plain @kbd{C-x (} followed by retyping the whole definition so far.  As
 a consequence it re-executes the macro as previously defined.
 
   You can also add to the end of the definition of the last keyboard
-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 (}.
 
   The variable @code{kmacro-execute-before-append} specifies whether
 a single @kbd{C-u} prefix causes the existing macro to be re-executed
@@ -174,18 +179,18 @@ before appending to it.
 @findex apply-macro-to-region-lines
 @kindex C-x C-k r
   The command @kbd{C-x C-k r} (@code{apply-macro-to-region-lines})
-repeats the last defined keyboard macro on each complete line within
-the current region.  It does this line by line, by moving point to the
+repeats the last defined keyboard macro on each line that begins in
+the region.  It does this line by line, by moving point to the
 beginning of the line and then executing the macro.
 
 @node Keyboard Macro Ring
-@section Where previous keyboard macros are saved
+@section The Keyboard Macro Ring
 
   All defined keyboard macros are recorded in the ``keyboard macro ring'',
 a list of sequences of keys.  There is only one keyboard macro ring,
 shared by all buffers.
 
-  All commands which operates on the keyboard macro ring use the
+  All commands which operate on the keyboard macro ring use the
 same @kbd{C-x C-k} prefix.  Most of these commands can be executed and
 repeated immediately after each other without repeating the @kbd{C-x
 C-k} prefix.  For example,
@@ -207,30 +212,39 @@ executes the keyboard macro at the head of the macro ring.  You can
 repeat the macro immediately by typing another @kbd{C-k}, or you can
 rotate the macro ring immediately by typing @kbd{C-n} or @kbd{C-p}.
 
+When a keyboard macro is being defined, @kbd{C-x C-k C-k} behaves like
+@kbd{C-x )} except that, immediately afterward, you can use most key
+bindings of this section without the @kbd{C-x C-k} prefix.  For
+instance, another @kbd{C-k} will re-execute the macro.
+
 @findex kmacro-cycle-ring-next
 @kindex C-x C-k C-n
 @findex kmacro-cycle-ring-previous
 @kindex C-x C-k C-p
   The commands @kbd{C-x C-k C-n} (@code{kmacro-cycle-ring-next}) and
-@kbd{C-x C-k C-p} (@code{kmacro-cycle-ring-previous}) rotates the
+@kbd{C-x C-k C-p} (@code{kmacro-cycle-ring-previous}) rotate the
 macro ring, bringing the next or previous keyboard macro to the head
 of the macro ring.  The definition of the new head macro is displayed
 in the echo area.  You can continue to rotate the macro ring
 immediately by repeating just @kbd{C-n} and @kbd{C-p} until the
 desired macro is at the head of the ring.  To execute the new macro
-ring head immediately, just type @kbd{C-k}.  
+ring head immediately, just type @kbd{C-k}.
+
+  Note that Emacs treats the head of the macro ring as the ``last
+defined keyboard macro''.  For instance, it is the keyboard macro that
+@kbd{C-x e} will execute.
 
 @findex kmacro-view-macro-repeat
 @kindex C-x C-k C-v
 
-  The commands @kbd{C-x C-k C-v} (@code{kmacro-view-macro-repeat})
+  The command @kbd{C-x C-k C-v} (@code{kmacro-view-macro-repeat})
 displays the last keyboard macro, or when repeated (with @kbd{C-v}),
 it displays the previous macro on the macro ring, just like @kbd{C-x
 C-k C-p}, but without actually rotating the macro ring.  If you enter
 @kbd{C-k} immediately after displaying a macro from the ring, that
 macro is executed, but still without altering the macro ring.
 
-  So while e.g. @kbd{C-x C-k C-p C-p C-k C-k} makes the 3rd previous
+  So while e.g. @kbd{C-x C-k C-p C-p C-p C-k C-k} makes the 3rd previous
 macro the current macro and executes it twice, @kbd{C-x C-k C-v C-v
 C-v C-k C-k} will display and execute the 3rd previous macro once and
 then the current macro once.
@@ -238,7 +252,7 @@ then the current macro once.
 @findex kmacro-delete-ring-head
 @kindex C-x C-k C-d
 
-  The commands @kbd{C-x C-k C-d} (@code{kmacro-delete-ring-head})
+  The command @kbd{C-x C-k C-d} (@code{kmacro-delete-ring-head})
 removes and deletes the macro currently at the head of the macro
 ring.  You can use this to delete a macro that didn't work as
 expected, or which you don't need anymore.
@@ -246,33 +260,35 @@ expected, or which you don't need anymore.
 @findex kmacro-swap-ring
 @kindex C-x C-k C-t
 
-  The commands @kbd{C-x C-k C-t} (@code{kmacro-swap-ring})
+  The command @kbd{C-x C-k C-t} (@code{kmacro-swap-ring})
 interchanges the head of the macro ring with the previous element on
 the macro ring.
 
 @findex kmacro-call-ring-2nd-repeat
 @kindex C-x C-k C-l
 
-  The commands @kbd{C-x C-k C-l} (@code{kmacro-call-ring-2nd-repeat})
+  The command @kbd{C-x C-k C-l} (@code{kmacro-call-ring-2nd-repeat})
 executes the previous (rather than the head) element on the macro ring.
 
+@vindex kmacro-ring-max
+  The maximum number of macros stored in the keyboard macro ring is
+determined by the customizable variable @code{kmacro-ring-max}.
+
 @node Keyboard Macro Counter
-@section Inserting incrementing numbers in macros
+@section The Keyboard Macro Counter
 
-  Each keyboard macro has an associated counter which is automatically
-incremented on every repetition of the keyboard macro.  Normally, the
+  Each keyboard macro has an associated counter.  Normally, the
 macro counter is initialized to 0 when you start defining the macro,
 and incremented by 1 after each insertion of the counter value;
 that is, if you insert the macro counter twice while defining the
-macro, it will be incremented by 2 time for each repetition of the
-macro.
+macro, the counter will increase by 2 on each repetition of the macro.
 
 @findex kmacro-insert-counter
 @kindex C-x C-k C-i
   The command @kbd{C-x C-k C-i} (@code{kmacro-insert-counter}) inserts
 the current value of the keyboard macro counter and increments the
 counter by 1.  You can use a numeric prefix argument to specify a
-different increment.  If you specify a @kbd{C-u} prefix, the last
+different increment.  If you just specify a @kbd{C-u} prefix, the last
 inserted counter value is repeated and the counter is not incremented.
 For example, if you enter the following sequence while defining a macro
 
@@ -285,30 +301,65 @@ the text @samp{0112} is inserted in the buffer, and for the first and
 second execution of the macro @samp{3445} and @samp{6778} are
 inserted.
 
+  This command usually only makes sense while defining a keyboard macro.
+But its behavior when no keyboard macro is being defined or executed
+is predictable: it inserts and increments the counter of the head of
+the keyboard macro ring.
+
 @findex kmacro-set-counter
 @kindex C-x C-k C-c
   The command @kbd{C-x C-k C-c} (@code{kmacro-set-counter}) prompts
 for the initial value of the keyboard macro counter if you use it
-before you define a keyboard macro.  If you use it while defining a
-keyboard macro, you set the macro counter to the same (initial) value
-on each repetition of the macro.  If you specify a @kbd{C-u} prefix,
-the counter is reset to the value it had prior to the current
-repetition of the macro (undoing any increments so far in this
-repetition).
+before you define a keyboard macro.  If you use it before executing a
+keyboard macro, it resets that macro's counter.  If you use it while
+defining a keyboard macro, then the macro counter gets reset to that same
+value on each repetition of the macro.  Rather than having the command
+prompt for a value, you can also specify the value with a numeric
+prefix argument.  If you just specify a @kbd{C-u} prefix, the counter
+is reset to the value it had prior to the current repetition of the
+macro (undoing any increments so far in this repetition).  If you just
+specify a @kbd{C-u} prefix while no macro is being defined or executed,
+then the new value of the counter is essentially unpredictable.
 
 @findex kmacro-add-counter
 @kindex C-x C-k C-a
   The command @kbd{C-x C-k C-a} (@code{kmacro-add-counter}) prompts
-for a value to add to the macro counter.
+for a value to add to the macro counter.  You can also specify the
+value with a numeric prefix argument.  If you just specify a @kbd{C-u}
+prefix, the counter is reset to the last value inserted by any
+keyboard macro.  Usually, this will only make sense if that value was
+inserted during the current macro definition or repetition.
+
+  This command normally only makes sense while defining a keyboard macro.
+But its behavior when no keyboard macro is being defined or executed
+is predictable: it affects the counter of the head of the keyboard
+macro ring.
 
 @findex kmacro-set-format
 @kindex C-x C-k C-f
-  The command @kbd{C-x C-k C-f} (@code{kmacro-set-format}) prompts
-for the format to use when inserting the macro counter.  The default
-format is @samp{%d}.  If you set the counter format before you define a
-macro, that format is restored before each repetition of the macro.
-Consequently, any changes you make to the macro counter format while
-defining a macro are only active for the rest of the macro.
+  The command @kbd{C-x C-k C-f} (@code{kmacro-set-format}) prompts for
+the format to use when inserting the macro counter.  The default
+format is @samp{%d}, which means to insert the number in decimal
+without any padding.  You can exit with empty minibuffer to reset the
+format to this default.  You can specify any format string that the
+@code{format} function accepts and that makes sense with a single
+integer extra argument (@pxref{Formatting Strings,,, elisp, The Emacs
+Lisp Reference Manual}).  Do not put the format string inside double
+quotes when you insert it in the minibuffer.
+
+If you use this command while no keyboard macro is being defined or
+executed, the new format affects all subsequent macro definitions.
+Existing macros continue to use the format in effect when they were
+defined.  If you set the format while defining a keyboard macro, this
+affects the macro being defined from that point on, but it does not
+affect subsequent macros.  Execution of the macro will, at each step,
+use the format in effect at that step during its definition.  Changes
+to the macro format during execution of a macro, like the
+corresponding changes during its definition, have no effect on
+subsequent macros.
+
+The format set by @kbd{C-x C-k C-f} does not affect insertion of
+numbers stored in registers.
 
 @node Keyboard Macro Query
 @section Executing Macros with Variations
@@ -358,28 +409,30 @@ register as a counter, incrementing it on each repetition of the macro.
 @section Naming and Saving Keyboard Macros
 
 @cindex saving keyboard macros
-@findex name-last-kbd-macro
+@findex kmacro-name-last-macro
 @kindex C-x C-k n
   If you wish to save a keyboard macro for later use, you can give it
-a name using @kbd{C-x C-k n} (@code{name-last-kbd-macro}). 
-This reads a name as an argument using the minibuffer and defines that name
-to execute the macro.  The macro name is a Lisp symbol, and defining it in
-this way makes it a valid command name for calling with @kbd{M-x} or for
-binding a key to with @code{global-set-key} (@pxref{Keymaps}).  If you
-specify a name that has a prior definition other than another keyboard
-macro, an error message is shown and nothing is changed.
+a name using @kbd{C-x C-k n} (@code{kmacro-name-last-macro}).
+This reads a name as an argument using the minibuffer and defines that
+name to execute the last keyboard macro, in its current form.  (If you
+later add to the definition of this macro, that does not alter the
+name's definition as a macro.)  The macro name is a Lisp symbol, and
+defining it in this way makes it a valid command name for calling with
+@kbd{M-x} or for binding a key to with @code{global-set-key}
+(@pxref{Keymaps}).  If you specify a name that has a prior definition
+other than a keyboard macro, an error message is shown and nothing is
+changed.
 
 @cindex binding keyboard macros
 @findex kmacro-bind-to-key
 @kindex C-x C-k b
-  Rather than giving a keyboard macro a name, you can bind it to a
-key using @kbd{C-x C-k b} (@code{kmacro-bind-to-key}) followed by the
-key sequence you want the keyboard macro to be bound to.  You can
-bind to any key sequence in the global keymap, but since most key
-sequences already have other bindings, you should select the key
-sequence carefylly.  If you try to bind to a key sequence with an
-existing binding (in any keymap), you will be asked if you really
-want to replace the existing binding of that key.
+  You can also bind the last keyboard macro (in its current form) to a
+key, using @kbd{C-x C-k b} (@code{kmacro-bind-to-key}) followed by the
+key sequence you want to bind.  You can bind to any key sequence in
+the global keymap, but since most key sequences already have other
+bindings, you should select the key sequence carefully.  If you try to
+bind to a key sequence with an existing binding (in any keymap), this
+command asks you for confirmation before replacing the existing binding.
 
 To avoid problems caused by overriding existing bindings, the key
 sequences @kbd{C-x C-k 0} through @kbd{C-x C-k 9} and @kbd{C-x C-k A}
@@ -414,12 +467,12 @@ save in is your init file @file{~/.emacs} (@pxref{Init File}) then the
 macro will be defined each time you run Emacs.
 
   If you give @code{insert-kbd-macro} a numeric argument, it makes
-additional Lisp code to record the keys (if any) that you have bound to the
-keyboard macro, so that the macro will be reassigned the same keys when you
-load the file.
+additional Lisp code to record the keys (if any) that you have bound
+to @var{macroname}, so that the macro will be reassigned the same keys
+when you load the file.
 
 @node Edit Keyboard Macro
-@section Interactively executing and editing a keyboard macro
+@section Editing a Keyboard Macro
 
 @findex kmacro-edit-macro
 @kindex C-x C-k C-e
@@ -443,22 +496,20 @@ keyboard input that you would use to invoke the macro---@kbd{C-x e} or
 @kbd{C-x C-k l} (@code{kmacro-edit-lossage}).
 
 @node Keyboard Macro Step-Edit
-@section Interactively executing and editing a keyboard macro
+@section Stepwise Editing a Keyboard Macro
 
 @findex kmacro-step-edit-macro
 @kindex C-x C-k SPC
-  You can interactively and stepwise replay and edit the last keyboard
-macro one command at a time by typing @kbd{C-x C-k SPC} 
+  You can interactively replay and edit the last keyboard
+macro, one command at a time, by typing @kbd{C-x C-k SPC}
 (@code{kmacro-step-edit-macro}).  Unless you quit the macro using
 @kbd{q} or @kbd{C-g}, the edited macro replaces the last macro on the
 macro ring.
 
-This shows the last macro in the minibuffer together with the first
-(or next) command to be executed, and prompts you for an action.
-You can enter @kbd{?} to get a command summary.
-
-The following commands are available in the step-edit mode and relate
-to the first (or current) command in the keyboard macro:
+  This macro editing feature shows the last macro in the minibuffer
+together with the first (or next) command to be executed, and prompts
+you for an action.  You can enter @kbd{?} to get a summary of your
+options.  These actions are available:
 
 @itemize @bullet{}
 @item