Put stdio.h, sys/types.h and sys/stat.h after config.h.
[bpt/emacs.git] / src / callint.c
index 53cad4a..1a79cb0 100644 (file)
@@ -1,11 +1,11 @@
 /* Call a Lisp function interactively.
-   Copyright (C) 1985, 1986, 1992 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1993, 1994 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
-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,
@@ -18,7 +18,7 @@ along with GNU Emacs; see the file COPYING.  If not, write to
 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 
-#include "config.h"
+#include <config.h>
 #include "lisp.h"
 #include "buffer.h"
 #include "commands.h"
@@ -35,6 +35,10 @@ Lisp_Object Vcommand_history;
 Lisp_Object Vcommand_debug_status, Qcommand_debug_status;
 Lisp_Object Qenable_recursive_minibuffers;
 
+/* Non-nil means treat the mark as active
+   even if mark_active is 0.  */
+Lisp_Object Vmark_even_if_inactive;
+
 Lisp_Object Qlist;
 Lisp_Object preserved_fns;
 
@@ -69,9 +73,9 @@ c -- Character.\n\
 C -- Command name: symbol with interactive function definition.\n\
 d -- Value of point as number.  Does not do I/O.\n\
 D -- Directory name.\n\
-e -- Event that invoked this command (value of `last-nonmenu-event').\n\
-     This skips events without parameters.\n\
-     If used more than once, the Nth 'e' returns the Nth parameterized event.\n\
+e -- Parametrized event (i.e., one that's a list) that invoked this command.\n\
+     If used more than once, the Nth `e' returns the Nth parameterized event.\n\
+     This skips events that are integers or symbols.\n\
 f -- Existing file name.\n\
 F -- Possibly nonexistent file name.\n\
 k -- Key sequence (string).\n\
@@ -89,10 +93,11 @@ X -- Lisp expression read and evaluated.\n\
 In addition, if the string begins with `*'\n\
  then an error is signaled if the buffer is read-only.\n\
  This happens before reading any arguments.\n\
-If the string begins with `@', then the window the mouse is over is selected\n\
- before anything else is done.  You may use both `@' and `*';\n\
-they are processed in the order that they appear."
-*/
+If the string begins with `@', then Emacs searches the key sequence\n\
+ which invoked the command for its first mouse click (or any other\n\
+ event which specifies a window), and selects that window before\n\
+ reading any arguments.  You may use both `@' and `*'; they are\n\
+ processed in the order that they appear." */
 
 /* ARGSUSED */
 DEFUN ("interactive", Finteractive, Sinteractive, 0, UNEVALLED, 0,
@@ -137,9 +142,13 @@ char *callint_argfuns[]
 static void
 check_mark ()
 {
-  Lisp_Object tem = Fmarker_buffer (current_buffer->mark);
+  Lisp_Object tem;
+  tem = Fmarker_buffer (current_buffer->mark);
   if (NILP (tem) || (XBUFFER (tem) != current_buffer))
     error ("The mark is not set now");
+  if (!NILP (Vtransient_mark_mode) && NILP (Vmark_even_if_inactive)
+      && NILP (current_buffer->mark_active))
+    Fsignal (Qmark_inactive, Qnil);
 }
 
 
@@ -167,7 +176,7 @@ Otherwise, this is done only if an arg is read using the minibuffer.")
 
   /* The index of the next element of this_command_keys to examine for
      the 'e' interactive code.  */
-  int next_event = 0;
+  int next_event;
 
   Lisp_Object prefix_arg;
   unsigned char *string;
@@ -209,7 +218,7 @@ Otherwise, this is done only if an arg is read using the minibuffer.")
       if (!string)
        {
        lose:
-         function = wrong_type_argument (Qcommandp, function, 0);
+         function = wrong_type_argument (Qcommandp, function);
          goto retry;
        }
       if ((int) string == 1)
@@ -296,6 +305,12 @@ Otherwise, this is done only if an arg is read using the minibuffer.")
 
   /* Here if function specifies a string to control parsing the defaults */
 
+  /* Set next_event to point to the first event with parameters.  */
+  for (next_event = 0; next_event < this_command_key_count; next_event++)
+    if (EVENT_HAS_PARAMETERS
+       (XVECTOR (this_command_keys)->contents[next_event]))
+      break;
+  
   /* Handle special starting chars `*' and `@'.  */
   while (1)
     {
@@ -307,9 +322,21 @@ Otherwise, this is done only if an arg is read using the minibuffer.")
        }
       else if (*string == '@')
        {
+         Lisp_Object event;
+
+         event = XVECTOR (this_command_keys)->contents[next_event];
+         if (EVENT_HAS_PARAMETERS (event)
+             && XTYPE (event = XCONS (event)->cdr) == Lisp_Cons
+             && XTYPE (event = XCONS (event)->car) == Lisp_Cons
+             && XTYPE (event = XCONS (event)->car) == Lisp_Window)
+           {
+             if (MINI_WINDOW_P (XWINDOW (event))
+                 && NILP (call1 (intern ("minibuffer-window-active-p"),
+                                 event)))
+               error ("Attempt to select inactive minibuffer window");
+             Fselect_window (event);
+           }
          string++;
-         if (!NILP (Vmouse_window))
-           Fselect_window (Vmouse_window);
        }
       else break;
     }
@@ -433,11 +460,6 @@ Otherwise, this is done only if an arg is read using the minibuffer.")
          break;
 
        case 'e':               /* The invoking event.  */
-         /* Find the next parameterized event.  */
-         while (next_event < this_command_key_count
-                && ! (EVENT_HAS_PARAMETERS
-                      (XVECTOR (this_command_keys)->contents[next_event])))
-           next_event++;
          if (next_event >= this_command_key_count)
            error ("%s must be bound to an event with parameters",
                   (XTYPE (function) == Lisp_Symbol
@@ -445,6 +467,13 @@ Otherwise, this is done only if an arg is read using the minibuffer.")
                    : "command"));
          args[i] = XVECTOR (this_command_keys)->contents[next_event++];
          varies[i] = -1;
+
+         /* Find the next parameterized event.  */
+         while (next_event < this_command_key_count
+                && ! (EVENT_HAS_PARAMETERS
+                      (XVECTOR (this_command_keys)->contents[next_event])))
+           next_event++;
+
          break;
 
        case 'm':               /* Value of mark.  Does not do I/O.  */
@@ -640,6 +669,14 @@ Bound each time `call-interactively' is called;\n\
 may be set by the debugger as a reminder for itself.");
   Vcommand_debug_status = Qnil;
 
+  DEFVAR_LISP ("mark-even-if-inactive", &Vmark_even_if_inactive,
+    "*Non-nil means you can use the mark even when inactive.\n\
+This option makes a difference in Transient Mark mode.\n\
+When the option is non-nil, deactivation of the mark\n\
+turns off region highlighting, but commands that use the mark\n\
+behave as if the mark were still active.");
+  Vmark_even_if_inactive = Qnil;
+
   defsubr (&Sinteractive);
   defsubr (&Scall_interactively);
   defsubr (&Sprefix_numeric_value);