Merge from trunk after a lot of time.
authorEli Zaretskii <eliz@gnu.org>
Thu, 5 Sep 2013 08:01:04 +0000 (11:01 +0300)
committerEli Zaretskii <eliz@gnu.org>
Thu, 5 Sep 2013 08:01:04 +0000 (11:01 +0300)
1  2 
src/dispextern.h
src/dispnew.c
src/keyboard.c
src/menu.c
src/menu.h
src/msdos.c
src/term.c
src/termhooks.h
src/w32console.c
src/window.c
src/xdisp.c

@@@ -3295,36 -3451,35 +3454,36 @@@ extern Lisp_Object marginal_area_strin
                                           Lisp_Object *,
                                           int *, int *, int *, int *);
  extern void redraw_frame (struct frame *);
- extern int update_frame (struct frame *, int, int);
+ extern void cancel_line (int, struct frame *);
+ extern void init_desired_glyphs (struct frame *);
+ extern bool update_frame (struct frame *, bool, bool);
 +extern void update_frame_with_menu (struct frame *);
  extern void bitch_at_user (void);
- extern void adjust_glyphs (struct frame *);
- extern void free_glyphs (struct frame *);
- extern void free_window_matrices (struct window *);
- extern void check_glyph_memory (void);
- extern struct glyph_matrix *save_current_matrix (struct frame *);
- extern void mirrored_line_dance (struct glyph_matrix *, int, int, int *,
-                                char *);
- extern void clear_glyph_matrix (struct glyph_matrix *);
- extern void clear_current_matrices (struct frame *f);
- extern void clear_desired_matrices (struct frame *);
- extern void shift_glyph_matrix (struct window *, struct glyph_matrix *,
-                               int, int, int);
- extern void rotate_matrix (struct glyph_matrix *, int, int, int);
- extern void increment_matrix_positions (struct glyph_matrix *,
-                                       int, int, ptrdiff_t, ptrdiff_t);
- extern void blank_row (struct window *, struct glyph_row *, int);
- extern void enable_glyph_matrix_rows (struct glyph_matrix *, int, int, int);
- extern void clear_glyph_row (struct glyph_row *);
- extern void prepare_desired_row (struct glyph_row *);
- extern void set_window_update_flags (struct window *, int);
- extern void update_single_window (struct window *, int);
- extern void do_pending_window_change (int);
- extern void change_frame_size (struct frame *, int, int, int, int, int);
- extern void init_display (void);
- extern void syms_of_display (void);
+ void adjust_glyphs (struct frame *);
+ void free_glyphs (struct frame *);
+ void free_window_matrices (struct window *);
+ void check_glyph_memory (void);
+ void mirrored_line_dance (struct glyph_matrix *, int, int, int *, char *);
+ void clear_glyph_matrix (struct glyph_matrix *);
+ void clear_current_matrices (struct frame *f);
+ void clear_desired_matrices (struct frame *);
+ void shift_glyph_matrix (struct window *, struct glyph_matrix *,
+                          int, int, int);
+ void rotate_matrix (struct glyph_matrix *, int, int, int);
+ void increment_matrix_positions (struct glyph_matrix *,
+                                  int, int, ptrdiff_t, ptrdiff_t);
+ void blank_row (struct window *, struct glyph_row *, int);
+ void clear_glyph_matrix_rows (struct glyph_matrix *, int, int);
+ void clear_glyph_row (struct glyph_row *);
+ void prepare_desired_row (struct glyph_row *);
+ void set_window_update_flags (struct window *, bool);
+ void update_single_window (struct window *, bool);
+ void do_pending_window_change (bool);
+ void change_frame_size (struct frame *, int, int, bool, bool, bool);
+ void init_display (void);
+ void syms_of_display (void);
  extern Lisp_Object Qredisplay_dont_pause;
 -void spec_glyph_lookup_face (struct window *, GLYPH *);
 +extern void spec_glyph_lookup_face (struct window *, GLYPH *);
  
  /* Defined in terminal.c */
  
