]> code.delx.au - gnu-emacs/blobdiff - src/keyboard.c
(follow_key): When downcasing, downcase just the
[gnu-emacs] / src / keyboard.c
index 6f950839533238a583a6b827fa3bb37fb1d68949..e7e58365491b083a831a64bf8fdae6934c80427a 100644 (file)
@@ -3027,7 +3027,10 @@ read_avail_input (expected)
     nread = (*read_socket_hook) (0, buf, KBD_BUFFER_SIZE, expected, expected);
   else
     {
-      unsigned char cbuf[KBD_BUFFER_SIZE];
+      /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
+        the kbd_buffer can really hold.  That may prevent loss
+        of characters on some systems when input is stuffed at us.  */
+      unsigned char cbuf[KBD_BUFFER_SIZE - 1];
 
 #ifdef FIONREAD
       /* Find out how much input is available.  */
@@ -3044,7 +3047,7 @@ read_avail_input (expected)
       if (nread > sizeof cbuf)
        nread = sizeof cbuf;
 #else /* no FIONREAD */
-#ifdef USG
+#if defined(USG) || defined(DGUX)
       /* Read some input if available, but don't wait.  */
       nread = sizeof cbuf;
       fcntl (fileno (stdin), F_SETFL, O_NDELAY);
@@ -3056,23 +3059,26 @@ read_avail_input (expected)
       /* Now read; for one reason or another, this will not block.  */
       while (1)
        {
-         nread = read (fileno (stdin), cbuf, nread);
+         int value = read (fileno (stdin), cbuf, nread);
 #ifdef AIX
          /* The kernel sometimes fails to deliver SIGHUP for ptys.
             This looks incorrect, but it isn't, because _BSD causes
             O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
             and that causes a value other than 0 when there is no input.  */
-         if (nread == 0)
+         if (value == 0)
            kill (SIGHUP, 0);
 #endif
          /* Retry the read if it is interrupted.  */
-         if (nread >= 0
+         if (value >= 0
              || ! (errno == EAGAIN || errno == EFAULT
 #ifdef EBADSLT
                    || errno == EBADSLT
 #endif
                    ))
-           break;
+           {
+             nread = value;
+             break;
+           }
        }
 
 #ifndef FIONREAD
@@ -3653,7 +3659,8 @@ follow_key (key, nmaps, current, defs, next)
       if (XINT (key) & shift_modifier)
        XSETINT (key, XINT (key) & ~shift_modifier);
       else
-       XSETINT (key, DOWNCASE (XINT (key)));
+       XSETINT (key, (DOWNCASE (XINT (key) & 0x3ffff)
+                      | (XINT (key) & ~0x3ffff)));
 
       first_binding = nmaps;
       for (i = nmaps - 1; i >= 0; i--)
@@ -3784,6 +3791,8 @@ read_key_sequence (keybuf, bufsize, prompt)
   Lisp_Object first_event;
 #endif
 
+  struct buffer *starting_buffer;
+
   int junk;
 
   last_nonmenu_event = Qnil;
@@ -3832,6 +3841,8 @@ read_key_sequence (keybuf, bufsize, prompt)
      keybuf[0..mock_input] holds the sequence we should reread.  */
  replay_sequence:
 
+  starting_buffer = current_buffer;
+
   /* Build our list of keymaps.
      If we recognize a function key and replace its escape sequence in
      keybuf with its symbol, or if the sequence starts with a mouse
@@ -3861,9 +3872,7 @@ read_key_sequence (keybuf, bufsize, prompt)
     if (! NILP (submaps[first_binding]))
       break;
 
-  /* We jump here when a function key substitution has forced us to
-     reprocess the current key sequence.  keybuf[0..mock_input] is the
-     sequence we want to reread.  */
+  /* Start from the beginning in keybuf.  */
   t = 0;
 
   /* These are no-ops the first time through, but if we restart, they
@@ -3952,6 +3961,17 @@ read_key_sequence (keybuf, bufsize, prompt)
              goto done;
            }
          
+         /* If we have a quit that was typed in another frame, and
+            quit_throw_to_read_char switched buffers,
+            replay to get the right keymap.  */
+         if (EQ (key, quit_char) && current_buffer != starting_buffer)
+           {
+             keybuf[t++] = key;
+             mock_input = t;
+             Vquit_flag = Qnil;
+             goto replay_sequence;
+           }
+           
          Vquit_flag = Qnil;
        }
 
@@ -4444,7 +4464,7 @@ and `quit-flag' is not set.\n\
 If the key sequence starts with a mouse click, then the sequence is read\n\
 using the keymaps of the buffer of the window clicked in, not the buffer\n\
 of the selected window as normal.\n\
-\n\
+""\n\
 `read-key-sequence' drops unbound button-down events, since you normally\n\
 only care about the click or drag events which follow them.  If a drag\n\
 or multi-click event is unbound, but the corresponding click event would\n\
@@ -4988,6 +5008,8 @@ quit_throw_to_read_char ()
   if (poll_suppress_count == 0)
     abort ();
 #endif
+  if (XFRAME (internal_last_event_frame) != selected_frame)
+    Fhandle_switch_frame (make_lispy_switch_frame (internal_last_event_frame));
 
   _longjmp (getcjmp, 1);
 }