>From 40a8513ac2f94130ca79a1ddfa956b5f01370282 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Thu, 7 Jul 2016 08:20:09 +0300 Subject: [PATCH 1/3] Simplify face_at_string_position and related users * src/xfaces.c (face_at_string_position): Remove 4th and 5th args, avoid call to Fnext_single_property_change because it's not actually required by the callers. * src/dispextern.h (face_at_string_position): Adjust prototype. * src/font.c (font_at): * src/xdisp.c (handle_face_prop, face_before_or_after_it_pos) (get_next_display_element, display_string, note_mouse_highlight) (note_mode_line_or_margin_highlight): Related users changed. --- src/dispextern.h | 4 ++-- src/font.c | 2 +- src/xdisp.c | 54 +++++++++++++++++------------------------------------- src/xfaces.c | 36 +++++------------------------------- 4 files changed, 25 insertions(+), 71 deletions(-) diff --git a/src/dispextern.h b/src/dispextern.h index 1325ff9..922534f 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3440,8 +3440,8 @@ int face_at_buffer_position (struct window *, ptrdiff_t, ptrdiff_t *, ptrdiff_t, bool, int); int face_for_overlay_string (struct window *, ptrdiff_t, ptrdiff_t *, ptrdiff_t, bool, Lisp_Object); -int face_at_string_position (struct window *, Lisp_Object, ptrdiff_t, ptrdiff_t, - ptrdiff_t *, enum face_id, bool); +int face_at_string_position (struct window *, Lisp_Object, ptrdiff_t, + enum face_id, bool); int merge_faces (struct frame *, Lisp_Object, int, int); int compute_char_face (struct frame *, int, Lisp_Object); void free_all_realized_faces (Lisp_Object); diff --git a/src/font.c b/src/font.c index 144ba07..2abb508 100644 --- a/src/font.c +++ b/src/font.c @@ -3747,7 +3747,7 @@ font_at (int c, ptrdiff_t pos, struct face *face, struct window *w, ptrdiff_t endptr; if (STRINGP (string)) - face_id = face_at_string_position (w, string, pos, 0, &endptr, + face_id = face_at_string_position (w, string, pos, DEFAULT_FACE_ID, false); else face_id = face_at_buffer_position (w, pos, &endptr, diff --git a/src/xdisp.c b/src/xdisp.c index d5ffb25..f7db9de 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -3907,7 +3907,6 @@ handle_face_prop (struct it *it) else { int base_face_id; - ptrdiff_t bufpos; int i; Lisp_Object from_overlay = (it->current.overlay_string_index >= 0 @@ -3936,23 +3935,18 @@ handle_face_prop (struct it *it) } if (! NILP (from_overlay)) - { - bufpos = IT_CHARPOS (*it); - /* For a string from an overlay, the base face depends - only on text properties and ignores overlays. */ - base_face_id - = face_for_overlay_string (it->w, - IT_CHARPOS (*it), - &next_stop, - (IT_CHARPOS (*it) - + TEXT_PROP_DISTANCE_LIMIT), - false, - from_overlay); - } + /* For a string from an overlay, the base face depends + only on text properties and ignores overlays. */ + base_face_id + = face_for_overlay_string (it->w, + IT_CHARPOS (*it), + &next_stop, + (IT_CHARPOS (*it) + + TEXT_PROP_DISTANCE_LIMIT), + false, + from_overlay); else { - bufpos = 0; - /* For strings from a `display' property, use the face at IT's current buffer position as the base face to merge with, so that overlay strings appear in the same face as @@ -3979,8 +3973,6 @@ handle_face_prop (struct it *it) new_face_id = face_at_string_position (it->w, it->string, IT_STRING_CHARPOS (*it), - bufpos, - &next_stop, base_face_id, false); /* Is this a start of a run of characters with box? Caveat: @@ -4046,7 +4038,7 @@ face_before_or_after_it_pos (struct it *it, bool before_p) if (STRINGP (it->string)) { - ptrdiff_t bufpos, charpos; + ptrdiff_t charpos; int base_face_id; /* No face change past the end of the string (for the case @@ -4115,19 +4107,10 @@ face_before_or_after_it_pos (struct it *it, bool before_p) } eassert (0 <= charpos && charpos <= SCHARS (it->string)); - if (it->current.overlay_string_index >= 0) - bufpos = IT_CHARPOS (*it); - else - bufpos = 0; - base_face_id = underlying_face_id (it); /* Get the face for ASCII, or unibyte. */ - face_id = face_at_string_position (it->w, - it->string, - charpos, - bufpos, - &next_check_charpos, + face_id = face_at_string_position (it->w, it->string, charpos, base_face_id, false); /* Correct the face for charsets different from ASCII. Do it @@ -7288,8 +7271,8 @@ get_next_display_element (struct it *it) { next_face_id = face_at_string_position (it->w, base_string, - CHARPOS (pos), 0, - &ignore, face_id, false); + CHARPOS (pos), + face_id, false); it->end_of_box_run_p = (FACE_FROM_ID (it->f, next_face_id)->box == FACE_NO_BOX); @@ -23991,12 +23974,11 @@ display_string (const char *string, Lisp_Object lisp_string, Lisp_Object face_st FACE_STRING, if that's given. */ if (STRINGP (face_string)) { - ptrdiff_t endptr; struct face *face; it->face_id = face_at_string_position (it->w, face_string, face_string_pos, - 0, &endptr, it->base_face_id, false); + it->base_face_id, false); face = FACE_FROM_ID (it->f, it->face_id); it->face_box_p = face->box != FACE_NO_BOX; } @@ -29898,7 +29880,7 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y, int gpos; int gseq_length; int total_pixel_width; - ptrdiff_t begpos, endpos, ignore; + ptrdiff_t begpos, endpos; int vpos, hpos; @@ -30002,7 +29984,6 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y, hlinfo->mouse_face_face_id = face_at_string_position (w, string, charpos, - 0, &ignore, glyph->face_id, true); show_mouse_face (hlinfo, DRAW_MOUSE_FACE); @@ -30318,7 +30299,6 @@ note_mouse_highlight (struct frame *f, int x, int y) /* The mouse-highlighting comes from a display string with a mouse-face. */ Lisp_Object s, e; - ptrdiff_t ignore; s = Fprevious_single_property_change (make_number (pos + 1), Qmouse_face, object, Qnil); @@ -30333,7 +30313,7 @@ note_mouse_highlight (struct frame *f, int x, int y) hlinfo->mouse_face_past_end = false; hlinfo->mouse_face_window = window; hlinfo->mouse_face_face_id - = face_at_string_position (w, object, pos, 0, &ignore, + = face_at_string_position (w, object, pos, glyph->face_id, true); show_mouse_face (hlinfo, DRAW_MOUSE_FACE); cursor = No_Cursor; diff --git a/src/xfaces.c b/src/xfaces.c index 0a1315d..6146ef5 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -6032,33 +6032,20 @@ face_for_overlay_string (struct window *w, ptrdiff_t pos, /* Compute the face at character position POS in Lisp string STRING on - window W, for ASCII characters. + window W, for ASCII characters. W must display the current buffer. - If STRING is an overlay string, it comes from position BUFPOS in - current_buffer, otherwise BUFPOS is zero to indicate that STRING is - not an overlay string. W must display the current buffer. - REGION_BEG and REGION_END give the start and end positions of the - region; both are -1 if no region is visible. - - BASE_FACE_ID is the id of a face to merge with. For strings coming - from overlays or the `display' property it is the face at BUFPOS. + BASE_FACE_ID is the id of a face to merge with. If MOUSE_P, use the character's mouse-face, not its face. - Set *ENDPTR to the next position where to check for faces in - STRING; -1 if the face is constant from POS to the end of the - string. - Value is the id of the face to use. The face returned is suitable for displaying ASCII characters. */ int -face_at_string_position (struct window *w, Lisp_Object string, - ptrdiff_t pos, ptrdiff_t bufpos, - ptrdiff_t *endptr, enum face_id base_face_id, - bool mouse_p) +face_at_string_position (struct window *w, Lisp_Object string, ptrdiff_t pos, + enum face_id base_face_id, bool mouse_p) { - Lisp_Object prop, position, end, limit; + Lisp_Object prop, position; struct frame *f = XFRAME (WINDOW_FRAME (w)); Lisp_Object attrs[LFACE_VECTOR_SIZE]; struct face *base_face; @@ -6070,19 +6057,6 @@ face_at_string_position (struct window *w, Lisp_Object string, XSETFASTINT (position, pos); prop = Fget_text_property (position, prop_name, string); - /* Get the next position at which to check for faces. Value of end - is nil if face is constant all the way to the end of the string. - Otherwise it is a string position where to check faces next. - Limit is the maximum position up to which to check for property - changes in Fnext_single_property_change. Strings are usually - short, so set the limit to the end of the string. */ - XSETFASTINT (limit, SCHARS (string)); - end = Fnext_single_property_change (position, prop_name, string, limit); - if (INTEGERP (end)) - *endptr = XFASTINT (end); - else - *endptr = -1; - base_face = FACE_FROM_ID (f, base_face_id); /* Optimize the default case that there is no face property. */ -- 2.9.0