]> code.delx.au - gnu-emacs/blobdiff - src/keyboard.c
*** empty log message ***
[gnu-emacs] / src / keyboard.c
index 680654baf545f68b4387212322b3a8880c081a0f..22ce74ed963265da874093d60472b7556d6657d5 100644 (file)
@@ -1,5 +1,5 @@
 /* Keyboard and mouse input; editor command loop.
-   Copyright (C) 1985, 1986, 1987, 1988, 1989 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1987, 1988, 1989, 1992 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -37,25 +37,16 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <setjmp.h>
 #include <errno.h>
 
-#include "emacssignal.h"
-
-extern int errno;
-
-/* Get FIONREAD, if it is available.  */
-#ifdef USG
-#include <termio.h>
-#include <fcntl.h>
-#else /* not USG */
 #ifndef VMS
 #include <sys/ioctl.h>
-#endif /* not VMS */
-#endif /* not USG */
-
-/* UNIPLUS systems may have FIONREAD.  */
-#ifdef UNIPLUS
-#include <sys.ioctl.h>
 #endif
 
+#include "syssignal.h"
+#include "systerm.h"
+#include "systime.h"
+
+extern int errno;
+
 #ifdef HAVE_X_WINDOWS
 extern Lisp_Object Vmouse_grabbed;
 
@@ -164,7 +155,7 @@ Lisp_Object meta_prefix_char;
 /* Last size recorded for a current buffer which is not a minibuffer.  */
 static int last_non_minibuf_size;
 
-/* Number of idle seconds before an auto-save.  */
+/* Number of idle seconds before an auto-save and garbage collection.  */
 static Lisp_Object Vauto_save_timeout;
 
 /* Total number of times read_char has returned.  */
@@ -321,8 +312,9 @@ Lisp_Object Qmode_line;
 Lisp_Object Qvertical_split;
 
 
-/* Address (if not 0) of word to zero out if a SIGIO interrupt happens.  */
-long *input_available_clear_word;
+/* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
+   happens.  */
+EMACS_TIME *input_available_clear_time;
 
 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
    Default is 1 if INTERRUPT_INPUT is defined.  */
@@ -334,22 +326,6 @@ int interrupts_deferred;
 /* nonzero means use ^S/^Q for flow control.  */
 int flow_control;
 
-#ifndef BSD4_1
-#define sigfree() sigsetmask (SIGEMPTYMASK)
-#define sigholdx(sig) sigsetmask (sigmask (sig))
-#define sigblockx(sig) sigblock (sigmask (sig))
-#define sigunblockx(sig) sigblock (SIGEMPTYMASK)
-#define sigpausex(sig) sigpause (0)
-#endif /* not BSD4_1 */
-
-#ifdef BSD4_1
-#define SIGIO SIGTINT
-/* sigfree and sigholdx are in sysdep.c */
-#define sigblockx(sig) sighold (sig)
-#define sigunblockx(sig) sigrelse (sig)
-#define sigpausex(sig) sigpause (sig)
-#endif /* BSD4_1 */
-
 /* Allow m- file to inhibit use of FIONREAD.  */
 #ifdef BROKEN_FIONREAD
 #undef FIONREAD
@@ -949,8 +925,6 @@ command_loop_1 ()
                       ||
                       (dp && (XTYPE (dp->contents[lose]) != Lisp_String
                               || XSTRING (dp->contents[lose])->size == sizeof (GLYPH))))
-                     && (SCREEN_CURSOR_X (selected_screen)
-                         != SCREEN_WIDTH (selected_screen) - 1)
                      && (XFASTINT (XWINDOW (selected_window)->last_modified)
                          >= MODIFF)
                      && (XFASTINT (XWINDOW (selected_window)->last_point)
@@ -972,7 +946,6 @@ command_loop_1 ()
                       ||
                       (dp && (XTYPE (dp->contents[lose]) != Lisp_String
                               || XSTRING (dp->contents[lose])->size == sizeof (GLYPH))))
-                     && (SCREEN_CURSOR_X (selected_screen) != 0)
                      && (XFASTINT (XWINDOW (selected_window)->last_modified)
                          >= MODIFF)
                      && (XFASTINT (XWINDOW (selected_window)->last_point)
@@ -1038,8 +1011,8 @@ command_loop_1 ()
            Fundo_boundary ();
          Fcommand_execute (cmd, Qnil);
 
-       directly_done: ;
        }
