Mercurial > hg > xemacs-beta
annotate src/macros.c @ 5149:b72f27a08ed5
Reflect --with-datadir setting in late-package directories.
2010-03-18 Mike Sperber <mike@xemacs.org>
* configure.ac: Set LATE_PACKAGE_DIRECTORIES_USER_DEFINED if
`datadir' was changed; set `with_late_packages' to something
sensible for this case.
| author | Mike Sperber <sperber@deinprogramm.de> |
|---|---|
| date | Thu, 18 Mar 2010 13:42:29 +0100 |
| parents | 6f2158fa75ed |
| children | 308d34e9f07d |
| rev | line source |
|---|---|
| 428 | 1 /* Keyboard macros. |
| 2 Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc. | |
|
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
4677
diff
changeset
|
3 Copyright (C) 2010 Ben Wing. |
| 428 | 4 |
| 5 This file is part of XEmacs. | |
| 6 | |
| 7 XEmacs is free software; you can redistribute it and/or modify it | |
| 8 under the terms of the GNU General Public License as published by the | |
| 9 Free Software Foundation; either version 2, or (at your option) any | |
| 10 later version. | |
| 11 | |
| 12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 15 for more details. | |
| 16 | |
| 17 You should have received a copy of the GNU General Public License | |
| 18 along with XEmacs; see the file COPYING. If not, write to | |
| 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 20 Boston, MA 02111-1307, USA. */ | |
| 21 | |
| 22 /* Synched up with: FSF 19.30. */ | |
| 23 | |
| 24 /* A keyboard macro is a string of ASCII characters, or a vector of event | |
| 25 objects. Only key-press, mouse-press, mouse-release, and menu-selection | |
| 26 events ever get into a keyboard macro. | |
| 27 | |
| 28 When interactively defining a keyboard macro, it will always be a vector | |
| 29 of events; strings may be executed for backwards compatibility. | |
| 30 */ | |
| 31 | |
| 32 #include <config.h> | |
| 33 #include "lisp.h" | |
| 800 | 34 |
| 35 #include "buffer.h" | |
| 428 | 36 #include "commands.h" |
| 872 | 37 #include "console-impl.h" |
| 800 | 38 #include "device.h" |
| 39 #include "events.h" | |
| 428 | 40 #include "frame.h" |
| 41 #include "keymap.h" | |
| 800 | 42 #include "macros.h" |
| 43 #include "window.h" | |
| 428 | 44 |
| 45 Lisp_Object Qexecute_kbd_macro; | |
| 46 | |
| 47 /* The current macro and our position in it. When executing nested kbd | |
| 48 macros, previous values for these are wound through the execution stack | |
| 49 with unwind-protect. | |
| 50 */ | |
| 51 Lisp_Object Vexecuting_macro; | |
| 52 int executing_macro_index; | |
| 53 | |
| 54 | |
| 55 DEFUN ("start-kbd-macro", Fstart_kbd_macro, 1, 1, "P", /* | |
| 56 Record subsequent keyboard and menu input, defining a keyboard macro. | |
| 57 The commands are recorded even as they are executed. | |
| 58 Use \\[end-kbd-macro] to finish recording and make the macro available. | |
| 59 Use \\[name-last-kbd-macro] to give it a permanent name. | |
| 60 Non-nil arg (prefix arg) means append to last macro defined; | |
| 61 This begins by re-executing that macro as if you typed it again. | |
| 62 */ | |
| 63 (append)) | |
| 64 { | |
| 65 /* This function can GC */ | |
| 66 struct console *con = XCONSOLE (Vselected_console); | |
| 67 if (!NILP (con->defining_kbd_macro)) | |
| 563 | 68 invalid_operation ("Already defining kbd macro", Qunbound); |
| 428 | 69 |
| 70 if (NILP (con->kbd_macro_builder)) | |
| 71 con->kbd_macro_builder = make_vector (30, Qnil); | |
| 72 | |
| 73 zmacs_region_stays = 1; /* set this before calling Fexecute_kbd_macro() | |
| 74 so that functions there can override */ | |
| 75 MARK_MODELINE_CHANGED; | |
| 76 if (NILP (append)) | |
| 77 { | |
| 78 con->kbd_macro_ptr = 0; | |
| 79 con->kbd_macro_end = 0; | |
| 80 message ("Defining kbd macro..."); | |
| 81 } | |
| 82 else | |
| 83 { | |
| 84 message ("Appending to kbd macro..."); | |
| 85 con->kbd_macro_ptr = con->kbd_macro_end; | |
| 86 Fexecute_kbd_macro (con->last_kbd_macro, make_int (1)); | |
| 87 } | |
| 88 con->defining_kbd_macro = Qt; | |
| 89 | |
| 90 return Qnil; | |
| 91 } | |
| 92 | |
| 93 DEFUN ("end-kbd-macro", Fend_kbd_macro, 0, 1, "P", /* | |
| 94 Finish defining a keyboard macro. | |
| 95 The definition was started by \\[start-kbd-macro]. | |
| 96 The macro is now available for use via \\[call-last-kbd-macro], | |
| 97 or it can be given a name with \\[name-last-kbd-macro] and then invoked | |
| 98 under that name. | |
| 99 | |
| 100 With numeric arg, repeat macro now that many times, | |
| 101 counting the definition just completed as the first repetition. | |
| 102 An argument of zero means repeat until error. | |
| 103 */ | |
| 104 (arg)) | |
| 105 { | |
| 106 /* This function can GC */ | |
| 107 struct console *con = XCONSOLE (Vselected_console); | |
| 108 int repeat; | |
| 109 | |
| 110 if (NILP (con->defining_kbd_macro)) | |
| 563 | 111 invalid_operation ("Not defining kbd macro", Qunbound); |
| 428 | 112 |
| 113 if (NILP (arg)) | |
| 114 repeat = -1; | |
| 115 else | |
| 116 repeat = XINT (Fprefix_numeric_value (arg)); | |
| 117 | |
| 118 if (!NILP (con->defining_kbd_macro)) | |
| 119 { | |
| 120 int i; | |
| 121 int size = con->kbd_macro_end; | |
| 122 | |
| 123 if (size < 0) | |
| 124 size = 0; | |
| 125 con->last_kbd_macro = make_vector (size, Qnil); | |
| 126 for (i = 0; i < size; i++) | |
| 127 XVECTOR_DATA (con->last_kbd_macro) [i] = | |
| 128 XVECTOR_DATA (con->kbd_macro_builder) [i]; | |
| 129 con->defining_kbd_macro = Qnil; | |
| 130 MARK_MODELINE_CHANGED; | |
| 131 message ("Keyboard macro defined"); | |
| 132 } | |
| 133 | |
| 134 zmacs_region_stays = 1; /* set this before calling Fexecute_kbd_macro() | |
| 135 so that functions there can override */ | |
| 136 if (repeat < 0) | |
| 137 return Qnil; | |
| 138 else if (repeat == 0) | |
| 139 return Fexecute_kbd_macro (con->last_kbd_macro, Qzero); | |
| 140 else | |
| 141 return Fexecute_kbd_macro (con->last_kbd_macro, | |
| 142 make_int (repeat - 1)); | |
| 143 } | |
| 144 | |
| 145 /* #### Read the comment in modeline.el to see why this ugliness is | |
| 146 needed. #### Try to avoid it, somehow! */ | |
| 147 DEFUN ("zap-last-kbd-macro-event", Fzap_last_kbd_macro_event, 0, 0, 0, /* | |
| 148 Don't look at this lest you vomit or spontaneously combust. | |
| 149 */ | |
| 150 ()) | |
| 151 { | |
| 152 struct console *con = XCONSOLE (Vselected_console); | |
| 153 if (con->kbd_macro_end) | |
| 154 --con->kbd_macro_end; | |
| 155 return Qnil; | |
| 156 } | |
| 157 | |
| 158 /* Store event into kbd macro being defined | |
| 159 */ | |
| 160 void | |
| 161 store_kbd_macro_event (Lisp_Object event) | |
| 162 { | |
| 163 struct console *con = event_console_or_selected (event); | |
| 164 | |
| 165 if (con->kbd_macro_ptr == XVECTOR_LENGTH (con->kbd_macro_builder)) | |
| 166 { | |
| 167 int i; | |
| 168 int old_size = XVECTOR_LENGTH (con->kbd_macro_builder); | |
| 169 int new_size = old_size * 2; | |
| 3025 | 170 Lisp_Object new_ = make_vector (new_size, Qnil); |
| 428 | 171 for (i = 0; i < old_size; i++) |
| 3025 | 172 XVECTOR_DATA (new_) [i] = XVECTOR_DATA (con->kbd_macro_builder) [i]; |
| 173 con->kbd_macro_builder = new_; | |
| 428 | 174 } |
| 175 XVECTOR_DATA (con->kbd_macro_builder) [con->kbd_macro_ptr++] = | |
| 176 Fcopy_event (event, Qnil); | |
| 177 } | |
| 178 | |
| 179 /* Extract the next kbd-macro element into the given event. | |
| 180 If we're done, throws to the catch in Fexecute_kbd_macro(). | |
| 181 */ | |
| 182 void | |
| 183 pop_kbd_macro_event (Lisp_Object event) | |
| 184 { | |
|
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
4677
diff
changeset
|
185 assert (!NILP (Vexecuting_macro)); |
| 428 | 186 |
| 187 if (STRINGP (Vexecuting_macro) || VECTORP (Vexecuting_macro)) | |
| 188 { | |
| 189 if (executing_macro_index < XINT (Flength (Vexecuting_macro))) | |
| 190 { | |
| 191 nth_of_key_sequence_as_event (Vexecuting_macro, | |
| 192 executing_macro_index++, | |
| 193 event); | |
| 194 return; | |
| 195 } | |
| 196 } | |
| 197 else if (!EQ (Vexecuting_macro, Qt)) /* Some things replace the macro | |
| 198 with Qt to force an early exit. */ | |
| 563 | 199 signal_error (Qinvalid_state, "junk in executing-macro", Qunbound); |
| 428 | 200 |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3025
diff
changeset
|
201 throw_or_bomb_out (Qexecute_kbd_macro, Qt, 0, Qnil, Qnil); |
| 428 | 202 } |
| 203 | |
| 204 | |
| 205 /* Declare that all chars stored so far in the kbd macro being defined | |
| 206 really belong to it. This is done in between editor commands. */ | |
| 207 | |
| 208 void | |
| 209 finalize_kbd_macro_chars (struct console *con) | |
| 210 { | |
| 211 con->kbd_macro_end = con->kbd_macro_ptr; | |
| 212 } | |
| 213 | |
| 214 DEFUN ("cancel-kbd-macro-events", Fcancel_kbd_macro_events, 0, 0, 0, /* | |
| 215 Cancel the events added to a keyboard macro for this command. | |
| 216 */ | |
| 217 ()) | |
| 218 { | |
| 219 struct console *con = XCONSOLE (Vselected_console); | |
| 220 | |
| 221 con->kbd_macro_ptr = con->kbd_macro_end; | |
| 222 | |
| 223 return Qnil; | |
| 224 } | |
| 225 | |
| 226 DEFUN ("call-last-kbd-macro", Fcall_last_kbd_macro, 0, 1, "p", /* | |
| 227 Call the last keyboard macro that you defined with \\[start-kbd-macro]. | |
| 228 | |
| 229 A prefix argument serves as a repeat count. Zero means repeat until error. | |
| 230 | |
| 231 To make a macro permanent so you can call it even after | |
| 232 defining others, use \\[name-last-kbd-macro]. | |
| 233 */ | |
| 234 (prefix)) | |
| 235 { | |
| 236 /* This function can GC */ | |
| 237 struct console *con = XCONSOLE (Vselected_console); | |
| 238 | |
| 239 if (!NILP (con->defining_kbd_macro)) | |
| 563 | 240 invalid_operation ("Can't execute anonymous macro while defining one", Qunbound); |
| 428 | 241 else if (NILP (con->last_kbd_macro)) |
| 563 | 242 invalid_operation ("No kbd macro has been defined", Qunbound); |
| 428 | 243 else |
| 244 Fexecute_kbd_macro (con->last_kbd_macro, prefix); | |
| 245 return Qnil; | |
| 246 } | |
| 247 | |
| 248 DEFUN ("execute-kbd-macro", Fexecute_kbd_macro, 1, 2, 0, /* | |
| 249 Execute MACRO as string of editor command characters. | |
| 250 If MACRO is a symbol, its function definition is used. | |
| 251 COUNT is a repeat count, or nil for once, or 0 for infinite loop. | |
| 252 */ | |
| 444 | 253 (macro, count)) |
| 428 | 254 { |
| 255 /* This function can GC */ | |
| 256 Lisp_Object final; | |
| 257 int speccount = specpdl_depth (); | |
| 258 int repeat = 1; | |
| 259 struct gcpro gcpro1; | |
| 260 struct console *con = XCONSOLE (Vselected_console); | |
| 261 | |
| 444 | 262 if (!NILP (count)) |
| 428 | 263 { |
| 444 | 264 count = Fprefix_numeric_value (count); |
| 265 repeat = XINT (count); | |
| 428 | 266 } |
| 267 | |
| 268 final = indirect_function (macro, 1); | |
| 269 if (!STRINGP (final) && !VECTORP (final)) | |
| 563 | 270 invalid_argument ("Keyboard macros must be strings or vectors", Qunbound); |
| 428 | 271 |
| 853 | 272 internal_bind_lisp_object (&Vexecuting_macro, Vexecuting_macro); |
| 273 internal_bind_int (&executing_macro_index, executing_macro_index); | |
| 428 | 274 |
| 275 GCPRO1 (final); | |
| 276 do | |
| 277 { | |
| 278 Vexecuting_macro = final; | |
| 279 executing_macro_index = 0; | |
| 280 con->prefix_arg = Qnil; | |
| 281 internal_catch (Qexecute_kbd_macro, call_command_loop, | |
| 2532 | 282 Qnil, 0, 0, 0); |
| 428 | 283 } |
| 284 while (--repeat != 0 | |
| 285 && (STRINGP (Vexecuting_macro) || | |
| 286 VECTORP (Vexecuting_macro))); | |
| 287 | |
| 288 UNGCPRO; | |
| 771 | 289 return unbind_to (speccount); |
| 428 | 290 } |
| 291 | |
| 292 | |
| 293 void | |
| 294 syms_of_macros (void) | |
| 295 { | |
| 296 DEFSUBR (Fstart_kbd_macro); | |
| 297 DEFSUBR (Fend_kbd_macro); | |
| 298 DEFSUBR (Fzap_last_kbd_macro_event); | |
| 299 DEFSUBR (Fcall_last_kbd_macro); | |
| 300 DEFSUBR (Fexecute_kbd_macro); | |
| 301 DEFSUBR (Fcancel_kbd_macro_events); | |
| 563 | 302 DEFSYMBOL (Qexecute_kbd_macro); |
| 428 | 303 } |
| 304 | |
| 305 void | |
| 306 vars_of_macros (void) | |
| 307 { | |
| 308 DEFVAR_LISP ("executing-macro", &Vexecuting_macro /* | |
| 309 Currently executing keyboard macro (a vector of events or string); | |
| 310 nil if none executing. | |
| 311 */ ); | |
| 312 | |
| 313 DEFVAR_LISP ("executing-kbd-macro", &Vexecuting_macro /* | |
| 314 Currently executing keyboard macro (a vector of events or string); | |
| 315 nil if none executing. | |
| 316 */ ); | |
| 317 } | |
| 318 | |
| 319 void | |
| 320 init_macros (void) | |
| 321 { | |
| 322 Vexecuting_macro = Qnil; | |
| 323 } | |
| 324 |
