1991-04-28 02:55:09 +00:00
|
|
|
|
/* Keyboard macros.
|
2001-01-08 12:23:32 +00:00
|
|
|
|
Copyright (C) 1985, 1986, 1993, 2000, 2001 Free Software Foundation, Inc.
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
|
|
|
|
This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
1992-05-18 08:13:37 +00:00
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
1991-04-28 02:55:09 +00:00
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
|
|
GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with GNU Emacs; see the file COPYING. If not, write to
|
1996-01-15 09:18:04 +00:00
|
|
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
Boston, MA 02111-1307, USA. */
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
|
|
|
|
|
1993-09-10 06:15:46 +00:00
|
|
|
|
#include <config.h>
|
1991-04-28 02:55:09 +00:00
|
|
|
|
#include "lisp.h"
|
|
|
|
|
#include "macros.h"
|
|
|
|
|
#include "commands.h"
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "window.h"
|
1995-04-10 05:33:58 +00:00
|
|
|
|
#include "keyboard.h"
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
2001-01-08 12:23:32 +00:00
|
|
|
|
Lisp_Object Qexecute_kbd_macro, Qkbd_macro_termination_hook;
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
1996-08-29 04:38:05 +00:00
|
|
|
|
/* Kbd macro currently being executed (a string or vector). */
|
|
|
|
|
|
1991-04-28 02:55:09 +00:00
|
|
|
|
Lisp_Object Vexecuting_macro;
|
1996-08-29 04:38:05 +00:00
|
|
|
|
|
|
|
|
|
/* Index of next character to fetch from that macro. */
|
|
|
|
|
|
2002-09-08 20:28:46 +00:00
|
|
|
|
EMACS_INT executing_macro_index;
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
1996-08-29 04:38:05 +00:00
|
|
|
|
/* Number of successful iterations so far
|
|
|
|
|
for innermost keyboard macro.
|
|
|
|
|
This is not bound at each level,
|
|
|
|
|
so after an error, it describes the innermost interrupted macro. */
|
|
|
|
|
|
|
|
|
|
int executing_macro_iterations;
|
|
|
|
|
|
|
|
|
|
/* This is the macro that was executing.
|
|
|
|
|
This is not bound at each level,
|
|
|
|
|
so after an error, it describes the innermost interrupted macro.
|
|
|
|
|
We use it only as a kind of flag, so no need to protect it. */
|
|
|
|
|
|
|
|
|
|
Lisp_Object executing_macro;
|
|
|
|
|
|
1998-10-12 20:03:15 +00:00
|
|
|
|
extern Lisp_Object real_this_command;
|
|
|
|
|
|
1991-04-28 02:55:09 +00:00
|
|
|
|
Lisp_Object Fexecute_kbd_macro ();
|
|
|
|
|
|
2002-08-14 10:35:31 +00:00
|
|
|
|
DEFUN ("start-kbd-macro", Fstart_kbd_macro, Sstart_kbd_macro, 1, 2, "P",
|
2001-12-11 06:23:50 +00:00
|
|
|
|
doc: /* Record subsequent keyboard input, defining a keyboard macro.
|
|
|
|
|
The commands are recorded even as they are executed.
|
|
|
|
|
Use \\[end-kbd-macro] to finish recording and make the macro available.
|
|
|
|
|
Use \\[name-last-kbd-macro] to give it a permanent name.
|
|
|
|
|
Non-nil arg (prefix arg) means append to last macro defined;
|
2002-08-14 10:35:31 +00:00
|
|
|
|
this begins by re-executing that macro as if you typed it again.
|
2003-02-04 14:56:31 +00:00
|
|
|
|
If optional second arg, NO-EXEC, is non-nil, do not re-execute last
|
2002-08-14 10:35:31 +00:00
|
|
|
|
macro before appending to it. */)
|
|
|
|
|
(append, no_exec)
|
|
|
|
|
Lisp_Object append, no_exec;
|
1991-04-28 02:55:09 +00:00
|
|
|
|
{
|
1995-03-15 01:49:46 +00:00
|
|
|
|
if (!NILP (current_kboard->defining_kbd_macro))
|
1991-04-28 02:55:09 +00:00
|
|
|
|
error ("Already defining kbd macro");
|
|
|
|
|
|
1995-03-15 01:49:46 +00:00
|
|
|
|
if (!current_kboard->kbd_macro_buffer)
|
1995-03-03 05:02:50 +00:00
|
|
|
|
{
|
1995-03-15 01:49:46 +00:00
|
|
|
|
current_kboard->kbd_macro_bufsize = 30;
|
|
|
|
|
current_kboard->kbd_macro_buffer
|
1996-01-24 23:41:04 +00:00
|
|
|
|
= (Lisp_Object *)xmalloc (30 * sizeof (Lisp_Object));
|
1995-03-03 05:02:50 +00:00
|
|
|
|
}
|
1991-04-28 02:55:09 +00:00
|
|
|
|
update_mode_lines++;
|
1992-01-13 21:48:08 +00:00
|
|
|
|
if (NILP (append))
|
1991-04-28 02:55:09 +00:00
|
|
|
|
{
|
1996-01-24 23:41:04 +00:00
|
|
|
|
if (current_kboard->kbd_macro_bufsize > 200)
|
|
|
|
|
{
|
|
|
|
|
current_kboard->kbd_macro_bufsize = 30;
|
|
|
|
|
current_kboard->kbd_macro_buffer
|
1996-05-12 20:07:43 +00:00
|
|
|
|
= (Lisp_Object *)xrealloc (current_kboard->kbd_macro_buffer,
|
|
|
|
|
30 * sizeof (Lisp_Object));
|
1996-01-24 23:41:04 +00:00
|
|
|
|
}
|
1995-03-15 01:49:46 +00:00
|
|
|
|
current_kboard->kbd_macro_ptr = current_kboard->kbd_macro_buffer;
|
|
|
|
|
current_kboard->kbd_macro_end = current_kboard->kbd_macro_buffer;
|
1996-01-24 23:41:04 +00:00
|
|
|
|
message ("Defining kbd macro...");
|
1991-04-28 02:55:09 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1999-12-13 03:50:21 +00:00
|
|
|
|
int i, len;
|
2003-02-12 11:08:36 +00:00
|
|
|
|
int cvt;
|
1999-12-13 03:50:21 +00:00
|
|
|
|
|
|
|
|
|
/* Check the type of last-kbd-macro in case Lisp code changed it. */
|
|
|
|
|
if (!STRINGP (current_kboard->Vlast_kbd_macro)
|
|
|
|
|
&& !VECTORP (current_kboard->Vlast_kbd_macro))
|
|
|
|
|
current_kboard->Vlast_kbd_macro
|
|
|
|
|
= wrong_type_argument (Qarrayp, current_kboard->Vlast_kbd_macro);
|
|
|
|
|
|
|
|
|
|
len = XINT (Flength (current_kboard->Vlast_kbd_macro));
|
|
|
|
|
|
|
|
|
|
/* Copy last-kbd-macro into the buffer, in case the Lisp code
|
|
|
|
|
has put another macro there. */
|
|
|
|
|
if (current_kboard->kbd_macro_bufsize < len + 30)
|
|
|
|
|
{
|
|
|
|
|
current_kboard->kbd_macro_bufsize = len + 30;
|
|
|
|
|
current_kboard->kbd_macro_buffer
|
|
|
|
|
= (Lisp_Object *)xrealloc (current_kboard->kbd_macro_buffer,
|
|
|
|
|
(len + 30) * sizeof (Lisp_Object));
|
|
|
|
|
}
|
2003-02-12 11:08:36 +00:00
|
|
|
|
|
|
|
|
|
/* Must convert meta modifier when copying string to vector. */
|
|
|
|
|
cvt = STRINGP (current_kboard->Vlast_kbd_macro);
|
1999-12-13 03:50:21 +00:00
|
|
|
|
for (i = 0; i < len; i++)
|
2003-02-12 11:08:36 +00:00
|
|
|
|
{
|
|
|
|
|
Lisp_Object c;
|
|
|
|
|
c = Faref (current_kboard->Vlast_kbd_macro, make_number (i));
|
2003-02-22 22:19:31 +00:00
|
|
|
|
if (cvt && NATNUMP (c) && (XFASTINT (c) & 0x80))
|
|
|
|
|
XSETFASTINT (c, CHAR_META | (XFASTINT (c) & ~0x80));
|
2003-02-12 11:08:36 +00:00
|
|
|
|
current_kboard->kbd_macro_buffer[i] = c;
|
|
|
|
|
}
|
1999-12-13 03:50:21 +00:00
|
|
|
|
|
|
|
|
|
current_kboard->kbd_macro_ptr = current_kboard->kbd_macro_buffer + len;
|
|
|
|
|
current_kboard->kbd_macro_end = current_kboard->kbd_macro_ptr;
|
|
|
|
|
|
|
|
|
|
/* Re-execute the macro we are appending to,
|
|
|
|
|
for consistency of behavior. */
|
2002-08-14 10:35:31 +00:00
|
|
|
|
if (NILP (no_exec))
|
|
|
|
|
Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro,
|
|
|
|
|
make_number (1), Qnil);
|
1999-12-13 03:50:21 +00:00
|
|
|
|
|
|
|
|
|
message ("Appending to kbd macro...");
|
1991-04-28 02:55:09 +00:00
|
|
|
|
}
|
1995-03-15 01:49:46 +00:00
|
|
|
|
current_kboard->defining_kbd_macro = Qt;
|
2003-02-04 14:56:31 +00:00
|
|
|
|
|
1991-04-28 02:55:09 +00:00
|
|
|
|
return Qnil;
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-09 22:33:51 +00:00
|
|
|
|
/* Finish defining the current keyboard macro. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
end_kbd_macro ()
|
|
|
|
|
{
|
|
|
|
|
current_kboard->defining_kbd_macro = Qnil;
|
|
|
|
|
update_mode_lines++;
|
|
|
|
|
current_kboard->Vlast_kbd_macro
|
|
|
|
|
= make_event_array ((current_kboard->kbd_macro_end
|
|
|
|
|
- current_kboard->kbd_macro_buffer),
|
|
|
|
|
current_kboard->kbd_macro_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-14 10:35:31 +00:00
|
|
|
|
DEFUN ("end-kbd-macro", Fend_kbd_macro, Send_kbd_macro, 0, 2, "p",
|
2001-12-11 06:23:50 +00:00
|
|
|
|
doc: /* Finish defining a keyboard macro.
|
|
|
|
|
The definition was started by \\[start-kbd-macro].
|
|
|
|
|
The macro is now available for use via \\[call-last-kbd-macro],
|
|
|
|
|
or it can be given a name with \\[name-last-kbd-macro] and then invoked
|
|
|
|
|
under that name.
|
|
|
|
|
|
|
|
|
|
With numeric arg, repeat macro now that many times,
|
|
|
|
|
counting the definition just completed as the first repetition.
|
2002-08-14 10:35:31 +00:00
|
|
|
|
An argument of zero means repeat until error.
|
|
|
|
|
|
2003-02-04 14:56:31 +00:00
|
|
|
|
In Lisp, optional second arg LOOPFUNC may be a function that is called prior to
|
2002-08-14 10:35:31 +00:00
|
|
|
|
each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
|
|
|
|
|
(repeat, loopfunc)
|
|
|
|
|
Lisp_Object repeat, loopfunc;
|
1991-04-28 02:55:09 +00:00
|
|
|
|
{
|
1995-03-15 01:49:46 +00:00
|
|
|
|
if (NILP (current_kboard->defining_kbd_macro))
|
1998-08-06 05:36:45 +00:00
|
|
|
|
error ("Not defining kbd macro");
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
1996-01-09 00:33:09 +00:00
|
|
|
|
if (NILP (repeat))
|
|
|
|
|
XSETFASTINT (repeat, 1);
|
1991-04-28 02:55:09 +00:00
|
|
|
|
else
|
2001-11-02 20:46:55 +00:00
|
|
|
|
CHECK_NUMBER (repeat);
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
1995-03-15 01:49:46 +00:00
|
|
|
|
if (!NILP (current_kboard->defining_kbd_macro))
|
1991-04-28 02:55:09 +00:00
|
|
|
|
{
|
2002-09-09 22:33:51 +00:00
|
|
|
|
end_kbd_macro ();
|
1996-01-24 23:41:04 +00:00
|
|
|
|
message ("Keyboard macro defined");
|
1991-04-28 02:55:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-01-09 00:33:09 +00:00
|
|
|
|
if (XFASTINT (repeat) == 0)
|
2002-08-14 10:35:31 +00:00
|
|
|
|
Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, repeat, loopfunc);
|
1991-04-28 02:55:09 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
1996-01-09 00:33:09 +00:00
|
|
|
|
XSETINT (repeat, XINT (repeat)-1);
|
|
|
|
|
if (XINT (repeat) > 0)
|
2002-08-14 10:35:31 +00:00
|
|
|
|
Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, repeat, loopfunc);
|
1991-04-28 02:55:09 +00:00
|
|
|
|
}
|
|
|
|
|
return Qnil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Store character c into kbd macro being defined */
|
|
|
|
|
|
1997-11-21 13:03:55 +00:00
|
|
|
|
void
|
1991-04-28 02:55:09 +00:00
|
|
|
|
store_kbd_macro_char (c)
|
|
|
|
|
Lisp_Object c;
|
|
|
|
|
{
|
2001-09-05 09:39:09 +00:00
|
|
|
|
struct kboard *kb = current_kboard;
|
|
|
|
|
|
|
|
|
|
if (!NILP (kb->defining_kbd_macro))
|
1991-04-28 02:55:09 +00:00
|
|
|
|
{
|
2001-09-05 09:39:09 +00:00
|
|
|
|
if (kb->kbd_macro_ptr - kb->kbd_macro_buffer == kb->kbd_macro_bufsize)
|
1991-04-28 02:55:09 +00:00
|
|
|
|
{
|
2001-09-05 09:39:09 +00:00
|
|
|
|
int ptr_offset, end_offset, nbytes;
|
2003-02-04 14:56:31 +00:00
|
|
|
|
|
2001-09-05 09:39:09 +00:00
|
|
|
|
ptr_offset = kb->kbd_macro_ptr - kb->kbd_macro_buffer;
|
|
|
|
|
end_offset = kb->kbd_macro_end - kb->kbd_macro_buffer;
|
|
|
|
|
kb->kbd_macro_bufsize *= 2;
|
|
|
|
|
nbytes = kb->kbd_macro_bufsize * sizeof *kb->kbd_macro_buffer;
|
|
|
|
|
kb->kbd_macro_buffer
|
|
|
|
|
= (Lisp_Object *) xrealloc (kb->kbd_macro_buffer, nbytes);
|
|
|
|
|
kb->kbd_macro_ptr = kb->kbd_macro_buffer + ptr_offset;
|
|
|
|
|
kb->kbd_macro_end = kb->kbd_macro_buffer + end_offset;
|
1991-04-28 02:55:09 +00:00
|
|
|
|
}
|
2003-02-04 14:56:31 +00:00
|
|
|
|
|
2001-09-05 09:39:09 +00:00
|
|
|
|
*kb->kbd_macro_ptr++ = c;
|
1991-04-28 02:55:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Declare that all chars stored so far in the kbd macro being defined
|
|
|
|
|
really belong to it. This is done in between editor commands. */
|
|
|
|
|
|
1997-11-21 13:03:55 +00:00
|
|
|
|
void
|
1991-04-28 02:55:09 +00:00
|
|
|
|
finalize_kbd_macro_chars ()
|
|
|
|
|
{
|
1995-03-15 01:49:46 +00:00
|
|
|
|
current_kboard->kbd_macro_end = current_kboard->kbd_macro_ptr;
|
1991-04-28 02:55:09 +00:00
|
|
|
|
}
|
1995-08-13 15:47:11 +00:00
|
|
|
|
|
|
|
|
|
DEFUN ("cancel-kbd-macro-events", Fcancel_kbd_macro_events,
|
|
|
|
|
Scancel_kbd_macro_events, 0, 0, 0,
|
2001-12-11 06:23:50 +00:00
|
|
|
|
doc: /* Cancel the events added to a keyboard macro for this command. */)
|
|
|
|
|
()
|
1995-08-13 15:47:11 +00:00
|
|
|
|
{
|
|
|
|
|
current_kboard->kbd_macro_ptr = current_kboard->kbd_macro_end;
|
2000-09-21 20:54:57 +00:00
|
|
|
|
return Qnil;
|
1995-08-13 15:47:11 +00:00
|
|
|
|
}
|
1995-12-21 17:11:28 +00:00
|
|
|
|
|
|
|
|
|
DEFUN ("store-kbd-macro-event", Fstore_kbd_macro_event,
|
|
|
|
|
Sstore_kbd_macro_event, 1, 1, 0,
|
2001-12-11 06:23:50 +00:00
|
|
|
|
doc: /* Store EVENT into the keyboard macro being defined. */)
|
|
|
|
|
(event)
|
1995-12-21 17:11:28 +00:00
|
|
|
|
Lisp_Object event;
|
|
|
|
|
{
|
|
|
|
|
store_kbd_macro_char (event);
|
|
|
|
|
return Qnil;
|
|
|
|
|
}
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
|
|
|
|
DEFUN ("call-last-kbd-macro", Fcall_last_kbd_macro, Scall_last_kbd_macro,
|
2002-08-14 10:35:31 +00:00
|
|
|
|
0, 2, "p",
|
2001-12-11 06:23:50 +00:00
|
|
|
|
doc: /* Call the last keyboard macro that you defined with \\[start-kbd-macro].
|
|
|
|
|
|
|
|
|
|
A prefix argument serves as a repeat count. Zero means repeat until error.
|
|
|
|
|
|
|
|
|
|
To make a macro permanent so you can call it even after
|
2003-02-04 14:56:31 +00:00
|
|
|
|
defining others, use \\[name-last-kbd-macro].
|
2002-08-14 10:35:31 +00:00
|
|
|
|
|
2003-02-04 14:56:31 +00:00
|
|
|
|
In Lisp, optional second arg LOOPFUNC may be a function that is called prior to
|
2002-08-14 10:35:31 +00:00
|
|
|
|
each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
|
|
|
|
|
(prefix, loopfunc)
|
|
|
|
|
Lisp_Object prefix, loopfunc;
|
1991-04-28 02:55:09 +00:00
|
|
|
|
{
|
1996-11-11 20:33:21 +00:00
|
|
|
|
/* Don't interfere with recognition of the previous command
|
|
|
|
|
from before this macro started. */
|
1998-08-09 21:55:58 +00:00
|
|
|
|
Vthis_command = current_kboard->Vlast_command;
|
1999-03-30 18:02:13 +00:00
|
|
|
|
/* C-x z after the macro should repeat the macro. */
|
|
|
|
|
real_this_command = current_kboard->Vlast_kbd_macro;
|
1996-11-11 20:33:21 +00:00
|
|
|
|
|
1995-03-15 01:49:46 +00:00
|
|
|
|
if (! NILP (current_kboard->defining_kbd_macro))
|
1991-04-28 02:55:09 +00:00
|
|
|
|
error ("Can't execute anonymous macro while defining one");
|
1995-03-15 01:49:46 +00:00
|
|
|
|
else if (NILP (current_kboard->Vlast_kbd_macro))
|
1991-04-28 02:55:09 +00:00
|
|
|
|
error ("No kbd macro has been defined");
|
|
|
|
|
else
|
2002-08-14 10:35:31 +00:00
|
|
|
|
Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, prefix, loopfunc);
|
1996-11-11 20:33:21 +00:00
|
|
|
|
|
|
|
|
|
/* command_loop_1 sets this to nil before it returns;
|
|
|
|
|
get back the last command within the macro
|
|
|
|
|
so that it can be last, again, after we return. */
|
1998-08-09 21:55:58 +00:00
|
|
|
|
Vthis_command = current_kboard->Vlast_command;
|
1996-11-11 20:33:21 +00:00
|
|
|
|
|
1991-04-28 02:55:09 +00:00
|
|
|
|
return Qnil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Restore Vexecuting_macro and executing_macro_index - called when
|
|
|
|
|
the unwind-protect in Fexecute_kbd_macro gets invoked. */
|
1996-08-29 04:38:05 +00:00
|
|
|
|
|
1991-04-28 02:55:09 +00:00
|
|
|
|
static Lisp_Object
|
|
|
|
|
pop_kbd_macro (info)
|
|
|
|
|
Lisp_Object info;
|
|
|
|
|
{
|
|
|
|
|
Lisp_Object tem;
|
1999-03-30 18:02:13 +00:00
|
|
|
|
Vexecuting_macro = XCAR (info);
|
|
|
|
|
tem = XCDR (info);
|
|
|
|
|
executing_macro_index = XINT (XCAR (tem));
|
|
|
|
|
real_this_command = XCDR (tem);
|
2001-01-08 12:23:32 +00:00
|
|
|
|
Frun_hooks (1, &Qkbd_macro_termination_hook);
|
1991-04-28 02:55:09 +00:00
|
|
|
|
return Qnil;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-14 10:35:31 +00:00
|
|
|
|
DEFUN ("execute-kbd-macro", Fexecute_kbd_macro, Sexecute_kbd_macro, 1, 3, 0,
|
2001-12-11 06:23:50 +00:00
|
|
|
|
doc: /* Execute MACRO as string of editor command characters.
|
|
|
|
|
If MACRO is a symbol, its function definition is used.
|
2003-02-04 14:56:31 +00:00
|
|
|
|
COUNT is a repeat count, or nil for once, or 0 for infinite loop.
|
2002-08-14 10:35:31 +00:00
|
|
|
|
|
2003-02-04 14:56:31 +00:00
|
|
|
|
Optional third arg LOOPFUNC may be a function that is called prior to
|
2002-08-14 10:35:31 +00:00
|
|
|
|
each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
|
|
|
|
|
(macro, count, loopfunc)
|
|
|
|
|
Lisp_Object macro, count, loopfunc;
|
1991-04-28 02:55:09 +00:00
|
|
|
|
{
|
|
|
|
|
Lisp_Object final;
|
|
|
|
|
Lisp_Object tem;
|
2002-07-11 15:24:13 +00:00
|
|
|
|
int pdlcount = SPECPDL_INDEX ();
|
1991-04-28 02:55:09 +00:00
|
|
|
|
int repeat = 1;
|
2002-08-14 10:35:31 +00:00
|
|
|
|
struct gcpro gcpro1, gcpro2;
|
1996-08-29 04:38:05 +00:00
|
|
|
|
int success_count = 0;
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
1999-03-14 06:33:01 +00:00
|
|
|
|
executing_macro_iterations = 0;
|
|
|
|
|
|
1996-01-09 03:58:16 +00:00
|
|
|
|
if (!NILP (count))
|
|
|
|
|
{
|
|
|
|
|
count = Fprefix_numeric_value (count);
|
|
|
|
|
repeat = XINT (count);
|
|
|
|
|
}
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
1992-05-18 08:13:37 +00:00
|
|
|
|
final = indirect_function (macro);
|
1994-09-27 02:25:20 +00:00
|
|
|
|
if (!STRINGP (final) && !VECTORP (final))
|
1998-08-06 05:36:45 +00:00
|
|
|
|
error ("Keyboard macros must be strings or vectors");
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
1999-03-30 18:02:13 +00:00
|
|
|
|
tem = Fcons (Vexecuting_macro,
|
|
|
|
|
Fcons (make_number (executing_macro_index),
|
|
|
|
|
real_this_command));
|
1991-04-28 02:55:09 +00:00
|
|
|
|
record_unwind_protect (pop_kbd_macro, tem);
|
|
|
|
|
|
2002-08-14 10:35:31 +00:00
|
|
|
|
GCPRO2 (final, loopfunc);
|
1991-04-28 02:55:09 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
Vexecuting_macro = final;
|
1996-08-29 04:38:05 +00:00
|
|
|
|
executing_macro = final;
|
1991-04-28 02:55:09 +00:00
|
|
|
|
executing_macro_index = 0;
|
|
|
|
|
|
1995-06-07 22:24:23 +00:00
|
|
|
|
current_kboard->Vprefix_arg = Qnil;
|
2002-08-14 10:35:31 +00:00
|
|
|
|
|
|
|
|
|
if (!NILP (loopfunc))
|
|
|
|
|
{
|
|
|
|
|
Lisp_Object cont;
|
|
|
|
|
cont = call0 (loopfunc);
|
|
|
|
|
if (NILP (cont))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
1991-04-28 02:55:09 +00:00
|
|
|
|
command_loop_1 ();
|
1992-12-12 15:35:41 +00:00
|
|
|
|
|
1996-08-29 04:38:05 +00:00
|
|
|
|
executing_macro_iterations = ++success_count;
|
|
|
|
|
|
1992-12-12 15:35:41 +00:00
|
|
|
|
QUIT;
|
1991-04-28 02:55:09 +00:00
|
|
|
|
}
|
1994-09-27 02:25:20 +00:00
|
|
|
|
while (--repeat
|
|
|
|
|
&& (STRINGP (Vexecuting_macro) || VECTORP (Vexecuting_macro)));
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
1996-08-29 04:38:05 +00:00
|
|
|
|
executing_macro = Qnil;
|
|
|
|
|
|
1998-10-12 20:03:15 +00:00
|
|
|
|
real_this_command = Vexecuting_macro;
|
|
|
|
|
|
1991-04-28 02:55:09 +00:00
|
|
|
|
UNGCPRO;
|
1996-01-09 02:34:30 +00:00
|
|
|
|
return unbind_to (pdlcount, Qnil);
|
1991-04-28 02:55:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-11-21 13:03:55 +00:00
|
|
|
|
void
|
1991-04-28 02:55:09 +00:00
|
|
|
|
init_macros ()
|
|
|
|
|
{
|
|
|
|
|
Vexecuting_macro = Qnil;
|
1996-08-29 21:22:04 +00:00
|
|
|
|
executing_macro = Qnil;
|
1991-04-28 02:55:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-11-21 13:03:55 +00:00
|
|
|
|
void
|
1991-04-28 02:55:09 +00:00
|
|
|
|
syms_of_macros ()
|
|
|
|
|
{
|
|
|
|
|
Qexecute_kbd_macro = intern ("execute-kbd-macro");
|
|
|
|
|
staticpro (&Qexecute_kbd_macro);
|
2001-01-08 12:23:32 +00:00
|
|
|
|
Qkbd_macro_termination_hook = intern ("kbd-macro-termination-hook");
|
|
|
|
|
staticpro (&Qkbd_macro_termination_hook);
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
|
|
|
|
defsubr (&Sstart_kbd_macro);
|
|
|
|
|
defsubr (&Send_kbd_macro);
|
|
|
|
|
defsubr (&Scall_last_kbd_macro);
|
|
|
|
|
defsubr (&Sexecute_kbd_macro);
|
1995-08-13 15:47:11 +00:00
|
|
|
|
defsubr (&Scancel_kbd_macro_events);
|
1995-12-21 17:11:28 +00:00
|
|
|
|
defsubr (&Sstore_kbd_macro_event);
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
1995-03-15 01:49:46 +00:00
|
|
|
|
DEFVAR_KBOARD ("defining-kbd-macro", defining_kbd_macro,
|
2004-11-05 22:46:28 +00:00
|
|
|
|
doc: /* Non-nil while a keyboard macro is being defined. Don't set this!
|
|
|
|
|
The value is the symbol `append' while appending to the definition of
|
|
|
|
|
an existing macro. */);
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
|
|
|
|
DEFVAR_LISP ("executing-macro", &Vexecuting_macro,
|
2001-12-11 06:23:50 +00:00
|
|
|
|
doc: /* Currently executing keyboard macro (string or vector); nil if none executing. */);
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
2002-09-08 20:28:46 +00:00
|
|
|
|
DEFVAR_INT ("executing-macro-index", &executing_macro_index,
|
|
|
|
|
doc: /* Index in currently executing keyboard macro; undefined if none executing. */);
|
|
|
|
|
|
1991-04-28 02:55:09 +00:00
|
|
|
|
DEFVAR_LISP_NOPRO ("executing-kbd-macro", &Vexecuting_macro,
|
2001-12-11 06:23:50 +00:00
|
|
|
|
doc: /* Currently executing keyboard macro (string or vector); nil if none executing. */);
|
1991-04-28 02:55:09 +00:00
|
|
|
|
|
1995-03-15 01:49:46 +00:00
|
|
|
|
DEFVAR_KBOARD ("last-kbd-macro", Vlast_kbd_macro,
|
2001-12-11 06:23:50 +00:00
|
|
|
|
doc: /* Last kbd macro defined, as a string or vector; nil if none defined. */);
|
1991-04-28 02:55:09 +00:00
|
|
|
|
}
|
2003-09-01 15:45:59 +00:00
|
|
|
|
|
|
|
|
|
/* arch-tag: d293fcc9-2266-4163-9198-7fa0de12ec9e
|
|
|
|
|
(do not change this comment) */
|