+    directly_done: ;
 
       /* If there is a prefix argument,
         1) We don't want last_command to be ``universal-argument''
@@ -1175,7 +1148,7 @@ read_char (commandflag)
     }
 
   /* Save outer setjmp data, in case called recursively.  */
-  bcopy (getcjmp, save_jump, sizeof getcjmp);
+  save_getcjmp (save_jump);
 
   stop_polling ();
 
@@ -1185,15 +1158,9 @@ read_char (commandflag)
   if (_setjmp (getcjmp))
     {
       XSET (c, Lisp_Int, quit_char);
-
-      /* Returning quit_char from this function represents a
-        resolution to the quit request, so clear the quit flag.
-        This prevents us from returning quit_char many times
-        for the same quit request.  */
-      Vquit_flag = Qnil;
-
-      waiting_for_input = 0;
-      input_available_clear_word = 0;
+#ifdef MULTI_SCREEN
+      XSET (Vlast_event_screen, Lisp_Screen, selected_screen);
+#endif
 
       goto non_reread;
     }
@@ -1213,7 +1180,7 @@ read_char (commandflag)
     {
       Lisp_Object tem0;
 
-      tem0 = Fsit_for (make_number (echo_keystrokes), Qnil, Qt);
+      tem0 = sit_for (echo_keystrokes, 0, 1, 1);
       if (EQ (tem0, Qt))
        echo ();
     }
