]> code.delx.au - gnu-emacs/blobdiff - src/keyboard.c
*** empty log message ***
[gnu-emacs] / src / keyboard.c
index 105131eedb8a24c082b34934ba468dd405ebdfbd..927e986b2684438e6c9a0df90639a28604bb6aba 100644 (file)
@@ -1,5 +1,5 @@
 /* Keyboard and mouse input; editor command loop.
-   Copyright (C) 1985,86,87,88,89,93,94,95,96,97,99, 2000
+   Copyright (C) 1985,86,87,88,89,93,94,95,96,97,99, 2000, 2001
      Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -202,7 +202,7 @@ int waiting_for_input;
 
 /* True while displaying for echoing.   Delays C-g throwing.  */
 
-static int echoing;
+int echoing;
 
 /* Non-null means we can start echoing at the next input pause even
    though there is something in the echo area.  */
@@ -219,7 +219,7 @@ static struct kboard *echo_kboard;
 /* The buffer used for echoing.  Set in echo_now, reset in
    cancel_echoing.  */
 
-static Lisp_Object echo_message_buffer;
+Lisp_Object echo_message_buffer;
 
 /* Nonzero means disregard local maps for the menu bar.  */
 static int inhibit_local_menu_bar_menus;
@@ -644,6 +644,10 @@ Lisp_Object Vdisable_point_adjustment;
 
 Lisp_Object Vglobal_disable_point_adjustment;
 
+/* The time when Emacs started being idle.  */
+
+static EMACS_TIME timer_idleness_start_time;
+
 \f
 /* Global variable declarations.  */
 
@@ -920,13 +924,25 @@ recursive_edit_1 ()
     }
 
 #ifdef HAVE_X_WINDOWS
-  /* The command loop has started a busy-cursor timer, so we have to
+  /* The command loop has started an hourglass timer, so we have to
      cancel it here, otherwise it will fire because the recursive edit
      can take some time.  */
-  if (display_busy_cursor_p)
-    cancel_busy_cursor ();
+  if (display_hourglass_p)
+    cancel_hourglass ();
 #endif
 
+  /* This function may have been called from a debugger called from
+     within redisplay, for instance by Edebugging a function called
+     from fontification-functions.  We want to allow redisplay in
+     the debugging session.
+
+     The recursive edit is left with a `(throw exit ...)'.  The `exit'
+     tag is not caught anywhere in redisplay, i.e. when we leave the
+     recursive edit, the original redisplay leading to the recursive
+     edit will be unwound.  The outcome should therefore be safe.  */
+  specbind (Qinhibit_redisplay, Qnil);
+  redisplaying_p = 0;
+
   val = command_loop ();
   if (EQ (val, Qt))
     Fsignal (Qquit, Qnil);
@@ -969,18 +985,6 @@ This function is called by the editor initialization to begin editing.")
   command_loop_level++;
   update_mode_lines = 1;
 
