Function: move-to-window-line

move-to-window-line is an interactive function defined in window.c.

Signature

(move-to-window-line ARG)

Documentation

Position point relative to window.

ARG nil means position point at center of window. Else, ARG specifies vertical position within the window; zero means top of window, negative means relative to bottom of window, -1 meaning the last fully visible display line of the window.

Value is the screen line of the window point moved to, counting from the top of the window.

View in manual

Key Bindings

Source Code

// Defined in /usr/src/emacs/src/window.c
{
  struct window *w = XWINDOW (selected_window);
  int lines, start;
  Lisp_Object window;
#if false
  int this_scroll_margin;
#endif

  if (!(BUFFERP (w->contents) && XBUFFER (w->contents) == current_buffer))
    /* This test is needed to make sure PT/PT_BYTE make sense in w->contents
       when passed below to set_marker_both.  */
    error ("move-to-window-line called from unrelated buffer");

  window = selected_window;
  start = marker_position (w->start);
  if (start < BEGV || start > ZV)
    {
      int height = window_internal_height (w);
      Fvertical_motion (make_fixnum (- (height / 2)), window, Qnil);
      set_marker_both (w->start, w->contents, PT, PT_BYTE);
      w->start_at_line_beg = !NILP (Fbolp ());
      w->force_start = true;
    }
  else
    Fgoto_char (w->start);

  lines = displayed_window_lines (w);

  if (NILP (arg))
    XSETFASTINT (arg, lines / 2);
  else
    {
      EMACS_INT iarg = XFIXNUM (Fprefix_numeric_value (arg));

      if (iarg < 0)
	iarg = iarg + lines;

#if false /* This code would prevent move-to-window-line from moving point
	     to a place inside the scroll margins (which would cause the
	     next redisplay to scroll).  I wrote this code, but then concluded
	     it is probably better not to install it.  However, it is here
	     inside #if false so as not to lose it.  -- rms.  */

      this_scroll_margin = window_scroll_margin (w, MARGIN_IN_LINES);

      /* Don't let it get into the margin at either top or bottom.  */
      iarg = max (iarg, this_scroll_margin);
      iarg = min (iarg, lines - this_scroll_margin - 1);
#endif

      arg = make_fixnum (iarg);
    }

  /* Skip past a partially visible first line.  */
  if (w->vscroll)
    XSETINT (arg, XFIXNUM (arg) + 1);

  return Fvertical_motion (arg, window, Qnil);
}