]> code.delx.au - gnu-emacs/blobdiff - src/macros.c
(add_properties, remove_properties, set_properties):
[gnu-emacs] / src / macros.c
index 5b19d926d6611a2f4dcc1e0e6af239334b9d0776..bbf5661377c048933272f981db2b10520d5a5364 100644 (file)
@@ -1,11 +1,11 @@
 /* Keyboard macros.
 /* Keyboard macros.
-   Copyright (C) 1985, 1986 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1993 Free Software Foundation, Inc.
 
 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
 
 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
-the Free Software Foundation; either version 1, or (at your option)
+the Free Software Foundation; either version 2, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -18,33 +18,16 @@ along with GNU Emacs; see the file COPYING.  If not, write to
 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 
 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 
-#include "config.h"
+#include <config.h>
 #include "lisp.h"
 #include "macros.h"
 #include "commands.h"
 #include "buffer.h"
 #include "window.h"
 #include "lisp.h"
 #include "macros.h"
 #include "commands.h"
 #include "buffer.h"
 #include "window.h"
+#include "keyboard.h"
 
 Lisp_Object Qexecute_kbd_macro;
 
 
 Lisp_Object Qexecute_kbd_macro;
 
-int defining_kbd_macro;
-
-/* The start of storage for the current keyboard macro, and its size.  */
-Lisp_Object *kbd_macro_buffer;
-int kbd_macro_bufsize;
-
-/* Where to store the next keystroke of the macro.  */
-Lisp_Object *kbd_macro_ptr;
-
-/* The finalized section of the macro starts at kbd_macro_buffer and
-   ends before this.  This is not the same as kbd_macro_pointer, because
-   we advance this to kbd_macro_pointer when a key's command is complete.
-   This way, the keystrokes for "end-kbd-macro" are not included in the
-   macro.  */
-Lisp_Object *kbd_macro_end;
-
-Lisp_Object Vlast_kbd_macro;
-
 Lisp_Object Vexecuting_macro;
 int executing_macro_index;
 
 Lisp_Object Vexecuting_macro;
 int executing_macro_index;
 
@@ -60,23 +43,30 @@ Non-nil arg (prefix arg) means append to last macro defined;\n\
   (append)
      Lisp_Object append;
 {
   (append)
      Lisp_Object append;
 {
-  if (defining_kbd_macro)
+  if (!NILP (current_kboard->defining_kbd_macro))
     error ("Already defining kbd macro");
 
     error ("Already defining kbd macro");
 
+  if (!current_kboard->kbd_macro_buffer)
+    {
+      current_kboard->kbd_macro_bufsize = 30;
+      current_kboard->kbd_macro_buffer
+       = (Lisp_Object *)malloc (30 * sizeof (Lisp_Object));
+    }
   update_mode_lines++;
   update_mode_lines++;
-  if (NULL (append))
+  if (NILP (append))
     {
     {
-      kbd_macro_ptr = kbd_macro_buffer;
-      kbd_macro_end = kbd_macro_buffer;
+      current_kboard->kbd_macro_ptr = current_kboard->kbd_macro_buffer;
+      current_kboard->kbd_macro_end = current_kboard->kbd_macro_buffer;
       message("Defining kbd macro...");
     }
   else
     {
       message("Appending to kbd macro...");
       message("Defining kbd macro...");
     }
   else
     {
       message("Appending to kbd macro...");
-      kbd_macro_ptr = kbd_macro_end;
-      Fexecute_kbd_macro (Vlast_kbd_macro, make_number (1));
+      current_kboard->kbd_macro_ptr = current_kboard->kbd_macro_end;
+      Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro,
+                         make_number (1));
     }
     }
-  defining_kbd_macro++;
+  current_kboard->defining_kbd_macro = Qt;
   
   return Qnil;
 }
   
   return Qnil;
 }
@@ -94,30 +84,32 @@ An argument of zero means repeat until error.")
   (arg)
      Lisp_Object arg;
 {
   (arg)
      Lisp_Object arg;
 {
-  if (!defining_kbd_macro)
-      error ("Not defining kbd macro.");
+  if (NILP (current_kboard->defining_kbd_macro))
+    error ("Not defining kbd macro.");
 
 
-  if (NULL (arg))
-    XFASTINT (arg) = 1;
+  if (NILP (arg))
+    XSETFASTINT (arg, 1);
   else
     CHECK_NUMBER (arg, 0);
 
   else
     CHECK_NUMBER (arg, 0);
 
-  if (defining_kbd_macro)
+  if (!NILP (current_kboard->defining_kbd_macro))
     {
     {
-      defining_kbd_macro = 0;
+      current_kboard->defining_kbd_macro = Qnil;
       update_mode_lines++;
       update_mode_lines++;
-      Vlast_kbd_macro = make_array (kbd_macro_end - kbd_macro_buffer,
-                                   kbd_macro_buffer);
+      current_kboard->Vlast_kbd_macro
+       = make_event_array ((current_kboard->kbd_macro_end
+                            - current_kboard->kbd_macro_buffer),
+                           current_kboard->kbd_macro_buffer);
       message("Keyboard macro defined");
     }
 
   if (XFASTINT (arg) == 0)
       message("Keyboard macro defined");
     }
 
   if (XFASTINT (arg) == 0)
-    Fexecute_kbd_macro (Vlast_kbd_macro, arg);
+    Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, arg);
   else
     {
   else
     {
-      XFASTINT (arg)--;
-      if (XFASTINT (arg) > 0)
-       Fexecute_kbd_macro (Vlast_kbd_macro, arg);
+      XSETINT (arg, XINT (arg)-1);
+      if (XINT (arg) > 0)
+       Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, arg);
     }
   return Qnil;
 }
     }
   return Qnil;
 }