-  /* This function may have been called from a debugger called from
-     within redisplay, for instance by Edebugging a function called
-     from fontification-functions.  We want to allow redisplay in
-     the debugging session.
-
-     The recursive edit is left with a `(throw exit ...)'.  The `exit'
-     tag is not caught anywhere in redisplay, i.e. when we leave the
-     recursive edit, the original redisplay leading to the recursive
-     edit will be unwound.  The outcome should therefore be safe.  */
-  specbind (Qinhibit_redisplay, Qnil);
-  redisplaying_p = 0;
-
   record_unwind_protect (recursive_edit_unwind,
                         (command_loop_level
                          && current_buffer != XBUFFER (XWINDOW (selected_window)->buffer))
@@ -1249,8 +1253,8 @@ DEFUN ("top-level", Ftop_level, Stop_level, 0, 0, "",
   ()
 {
 #ifdef HAVE_X_WINDOWS
-  if (display_busy_cursor_p)
-    cancel_busy_cursor ();
+  if (display_hourglass_p)
+    cancel_hourglass ();
 #endif
   return Fthrow (Qtop_level, Qnil);
 }
@@ -1280,10 +1284,11 @@ DEFUN ("abort-recursive-edit", Fabort_recursive_edit, Sabort_recursive_edit, 0,
 /* This is the actual command reading loop,
    sans error-handling encapsulation.  */
 
-Lisp_Object Fcommand_execute ();
-static int read_key_sequence ();
-void safe_run_hooks ();
-static void adjust_point_for_property ();
+EXFUN (Fcommand_execute, 4);
+static int read_key_sequence P_ ((Lisp_Object *, int, Lisp_Object,
+                                 int, int, int));
+void safe_run_hooks P_ ((Lisp_Object));
+static void adjust_point_for_property P_ ((int));
 
 Lisp_Object
 command_loop_1 ()
@@ -1478,6 +1483,10 @@ command_loop_1 ()
          this variable differently.  */
       Vdisable_point_adjustment = Qnil;
 
+      /* Process filters and timers may have messed with deactivate-mark.
+        reset it before we execute the command. */
+      Vdeactivate_mark = Qnil;
+
       /* Execute the command.  */
 
       Vthis_command = cmd;
@@ -1606,8 +1615,8 @@ command_loop_1 ()
          /* Here for a command that isn't executed directly */
 
 #ifdef HAVE_X_WINDOWS
-         if (display_busy_cursor_p)
-           start_busy_cursor ();
+         if (display_hourglass_p)
+           start_hourglass ();
 #endif
 
          nonundocount = 0;
@@ -1616,8 +1625,8 @@ command_loop_1 ()
          Fcommand_execute (Vthis_command, Qnil, Qnil, Qnil);
 
 #ifdef HAVE_X_WINDOWS
-         if (display_busy_cursor_p)
-           cancel_busy_cursor ();
+         if (display_hourglass_p)
+           cancel_hourglass ();
 #endif
        }
     directly_done: ;
@@ -2090,6 +2099,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
   volatile Lisp_Object also_record;
   volatile int reread;
   struct gcpro gcpro1, gcpro2;
+  EMACS_TIME last_idle_start;
 
   also_record = Qnil;
 
@@ -2141,6 +2151,12 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
          && NILP (XCDR (c)))
        c = XCAR (c);
 
+      /* If the queued event is something that used the mouse,
+         set used_mouse_menu accordingly.  */
+      if (used_mouse_menu
+         && (EQ (c, Qtool_bar) || EQ (c, Qmenu_bar)))
+       *used_mouse_menu = 1;
+      
       reread = 1;
       goto reread_for_input_method;
     }
@@ -2221,7 +2237,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
       while (!input_pending)
        {
          if (help_echo_showing_p && !EQ (selected_window, minibuf_window))
-           redisplay_preserve_echo_area ();
+           redisplay_preserve_echo_area (5);
          else
            redisplay ();
 
@@ -2577,6 +2593,9 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
 
  non_reread:
 
+  /* Record the last idle start time so that we can reset it
+     should the next event read be a help-echo.  */
+  last_idle_start = timer_idleness_start_time;
   timer_stop_idle ();
   start_polling ();
 
@@ -2793,6 +2812,9 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
       object = Fnth (make_number (4), c);
       position = Fnth (make_number (5), c);
       show_help_echo (help, window, object, position, 0);
+
+      /* We stopped being idle for this event; undo that.  */
+      timer_idleness_start_time = last_idle_start;
       goto retry;
     }
   
@@ -3039,7 +3061,7 @@ tracking_off (old_value)
         redisplay.  */
       if (!readable_events (1))
        {
-         redisplay_preserve_echo_area ();
+         redisplay_preserve_echo_area (6);
          get_input_pending (&input_pending, 1);
        }
     }
@@ -3810,11 +3832,9 @@ swallow_events (do_display)
   get_input_pending (&input_pending, 1);
 
   if (timers_run != old_timers_run && do_display)
-    redisplay_preserve_echo_area ();
+    redisplay_preserve_echo_area (7);
 }
 \f
-static EMACS_TIME timer_idleness_start_time;
-
 /* Record the start of when Emacs is idle,
    for the sake of running idle-time timers.  */
 
