annotate src/macros.c @ 6743:77349221ca81

(hscroll-window-column): New function. (hscroll-point-visible): Do the right thing in the hard cases.
author Karl Heuer <kwzh@gnu.org>
date Fri, 08 Apr 1994 03:23:08 +0000
parents 1fc792473491
children 9ba3f17d6631
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
246
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Keyboard macros.
2961
e94a593c3952 Updated copyright years.
Jim Blandy <jimb@redhat.com>
parents: 2015
diff changeset
2 Copyright (C) 1985, 1986, 1993 Free Software Foundation, Inc.
246
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
647
529171c8b71c entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
246
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 2961
diff changeset
21 #include <config.h>
246
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 #include "lisp.h"
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 #include "macros.h"
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include "commands.h"
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 #include "buffer.h"
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 #include "window.h"
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 Lisp_Object Qexecute_kbd_macro;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 int defining_kbd_macro;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 /* The start of storage for the current keyboard macro, and its size. */
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 Lisp_Object *kbd_macro_buffer;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 int kbd_macro_bufsize;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 /* Where to store the next keystroke of the macro. */
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 Lisp_Object *kbd_macro_ptr;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 /* The finalized section of the macro starts at kbd_macro_buffer and
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 ends before this. This is not the same as kbd_macro_pointer, because
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 we advance this to kbd_macro_pointer when a key's command is complete.
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 This way, the keystrokes for "end-kbd-macro" are not included in the
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 macro. */
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 Lisp_Object *kbd_macro_end;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 Lisp_Object Vlast_kbd_macro;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 Lisp_Object Vexecuting_macro;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 int executing_macro_index;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 Lisp_Object Fexecute_kbd_macro ();
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 DEFUN ("start-kbd-macro", Fstart_kbd_macro, Sstart_kbd_macro, 1, 1, "P",
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 "Record subsequent keyboard input, defining a keyboard macro.\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 The commands are recorded even as they are executed.\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 Use \\[end-kbd-macro] to finish recording and make the macro available.\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 Use \\[name-last-kbd-macro] to give it a permanent name.\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 Non-nil arg (prefix arg) means append to last macro defined;\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 This begins by re-executing that macro as if you typed it again.")
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 (append)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 Lisp_Object append;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 if (defining_kbd_macro)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 error ("Already defining kbd macro");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 update_mode_lines++;
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 434
diff changeset
67 if (NILP (append))
246
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 kbd_macro_ptr = kbd_macro_buffer;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 kbd_macro_end = kbd_macro_buffer;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 message("Defining kbd macro...");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 else
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 message("Appending to kbd macro...");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 kbd_macro_ptr = kbd_macro_end;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 Fexecute_kbd_macro (Vlast_kbd_macro, make_number (1));
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 defining_kbd_macro++;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 return Qnil;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 DEFUN ("end-kbd-macro", Fend_kbd_macro, Send_kbd_macro, 0, 1, "p",
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 "Finish defining a keyboard macro.\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 The definition was started by \\[start-kbd-macro].\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 The macro is now available for use via \\[call-last-kbd-macro],\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 or it can be given a name with \\[name-last-kbd-macro] and then invoked\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 under that name.\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 \n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 With numeric arg, repeat macro now that many times,\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 counting the definition just completed as the first repetition.\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 An argument of zero means repeat until error.")
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 (arg)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 Lisp_Object arg;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 if (!defining_kbd_macro)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 error ("Not defining kbd macro.");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 434
diff changeset
100 if (NILP (arg))
246
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 XFASTINT (arg) = 1;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 else
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 CHECK_NUMBER (arg, 0);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 if (defining_kbd_macro)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 defining_kbd_macro = 0;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 update_mode_lines++;
2015
4fe063d2aecf (Fend_kbd_macro): Fix call to make_event_array.
Richard M. Stallman <rms@gnu.org>
parents: 1682
diff changeset
109 Vlast_kbd_macro = make_event_array (kbd_macro_end - kbd_macro_buffer,
4fe063d2aecf (Fend_kbd_macro): Fix call to make_event_array.
Richard M. Stallman <rms@gnu.org>
parents: 1682
diff changeset
110 kbd_macro_buffer);
246
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 message("Keyboard macro defined");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 if (XFASTINT (arg) == 0)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 Fexecute_kbd_macro (Vlast_kbd_macro, arg);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 else
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 {
1682
af0995b9b142 * macros.c (Fend_kbd_macro): Don't use XFASTINT to check if arg is
Jim Blandy <jimb@redhat.com>
parents: 647
diff changeset
118 XSETINT (arg, XINT (arg)-1);
af0995b9b142 * macros.c (Fend_kbd_macro): Don't use XFASTINT to check if arg is
Jim Blandy <jimb@redhat.com>
parents: 647
diff changeset
119 if (XINT (arg) > 0)
246
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 Fexecute_kbd_macro (Vlast_kbd_macro, arg);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 return Qnil;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 /* Store character c into kbd macro being defined */
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 store_kbd_macro_char (c)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 Lisp_Object c;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 if (defining_kbd_macro)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 if (kbd_macro_ptr - kbd_macro_buffer == kbd_macro_bufsize)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 register Lisp_Object *new
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 = (Lisp_Object *) xrealloc (kbd_macro_buffer,
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 ((kbd_macro_bufsize *= 2)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 * sizeof (Lisp_Object)));
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 kbd_macro_ptr += new - kbd_macro_buffer;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 kbd_macro_end += new - kbd_macro_buffer;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 kbd_macro_buffer = new;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 *kbd_macro_ptr++ = c;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 /* Declare that all chars stored so far in the kbd macro being defined
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 really belong to it. This is done in between editor commands. */
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 finalize_kbd_macro_chars ()
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 kbd_macro_end = kbd_macro_ptr;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 DEFUN ("call-last-kbd-macro", Fcall_last_kbd_macro, Scall_last_kbd_macro,
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 0, 1, "p",
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 "Call the last keyboard macro that you defined with \\[start-kbd-macro].\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 \n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 A prefix argument serves as a repeat count. Zero means repeat until error.\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 \n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 To make a macro permanent so you can call it even after\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 defining others, use \\[name-last-kbd-macro].")
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 (prefix)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 Lisp_Object prefix;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 if (defining_kbd_macro)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 error ("Can't execute anonymous macro while defining one");
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 434
diff changeset
167 else if (NILP (Vlast_kbd_macro))
246
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 error ("No kbd macro has been defined");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 else
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 Fexecute_kbd_macro (Vlast_kbd_macro, prefix);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 return Qnil;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 /* Restore Vexecuting_macro and executing_macro_index - called when
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 the unwind-protect in Fexecute_kbd_macro gets invoked. */
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 static Lisp_Object
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 pop_kbd_macro (info)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 Lisp_Object info;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 Lisp_Object tem;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 Vexecuting_macro = Fcar (info);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 tem = Fcdr (info);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 executing_macro_index = XINT (tem);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 return Qnil;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 DEFUN ("execute-kbd-macro", Fexecute_kbd_macro, Sexecute_kbd_macro, 1, 2, 0,
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 "Execute MACRO as string of editor command characters.\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 If MACRO is a symbol, its function definition is used.\n\
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 COUNT is a repeat count, or nil for once, or 0 for infinite loop.")
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 (macro, prefixarg)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 Lisp_Object macro, prefixarg;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 Lisp_Object final;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 Lisp_Object tem;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 int count = specpdl_ptr - specpdl;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 int repeat = 1;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 struct gcpro gcpro1;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 434
diff changeset
200 if (!NILP (prefixarg))
246
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 prefixarg = Fprefix_numeric_value (prefixarg),
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 repeat = XINT (prefixarg);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203
647
529171c8b71c entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
204 final = indirect_function (macro);
246
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 if (XTYPE (final) != Lisp_String
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 && XTYPE (final) != Lisp_Vector)
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 error ("Keyboard macros must be strings or vectors.");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 XFASTINT (tem) = executing_macro_index;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 tem = Fcons (Vexecuting_macro, tem);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 record_unwind_protect (pop_kbd_macro, tem);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 GCPRO1 (final);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 do
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 Vexecuting_macro = final;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 executing_macro_index = 0;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 command_loop_1 ();
1682
af0995b9b142 * macros.c (Fend_kbd_macro): Don't use XFASTINT to check if arg is
Jim Blandy <jimb@redhat.com>
parents: 647
diff changeset
220
af0995b9b142 * macros.c (Fend_kbd_macro): Don't use XFASTINT to check if arg is
Jim Blandy <jimb@redhat.com>
parents: 647
diff changeset
221 QUIT;
246
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 while (--repeat && (XTYPE (Vexecuting_macro) == Lisp_String
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 || XTYPE (Vexecuting_macro) == Lisp_Vector));
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 UNGCPRO;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 return unbind_to (count, Qnil);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 init_macros ()
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 Vlast_kbd_macro = Qnil;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 defining_kbd_macro = 0;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 Vexecuting_macro = Qnil;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 syms_of_macros ()
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 kbd_macro_bufsize = 100;
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 kbd_macro_buffer = (Lisp_Object *) malloc (kbd_macro_bufsize
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 * sizeof (Lisp_Object));
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 Qexecute_kbd_macro = intern ("execute-kbd-macro");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 staticpro (&Qexecute_kbd_macro);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 defsubr (&Sstart_kbd_macro);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 defsubr (&Send_kbd_macro);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 defsubr (&Scall_last_kbd_macro);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 defsubr (&Sexecute_kbd_macro);
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 DEFVAR_BOOL ("defining-kbd-macro", &defining_kbd_macro,
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 "Non-nil while a keyboard macro is being defined. Don't set this!");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 DEFVAR_LISP ("executing-macro", &Vexecuting_macro,
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 "Currently executing keyboard macro (a string); nil if none executing.");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 DEFVAR_LISP_NOPRO ("executing-kbd-macro", &Vexecuting_macro,
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 "Currently executing keyboard macro (a string); nil if none executing.");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 DEFVAR_LISP ("last-kbd-macro", &Vlast_kbd_macro,
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 "Last kbd macro defined, as a string; nil if none defined.");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 }
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 keys_of_macros ()
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 {
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 initial_define_key (control_x_map, ('e'), "call-last-kbd-macro");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 initial_define_key (control_x_map, ('('), "start-kbd-macro");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 initial_define_key (control_x_map, (')'), "end-kbd-macro");
81e375c3eb58 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 }