]> code.delx.au - gnu-emacs/blobdiff - src/keyboard.c
* lisp/emacs-lisp/package.el: Fix selected-package logic
[gnu-emacs] / src / keyboard.c
index 383c109c4466abda02a8277b459e2973d0f554ee..eb66c445559e2d01d0b712f87e1fc425ac67f466 100644 (file)
@@ -391,47 +391,47 @@ static void store_user_signal_events (void);
 static void
 kset_echo_string (struct kboard *kb, Lisp_Object val)
 {
-  kb->INTERNAL_FIELD (echo_string) = val;
+  kb->echo_string_ = val;
 }
 static void
 kset_kbd_queue (struct kboard *kb, Lisp_Object val)
 {
-  kb->INTERNAL_FIELD (kbd_queue) = val;
+  kb->kbd_queue_ = val;
 }
 static void
 kset_keyboard_translate_table (struct kboard *kb, Lisp_Object val)
 {
-  kb->INTERNAL_FIELD (Vkeyboard_translate_table) = val;
+  kb->Vkeyboard_translate_table_ = val;
 }
 static void
 kset_last_prefix_arg (struct kboard *kb, Lisp_Object val)
 {
-  kb->INTERNAL_FIELD (Vlast_prefix_arg) = val;
+  kb->Vlast_prefix_arg_ = val;
 }
 static void
 kset_last_repeatable_command (struct kboard *kb, Lisp_Object val)
 {
-  kb->INTERNAL_FIELD (Vlast_repeatable_command) = val;
+  kb->Vlast_repeatable_command_ = val;
 }
 static void
 kset_local_function_key_map (struct kboard *kb, Lisp_Object val)
 {
-  kb->INTERNAL_FIELD (Vlocal_function_key_map) = val;
+  kb->Vlocal_function_key_map_ = val;
 }
 static void
 kset_overriding_terminal_local_map (struct kboard *kb, Lisp_Object val)
 {
-  kb->INTERNAL_FIELD (Voverriding_terminal_local_map) = val;
+  kb->Voverriding_terminal_local_map_ = val;
 }
 static void
 kset_real_last_command (struct kboard *kb, Lisp_Object val)
 {
-  kb->INTERNAL_FIELD (Vreal_last_command) = val;
+  kb->Vreal_last_command_ = val;
 }
 static void
 kset_system_key_syms (struct kboard *kb, Lisp_Object val)
 {
-  kb->INTERNAL_FIELD (system_key_syms) = val;
+  kb->system_key_syms_ = val;
 }
 
 \f
