diff options
| author | Kim F. Storm | 2003-08-17 22:26:42 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2003-08-17 22:26:42 +0000 |
| commit | a0d0adaf6ab3e109b04d540d55c925e37b970b37 (patch) | |
| tree | 57840a0ed09b39dd559dc6335a3eb99956d402ee | |
| parent | baf2630dd7d96cba636d428c302a9907a0c99ace (diff) | |
| download | emacs-a0d0adaf6ab3e109b04d540d55c925e37b970b37.tar.gz emacs-a0d0adaf6ab3e109b04d540d55c925e37b970b37.zip | |
(Customization): Add xref to Keyboard Macros chapter.
(Keyboard Macros): Move to new kmacro.texi file.
| -rw-r--r-- | man/custom.texi | 233 |
1 files changed, 5 insertions, 228 deletions
diff --git a/man/custom.texi b/man/custom.texi index 4a89f8f086b..9cd3f0baee6 100644 --- a/man/custom.texi +++ b/man/custom.texi | |||
| @@ -19,15 +19,17 @@ between sessions unless you save the customization in a file such as | |||
| 19 | customizations for future sessions, this actually works by editing | 19 | customizations for future sessions, this actually works by editing |
| 20 | @file{.emacs} for you. | 20 | @file{.emacs} for you. |
| 21 | 21 | ||
| 22 | Another means of customization is the keyboard macro, which is a | ||
| 23 | sequence of keystrokes to be replayed with a single command. | ||
| 24 | @xref{Keyboard Macros}, for full instruction how to record, manage, and | ||
| 25 | replay sequences of keys. | ||
| 26 | |||
| 22 | @menu | 27 | @menu |
| 23 | * Minor Modes:: Each minor mode is one feature you can turn on | 28 | * Minor Modes:: Each minor mode is one feature you can turn on |
| 24 | independently of any others. | 29 | independently of any others. |
| 25 | * Variables:: Many Emacs commands examine Emacs variables | 30 | * Variables:: Many Emacs commands examine Emacs variables |
| 26 | to decide what to do; by setting variables, | 31 | to decide what to do; by setting variables, |
| 27 | you can control their functioning. | 32 | you can control their functioning. |
| 28 | * Keyboard Macros:: A keyboard macro records a sequence of | ||
| 29 | keystrokes to be replayed with a single | ||
| 30 | command. | ||
| 31 | * Key Bindings:: The keymaps say what command each key runs. | 33 | * Key Bindings:: The keymaps say what command each key runs. |
| 32 | By changing them, you can "redefine keys". | 34 | By changing them, you can "redefine keys". |
| 33 | * Keyboard Translations:: | 35 | * Keyboard Translations:: |
| @@ -1058,231 +1060,6 @@ value are @code{t}, @code{nil}, and anything else, just as for | |||
| 1058 | neither @code{t} nor @code{nil}, so normally Emacs does ask for | 1060 | neither @code{t} nor @code{nil}, so normally Emacs does ask for |
| 1059 | confirmation about file settings for these variables. | 1061 | confirmation about file settings for these variables. |
| 1060 | 1062 | ||
| 1061 | @node Keyboard Macros | ||
| 1062 | @section Keyboard Macros | ||
| 1063 | |||
| 1064 | @cindex defining keyboard macros | ||
| 1065 | @cindex keyboard macro | ||
| 1066 | A @dfn{keyboard macro} is a command defined by the user to stand for | ||
| 1067 | another sequence of keys. For example, if you discover that you are | ||
| 1068 | about to type @kbd{C-n C-d} forty times, you can speed your work by | ||
| 1069 | defining a keyboard macro to do @kbd{C-n C-d} and calling it with a | ||
| 1070 | repeat count of forty. | ||
| 1071 | |||
| 1072 | @table @kbd | ||
| 1073 | @item C-x ( | ||
| 1074 | Start defining a keyboard macro (@code{start-kbd-macro}). | ||
| 1075 | @item C-x ) | ||
| 1076 | End the definition of a keyboard macro (@code{end-kbd-macro}). | ||
| 1077 | @item C-x e | ||
| 1078 | Execute the most recent keyboard macro (@code{call-last-kbd-macro}). | ||
| 1079 | @item C-u C-x ( | ||
| 1080 | Re-execute last keyboard macro, then add more keys to its definition. | ||
| 1081 | @item C-x q | ||
| 1082 | When this point is reached during macro execution, ask for confirmation | ||
| 1083 | (@code{kbd-macro-query}). | ||
| 1084 | @item M-x name-last-kbd-macro | ||
| 1085 | Give a command name (for the duration of the session) to the most | ||
| 1086 | recently defined keyboard macro. | ||
| 1087 | @item M-x insert-kbd-macro | ||
| 1088 | Insert in the buffer a keyboard macro's definition, as Lisp code. | ||
| 1089 | @item C-x C-k | ||
| 1090 | Edit a previously defined keyboard macro (@code{edit-kbd-macro}). | ||
| 1091 | @item M-x apply-macro-to-region-lines | ||
| 1092 | Run the last keyboard macro on each complete line in the region. | ||
| 1093 | @end table | ||
| 1094 | |||
| 1095 | Keyboard macros differ from ordinary Emacs commands in that they are | ||
| 1096 | written in the Emacs command language rather than in Lisp. This makes it | ||
| 1097 | easier for the novice to write them, and makes them more convenient as | ||
| 1098 | temporary hacks. However, the Emacs command language is not powerful | ||
| 1099 | enough as a programming language to be useful for writing anything | ||
| 1100 | intelligent or general. For such things, Lisp must be used. | ||
| 1101 | |||
| 1102 | You define a keyboard macro while executing the commands which are the | ||
| 1103 | definition. Put differently, as you define a keyboard macro, the | ||
| 1104 | definition is being executed for the first time. This way, you can see | ||
| 1105 | what the effects of your commands are, so that you don't have to figure | ||
| 1106 | them out in your head. When you are finished, the keyboard macro is | ||
| 1107 | defined and also has been, in effect, executed once. You can then do the | ||
| 1108 | whole thing over again by invoking the macro. | ||
| 1109 | |||
| 1110 | @menu | ||
| 1111 | * Basic Kbd Macro:: Defining and running keyboard macros. | ||
| 1112 | * Save Kbd Macro:: Giving keyboard macros names; saving them in files. | ||
| 1113 | * Kbd Macro Query:: Making keyboard macros do different things each time. | ||
| 1114 | @end menu | ||
| 1115 | |||
| 1116 | @node Basic Kbd Macro | ||
| 1117 | @subsection Basic Use | ||
| 1118 | |||
| 1119 | @kindex C-x ( | ||
| 1120 | @kindex C-x ) | ||
| 1121 | @kindex C-x e | ||
| 1122 | @findex start-kbd-macro | ||
| 1123 | @findex end-kbd-macro | ||
| 1124 | @findex call-last-kbd-macro | ||
| 1125 | To start defining a keyboard macro, type the @kbd{C-x (} command | ||
| 1126 | (@code{start-kbd-macro}). From then on, your keys continue to be | ||
| 1127 | executed, but also become part of the definition of the macro. @samp{Def} | ||
| 1128 | appears in the mode line to remind you of what is going on. When you are | ||
| 1129 | finished, the @kbd{C-x )} command (@code{end-kbd-macro}) terminates the | ||
| 1130 | definition (without becoming part of it!). For example, | ||
| 1131 | |||
| 1132 | @example | ||
| 1133 | C-x ( M-f foo C-x ) | ||
| 1134 | @end example | ||
| 1135 | |||
| 1136 | @noindent | ||
| 1137 | defines a macro to move forward a word and then insert @samp{foo}. | ||
| 1138 | |||
| 1139 | The macro thus defined can be invoked again with the @kbd{C-x e} | ||
| 1140 | command (@code{call-last-kbd-macro}), which may be given a repeat count | ||
| 1141 | as a numeric argument to execute the macro many times. @kbd{C-x )} can | ||
| 1142 | also be given a repeat count as an argument, in which case it repeats | ||
| 1143 | the macro that many times right after defining it, but defining the | ||
| 1144 | macro counts as the first repetition (since it is executed as you define | ||
| 1145 | it). Therefore, giving @kbd{C-x )} an argument of 4 executes the macro | ||
| 1146 | immediately 3 additional times. An argument of zero to @kbd{C-x e} or | ||
| 1147 | @kbd{C-x )} means repeat the macro indefinitely (until it gets an error | ||
| 1148 | or you type @kbd{C-g} or, on MS-DOS, @kbd{C-@key{BREAK}}). | ||
| 1149 | |||
| 1150 | If you wish to repeat an operation at regularly spaced places in the | ||
| 1151 | text, define a macro and include as part of the macro the commands to move | ||
| 1152 | to the next place you want to use it. For example, if you want to change | ||
| 1153 | each line, you should position point at the start of a line, and define a | ||
| 1154 | macro to change that line and leave point at the start of the next line. | ||
| 1155 | Then repeating the macro will operate on successive lines. | ||
| 1156 | |||
| 1157 | When a command reads an argument with the minibuffer, your | ||
| 1158 | minibuffer input becomes part of the macro along with the command. So | ||
| 1159 | when you replay the macro, the command gets the same argument as | ||
| 1160 | when you entered the macro. For example, | ||
| 1161 | |||
| 1162 | @example | ||
| 1163 | C-x ( C-a C-@key{SPC} C-n M-w C-x b f o o @key{RET} C-y C-x b @key{RET} C-x ) | ||
| 1164 | @end example | ||
| 1165 | |||
| 1166 | @noindent | ||
| 1167 | defines a macro that copies the current line into the buffer | ||
| 1168 | @samp{foo}, then returns to the original buffer. | ||
| 1169 | |||
| 1170 | You can use function keys in a keyboard macro, just like keyboard | ||
| 1171 | keys. You can even use mouse events, but be careful about that: when | ||
| 1172 | the macro replays the mouse event, it uses the original mouse position | ||
| 1173 | of that event, the position that the mouse had while you were defining | ||
| 1174 | the macro. The effect of this may be hard to predict. (Using the | ||
| 1175 | current mouse position would be even less predictable.) | ||
| 1176 | |||
| 1177 | One thing that doesn't always work well in a keyboard macro is the | ||
| 1178 | command @kbd{C-M-c} (@code{exit-recursive-edit}). When this command | ||
| 1179 | exits a recursive edit that started within the macro, it works as you'd | ||
| 1180 | expect. But if it exits a recursive edit that started before you | ||
| 1181 | invoked the keyboard macro, it also necessarily exits the keyboard macro | ||
| 1182 | as part of the process. | ||
| 1183 | |||
| 1184 | After you have terminated the definition of a keyboard macro, you can add | ||
| 1185 | to the end of its definition by typing @kbd{C-u C-x (}. This is equivalent | ||
| 1186 | to plain @kbd{C-x (} followed by retyping the whole definition so far. As | ||
| 1187 | a consequence it re-executes the macro as previously defined. | ||
| 1188 | |||
| 1189 | @findex edit-kbd-macro | ||
| 1190 | @kindex C-x C-k | ||
| 1191 | You can edit a keyboard macro already defined by typing @kbd{C-x C-k} | ||
| 1192 | (@code{edit-kbd-macro}). Follow that with the keyboard input that you | ||
| 1193 | would use to invoke the macro---@kbd{C-x e} or @kbd{M-x @var{name}} or | ||
| 1194 | some other key sequence. This formats the macro definition in a buffer | ||
| 1195 | and enters a specialized major mode for editing it. Type @kbd{C-h m} | ||
| 1196 | once in that buffer to display details of how to edit the macro. When | ||
| 1197 | you are finished editing, type @kbd{C-c C-c}. | ||
| 1198 | |||
| 1199 | @findex apply-macro-to-region-lines | ||
| 1200 | The command @kbd{M-x apply-macro-to-region-lines} repeats the last | ||
| 1201 | defined keyboard macro on each complete line within the current region. | ||
| 1202 | It does this line by line, by moving point to the beginning of the line | ||
| 1203 | and then executing the macro. | ||
| 1204 | |||
| 1205 | @node Save Kbd Macro | ||
| 1206 | @subsection Naming and Saving Keyboard Macros | ||
| 1207 | |||
| 1208 | @cindex saving keyboard macros | ||
| 1209 | @findex name-last-kbd-macro | ||
| 1210 | If you wish to save a keyboard macro for longer than until you define the | ||
| 1211 | next one, you must give it a name using @kbd{M-x name-last-kbd-macro}. | ||
| 1212 | This reads a name as an argument using the minibuffer and defines that name | ||
| 1213 | to execute the macro. The macro name is a Lisp symbol, and defining it in | ||
| 1214 | this way makes it a valid command name for calling with @kbd{M-x} or for | ||
| 1215 | binding a key to with @code{global-set-key} (@pxref{Keymaps}). If you | ||
| 1216 | specify a name that has a prior definition other than another keyboard | ||
| 1217 | macro, an error message is shown and nothing is changed. | ||
| 1218 | |||
| 1219 | @findex insert-kbd-macro | ||
| 1220 | Once a macro has a command name, you can save its definition in a file. | ||
| 1221 | Then it can be used in another editing session. First, visit the file | ||
| 1222 | you want to save the definition in. Then use this command: | ||
| 1223 | |||
| 1224 | @example | ||
| 1225 | M-x insert-kbd-macro @key{RET} @var{macroname} @key{RET} | ||
| 1226 | @end example | ||
| 1227 | |||
| 1228 | @noindent | ||
| 1229 | This inserts some Lisp code that, when executed later, will define the | ||
| 1230 | same macro with the same definition it has now. (You need not | ||
| 1231 | understand Lisp code to do this, because @code{insert-kbd-macro} writes | ||
| 1232 | the Lisp code for you.) Then save the file. You can load the file | ||
| 1233 | later with @code{load-file} (@pxref{Lisp Libraries}). If the file you | ||
| 1234 | save in is your init file @file{~/.emacs} (@pxref{Init File}) then the | ||
| 1235 | macro will be defined each time you run Emacs. | ||
| 1236 | |||
| 1237 | If you give @code{insert-kbd-macro} a numeric argument, it makes | ||
| 1238 | additional Lisp code to record the keys (if any) that you have bound to the | ||
| 1239 | keyboard macro, so that the macro will be reassigned the same keys when you | ||
| 1240 | load the file. | ||
| 1241 | |||
| 1242 | @node Kbd Macro Query | ||
| 1243 | @subsection Executing Macros with Variations | ||
| 1244 | |||
| 1245 | @kindex C-x q | ||
| 1246 | @findex kbd-macro-query | ||
| 1247 | Using @kbd{C-x q} (@code{kbd-macro-query}), you can get an effect | ||
| 1248 | similar to that of @code{query-replace}, where the macro asks you each | ||
| 1249 | time around whether to make a change. While defining the macro, | ||
| 1250 | type @kbd{C-x q} at the point where you want the query to occur. During | ||
| 1251 | macro definition, the @kbd{C-x q} does nothing, but when you run the | ||
| 1252 | macro later, @kbd{C-x q} asks you interactively whether to continue. | ||
| 1253 | |||
| 1254 | The valid responses when @kbd{C-x q} asks are @key{SPC} (or @kbd{y}), | ||
| 1255 | @key{DEL} (or @kbd{n}), @key{RET} (or @kbd{q}), @kbd{C-l} and @kbd{C-r}. | ||
| 1256 | The answers are the same as in @code{query-replace}, though not all of | ||
| 1257 | the @code{query-replace} options are meaningful. | ||
| 1258 | |||
| 1259 | These responses include @key{SPC} to continue, and @key{DEL} to skip | ||
| 1260 | the remainder of this repetition of the macro and start right away with | ||
| 1261 | the next repetition. @key{RET} means to skip the remainder of this | ||
| 1262 | repetition and cancel further repetitions. @kbd{C-l} redraws the screen | ||
| 1263 | and asks you again for a character to say what to do. | ||
| 1264 | |||
| 1265 | @kbd{C-r} enters a recursive editing level, in which you can perform | ||
| 1266 | editing which is not part of the macro. When you exit the recursive | ||
| 1267 | edit using @kbd{C-M-c}, you are asked again how to continue with the | ||
| 1268 | keyboard macro. If you type a @key{SPC} at this time, the rest of the | ||
| 1269 | macro definition is executed. It is up to you to leave point and the | ||
| 1270 | text in a state such that the rest of the macro will do what you | ||
| 1271 | want.@refill | ||
| 1272 | |||
| 1273 | @kbd{C-u C-x q}, which is @kbd{C-x q} with a numeric argument, | ||
| 1274 | performs a completely different function. It enters a recursive edit | ||
| 1275 | reading input from the keyboard, both when you type it during the | ||
| 1276 | definition of the macro, and when it is executed from the macro. During | ||
| 1277 | definition, the editing you do inside the recursive edit does not become | ||
| 1278 | part of the macro. During macro execution, the recursive edit gives you | ||
| 1279 | a chance to do some particularized editing on each repetition. | ||
| 1280 | @xref{Recursive Edit}. | ||
| 1281 | |||
| 1282 | Another way to vary the behavior of a keyboard macro is to use a | ||
| 1283 | register as a counter, incrementing it on each repetition of the macro. | ||
| 1284 | @xref{RegNumbers}. | ||
| 1285 | |||
| 1286 | @node Key Bindings | 1063 | @node Key Bindings |
| 1287 | @section Customizing Key Bindings | 1064 | @section Customizing Key Bindings |
| 1288 | @cindex key bindings | 1065 | @cindex key bindings |