]> code.delx.au - gnu-emacs/blobdiff - src/xdisp.c
Merge branch 'master' into xwidget
[gnu-emacs] / src / xdisp.c
index 8b68ab7ddf78982dfbf23dc1e19c6285289396ee..01d598fe2c2d2f5281b192cd8d652bacedf93cfb 100644 (file)
@@ -2730,9 +2730,9 @@ init_iterator (struct it *it, struct window *w,
      free realized faces now because they depend on face definitions
      that might have changed.  Don't free faces while there might be
      desired matrices pending which reference these faces.  */
-  if (face_change_count && !inhibit_free_realized_faces)
+  if (face_change && !inhibit_free_realized_faces)
     {
-      face_change_count = 0;
+      face_change = false;
       free_all_realized_faces (Qnil);
     }
 
@@ -2752,17 +2752,14 @@ init_iterator (struct it *it, struct window *w,
        row = MATRIX_HEADER_LINE_ROW (w->desired_matrix);
     }
 
-  /* Clear IT.  */
-  memset (it, 0, sizeof *it);
+  /* Clear IT, and set it->object and other IT's Lisp objects to Qnil.
+     Other parts of redisplay rely on that.  */
+  memclear (it, sizeof *it);
   it->current.overlay_string_index = -1;
   it->current.dpvec_index = -1;
   it->base_face_id = remapped_base_face_id;
-  it->string = Qnil;
   IT_STRING_CHARPOS (*it) = IT_STRING_BYTEPOS (*it) = -1;
   it->paragraph_embedding = L2R;
-  it->bidi_it.string.lstring = Qnil;
-  it->bidi_it.string.s = NULL;
-  it->bidi_it.string.bufpos = 0;
   it->bidi_it.w = w;
 
   /* The window in which we iterate over current_buffer:  */
@@ -2783,7 +2780,6 @@ init_iterator (struct it *it, struct window *w,
                                  * FRAME_LINE_HEIGHT (it->f));
       else if (it->f->extra_line_spacing > 0)
        it->extra_line_spacing = it->f->extra_line_spacing;
-      it->max_extra_line_spacing = 0;
     }
 
   /* If realized faces have been removed, e.g. because of face
@@ -2795,10 +2791,6 @@ init_iterator (struct it *it, struct window *w,
   if (FRAME_FACE_CACHE (it->f)->used == 0)
     recompute_basic_faces (it->f);
 
-  /* Current value of the `slice', `space-width', and 'height' properties.  */
-  it->slice.x = it->slice.y = it->slice.width = it->slice.height = Qnil;
-  it->space_width = Qnil;
-  it->font_height = Qnil;
   it->override_ascent = -1;
 
   /* Are control characters displayed as `^C'?  */
