Skip to content

Windows and Point ​

Each window has its own value of point (see Point), independent of the value of point in other windows displaying the same buffer. This makes it useful to have multiple windows showing one buffer.

  • Window point is established when a window is first created; it is initialized from the buffer’s point, or from window point of another window opened on the buffer if such a window exists.
  • Selecting a window sets the value of point in its buffer from the window’s value of point. Conversely, deselecting a window sets the window’s value of point from that of the buffer. Thus, when you switch between windows that display a given buffer, the point value for the selected window is in effect in the buffer, while the point values for the other windows are stored in those windows.
  • As long as the selected window displays the current buffer, the window’s point and the buffer’s point always move together; they remain equal.
  • Many Emacs functions temporarily select a window in order to operate on its contents. This will move point (see Point) of that window’s buffer to the position of window point of that window and not restore buffer point to its previous position when terminating the temporary selection. This means that when one and the same buffer is simultaneously displayed in more than one window, its buffer point may change in unpredictable ways to the position of window point of any of these windows as a side-effect of things like redisplay, calling with-selected-window (see Selecting Windows) or running window-configuration-change-hook (see Hooks for Window Scrolling and Changes).

Emacs displays the cursor, by default as a rectangular block, in each window at the position of that window’s point. When the user switches to another buffer in a window, Emacs moves that window’s cursor to where point is in that buffer. If the exact position of point is hidden behind some display element, such as a display string or an image, Emacs displays the cursor immediately before or after that display element.

Function: window-point &optional window ​

This function returns the current position of point in window. For a nonselected window, this is the value point would have (in that window’s buffer) if that window were selected. The default for window is the selected window.

When window is the selected window, the value returned is the value of point in that window’s buffer. Strictly speaking, it would be more correct to return the top-level value of point, outside of any save-excursion forms. But that value is hard to find.

Function: set-window-point window position ​

This function positions point in window at position position in window’s buffer. It returns position.

If window is selected, this simply does goto-char in window’s buffer.

Variable: window-point-insertion-type ​

This variable specifies the marker insertion type (see Marker Insertion Types) of window-point. The default is nil, so window-point will stay behind text inserted there.

Function: set-window-cursor-type window type ​

This function sets the cursor shape for window. This setting takes precedence over the cursor-type variable, and type has the same format as the value of that variable. See Cursor Parameters. If window is nil, it means to set the cursor type for the selected window.

The initial value for new windows is t, which says to respect the buffer-local value of cursor-type. The value set by this function persists across buffers shown in window, so set-window-buffer does not reset it. See Buffers and Windows.

Function: window-cursor-type &optional window ​

This function returns the cursor type of window, defaulting to the selected window.

Function: window-cursor-info &optional window ​

This function returns information about the cursor of window, defaulting to the selected window.

The value returned by the function is a vector of the form [type x y width height ascent]. Here’s the description of each components of this vector:

type ​

The type of the cursor, a symbol. This is the same value returned by window-cursor-type.

x ​

y ​

The pixel coordinates of the cursor’s top-left corner, relative to the top-left corner of window’s text area.

width ​

height ​

The pixel dimensions of the cursor.

ascent ​

The number of pixels the cursor extends above the baseline.

If the cursor is not currently displayed for window, this function returns nil.

Any element except the first one in the returned vector may be -1, meaning the actual value is currently unavailable.