@@ -127,19 +119,24 @@ An argument of zero means repeat until error.")
 store_kbd_macro_char (c)
      Lisp_Object c;
 {
 store_kbd_macro_char (c)
      Lisp_Object c;
 {
-  if (defining_kbd_macro)
+  if (!NILP (current_kboard->defining_kbd_macro))
     {
     {
-      if (kbd_macro_ptr - kbd_macro_buffer == kbd_macro_bufsize)
+      if ((current_kboard->kbd_macro_ptr
+          - current_kboard->kbd_macro_buffer)
+         == current_kboard->kbd_macro_bufsize)
        {
        {
-         register Lisp_Object *new
-           = (Lisp_Object *) xrealloc (kbd_macro_buffer,
-                                       ((kbd_macro_bufsize *= 2)
-                                        * sizeof (Lisp_Object)));
-         kbd_macro_ptr += new - kbd_macro_buffer;
-         kbd_macro_end += new - kbd_macro_buffer;
-         kbd_macro_buffer = new;
+         register Lisp_Object *new;
+         current_kboard->kbd_macro_bufsize *= 2;
+         new = (Lisp_Object *)xrealloc (current_kboard->kbd_macro_buffer,
+                                        (current_kboard->kbd_macro_bufsize
+                                         * sizeof (Lisp_Object)));
+         current_kboard->kbd_macro_ptr
+           += new - current_kboard->kbd_macro_buffer;
+         current_kboard->kbd_macro_end
+           += new - current_kboard->kbd_macro_buffer;
+         current_kboard->kbd_macro_buffer = new;
        }
        }
-      *kbd_macro_ptr++ = c;
+      *current_kboard->kbd_macro_ptr++ = c;
     }
 }
 
     }
 }
 
@@ -148,7 +145,25 @@ store_kbd_macro_char (c)
 
 finalize_kbd_macro_chars ()
 {
 
 finalize_kbd_macro_chars ()
 {
-  kbd_macro_end = kbd_macro_ptr;
+  current_kboard->kbd_macro_end = current_kboard->kbd_macro_ptr;
+}
+
+DEFUN ("cancel-kbd-macro-events", Fcancel_kbd_macro_events,
+       Scancel_kbd_macro_events, 0, 0, 0,
+  "Cancel the events added to a keyboard macro for this command.")
+  ()
+{
+  current_kboard->kbd_macro_ptr = current_kboard->kbd_macro_end;
+}
+
+DEFUN ("store-kbd-macro-event", Fstore_kbd_macro_event,
+       Sstore_kbd_macro_event, 1, 1, 0,
+  "Store EVENT into the keyboard macro being defined.")
+  (event)
+     Lisp_Object event;
+{
+  store_kbd_macro_char (event);
+  return Qnil;
 }
 \f
 DEFUN ("call-last-kbd-macro", Fcall_last_kbd_macro, Scall_last_kbd_macro,
 }
 \f
 DEFUN ("call-last-kbd-macro", Fcall_last_kbd_macro, Scall_last_kbd_macro,
@@ -162,12 +177,12 @@ defining others, use \\[name-last-kbd-macro].")
   (prefix)
      Lisp_Object prefix;
 {
   (prefix)
      Lisp_Object prefix;
 {
-  if (defining_kbd_macro)
+  if (! NILP (current_kboard->defining_kbd_macro))
     error ("Can't execute anonymous macro while defining one");
     error ("Can't execute anonymous macro while defining one");
-  else if (NULL (Vlast_kbd_macro))
+  else if (NILP (current_kboard->Vlast_kbd_macro))
     error ("No kbd macro has been defined");
   else
     error ("No kbd macro has been defined");
   else
-    Fexecute_kbd_macro (Vlast_kbd_macro, prefix);
+    Fexecute_kbd_macro (current_kboard->Vlast_kbd_macro, prefix);
   return Qnil;
 }
 
   return Qnil;
 }
 
@@ -197,18 +212,15 @@ COUNT is a repeat count, or nil for once, or 0 for infinite loop.")
   int repeat = 1;
   struct gcpro gcpro1;
 
   int repeat = 1;
   struct gcpro gcpro1;
 
-  if (!NULL (prefixarg))
+  if (!NILP (prefixarg))
     prefixarg = Fprefix_numeric_value (prefixarg),
     repeat = XINT (prefixarg);
 
     prefixarg = Fprefix_numeric_value (prefixarg),
     repeat = XINT (prefixarg);
 
-  final = macro;
-  while (XTYPE (final) == Lisp_Symbol && !EQ (final, Qunbound))
-    final = XSYMBOL (final)->function;
-  if (XTYPE (final) != Lisp_String
-      && XTYPE (final) != Lisp_Vector)
+  final = indirect_function (macro);
+  if (!STRINGP (final) && !VECTORP (final))
     error ("Keyboard macros must be strings or vectors.");
 
     error ("Keyboard macros must be strings or vectors.");
 
-  XFASTINT (tem) = executing_macro_index;
+  XSETFASTINT (tem, executing_macro_index);
   tem = Fcons (Vexecuting_macro, tem);
   record_unwind_protect (pop_kbd_macro, tem);
 
   tem = Fcons (Vexecuting_macro, tem);
   record_unwind_protect (pop_kbd_macro, tem);
 
@@ -218,10 +230,13 @@ COUNT is a repeat count, or nil for once, or 0 for infinite loop.")
       Vexecuting_macro = final;
       executing_macro_index = 0;
 
       Vexecuting_macro = final;
       executing_macro_index = 0;
 
+      current_kboard->Vprefix_arg = Qnil;
       command_loop_1 ();
       command_loop_1 ();
+
+      QUIT;
     }
     }