diff --cc src/dispnew.c
@@@ -2058,26 -1926,9 +1926,26 @@@ save_current_matrix (struct frame *f
        struct glyph_row *from = f->current_matrix->rows + i;
        struct glyph_row *to = saved->rows + i;
        ptrdiff_t nbytes = from->used[TEXT_AREA] * sizeof (struct glyph);
-       to->glyphs[TEXT_AREA] = (struct glyph *) xmalloc (nbytes);
 +
+       to->glyphs[TEXT_AREA] = xmalloc (nbytes);
        memcpy (to->glyphs[TEXT_AREA], from->glyphs[TEXT_AREA], nbytes);
        to->used[TEXT_AREA] = from->used[TEXT_AREA];
 +      if (from->used[LEFT_MARGIN_AREA])
 +      {
 +        nbytes = from->used[LEFT_MARGIN_AREA] * sizeof (struct glyph);
 +        to->glyphs[LEFT_MARGIN_AREA] = (struct glyph *) xmalloc (nbytes);
 +        memcpy (to->glyphs[LEFT_MARGIN_AREA],
 +                from->glyphs[LEFT_MARGIN_AREA], nbytes);
 +        to->used[LEFT_MARGIN_AREA] = from->used[LEFT_MARGIN_AREA];
 +      }
 +      if (from->used[RIGHT_MARGIN_AREA])
 +      {
 +        nbytes = from->used[RIGHT_MARGIN_AREA] * sizeof (struct glyph);
 +        to->glyphs[RIGHT_MARGIN_AREA] = (struct glyph *) xmalloc (nbytes);
 +        memcpy (to->glyphs[RIGHT_MARGIN_AREA],
 +                from->glyphs[RIGHT_MARGIN_AREA], nbytes);
 +        to->used[RIGHT_MARGIN_AREA] = from->used[RIGHT_MARGIN_AREA];
 +      }
      }
  
    return saved;