@@ -2836,21 +2828,19 @@ init_iterator (struct it *it, struct window *w,
   it->tab_width = SANE_TAB_WIDTH (current_buffer);
 
   /* Are lines in the display truncated?  */
-  if (base_face_id != DEFAULT_FACE_ID
-      || it->w->hscroll
-      || (! WINDOW_FULL_WIDTH_P (it->w)
-         && ((!NILP (Vtruncate_partial_width_windows)
-              && !INTEGERP (Vtruncate_partial_width_windows))
-             || (INTEGERP (Vtruncate_partial_width_windows)
-                 /* PXW: Shall we do something about this?  */
-                 && (WINDOW_TOTAL_COLS (it->w)
-                     < XINT (Vtruncate_partial_width_windows))))))
+  if (TRUNCATE != 0)
     it->line_wrap = TRUNCATE;
-  else if (NILP (BVAR (current_buffer, truncate_lines)))
+  if (base_face_id == DEFAULT_FACE_ID
+      && !it->w->hscroll
+      && (WINDOW_FULL_WIDTH_P (it->w)
+         || NILP (Vtruncate_partial_width_windows)
+         || (INTEGERP (Vtruncate_partial_width_windows)
+             /* PXW: Shall we do something about this?  */
+             && (XINT (Vtruncate_partial_width_windows)
+                 <= WINDOW_TOTAL_COLS (it->w))))
+      && NILP (BVAR (current_buffer, truncate_lines)))
     it->line_wrap = NILP (BVAR (current_buffer, word_wrap))
       ? WINDOW_WRAP : WORD_WRAP;
-  else
-    it->line_wrap = TRUNCATE;
 
   /* Get dimensions of truncation and continuation glyphs.  These are
      displayed as fringe bitmaps under X, but we need them for such
@@ -3893,7 +3883,7 @@ handle_face_prop (struct it *it)
                                   &next_stop,
                                   (IT_CHARPOS (*it)
                                    + TEXT_PROP_DISTANCE_LIMIT),
-                                  0, it->base_face_id);
+                                  false, it->base_face_id);
 
       /* Is this a start of a run of characters with box face?
         Caveat: this can be called for a freshly initialized
@@ -3969,7 +3959,7 @@ handle_face_prop (struct it *it)
                                       &next_stop,
                                       (IT_CHARPOS (*it)
                                        + TEXT_PROP_DISTANCE_LIMIT),
-                                      0,
+                                      false,
                                       from_overlay);
        }
       else
@@ -4004,7 +3994,7 @@ handle_face_prop (struct it *it)
                                             IT_STRING_CHARPOS (*it),
                                             bufpos,
                                             &next_stop,
-                                            base_face_id, 0);
+                                            base_face_id, false);
 
       /* Is this a start of a run of characters with box?  Caveat:
         this can be called for a freshly allocated iterator; face_id
@@ -4146,7 +4136,7 @@ face_before_or_after_it_pos (struct it *it, int before_p)
                                         charpos,
                                         bufpos,
                                         &next_check_charpos,
-                                        base_face_id, 0);
+                                        base_face_id, false);
 
       /* Correct the face for charsets different from ASCII.  Do it
         for the multibyte case only.  The face returned above is
@@ -4235,7 +4225,7 @@ face_before_or_after_it_pos (struct it *it, int before_p)
       face_id = face_at_buffer_position (it->w,
                                         CHARPOS (pos),
                                         &next_check_charpos,
-                                        limit, 0, -1);
+                                        limit, false, -1);
 
       /* Correct the face for charsets different from ASCII.  Do it
         for the multibyte case only.  The face returned above is
@@ -5145,7 +5135,8 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
 #endif /* not HAVE_WINDOW_SYSTEM */
              || (CONSP (value) && EQ (XCAR (value), Qspace))
 #ifdef HAVE_XWIDGETS
-             || valid_xwidget_spec_p(value)
+             || ((it ? FRAME_WINDOW_P (it->f) : frame_window_p)
+                && valid_xwidget_spec_p(value))
 #endif
              );
 
