comparison src/macros.c @ 88155:d7ddb3e565de

sync with trunk
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 00:03:54 +0000
parents 282c490f6cd4
children
comparison
equal deleted inserted replaced
88154:8ce476d3ba36 88155:d7ddb3e565de
1 /* Keyboard macros. 1 /* Keyboard macros.
2 Copyright (C) 1985, 1986, 1993, 2000, 2001 Free Software Foundation, Inc. 2 Copyright (C) 1985, 1986, 1993, 2000, 2001, 2002, 2003, 2004,
3 2005 Free Software Foundation, Inc.
3 4
4 This file is part of GNU Emacs. 5 This file is part of GNU Emacs.
5 6
6 GNU Emacs is free software; you can redistribute it and/or modify 7 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 15 GNU General Public License for more details.
15 16
16 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to 18 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02111-1307, USA. */ 20 Boston, MA 02110-1301, USA. */
20 21
21 22
22 #include <config.h> 23 #include <config.h>
23 #include "lisp.h" 24 #include "lisp.h"
24 #include "macros.h" 25 #include "macros.h"
29 30
30 Lisp_Object Qexecute_kbd_macro, Qkbd_macro_termination_hook; 31 Lisp_Object Qexecute_kbd_macro, Qkbd_macro_termination_hook;
31 32
32 /* Kbd macro currently being executed (a string or vector). */ 33 /* Kbd macro currently being executed (a string or vector). */
33 34
34 Lisp_Object Vexecuting_macro; 35 Lisp_Object Vexecuting_kbd_macro;
35 36
36 /* Index of next character to fetch from that macro. */ 37 /* Index of next character to fetch from that macro. */
37 38
38 EMACS_INT executing_macro_index; 39 EMACS_INT executing_kbd_macro_index;
39 40
40 /* Number of successful iterations so far 41 /* Number of successful iterations so far
41 for innermost keyboard macro. 42 for innermost keyboard macro.
42 This is not bound at each level, 43 This is not bound at each level,
43 so after an error, it describes the innermost interrupted macro. */ 44 so after an error, it describes the innermost interrupted macro. */
44 45
45 int executing_macro_iterations; 46 int executing_kbd_macro_iterations;
46 47
47 /* This is the macro that was executing. 48 /* This is the macro that was executing.
48 This is not bound at each level, 49 This is not bound at each level,
49 so after an error, it describes the innermost interrupted macro. 50 so after an error, it describes the innermost interrupted macro.
50 We use it only as a kind of flag, so no need to protect it. */ 51 We use it only as a kind of flag, so no need to protect it. */
51 52
52 Lisp_Object executing_macro; 53 Lisp_Object executing_kbd_macro;
53 54
54 extern Lisp_Object real_this_command; 55 extern Lisp_Object real_this_command;
55 56
56 Lisp_Object Fexecute_kbd_macro (); 57 Lisp_Object Fexecute_kbd_macro ();
57 58
112 = (Lisp_Object *)xrealloc (current_kboard->kbd_macro_buffer, 113 = (Lisp_Object *)xrealloc (current_kboard->kbd_macro_buffer,
113 (len + 30) * sizeof (Lisp_Object)); 114 (len + 30) * sizeof (Lisp_Object));
114 } 115 }
115 116
116 /* Must convert meta modifier when copying string to vector. */ 117 /* Must convert meta modifier when copying string to vector. */
117 cvt = STRINGP (current_kboard->Vlast_kbd_macro); 118 cvt = STRINGP (current_kboard->Vlast_kbd_macro);
118 for (i = 0; i < len; i++) 119 for (i = 0; i < len; i++)
119 { 120 {
120 Lisp_Object c; 121 Lisp_Object c;
121 c = Faref (current_kboard->Vlast_kbd_macro, make_number (i)); 122 c = Faref (current_kboard->Vlast_kbd_macro, make_number (i));
122 if (cvt && INTEGERP (c) && (XINT (c) & 0x80)) 123 if (cvt && NATNUMP (c) && (XFASTINT (c) & 0x80))
123 c = XSETFASTINT (c, CHAR_META | (XINT (c) & ~0x80)); 124 XSETFASTINT (c, CHAR_META | (XFASTINT (c) & ~0x80));
124 current_kboard->kbd_macro_buffer[i] = c; 125 current_kboard->kbd_macro_buffer[i] = c;
125 } 126 }
126 127
127 current_kboard->kbd_macro_ptr = current_kboard->kbd_macro_buffer + len; 128 current_kboard->kbd_macro_ptr = current_kboard->kbd_macro_buffer + len;
128 current_kboard->kbd_macro_end = current_kboard->kbd_macro_ptr; 129 current_kboard->kbd_macro_end = current_kboard->kbd_macro_ptr;
283 Vthis_command = current_kboard->Vlast_command; 284 Vthis_command = current_kboard->Vlast_command;
284 285
285 return Qnil; 286 return Qnil;
286 } 287 }
287 288
288 /* Restore Vexecuting_macro and executing_macro_index - called when 289 /* Restore Vexecuting_kbd_macro and executing_kbd_macro_index.
289 the unwind-protect in Fexecute_kbd_macro gets invoked. */ 290 Called when the unwind-protect in Fexecute_kbd_macro gets invoked. */
290 291
291 static Lisp_Object 292 static Lisp_Object
292 pop_kbd_macro (info) 293 pop_kbd_macro (info)
293 Lisp_Object info; 294 Lisp_Object info;
294 { 295 {
295 Lisp_Object tem; 296 Lisp_Object tem;
296 Vexecuting_macro = XCAR (info); 297 Vexecuting_kbd_macro = XCAR (info);
297 tem = XCDR (info); 298 tem = XCDR (info);
298 executing_macro_index = XINT (XCAR (tem)); 299 executing_kbd_macro_index = XINT (XCAR (tem));
299 real_this_command = XCDR (tem); 300 real_this_command = XCDR (tem);
300 Frun_hooks (1, &Qkbd_macro_termination_hook); 301 Frun_hooks (1, &Qkbd_macro_termination_hook);
301 return Qnil; 302 return Qnil;
302 } 303 }
303 304
316 int pdlcount = SPECPDL_INDEX (); 317 int pdlcount = SPECPDL_INDEX ();
317 int repeat = 1; 318 int repeat = 1;
318 struct gcpro gcpro1, gcpro2; 319 struct gcpro gcpro1, gcpro2;
319 int success_count = 0; 320 int success_count = 0;
320 321
321 executing_macro_iterations = 0; 322 executing_kbd_macro_iterations = 0;
322 323
323 if (!NILP (count)) 324 if (!NILP (count))
324 { 325 {
325 count = Fprefix_numeric_value (count); 326 count = Fprefix_numeric_value (count);
326 repeat = XINT (count); 327 repeat = XINT (count);
328 329
329 final = indirect_function (macro); 330 final = indirect_function (macro);
330 if (!STRINGP (final) && !VECTORP (final)) 331 if (!STRINGP (final) && !VECTORP (final))
331 error ("Keyboard macros must be strings or vectors"); 332 error ("Keyboard macros must be strings or vectors");
332 333
333 tem = Fcons (Vexecuting_macro, 334 tem = Fcons (Vexecuting_kbd_macro,
334 Fcons (make_number (executing_macro_index), 335 Fcons (make_number (executing_kbd_macro_index),
335 real_this_command)); 336 real_this_command));
336 record_unwind_protect (pop_kbd_macro, tem); 337 record_unwind_protect (pop_kbd_macro, tem);
337 338
338 GCPRO2 (final, loopfunc); 339 GCPRO2 (final, loopfunc);
339 do 340 do
340 { 341 {
341 Vexecuting_macro = final; 342 Vexecuting_kbd_macro = final;
342 executing_macro = final; 343 executing_kbd_macro = final;
343 executing_macro_index = 0; 344 executing_kbd_macro_index = 0;
344 345
345 current_kboard->Vprefix_arg = Qnil; 346 current_kboard->Vprefix_arg = Qnil;
346 347
347 if (!NILP (loopfunc)) 348 if (!NILP (loopfunc))
348 { 349 {
352 break; 353 break;
353 } 354 }
354 355
355 command_loop_1 (); 356 command_loop_1 ();
356 357
357 executing_macro_iterations = ++success_count; 358 executing_kbd_macro_iterations = ++success_count;
358 359
359 QUIT; 360 QUIT;
360 } 361 }
361 while (--repeat 362 while (--repeat
362 && (STRINGP (Vexecuting_macro) || VECTORP (Vexecuting_macro))); 363 && (STRINGP (Vexecuting_kbd_macro) || VECTORP (Vexecuting_kbd_macro)));
363 364
364 executing_macro = Qnil; 365 executing_kbd_macro = Qnil;
365 366
366 real_this_command = Vexecuting_macro; 367 real_this_command = Vexecuting_kbd_macro;
367 368
368 UNGCPRO; 369 UNGCPRO;
369 return unbind_to (pdlcount, Qnil); 370 return unbind_to (pdlcount, Qnil);
370 } 371 }
371 372
372 void 373 void
373 init_macros () 374 init_macros ()
374 { 375 {
375 Vexecuting_macro = Qnil; 376 Vexecuting_kbd_macro = Qnil;
376 executing_macro = Qnil; 377 executing_kbd_macro = Qnil;
377 } 378 }
378 379
379 void 380 void
380 syms_of_macros () 381 syms_of_macros ()
381 { 382 {
390 defsubr (&Sexecute_kbd_macro); 391 defsubr (&Sexecute_kbd_macro);
391 defsubr (&Scancel_kbd_macro_events); 392 defsubr (&Scancel_kbd_macro_events);
392 defsubr (&Sstore_kbd_macro_event); 393 defsubr (&Sstore_kbd_macro_event);
393 394
394 DEFVAR_KBOARD ("defining-kbd-macro", defining_kbd_macro, 395 DEFVAR_KBOARD ("defining-kbd-macro", defining_kbd_macro,
395 doc: /* Non-nil while a keyboard macro is being defined. Don't set this! */); 396 doc: /* Non-nil while a keyboard macro is being defined. Don't set this!
396 397 The value is the symbol `append' while appending to the definition of
397 DEFVAR_LISP ("executing-macro", &Vexecuting_macro, 398 an existing macro. */);
398 doc: /* Currently executing keyboard macro (string or vector); nil if none executing. */); 399
399 400 DEFVAR_LISP ("executing-kbd-macro", &Vexecuting_kbd_macro,
400 DEFVAR_INT ("executing-macro-index", &executing_macro_index, 401 doc: /* Currently executing keyboard macro (string or vector).
402 This is nil when not executing a keyboard macro. */);
403
404 DEFVAR_INT ("executing-kbd-macro-index", &executing_kbd_macro_index,
401 doc: /* Index in currently executing keyboard macro; undefined if none executing. */); 405 doc: /* Index in currently executing keyboard macro; undefined if none executing. */);
402
403 DEFVAR_LISP_NOPRO ("executing-kbd-macro", &Vexecuting_macro,
404 doc: /* Currently executing keyboard macro (string or vector); nil if none executing. */);
405 406
406 DEFVAR_KBOARD ("last-kbd-macro", Vlast_kbd_macro, 407 DEFVAR_KBOARD ("last-kbd-macro", Vlast_kbd_macro,
407 doc: /* Last kbd macro defined, as a string or vector; nil if none defined. */); 408 doc: /* Last kbd macro defined, as a string or vector; nil if none defined. */);
408 } 409 }
410
411 /* arch-tag: d293fcc9-2266-4163-9198-7fa0de12ec9e
412 (do not change this comment) */