@@ -4010,17 +4030,18 @@ timer_check (do_it_now)
          if (NILP (vector[0]))
            {
              int was_locked = single_kboard;
-             int count = specpdl_ptr - specpdl;
+             int count = BINDING_STACK_SIZE ();
+             Lisp_Object old_deactivate_mark = Vdeactivate_mark;
 
              /* Mark the timer as triggered to prevent problems if the lisp
                 code fails to reschedule it right.  */
              vector[0] = Qt;
 
              specbind (Qinhibit_quit, Qt);
-
+             
              call1 (Qtimer_event_handler, chosen_timer);
+             Vdeactivate_mark = old_deactivate_mark;
              timers_run++;
-
              unbind_to (count, Qnil);
 
              /* Resume allowing input from any kboard, if that was true before.  */
@@ -4705,14 +4726,14 @@ make_lispy_event (event)
                for (i = 0; i < XVECTOR (items)->size; i += 4)
                  {
                    Lisp_Object pos, string;
-                   string = XVECTOR (items)->contents[i + 1];
-                   pos = XVECTOR (items)->contents[i + 3];
+                   string = AREF (items, i + 1);
+                   pos = AREF (items, i + 3);
                    if (NILP (string))
                      break;
                    if (column >= XINT (pos)
                        && column < XINT (pos) + XSTRING (string)->size)
                      {
-                       item = XVECTOR (items)->contents[i];
+                       item = AREF (items, i);
                        break;
                      }
                  }
@@ -4771,7 +4792,16 @@ make_lispy_event (event)
                else if (part == 2)
                  posn = Qvertical_line;
                else
-                 XSETINT (posn, buffer_posn_from_coords (w, &wx, &wy));
+                 {
+                   Lisp_Object object;
+                   struct display_pos p;
+                   buffer_posn_from_coords (w, &wx, &wy, &object, &p);
+                   posn = make_number (CHARPOS (p.pos));
+                   if (STRINGP (object))
+                     string_info
+                       = Fcons (object,
+                                make_number (CHARPOS (p.string_pos)));
+                 }
              }
 
            position
@@ -4804,15 +4834,14 @@ make_lispy_event (event)
          }
 #endif /* not USE_TOOLKIT_SCROLL_BARS */
 
-       if (button >= XVECTOR (button_down_location)->size)
+       if (button >= ASIZE (button_down_location))
          {
            button_down_location = larger_vector (button_down_location,
                                                  button + 1, Qnil);
            mouse_syms = larger_vector (mouse_syms, button + 1, Qnil);
          }
        
-       start_pos_ptr = &XVECTOR (button_down_location)->contents[button];
-
+       start_pos_ptr = &AREF (button_down_location, button);
        start_pos = *start_pos_ptr;
        *start_pos_ptr = Qnil;
 