diff --cc src/keyboard.c
@@@ -2246,14 -2205,165 +2205,166 @@@ do { if (! polling_stopped_here) stop_p
  do { if (polling_stopped_here) start_polling ();      \
         polling_stopped_here = 0; } while (0)
  
- /* read a character from the keyboard; call the redisplay if needed */
+ static Lisp_Object
+ read_event_from_main_queue (struct timespec *end_time,
+                             sys_jmp_buf local_getcjmp,
+                             bool *used_mouse_menu)
+ {
+   Lisp_Object c = Qnil;
+   sys_jmp_buf save_jump;
+   KBOARD *kb IF_LINT (= NULL);
+  start:
+   /* Read from the main queue, and if that gives us something we can't use yet,
+      we put it on the appropriate side queue and try again.  */
+   if (end_time && timespec_cmp (*end_time, current_timespec ()) <= 0)
+     return c;
+   /* Actually read a character, waiting if necessary.  */
+   save_getcjmp (save_jump);
+   restore_getcjmp (local_getcjmp);
+   if (!end_time)
+       timer_start_idle ();
+   c = kbd_buffer_get_event (&kb, used_mouse_menu, end_time);
+   restore_getcjmp (save_jump);
+   if (! NILP (c) && (kb != current_kboard))
+     {
+       Lisp_Object last = KVAR (kb, kbd_queue);
+       if (CONSP (last))
+         {
+           while (CONSP (XCDR (last)))
+               last = XCDR (last);
+           if (!NILP (XCDR (last)))
+               emacs_abort ();
+         }
+       if (!CONSP (last))
+         kset_kbd_queue (kb, list1 (c));
+       else
+         XSETCDR (last, list1 (c));
+       kb->kbd_queue_has_data = 1;
+       c = Qnil;
+       if (single_kboard)
+         goto start;
+       current_kboard = kb;
+       /* This is going to exit from read_char
+          so we had better get rid of this frame's stuff.  */
+       return make_number (-2);
+     }
+   /* Terminate Emacs in batch mode if at eof.  */
+   if (noninteractive && INTEGERP (c) && XINT (c) < 0)
+     Fkill_emacs (make_number (1));
+   if (INTEGERP (c))
+     {
+       /* Add in any extra modifiers, where appropriate.  */
+       if ((extra_keyboard_modifiers & CHAR_CTL)
+         || ((extra_keyboard_modifiers & 0177) < ' '
+             && (extra_keyboard_modifiers & 0177) != 0))
+       XSETINT (c, make_ctrl_char (XINT (c)));
+       /* Transfer any other modifier bits directly from
+        extra_keyboard_modifiers to c.  Ignore the actual character code
+        in the low 16 bits of extra_keyboard_modifiers.  */
+       XSETINT (c, XINT (c) | (extra_keyboard_modifiers & ~0xff7f & ~CHAR_CTL));
+     }
+   return c;
+ }
+ /* Like `read_event_from_main_queue' but applies keyboard-coding-system
+    to tty input.  */
+ static Lisp_Object
+ read_decoded_event_from_main_queue (struct timespec *end_time,
+                                     sys_jmp_buf local_getcjmp,
+                                     Lisp_Object prev_event,
+                                     bool *used_mouse_menu)
+ {
+ #define MAX_ENCODED_BYTES 16
+   Lisp_Object events[MAX_ENCODED_BYTES];
+   int n = 0;
+   while (true)
+     {
+       Lisp_Object nextevt
+         = read_event_from_main_queue (end_time, local_getcjmp,
+                                       used_mouse_menu);
+ #ifdef WINDOWSNT
+       /* w32_console already returns decoded events.  It either reads
+        Unicode characters from the Windows keyboard input, or
+        converts characters encoded in the current codepage into
+        Unicode.  See w32inevt.c:key_event, near its end.  */
+       return nextevt;
+ #else
+       struct frame *frame = XFRAME (selected_frame);
+       struct terminal *terminal = frame->terminal;
+       if (!((FRAME_TERMCAP_P (frame) || FRAME_MSDOS_P (frame))
+             /* Don't apply decoding if we're just reading a raw event
+                (e.g. reading bytes sent by the xterm to specify the position
+                of a mouse click).  */
+             && (!EQ (prev_event, Qt))
+           && (TERMINAL_KEYBOARD_CODING (terminal)->common_flags
+               & CODING_REQUIRE_DECODING_MASK)))
+       return nextevt;         /* No decoding needed.  */
+       else
+       {
+         int meta_key = terminal->display_info.tty->meta_key;
+         eassert (n < MAX_ENCODED_BYTES);
+         events[n++] = nextevt;
+         if (NATNUMP (nextevt)
+             && XINT (nextevt) < (meta_key == 1 ? 0x80 : 0x100))
+           { /* An encoded byte sequence, let's try to decode it.  */
+             struct coding_system *coding
+               = TERMINAL_KEYBOARD_CODING (terminal);
+             unsigned char *src = alloca (n);
+             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 = alloca (n * 4);
+             coding->dst_bytes = n * 4;
+             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.
+            Normally, n should be equal to 1, but better not rely on it.
+            We can only return one event here, so return the first we
+            had and keep the others (if any) for later.  */
+         while (n > 1)
+           Vunread_command_events
+             = Fcons (events[--n], Vunread_command_events);
+         return events[0];
+       }
+ #endif
+     }
+ }
+ /* Read a character from the keyboard; call the redisplay if needed.  */
  /* commandflag 0 means do not autosave, but do redisplay.
     -1 means do not redisplay, but do autosave.
 +   -2 means do neither.
     1 means do both.  */
  
- /* The arguments MAPS and NMAPS are for menu prompting.
-    MAPS is an array of keymaps;  NMAPS is the length of MAPS.
+ /* The arguments MAP is for menu prompting.  MAP is a keymap.
  
     PREV_EVENT is the previous input event, or nil if we are reading
     the first event of a key sequence (or not reading a key sequence).
diff --cc src/menu.c
@@@ -1339,17 -1324,12 +1330,17 @@@ no quit occurs and `x-popup-menu' retur
       Is this assumption ever violated?  We can't use the timestamp
       stored within POSITION because there the top bits from the actual
       timestamp may be truncated away (Bug#4930).  */
 -  selection = xmenu_show (f, xpos, ypos, for_click,
 -                        keymaps, title, &error_name,
 -                        last_event_timestamp);
 +  if (FRAME_X_P (f) || FRAME_MSDOS_P (f))
 +    selection = xmenu_show (f, xpos, ypos, for_click,
 +                          keymaps, title, &error_name,
 +                          last_event_timestamp);
 +  else
  #endif
 +  if (FRAME_TERMCAP_P (f))
 +    selection = tty_menu_show (f, xpos, ypos, for_click,
 +                             keymaps, title, &error_name);
  
-   UNBLOCK_INPUT;
+   unblock_input ();
  
  #ifdef HAVE_NS
    unbind_to (specpdl_count, Qnil);
diff --cc src/menu.h
@@@ -42,15 -42,13 +42,15 @@@ extern widget_value *digest_single_subm
  #endif
  
  #ifdef HAVE_X_WINDOWS
- extern void mouse_position_for_popup (FRAME_PTR f, int *x, int *y);
+ extern void mouse_position_for_popup (struct frame *f, int *x, int *y);
  #endif
  
- extern Lisp_Object w32_menu_show (FRAME_PTR, int, int, int, int,
+ extern Lisp_Object w32_menu_show (struct frame *, int, int, int, int,
                                  Lisp_Object, const char **);
- extern Lisp_Object ns_menu_show (FRAME_PTR, int, int, int, int,
+ extern Lisp_Object ns_menu_show (struct frame *, int, int, bool, bool,
                                 Lisp_Object, const char **);
- extern Lisp_Object xmenu_show (FRAME_PTR, int, int, int, int,
+ extern Lisp_Object xmenu_show (struct frame *, int, int, bool, bool,
                               Lisp_Object, const char **, Time);
 +extern Lisp_Object tty_menu_show (FRAME_PTR, int, int, int, int,
 +                                Lisp_Object, const char **);
  #endif /* MENU_H */
diff --cc src/msdos.c
@@@ -1386,9 -1376,16 +1376,9 @@@ IT_insert_glyphs (struct frame *f, stru
  static void
  IT_delete_glyphs (struct frame *f, int n)
  {
-   abort ();
+   emacs_abort ();
  }
  
 -/* set-window-configuration on window.c needs this.  */
 -void
 -x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 -{
 -  set_menu_bar_lines (f, value, oldval);
 -}
 -
  /* This was copied from xfaces.c  */
  
  extern Lisp_Object Qbackground_color;
diff --cc src/term.c
@@@ -58,18 -56,6 +56,8 @@@ static int been_here = -1
  #include "xterm.h"
  #endif
  
- #ifdef HAVE_MENUS
 +#include "menu.h"
- #endif
- #ifndef O_RDWR
- #define O_RDWR 2
- #endif
- #ifndef O_NOCTTY
- #define O_NOCTTY 0
- #endif
 +
  /* The name of the default console device.  */
  #ifdef WINDOWSNT
  #define DEV_TTY  "CONOUT$"
diff --cc src/termhooks.h
@@@ -666,8 -663,6 +663,11 @@@ extern unsigned char *encode_terminal_c
  extern void close_gpm (int gpm_fd);
  #endif
  
 +#ifdef WINDOWSNT
 +extern int curX (struct tty_display_info *);
 +extern int curY (struct tty_display_info *);
 +#endif
 +
+ INLINE_HEADER_END
+ #endif /* EMACS_TERMHOOKS_H */
Simple merge
diff --cc src/window.c
Simple merge
diff --cc src/xdisp.c
Simple merge