]> code.delx.au - gnu-emacs/blobdiff - src/keyboard.c
* makefile.w32-in (obj): Remove sunfns.o.
[gnu-emacs] / src / keyboard.c
index 9068f9446646cc2c777c57ab641fc129403b05b9..23f2e6d53ff0a8f9fb52eb59f400ad395356a038 100644 (file)
@@ -160,14 +160,7 @@ int raw_keybuf_count;
 
 #define GROW_RAW_KEYBUF                                                        \
  if (raw_keybuf_count == XVECTOR (raw_keybuf)->size)                   \
-  {                                                                    \
-    int newsize = 2 * XVECTOR (raw_keybuf)->size;                      \
-    Lisp_Object new;                                                   \
-    new = Fmake_vector (make_number (newsize), Qnil);                  \
-    bcopy (XVECTOR (raw_keybuf)->contents, XVECTOR (new)->contents,    \
-          raw_keybuf_count * sizeof (Lisp_Object));                    \
-    raw_keybuf = new;                                                  \
-  }
+   raw_keybuf = larger_vector (raw_keybuf, raw_keybuf_count * 2, Qnil)  \
 
 /* Number of elements of this_command_keys
    that precede this key sequence.  */
@@ -1612,6 +1605,8 @@ command_loop_1 ()
   /* Do this after running Vpost_command_hook, for consistency.  */
   current_kboard->Vlast_command = Vthis_command;
   current_kboard->Vreal_last_command = real_this_command;