@@ -4849,12 +4878,11 @@ make_lispy_event (event)
            see if this was a click or a drag.  */
        else if (event->modifiers & up_modifier)
          {
-           /* If we did not see a down before this up,
-              ignore the up.  Probably this happened because
-              the down event chose a menu item.
-              It would be an annoyance to treat the release
-              of the button that chose the menu item
-              as a separate event.  */
+           /* If we did not see a down before this up, ignore the up.
+              Probably this happened because the down event chose a
+              menu item.  It would be an annoyance to treat the
+              release of the button that chose the menu item as a
+              separate event.  */
 
            if (!CONSP (start_pos))
              return Qnil;
@@ -4871,16 +4899,29 @@ make_lispy_event (event)
                Lisp_Object down;
 
                down = Fnth (make_number (2), start_pos);
-               if (EQ (event->x, XCAR (down))
-                   && EQ (event->y, XCDR (down)))
-                 {
-                   event->modifiers |= click_modifier;
-                 }
+               if (EQ (event->x, XCAR (down)) && EQ (event->y, XCDR (down)))
+                 /* Mouse hasn't moved.  */
+                 event->modifiers |= click_modifier;
                else
                  {
-                   button_down_time = 0;
-                   event->modifiers |= drag_modifier;
+                   Lisp_Object window1, window2, posn1, posn2;
+
+                   /* Avoid generating a drag event if the mouse
+                      hasn't actually moved off the buffer position.  */
+                   window1 = Fnth (make_number (0), position);
+                   posn1 = Fnth (make_number (1), position);
+                   window2 = Fnth (make_number (0), start_pos);
+                   posn2 = Fnth (make_number (1), start_pos);
+
+                   if (EQ (window1, window2) && EQ (posn1, posn2))
+                     event->modifiers |= click_modifier;
+                   else
+                     {
+                       button_down_time = 0;
+                       event->modifiers |= drag_modifier;
+                     }
                  }
+               
                /* Don't check is_double; treat this as multiple
                   if the down-event was multiple.  */
                if (double_click_count > 1)
@@ -5054,9 +5095,13 @@ make_lispy_event (event)
            else if (part == 3)
              posn = Qheader_line;
            else
-             XSETINT (posn,
-                      buffer_posn_from_coords (XWINDOW (window),
-                                               &column, &row));
+             {
+               Lisp_Object object;
+               struct display_pos p;
+               buffer_posn_from_coords (XWINDOW (window), &column, &row,
+                                        &object, &p);
+               posn = make_number (CHARPOS (p.pos));
+             }
          }
 
        {
@@ -5133,7 +5178,12 @@ make_lispy_event (event)
            else if (part == 3)
              posn = Qheader_line;
            else
-             XSETINT (posn, buffer_posn_from_coords (w, &wx, &wy));
+             {
+               Lisp_Object object;
+               struct display_pos p;
+               buffer_posn_from_coords (w, &wx, &wy, &object, &p);
+               posn = make_number (CHARPOS (p.pos));
+             }
          }
 
        {
@@ -5245,7 +5295,12 @@ make_lispy_movement (frame, bar_window, part, x, y, time)
          else if (area == 3)
            posn = Qheader_line;
          else
-           XSETINT (posn, buffer_posn_from_coords (w, &wx, &wy));
+           {
+             Lisp_Object object;
+             struct display_pos p;
+             buffer_posn_from_coords (w, &wx, &wy, &object, &p);
+             posn = make_number (CHARPOS (p.pos));
+           }
        }
       else if (frame != 0)
        {
@@ -6303,7 +6358,7 @@ menu_bar_items (old)
       {
        /* No, so use major and minor mode keymaps and keymap property.  */
        int extra_maps = 2;
-       Lisp_Object map = get_local_map (PT, current_buffer, keymap);
+       Lisp_Object map = get_local_map (PT, current_buffer, Qkeymap);
        if (!NILP (map))
          extra_maps = 3;
        nmaps = current_minor_maps (NULL, &tmaps);
@@ -6312,7 +6367,7 @@ menu_bar_items (old)
        bcopy (tmaps, maps, nmaps * sizeof (maps[0]));
        if (!NILP (map))
          maps[nmaps++] = map;
-       maps[nmaps++] = get_local_map (PT, current_buffer, local_map);
+       maps[nmaps++] = get_local_map (PT, current_buffer, Qlocal_map);
       }
     maps[nmaps++] = current_global_map;
   }
@@ -6955,7 +7010,7 @@ tool_bar_items (reuse, nitems)
     {
       /* No, so use major and minor mode keymaps and keymap property.  */
       int extra_maps = 2;
-      Lisp_Object map = get_local_map (PT, current_buffer, keymap);
+      Lisp_Object map = get_local_map (PT, current_buffer, Qkeymap);
       if (!NILP (map))
        extra_maps = 3;
       nmaps = current_minor_maps (NULL, &tmaps);
@@ -6964,7 +7019,7 @@ tool_bar_items (reuse, nitems)
       bcopy (tmaps, maps, nmaps * sizeof (maps[0]));
       if (!NILP (map))
        maps[nmaps++] = map;
-      maps[nmaps++] = get_local_map (PT, current_buffer, local_map);
+      maps[nmaps++] = get_local_map (PT, current_buffer, Qlocal_map);
     }
 
   /* Add global keymap at the end.  */
