comparison src/window.c @ 32710:cd7dca826a03

(pos_fully_visible_in_window_p): New function. (Fpos_visible_in_window_p): Add FULLY argument. Use pos_fully_visible_in_window_p. (window_scroll_pixel_based, window_scroll_line_based): Update calls to Fpos_visible_in_window_p.
author Miles Bader <miles@gnu.org>
date Sat, 21 Oct 2000 07:57:20 +0000
parents e34686f28483
children 923b8d6d8277
comparison
equal deleted inserted replaced
32709:ca8d3812cb67 32710:cd7dca826a03
288 { 288 {
289 struct window *w = decode_window (window); 289 struct window *w = decode_window (window);
290 return (MINI_WINDOW_P (w) ? Qt : Qnil); 290 return (MINI_WINDOW_P (w) ? Qt : Qnil);
291 } 291 }
292 292
293
294 /* Return true if POS is fully visible in the window W. If W's end
295 position is not known, then return false. */
296
297 static int
298 pos_fully_visible_in_window_p (pos, w)
299 int pos;
300 struct window *w;
301 {
302 struct glyph_row *first_row = &w->desired_matrix->rows[0];
303 struct glyph_row *last_row;
304
305 if (pos < first_row->start.pos.charpos)
306 /* POS is before the beginning of W. */
307 return 0;
308 else if (pos < first_row->end.pos.charpos)
309 /* POS is on the first row of W, so see if that row is fully visible. */
310 return !MATRIX_ROW_PARTIALLY_VISIBLE_P (first_row);
311
312 if (NILP (w->window_end_valid))
313 /* We can't determine where the end is, so we don't know. */
314 return 0;
315
316 last_row = &w->desired_matrix->rows[XFASTINT (w->window_end_vpos)];
317
318 if (pos < last_row->start.pos.charpos)
319 /* POS is somewhere in the middle of the window, not on the first or
320 last row, so it must be visible. */
321 return 1;
322 else if (pos >= last_row->end.pos.charpos)
323 /* POS is after the end of W. */
324 return 0;
325 else
326 /* POS is on the last row of W, so see if that row is fully visible. */
327 return !MATRIX_ROW_PARTIALLY_VISIBLE_P (last_row);
328 }
329
330
293 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p, 331 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p,
294 Spos_visible_in_window_p, 0, 2, 0, 332 Spos_visible_in_window_p, 0, 3, 0,
295 "Return t if position POS is currently on the frame in WINDOW.\n\ 333 "Return t if position POS is currently on the frame in WINDOW.\n\
296 Returns nil if that position is scrolled vertically out of view.\n\ 334 Returns nil if that position is scrolled vertically out of view.\n\
335 If FULLY is non-nil, then only return t when POS is completely visible.\n\
297 POS defaults to point; WINDOW, to the selected window.") 336 POS defaults to point; WINDOW, to the selected window.")
298 (pos, window) 337 (pos, window, fully)
299 Lisp_Object pos, window; 338 Lisp_Object pos, window, fully;
300 { 339 {
301 register struct window *w; 340 register struct window *w;
302 register int posint; 341 register int posint;
303 register struct buffer *buf; 342 register struct buffer *buf;
304 struct text_pos top; 343 struct text_pos top;
318 357
319 /* If position above window, it's not visible. */ 358 /* If position above window, it's not visible. */
320 if (posint < CHARPOS (top)) 359 if (posint < CHARPOS (top))
321 in_window = Qnil; 360 in_window = Qnil;
322 else if (XFASTINT (w->last_modified) >= BUF_MODIFF (buf) 361 else if (XFASTINT (w->last_modified) >= BUF_MODIFF (buf)
323 && XFASTINT (w->last_overlay_modified) >= BUF_OVERLAY_MODIFF (buf) 362 && XFASTINT (w->last_overlay_modified) >= BUF_OVERLAY_MODIFF (buf)
324 && posint < BUF_Z (buf) - XFASTINT (w->window_end_pos)) 363 && posint < BUF_Z (buf) - XFASTINT (w->window_end_pos))
325 /* If frame is up to date, and POSINT is < window end pos, use 364 /* If frame is up to date, and POSINT is < window end pos, use
326 that info. This doesn't work for POSINT == end pos, because 365 that info. This doesn't work for POSINT == end pos, because
327 the window end pos is actually the position _after_ the last 366 the window end pos is actually the position _after_ the last
328 char in the window. */ 367 char in the window. */
329 in_window = Qt; 368 {
369 if (NILP (fully) || pos_fully_visible_in_window_p (posint, w))
370 in_window = Qt;
371 else
372 in_window = Qnil;
373 }
330 else if (posint > BUF_ZV (buf)) 374 else if (posint > BUF_ZV (buf))
331 in_window = Qnil; 375 in_window = Qnil;
332 else if (CHARPOS (top) < BUF_BEGV (buf) || CHARPOS (top) > BUF_ZV (buf)) 376 else if (CHARPOS (top) < BUF_BEGV (buf) || CHARPOS (top) > BUF_ZV (buf))
333 /* If window start is out of range, do something reasonable. */ 377 /* If window start is out of range, do something reasonable. */
334 in_window = Qnil; 378 in_window = Qnil;
336 { 380 {
337 struct it it; 381 struct it it;
338 start_display (&it, w, top); 382 start_display (&it, w, top);
339 move_it_to (&it, posint, 0, it.last_visible_y, -1, 383 move_it_to (&it, posint, 0, it.last_visible_y, -1,
340 MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); 384 MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y);
341 in_window = IT_CHARPOS (it) == posint ? Qt : Qnil; 385 if (IT_CHARPOS (it) == posint)
386 {
387 if (NILP (fully))
388 in_window = Qt;
389 else
390 {
391 struct glyph_row *pos_row = &w->desired_matrix->rows[it.vpos];
392 return MATRIX_ROW_PARTIALLY_VISIBLE_P(pos_row) ? Qnil : Qt;
393 }
394 }
395 else
396 in_window = Qnil;
342 } 397 }
343 398
344 return in_window; 399 return in_window;
345 } 400 }
346 401
3782 SET_TEXT_POS_FROM_MARKER (start, w->start); 3837 SET_TEXT_POS_FROM_MARKER (start, w->start);
3783 3838
3784 /* If PT is not visible in WINDOW, move back one half of 3839 /* If PT is not visible in WINDOW, move back one half of
3785 the screen. */ 3840 the screen. */
3786 XSETFASTINT (tem, PT); 3841 XSETFASTINT (tem, PT);
3787 tem = Fpos_visible_in_window_p (tem, window); 3842 tem = Fpos_visible_in_window_p (tem, window, Qt);
3788 if (NILP (tem)) 3843 if (NILP (tem))
3789 { 3844 {
3790 /* Move backward half the height of the window. Performance note: 3845 /* Move backward half the height of the window. Performance note:
3791 vmotion used here is about 10% faster, but would give wrong 3846 vmotion used here is about 10% faster, but would give wrong
3792 results for variable height lines. */ 3847 results for variable height lines. */
3926 window_internal_width (w), XINT (w->hscroll), 3981 window_internal_width (w), XINT (w->hscroll),
3927 0, w); 3982 0, w);
3928 original_vpos = posit.vpos; 3983 original_vpos = posit.vpos;
3929 3984
3930 XSETFASTINT (tem, PT); 3985 XSETFASTINT (tem, PT);
3931 tem = Fpos_visible_in_window_p (tem, window); 3986 tem = Fpos_visible_in_window_p (tem, window, Qt);
3932 3987
3933 if (NILP (tem)) 3988 if (NILP (tem))
3934 { 3989 {
3935 Fvertical_motion (make_number (- (ht / 2)), window); 3990 Fvertical_motion (make_number (- (ht / 2)), window);
3936 startpos = PT; 3991 startpos = PT;