]> code.delx.au - gnu-emacs/blobdiff - src/keyboard.c
Fix a typo in the last entry for dispnew.c
[gnu-emacs] / src / keyboard.c
index b086ae57ca629c066e04adcf3b11f5aa1d8a3e83..62ca678924469a1c5876ee5ece39c63b1fa806df 100644 (file)
@@ -251,6 +251,10 @@ Lisp_Object Vmenu_bar_final_items;
    If the value is non-nil and not a number, we wait 2 seconds.  */
 Lisp_Object Vsuggest_key_bindings;
 
+/* How long to display an echo-area message when the minibuffer is active.
+   If the value is not a number, such messages don't time out.  */
+Lisp_Object Vminibuffer_message_timeout;
+
 /* Character that causes a quit.  Normally C-g.
 
    If we are running on an ordinary terminal, this must be an ordinary
@@ -519,7 +523,7 @@ static struct input_event * volatile kbd_store_ptr;
 /* If this flag is non-nil, we check mouse_moved to see when the
    mouse moves, and motion events will appear in the input stream.
    Otherwise, mouse motion is ignored.  */
-static Lisp_Object do_mouse_tracking;
+Lisp_Object do_mouse_tracking;
 
 /* Symbols to head events.  */
 Lisp_Object Qmouse_movement;
@@ -686,17 +690,39 @@ static int cannot_suspend;
 
 void
 echo_prompt (str)
-     char *str;
+     Lisp_Object str;
 {
-  int len = strlen (str);
+  int nbytes = STRING_BYTES (XSTRING (str));
+  int multibyte_p = STRING_MULTIBYTE (str);
 
-  if (len > ECHOBUFSIZE - 4)
-    len = ECHOBUFSIZE - 4;
-  bcopy (str, current_kboard->echobuf, len);
-  current_kboard->echoptr = current_kboard->echobuf + len;
-  *current_kboard->echoptr = '\0';
+  if (nbytes > ECHOBUFSIZE - 4)
+    {
+      if (multibyte_p)
+       {
+         /* Have to find the last character that fit's into the 
+            echo buffer.  */
+         unsigned char *p = XSTRING (str)->data;
+         unsigned char *pend = p + ECHOBUFSIZE - 4;
+         int char_len;
+
+         do 
+           {
+             PARSE_MULTIBYTE_SEQ (p, pend - p, char_len);
+             p += char_len;
+           }
+         while (p < pend);
+
+         nbytes = p - XSTRING (str)->data - char_len;
+       }
+      else
+       nbytes = ECHOBUFSIZE - 4;
+    }
 
-  current_kboard->echo_after_prompt = len;
+  nbytes = copy_text (XSTRING (str)->data, current_kboard->echobuf, nbytes,
+                     STRING_MULTIBYTE (str), 1);
+  current_kboard->echoptr = current_kboard->echobuf + nbytes;
+  *current_kboard->echoptr = '\0';
+  current_kboard->echo_after_prompt = nbytes;
 
   echo_now ();
 }