@@ -7733,6 +7788,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
      int can_return_switch_frame;
      int fix_current_buffer;
 {
+  volatile Lisp_Object from_string;
   volatile int count = specpdl_ptr - specpdl;
 
   /* How many keys there are in the current key sequence.  */
@@ -7824,6 +7880,9 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
   volatile int function_key_possible = 0;
   volatile int key_translation_possible = 0;
 
+  /* List of events for which a fake prefix key has been generated.  */
+  volatile Lisp_Object fake_prefixed_keys = Qnil;
+
   /* Save the status of key translation before each step,
      so that we can restore this after downcasing.  */
   Lisp_Object prev_fkey_map;
@@ -7838,6 +7897,9 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
   int junk;
 #endif
 
+  struct gcpro gcpro1;
+
+  GCPRO1 (fake_prefixed_keys);
   raw_keybuf_count = 0;
 
   last_nonmenu_event = Qnil;
@@ -7884,8 +7946,9 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
                           &junk);
 #endif /* GOBBLE_FIRST_EVENT */
 
-  orig_local_map = get_local_map (PT, current_buffer, local_map);
-  orig_keymap = get_local_map (PT, current_buffer, keymap);
+  orig_local_map = get_local_map (PT, current_buffer, Qlocal_map);
+  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,
@@ -8054,8 +8117,8 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
                               interrupted_kboard->kbd_queue);
                  }
                mock_input = 0;
-               orig_local_map = get_local_map (PT, current_buffer, local_map);
-               orig_keymap = get_local_map (PT, current_buffer, keymap);
+               orig_local_map = get_local_map (PT, current_buffer, Qlocal_map);
+               orig_keymap = get_local_map (PT, current_buffer, Qkeymap);
                goto replay_sequence;
              }
 #endif
@@ -8069,6 +8132,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
          if (EQ (key, Qt))
            {
              unbind_to (count, Qnil);
+             UNGCPRO;
              return -1;
            }
 
@@ -8101,8 +8165,8 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
                    Fset_buffer (XWINDOW (selected_window)->buffer);
                }
 
-             orig_local_map = get_local_map (PT, current_buffer, local_map);
-             orig_keymap = get_local_map (PT, current_buffer, keymap);
+             orig_local_map = get_local_map (PT, current_buffer, Qlocal_map);
+             orig_keymap = get_local_map (PT, current_buffer, Qkeymap);
              goto replay_sequence;
            }
 
@@ -8116,8 +8180,8 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
              keybuf[t++] = key;
              mock_input = t;
              Vquit_flag = Qnil;
-             orig_local_map = get_local_map (PT, current_buffer, local_map);
-             orig_keymap = get_local_map (PT, current_buffer, keymap);
+             orig_local_map = get_local_map (PT, current_buffer, Qlocal_map);
+             orig_keymap = get_local_map (PT, current_buffer, Qkeymap);
              goto replay_sequence;
            }
 
@@ -8166,10 +8230,12 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
              window = POSN_WINDOW      (EVENT_START (key));
              posn   = POSN_BUFFER_POSN (EVENT_START (key));
 
-             if (CONSP (posn))
+             if (CONSP (posn)
+                 || (!NILP (fake_prefixed_keys)
+                     && !NILP (Fmemq (key, fake_prefixed_keys))))
                {
-                 /* We're looking at the second event of a
-                    sequence which we expanded before.  Set
+                 /* We're looking a second time at an event for which
+                    we generated a fake prefix key.  Set
                     last_real_key_start appropriately.  */
                  if (t > 0)
                    last_real_key_start = t - 1;
@@ -8202,12 +8268,10 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
 
                  if (! FRAME_LIVE_P (XFRAME (selected_frame)))
                    Fkill_emacs (Qnil);
-                 set_buffer_internal (XBUFFER (XWINDOW
-                 (window)->buffer)
-);
+                 set_buffer_internal (XBUFFER (XWINDOW (window)->buffer));
                  orig_local_map = get_local_map (PT, current_buffer,
-                                                 local_map);
-                 orig_keymap = get_local_map (PT, current_buffer, keymap);
+                                                 Qlocal_map);
+                 orig_keymap = get_local_map (PT, current_buffer, Qkeymap);
                  goto replay_sequence;
                }
              
