]> code.delx.au - gnu-emacs/blobdiff - man/kmacro.texi
(Face Resources): Split table into font resources and the rest.
[gnu-emacs] / man / kmacro.texi
index 5ef34f6c929b1015f2ea1638de97c350052e7177..7f14c40a95bfd36ec6352cf82112045acd8d5846 100644 (file)
@@ -1,28 +1,28 @@
 @c This is part of the Emacs manual.
-@c Copyright (C) 1985,86,87,93,94,95,97,2000,2001,2002,2003,2004
-@c  Free Software Foundation, Inc.
+@c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2000, 2001,
+@c   2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 @c See file emacs.texi for copying conditions.
 @node Keyboard Macros, Files, Fixit, Top
 @chapter Keyboard Macros
 @cindex defining keyboard macros
 @cindex keyboard macro
 
-  In this chapter we describe how a sequence of editing commands can
-be recorded and repeated multiple times.
+  In this chapter we describe how to record a sequence of editing
+commands so you can repeat it conveniently later.
 
-  A @dfn{keyboard macro} is a command defined by the user to stand for
+  A @dfn{keyboard macro} is a command defined by an Emacs user to stand for
 another sequence of keys.  For example, if you discover that you are
-about to type @kbd{C-n C-d} forty times, you can speed your work by
-defining a keyboard macro to do @kbd{C-n C-d} and calling it with a
-repeat count of forty.
-
-  You define a keyboard macro while executing the commands which are the
-definition.  Put differently, as you define a keyboard macro, the
-definition is being executed for the first time.  This way, you can see
-what the effects of your commands are, so that you don't have to figure
-them out in your head.  When you are finished, the keyboard macro is
-defined and also has been, in effect, executed once.  You can then do the
-whole thing over again by invoking the macro.
+about to type @kbd{C-n M-d C-d} forty times, you can speed your work by
+defining a keyboard macro to do @kbd{C-n M-d C-d}, and then executing
+it 39 more times.
+
+  You define a keyboard macro by executing and recording the commands
+which are its definition.  Put differently, as you define a keyboard
+macro, the definition is being executed for the first time.  This way,
+you can see the effects of your commands, so that you don't have to
+figure them out in your head.  When you close the definition, the
+keyboard macro is defined and also has been, in effect, executed once.
+You can then do the whole thing over again by invoking the macro.
 
   Keyboard macros differ from ordinary Emacs commands in that they are
 written in the Emacs command language rather than in Lisp.  This makes it
@@ -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
@@ -62,19 +63,6 @@ execute the most recent keyboard macro
 Re-execute last keyboard macro, then add more keys to its definition.
 @item C-u C-u C-x (
 Add more keys to the last keyboard macro without re-executing it.
-@item C-x q
-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{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}).
-@item M-x insert-kbd-macro
-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 line that begins in the region
 (@code{apply-macro-to-region-lines}).
@@ -156,12 +144,12 @@ of that event, the position that the mouse had while you were defining
 the macro.  The effect of this may be hard to predict.  (Using the
 current mouse position would be even less predictable.)
 
-  One thing that doesn't always work well in a keyboard macro is the
+  One thing that sometimes works badly in a keyboard macro is the
 command @kbd{C-M-c} (@code{exit-recursive-edit}).  When this command