@@ -1702,7 +1702,8 @@ adjust_point_for_property (ptrdiff_t last_pt, bool modified)
       if (check_display
          && PT > BEGV && PT < ZV
          && !NILP (val = get_char_property_and_overlay
-                             (make_number (PT), Qdisplay, Qnil, &overlay))
+                             (make_number (PT), Qdisplay, selected_window,
+                              &overlay))
          && display_prop_intangible_p (val, overlay, PT, PT_BYTE)
          && (!OVERLAYP (overlay)
              ? get_property_and_range (PT, Qdisplay, &val, &beg, &end, Qnil)
@@ -2192,7 +2193,7 @@ read_event_from_main_queue (struct timespec *end_time,
   save_getcjmp (save_jump);
   restore_getcjmp (local_getcjmp);
   if (!end_time)
-       timer_start_idle ();
+    timer_start_idle ();
   c = kbd_buffer_get_event (&kb, used_mouse_menu, end_time);
   restore_getcjmp (save_jump);
 
@@ -2288,30 +2289,41 @@ read_decoded_event_from_main_queue (struct timespec *end_time,
            { /* An encoded byte sequence, let's try to decode it.  */
              struct coding_system *coding
                = TERMINAL_KEYBOARD_CODING (terminal);
-             unsigned char src[MAX_ENCODED_BYTES];
-             unsigned char dest[MAX_ENCODED_BYTES * MAX_MULTIBYTE_LENGTH];
-             int i;
-             for (i = 0; i < n; i++)
-               src[i] = XINT (events[i]);
-             if (meta_key != 2)
-               for (i = 0; i < n; i++)
-                 src[i] &= ~0x80;
-             coding->destination = dest;
-             coding->dst_bytes = sizeof dest;
-             decode_coding_c_string (coding, src, n, Qnil);
-             eassert (coding->produced_char <= n);
-             if (coding->produced_char == 0)
-               { /* The encoded sequence is incomplete.  */
-                 if (n < MAX_ENCODED_BYTES) /* Avoid buffer overflow.  */
-                   continue;                /* Read on!  */
+
+             if (raw_text_coding_system_p (coding))
+               {
+                 int i;
+                 if (meta_key != 2)
+                   for (i = 0; i < n; i++)
+                     events[i] = make_number (XINT (events[i]) & ~0x80);
                }
              else
                {
-                 const unsigned char *p = coding->destination;
-                 eassert (coding->carryover_bytes == 0);
-                 n = 0;
-                 while (n < coding->produced_char)
-                   events[n++] = make_number (STRING_CHAR_ADVANCE (p));
+                 unsigned char src[MAX_ENCODED_BYTES];
+                 unsigned char dest[MAX_ENCODED_BYTES * MAX_MULTIBYTE_LENGTH];
+                 int i;
+                 for (i = 0; i < n; i++)
+                   src[i] = XINT (events[i]);
+                 if (meta_key != 2)
+                   for (i = 0; i < n; i++)
+                     src[i] &= ~0x80;
+                 coding->destination = dest;
+                 coding->dst_bytes = sizeof dest;
+                 decode_coding_c_string (coding, src, n, Qnil);
+                 eassert (coding->produced_char <= n);
+                 if (coding->produced_char == 0)
+                   { /* The encoded sequence is incomplete.  */
+                     if (n < MAX_ENCODED_BYTES) /* Avoid buffer overflow.  */
+                       continue;                    /* Read on!  */
+                   }
+                 else
+                   {
+                     const unsigned char *p = coding->destination;
+                     eassert (coding->carryover_bytes == 0);
+                     n = 0;
+                     while (n < coding->produced_char)
+                       events[n++] = make_number (STRING_CHAR_ADVANCE (p));
+                   }
                }
            }
          /* Now `events' should hold decoded events.
@@ -3023,6 +3035,7 @@ read_char (int commandflag, Lisp_Object map,
       Lisp_Object keys;
       ptrdiff_t key_count;
       bool key_count_reset;
+      ptrdiff_t command_key_start;
       struct gcpro gcpro1;
       ptrdiff_t count = SPECPDL_INDEX ();
 
@@ -3046,6 +3059,7 @@ read_char (int commandflag, Lisp_Object map,
       /* Save the this_command_keys status.  */
       key_count = this_command_key_count;
       key_count_reset = this_command_key_count_reset;
+      command_key_start = this_single_command_key_start;
 
       if (key_count > 0)
        keys = Fcopy_sequence (this_command_keys);
@@ -3056,6 +3070,7 @@ read_char (int commandflag, Lisp_Object map,
       /* Clear out this_command_keys.  */
       this_command_key_count = 0;
       this_command_key_count_reset = 0;
+      this_single_command_key_start = 0;
 
       /* Now wipe the echo area.  */
       if (!NILP (echo_area_buffer[0]))
@@ -3079,12 +3094,20 @@ read_char (int commandflag, Lisp_Object map,
         and this_command_keys state.  */
       this_command_key_count = key_count;
       this_command_key_count_reset = key_count_reset;
+      this_single_command_key_start = command_key_start;
       if (key_count > 0)
        this_command_keys = keys;
 
       cancel_echoing ();
       ok_to_echo_at_next_pause = saved_ok_to_echo;
-      kset_echo_string (current_kboard, saved_echo_string);
+      /* Do not restore the echo area string when the user is
+         introducing a prefix argument. Otherwise we end with
+         repetitions of the partially introduced prefix
+         argument. (bug#19875) */
+      if (NILP (intern ("prefix-arg")))
+        {
+          kset_echo_string (current_kboard, saved_echo_string);
+        }
       current_kboard->echo_after_prompt = saved_echo_after_prompt;
       if (saved_immediate_echo)
        echo_now ();
@@ -3639,7 +3662,9 @@ kbd_buffer_store_event_hold (register struct input_event *event,
      as input, set quit-flag to cause an interrupt.  */
   if (!NILP (Vthrow_on_input)
       && event->kind != FOCUS_IN_EVENT
+      && event->kind != FOCUS_OUT_EVENT
       && event->kind != HELP_EVENT
+      && event->kind != ICONIFY_EVENT
       && event->kind != DEICONIFY_EVENT)
     {
       Vquit_flag = Vthrow_on_input;
@@ -3829,7 +3854,7 @@ kbd_buffer_get_event (KBOARD **kbp,
   if (noninteractive
       /* In case we are running as a daemon, only do this before
         detaching from the terminal.  */
-      || (IS_DAEMON && daemon_pipe[1] >= 0))
+      || (IS_DAEMON && DAEMON_RUNNING))
     {
       int c = getchar ();
       XSETINT (obj, c);
@@ -4356,19 +4381,18 @@ Lisp_Object pending_funcalls;
 static bool
 decode_timer (Lisp_Object timer, struct timespec *result)
 {
-  Lisp_Object *vector;
+  Lisp_Object *vec;
 
   if (! (VECTORP (timer) && ASIZE (timer) == 9))
     return 0;
-  vector = XVECTOR (timer)->contents;
-  if (! NILP (vector[0]))
+  vec = XVECTOR (timer)->contents;
+  if (! NILP (vec[0]))
     return 0;
-  if (! INTEGERP (vector[2]))
+  if (! INTEGERP (vec[2]))
     return false;
 
   struct lisp_time t;
-  if (! decode_time_components (vector[1], vector[2], vector[3], vector[8],
-                               &t, 0))
+  if (decode_time_components (vec[1], vec[2], vec[3], vec[8], &t, 0) <= 0)
     return false;
   *result = lisp_to_timespec (t);
   return timespec_valid_p (*result);
@@ -4429,7 +4453,7 @@ timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers)
       /* Set TIMER and TIMER_DIFFERENCE
         based on the next ordinary timer.
         TIMER_DIFFERENCE is the distance in time from NOW to when
-        this timer becomes ripe (negative if it's already ripe).
+        this timer becomes ripe.
          Skip past invalid timers and timers already handled.  */
       if (CONSP (timers))
        {
@@ -5337,9 +5361,9 @@ make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
          dy = yret = wy;
        }
 
-      /* For clicks in the text area, fringes, or margins, call
-        buffer_posn_from_coords to extract TEXTPOS, the buffer
-        position nearest to the click.  */
+      /* For clicks in the text area, fringes, margins, or vertical
+        scroll bar, call buffer_posn_from_coords to extract TEXTPOS,
+        the buffer position nearest to the click.  */
       if (!textpos)
        {
          Lisp_Object string2, object2 = Qnil;
@@ -5347,11 +5371,14 @@ make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
          int dx2, dy2;
          int width2, height2;
          /* The pixel X coordinate passed to buffer_posn_from_coords
-            is the X coordinate relative to the text area for
-            text-area and right-margin clicks, zero otherwise.  */
+            is the X coordinate relative to the text area for clicks
+            in text-area, right-margin/fringe and right-side vertical
+            scroll bar, zero otherwise.  */
          int x2
            = (part == ON_TEXT) ? xret
-           : (part == ON_RIGHT_FRINGE || part == ON_RIGHT_MARGIN)
+           : (part == ON_RIGHT_FRINGE || part == ON_RIGHT_MARGIN
+              || (part == ON_VERTICAL_SCROLL_BAR
+                  && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w)))
            ? (XINT (x) - window_box_left (w, TEXT_AREA))
            : 0;
          int y2 = wy;
@@ -8681,12 +8708,10 @@ read_char_minibuf_menu_prompt (int commandflag,
       while (BUFFERP (obj));
       kset_defining_kbd_macro (current_kboard, orig_defn_macro);
 
-      if (!INTEGERP (obj) || XINT (obj) == -2)
-        return obj;
-
-      if (! EQ (obj, menu_prompt_more_char)
-         && (!INTEGERP (menu_prompt_more_char)
-             || ! EQ (obj, make_number (Ctl (XINT (menu_prompt_more_char))))))
+      if (!INTEGERP (obj) || XINT (obj) == -2
+         || (! EQ (obj, menu_prompt_more_char)
+             && (!INTEGERP (menu_prompt_more_char)
+                 || ! EQ (obj, make_number (Ctl (XINT (menu_prompt_more_char)))))))
        {
          if (!NILP (KVAR (current_kboard, defining_kbd_macro)))
            store_kbd_macro_char (obj);
@@ -9565,6 +9590,18 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
 
       /* Record what part of this_command_keys is the current key sequence.  */
       this_single_command_key_start = this_command_key_count - t;
+      /* When 'input-method-function' called above causes events to be
+        put on 'unread-post-input-method-events', and as result
+        'reread' is set to 'true', the value of 't' can become larger
+        than 'this_command_key_count', because 'add_command_key' is
+        not called to update 'this_command_key_count'.  If this
+        happens, 'this_single_command_key_start' will become negative
+        above, and any call to 'this-single-command-keys' will return
+        a garbled vector.  See bug #20223 for one such situation.
+        Here we force 'this_single_command_key_start' to never become
+        negative, to avoid that.  */
+      if (this_single_command_key_start < 0)
+       this_single_command_key_start = 0;
 
       /* Look for this sequence in input-decode-map.
         Scan from indec.end until we find a bound suffix.  */
@@ -11454,6 +11491,7 @@ for that character after that prefix key.  */);
               doc: /* Form to evaluate when Emacs starts up.
 Useful to set before you dump a modified Emacs.  */);
   Vtop_level = Qnil;
+  XSYMBOL (Qtop_level)->declared_special = false;
 
   DEFVAR_KBOARD ("keyboard-translate-table", Vkeyboard_translate_table,
                  doc: /* Translate table for local keyboard input, or nil.
@@ -11575,7 +11613,7 @@ and the minor mode maps regardless of `overriding-local-map'.  */);
 
   DEFVAR_LISP ("special-event-map", Vspecial_event_map,
               doc: /* Keymap defining bindings for special events to execute at low level.  */);
-  Vspecial_event_map = list1 (intern_c_string ("keymap"));
+  Vspecial_event_map = list1 (Qkeymap);
 
   DEFVAR_LISP ("track-mouse", do_mouse_tracking,
               doc: /* Non-nil means generate motion events for mouse motion.  */);
@@ -11695,7 +11733,7 @@ the previous echo area message.
 The input method function should refer to the variables
 `input-method-use-echo-area' and `input-method-exit-on-first-char'
 for guidance on what to do.  */);
-  Vinput_method_function = Qnil;
+  Vinput_method_function = Qlist;
 
   DEFVAR_LISP ("input-method-previous-message",
               Vinput_method_previous_message,