>From c482a125a9bc0f0fcf1763be9d340ec8f164ed10 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Thu, 7 Jul 2016 09:42:06 +0300 Subject: [PATCH 3/3] Simplify face_at_buffer_position and related users * src/xfaces.c (face_at_buffer_position): Remove 3rd arg, avoid call to Fnext_single_property_change because it's not actually required by the callers. * src/dispextern.h (face_at_buffer_position): Adjust prototype. * src/font.c (font_at, font_range, Finternal_char_font): * src/xdisp.c (handle_face_prop, face_before_or_after_it_pos) (get_next_display_element, mouse_face_from_buffer_pos): Related users changed. --- src/dispextern.h | 3 +-- src/font.c | 13 ++++--------- src/xdisp.c | 18 +++++------------- src/xfaces.c | 35 +++-------------------------------- 4 files changed, 13 insertions(+), 56 deletions(-) diff --git a/src/dispextern.h b/src/dispextern.h index bf44cd0..d8ca923 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3436,8 +3436,7 @@ int lookup_derived_face (struct frame *, Lisp_Object, int, bool); void init_frame_faces (struct frame *); void free_frame_faces (struct frame *); void recompute_basic_faces (struct frame *); -int face_at_buffer_position (struct window *, ptrdiff_t, ptrdiff_t *, ptrdiff_t, - bool, int); +int face_at_buffer_position (struct window *, ptrdiff_t, ptrdiff_t, bool, int); int face_for_overlay_string (struct window *, ptrdiff_t, bool, Lisp_Object); int face_at_string_position (struct window *, Lisp_Object, ptrdiff_t, enum face_id, bool); diff --git a/src/font.c b/src/font.c index 2abb508..17d1518 100644 --- a/src/font.c +++ b/src/font.c @@ -3744,14 +3744,12 @@ font_at (int c, ptrdiff_t pos, struct face *face, struct window *w, if (! face) { int face_id; - ptrdiff_t endptr; if (STRINGP (string)) face_id = face_at_string_position (w, string, pos, DEFAULT_FACE_ID, false); else - face_id = face_at_buffer_position (w, pos, &endptr, - pos + 100, false, -1); + face_id = face_at_buffer_position (w, pos, pos + 100, false, -1); face = FACE_FROM_ID (f, face_id); } if (multibyte) @@ -3784,7 +3782,6 @@ Lisp_Object font_range (ptrdiff_t pos, ptrdiff_t pos_byte, ptrdiff_t *limit, struct window *w, struct face *face, Lisp_Object string) { - ptrdiff_t ignore; int c; Lisp_Object font_object = Qnil; @@ -3794,8 +3791,7 @@ font_range (ptrdiff_t pos, ptrdiff_t pos_byte, ptrdiff_t *limit, { int face_id; - face_id = face_at_buffer_position (w, pos, &ignore, - *limit, false, -1); + face_id = face_at_buffer_position (w, pos, *limit, false, -1); face = FACE_FROM_ID (XFRAME (w->frame), face_id); } } @@ -4533,7 +4529,7 @@ DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 2, 0, doc: /* For internal use only. */) (Lisp_Object position, Lisp_Object ch) { - ptrdiff_t pos, pos_byte, dummy; + ptrdiff_t pos, pos_byte; int face_id; int c; struct frame *f; @@ -4568,8 +4564,7 @@ DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 2, 0, return Qnil; w = XWINDOW (window); f = XFRAME (w->frame); - face_id = face_at_buffer_position (w, pos, &dummy, - pos + 100, false, -1); + face_id = face_at_buffer_position (w, pos, pos + 100, false, -1); } if (! CHAR_VALID_P (c)) return Qnil; diff --git a/src/xdisp.c b/src/xdisp.c index 790709e..ac7f3d2 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -3860,14 +3860,11 @@ static enum prop_handled handle_face_prop (struct it *it) { int new_face_id; - ptrdiff_t next_stop; if (!STRINGP (it->string)) { new_face_id - = face_at_buffer_position (it->w, - IT_CHARPOS (*it), - &next_stop, + = face_at_buffer_position (it->w, IT_CHARPOS (*it), (IT_CHARPOS (*it) + TEXT_PROP_DISTANCE_LIMIT), false, it->base_face_id); @@ -4025,7 +4022,6 @@ static int face_before_or_after_it_pos (struct it *it, bool before_p) { int face_id, limit; - ptrdiff_t next_check_charpos; struct it it_copy; void *it_copy_data = NULL; @@ -4197,9 +4193,7 @@ face_before_or_after_it_pos (struct it *it, bool before_p) eassert (BEGV <= CHARPOS (pos) && CHARPOS (pos) <= ZV); /* Determine face for CHARSET_ASCII, or unibyte. */ - face_id = face_at_buffer_position (it->w, - CHARPOS (pos), - &next_check_charpos, + face_id = face_at_buffer_position (it->w, CHARPOS (pos), limit, false, -1); /* Correct the face for charsets different from ASCII. Do it @@ -7214,7 +7208,6 @@ get_next_display_element (struct it *it) /* A string from display property. */ || it->from_disp_prop_p)) { - ptrdiff_t ignore; int next_face_id; bool text_from_string = false; /* Normally, the next buffer location is stored in @@ -7278,7 +7271,7 @@ get_next_display_element (struct it *it) else { next_face_id = - face_at_buffer_position (it->w, CHARPOS (pos), &ignore, + face_at_buffer_position (it->w, CHARPOS (pos), CHARPOS (pos) + TEXT_PROP_DISTANCE_LIMIT, false, -1); @@ -28985,7 +28978,7 @@ mouse_face_from_buffer_pos (Lisp_Object window, struct glyph_row *first = MATRIX_FIRST_TEXT_ROW (w->current_matrix); struct glyph_row *r1, *r2; struct glyph *glyph, *end; - ptrdiff_t ignore, pos; + ptrdiff_t pos; int x; eassert (NILP (disp_string) || STRINGP (disp_string)); @@ -29288,8 +29281,7 @@ mouse_face_from_buffer_pos (Lisp_Object window, hlinfo->mouse_face_window = window; hlinfo->mouse_face_face_id - = face_at_buffer_position (w, mouse_charpos, &ignore, - mouse_charpos + 1, + = face_at_buffer_position (w, mouse_charpos, mouse_charpos + 1, !hlinfo->mouse_face_hidden, -1); show_mouse_face (hlinfo, DRAW_MOUSE_FACE); } diff --git a/src/xfaces.c b/src/xfaces.c index 41a45cf..c401b7a 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -5858,13 +5858,8 @@ compute_char_face (struct frame *f, int ch, Lisp_Object prop) return face_id; } -/* Return the face ID associated with buffer position POS for - displaying ASCII characters. Return in *ENDPTR the position at - which a different face is needed, as far as text properties and - overlays are concerned. W is a window displaying current_buffer. - - REGION_BEG, REGION_END delimit the region, so it can be - highlighted. +/* Return the face ID associated with buffer position POS for displaying + ASCII characters. W is a window displaying current_buffer. LIMIT is a position not to scan beyond. That is to limit the time this function can take. @@ -5877,8 +5872,7 @@ compute_char_face (struct frame *f, int ch, Lisp_Object prop) The face returned is suitable for displaying ASCII characters. */ int -face_at_buffer_position (struct window *w, ptrdiff_t pos, - ptrdiff_t *endptr, ptrdiff_t limit, +face_at_buffer_position (struct window *w, ptrdiff_t pos, ptrdiff_t limit, bool mouse, int base_face_id) { struct frame *f = XFRAME (w->frame); @@ -5886,26 +5880,17 @@ face_at_buffer_position (struct window *w, ptrdiff_t pos, Lisp_Object prop, position; ptrdiff_t i, noverlays; Lisp_Object *overlay_vec; - ptrdiff_t endpos; Lisp_Object propname = mouse ? Qmouse_face : Qface; - Lisp_Object limit1, end; struct face *default_face; /* W must display the current buffer. We could write this function to use the frame and buffer of W, but right now it doesn't. */ - /* eassert (XBUFFER (w->contents) == current_buffer); */ XSETFASTINT (position, pos); - endpos = ZV; - /* Get the `face' or `mouse_face' text property at POS, and determine the next position at which the property changes. */ prop = Fget_text_property (position, propname, w->contents); - XSETFASTINT (limit1, (limit < endpos ? limit : endpos)); - end = Fnext_single_property_change (position, propname, w->contents, limit1); - if (INTEGERP (end)) - endpos = XINT (end); /* Look at properties from overlays. */ USE_SAFE_ALLOCA; @@ -5913,12 +5898,8 @@ face_at_buffer_position (struct window *w, ptrdiff_t pos, ptrdiff_t next_overlay; GET_OVERLAYS_AT (pos, overlay_vec, noverlays, &next_overlay, false); - if (next_overlay < endpos) - endpos = next_overlay; } - *endptr = endpos; - { int face_id; @@ -5951,21 +5932,11 @@ face_at_buffer_position (struct window *w, ptrdiff_t pos, noverlays = sort_overlays (overlay_vec, noverlays, w); for (i = 0; i < noverlays; i++) { - Lisp_Object oend; - ptrdiff_t oendpos; - prop = Foverlay_get (overlay_vec[i], propname); if (!NILP (prop)) merge_face_ref (f, prop, attrs, true, 0); - - oend = OVERLAY_END (overlay_vec[i]); - oendpos = OVERLAY_POSITION (oend); - if (oendpos < endpos) - endpos = oendpos; } - *endptr = endpos; - SAFE_FREE (); /* Look up a realized face with the given face attributes, -- 2.9.0