@@ -8229,7 +8293,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
                          && XINT (pos) >= BEG && XINT (pos) <= Z)
                        {
                          map_here = get_local_map (XINT (pos),
-                                                   current_buffer, local_map);
+                                                   current_buffer, Qlocal_map);
                          if (!EQ (map_here, orig_local_map))
                            {
                              orig_local_map = map_here;
@@ -8239,7 +8303,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
                              goto replay_sequence;
                            }
                          map_here = get_local_map (XINT (pos),
-                                                    current_buffer, keymap);
+                                                    current_buffer, Qkeymap);
                          if (!EQ (map_here, orig_keymap))
                            {
                              orig_keymap = map_here;
@@ -8254,18 +8318,22 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
 
              /* Expand mode-line and scroll-bar events into two events:
                 use posn as a fake prefix key.  */
-             if (SYMBOLP (posn))
+             if (SYMBOLP (posn)
+                 && (NILP (fake_prefixed_keys)
+                     || NILP (Fmemq (key, fake_prefixed_keys))))
                {
                  if (t + 1 >= bufsize)
                    error ("Key sequence too long");
-                 keybuf[t] = posn;
-                 keybuf[t+1] = key;
-                 mock_input = t + 2;
                  
-                 /* Zap the position in key, so we know that we've
-                    expanded it, and don't try to do so again.  */
-                 POSN_BUFFER_POSN (EVENT_START (key))
-                   = Fcons (posn, Qnil);
+                 keybuf[t]     = posn;
+                 keybuf[t + 1] = key;
+                 mock_input    = t + 2;
+
+                 /* Record that a fake prefix key has been generated
+                    for KEY.  Don't modify the event; this would
+                    prevent proper action when the event is pushed
+                    back tino unread-command-events.  */
+                 fake_prefixed_keys = Fcons (key, fake_prefixed_keys);
 
                  /* If on a mode line string with a local keymap,
                     reconsider the key sequence with that keymap.  */
@@ -8292,6 +8360,35 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
 
                  goto replay_key;
                }
+             else if (CONSP (POSN_STRING (EVENT_START (key)))
+                      && NILP (from_string))
+               {
+                 /* For a click on a string, i.e. overlay string or a
+                    string displayed via the `display' property,
+                    consider `local-map' and `keymap' properties of
+                    that string.  */
+                 Lisp_Object string, pos, map, map2;
+
+                 string = POSN_STRING (EVENT_START (key));
+                 pos = XCDR (string);
+                 string = XCAR (string);
+                 if (XINT (pos) >= 0
+                     && XINT (pos) < XSTRING (string)->size)
+                   {
+                     map = Fget_text_property (pos, Qlocal_map, string);
+                     if (!NILP (map))
+                       orig_local_map = map;
+                     map2 = Fget_text_property (pos, Qkeymap, string);
+                     if (!NILP (map2))
+                       orig_keymap = map2;
+
+                     if (!NILP (map) || !NILP (map2))
+                       {
+                         from_string = string;
+                         goto replay_sequence;
+                       }
+                   }
+               }
            }
          else if (CONSP (XCDR (key))
                   && CONSP (EVENT_START (key))
@@ -8805,6 +8902,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
 
   
 
+  UNGCPRO;
   return t;
 }
 
@@ -8892,8 +8990,8 @@ DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 5, 0,
     }
 
 #ifdef HAVE_X_WINDOWS
-  if (display_busy_cursor_p)
-    cancel_busy_cursor ();
+  if (display_hourglass_p)
+    cancel_hourglass ();
 #endif
 
   i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])),
@@ -8904,8 +9002,8 @@ DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 5, 0,
          then proceeding with a lenghty compuation, but it's not good
          for code reading keys in a loop, like an input method.  */
 #ifdef HAVE_X_WINDOWS
-  if (display_busy_cursor_p)
-    start_busy_cursor ();
+  if (display_hourglass_p)
+    start_hourglass ();
 #endif
 #endif
 
@@ -8921,8 +9019,8 @@ DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 5, 0,
 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector,
        Sread_key_sequence_vector, 1, 5, 0,
   "Like `read-key-sequence' but always return a vector.")
