diff options
| author | Kim F. Storm | 2002-08-14 10:35:31 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2002-08-14 10:35:31 +0000 |
| commit | f90d3a6bffc7e48fdf3b0fd8198cda679477cec6 (patch) | |
| tree | ec7d43d68f462f123ef60d2c0ec58b1e0b0c8e6d /src | |
| parent | a361276f071e444994fad6aa5248c36fa45966f4 (diff) | |
| download | emacs-f90d3a6bffc7e48fdf3b0fd8198cda679477cec6.tar.gz emacs-f90d3a6bffc7e48fdf3b0fd8198cda679477cec6.zip | |
(Fstart_kbd_macro): Added NO-EXEC argument to inhibit
executing macro before appending to it (when used from Lisp).
(Fexecute_kbd_macro): Added LOOPFUNC argument to supply function
which is called prior to each iteration of macro (for kmacro.el).
(Fend_kbd_macro, Fcall_last_kbd_macro): Likewise.
Diffstat (limited to 'src')
| -rw-r--r-- | src/macros.c | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/src/macros.c b/src/macros.c index 5f6d83b52d6..e9601b1aa7f 100644 --- a/src/macros.c +++ b/src/macros.c | |||
| @@ -55,15 +55,17 @@ extern Lisp_Object real_this_command; | |||
| 55 | 55 | ||
| 56 | Lisp_Object Fexecute_kbd_macro (); | 56 | Lisp_Object Fexecute_kbd_macro (); |
| 57 | 57 | ||
| 58 | DEFUN ("start-kbd-macro", Fstart_kbd_macro, Sstart_kbd_macro, 1, 1, "P", | 58 | DEFUN ("start-kbd-macro", Fstart_kbd_macro, Sstart_kbd_macro, 1, 2, "P", |
| 59 | doc: /* Record subsequent keyboard input, defining a keyboard macro. | 59 | doc: /* Record subsequent keyboard input, defining a keyboard macro. |
| 60 | The commands are recorded even as they are executed. | 60 | The commands are recorded even as they are executed. |
| 61 | Use \\[end-kbd-macro] to finish recording and make the macro available. | 61 | Use \\[end-kbd-macro] to finish recording and make the macro available. |
| 62 | Use \\[name-last-kbd-macro] to give it a permanent name. | 62 | Use \\[name-last-kbd-macro] to give it a permanent name. |
| 63 | Non-nil arg (prefix arg) means append to last macro defined; | 63 | Non-nil arg (prefix arg) means append to last macro defined; |
| 64 | this begins by re-executing that macro as if you typed it again. */) | 64 | this begins by re-executing that macro as if you typed it again. |
| 65 | (append) | 65 | If optional second arg, NO-EXEC, is non-nil, do not re-execute last |
| 66 | Lisp_Object append; | 66 | macro before appending to it. */) |
| 67 | (append, no_exec) | ||
| 68 | Lisp_Object append, no_exec; | ||
| 67 | { | 69 | { |
| 68 | if (!NILP (current_kboard->defining_kbd_macro)) | 70 | if (!NILP (current_kboard->defining_kbd_macro)) |
| 69 | error ("Already defining kbd macro"); | 71 | error ("Already defining kbd macro"); |
| @@ -118,8 +120,9 @@ this begins by re-executing that macro as if you typed it again. */) | |||
| 118 | 120 | ||
| 119 | /* Re-execute the macro we are appending to, | 121 | /* Re-execute the macro we are appending to, |
| 120 | for consistency of behavior. */ | 122 | for consistency of behavior. */ |
| 121 | Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, | 123 | if (NILP (no_exec)) |
| 122 | make_number (1)); | 124 | Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, |
| 125 | make_number (1), Qnil); | ||
| 123 | 126 | ||
| 124 | message ("Appending to kbd macro..."); | 127 | message ("Appending to kbd macro..."); |
| 125 | } | 128 | } |
| @@ -128,7 +131,7 @@ this begins by re-executing that macro as if you typed it again. */) | |||
| 128 | return Qnil; | 131 | return Qnil; |
| 129 | } | 132 | } |
| 130 | 133 | ||
| 131 | DEFUN ("end-kbd-macro", Fend_kbd_macro, Send_kbd_macro, 0, 1, "p", | 134 | DEFUN ("end-kbd-macro", Fend_kbd_macro, Send_kbd_macro, 0, 2, "p", |
| 132 | doc: /* Finish defining a keyboard macro. | 135 | doc: /* Finish defining a keyboard macro. |
| 133 | The definition was started by \\[start-kbd-macro]. | 136 | The definition was started by \\[start-kbd-macro]. |
| 134 | The macro is now available for use via \\[call-last-kbd-macro], | 137 | The macro is now available for use via \\[call-last-kbd-macro], |
| @@ -137,9 +140,12 @@ under that name. | |||
| 137 | 140 | ||
| 138 | With numeric arg, repeat macro now that many times, | 141 | With numeric arg, repeat macro now that many times, |
| 139 | counting the definition just completed as the first repetition. | 142 | counting the definition just completed as the first repetition. |
| 140 | An argument of zero means repeat until error. */) | 143 | An argument of zero means repeat until error. |
| 141 | (repeat) | 144 | |
| 142 | Lisp_Object repeat; | 145 | In Lisp, optional second arg LOOPFUNC may be a function that is called prior to |
| 146 | each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */) | ||
| 147 | (repeat, loopfunc) | ||
| 148 | Lisp_Object repeat, loopfunc; | ||
| 143 | { | 149 | { |
| 144 | if (NILP (current_kboard->defining_kbd_macro)) | 150 | if (NILP (current_kboard->defining_kbd_macro)) |
| 145 | error ("Not defining kbd macro"); | 151 | error ("Not defining kbd macro"); |
| @@ -161,12 +167,12 @@ An argument of zero means repeat until error. */) | |||
| 161 | } | 167 | } |
| 162 | 168 | ||
| 163 | if (XFASTINT (repeat) == 0) | 169 | if (XFASTINT (repeat) == 0) |
| 164 | Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, repeat); | 170 | Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, repeat, loopfunc); |
| 165 | else | 171 | else |
| 166 | { | 172 | { |
| 167 | XSETINT (repeat, XINT (repeat)-1); | 173 | XSETINT (repeat, XINT (repeat)-1); |
| 168 | if (XINT (repeat) > 0) | 174 | if (XINT (repeat) > 0) |
| 169 | Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, repeat); | 175 | Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, repeat, loopfunc); |
| 170 | } | 176 | } |
| 171 | return Qnil; | 177 | return Qnil; |
| 172 | } | 178 | } |
| @@ -228,15 +234,18 @@ DEFUN ("store-kbd-macro-event", Fstore_kbd_macro_event, | |||
| 228 | } | 234 | } |
| 229 | 235 | ||
| 230 | DEFUN ("call-last-kbd-macro", Fcall_last_kbd_macro, Scall_last_kbd_macro, | 236 | DEFUN ("call-last-kbd-macro", Fcall_last_kbd_macro, Scall_last_kbd_macro, |
| 231 | 0, 1, "p", | 237 | 0, 2, "p", |
| 232 | doc: /* Call the last keyboard macro that you defined with \\[start-kbd-macro]. | 238 | doc: /* Call the last keyboard macro that you defined with \\[start-kbd-macro]. |
| 233 | 239 | ||
| 234 | A prefix argument serves as a repeat count. Zero means repeat until error. | 240 | A prefix argument serves as a repeat count. Zero means repeat until error. |
| 235 | 241 | ||
| 236 | To make a macro permanent so you can call it even after | 242 | To make a macro permanent so you can call it even after |
| 237 | defining others, use \\[name-last-kbd-macro]. */) | 243 | defining others, use \\[name-last-kbd-macro]. |
| 238 | (prefix) | 244 | |
| 239 | Lisp_Object prefix; | 245 | In Lisp, optional second arg LOOPFUNC may be a function that is called prior to |
| 246 | each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */) | ||
| 247 | (prefix, loopfunc) | ||
| 248 | Lisp_Object prefix, loopfunc; | ||
| 240 | { | 249 | { |
| 241 | /* Don't interfere with recognition of the previous command | 250 | /* Don't interfere with recognition of the previous command |
| 242 | from before this macro started. */ | 251 | from before this macro started. */ |
| @@ -249,7 +258,7 @@ defining others, use \\[name-last-kbd-macro]. */) | |||
| 249 | else if (NILP (current_kboard->Vlast_kbd_macro)) | 258 | else if (NILP (current_kboard->Vlast_kbd_macro)) |
| 250 | error ("No kbd macro has been defined"); | 259 | error ("No kbd macro has been defined"); |
| 251 | else | 260 | else |
| 252 | Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, prefix); | 261 | Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, prefix, loopfunc); |
| 253 | 262 | ||
| 254 | /* command_loop_1 sets this to nil before it returns; | 263 | /* command_loop_1 sets this to nil before it returns; |
| 255 | get back the last command within the macro | 264 | get back the last command within the macro |
| @@ -275,18 +284,21 @@ pop_kbd_macro (info) | |||
| 275 | return Qnil; | 284 | return Qnil; |
| 276 | } | 285 | } |
| 277 | 286 | ||
| 278 | DEFUN ("execute-kbd-macro", Fexecute_kbd_macro, Sexecute_kbd_macro, 1, 2, 0, | 287 | DEFUN ("execute-kbd-macro", Fexecute_kbd_macro, Sexecute_kbd_macro, 1, 3, 0, |
| 279 | doc: /* Execute MACRO as string of editor command characters. | 288 | doc: /* Execute MACRO as string of editor command characters. |
| 280 | If MACRO is a symbol, its function definition is used. | 289 | If MACRO is a symbol, its function definition is used. |
| 281 | COUNT is a repeat count, or nil for once, or 0 for infinite loop. */) | 290 | COUNT is a repeat count, or nil for once, or 0 for infinite loop. |
| 282 | (macro, count) | 291 | |
| 283 | Lisp_Object macro, count; | 292 | Optional third arg LOOPFUNC may be a function that is called prior to |
| 293 | each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */) | ||
| 294 | (macro, count, loopfunc) | ||
| 295 | Lisp_Object macro, count, loopfunc; | ||
| 284 | { | 296 | { |
| 285 | Lisp_Object final; | 297 | Lisp_Object final; |
| 286 | Lisp_Object tem; | 298 | Lisp_Object tem; |
| 287 | int pdlcount = SPECPDL_INDEX (); | 299 | int pdlcount = SPECPDL_INDEX (); |
| 288 | int repeat = 1; | 300 | int repeat = 1; |
| 289 | struct gcpro gcpro1; | 301 | struct gcpro gcpro1, gcpro2; |
| 290 | int success_count = 0; | 302 | int success_count = 0; |
| 291 | 303 | ||
| 292 | executing_macro_iterations = 0; | 304 | executing_macro_iterations = 0; |
| @@ -306,7 +318,7 @@ COUNT is a repeat count, or nil for once, or 0 for infinite loop. */) | |||
| 306 | real_this_command)); | 318 | real_this_command)); |
| 307 | record_unwind_protect (pop_kbd_macro, tem); | 319 | record_unwind_protect (pop_kbd_macro, tem); |
| 308 | 320 | ||
| 309 | GCPRO1 (final); | 321 | GCPRO2 (final, loopfunc); |
| 310 | do | 322 | do |
| 311 | { | 323 | { |
| 312 | Vexecuting_macro = final; | 324 | Vexecuting_macro = final; |
| @@ -314,6 +326,15 @@ COUNT is a repeat count, or nil for once, or 0 for infinite loop. */) | |||
| 314 | executing_macro_index = 0; | 326 | executing_macro_index = 0; |
| 315 | 327 | ||
| 316 | current_kboard->Vprefix_arg = Qnil; | 328 | current_kboard->Vprefix_arg = Qnil; |
| 329 | |||
| 330 | if (!NILP (loopfunc)) | ||
| 331 | { | ||
| 332 | Lisp_Object cont; | ||
| 333 | cont = call0 (loopfunc); | ||
| 334 | if (NILP (cont)) | ||
| 335 | break; | ||
| 336 | } | ||
| 337 | |||
| 317 | command_loop_1 (); | 338 | command_loop_1 (); |
| 318 | 339 | ||
| 319 | executing_macro_iterations = ++success_count; | 340 | executing_macro_iterations = ++success_count; |