@@ -5225,7 +5216,6 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
 #ifdef HAVE_XWIDGETS
       else if (valid_xwidget_spec_p(value))
        {
-          //printf("handle_single_display_spec: im an xwidget!!\n");
           it->what = IT_XWIDGET;
           it->method = GET_FROM_XWIDGET;
           it->position = start_pos;
@@ -7214,7 +7204,7 @@ get_next_display_element (struct it *it)
                    {
                      next_face_id = face_at_buffer_position
                        (it->w, CHARPOS (pos), &ignore,
-                        CHARPOS (pos) + TEXT_PROP_DISTANCE_LIMIT, 0, -1);
+                        CHARPOS (pos) + TEXT_PROP_DISTANCE_LIMIT, false, -1);
                      it->end_of_box_run_p
                        = (FACE_FROM_ID (it->f, next_face_id)->box
                           == FACE_NO_BOX);
@@ -8056,9 +8046,6 @@ static int
 next_element_from_xwidget (struct it *it)
 {
   it->what = IT_XWIDGET;
-  //assert_valid_xwidget_id(it->xwidget_id,"next_element_from_xwidget");
-  //this is shaky because why do we set "what" if we dont set the other parts??
-  //printf("xwidget_id %d: in next_element_from_xwidget: FIXME \n", it->xwidget_id);
   return 1;
 }
 #endif
@@ -8352,22 +8339,18 @@ next_element_from_buffer (struct it *it)
 static void
 run_redisplay_end_trigger_hook (struct it *it)
 {
-  Lisp_Object args[3];
-
   /* IT->glyph_row should be non-null, i.e. we should be actually
      displaying something, or otherwise we should not run the hook.  */
   eassert (it->glyph_row);
 
-  /* Set up hook arguments.  */
-  args[0] = Qredisplay_end_trigger_functions;
-  args[1] = it->window;
-  XSETINT (args[2], it->redisplay_end_trigger_charpos);
+  ptrdiff_t charpos = it->redisplay_end_trigger_charpos;
   it->redisplay_end_trigger_charpos = 0;
 
   /* Since we are *trying* to run these functions, don't try to run
      them again, even if they get an error.  */
   wset_redisplay_end_trigger (it->w, Qnil);
-  Frun_hook_with_args (3, args);
+  CALLN (Frun_hook_with_args, Qredisplay_end_trigger_functions, it->window,
+        make_number (charpos));
 
   /* Notice if it changed the face of the character we are on.  */
   handle_face_prop (it);
@@ -9333,6 +9316,7 @@ move_it_to (struct it *it, ptrdiff_t to_charpos, int to_x, int to_y, int to_vpos
       && it->current_x == it->last_visible_x - 1
       && it->c != '\n'
       && it->c != '\t'
+      && it->w->window_end_valid
       && it->vpos < it->w->window_end_vpos)
     {
       it->continuation_lines_width += it->current_x;
@@ -9866,7 +9850,6 @@ include the height of both, if present, in the return value.  */)
 void
 add_to_log (const char *format, Lisp_Object arg1, Lisp_Object arg2)
 {
-  Lisp_Object args[3];
   Lisp_Object msg, fmt;
   char *buffer;
   ptrdiff_t len;
@@ -9876,10 +9859,8 @@ add_to_log (const char *format, Lisp_Object arg1, Lisp_Object arg2)
   fmt = msg = Qnil;
   GCPRO4 (fmt, msg, arg1, arg2);
 
-  args[0] = fmt = build_string (format);
-  args[1] = arg1;
-  args[2] = arg2;
-  msg = Fformat (3, args);
+  fmt = build_string (format);
+  msg = CALLN (Fformat, fmt, arg1, arg2);
 
   len = SBYTES (msg) + 1;
   buffer = SAFE_ALLOCA (len);
@@ -10294,15 +10275,13 @@ message_with_string (const char *m, Lisp_Object string, int log)
         initialized yet, just toss it.  */
       if (f->glyphs_initialized_p)
        {
-         Lisp_Object args[2], msg;
          struct gcpro gcpro1, gcpro2;
 
-         args[0] = build_string (m);
-         args[1] = msg = string;
-         GCPRO2 (args[0], msg);
-         gcpro1.nvars = 2;
+         Lisp_Object fmt = build_string (m);
+         Lisp_Object msg = string;
+         GCPRO2 (fmt, msg);
 
-         msg = Fformat (2, args);
+         msg = CALLN (Fformat, fmt, msg);
 
          if (log)
            message3 (msg);
@@ -12408,6 +12387,7 @@ redisplay_tool_bar (struct frame *f)
       if (new_height != WINDOW_PIXEL_HEIGHT (w))
        {
          x_change_tool_bar_height (f, new_height);
+         frame_default_tool_bar_height = new_height;
          /* Always do that now.  */
          clear_glyph_matrix (w->desired_matrix);
          f->fonts_changed = 1;
@@ -12502,6 +12482,7 @@ redisplay_tool_bar (struct frame *f)
          if (change_height_p)
            {
              x_change_tool_bar_height (f, new_height);
+             frame_default_tool_bar_height = new_height;
              clear_glyph_matrix (w->desired_matrix);
              f->n_tool_bar_rows = nrows;
              f->fonts_changed = 1;
@@ -13445,10 +13426,10 @@ redisplay_internal (void)
   last_glyphless_glyph_frame = NULL;
   last_glyphless_glyph_face_id = (1 << FACE_ID_BITS);
 
-  /* If face_change_count is non-zero, init_iterator will free all
-     realized faces, which includes the faces referenced from current
-     matrices.  So, we can't reuse current matrices in this case.  */
-  if (face_change_count)
+  /* If face_change, init_iterator will free all realized faces, which
+     includes the faces referenced from current matrices.  So, we
+     can't reuse current matrices in this case.  */
+  if (face_change)
     windows_or_buffers_changed = 47;
 
   if ((FRAME_TERMCAP_P (sf) || FRAME_MSDOS_P (sf))
@@ -13831,6 +13812,17 @@ redisplay_internal (void)
 
        retry_frame:
 
+#if defined (HAVE_WINDOW_SYSTEM) && !defined (USE_GTK) && !defined (HAVE_NS)
+         /* Redisplay internal tool bar if this is the first time so we
+            can adjust the frame height right now, if necessary.  */
+         if (!f->tool_bar_redisplayed_once)
+           {
+             if (redisplay_tool_bar (f))
+               adjust_frame_glyphs (f);
+             f->tool_bar_redisplayed_once = true;
+           }
+#endif
+
          if (FRAME_WINDOW_P (f) || FRAME_TERMCAP_P (f) || f == sf)
            {
              bool gcscrollbars
@@ -15445,7 +15437,8 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste
   /* Likewise there was a check whether window_end_vpos is nil or larger
      than the window.  Now window_end_vpos is int and so never nil, but
      let's leave eassert to check whether it fits in the window.  */
-  eassert (w->window_end_vpos < w->current_matrix->nrows);
+  eassert (!w->window_end_valid
+          || w->window_end_vpos < w->current_matrix->nrows);
 
   /* Handle case where text has not changed, only point, and it has
      not moved off the frame.  */
@@ -18192,6 +18185,21 @@ try_window_id (struct window *w)
   if (f->fonts_changed)
     return -1;
 
+  /* The redisplay iterations in display_line above could have
+     triggered font-lock, which could have done something that
+     invalidates IT->w window's end-point information, on which we
+     rely below.  E.g., one package, which will remain unnamed, used
+     to install a font-lock-fontify-region-function that called
+     bury-buffer, whose side effect is to switch the buffer displayed
+     by IT->w, and that predictably resets IT->w's window_end_valid
+     flag, which we already tested at the entry to this function.
+     Amply punish such packages/modes by giving up on this
+     optimization in those cases.  */
+  if (!w->window_end_valid)
+    {
+      clear_glyph_matrix (w->desired_matrix);
+      return -1;
+    }
 
   /* Compute differences in buffer positions, y-positions etc.  for
      lines reused at the bottom of the window.  Compute what we can
@@ -18669,7 +18677,6 @@ dump_glyph (struct glyph_row *row, struct glyph *glyph, int area)
               glyph->left_box_line_p,
               glyph->right_box_line_p);
 
-      //      printf("dump xwidget glyph\n");
     }
 #endif
 }
@@ -18889,7 +18896,7 @@ usage: (trace-to-stderr STRING &rest OBJECTS)  */)
   (ptrdiff_t nargs, Lisp_Object *args)
 {
   Lisp_Object s = Fformat (nargs, args);
-  fprintf (stderr, "%s", SDATA (s));
+  fwrite (SDATA (s), 1, SBYTES (s), stderr);
   return Qnil;
 }
 
@@ -19643,7 +19650,7 @@ highlight_trailing_whitespace (struct frame *f, struct glyph_row *row)
                  && glyph->u.ch == ' '))
          && trailing_whitespace_p (glyph->charpos))
        {
-         int face_id = lookup_named_face (f, Qtrailing_whitespace, 0);
+         int face_id = lookup_named_face (f, Qtrailing_whitespace, false);
          if (face_id < 0)
            return;
 
@@ -23653,7 +23660,7 @@ display_string (const char *string, Lisp_Object lisp_string, Lisp_Object face_st
 
       it->face_id
        = face_at_string_position (it->w, face_string, face_string_pos,
-                                  0, &endptr, it->base_face_id, 0);
+                                  0, &endptr, it->base_face_id, false);
       face = FACE_FROM_ID (it->f, it->face_id);
       it->face_box_p = face->box != FACE_NO_BOX;
     }
@@ -24092,7 +24099,7 @@ calc_pixel_width_or_height (double *res, struct it *it, Lisp_Object prop,
 #ifdef HAVE_XWIDGETS
          if (FRAME_WINDOW_P (it->f) && valid_xwidget_spec_p (prop))
            {
-              printf("calc_pixel_width_or_height: return dummy size FIXME\n");
+              //TODO dont return dummy size
               return OK_PIXELS (width_p ? 100 : 100);
             }
 #endif
@@ -24605,13 +24612,11 @@ static void
 fill_xwidget_glyph_string (struct glyph_string *s)
 {
   eassert (s->first_glyph->type == XWIDGET_GLYPH);
-  printf("fill_xwidget_glyph_string: width:%d \n",s->first_glyph->pixel_width);
   s->face = FACE_FROM_ID (s->f, s->first_glyph->face_id);
   s->font = s->face->font;
   s->width = s->first_glyph->pixel_width;
   s->ybase += s->first_glyph->voffset;
   s->xwidget = s->first_glyph->u.xwidget;
-  //assert_valid_xwidget_id ( s->xwidget, "fill_xwidget_glyph_string");
 }
 #endif
 /* Fill glyph string S from a sequence of stretch glyphs.
@@ -24953,7 +24958,6 @@ compute_overhangs_and_x (struct glyph_string *s, int x, int backward_p)
 #define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
      do                                                                        \
        { \
-         printf("BUILD_XWIDGET_GLYPH_STRING\n");                                                      \
         s = (struct glyph_string *) alloca (sizeof *s);                \
         INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL);          \
         fill_xwidget_glyph_string (s);                                 \
@@ -25741,6 +25745,15 @@ produce_image_glyph (struct it *it)
       enum glyph_row_area area = it->area;
 
       glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area];
+      if (it->glyph_row->reversed_p)
+       {
+         struct glyph *g;
+
+         /* Make room for the new glyph.  */
+         for (g = glyph - 1; g >= it->glyph_row->glyphs[it->area]; g--)
+           g[1] = *g;
+         glyph = it->glyph_row->glyphs[it->area];
+       }
       if (glyph < it->glyph_row->glyphs[area + 1])
        {
          glyph->charpos = CHARPOS (it->position);
@@ -25791,7 +25804,6 @@ produce_xwidget_glyph (struct it *it)
   struct xwidget* xw;
   struct face *face;
   int glyph_ascent, crop;
-  printf("produce_xwidget_glyph:\n");
   eassert (it->what == IT_XWIDGET);
 
   face = FACE_FROM_ID (it->f, it->face_id);
@@ -25840,6 +25852,15 @@ produce_xwidget_glyph (struct it *it)
       enum glyph_row_area area = it->area;
 
       glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area];
+      if (it->glyph_row->reversed_p)
+       {
+         struct glyph *g;
+
+         /* Make room for the new glyph.  */
+         for (g = glyph - 1; g >= it->glyph_row->glyphs[it->area]; g--)
+           g[1] = *g;
+         glyph = it->glyph_row->glyphs[it->area];
+       }
       if (glyph < it->glyph_row->glyphs[area + 1])
        {
          glyph->charpos = CHARPOS (it->position);
@@ -25849,17 +25870,33 @@ produce_xwidget_glyph (struct it *it)
          glyph->descent = it->descent;
          glyph->voffset = it->voffset;
          glyph->type = XWIDGET_GLYPH;
-
+         glyph->avoid_cursor_p = it->avoid_cursor_p;
          glyph->multibyte_p = it->multibyte_p;
-         glyph->left_box_line_p = it->start_of_box_run_p;
-         glyph->right_box_line_p = it->end_of_box_run_p;
-         glyph->overlaps_vertically_p = 0;
+         if (it->glyph_row->reversed_p && area == TEXT_AREA)
+           {
+             /* In R2L rows, the left and the right box edges need to be
+                drawn in reverse direction.  */
+             glyph->right_box_line_p = it->start_of_box_run_p;
+             glyph->left_box_line_p = it->end_of_box_run_p;
+           }
+         else
+           {
+             glyph->left_box_line_p = it->start_of_box_run_p;
+             glyph->right_box_line_p = it->end_of_box_run_p;
+           }
+          glyph->overlaps_vertically_p = 0;
           glyph->padding_p = 0;
          glyph->glyph_not_available_p = 0;
          glyph->face_id = it->face_id;
           glyph->u.xwidget = it->xwidget;
           //assert_valid_xwidget_id(glyph->u.xwidget_id,"produce_xwidget_glyph");
          glyph->font_type = FONT_TYPE_UNKNOWN;
+         if (it->bidi_p)
+           {
+             glyph->resolved_level = it->bidi_it.resolved_level;
+             eassert ((it->bidi_it.type & 7) == it->bidi_it.type);
+             glyph->bidi_type = it->bidi_it.type;
+           }
          ++it->glyph_row->used[area];
        }
       else
@@ -26297,7 +26334,7 @@ calc_line_height_property (struct it *it, Lisp_Object val, struct font *font,
       int face_id;
       struct face *face;
 
-      face_id = lookup_named_face (it->f, face_name, 0);
+      face_id = lookup_named_face (it->f, face_name, false);
       if (face_id < 0)
        return make_number (-1);
 
@@ -27583,7 +27620,6 @@ get_window_cursor_type (struct window *w, struct glyph *glyph, int *width,
 
 #ifdef HAVE_XWIDGETS
       if (glyph != NULL && glyph->type == XWIDGET_GLYPH){
-        //printf("attempt xwidget cursor avoidance in get_window_cursor_type\n");
         return NO_CURSOR;
       }
 #endif
@@ -29524,7 +29560,7 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y,
                                                                charpos,
                                                                0, &ignore,
                                                                glyph->face_id,
-                                                               1);
+                                                               true);
          show_mouse_face (hlinfo, DRAW_MOUSE_FACE);
 
          if (NILP (pointer))
@@ -29852,7 +29888,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
              hlinfo->mouse_face_window = window;
              hlinfo->mouse_face_face_id
                = face_at_string_position (w, object, pos, 0, &ignore,
-                                          glyph->face_id, 1);
+                                          glyph->face_id, true);
              show_mouse_face (hlinfo, DRAW_MOUSE_FACE);
              cursor = No_Cursor;
            }