-     /* Don't break the following line for documentation's sake.  */
-  (prompt, continue_echo, dont_downcase_last, can_return_switch_frame, command_loop)
+  (prompt, continue_echo, dont_downcase_last, can_return_switch_frame,
+   command_loop)
      Lisp_Object prompt, continue_echo, dont_downcase_last;
      Lisp_Object can_return_switch_frame, command_loop;
 {
@@ -8951,8 +9049,8 @@ DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector,
     }
 
 #ifdef HAVE_X_WINDOWS
-  if (display_busy_cursor_p)
-    cancel_busy_cursor ();
+  if (display_hourglass_p)
+    cancel_hourglass ();
 #endif
 
   i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])),
@@ -8960,8 +9058,8 @@ DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector,
                         ! NILP (can_return_switch_frame), 0);
 
 #ifdef HAVE_X_WINDOWS
-  if (display_busy_cursor_p)
-    start_busy_cursor ();
+  if (display_hourglass_p)
+    start_hourglass ();
 #endif
 
   if (i == -1)
@@ -9249,7 +9347,7 @@ current_active_maps (maps_p)
     {
       /* No, so use major and minor mode keymaps and keymap property.  */
       int extra_maps = 2;
-      Lisp_Object map = get_local_map (PT, current_buffer, keymap);
+      Lisp_Object map = get_local_map (PT, current_buffer, Qkeymap);
       if (!NILP (map))
        extra_maps = 3;
       nmaps = current_minor_maps (NULL, &tmaps);
@@ -9258,7 +9356,7 @@ current_active_maps (maps_p)
       bcopy (tmaps, maps, nmaps * sizeof (maps[0]));
       if (!NILP (map))
        maps[nmaps++] = map;
-      maps[nmaps++] = get_local_map (PT, current_buffer, local_map);
+      maps[nmaps++] = get_local_map (PT, current_buffer, Qlocal_map);
     }
   maps[nmaps++] = current_global_map;
 
@@ -9290,7 +9388,7 @@ detect_input_pending_run_timers (do_display)
 
   if (old_timers_run != timers_run && do_display)
     {
-      redisplay_preserve_echo_area ();
+      redisplay_preserve_echo_area (8);
       /* The following fixes a bug when using lazy-lock with
         lazy-lock-defer-on-the-fly set to t, i.e.  when fontifying
         from an idle timer function.  The symptom of the bug is that
@@ -9797,7 +9895,7 @@ quit_throw_to_read_char ()
   if (FRAMEP (internal_last_event_frame)
       && !EQ (internal_last_event_frame, selected_frame))
     do_switch_frame (make_lispy_switch_frame (internal_last_event_frame),
-                    Qnil, 0);
+                    0, 0);
 
   _longjmp (getcjmp, 1);
 }
@@ -9942,19 +10040,35 @@ wipe_kboard (kb)
 }
 
 #ifdef MULTI_KBOARD
+
+/* Free KB and memory referenced from it.  */
+
 void
 delete_kboard (kb)
-  KBOARD *kb;
+     KBOARD *kb;
 {
   KBOARD **kbp;
+  
   for (kbp = &all_kboards; *kbp != kb; kbp = &(*kbp)->next_kboard)
     if (*kbp == NULL)
       abort ();
   *kbp = kb->next_kboard;
+
+  /* Prevent a dangling reference to KB.  */
+  if (kb == current_kboard
+      && FRAMEP (selected_frame)
+      && FRAME_LIVE_P (XFRAME (selected_frame)))
+    {
+      current_kboard = XFRAME (selected_frame)->kboard;
+      if (current_kboard == kb)
+       abort ();
+    }
+  
   wipe_kboard (kb);
   xfree (kb);
 }
-#endif
+
+#endif /* MULTI_KBOARD */
 
 void
 init_keyboard ()
@@ -10551,7 +10665,7 @@ The elements of the list are event types that may have menu bar bindings.");
     "Per-terminal keymap that overrides all other local keymaps.\n\
 If this variable is non-nil, it is used as a keymap instead of the\n\
 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
-This variable is intended to let commands such as `universal-argumemnt'\n\
+This variable is intended to let commands such as `universal-argument'\n\
 set up a different keymap for reading the next command.");
 
   DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map,