]> code.delx.au - gnu-emacs/blobdiff - src/callint.c
(shrink_regexp_cache): Use xrealloc.
[gnu-emacs] / src / callint.c
index b4b1e198544fa708ce491fa25a2901fc361ce9a0..4edb4201fa4b1e6786bd8c911006330839f41e3c 100644 (file)
@@ -1,5 +1,5 @@
 /* Call a Lisp function interactively.
-   Copyright (C) 1985, 86, 93, 94, 95, 1997, 2000, 2002
+   Copyright (C) 1985, 86, 93, 94, 95, 1997, 2000, 02, 2003
    Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -51,7 +51,7 @@ Lisp_Object Vmark_even_if_inactive;
 
 Lisp_Object Vmouse_leave_buffer_hook, Qmouse_leave_buffer_hook;
 
-Lisp_Object Qlist, Qlet, Qletx, Qsave_excursion, Qprogn;
+Lisp_Object Qlist, Qlet, Qletx, Qsave_excursion, Qprogn, Qif, Qwhen;
 static Lisp_Object preserved_fns;
 
 /* Marker used within call-interactively to refer to point.  */
@@ -174,6 +174,74 @@ check_mark (for_region)
     Fsignal (Qmark_inactive, Qnil);
 }
 
+/* If the list of args INPUT was produced with an explicit call to
+   `list', look for elements that were computed with
+   (region-beginning) or (region-end), and put those expressions into
+   VALUES instead of the present values.
+
+   This function doesn't return a value because it modifies elements
+   of VALUES to do its job.  */
+
+static void
+fix_command (input, values)
+     Lisp_Object input, values;
+{
+  if (CONSP (input))
+    {
+      Lisp_Object car;
+
+      car = XCAR (input);
+      /* Skip through certain special forms.  */
+      while (EQ (car, Qlet) || EQ (car, Qletx)
+            || EQ (car, Qsave_excursion)
+            || EQ (car, Qprogn))
+       {
+         while (CONSP (XCDR (input)))
+           input = XCDR (input);
+         input = XCAR (input);
+         if (!CONSP (input))
+           break;
+         car = XCAR (input);
+       }
+      if (EQ (car, Qlist))
+       {
+         Lisp_Object intail, valtail;
+         for (intail = Fcdr (input), valtail = values;
+              CONSP (valtail);
+              intail = Fcdr (intail), valtail = Fcdr (valtail))
+           {
+             Lisp_Object elt;
+             elt = Fcar (intail);
+             if (CONSP (elt))
+               {
+                 Lisp_Object presflag, carelt;
+                 carelt = Fcar (elt);
+                 /* If it is (if X Y), look at Y.  */
+                 if (EQ (carelt, Qif)
+                     && EQ (Fnthcdr (make_number (3), elt), Qnil))
+                   elt = Fnth (make_number (2), elt);
+                 /* If it is (when ... Y), look at Y.  */
+                 else if (EQ (carelt, Qwhen))
+                   {
+                     while (CONSP (XCDR (elt)))
+                       elt = XCDR (elt);
+                     elt = Fcar (elt);
+                   }
+
+                 /* If the function call we're looking at
+                    is a special preserved one, copy the
+                    whole expression for this argument.  */
+                 if (CONSP (elt))
+                   {
+                     presflag = Fmemq (Fcar (elt), preserved_fns);
+                     if (!NILP (presflag))
+                       Fsetcar (valtail, Fcar (intail));
+                   }
+               }
+           }
+       }
+    }
+}
 
 DEFUN ("call-interactively", Fcall_interactively, Scall_interactively, 1, 3, 0,
        doc: /* Call FUNCTION, reading args according to its interactive calling specs.
@@ -311,48 +379,11 @@ supply if the command inquires which events were used to invoke it.  */)
       if (i != num_input_events || !NILP (record_flag))
        {
          /* We should record this command on the command history.  */
-         Lisp_Object values, car;
+         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));
-         /* If the list of args was produced with an explicit call to `list',
-            look for elements that were computed with (region-beginning)
-            or (region-end), and put those expressions into VALUES
-            instead of the present values.  */
-         if (CONSP (input))
-           {
-             car = XCAR (input);
-             /* Skip through certain special forms.  */
-             while (EQ (car, Qlet) || EQ (car, Qletx)
-                    || EQ (car, Qsave_excursion)
-                    || EQ (car, Qprogn))
-               {
-                 while (CONSP (XCDR (input)))
-                   input = XCDR (input);
-                 input = XCAR (input);
-                 if (!CONSP (input))
-                   break;
-                 car = XCAR (input);
-               }
-             if (EQ (car, Qlist))
-               {
-                 Lisp_Object intail, valtail;
-                 for (intail = Fcdr (input), valtail = values;
-                      CONSP (valtail);
-                      intail = Fcdr (intail), valtail = Fcdr (valtail))
-                   {
-                     Lisp_Object elt;
-                     elt = Fcar (intail);
-                     if (CONSP (elt))
-                       {
-                         Lisp_Object presflag;
-                         presflag = Fmemq (Fcar (elt), preserved_fns);
-                         if (!NILP (presflag))
-                           Fsetcar (valtail, Fcar (intail));
-                       }
-                   }
-               }
-           }
+         fix_command (input, values);
          Vcommand_history
            = Fcons (Fcons (function, values), Vcommand_history);
 
@@ -409,7 +440,9 @@ supply if the command inquires which events were used to invoke it.  */)
        {
          Lisp_Object event;
 
-         event = XVECTOR (keys)->contents[next_event];
+         event = (next_event < key_count
+                  ? XVECTOR (keys)->contents[next_event]
+                  : Qnil);
          if (EVENT_HAS_PARAMETERS (event)
              && (event = XCDR (event), CONSP (event))
              && (event = XCAR (event), CONSP (event))
@@ -423,7 +456,7 @@ supply if the command inquires which events were used to invoke it.  */)
              if (!NILP (Vmouse_leave_buffer_hook))
                call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
 
-             Fselect_window (event);
+             Fselect_window (event, Qnil);
            }
          string++;
        }
@@ -741,7 +774,7 @@ supply if the command inquires which events were used to invoke it.  */)
              args[i] = Qnil;
              varies[i] = -1;
            }
-         else 
+         else
            {
              args[i]
                = Fread_non_nil_coding_system (build_string (callint_message));
@@ -818,7 +851,7 @@ supply if the command inquires which events were used to invoke it.  */)
     UNGCPRO;
     return unbind_to (speccount, val);
   }
-}  
+}
 
 DEFUN ("prefix-numeric-value", Fprefix_numeric_value, Sprefix_numeric_value,
        1, 1, 0,
@@ -829,7 +862,7 @@ Its numeric meaning is what you would get from `(interactive "p")'.  */)
      Lisp_Object raw;
 {
   Lisp_Object val;
-  
+
   if (NILP (raw))
     XSETFASTINT (val, 1);
   else if (EQ (raw, Qminus))
@@ -860,6 +893,10 @@ syms_of_callint ()
   staticpro (&Qlist);
   Qlet = intern ("let");
   staticpro (&Qlet);
+  Qif = intern ("if");
+  staticpro (&Qif);
+  Qwhen = intern ("when");
+  staticpro (&Qwhen);
   Qletx = intern ("let*");
   staticpro (&Qletx);
   Qsave_excursion = intern ("save-excursion");