changeset 1591:765cb54fa9af

* lread.c: #include "keyboard.h". (Fread_char, Fread_char_exclusive): Don't signal an error for or throw away switch-frame events; instead, put them off until after we've found a character we can respond to. Rename unread_command_char to unread_command_event; it has subtly different semantics now, and we should use `make-obsolete-variable' to warn people. * lread.c (Fread_char): Change reference.
author Jim Blandy <jimb@redhat.com>
date Mon, 16 Nov 1992 00:45:02 +0000
parents 11cd7c23f538
children 613783a3f00c
files src/lread.c
diffstat 1 files changed, 66 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/lread.c	Mon Nov 16 00:44:13 1992 +0000
+++ b/src/lread.c	Mon Nov 16 00:45:02 1992 +0000
@@ -32,6 +32,7 @@
 #include "buffer.h"
 #include "paths.h"
 #include "commands.h"
+#include "keyboard.h"
 #endif
 
 #ifdef lint
@@ -164,20 +165,48 @@
   "Read a character from the command input (keyboard or macro).\n\
 It is returned as a number.\n\
 If the user generates an event which is not a character (i.e. a mouse\n\
-click or function key event), `read-char' signals an error.  If you\n\
-want to read non-character events, or ignore them, call `read-event'\n\
-or `read-char-exclusive' instead.")
+click or function key event), `read-char' signals an error.  As an\n\
+exception, switch-frame events are put off until non-ASCII events can\n\
+be read.\n\
+If you want to read non-character events, or ignore them, call\n\
+`read-event' or `read-char-exclusive' instead.")
   ()
 {
   register Lisp_Object val;
 
 #ifndef standalone
-  val = read_char (0, 0, 0, Qnil, 0);
-  if (XTYPE (val) != Lisp_Int)
-    {
-      unread_command_char = val;
-      error ("Object read was not a character");
-    }
+  {
+    register Lisp_Object delayed_switch_frame;
+
+    delayed_switch_frame = Qnil;
+
+    for (;;)
+      {
+	val = read_char (0, 0, 0, Qnil, 0);
+      
+	/* switch-frame events are put off until after the next ASCII
+	   character.  This is better than signalling an error just
+	   because the last characters were typed to a separate
+	   minibuffer frame, for example.  Eventually, some code which
+	   can deal with switch-frame events will read it and process
+	   it.  */
+	if (EVENT_HAS_PARAMETERS (val)
+	    && EQ (EVENT_HEAD (val), Qswitch_frame))
+	  delayed_switch_frame = val;
+	else
+	  break;
+      }
+      
+    if (! NILP (delayed_switch_frame))
+      unread_switch_frame = delayed_switch_frame;
+
+    /* Only ASCII characters are acceptable.  */
+    if (XTYPE (val) != Lisp_Int)
+      {
+	unread_command_event = val;
+	error ("Object read was not a character");
+      }
+  }
 #else
   val = getchar ();
 #endif
@@ -203,11 +232,34 @@
   register Lisp_Object val;
 
 #ifndef standalone
-  do
-    {
-      val = read_char (0, 0, 0, Qnil, 0);
-    }
-  while (XTYPE (val) != Lisp_Int);
+  {
+    Lisp_Object delayed_switch_frame;
+
+    delayed_switch_frame = Qnil;
+
+    for (;;)
+      {
+	val = read_char (0, 0, 0, Qnil, 0);
+
+	if (XTYPE (val) == Lisp_Int)
+	  break;
+
+	/* switch-frame events are put off until after the next ASCII
+	   character.  This is better than signalling an error just
+	   because the last characters were typed to a separate
+	   minibuffer frame, for example.  Eventually, some code which
+	   can deal with switch-frame events will read it and process
+	   it.  */
+	else if (EVENT_HAS_PARAMETERS (val)
+	    && EQ (EVENT_HEAD (val), Qswitch_frame))
+	  delayed_switch_frame = val;
+
+	/* Drop everything else.  */
+      }
+
+    if (! NILP (delayed_switch_frame))
+      unread_switch_frame = delayed_switch_frame;
+  }
 #else
   val = getchar ();
 #endif