-  while (--repeat && (XTYPE (Vexecuting_macro) == Lisp_String
-                     || XTYPE (Vexecuting_macro) == Lisp_Vector));
+  while (--repeat
+        && (STRINGP (Vexecuting_macro) || VECTORP (Vexecuting_macro)));
 
   UNGCPRO;
   return unbind_to (count, Qnil);
 
   UNGCPRO;
   return unbind_to (count, Qnil);
@@ -229,18 +244,11 @@ COUNT is a repeat count, or nil for once, or 0 for infinite loop.")
 \f
 init_macros ()
 {
 \f
 init_macros ()
 {
-  Vlast_kbd_macro = Qnil;
-  defining_kbd_macro = 0;
-
   Vexecuting_macro = Qnil;
 }
 
 syms_of_macros ()
 {
   Vexecuting_macro = Qnil;
 }
 
 syms_of_macros ()
 {
-  kbd_macro_bufsize = 100;
-  kbd_macro_buffer = (Lisp_Object *) malloc (kbd_macro_bufsize
-                                            * sizeof (Lisp_Object));
-
   Qexecute_kbd_macro = intern ("execute-kbd-macro");
   staticpro (&Qexecute_kbd_macro);
 
   Qexecute_kbd_macro = intern ("execute-kbd-macro");
   staticpro (&Qexecute_kbd_macro);
 
@@ -248,18 +256,20 @@ syms_of_macros ()
   defsubr (&Send_kbd_macro);
   defsubr (&Scall_last_kbd_macro);
   defsubr (&Sexecute_kbd_macro);
   defsubr (&Send_kbd_macro);
   defsubr (&Scall_last_kbd_macro);
   defsubr (&Sexecute_kbd_macro);
+  defsubr (&Scancel_kbd_macro_events);
+  defsubr (&Sstore_kbd_macro_event);
 
 
-  DEFVAR_BOOL ("defining-kbd-macro", &defining_kbd_macro,
+  DEFVAR_KBOARD ("defining-kbd-macro", defining_kbd_macro,
     "Non-nil while a keyboard macro is being defined.  Don't set this!");
 
   DEFVAR_LISP ("executing-macro", &Vexecuting_macro,
     "Non-nil while a keyboard macro is being defined.  Don't set this!");
 
   DEFVAR_LISP ("executing-macro", &Vexecuting_macro,
-    "Currently executing keyboard macro (a string); nil if none executing.");
+    "Currently executing keyboard macro (string or vector); nil if none executing.");
 
   DEFVAR_LISP_NOPRO ("executing-kbd-macro", &Vexecuting_macro,
 
   DEFVAR_LISP_NOPRO ("executing-kbd-macro", &Vexecuting_macro,
-    "Currently executing keyboard macro (a string); nil if none executing.");
+    "Currently executing keyboard macro (string or vector); nil if none executing.");
 
 
-  DEFVAR_LISP ("last-kbd-macro", &Vlast_kbd_macro,
-    "Last kbd macro defined, as a string; nil if none defined.");
+  DEFVAR_KBOARD ("last-kbd-macro", Vlast_kbd_macro,
+    "Last kbd macro defined, as a string or vector; nil if none defined.");
 }
 
 keys_of_macros ()
 }
 
 keys_of_macros ()