if (CHARPOS (top) > ZV)
SET_TEXT_POS (top, BEGV, BEGV_BYTE);
+ /* If the top of the window is after CHARPOS, the latter is surely
+ not visible. */
+ if (charpos >= 0 && CHARPOS (top) > charpos)
+ return visible_p;
+
/* Compute exact mode line heights. */
if (WINDOW_WANTS_MODELINE_P (w))
w->mode_line_height
cache and mode line face are not yet initialized. */
if (FRAME_FACE_CACHE (f))
{
- struct face *face = FACE_OPT_FROM_ID (f, face_id);
+ struct face *face = FACE_FROM_ID_OR_NULL (f, face_id);
if (face)
{
if (face->font)
/* If we have a boxed mode line, make the first character appear
with a left box line. */
- face = FACE_OPT_FROM_ID (it->f, remapped_base_face_id);
+ face = FACE_FROM_ID_OR_NULL (it->f, remapped_base_face_id);
if (face && face->box != FACE_NO_BOX)
it->start_of_box_run_p = true;
}
{
struct face *new_face = FACE_FROM_ID (it->f, new_face_id);
/* If it->face_id is -1, old_face below will be NULL, see
- the definition of FACE_OPT_FROM_ID. This will happen if this
- is the initial call that gets the face. */
- struct face *old_face = FACE_OPT_FROM_ID (it->f, it->face_id);
+ the definition of FACE_FROM_ID_OR_NULL. This will happen
+ if this is the initial call that gets the face. */
+ struct face *old_face = FACE_FROM_ID_OR_NULL (it->f, it->face_id);
/* If the value of face_id of the iterator is -1, we have to
look in front of IT's position and see whether there is a
{
int prev_face_id = face_before_it_pos (it);
- old_face = FACE_OPT_FROM_ID (it->f, prev_face_id);
+ old_face = FACE_FROM_ID_OR_NULL (it->f, prev_face_id);
}
/* If the new face has a box, but the old face does not,
if (new_face_id != it->face_id)
{
struct face *new_face = FACE_FROM_ID (it->f, new_face_id);
- struct face *old_face = FACE_OPT_FROM_ID (it->f, it->face_id);
+ struct face *old_face = FACE_FROM_ID_OR_NULL (it->f, it->face_id);
/* If new face has a box but old face hasn't, this is the
start of a run of characters with box, i.e. it has a
break;
case GET_FROM_STRING:
{
- struct face *face = FACE_OPT_FROM_ID (it->f, it->face_id);
+ struct face *face = FACE_FROM_ID_OR_NULL (it->f, it->face_id);
/* Restore the face_box_p flag, since it could have been
overwritten by the face of the object that we just finished
|| ((IT)->cmp_it.stop_pos == (CHARPOS) \
&& composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
END_CHARPOS, (IT)->w, \
- FACE_OPT_FROM_ID ((IT)->f, (IT)->face_id), \
+ FACE_FROM_ID_OR_NULL ((IT)->f, \
+ (IT)->face_id), \
(IT)->string)))
if (it->method == GET_FROM_STRING && it->sp)
{
int face_id = underlying_face_id (it);
- struct face *face = FACE_OPT_FROM_ID (it->f, face_id);
+ struct face *face = FACE_FROM_ID_OR_NULL (it->f, face_id);
if (face)
{
/* Glyphs in the display vector could have the box face, so we
need to set the related flags in the iterator, as
appropriate. */
- this_face = FACE_OPT_FROM_ID (it->f, it->face_id);
- prev_face = FACE_OPT_FROM_ID (it->f, prev_face_id);
+ this_face = FACE_FROM_ID_OR_NULL (it->f, it->face_id);
+ prev_face = FACE_FROM_ID_OR_NULL (it->f, prev_face_id);
/* Is this character the first character of a box-face run? */
it->start_of_box_run_p = (this_face && this_face->box != FACE_NO_BOX
it->saved_face_id);
}
}
- next_face = FACE_OPT_FROM_ID (it->f, next_face_id);
+ next_face = FACE_FROM_ID_OR_NULL (it->f, next_face_id);
it->end_of_box_run_p = (this_face && this_face->box != FACE_NO_BOX
&& (!next_face
|| next_face->box == FACE_NO_BOX));
&& it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
/* If there's a line-/wrap-prefix, handle it. */
- if (it->hpos == 0 && it->method == GET_FROM_BUFFER
- && it->current_y < it->last_visible_y)
+ if (it->hpos == 0 && it->method == GET_FROM_BUFFER)
handle_line_prefix (it);
if (IT_CHARPOS (*it) < CHARPOS (this_line_min_pos))
it.last_visible_x = max_x;
/* Actually, we never want move_it_to stop at to_x. But to make
sure that move_it_in_display_line_to always moves far enough,
- we set it to INT_MAX and specify MOVE_TO_X. Also bound width
- value by X-LIMIT. */
- x = min (move_it_to (&it, end, INT_MAX, max_y, -1,
- MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y),
- max_x);
+ we set it to INT_MAX and specify MOVE_TO_X. */
+ x = move_it_to (&it, end, INT_MAX, max_y, -1,
+ MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y);
+ /* Don't return more than X-LIMIT. */
+ if (x > max_x)
+ x = max_x;
}
/* Subtract height of header-line which was counted automatically by
start_display. */
- y = min (it.current_y + it.max_ascent + it.max_descent
- - WINDOW_HEADER_LINE_HEIGHT (w),
- max_y);
+ y = it.current_y + it.max_ascent + it.max_descent
+ - WINDOW_HEADER_LINE_HEIGHT (w);
+ /* Don't return more than Y-LIMIT. */
+ if (y > max_y)
+ y = max_y;
if (EQ (mode_and_header_line, Qheader_line)
|| EQ (mode_and_header_line, Qt))
The new window start will be computed, based on W's width, starting
from the start of the continued line. It is the start of the
- screen line with the minimum distance from the old start W->start. */
+ screen line with the minimum distance from the old start W->start,
+ which is still before point (otherwise point will definitely not
+ be visible in the window). */
static bool
compute_window_start_on_continuation_line (struct window *w)
{
- struct text_pos pos, start_pos;
+ struct text_pos pos, start_pos, pos_before_pt;
bool window_start_changed_p = false;
SET_TEXT_POS_FROM_MARKER (start_pos, w->start);
reseat_at_previous_visible_line_start (&it);
/* If the line start is "too far" away from the window start,
- say it takes too much time to compute a new window start. */
- if (CHARPOS (start_pos) - IT_CHARPOS (it)
- /* PXW: Do we need upper bounds here? */
- < WINDOW_TOTAL_LINES (w) * WINDOW_TOTAL_COLS (w))
+ say it takes too much time to compute a new window start.
+ Also, give up if the line start is after point, as in that
+ case point will not be visible with any window start we
+ compute. */
+ if (IT_CHARPOS (it) <= PT
+ || (CHARPOS (start_pos) - IT_CHARPOS (it)
+ /* PXW: Do we need upper bounds here? */
+ < WINDOW_TOTAL_LINES (w) * WINDOW_TOTAL_COLS (w)))
{
int min_distance, distance;
decreased, the new window start will be < the old start.
So, we're looking for the display line start with the
minimum distance from the old window start. */
- pos = it.current.pos;
+ pos_before_pt = pos = it.current.pos;
min_distance = INFINITY;
while ((distance = eabs (CHARPOS (start_pos) - IT_CHARPOS (it))),
distance < min_distance)
{
min_distance = distance;
+ if (CHARPOS (pos) <= PT)
+ pos_before_pt = pos;
pos = it.current.pos;
if (it.line_wrap == WORD_WRAP)
{
move_it_by_lines (&it, 1);
}
+ /* It makes very little sense to make the new window start
+ after point, as point won't be visible. If that's what
+ the loop above finds, fall back on the candidate before
+ or at point that is closest to the old window start. */
+ if (CHARPOS (pos) > PT)
+ pos = pos_before_pt;
+
/* Set the window start there. */
SET_MARKER_FROM_TEXT_POS (w->start, pos);
window_start_changed_p = true;
return;
/* The default face, possibly remapped. */
- default_face = FACE_OPT_FROM_ID (f, lookup_basic_face (f, DEFAULT_FACE_ID));
+ default_face = FACE_FROM_ID_OR_NULL (f,
+ lookup_basic_face (f, DEFAULT_FACE_ID));
/* Face extension extends the background and box of IT->face_id
to the end of the line. If the background equals the background
of the frame, we don't have to do anything. */
- face = FACE_OPT_FROM_ID (f, (it->face_before_selective_p
- ? it->saved_face_id
- : it->face_id));
+ face = FACE_FROM_ID (f, (it->face_before_selective_p
+ ? it->saved_face_id
+ : it->face_id));
if (FRAME_WINDOW_P (f)
&& MATRIX_ROW_DISPLAYS_TEXT_P (it->glyph_row)
s->cmp_id = glyph->u.cmp.id;
s->cmp_from = glyph->slice.cmp.from;
s->cmp_to = glyph->slice.cmp.to + 1;
- s->face = FACE_OPT_FROM_ID (s->f, face_id);
+ s->face = FACE_FROM_ID (s->f, face_id);
lgstring = composition_gstring_from_id (s->cmp_id);
s->font = XFONT_OBJECT (LGSTRING_FONT (lgstring));
glyph++;
#define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
do { \
int face_id = (row)->glyphs[area][START].face_id; \
- struct face *base_face = FACE_OPT_FROM_ID (f, face_id); \
+ struct face *base_face = FACE_FROM_ID (f, face_id); \
ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
struct composition *cmp = composition_table[cmp_id]; \
XChar2b *char2b; \
struct face *face;
face_id = lookup_named_face (it->f, face_name, false);
- if (face_id < 0)
- return make_number (-1);
-
- face = FACE_FROM_ID (it->f, face_id);
- font = face->font;
- if (font == NULL)
+ face = FACE_FROM_ID_OR_NULL (it->f, face_id);
+ if (face == NULL || ((font = face->font) == NULL))
return make_number (-1);
boff = font->baseline_offset;
if (font->vertical_centering)