@@ -1254,7 +1221,7 @@ read_char (commandflag)
       {
        Lisp_Object tem0;
        int delay = delay_level * XFASTINT (Vauto_save_timeout) / 4;
-       tem0 = Fsit_for (make_number (delay), Qnil, Qt);
+       tem0 = sit_for (delay, 0, 1, 1);
        if (EQ (tem0, Qt))
          {
            jmp_buf temp;
@@ -1294,7 +1261,7 @@ read_char (commandflag)
 
  non_reread:
 
-  bcopy (save_jump, getcjmp, sizeof getcjmp);
+  restore_getcjmp (save_jump);
 
   start_polling ();
 
@@ -1484,8 +1451,9 @@ tracking_off (old_value)
 
 DEFUN ("track-mouse", Ftrack_mouse, Strack_mouse, 0, UNEVALLED, 0,
   "Evaluate BODY with mouse movement and button release events enabled.\n\
-Within a track-mouse, read-event reports mouse movement and button releases;\n\
-otherwise, they are ignored.")
+Within a `track-mouse', mouse motion and button releases generate input\n\
+events that you can read with `read-event'.\n\
+Normally, these occurrences don't generate events.")
   (args)
      Lisp_Object args;
 {
@@ -1523,7 +1491,7 @@ kbd_buffer_store_event (event)
             will set Vlast_event_screen again, so this is safe to do.  */
          extern SIGTYPE interrupt_signal ();
          XSET (Vlast_event_screen, Lisp_Screen, event->screen);
-         last_event_timestamp = XINT (event->timestamp);
+         last_event_timestamp = event->timestamp;
          interrupt_signal ();
          return;
        }
@@ -1621,24 +1589,10 @@ kbd_buffer_get_event ()
 #endif /* SIGIO */
       if (EVENT_QUEUES_EMPTY)
        {
-#ifdef subprocesses
-         wait_reading_process_input (0, 0, -1, 1);
-#else
-/* Note SIGIO has been undef'd if FIONREAD is missing.  */
-#ifdef SIGIO
-         if (interrupt_input)
-           {
-             sigblockx (SIGIO);
-             set_waiting_for_input (0);
-             while (EVENT_QUEUES_EMPTY)
-               sigpausex (SIGIO);
-             clear_waiting_for_input ();
-             sigunblockx (SIGIO);
-           }
-#else
-         interrupt_input = 0;
-#endif /* not SIGIO */
-#endif /* subprocesses */
+         Lisp_Object minus_one;
+
+         XSET (minus_one, Lisp_Int, -1);
+         wait_reading_process_input (0, 0, minus_one, 1);
 
          if (!interrupt_input && EVENT_QUEUES_EMPTY)
            {
@@ -2153,7 +2107,8 @@ gobble_input (expected)
 #ifdef SIGIO
   if (interrupt_input)
     {
-      SIGMASKTYPE mask = sigblockx (SIGIO);
+      SIGMASKTYPE mask;
+      mask = sigblockx (SIGIO);
       read_avail_input (expected);
       sigsetmask (mask);
     }
@@ -2285,8 +2240,8 @@ input_available_signal (signo)
   sigisheld (SIGIO);
 #endif
 
-  if (input_available_clear_word)
-    *input_available_clear_word = 0;
+  if (input_available_clear_time)
+    EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0);
 
   while (1)
     {
@@ -2734,10 +2689,10 @@ read_key_sequence (keybuf, bufsize, prompt)
            {
              fkey_next =
                get_keyelt (access_keymap (fkey_map, keybuf[fkey_end++]));
-
              /* If keybuf[fkey_start..fkey_next] is bound in the
-                function key map and it's a suffix, replace it with
-                the binding and restart.  */
+                function key map and it's a suffix of the current
+                sequence (i.e. fkey_next == t), replace it with
+                the binding and restart with fkey_start at the end. */
              if (XTYPE (fkey_next) == Lisp_Vector
                  && fkey_end == t)
                {
@@ -2761,9 +2716,8 @@ read_key_sequence (keybuf, bufsize, prompt)
              
              fkey_map = get_keymap_1 (fkey_next, 0);
 
-             /* If we no longer have a bound suffix, advance 
-                the start of the function key suffix and continue
-                scanning from there.  */
+             /* If we no longer have a bound suffix, try a new positions for 
+                fkey_start.  */
              if (NILP (fkey_map))
                {
                  fkey_end = ++fkey_start;
@@ -2842,13 +2796,7 @@ Otherwise, that is done only if an arg is read using the minibuffer.")
 
   while (1)
     {
-      final = cmd;
-      while (XTYPE (final) == Lisp_Symbol)
-       {
-         if (EQ (Qunbound, XSYMBOL (final)->function))
-           Fsymbol_function (final);    /* Get an error! */
-         final = XSYMBOL (final)->function;
-       }
+      final = Findirect_function (cmd);
 
       if (CONSP (final) && (tem = Fcar (final), EQ (tem, Qautoload)))
        do_autoload (final, cmd);
@@ -3061,6 +3009,14 @@ detect_input_pending ()
   return input_pending;
 }
 
+/* This is called in some cases before a possible quit.
+   It cases the next call to detect_input_pending to recompute input_pending.
+   So calling this function unnecessarily can't do any harm.  */
+clear_input_pending ()
+{
+  input_pending = 0;
+}
+
 DEFUN ("input-pending-p", Finput_pending_p, Sinput_pending_p, 0, 0, 0,
   "T if command input is currently available with no waiting.\n\
 Actually, the value is nil only if we can be sure that no input is available.")
@@ -3243,10 +3199,10 @@ stuff_buffered_input (stuffstring)
 #endif /* BSD and not BSD4_1 */
 }
 \f
-set_waiting_for_input (word_to_clear)
-     long *word_to_clear;
+set_waiting_for_input (time_to_clear)
+     EMACS_TIME *time_to_clear;
 {
-  input_available_clear_word = word_to_clear;
+  input_available_clear_time = time_to_clear;
 
   /* Tell interrupt_signal to throw back to read_char,  */
   waiting_for_input = 1;
@@ -3268,7 +3224,7 @@ clear_waiting_for_input ()
 {
   /* Tell interrupt_signal not to throw back to read_char,  */
   waiting_for_input = 0;
-  input_available_clear_word = 0;
+  input_available_clear_time = 0;
 }
 
 /* This routine is called at interrupt level in response to C-G.
@@ -3376,7 +3332,7 @@ quit_throw_to_read_char ()
   quit_error_check ();
   sigfree ();
   /* Prevent another signal from doing this before we finish.  */
-  waiting_for_input = 0;
+  clear_waiting_for_input ();
   input_pending = 0;
 
 #if 0
@@ -3613,7 +3569,9 @@ Zero means disable autosaving due to number of characters typed.");
 
   DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout,
     "*Number of seconds idle time before auto-save.\n\
-Zero or nil means disable auto-saving due to idleness.");
+Zero or nil means disable auto-saving due to idleness.\n\
+After auto-saving due to this many seconds of idle time,\n\
+Emacs also does a garbage collection if that seems to be warranted."
   XFASTINT (Vauto_save_timeout) = 30;
 
   DEFVAR_INT ("echo-keystrokes", &echo_keystrokes,