aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKim F. Storm2002-08-14 10:35:31 +0000
committerKim F. Storm2002-08-14 10:35:31 +0000
commitf90d3a6bffc7e48fdf3b0fd8198cda679477cec6 (patch)
treeec7d43d68f462f123ef60d2c0ec58b1e0b0c8e6d /src
parenta361276f071e444994fad6aa5248c36fa45966f4 (diff)
downloademacs-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.c67
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
56Lisp_Object Fexecute_kbd_macro (); 56Lisp_Object Fexecute_kbd_macro ();
57 57
58DEFUN ("start-kbd-macro", Fstart_kbd_macro, Sstart_kbd_macro, 1, 1, "P", 58DEFUN ("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.
60The commands are recorded even as they are executed. 60The commands are recorded even as they are executed.
61Use \\[end-kbd-macro] to finish recording and make the macro available. 61Use \\[end-kbd-macro] to finish recording and make the macro available.
62Use \\[name-last-kbd-macro] to give it a permanent name. 62Use \\[name-last-kbd-macro] to give it a permanent name.
63Non-nil arg (prefix arg) means append to last macro defined; 63Non-nil arg (prefix arg) means append to last macro defined;
64this begins by re-executing that macro as if you typed it again. */) 64this begins by re-executing that macro as if you typed it again.
65 (append) 65If optional second arg, NO-EXEC, is non-nil, do not re-execute last
66 Lisp_Object append; 66macro 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
131DEFUN ("end-kbd-macro", Fend_kbd_macro, Send_kbd_macro, 0, 1, "p", 134DEFUN ("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.
133The definition was started by \\[start-kbd-macro]. 136The definition was started by \\[start-kbd-macro].
134The macro is now available for use via \\[call-last-kbd-macro], 137The macro is now available for use via \\[call-last-kbd-macro],
@@ -137,9 +140,12 @@ under that name.
137 140
138With numeric arg, repeat macro now that many times, 141With numeric arg, repeat macro now that many times,
139counting the definition just completed as the first repetition. 142counting the definition just completed as the first repetition.
140An argument of zero means repeat until error. */) 143An argument of zero means repeat until error.
141 (repeat) 144
142 Lisp_Object repeat; 145In Lisp, optional second arg LOOPFUNC may be a function that is called prior to
146each 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
230DEFUN ("call-last-kbd-macro", Fcall_last_kbd_macro, Scall_last_kbd_macro, 236DEFUN ("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
234A prefix argument serves as a repeat count. Zero means repeat until error. 240A prefix argument serves as a repeat count. Zero means repeat until error.
235 241
236To make a macro permanent so you can call it even after 242To make a macro permanent so you can call it even after
237defining others, use \\[name-last-kbd-macro]. */) 243defining others, use \\[name-last-kbd-macro].
238 (prefix) 244
239 Lisp_Object prefix; 245In Lisp, optional second arg LOOPFUNC may be a function that is called prior to
246each 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
278DEFUN ("execute-kbd-macro", Fexecute_kbd_macro, Sexecute_kbd_macro, 1, 2, 0, 287DEFUN ("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.
280If MACRO is a symbol, its function definition is used. 289If MACRO is a symbol, its function definition is used.
281COUNT is a repeat count, or nil for once, or 0 for infinite loop. */) 290COUNT is a repeat count, or nil for once, or 0 for infinite loop.
282 (macro, count) 291
283 Lisp_Object macro, count; 292Optional third arg LOOPFUNC may be a function that is called prior to
293each 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;