+  if (!CONSP (last_command_char))
+    current_kboard->Vlast_repeatable_command = real_this_command;
 
   while (1)
     {
@@ -1987,6 +1982,8 @@ command_loop_1 ()
        {
          current_kboard->Vlast_command = Vthis_command;
          current_kboard->Vreal_last_command = real_this_command;
+         if (!CONSP (last_command_char))
+           current_kboard->Vlast_repeatable_command = real_this_command;
          cancel_echoing ();
          this_command_key_count = 0;
          this_command_key_count_reset = 0;
@@ -4098,6 +4095,12 @@ kbd_buffer_get_event (kbp, used_mouse_menu, end_time)
   /* Wait until there is input available.  */
   for (;;)
     {
+      /* Break loop if there's an unread command event.  Needed in
+        moused window autoselection which uses a timer to insert such
+        events.  */
+      if (CONSP (Vunread_command_events))
+       break;
+      
       if (kbd_fetch_ptr != kbd_store_ptr)
        break;
 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
@@ -4713,12 +4716,14 @@ timer_check (do_it_now)
 }
 
 DEFUN ("current-idle-time", Fcurrent_idle_time, Scurrent_idle_time, 0, 0, 0,
-       doc: /* Return the current length of Emacs idleness.
-The value is returned as a list of three integers.  The first has the
+       doc: /* Return the current length of Emacs idleness, or nil.
+The value when Emacs is idle is a list of three integers.  The first has the
 most significant 16 bits of the seconds, while the second has the
 least significant 16 bits.  The third integer gives the microsecond
 count.
 
+The value when Emacs is not idle is nil.
+
 The microsecond count is zero on systems that do not provide
 resolution finer than a second.  */)
   ()
@@ -5704,8 +5709,8 @@ make_lispy_event (event)
            fuzz = double_click_fuzz / 8;
 
          is_double = (button == last_mouse_button
-                      && (abs (XINT (event->x) - last_mouse_x) <= fuzz)
-                      && (abs (XINT (event->y) - last_mouse_y) <= fuzz)
+                      && (eabs (XINT (event->x) - last_mouse_x) <= fuzz)
+                      && (eabs (XINT (event->y) - last_mouse_y) <= fuzz)
                       && button_down_time != 0
                       && (EQ (Vdouble_click_time, Qt)
                           || (INTEGERP (Vdouble_click_time)
@@ -5873,8 +5878,8 @@ make_lispy_event (event)
            fuzz = double_click_fuzz / 8;
 
          is_double = (last_mouse_button < 0
-                      && (abs (XINT (event->x) - last_mouse_x) <= fuzz)
-                      && (abs (XINT (event->y) - last_mouse_y) <= fuzz)
+                      && (eabs (XINT (event->x) - last_mouse_x) <= fuzz)
+                      && (eabs (XINT (event->y) - last_mouse_y) <= fuzz)
                       && button_down_time != 0
                       && (EQ (Vdouble_click_time, Qt)
                           || (INTEGERP (Vdouble_click_time)
@@ -7092,7 +7097,7 @@ tty_read_avail_input (struct terminal *terminal,
   int nread = 0;
 
   if (!terminal->name)         /* Don't read from a dead terminal. */
-    return;
+    return 0;
 
   if (terminal->type != output_termcap)
     abort ();
@@ -7588,13 +7593,7 @@ menu_bar_items (old)
   /* Add nil, nil, nil, nil at the end.  */
   i = menu_bar_items_index;
   if (i + 4 > XVECTOR (menu_bar_items_vector)->size)
-    {
-      Lisp_Object tem;
-      tem = Fmake_vector (make_number (2 * i), Qnil);
-      bcopy (XVECTOR (menu_bar_items_vector)->contents,
-            XVECTOR (tem)->contents, i * sizeof (Lisp_Object));
-      menu_bar_items_vector = tem;
-    }
+    menu_bar_items_vector = larger_vector (menu_bar_items_vector, 2 * i, Qnil);
   /* Add this item.  */
   XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
   XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
@@ -7666,14 +7665,7 @@ menu_bar_item (key, item, dummy1, dummy2)
     {
       /* If vector is too small, get a bigger one.  */
       if (i + 4 > XVECTOR (menu_bar_items_vector)->size)
-       {
-         Lisp_Object tem;
-         tem = Fmake_vector (make_number (2 * i), Qnil);
-         bcopy (XVECTOR (menu_bar_items_vector)->contents,
-                XVECTOR (tem)->contents, i * sizeof (Lisp_Object));
-         menu_bar_items_vector = tem;
-       }
-
+       menu_bar_items_vector = larger_vector (menu_bar_items_vector, 2 * i, Qnil);
       /* Add this item.  */
       XVECTOR (menu_bar_items_vector)->contents[i++] = key;
       XVECTOR (menu_bar_items_vector)->contents[i++]
@@ -8442,16 +8434,9 @@ append_tool_bar_item ()
   /* Enlarge tool_bar_items_vector if necessary.  */
   if (ntool_bar_items + TOOL_BAR_ITEM_NSLOTS
       >= XVECTOR (tool_bar_items_vector)->size)
-    {
-      Lisp_Object new_vector;
-      int old_size = XVECTOR (tool_bar_items_vector)->size;
-
-      new_vector = Fmake_vector (make_number (2 * old_size), Qnil);
-      bcopy (XVECTOR (tool_bar_items_vector)->contents,
-            XVECTOR (new_vector)->contents,
-            old_size * sizeof (Lisp_Object));
-      tool_bar_items_vector = new_vector;
-    }
+    tool_bar_items_vector
+      = larger_vector (tool_bar_items_vector,
+                      2 * XVECTOR (tool_bar_items_vector)->size, Qnil);
 
   /* Append entries from tool_bar_item_properties to the end of
      tool_bar_items_vector.  */
@@ -8555,7 +8540,7 @@ read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu)
             to indicate that they came from a mouse menu,
             so that when present in last_nonmenu_event
             they won't confuse things.  */
-         for (tem = XCDR (value); !NILP (tem); tem = XCDR (tem))
+         for (tem = XCDR (value); CONSP (tem); tem = XCDR (tem))
            {
              record_menu_key (XCAR (tem));
              if (SYMBOLP (XCAR (tem))
@@ -9202,13 +9187,16 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
   orig_keymap = get_local_map (PT, current_buffer, Qkeymap);
   from_string = Qnil;
 
-  /* We jump here when the key sequence has been thoroughly changed, and
-     we need to rescan it starting from the beginning.  When we jump here,
-     keybuf[0..mock_input] holds the sequence we should reread.  */
- replay_sequence:
-
-  /* We may switch keyboards between rescans, so we need to
-     reinitialize fkey and keytran before each replay.  */
+  /* The multi-tty merge moved the code below to right after
+   `replay_sequence' which caused all these translation maps to be applied
+   repeatedly, even tho their doc says very clearly they are not applied to
+   their own output.
+   The reason for this move was: "We may switch keyboards between rescans,
+   so we need to reinitialize fkey and keytran before each replay".
+   This move was wrong (even if we switch keyboards, keybuf still holds the
+   keys we've read already from the original keyboard and some of those keys
+   may have already been translated).  So there may still be a bug out there
+   lurking.  */
   indec.map = indec.parent = current_kboard->Vinput_decode_map;
   fkey.map = fkey.parent = current_kboard->Vlocal_function_key_map;
   keytran.map = keytran.parent = Vkey_translation_map;
@@ -9216,6 +9204,11 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
   fkey.start = fkey.end = 0;
   keytran.start = keytran.end = 0;
 
+  /* We jump here when the key sequence has been thoroughly changed, and
+     we need to rescan it starting from the beginning.  When we jump here,
+     keybuf[0..mock_input] holds the sequence we should reread.  */
+ replay_sequence:
+
   starting_buffer = current_buffer;
   first_unbound = bufsize + 1;
 
@@ -11483,6 +11476,7 @@ init_kboard (kb)
   kb->Vlast_command = Qnil;
   kb->Vreal_last_command = Qnil;
   kb->Vkeyboard_translate_table = Qnil;
+  kb->Vlast_repeatable_command = Qnil;
   kb->Vprefix_arg = Qnil;
   kb->Vlast_prefix_arg = Qnil;
   kb->kbd_queue = Qnil;
@@ -11497,6 +11491,7 @@ init_kboard (kb)
   kb->reference_count = 0;
   kb->Vsystem_key_alist = Qnil;
   kb->system_key_syms = Qnil;
+  kb->Vwindow_system = Qt;     /* Unset.  */
   kb->Vinput_decode_map = Fmake_sparse_keymap (Qnil);
   kb->Vlocal_function_key_map = Fmake_sparse_keymap (Qnil);
   Fset_keymap_parent (kb->Vlocal_function_key_map, Vfunction_key_map);
@@ -11577,8 +11572,12 @@ init_keyboard ()
 #ifdef MULTI_KBOARD
   current_kboard = initial_kboard;
 #endif
+  /* Re-initialize the keyboard again.  */
   wipe_kboard (current_kboard);
   init_kboard (current_kboard);
+  /* A value of nil for Vwindow_system normally means a tty, but we also use
+     it for the initial terminal since there is no window system there.  */
+  current_kboard->Vwindow_system = Qnil;
 
   if (!noninteractive)
     {
@@ -11990,6 +11989,11 @@ See Info node `(elisp)Multiple displays'.  */);
   DEFVAR_KBOARD ("real-last-command", Vreal_last_command,
                 doc: /* Same as `last-command', but never altered by Lisp code.  */);
 
+  DEFVAR_KBOARD ("last-repeatable-command", Vlast_repeatable_command,
+                doc: /* Last command that may be repeated.
+The last command executed that was not bound to an input event.
+This is the command `repeat' will try to repeat.  */);
+
   DEFVAR_LISP ("this-command", &Vthis_command,
               doc: /* The command now being executed.
 The command can set this variable; whatever is put here
@@ -12399,6 +12403,15 @@ and the Lisp function within which the error was signaled.  */);
 Help functions bind this to allow help on disabled menu items
 and tool-bar buttons.  */);
   Venable_disabled_menus_and_buttons = Qnil;
+
+#ifdef MULTI_KBOARD
+  /* Create the initial keyboard. */
+  initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
+  init_kboard (initial_kboard);
+  /* Vwindow_system is left at t for now.  */
+  initial_kboard->next_kboard = all_kboards;
+  all_kboards = initial_kboard;
+#endif  
 }
 
 void
@@ -12461,6 +12474,7 @@ mark_kboards ()
       mark_object (kb->Vlast_command);
       mark_object (kb->Vreal_last_command);
       mark_object (kb->Vkeyboard_translate_table);
+      mark_object (kb->Vlast_repeatable_command);
       mark_object (kb->Vprefix_arg);
       mark_object (kb->Vlast_prefix_arg);
       mark_object (kb->kbd_queue);
@@ -12468,6 +12482,7 @@ mark_kboards ()
       mark_object (kb->Vlast_kbd_macro);
       mark_object (kb->Vsystem_key_alist);
       mark_object (kb->system_key_syms);
+      mark_object (kb->Vwindow_system);
       mark_object (kb->Vinput_decode_map);
       mark_object (kb->Vlocal_function_key_map);
       mark_object (kb->Vdefault_minibuffer_frame);