changeset 1439:b3b2d1181d3a

* keyboard.c (this_command_keys): Make this a vector, instead of an array of Lisp_Objects. (this_command_keys_size): Deleted. (echo, add_command_key, Fthis_command_keys): Adjusted appropriately. (init_keyboard): Don't allocate it here. (syms_of_keyboard): Allocate it here, and staticpro it. * keyboard.c (read_char): Call ourselves with the appropriate number of arguments. (read_char_menu_prompt): If USED_MOUSE_MENU is zero, don't try to store things in it. * keyboard.c (modify_event_symbol): Arrange to set the click_modifier bit on otherwise unmodified mouse clicks. * keyboard.c (kbd_buffer_get_event): Remember that *mouse_position_hook may set *FRAME to 0; don't generate switch-frame events in this case. Fix fencepost bug in fetching events from keyboard buffer.
author Jim Blandy <jimb@redhat.com>
date Mon, 19 Oct 1992 18:38:58 +0000
parents 57f20a185901
children 8c27b145955a
files src/keyboard.c
diffstat 1 files changed, 38 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/keyboard.c	Mon Oct 19 18:36:13 1992 +0000
+++ b/src/keyboard.c	Mon Oct 19 18:38:58 1992 +0000
@@ -78,10 +78,13 @@
 int total_keys;		/* Total number of elements stored into recent_keys */
 Lisp_Object recent_keys; /* A vector, holding the last 100 keystrokes */
 
-/* Buffer holding the key that invoked the current command.  */
-Lisp_Object *this_command_keys;
-int this_command_key_count;	/* Size in use.  */
-int this_command_keys_size;	/* Size allocated.  */
+/* Vector holding the key sequence that invoked the current command.
+   It is reused for each command, and it may be longer than the current
+   sequence; this_command_key_count indicates how many elements
+   actually mean something.
+   It's easier to staticpro a single Lisp_Object than an array.  */
+Lisp_Object this_command_keys;
+int this_command_key_count;
 
 extern int minbuf_level;
 
@@ -472,7 +475,7 @@
       immediate_echo = 1;
 
       for (i = 0; i < this_command_key_count; i++)
-	echo_char (this_command_keys[i]);
+	echo_char (XVECTOR (this_command_keys)->contents[i]);
       echo_dash ();
     }
 
@@ -518,15 +521,20 @@
 add_command_key (key)
      Lisp_Object key;
 {
-  if (this_command_key_count == this_command_keys_size)
+  int size = XVECTOR (this_command_keys)->size;
+
+  if (this_command_key_count >= size)
     {
-      this_command_keys_size *= 2;
-      this_command_keys
-	= (Lisp_Object *) xrealloc (this_command_keys,
-				    (this_command_keys_size
-				     * sizeof (Lisp_Object)));
+      Lisp_Object new_keys = Fmake_vector (make_number (size * 2), Qnil);
+
+      bcopy (XVECTOR (this_command_keys)->contents,
+	     XVECTOR (new_keys)->contents,
+	     size);
+
+      this_command_keys = new_keys;
     }
-  this_command_keys[this_command_key_count++] = key;
+
+  XVECTOR (this_command_keys)->contents[this_command_key_count++] = key;
 }
 
 Lisp_Object
@@ -1095,8 +1103,9 @@
    PREV_EVENT is the previous input event, or nil if we are reading
    the first event of a key sequence.
 
-   If we use a mouse menu to read the input, we store 1 into *USED_MOUSE_MENU.
-   Otherwise we store 0 there.  */
+   If USED_MOUSE_MENU is non-zero, then we set *USED_MOUSE_MENU to 1
+   if we used a mouse menu to read the input, or zero otherwise.  If
+   USED_MOUSE_MENU is zero, *USED_MOUSE_MENU is left alone.  */
 
 Lisp_Object
 read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
@@ -1359,7 +1368,7 @@
 	internal_with_output_to_temp_buffer ("*Help*", print_help, tem0);
 
       cancel_echoing ();
-      c = read_char (0);
+      c = read_char (0, 0, 0, Qnil, 0);
       /* Remove the help from the frame */
       unbind_to (count, Qnil);
       redisplay ();
@@ -2032,8 +2041,7 @@
   if (! (modifiers & (down_modifier | drag_modifier))
       && i + 7 == name->size
       && strncmp (name->data + i, "mouse-", 6)
-      && '0' <= name->data[i + 6]
-      && name->data[i + 6] <= '9')
+      && ('0' <= name->data[i + 6] && name->data[i + 6] <= '9'))
     modifiers |= click_modifier;
 
   if (modifier_end)
@@ -2297,7 +2305,7 @@
       /* Fill in the cache entries for this symbol; this also 	
 	 builds the Qevent_symbol_elements property, which the user
 	 cares about.  */
-      apply_modifiers (0, *slot);
+      apply_modifiers (modifiers & click_modifier, *slot);
       Fput (*slot, Qevent_kind, symbol_kind);
     }
 
@@ -2539,8 +2547,9 @@
    PREV_EVENT is the previous input event, or nil if we are reading
    the first event of a key sequence.
 
-   If we use a mouse menu to read the input, we store 1 into *USED_MOUSE_MENU.
-   Otherwise we store 0 there.
+   If USED_MOUSE_MENU is non-zero, then we set *USED_MOUSE_MENU to 1
+   if we used a mouse menu to read the input, or zero otherwise.  If
+   USED_MOUSE_MENU is zero, *USED_MOUSE_MENU is left alone.
 
    The prompting is done based on the prompt-string of the map
    and the strings associated with various map elements.  */
@@ -2560,7 +2569,8 @@
   int idx = -1;
   Lisp_Object rest, vector;
 
-  *used_mouse_menu = 0;
+  if (used_mouse_menu)
+    *used_mouse_menu = 0;
 
   /* Use local over global Menu maps */
 
@@ -2599,7 +2609,8 @@
       value = Fx_popup_menu (prev_event, Flist (nmaps1, realmaps));
       if (NILP (value))
 	XSET (value, Lisp_Int, quit_char);
-      *used_mouse_menu = 1;
+      if (used_mouse_menu)
+	*used_mouse_menu = 1;
       return value;
     }
 #endif /* not NO_X_MENU */
@@ -3447,7 +3458,8 @@
   "Return string of the keystrokes that invoked this command.")
   ()
 {
-  return make_array (this_command_key_count, this_command_keys);
+  return make_array (this_command_key_count,
+		     XVECTOR (this_command_keys)->contents);
 }
 
 DEFUN ("recursion-depth", Frecursion_depth, Srecursion_depth, 0, 0, 0,
@@ -3776,10 +3788,6 @@
 
 init_keyboard ()
 {
-  this_command_keys_size = 40;
-  this_command_keys =
-    (Lisp_Object *) xmalloc (this_command_keys_size * sizeof (Lisp_Object));
-
   /* This is correct before outermost invocation of the editor loop */
   command_loop_level = -1;
   immediate_quit = 0;
@@ -3922,6 +3930,9 @@
   recent_keys = Fmake_vector (make_number (NUM_RECENT_KEYS), Qnil);
   staticpro (&recent_keys);
 
+  this_command_keys = Fmake_vector (make_number (40), Qnil);
+  staticpro (&recent_keys);
+
   func_key_syms = Qnil;
   staticpro (&func_key_syms);