@@ -709,8 +735,6 @@ void
 echo_char (c)
      Lisp_Object c;
 {
-  extern char *push_key_description ();
-
   if (current_kboard->immediate_echo)
     {
       char *ptr = current_kboard->echoptr;
@@ -723,11 +747,13 @@ echo_char (c)
 
       if (INTEGERP (c))
        {
+         int ch = XINT (c);
+
          if (ptr - current_kboard->echobuf
              > ECHOBUFSIZE - KEY_DESCRIPTION_SIZE)
            return;
 
-         ptr = push_key_description (XINT (c), ptr);
+         ptr = push_key_description (ch, ptr, 1);
        }
       else if (SYMBOLP (c))
        {
@@ -735,8 +761,8 @@ echo_char (c)
          if ((ptr - current_kboard->echobuf) + STRING_BYTES (name) + 4
              > ECHOBUFSIZE)
            return;
-         bcopy (name->data, ptr, STRING_BYTES (name));
-         ptr += STRING_BYTES (name);
+         ptr += copy_text (name->data, ptr, STRING_BYTES (name),
+                           name->size_byte >= 0, 1);
        }
 
       if (current_kboard->echoptr == current_kboard->echobuf
@@ -802,7 +828,7 @@ echo_now ()
 
   echoing = 1;
   message2_nolog (current_kboard->echobuf, strlen (current_kboard->echobuf),
-                 ! NILP (current_buffer->enable_multibyte_characters));
+                 1);
   echoing = 0;
 
   /* Record in what buffer we echoed, and from which kboard.  */
@@ -1333,18 +1359,19 @@ command_loop_1 ()
       Vdeactivate_mark = Qnil;
 
       /* If minibuffer on and echo area in use,
-        wait 2 sec and redraw minibuffer.  */
+        wait a short time and redraw minibuffer.  */
 
       if (minibuf_level
          && !NILP (echo_area_buffer[0])
-         && EQ (minibuf_window, echo_area_window))
+         && EQ (minibuf_window, echo_area_window)
+         && NUMBERP (Vminibuffer_message_timeout))
        {
          /* Bind inhibit-quit to t so that C-g gets read in
             rather than quitting back to the minibuffer.  */
          int count = specpdl_ptr - specpdl;
          specbind (Qinhibit_quit, Qt);
 
-         Fsit_for (make_number (2), Qnil, Qnil);
+         Fsit_for (Vminibuffer_message_timeout, Qnil, Qnil);
          /* Clear the echo area.  */
          message2 (0, 0, 0);
          safe_run_hooks (Qecho_area_clear_hook);
@@ -2001,7 +2028,7 @@ show_help_echo (help, window, object, pos, ok_to_overwrite_keystroke_echo)
            {
              int count = specpdl_ptr - specpdl;
              specbind (Qmessage_truncate_lines, Qt);
-             message3_nolog (help, XSTRING (help)->size,
+             message3_nolog (help, STRING_BYTES (XSTRING (help)),
                              STRING_MULTIBYTE (help));
              unbind_to (count, Qnil);
            }
@@ -2886,11 +2913,44 @@ static void
 record_char (c)
      Lisp_Object c;
 {
-  total_keys++;
-  XVECTOR (recent_keys)->contents[recent_keys_index] = c;
-  if (++recent_keys_index >= NUM_RECENT_KEYS)
-    recent_keys_index = 0;
+  /* Don't record `help-echo' in recent_keys unless it shows some help
+     message, and a different help than the previoiusly recorded
+     event.  */
+  if (CONSP (c) && EQ (XCAR (c), Qhelp_echo))
+    {
+      Lisp_Object help;
 
+      help = Fnth (make_number (2), c);
+      if (STRINGP (help))
+       {
+         int last_idx;
+         Lisp_Object last_c, last_help;
+         
+         last_idx = recent_keys_index - 1;
+         if (last_idx < 0)
+           last_idx = NUM_RECENT_KEYS - 1;
+         last_c = AREF (recent_keys, last_idx);
+         
+         if (!CONSP (last_c)
+             || !EQ (XCAR (last_c), Qhelp_echo)
+             || (last_help = Fnth (make_number (2), last_c),
+                 !EQ (last_help, help)))
+           {
+             total_keys++;
+             ASET (recent_keys, recent_keys_index, c);
+             if (++recent_keys_index >= NUM_RECENT_KEYS)
+               recent_keys_index = 0;
+           }
+       }
+    }
+  else
+    {
+      total_keys++;
+      ASET (recent_keys, recent_keys_index, c);
+      if (++recent_keys_index >= NUM_RECENT_KEYS)
+       recent_keys_index = 0;
+    }
+      
   /* Write c to the dribble file.  If c is a lispy event, write
      the event's symbol to the dribble file, in <brackets>.  Bleaugh.
      If you, dear reader, have a better idea, you've got the source.  :-) */
@@ -2923,7 +2983,8 @@ record_char (c)
       fflush (dribble);
     }
 
-  store_kbd_macro_char (c);
+  if (!CONSP (c) || !EQ (Qhelp_echo, XCAR (c)))
+    store_kbd_macro_char (c);
 
   num_nonmacro_input_events++;
 }
@@ -3609,8 +3670,6 @@ kbd_buffer_get_event (kbp, used_mouse_menu)
 
          if (NILP (obj))
            {
-             int idx;
-             
              obj = make_lispy_event (event);
              
 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
@@ -4699,7 +4758,7 @@ make_lispy_event (event)
 
                if (part == 1 || part == 3)
                  {
-                   /* Mode line or top line.  Look for a string under
+                   /* Mode line or header line.  Look for a string under
                       the mouse that may have a `local-map' property.  */
                    Lisp_Object string;
                    int charpos;
@@ -4970,7 +5029,8 @@ make_lispy_event (event)
          return Qnil;
        pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y),
                               &column, &row, NULL, 1);
-       window = window_from_coordinates (f, column, row, &part, 0);
+       window = window_from_coordinates (f, XINT (event->x),
+                                          XINT (event->y), &part, 0);
 
        if (!WINDOWP (window))
          {
@@ -5028,7 +5088,6 @@ make_lispy_event (event)
        Lisp_Object window;
        Lisp_Object posn;
        Lisp_Object files;
-       int row, column;
 
        /* The frame_or_window field should be a cons of the frame in
           which the event occurred and a list of the filenames
@@ -5043,9 +5102,9 @@ make_lispy_event (event)
           have been deleted.  */
        if (! FRAME_LIVE_P (f))
          return Qnil;
-       pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y),
-                              &column, &row, NULL, 1);
-       window = window_from_coordinates (f, column, row, &part, 0);
+
+       window = window_from_coordinates (f, XINT (event->x),
+                                          XINT (event->y), &part, 0);
 
        if (!WINDOWP (window))
          {
@@ -5819,6 +5878,12 @@ lucid_event_type_list_p (object)
   if (! CONSP (object))
     return 0;
 
+  if (EQ (XCAR (object), Qhelp_echo)
+      || EQ (XCAR (object), Qvertical_line)
+      || EQ (XCAR (object), Qmode_line)
+      || EQ (XCAR (object), Qheader_line))
+    return 0;
+
   for (tail = object; CONSP (tail); tail = XCDR (tail))
     {
       Lisp_Object elt;
@@ -6187,7 +6252,7 @@ menu_bar_items (old)
      in the current keymaps, or nil where it is not a prefix.  */
   Lisp_Object *maps;
 
-  Lisp_Object def, tem, tail;
+  Lisp_Object def, tail;
 
   Lisp_Object result;
 
@@ -6238,7 +6303,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);
@@ -6247,7 +6312,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;
   }
@@ -6259,8 +6324,8 @@ menu_bar_items (old)
   for (mapno = nmaps - 1; mapno >= 0; mapno--)
     if (!NILP (maps[mapno]))
       {
-       def = get_keymap (access_keymap (maps[mapno], Qmenu_bar, 1, 0, 0),
-                         0, 0);
+       def = get_keymap (access_keymap (maps[mapno], Qmenu_bar, 1, 0, 1),
+                         0, 1);
        if (CONSP (def))
          menu_bar_one_keymap (def);
       }
@@ -6890,7 +6955,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);
@@ -6899,7 +6964,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.  */
@@ -6912,8 +6977,7 @@ tool_bar_items (reuse, nitems)
       {
        Lisp_Object keymap;
 
-       /* Why set the `noinherit' flag ?  -sm  */
-       keymap = get_keymap (access_keymap (maps[i], Qtool_bar, 1, 1, 0), 0, 0);
+       keymap = get_keymap (access_keymap (maps[i], Qtool_bar, 1, 0, 1), 0, 1);
        if (CONSP (keymap))
          {
            Lisp_Object tail;
@@ -7793,7 +7857,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
   if (INTERACTIVE)
     {
       if (!NILP (prompt))
-       echo_prompt (XSTRING (prompt)->data);
+       echo_prompt (prompt);
       else if (cursor_in_echo_area
               && (FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes))
               && NILP (Fzerop (Vecho_keystrokes)))
@@ -7820,8 +7884,8 @@ 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);
 
   /* 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,
@@ -7990,8 +8054,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
@@ -8037,8 +8101,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;
            }
 
@@ -8052,8 +8116,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;
            }
 
@@ -8138,12 +8202,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;
                }
              
@@ -8165,7 +8227,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;
@@ -8175,7 +8237,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;
@@ -8836,9 +8898,13 @@ DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 5, 0,
                         prompt, ! NILP (dont_downcase_last),
                         ! NILP (can_return_switch_frame), 0);
 
+#if 0  /* The following is fine for code reading a key sequence and
+         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 ();
+#endif
 #endif
 
   if (i == -1)
@@ -8853,8 +8919,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.")
-  (prompt, continue_echo, dont_downcase_last, can_return_switch_frame,
-   command_loop)
+     /* Don't break the following line for documentation's sake.  */
+  (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;
 {
@@ -9002,6 +9068,8 @@ a special event, so ignore the prefix argument and don't clear it.")
     }
   return Qnil;
 }
+
+
 \f
 DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_command,
   1, 1, "P",
@@ -9124,7 +9192,9 @@ DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_
          Lisp_Object binding;
          char *newmessage;
          int message_p = push_message ();
+         int count = BINDING_STACK_SIZE ();
 
+         record_unwind_protect (push_message_unwind, Qnil);
          binding = Fkey_description (bindings);
 
          newmessage
@@ -9143,7 +9213,7 @@ DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_
              && message_p)
            restore_message ();
 
-         pop_message ();
+         unbind_to (count, Qnil);
        }
     }
 
@@ -9177,7 +9247,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);
@@ -9186,7 +9256,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;
 
@@ -10591,6 +10661,11 @@ suppressed only after special commands that set\n\
 A value of nil means menu bindings should not be updated.\n\
 Used during Emacs' startup.");
   update_menu_bindings = 1;
+
+  DEFVAR_LISP ("minibuffer-message-timeout", &Vminibuffer_message_timeout,
+    "*How long to display an echo-area message when the minibuffer is active.\n\
+If the value is not a number, such messages don't time out.");
+  Vminibuffer_message_timeout = make_number (2);
 }
 
 void