-exits a recursive edit that started within the macro, it works as you'd
-expect.  But if it exits a recursive edit that started before you
-invoked the keyboard macro, it also necessarily exits the keyboard macro
-as part of the process.
+exits a recursive edit that started within the macro, it works as
+you'd expect.  But if it exits a recursive edit that started before
+you invoked the keyboard macro, it also necessarily exits the keyboard
+macro as part of the process.
 
   After you have terminated the definition of a keyboard macro, you can add
 to the end of its definition by typing @kbd{C-u C-x (}.  This is equivalent
@@ -189,6 +177,17 @@ beginning of the line and then executing the macro.
 a list of sequences of keys.  There is only one keyboard macro ring,
 shared by all buffers.
 
+@table @kbd
+@item C-x C-k C-k
+Execute the keyboard macro at the head of the ring (@code{kmacro-end-or-call-macro-repeat}).
+@item C-x C-k C-n
+Rotate the keyboard macro ring to the next macro (defined earlier)
+(@code{kmacro-cycle-ring-next}).
+@item C-x C-k C-p
+Rotate the keyboard macro ring to the previous macro (defined later)
+(@code{kmacro-cycle-ring-previous}).
+@end table
+
   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
@@ -211,7 +210,7 @@ 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
+  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.
@@ -230,12 +229,13 @@ desired macro is at the head of the ring.  To execute the new macro
 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.
+defined keyboard macro.''  For instance, @kbd{C-x e} will execute that
+macro, and @kbd{C-x C-k n} will give it a name.
 
+@ignore  @c This interface is too kludgy
+  @c and the functionality duplicates the functionality above -- rms.
 @findex kmacro-view-macro-repeat
 @kindex C-x C-k C-v
-
   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
@@ -247,7 +247,11 @@ macro is executed, but still without altering the macro ring.
 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.
+@end ignore
 
+@ignore  @c This is just too much feeping creaturism.
+ @c If you are reusing certain macros enough to want these,
+ @c you should give then names. -- rms
 @findex kmacro-delete-ring-head
 @kindex C-x C-k C-d
 
@@ -268,6 +272,7 @@ the macro ring.
 
   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.
+@end ignore
 
 @vindex kmacro-ring-max
   The maximum number of macros stored in the keyboard macro ring is
@@ -276,6 +281,19 @@ determined by the customizable variable @code{kmacro-ring-max}.
 @node Keyboard Macro Counter
 @section The Keyboard Macro Counter
 
+@table @kbd
+@item C-x C-k C-i
+Insert the keyboard macro counter value in the buffer
+(@code{kmacro-insert-counter}).
+@item C-x C-k C-c
+Set the keyboard macro counter (@code{kmacro-set-counter}).
+@item C-x C-k C-a
+Add the prefix arg to the keyboard macro counter (@code{kmacro-add-counter}).
+@item C-x C-k C-f
+Specify the format for inserting the keyboard macro counter
+(@code{kmacro-set-format}).
+@end table
+
   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;
@@ -285,54 +303,43 @@ 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 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
+the current value of the current keyboard macro's counter, and
+increments the counter by 1.  You can use a numeric prefix argument to
+specify a different increment.  If you just specify a @kbd{C-u}
+prefix, then the increment is zero, so it repeats the last inserted
+counter value.  For example, if you enter the following sequence while
+defining a macro
 
 @example
 C-x C-k C-i C-x C-k C-i C-u C-x C-k C-i C-x C-k C-i
 @end example
 
 @noindent
-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.
+it inserts @samp{0112} in the buffer.  The next two iterations
+of the macro will insert @samp{3445} and @samp{6778}.
 
-  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.
+  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
+macro at 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 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.
+  The command @kbd{C-x C-k C-c} (@code{kmacro-set-counter}) sets the
+current macro counter to the value of the numeric argument.  If you use
+it inside the macro, it operates on each repetition of the macro.  If
+you specify just @kbd{C-u} as the prefix, while executing the macro,
+that resets the counter to the value it had at the beginning of the
+current repetition of the macro (undoing any increments so far in this
+repetition).
 
 @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.  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.
+  The command @kbd{C-x C-k C-a} (@code{kmacro-add-counter}) adds the
+prefix argument to the current macro counter.  With just @kbd{C-u} as
+argument, it resets the counter to the last value inserted by any
+keyboard macro.  (Normally, when you use this, the last insertion
+will be in the same macro and it will be the same counter.)
 
 @findex kmacro-set-format
 @kindex C-x C-k C-f
@@ -346,7 +353,7 @@ 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
+  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
@@ -357,12 +364,18 @@ 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
+  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
 
+@table @kbd
+@item C-x q
+When this point is reached during macro execution, ask for confirmation
+(@code{kbd-macro-query}).
+@end table
+
 @kindex C-x q
 @findex kbd-macro-query
   Using @kbd{C-x q} (@code{kbd-macro-query}), you can get an effect
@@ -407,6 +420,17 @@ register as a counter, incrementing it on each repetition of the macro.
 @node Save Keyboard Macro
 @section Naming and Saving Keyboard Macros
 
+@table @kbd
+@item C-x C-k n
+Give a command name (for the duration of the Emacs session) to the most
+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}).
+@item M-x insert-kbd-macro
+Insert in the buffer a keyboard macro's definition, as Lisp code.
+@end table
+
 @cindex saving keyboard macros
 @findex kmacro-name-last-macro
 @kindex C-x C-k n
@@ -433,7 +457,7 @@ 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
+  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}
 through @kbd{C-x C-k Z} are reserved for your own keyboard macro
 bindings.  In fact, to bind to one of these key sequences, you only
@@ -473,6 +497,16 @@ when you load the file.
 @node Edit Keyboard Macro
 @section Editing a Keyboard Macro
 
+@table @kbd
+@item C-x C-k C-e
+Edit the last defined keyboard macro (@code{kmacro-edit-macro}).
+@item C-x C-k e @var{name} @key{RET}
+Edit a previously defined keyboard macro @var{name} (@code{edit-kbd-macro}).
+@item C-x C-k l
+Edit the last 100 keystrokes as a keyboard macro
+(@code{kmacro-edit-lossage}).
+@end table
+
 @findex kmacro-edit-macro
 @kindex C-x C-k C-e
 @kindex C-x C-k RET
@@ -520,8 +554,8 @@ next command in the keyboard macro.
 @kbd{f} skips the current command in this execution of the keyboard
 macro, but doesn't delete it from the macro.
 @item
-@kbd{TAB} executes the current command, as well as all similar
-commands immediately following the current command; for example, TAB
+@kbd{@key{TAB}} executes the current command, as well as all similar
+commands immediately following the current command; for example, @key{TAB}
 may be used to insert a sequence of characters (corresponding to a
 sequence of @code{self-insert-command} commands).
 @item