Function: window-line-height

window-line-height is a function defined in window.c.

Signature

(window-line-height &optional LINE WINDOW)

Documentation

Return height in pixels of text line LINE in window WINDOW.

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

Return height of current line if LINE is omitted or nil. Return height of header or mode line if LINE is header-line or mode-line. Otherwise, LINE is a text line number starting from 0. A negative number counts from the end of the window.

Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height in pixels of the visible part of the line, VPOS and YPOS are the vertical position in lines and pixels of the line, relative to the top of the first text line, and OFFBOT is the number of off-window pixels at the bottom of the text line. If there are off-window pixels at the top of the (first) text line, YPOS is negative.

Return nil if window display is not up-to-date. In that case, use pos-visible-in-window-p to obtain the information.

View in manual

Probably introduced at or before Emacs version 22.1.

Source Code

// Defined in /usr/src/emacs/src/window.c
{
  register struct window *w;
  register struct buffer *b;
  struct glyph_row *row, *end_row;
  int max_y, crop, i;
  EMACS_INT n;

  w = decode_live_window (window);

  if (noninteractive || w->pseudo_window_p)
    return Qnil;

  CHECK_BUFFER (w->contents);
  b = XBUFFER (w->contents);

  /* Fail if current matrix is not up-to-date.  */
  if (!w->window_end_valid
      || windows_or_buffers_changed
      || b->clip_changed
      || b->prevent_redisplay_optimizations_p
      || window_outdated (w))
    return Qnil;

  if (NILP (line))
    {
      i = w->cursor.vpos;
      if (i < 0 || i >= w->current_matrix->nrows
	  || (row = MATRIX_ROW (w->current_matrix, i), !row->enabled_p))
	return Qnil;
      max_y = window_text_bottom_y (w);
      goto found_row;
    }

  if (EQ (line, Qtab_line))
    {
      if (!window_wants_tab_line (w))
	return Qnil;
      row = MATRIX_TAB_LINE_ROW (w->current_matrix);
      return row->enabled_p ? list4i (row->height, 0, 0, 0) : Qnil;
    }

  if (EQ (line, Qheader_line))
    {
      if (!window_wants_header_line (w))
	return Qnil;
      row = MATRIX_HEADER_LINE_ROW (w->current_matrix);
      return row->enabled_p ? list4i (row->height, 0, 0, 0) : Qnil;
    }

  if (EQ (line, Qmode_line))
    {
      row = MATRIX_MODE_LINE_ROW (w->current_matrix);
      return (row->enabled_p ?
	      list4i (row->height,
		      0, /* not accurate */
		      (WINDOW_TAB_LINE_HEIGHT (w)
		       + WINDOW_HEADER_LINE_HEIGHT (w)
		       + window_text_bottom_y (w)),
		      0)
	      : Qnil);
    }

  CHECK_FIXNUM (line);
  n = XFIXNUM (line);

  row = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
  end_row = MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w);
  max_y = window_text_bottom_y (w);
  i = 0;

  while ((n < 0 || i < n)
	 && row <= end_row && row->enabled_p
	 && row->y + row->height < max_y)
    row++, i++;

  if (row > end_row || !row->enabled_p)
    return Qnil;

  if (++n < 0)
    {
      if (-n > i)
	return Qnil;
      row += n;
      i += n;
    }

 found_row:
  crop = max (0, (row->y + row->height) - max_y);
  return list4i (row->height + min (0, row->y) - crop, i, row->y, crop);
}