emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there a plan to record kbd macro as elisp code?


From: yzhh
Subject: Re: Is there a plan to record kbd macro as elisp code?
Date: Sun, 28 Oct 2007 07:13:51 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Ah, I forgot the code:

Index: src/keyboard.c
===================================================================
--- src/keyboard.c      (revision 4)
+++ src/keyboard.c      (revision 7)
@@ -10020,6 +10020,24 @@
            }
        }

This approach looks quite promising. 


Index: src/keyboard.c
===================================================================
--- src/keyboard.c      (revision 4)
+++ src/keyboard.c      (revision 7)
@@ -10020,6 +10020,24 @@
            }
        }
 
+      /* Record every command for kbd macro's purpose. */
+      if (!NILP (current_kboard->defining_kbd_macro)
+          && NILP (Vexecuting_kbd_macro))
+        {
+          Vkbd_macro_command_history
+            = Fcons (Fcons (Qexecute_kbd_macro,
+                            Fcons (final, Fcons (prefixarg, Qnil))),
+                     Vkbd_macro_command_history);
+
+          /* Don't keep command history around forever.  */
+          if (NUMBERP (Vhistory_length) && XINT (Vhistory_length) > 0)
+            {
+              tem = Fnthcdr (Vhistory_length, Vkbd_macro_command_history);
+              if (CONSP (tem))
+                XSETCDR (tem, Qnil);
+            }
+        }
+  
       return Fexecute_kbd_macro (final, prefixarg, Qnil);
     }
 
Index: src/lisp.h
===================================================================
--- src/lisp.h  (revision 4)
+++ src/lisp.h  (revision 7)
@@ -2945,6 +2945,7 @@
 
 extern Lisp_Object Qminus, Qplus, Vcurrent_prefix_arg;
 extern Lisp_Object Vcommand_history;
+extern Lisp_Object Vkbd_macro_command_history;
 extern Lisp_Object Qcall_interactively, Qmouse_leave_buffer_hook;
 EXFUN (Fcall_interactively, 3);
 EXFUN (Fprefix_numeric_value, 1);
Index: src/callint.c
===================================================================
--- src/callint.c       (revision 4)
+++ src/callint.c       (revision 7)
@@ -39,6 +39,7 @@
 Lisp_Object Vcurrent_prefix_arg, Qminus, Qplus;
 Lisp_Object Qcall_interactively;
 Lisp_Object Vcommand_history;
+Lisp_Object Vkbd_macro_command_history;
 
 extern Lisp_Object Vhistory_length;
 extern Lisp_Object Vthis_original_command, real_this_command;
@@ -377,6 +378,7 @@
       GCPRO2 (input, filter_specs);
       specs = Feval (specs);
       UNGCPRO;
+
       if (i != num_input_events || !NILP (record_flag))
        {
          /* We should record this command on the command history.  */
@@ -397,6 +399,28 @@
            }
        }
 
+      /* Record every command for kbd macro's purpose. */
+      if ((i != num_input_events)
+          || (!NILP (current_kboard->defining_kbd_macro)
+              && NILP (Vexecuting_kbd_macro)))
+        {
+         Lisp_Object values;
+         /* Make a copy of the list of values, for the command history,
+            and turn them into things we can eval.  */
+         values = quotify_args (Fcopy_sequence (specs));
+         fix_command (input, values);
+         Vkbd_macro_command_history
+           = Fcons (Fcons (function, values), Vkbd_macro_command_history);
+
+         /* Don't keep command history around forever.  */
+         if (INTEGERP (Vhistory_length) && XINT (Vhistory_length) > 0)
+           {
+             teml = Fnthcdr (Vhistory_length, Vkbd_macro_command_history);
+             if (CONSP (teml))
+               XSETCDR (teml, Qnil);
+           }
+        }
+
       Vthis_command = save_this_command;
       Vthis_original_command = save_this_original_command;
       real_this_command= save_real_this_command;
@@ -837,6 +861,30 @@
        }
     }
 
+  /* Record every command for kbd macro's purpose. */
+  if (arg_from_tty || (!NILP (current_kboard->defining_kbd_macro)
+                       && NILP (Vexecuting_kbd_macro)))
+    {
+      visargs[0] = function;
+      for (i = 1; i < count + 1; i++)
+       {
+         if (varies[i] > 0)
+           visargs[i] = Fcons (intern (callint_argfuns[varies[i]]), Qnil);
+         else
+           visargs[i] = quotify_arg (args[i]);
+       }
+      Vkbd_macro_command_history = Fcons (Flist (count + 1, visargs),
+                               Vkbd_macro_command_history);
+      /* Don't keep command history around forever.  */
+      if (INTEGERP (Vhistory_length) && XINT (Vhistory_length) > 0)
+       {
+         teml = Fnthcdr (Vhistory_length, Vkbd_macro_command_history);
+         if (CONSP (teml))
+           XSETCDR (teml, Qnil);
+       }
+    }
+
+
   /* If we used a marker to hold point, mark, or an end of the region,
      temporarily, convert it to an integer now.  */
   for (i = 1; i <= count; i++)
@@ -963,6 +1011,11 @@
 Each command is represented as a form to evaluate.  */);
   Vcommand_history = Qnil;
 
+  DEFVAR_LISP ("kbd-macro-command-history", &Vkbd_macro_command_history,
+              doc: /* List of commands recorded in the last keyboard macro.
+Each command is represented as a form to evaluate.  */);
+  Vkbd_macro_command_history = Qnil;
+
   DEFVAR_LISP ("command-debug-status", &Vcommand_debug_status,
               doc: /* Debugging status of current interactive command.
 Bound each time `call-interactively' is called;






reply via email to

[Prev in Thread] Current Thread [Next in Thread]