Each window maintains a marker used to keep track of a buffer position that specifies where in the buffer display should start. This position is called the display-start position of the window (or just the start). The character after this position is the one that appears at the upper left corner of the window. It is usually, but not inevitably, at the beginning of a text line.
After switching windows or buffers, and in some other cases, if the window start is in the middle of a line, Emacs adjusts the window start to the start of a line. This prevents certain operations from leaving the window start at a meaningless point within a line. This feature may interfere with testing some Lisp code by executing it using the commands of Lisp mode, because they trigger this readjustment. To test such code, put it into a command and bind the command to a key.
When you create a window, or display a different buffer in it, the display-start position is set to a display-start position recently used for the same buffer, or to
point-minif the buffer doesn't have any.
Redisplay updates the window-start position (if you have not specified it explicitly since the previous redisplay)—to make sure point appears on the screen. Nothing except redisplay automatically changes the window-start position; if you move point, do not expect the window-start position to change in response until after the next redisplay.
This function returns the position where display of its buffer ends in window. The default for window is the selected window.
Simply changing the buffer text or moving point does not update the value that
window-endreturns. The value is updated only when Emacs redisplays and redisplay completes without being preempted.
If the last redisplay of window was preempted, and did not finish, Emacs does not know the position of the end of display in that window. In that case, this function returns
If update is non-
window-endalways returns an up-to-date value for where display ends, based on the current
window-startvalue. If a previously saved value of that position is still valid,
window-endreturns that value; otherwise it computes the correct value by scanning the buffer text.
Even if update is non-
window-enddoes not attempt to scroll the display if point has moved off the screen, the way real redisplay would do. It does not alter the
window-startvalue. In effect, it reports where the displayed text will end if scrolling is not required.
This function sets the display-start position of window to position in window's buffer. It returns position.
The display routines insist that the position of point be visible when a buffer is displayed. Normally, they change the display-start position (that is, scroll the window) whenever necessary to make point visible. However, if you specify the start position with this function using
nilfor noforce, it means you want display to start at position even if that would put the location of point off the screen. If this does place point off screen, the display routines move point to the left margin on the middle line in the window.
For example, if point is 1 and you set the start of the window to 37, the start of the next line, point will be “above” the top of the window. The display routines will automatically move point if it is still 1 when redisplay occurs. Here is an example:;; Here is what ‘foo’ looks like before executing ;; the
set-window-startexpression. ---------- Buffer: foo ---------- -!-This is the contents of buffer foo. 2 3 4 5 6 ---------- Buffer: foo ---------- (set-window-start (selected-window) (save-excursion (goto-char 1) (forward-line 1) (point))) ⇒ 37 ;; Here is what ‘foo’ looks like after executing ;; the
set-window-startexpression. ---------- Buffer: foo ---------- 2 3 -!-4 5 6 ---------- Buffer: foo ----------
If noforce is non-
nil, and position would place point off screen at the next redisplay, then redisplay computes a new window-start position that works well with point, and thus position is not used.
This function returns non-
nilif position is within the range of text currently visible on the screen in window. It returns
nilif position is scrolled vertically out of view. Locations that are partially obscured are not considered visible unless partially is non-
nil. The argument position defaults to the current position of point in window; window, to the selected window. If position is
t, that means to check the last visible position in window.
This function considers only vertical scrolling. If position is out of view only because window has been scrolled horizontally,
nilanyway. See Horizontal Scrolling.
If position is visible,
tif partially is
nil; if partially is non-
nil, and the character following position is fully visible, it returns a list of the form
), where x and y are the pixel coordinates relative to the top left corner of the window; otherwise it returns an extended list of the form
(x y rtop rbot rowh vpos
), where rtop and rbot specify the number of off-window pixels at the top and bottom of the row at position, rowh specifies the visible height of that row, and vpos specifies the vertical position (zero-based row number) of that row.
Here is an example:;; If point is off the screen now, recenter it now. (or (pos-visible-in-window-p (point) (selected-window)) (recenter 0))
This function returns the height of text line line in window. If line is one of
window-line-heightreturns information about the corresponding line of the window. Otherwise, line is a text line number starting from 0. A negative number counts from the end of the window. The default for line is the current line in window; the default for window is the selected window.
If the display is not up to date,
nil. In that case,
pos-visible-in-window-pmay be used to obtain related information.
If there is no line corresponding to the specified line,
nil. Otherwise, it returns 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.