Function: pos-visible-in-window-p

pos-visible-in-window-p is a function defined in window.c.

Signature

(pos-visible-in-window-p &optional POS WINDOW PARTIALLY)

Documentation

Return non-nil if position POS is currently on the frame in WINDOW.

WINDOW must be a live window and defaults to the selected one.

Return nil if that position is scrolled vertically out of view. If a character is only partially visible, nil is returned, unless the optional argument PARTIALLY is non-nil. If POS is only out of view because of horizontal scrolling, return non-nil. If POS is t, it specifies either the first position displayed on the last visible screen line in WINDOW, or the end-of-buffer position, whichever comes first. POS defaults to point in WINDOW; WINDOW defaults to the selected window.

If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil, the return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]), where X and Y are the pixel coordinates relative to the top left corner of the window. The remaining elements are omitted if the character after POS is fully visible; otherwise, RTOP and RBOT are the number of pixels off-window at the top and bottom of the screen line ("row") containing POS, ROWH is the visible height of that row, and VPOS is the row number
(zero-based).

View in manual

Probably introduced at or before Emacs version 1.1.

Source Code

// Defined in /usr/src/emacs/src/window.c
{
  struct window *w;
  EMACS_INT posint;
  struct buffer *buf;
  struct text_pos top;
  Lisp_Object in_window = Qnil;
  int rtop, rbot, rowh, vpos;
  bool fully_p = true;
  int x, y;

  w = decode_live_window (window);
  buf = XBUFFER (w->contents);
  SET_TEXT_POS_FROM_MARKER (top, w->start);

  if (EQ (pos, Qt))
    posint = -1;
  else if (!NILP (pos))
    posint = fix_position (pos);
  else if (w == XWINDOW (selected_window))
    posint = PT;
  else
    posint = marker_position (w->pointm);

  /* If position is above window start or outside buffer boundaries,
     or if window start is out of range, position is not visible.  */
  if ((EQ (pos, Qt)
       || (posint >= CHARPOS (top) && posint <= BUF_ZV (buf)))
      && CHARPOS (top) >= BUF_BEGV (buf)
      && CHARPOS (top) <= BUF_ZV (buf)
      && pos_visible_p (w, posint, &x, &y, &rtop, &rbot, &rowh, &vpos))
    {
      fully_p = !rtop && !rbot;
      if (!NILP (partially) || fully_p)
	in_window = Qt;
    }

  if (!NILP (in_window) && !NILP (partially))
    {
      Lisp_Object part = Qnil;
      if (!fully_p)
	part = list4i (rtop, rbot, rowh, vpos);
      in_window = Fcons (make_fixnum (x),
			 Fcons (make_fixnum (y), part));
    }

  return in_window;
}