emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem of display property [Re: list-charset-chars and unicode-bmp]


From: Kenichi Handa
Subject: Re: problem of display property [Re: list-charset-chars and unicode-bmp]
Date: Wed, 29 Jan 2003 16:39:59 +0900 (JST)
User-agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/21.2.92 (sparc-sun-solaris2.6) MULE/5.0 (SAKAKI)

In article <address@hidden>, address@hidden (Gerd Moellmann) writes:
> When current glyphs are reused, their positions are adjusted for the
> changes in the buffer since the glyphs were made current.  The
> function try_window_id is one such example.  I didn't see this being
> done for the new slot you added to struct glyph.  (Insofar, the
> comment of struct glyph doesn't appear to be that devious :).)

Ah, thank you!  That explains the strange behaviour I
noticed after I applied my patch, and is fixed by adjusting
buf_charpos in increment_row_positions.  But...

> Be it as it may, I think I'd rather try to avoid enlarging struct
> glyph.  Instead, I'd try using the function string_buffer_position in
> the cursor position computation.  Strings aren't displayed frequently,
> so the additional function calls shouldn't matter, and anyway,
> enlarging glyphs costs performance too, and that in all cases.

Oops, I didn't know about string_buffer_position.  You are
right.  By using it, we can confine the change to
set_cursor_from_row as attached.  The change was not that
straight, but I think it is better than the previous one.

The reason why the change looks complicated is to correctly
handle this kind of case where string_buffer_position is
confused by the same string used in display properties.

(setq s1 "<dot>")
(setq s2 "<comma>")
(setq c1 (propertize "." 'display s1))
(setq c2 (propertize "," 'display s2))
(insert c1 c2 c1 c2 c1 c2)

Could you check the change and comment again?

---
Ken'ichi HANDA
address@hidden

*** xdisp.c.~1.729.2.12.~       Thu Nov  7 15:24:40 2002
--- xdisp.c     Wed Jan 29 15:54:27 2003
***************
*** 9369,9374 ****
--- 9369,9382 ----
  {
    struct glyph *glyph = row->glyphs[TEXT_AREA];
    struct glyph *end = glyph + row->used[TEXT_AREA];
+   /* The first glyph that starts a sequence of glyphs from string.  */
+   struct glyph *string_start;
+   /* The X coordinate of string_start.  */
+   int string_start_x;
+   /* The last known character position.  */
+   int last_pos = MATRIX_ROW_START_CHARPOS (row) + delta;
+   /* The last known character position before string_start.  */
+   int string_before_pos;
    int x = row->x;
    int pt_old = PT - delta;
  
***************
*** 9384,9396 ****
        ++glyph;
        }
  
    while (glyph < end
         && !INTEGERP (glyph->object)
         && (!BUFFERP (glyph->object)
!            || glyph->charpos < pt_old))
      {
!       x += glyph->pixel_width;
!       ++glyph;
      }
  
    w->cursor.hpos = glyph - row->glyphs[TEXT_AREA];
--- 9392,9454 ----
        ++glyph;
        }
  
+   string_start = NULL;
    while (glyph < end
         && !INTEGERP (glyph->object)
         && (!BUFFERP (glyph->object)
!            || (last_pos = glyph->charpos) < pt_old))
      {
!       if (! STRINGP (glyph->object))
!       {
!         string_start = NULL;
!         x += glyph->pixel_width;
!         ++glyph;
!       }
!       else
!       {
!         string_before_pos = last_pos;
!         string_start = glyph;
!         string_start_x = x;
!         /* Skip all glyphs from string.  */
!         do
!           {
!             x += glyph->pixel_width;
!             ++glyph;
!           }
!         while (glyph < end && STRINGP (glyph->object));
!       }
!     }
! 
!   if (string_start
!       && (glyph == end || !BUFFERP (glyph->object) || last_pos > pt_old))
!     {
!       /* We may have skipped over point because the previous glyphs
!        are from string.  As there's no easy way to know the
!        character position of the current glyph, find the correct
!        glyph on point by scanning from string_start again.  */
!       Lisp_Object pos, limit;
! 
!       limit = make_number (MATRIX_ROW_END_CHARPOS (row) + delta);
!       glyph = string_start;
!       x = string_start_x;
!       pos = make_number (string_buffer_position (w, glyph->object,
!                                                string_before_pos));
!       pos = Fnext_single_char_property_change (pos, Qdisplay, Qnil, limit);
!       while (XINT (pos) <= pt_old)
!       {
!         /* Skip glyphs from the same string.  */
!         do
!           {
!             x += glyph->pixel_width;
!             ++glyph;
!           }
!         while (glyph < end
!                && EQ (glyph->object, string_start->object));
!         if (glyph == end || !STRINGP (glyph->object))
!           break;
!         string_start = glyph;
!         pos = Fnext_single_char_property_change (pos, Qdisplay, Qnil, limit);
!       }
      }
  
    w->cursor.hpos = glyph - row->glyphs[TEXT_AREA];




reply via email to

[Prev in Thread] Current Thread [Next in Thread]