(xref-collect-matches): Use '-E' together with '-e'
[emacs.git] / doc / lispref / windows.texi
blob6f3de0c8a0e3b44dea2fce1dc8051ae16c0490be
1 @c -*-texinfo-*-
2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 1990-1995, 1998-1999, 2001-2017 Free Software
4 @c Foundation, Inc.
5 @c See the file elisp.texi for copying conditions.
6 @node Windows
7 @chapter Windows
9 This chapter describes the functions and variables related to Emacs
10 windows.  @xref{Frames}, for how windows are assigned an area of screen
11 available for Emacs to use.  @xref{Display}, for information on how text
12 is displayed in windows.
14 @menu
15 * Basic Windows::           Basic information on using windows.
16 * Windows and Frames::      Relating windows to the frame they appear on.
17 * Window Sizes::            Accessing a window's size.
18 * Resizing Windows::        Changing the sizes of windows.
19 * Preserving Window Sizes:: Preserving the size of windows.
20 * Splitting Windows::       Creating a new window.
21 * Deleting Windows::        Removing a window from its frame.
22 * Recombining Windows::     Preserving the frame layout when splitting and
23                               deleting windows.
24 * Selecting Windows::       The selected window is the one that you edit in.
25 * Cyclic Window Ordering::  Moving around the existing windows.
26 * Buffers and Windows::     Each window displays the contents of a buffer.
27 * Switching Buffers::       Higher-level functions for switching to a buffer.
28 * Choosing Window::         How to choose a window for displaying a buffer.
29 * Display Action Functions:: Subroutines for @code{display-buffer}.
30 * Choosing Window Options:: Extra options affecting how buffers are displayed.
31 * Window History::          Each window remembers the buffers displayed in it.
32 * Dedicated Windows::       How to avoid displaying another buffer in
33                               a specific window.
34 * Quitting Windows::        How to restore the state prior to displaying a
35                               buffer.
36 * Side Windows::            Special windows on a frame's sides.
37 * Atomic Windows::          Preserving parts of the window layout.
38 * Window Point::            Each window has its own location of point.
39 * Window Start and End::    Buffer positions indicating which text is
40                               on-screen in a window.
41 * Textual Scrolling::       Moving text up and down through the window.
42 * Vertical Scrolling::      Moving the contents up and down on the window.
43 * Horizontal Scrolling::    Moving the contents sideways on the window.
44 * Coordinates and Windows:: Converting coordinates to windows.
45 * Window Configurations::   Saving and restoring the state of the screen.
46 * Window Parameters::       Associating additional information with windows.
47 * Window Hooks::            Hooks for scrolling, window size changes,
48                               redisplay going past a certain point,
49                               or window configuration changes.
50 @end menu
53 @node Basic Windows
54 @section Basic Concepts of Emacs Windows
55 @cindex window
57 A @dfn{window} is an area of the screen that is used to display a buffer
58 (@pxref{Buffers}).  In Emacs Lisp, windows are represented by a special
59 Lisp object type.
61 @cindex multiple windows
62   Windows are grouped into frames (@pxref{Frames}).  Each frame
63 contains at least one window; the user can subdivide it into multiple,
64 non-overlapping windows to view several buffers at once.  Lisp
65 programs can use multiple windows for a variety of purposes.  In
66 Rmail, for example, you can view a summary of message titles in one
67 window, and the contents of the selected message in another window.
69 @cindex terminal screen
70 @cindex screen of terminal
71   Emacs uses the word ``window'' with a different meaning than in
72 graphical desktop environments and window systems, such as the X
73 Window System.  When Emacs is run on X, each of its graphical X
74 windows is an Emacs frame (containing one or more Emacs windows).
75 When Emacs is run on a text terminal, the frame fills the entire
76 terminal screen.
78 @cindex tiled windows
79   Unlike X windows, Emacs windows are @dfn{tiled}; they never overlap
80 within the area of the frame.  When a window is created, resized, or
81 deleted, the change in window space is taken from or given to the
82 adjacent windows, so that the total area of the frame is unchanged.
84 @defun windowp object
85 This function returns @code{t} if @var{object} is a window (whether or
86 not it displays a buffer).  Otherwise, it returns @code{nil}.
87 @end defun
89 @cindex live windows
90 A @dfn{live window} is one that is actually displaying a buffer in a
91 frame.
93 @defun window-live-p object
94 This function returns @code{t} if @var{object} is a live window and
95 @code{nil} otherwise.  A live window is one that displays a buffer.
96 @end defun
98 @cindex internal windows
99 The windows in each frame are organized into a @dfn{window tree}.
100 @xref{Windows and Frames}.  The leaf nodes of each window tree are live
101 windows---the ones actually displaying buffers.  The internal nodes of
102 the window tree are @dfn{internal windows}, which are not live.
104 @cindex valid windows
105    A @dfn{valid window} is one that is either live or internal.  A valid
106 window can be @dfn{deleted}, i.e., removed from its frame
107 (@pxref{Deleting Windows}); then it is no longer valid, but the Lisp
108 object representing it might be still referenced from other Lisp
109 objects.  A deleted window may be made valid again by restoring a saved
110 window configuration (@pxref{Window Configurations}).
112    You can distinguish valid windows from deleted windows with
113 @code{window-valid-p}.
115 @defun window-valid-p object
116 This function returns @code{t} if @var{object} is a live window, or an
117 internal window in a window tree.  Otherwise, it returns @code{nil},
118 including for the case where @var{object} is a deleted window.
119 @end defun
121 @cindex selected window
122 @cindex window selected within a frame
123   In each frame, at any time, exactly one Emacs window is designated
124 as @dfn{selected within the frame}.  For the selected frame, that
125 window is called the @dfn{selected window}---the one in which most
126 editing takes place, and in which the cursor for selected windows
127 appears (@pxref{Cursor Parameters}).  The selected window's buffer is
128 usually also the current buffer, except when @code{set-buffer} has
129 been used (@pxref{Current Buffer}).  As for non-selected frames, the
130 window selected within the frame becomes the selected window if the
131 frame is ever selected.  @xref{Selecting Windows}.
133 @defun selected-window
134 This function returns the selected window (which is always a live
135 window).
136 @end defun
138 @anchor{Window Group}Sometimes several windows collectively and
139 cooperatively display a buffer, for example, under the management of
140 Follow Mode (@pxref{Follow Mode,,, emacs}), where the windows together
141 display a bigger portion of the buffer than one window could alone.
142 It is often useful to consider such a @dfn{window group} as a single
143 entity.  Several functions such as @code{window-group-start}
144 (@pxref{Window Start and End}) allow you to do this by supplying, as
145 an argument, one of the windows as a stand in for the whole group.
147 @defun selected-window-group
148 @vindex selected-window-group-function
149 When the selected window is a member of a group of windows, this
150 function returns a list of the windows in the group, ordered such that
151 the first window in the list is displaying the earliest part of the
152 buffer, and so on.  Otherwise the function returns a list containing
153 just the selected window.
155 The selected window is considered part of a group when the buffer
156 local variable @code{selected-window-group-function} is set to a
157 function.  In this case, @code{selected-window-group} calls it with no
158 arguments and returns its result (which should be the list of windows
159 in the group).
160 @end defun
162 @node Windows and Frames
163 @section Windows and Frames
165 Each window belongs to exactly one frame (@pxref{Frames}).
167 @defun window-frame &optional window
168 This function returns the frame that the window @var{window} belongs
169 to.  If @var{window} is @code{nil}, it defaults to the selected
170 window.
171 @end defun
173 @defun window-list &optional frame minibuffer window
174 This function returns a list of live windows belonging to the frame
175 @var{frame}.  If @var{frame} is omitted or @code{nil}, it defaults to
176 the selected frame.
178 The optional argument @var{minibuffer} specifies whether to include
179 the minibuffer window in the returned list.  If @var{minibuffer} is
180 @code{t}, the minibuffer window is included.  If @var{minibuffer} is
181 @code{nil} or omitted, the minibuffer window is included only if it is
182 active.  If @var{minibuffer} is neither @code{nil} nor @code{t}, the
183 minibuffer window is never included.
185 The optional argument @var{window}, if non-@code{nil}, should be a live
186 window on the specified frame; then @var{window} will be the first
187 element in the returned list.  If @var{window} is omitted or @code{nil},
188 the window selected within the frame is the first element.
189 @end defun
191 @cindex window tree
192 @cindex root window
193   Windows in the same frame are organized into a @dfn{window tree},
194 whose leaf nodes are the live windows.  The internal nodes of a window
195 tree are not live; they exist for the purpose of organizing the
196 relationships between live windows.  The root node of a window tree is
197 called the @dfn{root window}.  It can be either a live window (if the
198 frame has just one window), or an internal window.
200   A minibuffer window (@pxref{Minibuffer Windows}) is not part of its
201 frame's window tree unless the frame is a minibuffer-only frame.
202 Nonetheless, most of the functions in this section accept the
203 minibuffer window as an argument.  Also, the function
204 @code{window-tree} described at the end of this section lists the
205 minibuffer window alongside the actual window tree.
207 @defun frame-root-window &optional frame-or-window
208 This function returns the root window for @var{frame-or-window}.  The
209 argument @var{frame-or-window} should be either a window or a frame;
210 if omitted or @code{nil}, it defaults to the selected frame.  If
211 @var{frame-or-window} is a window, the return value is the root window
212 of that window's frame.
213 @end defun
215 @cindex parent window
216 @cindex child window
217 @cindex sibling window
218   When a window is split, there are two live windows where previously
219 there was one.  One of these is represented by the same Lisp window
220 object as the original window, and the other is represented by a
221 newly-created Lisp window object.  Both of these live windows become
222 leaf nodes of the window tree, as @dfn{child windows} of a single
223 internal window.  If necessary, Emacs automatically creates this
224 internal window, which is also called the @dfn{parent window}, and
225 assigns it to the appropriate position in the window tree.  A set of
226 windows that share the same parent are called @dfn{siblings}.
228 @cindex parent window
229 @defun window-parent &optional window
230 This function returns the parent window of @var{window}.  If
231 @var{window} is omitted or @code{nil}, it defaults to the selected
232 window.  The return value is @code{nil} if @var{window} has no parent
233 (i.e., it is a minibuffer window or the root window of its frame).
234 @end defun
236   Each internal window always has at least two child windows.  If this
237 number falls to one as a result of window deletion, Emacs
238 automatically deletes the internal window, and its sole remaining
239 child window takes its place in the window tree.
241   Each child window can be either a live window, or an internal window
242 (which in turn would have its own child windows).  Therefore, each
243 internal window can be thought of as occupying a certain rectangular
244 @dfn{screen area}---the union of the areas occupied by the live
245 windows that are ultimately descended from it.
247 @cindex window combination
248 @cindex vertical combination
249 @cindex horizontal combination
250   For each internal window, the screen areas of the immediate children
251 are arranged either vertically or horizontally (never both).  If the
252 child windows are arranged one above the other, they are said to form
253 a @dfn{vertical combination}; if they are arranged side by side, they
254 are said to form a @dfn{horizontal combination}.  Consider the
255 following example:
257 @smallexample
258 @group
259      ______________________________________
260     | ______  ____________________________ |
261     ||      || __________________________ ||
262     ||      |||                          |||
263     ||      |||                          |||
264     ||      |||                          |||
265     ||      |||____________W4____________|||
266     ||      || __________________________ ||
267     ||      |||                          |||
268     ||      |||                          |||
269     ||      |||____________W5____________|||
270     ||__W2__||_____________W3_____________ |
271     |__________________W1__________________|
273 @end group
274 @end smallexample
276 @noindent
277 The root window of this frame is an internal window, @var{W1}.  Its
278 child windows form a horizontal combination, consisting of the live
279 window @var{W2} and the internal window @var{W3}.  The child windows
280 of @var{W3} form a vertical combination, consisting of the live
281 windows @var{W4} and @var{W5}.  Hence, the live windows in this
282 window tree are @var{W2}, @var{W4}, and @var{W5}.
284   The following functions can be used to retrieve a child window of an
285 internal window, and the siblings of a child window.
287 @defun window-top-child &optional window
288 This function returns the topmost child window of @var{window}, if
289 @var{window} is an internal window whose children form a vertical
290 combination.  For any other type of window, the return value is
291 @code{nil}.
292 @end defun
294 @defun window-left-child &optional window
295 This function returns the leftmost child window of @var{window}, if
296 @var{window} is an internal window whose children form a horizontal
297 combination.  For any other type of window, the return value is
298 @code{nil}.
299 @end defun
301 @defun window-child window
302 This function returns the first child window of the internal window
303 @var{window}---the topmost child window for a vertical combination, or
304 the leftmost child window for a horizontal combination.  If
305 @var{window} is a live window, the return value is @code{nil}.
306 @end defun
308 @defun window-combined-p &optional window horizontal
309 This function returns a non-@code{nil} value if and only if
310 @var{window} is part of a vertical combination.  If @var{window} is
311 omitted or @code{nil}, it defaults to the selected one.
313 If the optional argument @var{horizontal} is non-@code{nil}, this
314 means to return non-@code{nil} if and only if @var{window} is part of
315 a horizontal combination.
316 @end defun
318 @defun window-next-sibling &optional window
319 This function returns the next sibling of the window @var{window}.  If
320 omitted or @code{nil}, @var{window} defaults to the selected window.
321 The return value is @code{nil} if @var{window} is the last child of
322 its parent.
323 @end defun
325 @defun window-prev-sibling &optional window
326 This function returns the previous sibling of the window @var{window}.
327 If omitted or @code{nil}, @var{window} defaults to the selected
328 window.  The return value is @code{nil} if @var{window} is the first
329 child of its parent.
330 @end defun
332 The functions @code{window-next-sibling} and
333 @code{window-prev-sibling} should not be confused with the functions
334 @code{next-window} and @code{previous-window}, which return the next
335 and previous window, respectively, in the cyclic ordering of windows
336 (@pxref{Cyclic Window Ordering}).
338   You can use the following functions to find the first live window on a
339 frame and the window nearest to a given window.
341 @defun frame-first-window &optional frame-or-window
342 This function returns the live window at the upper left corner of the
343 frame specified by @var{frame-or-window}.  The argument
344 @var{frame-or-window} must denote a window or a live frame and defaults
345 to the selected frame.  If @var{frame-or-window} specifies a window,
346 this function returns the first window on that window's frame.  Under
347 the assumption that the frame from our canonical example is selected
348 @code{(frame-first-window)} returns @var{W2}.
349 @end defun
351 @cindex window in direction
352 @defun window-in-direction direction &optional window ignore sign wrap mini
353 This function returns the nearest live window in direction
354 @var{direction} as seen from the position of @code{window-point} in
355 window @var{window}.  The argument @var{direction} must be one of
356 @code{above}, @code{below}, @code{left} or @code{right}.  The optional
357 argument @var{window} must denote a live window and defaults to the
358 selected one.
360 This function does not return a window whose @code{no-other-window}
361 parameter is non-@code{nil} (@pxref{Window Parameters}).  If the nearest
362 window's @code{no-other-window} parameter is non-@code{nil}, this
363 function tries to find another window in the indicated direction whose
364 @code{no-other-window} parameter is @code{nil}.  If the optional
365 argument @var{ignore} is non-@code{nil}, a window may be returned even
366 if its @code{no-other-window} parameter is non-@code{nil}.
368 If the optional argument @var{sign} is a negative number, it means to
369 use the right or bottom edge of @var{window} as reference position
370 instead of @code{window-point}.  If @var{sign} is a positive number, it
371 means to use the left or top edge of @var{window} as reference position.
373 If the optional argument @var{wrap} is non-@code{nil}, this means to
374 wrap @var{direction} around frame borders.  For example, if @var{window}
375 is at the top of the frame and @var{direction} is @code{above}, then
376 this function usually returns the frame's minibuffer window if it's
377 active and a window at the bottom of the frame otherwise.
379 If the optional argument @var{mini} is @code{nil}, this means to return
380 the minibuffer window if and only if it is currently active.  If
381 @var{mini} is non-@code{nil}, this function may return the minibuffer
382 window even when it's not active.  However, if @var{wrap} is
383 non-@code{nil}, it always acts as if @var{mini} were @code{nil}.
385 If it doesn't find a suitable window, this function returns @code{nil}.
386 @end defun
388 The following function allows the entire window tree of a frame to be
389 retrieved:
391 @defun window-tree &optional frame
392 This function returns a list representing the window tree for frame
393 @var{frame}.  If @var{frame} is omitted or @code{nil}, it defaults to
394 the selected frame.
396 The return value is a list of the form @code{(@var{root} @var{mini})},
397 where @var{root} represents the window tree of the frame's root
398 window, and @var{mini} is the frame's minibuffer window.
400 If the root window is live, @var{root} is that window itself.
401 Otherwise, @var{root} is a list @code{(@var{dir} @var{edges} @var{w1}
402 @var{w2} ...)} where @var{dir} is @code{nil} for a horizontal
403 combination and @code{t} for a vertical combination, @var{edges} gives
404 the size and position of the combination, and the remaining elements
405 are the child windows.  Each child window may again be a window object
406 (for a live window) or a list with the same format as above (for an
407 internal window).  The @var{edges} element is a list @code{(@var{left}
408 @var{top} @var{right} @var{bottom})}, similar to the value returned by
409 @code{window-edges} (@pxref{Coordinates and Windows}).
410 @end defun
413 @node Window Sizes
414 @section Window Sizes
415 @cindex window size
416 @cindex size of window
418   The following schematic shows the structure of a live window:
420 @smallexample
421 @group
422         ____________________________________________
423        |______________ Header Line ______________|RD| ^
424      ^ |LS|LM|LF|                       |RF|RM|RS|  | |
425      | |  |  |  |                       |  |  |  |  | |
426 Window |  |  |  |       Text Area       |  |  |  |  | Window
427 Body | |  |  |  |     (Window Body)     |  |  |  |  | Total
428 Height |  |  |  |                       |  |  |  |  | Height
429      | |  |  |  |<- Window Body Width ->|  |  |  |  | |
430      v |__|__|__|_______________________|__|__|__|  | |
431        |_________ Horizontal Scroll Bar _________|  | |
432        |_______________ Mode Line _______________|__| |
433        |_____________ Bottom Divider _______________| v
434         <---------- Window Total Width ------------>
436 @end group
437 @end smallexample
439 @cindex window body
440 @cindex text area of a window
441 @cindex body of a window
442   At the center of the window is the @dfn{text area}, or @dfn{body},
443 where the buffer text is displayed.  The text area can be surrounded by
444 a series of optional areas.  On the left and right, from innermost to
445 outermost, these are the left and right fringes, denoted by LF and RF
446 (@pxref{Fringes}); the left and right margins, denoted by LM and RM in
447 the schematic (@pxref{Display Margins}); the left or right vertical
448 scroll bar, only one of which is present at any time, denoted by LS and
449 RS (@pxref{Scroll Bars}); and the right divider, denoted by RD
450 (@pxref{Window Dividers}).  At the top of the window is the header line
451 (@pxref{Header Lines}).  At the bottom of the window are the horizontal
452 scroll bar (@pxref{Scroll Bars}); the mode line (@pxref{Mode Line
453 Format}); and the bottom divider (@pxref{Window Dividers}).
455   Emacs provides miscellaneous functions for finding the height and
456 width of a window.  The return value of many of these functions can be
457 specified either in units of pixels or in units of lines and columns.
458 On a graphical display, the latter actually correspond to the height and
459 width of a default character specified by the frame's default font
460 as returned by @code{frame-char-height} and @code{frame-char-width}
461 (@pxref{Frame Font}).  Thus, if a window is displaying text with a
462 different font or size, the reported line height and column width for
463 that window may differ from the actual number of text lines or columns
464 displayed within it.
466 @cindex window height
467 @cindex height of a window
468 @cindex total height of a window
469   The @dfn{total height} of a window is the number of lines comprising
470 the window's body, the header line, the horizontal scroll bar, the mode
471 line and the bottom divider (if any).
473 @defun window-total-height &optional window round
474 This function returns the total height, in lines, of the window
475 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults to
476 the selected window.  If @var{window} is an internal window, the return
477 value is the total height occupied by its descendant windows.
479   If a window's pixel height is not an integral multiple of its frame's
480 default character height, the number of lines occupied by the window is
481 rounded internally.  This is done in a way such that, if the window is a
482 parent window, the sum of the total heights of all its child windows
483 internally equals the total height of their parent.  This means that
484 although two windows have the same pixel height, their internal total
485 heights may differ by one line.  This means also, that if window is
486 vertically combined and has a next sibling, the topmost row of that
487 sibling can be calculated as the sum of this window's topmost row and
488 total height (@pxref{Coordinates and Windows})
490   If the optional argument @var{round} is @code{ceiling}, this
491 function returns the smallest integer larger than @var{window}'s pixel
492 height divided by the character height of its frame; if it is
493 @code{floor}, it returns the largest integer smaller than said value;
494 with any other @var{round} it returns the internal value of
495 @var{windows}'s total height.
496 @end defun
498 @cindex window width
499 @cindex width of a window
500 @cindex total width of a window
501 The @dfn{total width} of a window is the number of lines comprising the
502 window's body, its margins, fringes, scroll bars and a right divider (if
503 any).
505 @defun window-total-width &optional window round
506 This function returns the total width, in columns, of the window
507 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults to
508 the selected window.  If @var{window} is internal, the return value is
509 the total width occupied by its descendant windows.
511   If a window's pixel width is not an integral multiple of its frame's
512 character width, the number of lines occupied by the window is rounded
513 internally.  This is done in a way such that, if the window is a parent
514 window, the sum of the total widths of all its children internally
515 equals the total width of their parent.  This means that although two
516 windows have the same pixel width, their internal total widths may
517 differ by one column.  This means also, that if this window is
518 horizontally combined and has a next sibling, the leftmost column of
519 that sibling can be calculated as the sum of this window's leftmost
520 column and total width (@pxref{Coordinates and Windows}).  The optional
521 argument @var{round} behaves as it does for @code{window-total-height}.
522 @end defun
524 @defun window-total-size &optional window horizontal round
525 This function returns either the total height in lines or the total
526 width in columns of the window @var{window}.  If @var{horizontal} is
527 omitted or @code{nil}, this is equivalent to calling
528 @code{window-total-height} for @var{window}; otherwise it is equivalent
529 to calling @code{window-total-width} for @var{window}.  The optional
530 argument @var{round} behaves as it does for @code{window-total-height}.
531 @end defun
533 The following two functions can be used to return the total size of a
534 window in units of pixels.
536 @cindex window pixel height
537 @cindex pixel height of a window
538 @cindex total pixel height of a window
540 @defun window-pixel-height &optional window
541 This function returns the total height of window @var{window} in pixels.
542 @var{window} must be a valid window and defaults to the selected one.
544 The return value includes mode and header line, a horizontal scroll bar
545 and a bottom divider, if any.  If @var{window} is an internal window,
546 its pixel height is the pixel height of the screen areas spanned by its
547 children.
548 @end defun
550 @defun window-pixel-height-before-size-change &optional Lisp_Object &optional window
551 This function returns the height of window @var{window} in pixels at the
552 time @code{window-size-change-functions} was run for the last time on
553 @var{window}'s frame (@pxref{Window Hooks}).
554 @end defun
556 @cindex window pixel width
557 @cindex pixel width of a window
558 @cindex total pixel width of a window
560 @defun window-pixel-width &optional window
561 This function returns the width of window @var{window} in pixels.
562 @var{window} must be a valid window and defaults to the selected one.
564 The return value includes the fringes and margins of @var{window} as
565 well as any vertical dividers or scroll bars belonging to @var{window}.
566 If @var{window} is an internal window, its pixel width is the width of
567 the screen areas spanned by its children.
568 @end defun
570 @defun window-pixel-width-before-size-change &optional Lisp_Object &optional window
571 This function returns the width of window @var{window} in pixels at the
572 time @code{window-size-change-functions} was run for the last time on
573 @var{window}'s frame (@pxref{Window Hooks}).
574 @end defun
576 @cindex full-width window
577 @cindex full-height window
578   The following functions can be used to determine whether a given
579 window has any adjacent windows.
581 @defun window-full-height-p &optional window
582 This function returns non-@code{nil} if @var{window} has no other window
583 above or below it in its frame.  More precisely, this means that the
584 total height of @var{window} equals the total height of the root window
585 on that frame.  The minibuffer window does not count in this regard.  If
586 @var{window} is omitted or @code{nil}, it defaults to the selected
587 window.
588 @end defun
590 @defun window-full-width-p &optional window
591 This function returns non-@code{nil} if @var{window} has no other
592 window to the left or right in its frame, i.e., its total width equals
593 that of the root window on that frame.  If @var{window} is omitted or
594 @code{nil}, it defaults to the selected window.
595 @end defun
597 @cindex window body height
598 @cindex body height of a window
599 The @dfn{body height} of a window is the height of its text area, which
600 does not include a mode or header line, a horizontal scroll bar, or a
601 bottom divider.
603 @defun window-body-height &optional window pixelwise
604 This function returns the height, in lines, of the body of window
605 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults to
606 the selected window; otherwise it must be a live window.
608 If the optional argument @var{pixelwise} is non-@code{nil}, this
609 function returns the body height of @var{window} counted in pixels.
611 If @var{pixelwise} is @code{nil}, the return value is rounded down to
612 the nearest integer, if necessary.  This means that if a line at the
613 bottom of the text area is only partially visible, that line is not
614 counted.  It also means that the height of a window's body can never
615 exceed its total height as returned by @code{window-total-height}.
616 @end defun
618 @cindex window body width
619 @cindex body width of a window
620 The @dfn{body width} of a window is the width of its text area, which
621 does not include the scroll bar, fringes, margins or a right divider.
622 Note that when one or both fringes are removed (by setting their width
623 to zero), the display engine reserves two character cells, one on each
624 side of the window, for displaying the continuation and truncation
625 glyphs, which leaves 2 columns less for text display.  (The function
626 @code{window-max-chars-per-line}, described below, takes this
627 peculiarity into account.)
629 @defun window-body-width &optional window pixelwise
630 This function returns the width, in columns, of the body of window
631 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults to
632 the selected window; otherwise it must be a live window.
634 If the optional argument @var{pixelwise} is non-@code{nil}, this
635 function returns the body width of @var{window} in units of pixels.
637 If @var{pixelwise} is @code{nil}, the return value is rounded down to
638 the nearest integer, if necessary.  This means that if a column on the
639 right of the text area is only partially visible, that column is not
640 counted.  It also means that the width of a window's body can never
641 exceed its total width as returned by @code{window-total-width}.
642 @end defun
644 @cindex window body size
645 @cindex body size of a window
646 @defun window-body-size &optional window horizontal pixelwise
647 This function returns the body height or body width of @var{window}.  If
648 @var{horizontal} is omitted or @code{nil}, it is equivalent to calling
649 @code{window-body-height} for @var{window}; otherwise it is equivalent
650 to calling @code{window-body-width}.  In either case, the optional
651 argument @var{pixelwise} is passed to the function called.
652 @end defun
654 For compatibility with previous versions of Emacs,
655 @code{window-height} is an alias for @code{window-total-height}, and
656 @code{window-width} is an alias for @code{window-body-width}.  These
657 aliases are considered obsolete and will be removed in the future.
659    The pixel heights of a window's mode and header line can be retrieved
660 with the functions given below.  Their return value is usually accurate
661 unless the window has not been displayed before: In that case, the
662 return value is based on an estimate of the font used for the window's
663 frame.
665 @defun window-mode-line-height &optional window
666 This function returns the height in pixels of @var{window}'s mode line.
667 @var{window} must be a live window and defaults to the selected one.  If
668 @var{window} has no mode line, the return value is zero.
669 @end defun
671 @defun window-header-line-height &optional window
672 This function returns the height in pixels of @var{window}'s header
673 line.  @var{window} must be a live window and defaults to the selected
674 one.  If @var{window} has no header line, the return value is zero.
675 @end defun
677 Functions for retrieving the height and/or width of window dividers
678 (@pxref{Window Dividers}), fringes (@pxref{Fringes}), scroll bars
679 (@pxref{Scroll Bars}), and display margins (@pxref{Display Margins}) are
680 described in the corresponding sections.
682 If your Lisp program needs to make layout decisions, you will find the
683 following function useful:
685 @defun window-max-chars-per-line &optional window face
686 This function returns the number of characters displayed in the
687 specified face @var{face} in the specified window @var{window} (which
688 must be a live window).  If @var{face} was remapped (@pxref{Face
689 Remapping}), the information is returned for the remapped face.  If
690 omitted or @code{nil}, @var{face} defaults to the default face, and
691 @var{window} defaults to the selected window.
693 Unlike @code{window-body-width}, this function accounts for the actual
694 size of @var{face}'s font, instead of working in units of the canonical
695 character width of @var{window}'s frame (@pxref{Frame Font}).  It also
696 accounts for space used by the continuation glyph, if @var{window} lacks
697 one or both of its fringes.
698 @end defun
700 @cindex fixed-size window
701 @vindex window-min-height
702 @vindex window-min-width
703   Commands that change the size of windows (@pxref{Resizing Windows}),
704 or split them (@pxref{Splitting Windows}), obey the variables
705 @code{window-min-height} and @code{window-min-width}, which specify the
706 smallest allowable window height and width.  They also obey the variable
707 @code{window-size-fixed}, with which a window can be @dfn{fixed} in
708 size (@pxref{Preserving Window Sizes}).
710 @defopt window-min-height
711 This option specifies the minimum total height, in lines, of any window.
712 Its value has to accommodate at least one text line as well as a mode
713 and header line, a horizontal scroll bar and a bottom divider, if
714 present.
715 @end defopt
717 @defopt window-min-width
718 This option specifies the minimum total width, in columns, of any
719 window.  Its value has to accommodate two text columns as well as
720 margins, fringes, a scroll bar and a right divider, if present.
721 @end defopt
723 The following function tells how small a specific window can get taking
724 into account the sizes of its areas and the values of
725 @code{window-min-height}, @code{window-min-width} and
726 @code{window-size-fixed} (@pxref{Preserving Window Sizes}).
728 @defun window-min-size &optional window horizontal ignore pixelwise
729 This function returns the minimum size of @var{window}.  @var{window}
730 must be a valid window and defaults to the selected one.  The optional
731 argument @var{horizontal} non-@code{nil} means to return the minimum
732 number of columns of @var{window}; otherwise return the minimum number
733 of @var{window}'s lines.
735 The return value makes sure that all components of @var{window} remain
736 fully visible if @var{window}'s size were actually set to it.  With
737 @var{horizontal} @code{nil} it includes the mode and header line, the
738 horizontal scroll bar and the bottom divider, if present.  With
739 @var{horizontal} non-@code{nil} it includes the margins and fringes, the
740 vertical scroll bar and the right divider, if present.
742 The optional argument @var{ignore}, if non-@code{nil}, means ignore
743 restrictions imposed by fixed size windows, @code{window-min-height} or
744 @code{window-min-width} settings.  If @var{ignore} equals @code{safe},
745 live windows may get as small as @code{window-safe-min-height} lines and
746 @code{window-safe-min-width} columns.  If @var{ignore} is a window,
747 ignore restrictions for that window only.  Any other non-@code{nil}
748 value means ignore all of the above restrictions for all windows.
750 The optional argument @var{pixelwise} non-@code{nil} means to return the
751 minimum size of @var{window} counted in pixels.
752 @end defun
754 @node Resizing Windows
755 @section Resizing Windows
756 @cindex window resizing
757 @cindex resize window
758 @cindex changing window size
759 @cindex window size, changing
761   This section describes functions for resizing a window without
762 changing the size of its frame.  Because live windows do not overlap,
763 these functions are meaningful only on frames that contain two or more
764 windows: resizing a window also changes the size of a neighboring
765 window.  If there is just one window on a frame, its size cannot be
766 changed except by resizing the frame (@pxref{Size and Position}).
768   Except where noted, these functions also accept internal windows as
769 arguments.  Resizing an internal window causes its child windows to be
770 resized to fit the same space.
772 @defun window-resizable window delta &optional horizontal ignore pixelwise
773 This function returns @var{delta} if the size of @var{window} can be
774 changed vertically by @var{delta} lines.  If the optional argument
775 @var{horizontal} is non-@code{nil}, it instead returns @var{delta} if
776 @var{window} can be resized horizontally by @var{delta} columns.  It
777 does not actually change the window size.
779 If @var{window} is @code{nil}, it defaults to the selected window.
781 A positive value of @var{delta} means to check whether the window can be
782 enlarged by that number of lines or columns; a negative value of
783 @var{delta} means to check whether the window can be shrunk by that many
784 lines or columns.  If @var{delta} is non-zero, a return value of 0 means
785 that the window cannot be resized.
787 Normally, the variables @code{window-min-height} and
788 @code{window-min-width} specify the smallest allowable window size
789 (@pxref{Window Sizes}).  However, if the optional argument @var{ignore}
790 is non-@code{nil}, this function ignores @code{window-min-height} and
791 @code{window-min-width}, as well as @code{window-size-fixed}.  Instead,
792 it considers the minimum-height window to be one consisting of a header
793 and a mode line, a horizontal scrollbar and a bottom divider (if any),
794 plus a text area one line tall; and a minimum-width window as one
795 consisting of fringes, margins, a scroll bar and a right divider (if
796 any), plus a text area two columns wide.
798 If the optional argument @var{pixelwise} is non-@code{nil},
799 @var{delta} is interpreted as pixels.
800 @end defun
802 @defun window-resize window delta &optional horizontal ignore pixelwise
803 This function resizes @var{window} by @var{delta} increments.  If
804 @var{horizontal} is @code{nil}, it changes the height by @var{delta}
805 lines; otherwise, it changes the width by @var{delta} columns.  A
806 positive @var{delta} means to enlarge the window, and a negative
807 @var{delta} means to shrink it.
809 If @var{window} is @code{nil}, it defaults to the selected window.  If
810 the window cannot be resized as demanded, an error is signaled.
812 The optional argument @var{ignore} has the same meaning as for the
813 function @code{window-resizable} above.
815 If the optional argument @var{pixelwise} is non-@code{nil},
816 @var{delta} will be interpreted as pixels.
818 The choice of which window edges this function alters depends on the
819 values of the option @code{window-combination-resize} and the
820 combination limits of the involved windows; in some cases, it may alter
821 both edges.  @xref{Recombining Windows}.  To resize by moving only the
822 bottom or right edge of a window, use the function
823 @code{adjust-window-trailing-edge}.
824 @end defun
826 @c The commands enlarge-window, enlarge-window-horizontally,
827 @c shrink-window, and shrink-window-horizontally are documented in the
828 @c Emacs manual.  They are not preferred for calling from Lisp.
830 @defun adjust-window-trailing-edge window delta &optional horizontal pixelwise
831 This function moves @var{window}'s bottom edge by @var{delta} lines.
832 If optional argument @var{horizontal} is non-@code{nil}, it instead
833 moves the right edge by @var{delta} columns.  If @var{window} is
834 @code{nil}, it defaults to the selected window.
836 If the optional argument @var{pixelwise} is non-@code{nil},
837 @var{delta} is interpreted as pixels.
839 A positive @var{delta} moves the edge downwards or to the right; a
840 negative @var{delta} moves it upwards or to the left.  If the edge
841 cannot be moved as far as specified by @var{delta}, this function
842 moves it as far as possible but does not signal a error.
844 This function tries to resize windows adjacent to the edge that is
845 moved.  If this is not possible for some reason (e.g., if that adjacent
846 window is fixed-size), it may resize other windows.
847 @end defun
849 @cindex pixelwise, resizing windows
850 @defopt window-resize-pixelwise
851 If the value of this option is non-@code{nil}, Emacs resizes windows in
852 units of pixels.  This currently affects functions like
853 @code{split-window} (@pxref{Splitting Windows}), @code{maximize-window},
854 @code{minimize-window}, @code{fit-window-to-buffer},
855 @code{fit-frame-to-buffer} and
856 @code{shrink-window-if-larger-than-buffer} (all listed below).
858 Note that when a frame's pixel size is not a multiple of its character
859 size, at least one window may get resized pixelwise even if this
860 option is @code{nil}.  The default value is @code{nil}.
861 @end defopt
863   The following commands resize windows in more specific ways.  When
864 called interactively, they act on the selected window.
866 @deffn Command fit-window-to-buffer &optional window max-height min-height max-width min-width preserve-size
867 This command adjusts the height or width of @var{window} to fit the text
868 in it.  It returns non-@code{nil} if it was able to resize @var{window},
869 and @code{nil} otherwise.  If @var{window} is omitted or @code{nil}, it
870 defaults to the selected window.  Otherwise, it should be a live window.
872 If @var{window} is part of a vertical combination, this function adjusts
873 @var{window}'s height.  The new height is calculated from the actual
874 height of the accessible portion of its buffer.  The optional argument
875 @var{max-height}, if non-@code{nil}, specifies the maximum total height
876 that this function can give @var{window}.  The optional argument
877 @var{min-height}, if non-@code{nil}, specifies the minimum total height
878 that it can give, which overrides the variable @code{window-min-height}.
879 Both @var{max-height} and @var{min-height} are specified in lines and
880 include mode and header line and a bottom divider, if any.
882 If @var{window} is part of a horizontal combination and the value of the
883 option @code{fit-window-to-buffer-horizontally} (see below) is
884 non-@code{nil}, this function adjusts @var{window}'s height.  The new
885 width of @var{window} is calculated from the maximum length of its
886 buffer's lines that follow the current start position of @var{window}.
887 The optional argument @var{max-width} specifies a maximum width and
888 defaults to the width of @var{window}'s frame.  The optional argument
889 @var{min-width} specifies a minimum width and defaults to
890 @code{window-min-width}.  Both @var{max-width} and @var{min-width} are
891 specified in columns and include fringes, margins and scrollbars, if
892 any.
894 The optional argument @var{preserve-size}, if non-@code{nil}, will
895 install a parameter to preserve the size of @var{window} during future
896 resize operations (@pxref{Preserving Window Sizes}).
898 If the option @code{fit-frame-to-buffer} (see below) is non-@code{nil},
899 this function will try to resize the frame of @var{window} to fit its
900 contents by calling @code{fit-frame-to-buffer} (see below).
901 @end deffn
903 @defopt fit-window-to-buffer-horizontally
904 If this is non-@code{nil}, @code{fit-window-to-buffer} can resize
905 windows horizontally.  If this is @code{nil} (the default)
906 @code{fit-window-to-buffer} never resizes windows horizontally.  If this
907 is @code{only}, it can resize windows horizontally only.  Any other
908 value means @code{fit-window-to-buffer} can resize windows in both
909 dimensions.
910 @end defopt
912 @defopt fit-frame-to-buffer
913 If this option is non-@code{nil}, @code{fit-window-to-buffer} can fit a
914 frame to its buffer.  A frame is fit if and only if its root window is a
915 live window and this option is non-@code{nil}.  If this is
916 @code{horizontally}, frames are fit horizontally only.  If this is
917 @code{vertically}, frames are fit vertically only.  Any other
918 non-@code{nil} value means frames can be resized in both dimensions.
919 @end defopt
921 If you have a frame that displays only one window, you can fit that
922 frame to its buffer using the command @code{fit-frame-to-buffer}.
924 @deffn Command fit-frame-to-buffer &optional frame max-height min-height max-width min-width only
925 This command adjusts the size of @var{frame} to display the contents of
926 its buffer exactly.  @var{frame} can be any live frame and defaults to
927 the selected one.  Fitting is done only if @var{frame}'s root window is
928 live.  The arguments @var{max-height}, @var{min-height}, @var{max-width}
929 and @var{min-width} specify bounds on the new total size of
930 @var{frame}'s root window.  @var{min-height} and @var{min-width} default
931 to the values of @code{window-min-height} and @code{window-min-width}
932 respectively.
934 If the optional argument @var{only} is @code{vertically}, this function
935 may resize the frame vertically only.  If @var{only} is
936 @code{horizontally}, it may resize the frame horizontally only.
937 @end deffn
939 The behavior of @code{fit-frame-to-buffer} can be controlled with the
940 help of the two options listed next.
942 @defopt fit-frame-to-buffer-margins
943 This option can be used to specify margins around frames to be fit by
944 @code{fit-frame-to-buffer}.  Such margins can be useful to avoid, for
945 example, that such frames overlap the taskbar.
947 It specifies the numbers of pixels to be left free on the left, above,
948 the right, and below a frame that shall be fit.  The default specifies
949 @code{nil} for each which means to use no margins.  The value specified
950 here can be overridden for a specific frame by that frame's
951 @code{fit-frame-to-buffer-margins} parameter, if present.
952 @end defopt
954 @defopt fit-frame-to-buffer-sizes
955 This option specifies size boundaries for @code{fit-frame-to-buffer}.
956 It specifies the total maximum and minimum lines and maximum and minimum
957 columns of the root window of any frame that shall be fit to its buffer.
958 If any of these values is non-@code{nil}, it overrides the corresponding
959 argument of @code{fit-frame-to-buffer}.
960 @end defopt
962 @deffn Command shrink-window-if-larger-than-buffer &optional window
963 This command attempts to reduce @var{window}'s height as much as
964 possible while still showing its full buffer, but no less than
965 @code{window-min-height} lines.  The return value is non-@code{nil} if
966 the window was resized, and @code{nil} otherwise.  If @var{window} is
967 omitted or @code{nil}, it defaults to the selected window.  Otherwise,
968 it should be a live window.
970 This command does nothing if the window is already too short to
971 display all of its buffer, or if any of the buffer is scrolled
972 off-screen, or if the window is the only live window in its frame.
974 This command calls @code{fit-window-to-buffer} (see above) to do its
975 work.
976 @end deffn
979 @cindex balancing window sizes
980 @deffn Command balance-windows &optional window-or-frame
981 This function balances windows in a way that gives more space to
982 full-width and/or full-height windows.  If @var{window-or-frame}
983 specifies a frame, it balances all windows on that frame.  If
984 @var{window-or-frame} specifies a window, it balances only that window
985 and its siblings (@pxref{Windows and Frames}).
986 @end deffn
988 @deffn Command balance-windows-area
989 This function attempts to give all windows on the selected frame
990 approximately the same share of the screen area.  Full-width or
991 full-height windows are not given more space than other windows.
992 @end deffn
994 @cindex maximizing windows
995 @deffn Command maximize-window &optional window
996 This function attempts to make @var{window} as large as possible, in
997 both dimensions, without resizing its frame or deleting other windows.
998 If @var{window} is omitted or @code{nil}, it defaults to the selected
999 window.
1000 @end deffn
1002 @cindex minimizing windows
1003 @deffn Command minimize-window &optional window
1004 This function attempts to make @var{window} as small as possible, in
1005 both dimensions, without deleting it or resizing its frame.  If
1006 @var{window} is omitted or @code{nil}, it defaults to the selected
1007 window.
1008 @end deffn
1011 @node Preserving Window Sizes
1012 @section Preserving Window Sizes
1013 @cindex preserving window sizes
1015 A window can get resized explicitly by using one of the functions from
1016 the preceding section or implicitly, for example, when resizing an
1017 adjacent window, when splitting or deleting a window (@pxref{Splitting
1018 Windows}, @pxref{Deleting Windows}) or when resizing the window's frame
1019 (@pxref{Size and Position}).
1021   It is possible to avoid implicit resizing of a specific window when
1022 there are one or more other resizable windows on the same frame.  For
1023 this purpose, Emacs must be advised to @dfn{preserve} the size of that
1024 window.  There are two basic ways to do that.
1026 @defvar window-size-fixed
1027 If this buffer-local variable is non-@code{nil}, the size of any window
1028 displaying the buffer cannot normally be changed.  Deleting a window or
1029 changing the frame's size may still change the window's size, if there
1030 is no choice.
1032 If the value is @code{height}, then only the window's height is fixed;
1033 if the value is @code{width}, then only the window's width is fixed.
1034 Any other non-@code{nil} value fixes both the width and the height.
1036 If this variable is @code{nil}, this does not necessarily mean that any
1037 window showing the buffer can be resized in the desired direction.  To
1038 determine that, use the function @code{window-resizable}.
1039 @xref{Resizing Windows}.
1040 @end defvar
1042 Often @code{window-size-fixed} is overly aggressive because it inhibits
1043 any attempt to explicitly resize or split an affected window as well.
1044 This may even happen after the window has been resized implicitly, for
1045 example, when deleting an adjacent window or resizing the window's
1046 frame.  The following function tries hard to never disallow resizing
1047 such a window explicitly:
1049 @defun window-preserve-size &optional window horizontal preserve
1050 This function (un-)marks the height of window @var{window} as preserved
1051 for future resize operations.  @var{window} must be a live window and
1052 defaults to the selected one.  If the optional argument @var{horizontal}
1053 is non-@code{nil}, it (un-)marks the width of @var{window} as preserved.
1055 If the optional argument @var{preserve} is @code{t}, this means to
1056 preserve the current height/width of @var{window}'s body.  The
1057 height/width of @var{window} will change only if Emacs has no better
1058 choice.  Resizing a window whose height/width is preserved by this
1059 function never throws an error.
1061 If @var{preserve} is @code{nil}, this means to stop preserving the
1062 height/width of @var{window}, lifting any respective restraint induced
1063 by a previous call of this function for @var{window}.  Calling
1064 @code{enlarge-window}, @code{shrink-window} or
1065 @code{fit-window-to-buffer} with @var{window} as argument may also
1066 remove the respective restraint.
1067 @end defun
1069 @code{window-preserve-size} is currently invoked by the following
1070 functions:
1072 @table @code
1073 @item fit-window-to-buffer
1074 If the optional argument @var{preserve-size} of that function
1075 (@pxref{Resizing Windows}) is non-@code{nil}, the size established by
1076 that function is preserved.
1078 @item display-buffer
1079 If the @var{alist} argument of that function (@pxref{Choosing Window})
1080 contains a @code{preserve-size} entry, the size of the window produced
1081 by that function is preserved.
1082 @end table
1084   @code{window-preserve-size} installs a window parameter (@pxref{Window
1085 Parameters}) called @code{preserved-size} which is consulted by the
1086 window resizing functions.  This parameter will not prevent resizing the
1087 window when the window shows another buffer than the one when
1088 @code{window-preserve-size} was invoked or if its size has changed since
1089 then.
1091 The following function can be used to check whether the height of a
1092 particular window is preserved:
1094 @defun window-preserved-size &optional window horizontal
1095 This function returns the preserved height of window @var{window} in
1096 pixels.  @var{window} must be a live window and defaults to the selected
1097 one.  If the optional argument @var{horizontal} is non-@code{nil}, it
1098 returns the preserved width of @var{window}.  It returns @code{nil} if
1099 the size of @var{window} is not preserved.
1100 @end defun
1103 @node Splitting Windows
1104 @section Splitting Windows
1105 @cindex splitting windows
1106 @cindex window splitting
1108 This section describes functions for creating a new window by
1109 @dfn{splitting} an existing one.
1111 @defun split-window &optional window size side pixelwise
1112 This function creates a new live window next to the window
1113 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults
1114 to the selected window.  That window is split, and reduced in
1115 size.  The space is taken up by the new window, which is returned.
1117 The optional second argument @var{size} determines the sizes of
1118 @var{window} and/or the new window.  If it is omitted or @code{nil},
1119 both windows are given equal sizes; if there is an odd line, it is
1120 allocated to the new window.  If @var{size} is a positive number,
1121 @var{window} is given @var{size} lines (or columns, depending on the
1122 value of @var{side}).  If @var{size} is a negative number, the new
1123 window is given @minus{}@var{size} lines (or columns).
1125 If @var{size} is @code{nil}, this function obeys the variables
1126 @code{window-min-height} and @code{window-min-width} (@pxref{Window
1127 Sizes}).  Thus, it signals an error if splitting would result in making
1128 a window smaller than those variables specify.  However, a
1129 non-@code{nil} value for @var{size} causes those variables to be
1130 ignored; in that case, the smallest allowable window is considered to be
1131 one that has space for a text area one line tall and/or two columns
1132 wide.
1134 Hence, if @var{size} is specified, it's the caller's responsibility to
1135 check whether the emanating windows are large enough to encompass all
1136 areas like a mode line or a scroll bar.  The function
1137 @code{window-min-size} (@pxref{Window Sizes}) can be used to determine
1138 the minimum requirements of @var{window} in this regard.  Since the new
1139 window usually inherits areas like the mode line or the scroll bar
1140 from @var{window}, that function is also a good guess for the minimum
1141 size of the new window.  The caller should specify a smaller size only
1142 if it correspondingly removes an inherited area before the next
1143 redisplay.
1145 The optional third argument @var{side} determines the position of the
1146 new window relative to @var{window}.  If it is @code{nil} or
1147 @code{below}, the new window is placed below @var{window}.  If it is
1148 @code{above}, the new window is placed above @var{window}.  In both
1149 these cases, @var{size} specifies a total window height, in lines.
1151 If @var{side} is @code{t} or @code{right}, the new window is placed on
1152 the right of @var{window}.  If @var{side} is @code{left}, the new
1153 window is placed on the left of @var{window}.  In both these cases,
1154 @var{size} specifies a total window width, in columns.
1156 The optional fourth argument @var{pixelwise}, if non-@code{nil}, means
1157 to interpret @var{size} in units of pixels, instead of lines and
1158 columns.
1160 If @var{window} is a live window, the new window inherits various
1161 properties from it, including margins and scroll bars.  If
1162 @var{window} is an internal window, the new window inherits the
1163 properties of the window selected within @var{window}'s frame.
1165 The behavior of this function may be altered by the window parameters
1166 of @var{window}, so long as the variable
1167 @code{ignore-window-parameters} is @code{nil}.  If the value of
1168 the @code{split-window} window parameter is @code{t}, this function
1169 ignores all other window parameters.  Otherwise, if the value of the
1170 @code{split-window} window parameter is a function, that function is
1171 called with the arguments @var{window}, @var{size}, and @var{side}, in
1172 lieu of the usual action of @code{split-window}.  Otherwise, this
1173 function obeys the @code{window-atom} or @code{window-side} window
1174 parameter, if any.  @xref{Window Parameters}.
1175 @end defun
1177   As an example, here is a sequence of @code{split-window} calls that
1178 yields the window configuration discussed in @ref{Windows and Frames}.
1179 This example demonstrates splitting a live window as well as splitting
1180 an internal window.  We begin with a frame containing a single window
1181 (a live root window), which we denote by @var{W4}.  Calling
1182 @code{(split-window W4)} yields this window configuration:
1184 @smallexample
1185 @group
1186      ______________________________________
1187     | ____________________________________ |
1188     ||                                    ||
1189     ||                                    ||
1190     ||                                    ||
1191     ||_________________W4_________________||
1192     | ____________________________________ |
1193     ||                                    ||
1194     ||                                    ||
1195     ||                                    ||
1196     ||_________________W5_________________||
1197     |__________________W3__________________|
1199 @end group
1200 @end smallexample
1202 @noindent
1203 The @code{split-window} call has created a new live window, denoted by
1204 @var{W5}.  It has also created a new internal window, denoted by
1205 @var{W3}, which becomes the root window and the parent of both
1206 @var{W4} and @var{W5}.
1208   Next, we call @code{(split-window W3 nil 'left)}, passing the
1209 internal window @var{W3} as the argument.  The result:
1211 @smallexample
1212 @group
1213      ______________________________________
1214     | ______  ____________________________ |
1215     ||      || __________________________ ||
1216     ||      |||                          |||
1217     ||      |||                          |||
1218     ||      |||                          |||
1219     ||      |||____________W4____________|||
1220     ||      || __________________________ ||
1221     ||      |||                          |||
1222     ||      |||                          |||
1223     ||      |||____________W5____________|||
1224     ||__W2__||_____________W3_____________ |
1225     |__________________W1__________________|
1226 @end group
1227 @end smallexample
1229 @noindent
1230 A new live window @var{W2} is created, to the left of the internal
1231 window @var{W3}.  A new internal window @var{W1} is created, becoming
1232 the new root window.
1234    For interactive use, Emacs provides two commands which always split
1235 the selected window.  These call @code{split-window} internally.
1237 @deffn Command split-window-right &optional size
1238 This function splits the selected window into two side-by-side
1239 windows, putting the selected window on the left.  If @var{size} is
1240 positive, the left window gets @var{size} columns; if @var{size} is
1241 negative, the right window gets @minus{}@var{size} columns.
1242 @end deffn
1244 @deffn Command split-window-below &optional size
1245 This function splits the selected window into two windows, one above
1246 the other, leaving the upper window selected.  If @var{size} is
1247 positive, the upper window gets @var{size} lines; if @var{size} is
1248 negative, the lower window gets @minus{}@var{size} lines.
1249 @end deffn
1251 @defopt split-window-keep-point
1252 If the value of this variable is non-@code{nil} (the default),
1253 @code{split-window-below} behaves as described above.
1255 If it is @code{nil}, @code{split-window-below} adjusts point in each
1256 of the two windows to minimize redisplay.  (This is useful on slow
1257 terminals.)  It selects whichever window contains the screen line that
1258 point was previously on.  Note that this only affects
1259 @code{split-window-below}, not the lower-level @code{split-window}
1260 function.
1261 @end defopt
1264 @node Deleting Windows
1265 @section Deleting Windows
1266 @cindex deleting windows
1268   @dfn{Deleting} a window removes it from the frame's window tree.  If
1269 the window is a live window, it disappears from the screen.  If the
1270 window is an internal window, its child windows are deleted too.
1272   Even after a window is deleted, it continues to exist as a Lisp
1273 object, until there are no more references to it.  Window deletion can
1274 be reversed, by restoring a saved window configuration (@pxref{Window
1275 Configurations}).
1277 @deffn Command delete-window &optional window
1278 This function removes @var{window} from display and returns
1279 @code{nil}.  If @var{window} is omitted or @code{nil}, it defaults to
1280 the selected window.
1282 If deleting the window would leave no more windows in the window tree
1283 (e.g., if it is the only live window in the frame) or all remaining
1284 windows on @var{window}'s frame are side windows (@pxref{Side Windows}),
1285 an error is signaled.
1287 By default, the space taken up by @var{window} is given to one of its
1288 adjacent sibling windows, if any.  However, if the variable
1289 @code{window-combination-resize} is non-@code{nil}, the space is
1290 proportionally distributed among any remaining windows in the same
1291 window combination.  @xref{Recombining Windows}.
1293 The behavior of this function may be altered by the window parameters of
1294 @var{window}, so long as the variable @code{ignore-window-parameters} is
1295 @code{nil}.  If the value of the @code{delete-window} window parameter
1296 is @code{t}, this function ignores all other window parameters.
1297 Otherwise, if the value of the @code{delete-window} window parameter is
1298 a function, that function is called with the argument @var{window}, in
1299 lieu of the usual action of @code{delete-window}.  @xref{Window
1300 Parameters}.
1301 @end deffn
1303 @deffn Command delete-other-windows &optional window
1304 This function makes @var{window} fill its frame, deleting other windows
1305 as necessary.  If @var{window} is omitted or @code{nil}, it defaults to
1306 the selected window.  An error is signaled if @var{window} is a side
1307 window (@pxref{Side Windows}).  The return value is @code{nil}.
1309 The behavior of this function may be altered by the window parameters of
1310 @var{window}, so long as the variable @code{ignore-window-parameters} is
1311 @code{nil}.  If the value of the @code{delete-other-windows} window
1312 parameter is @code{t}, this function ignores all other window
1313 parameters.  Otherwise, if the value of the @code{delete-other-windows}
1314 window parameter is a function, that function is called with the
1315 argument @var{window}, in lieu of the usual action of
1316 @code{delete-other-windows}.  @xref{Window Parameters}.
1318 Also, if @code{ignore-window-parameters} is @code{nil}, this function
1319 does not delete any window whose @code{no-delete-other-window} parameter
1320 is non-@code{nil}.
1321 @end deffn
1323 @deffn Command delete-windows-on &optional buffer-or-name frame
1324 This function deletes all windows showing @var{buffer-or-name}, by
1325 calling @code{delete-window} on those windows.  @var{buffer-or-name}
1326 should be a buffer, or the name of a buffer; if omitted or @code{nil},
1327 it defaults to the current buffer.  If there are no windows showing
1328 the specified buffer, this function does nothing.  If the specified
1329 buffer is a minibuffer, an error is signaled.
1331 If there is a dedicated window showing the buffer, and that window is
1332 the only one on its frame, this function also deletes that frame if it
1333 is not the only frame on the terminal.
1335 The optional argument @var{frame} specifies which frames to operate
1338 @itemize @bullet
1339 @item @code{nil}
1340 means operate on all frames.
1341 @item @code{t}
1342 means operate on the selected frame.
1343 @item @code{visible}
1344 means operate on all visible frames.
1345 @item @code{0}
1346 means operate on all visible or iconified frames.
1347 @item A frame
1348 means operate on that frame.
1349 @end itemize
1351 Note that this argument does not have the same meaning as in other
1352 functions which scan all live windows (@pxref{Cyclic Window
1353 Ordering}).  Specifically, the meanings of @code{t} and @code{nil} here
1354 are the opposite of what they are in those other functions.
1355 @end deffn
1358 @node Recombining Windows
1359 @section Recombining Windows
1360 @cindex recombining windows
1361 @cindex windows, recombining
1363 When deleting the last sibling of a window @var{W}, its parent window
1364 is deleted too, with @var{W} replacing it in the window tree.  This
1365 means that @var{W} must be recombined with its parent's siblings to
1366 form a new window combination (@pxref{Windows and Frames}).  In some
1367 occasions, deleting a live window may even entail the deletion of two
1368 internal windows.
1370 @smallexample
1371 @group
1372      ______________________________________
1373     | ______  ____________________________ |
1374     ||      || __________________________ ||
1375     ||      ||| ___________  ___________ |||
1376     ||      ||||           ||           ||||
1377     ||      ||||____W6_____||_____W7____||||
1378     ||      |||____________W4____________|||
1379     ||      || __________________________ ||
1380     ||      |||                          |||
1381     ||      |||                          |||
1382     ||      |||____________W5____________|||
1383     ||__W2__||_____________W3_____________ |
1384     |__________________W1__________________|
1386 @end group
1387 @end smallexample
1389 @noindent
1390 Deleting @var{W5} in this configuration normally causes the deletion of
1391 @var{W3} and @var{W4}.  The remaining live windows @var{W2},
1392 @var{W6} and @var{W7} are recombined to form a new horizontal
1393 combination with parent @var{W1}.
1395    Sometimes, however, it makes sense to not delete a parent window like
1396 @var{W4}.  In particular, a parent window should not be removed when it
1397 was used to preserve a combination embedded in a combination of the same
1398 type.  Such embeddings make sense to assure that when you split a window
1399 and subsequently delete the new window, Emacs reestablishes the layout
1400 of the associated frame as it existed before the splitting.
1402    Consider a scenario starting with two live windows @var{W2} and
1403 @var{W3} and their parent @var{W1}.
1405 @smallexample
1406 @group
1407      ______________________________________
1408     | ____________________________________ |
1409     ||                                    ||
1410     ||                                    ||
1411     ||                                    ||
1412     ||                                    ||
1413     ||                                    ||
1414     ||                                    ||
1415     ||_________________W2_________________||
1416     | ____________________________________ |
1417     ||                                    ||
1418     ||                                    ||
1419     ||_________________W3_________________||
1420     |__________________W1__________________|
1422 @end group
1423 @end smallexample
1425 @noindent
1426 Split @var{W2} to make a new window @var{W4} as follows.
1428 @smallexample
1429 @group
1430      ______________________________________
1431     | ____________________________________ |
1432     ||                                    ||
1433     ||                                    ||
1434     ||_________________W2_________________||
1435     | ____________________________________ |
1436     ||                                    ||
1437     ||                                    ||
1438     ||_________________W4_________________||
1439     | ____________________________________ |
1440     ||                                    ||
1441     ||                                    ||
1442     ||_________________W3_________________||
1443     |__________________W1__________________|
1445 @end group
1446 @end smallexample
1448 @noindent
1449 Now, when enlarging a window vertically, Emacs tries to obtain the
1450 corresponding space from its lower sibling, provided such a window
1451 exists.  In our scenario, enlarging @var{W4} will steal space from
1452 @var{W3}.
1454 @smallexample
1455 @group
1456      ______________________________________
1457     | ____________________________________ |
1458     ||                                    ||
1459     ||                                    ||
1460     ||_________________W2_________________||
1461     | ____________________________________ |
1462     ||                                    ||
1463     ||                                    ||
1464     ||                                    ||
1465     ||                                    ||
1466     ||_________________W4_________________||
1467     | ____________________________________ |
1468     ||_________________W3_________________||
1469     |__________________W1__________________|
1471 @end group
1472 @end smallexample
1474 @noindent
1475 Deleting @var{W4} will now give its entire space to @var{W2},
1476 including the space earlier stolen from @var{W3}.
1478 @smallexample
1479 @group
1480      ______________________________________
1481     | ____________________________________ |
1482     ||                                    ||
1483     ||                                    ||
1484     ||                                    ||
1485     ||                                    ||
1486     ||                                    ||
1487     ||                                    ||
1488     ||                                    ||
1489     ||                                    ||
1490     ||_________________W2_________________||
1491     | ____________________________________ |
1492     ||_________________W3_________________||
1493     |__________________W1__________________|
1495 @end group
1496 @end smallexample
1498 @noindent
1499 This can be counterintuitive, in particular if @var{W4} were used for
1500 displaying a buffer only temporarily (@pxref{Temporary Displays}), and
1501 you want to continue working with the initial layout.
1503 The behavior can be fixed by making a new parent window when splitting
1504 @var{W2}.  The variable described next allows that to be done.
1506 @defopt window-combination-limit
1507 This variable controls whether splitting a window shall make a new
1508 parent window.  The following values are recognized:
1510 @table @code
1511 @item nil
1512 This means that the new live window is allowed to share the existing
1513 parent window, if one exists, provided the split occurs in the same
1514 direction as the existing window combination (otherwise, a new internal
1515 window is created anyway).
1517 @item window-size
1518 In this case @code{display-buffer} makes a new parent window if it is
1519 passed a @code{window-height} or @code{window-width} entry in the
1520 @var{alist} argument (@pxref{Display Action Functions}).
1522 @item temp-buffer
1523 This value causes the creation of a new parent window when a window is
1524 split for showing a temporary buffer (@pxref{Temporary Displays}) only.
1526 @item display-buffer
1527 This means that when @code{display-buffer} (@pxref{Choosing Window})
1528 splits a window it always makes a new parent window.
1530 @item t
1531 In this case a new parent window is always created when splitting a
1532 window.  Thus, if the value of this variable is at all times @code{t},
1533 then at all times every window tree is a binary tree (a tree where each
1534 window except the root window has exactly one sibling).
1535 @end table
1537 The default is @code{nil}.  Other values are reserved for future use.
1539 If, as a consequence of this variable's setting, @code{split-window}
1540 makes a new parent window, it also calls
1541 @code{set-window-combination-limit} (see below) on the newly-created
1542 internal window.  This affects how the window tree is rearranged when
1543 the child windows are deleted (see below).
1544 @end defopt
1546   If @code{window-combination-limit} is @code{t}, splitting @var{W2} in
1547 the initial configuration of our scenario would have produced this:
1549 @smallexample
1550 @group
1551      ______________________________________
1552     | ____________________________________ |
1553     || __________________________________ ||
1554     |||                                  |||
1555     |||________________W2________________|||
1556     || __________________________________ ||
1557     |||                                  |||
1558     |||________________W4________________|||
1559     ||_________________W5_________________||
1560     | ____________________________________ |
1561     ||                                    ||
1562     ||                                    ||
1563     ||_________________W3_________________||
1564     |__________________W1__________________|
1566 @end group
1567 @end smallexample
1569 @noindent
1570 A new internal window @var{W5} has been created; its children are
1571 @var{W2} and the new live window @var{W4}.  Now, @var{W2} is the only
1572 sibling of @var{W4}, so enlarging @var{W4} will try to shrink
1573 @var{W2}, leaving @var{W3} unaffected.  Observe that @var{W5}
1574 represents a vertical combination of two windows embedded in the
1575 vertical combination @var{W1}.
1577 @cindex window combination limit
1578 @defun set-window-combination-limit window limit
1579 This function sets the @dfn{combination limit} of the window
1580 @var{window} to @var{limit}.  This value can be retrieved via the
1581 function @code{window-combination-limit}.  See below for its effects;
1582 note that it is only meaningful for internal windows.  The
1583 @code{split-window} function automatically calls this function, passing
1584 it @code{t} as @var{limit}, provided the value of the variable
1585 @code{window-combination-limit} is @code{t} when it is called.
1586 @end defun
1588 @defun window-combination-limit window
1589 This function returns the combination limit for @var{window}.
1591 The combination limit is meaningful only for an internal window.  If it
1592 is @code{nil}, then Emacs is allowed to automatically delete
1593 @var{window}, in response to a window deletion, in order to group the
1594 child windows of @var{window} with its sibling windows to form a new
1595 window combination.  If the combination limit is @code{t}, the child
1596 windows of @var{window} are never automatically recombined with its
1597 siblings.
1599 If, in the configuration shown at the beginning of this section, the
1600 combination limit of @var{W4} (the parent window of @var{W6} and
1601 @var{W7}) is @code{t}, deleting @var{W5} will not implicitly delete
1602 @var{W4} too.
1603 @end defun
1605 Alternatively, the problems sketched above can be avoided by always
1606 resizing all windows in the same combination whenever one of its windows
1607 is split or deleted.  This also permits splitting windows that would be
1608 otherwise too small for such an operation.
1610 @defopt window-combination-resize
1611 If this variable is @code{nil}, @code{split-window} can only split a
1612 window (denoted by @var{window}) if @var{window}'s screen area is large
1613 enough to accommodate both itself and the new window.
1615 If this variable is @code{t}, @code{split-window} tries to resize all
1616 windows that are part of the same combination as @var{window}, in order
1617 to accommodate the new window.  In particular, this may allow
1618 @code{split-window} to succeed even if @var{window} is a fixed-size
1619 window or too small to ordinarily split.  Furthermore, subsequently
1620 resizing or deleting @var{window} may resize all other windows in its
1621 combination.
1623 The default is @code{nil}.  Other values are reserved for future use.  A
1624 specific split operation may ignore the value of this variable if it is
1625 affected by a non-@code{nil} value of @code{window-combination-limit}.
1626 @end defopt
1628   To illustrate the effect of @code{window-combination-resize}, consider
1629 the following frame layout.
1631 @smallexample
1632 @group
1633      ______________________________________
1634     | ____________________________________ |
1635     ||                                    ||
1636     ||                                    ||
1637     ||                                    ||
1638     ||                                    ||
1639     ||_________________W2_________________||
1640     | ____________________________________ |
1641     ||                                    ||
1642     ||                                    ||
1643     ||                                    ||
1644     ||                                    ||
1645     ||_________________W3_________________||
1646     |__________________W1__________________|
1648 @end group
1649 @end smallexample
1651 @noindent
1652 If @code{window-combination-resize} is @code{nil}, splitting window
1653 @var{W3} leaves the size of @var{W2} unchanged:
1655 @smallexample
1656 @group
1657      ______________________________________
1658     | ____________________________________ |
1659     ||                                    ||
1660     ||                                    ||
1661     ||                                    ||
1662     ||                                    ||
1663     ||_________________W2_________________||
1664     | ____________________________________ |
1665     ||                                    ||
1666     ||_________________W3_________________||
1667     | ____________________________________ |
1668     ||                                    ||
1669     ||_________________W4_________________||
1670     |__________________W1__________________|
1672 @end group
1673 @end smallexample
1675 @noindent
1676 If @code{window-combination-resize} is @code{t}, splitting @var{W3}
1677 instead leaves all three live windows with approximately the same
1678 height:
1680 @smallexample
1681 @group
1682      ______________________________________
1683     | ____________________________________ |
1684     ||                                    ||
1685     ||                                    ||
1686     ||_________________W2_________________||
1687     | ____________________________________ |
1688     ||                                    ||
1689     ||                                    ||
1690     ||_________________W3_________________||
1691     | ____________________________________ |
1692     ||                                    ||
1693     ||                                    ||
1694     ||_________________W4_________________||
1695     |__________________W1__________________|
1697 @end group
1698 @end smallexample
1700 @noindent
1701 Deleting any of the live windows @var{W2}, @var{W3} or @var{W4} will
1702 distribute its space proportionally among the two remaining live
1703 windows.
1706 @node Selecting Windows
1707 @section Selecting Windows
1708 @cindex selecting a window
1710 @defun select-window window &optional norecord
1711 This function makes @var{window} the selected window and the window
1712 selected within its frame (@pxref{Basic Windows}) and selects that
1713 frame.  It also makes @var{window}'s buffer (@pxref{Buffers and
1714 Windows}) current and sets that buffer's value of @code{point} to the
1715 value of @code{window-point} (@pxref{Window Point}) in @var{window}.
1716 @var{window} must be a live window.  The return value is @var{window}.
1718 By default, this function also moves @var{window}'s buffer to the front
1719 of the buffer list (@pxref{Buffer List}), and makes @var{window} the
1720 most recently selected window.  However, if the optional argument
1721 @var{norecord} is non-@code{nil}, these additional actions are omitted.
1723 This function runs @code{buffer-list-update-hook} (@pxref{Buffer List})
1724 unless @var{norecord} is non-@code{nil}.  Note that applications and
1725 internal routines often temporarily select a window in order to simplify
1726 coding.  As a rule, such selections (including those made by the macros
1727 @code{save-selected-window} and @code{with-selected-window} below) are
1728 not recorded thus avoiding to pollute @code{buffer-list-update-hook}.
1729 Selections that really count are those causing a visible change in
1730 the next redisplay of @var{window}'s frame and should be always
1731 recorded.  This also means that to run a function each time a window
1732 gets selected, putting it on @code{buffer-list-update-hook} should be
1733 the right choice.
1734 @end defun
1736 @cindex most recently selected windows
1737   The sequence of calls to @code{select-window} with a non-@code{nil}
1738 @var{norecord} argument determines an ordering of windows by their
1739 selection time.  The function @code{get-lru-window} can be used to
1740 retrieve the least recently selected live window (@pxref{Cyclic Window
1741 Ordering}).
1743 @defmac save-selected-window forms@dots{}
1744 This macro records the selected frame, as well as the selected window
1745 of each frame, executes @var{forms} in sequence, then restores the
1746 earlier selected frame and windows.  It also saves and restores the
1747 current buffer.  It returns the value of the last form in @var{forms}.
1749 This macro does not save or restore anything about the sizes,
1750 arrangement or contents of windows; therefore, if @var{forms} change
1751 them, the change persists.  If the previously selected window of some
1752 frame is no longer live at the time of exit from @var{forms}, that
1753 frame's selected window is left alone.  If the previously selected
1754 window is no longer live, then whatever window is selected at the end of
1755 @var{forms} remains selected.  The current buffer is restored if and
1756 only if it is still live when exiting @var{forms}.
1758 This macro changes neither the ordering of recently selected windows nor
1759 the buffer list.
1760 @end defmac
1762 @defmac with-selected-window window forms@dots{}
1763 This macro selects @var{window}, executes @var{forms} in sequence, then
1764 restores the previously selected window and current buffer.  The ordering
1765 of recently selected windows and the buffer list remain unchanged unless
1766 you deliberately change them within @var{forms}; for example, by calling
1767 @code{select-window} with argument @var{norecord} @code{nil}.
1769 This macro does not change the order of recently selected windows or
1770 the buffer list.
1771 @end defmac
1773 @defun frame-selected-window &optional frame
1774 This function returns the window on @var{frame} that is selected
1775 within that frame.  @var{frame} should be a live frame; if omitted or
1776 @code{nil}, it defaults to the selected frame.
1777 @end defun
1779 @defun set-frame-selected-window frame window &optional norecord
1780 This function makes @var{window} the window selected within the frame
1781 @var{frame}.  @var{frame} should be a live frame; if @code{nil}, it
1782 defaults to the selected frame.  @var{window} should be a live window;
1783 if @code{nil}, it defaults to the selected window.
1785 If @var{frame} is the selected frame, this makes @var{window} the
1786 selected window.
1788 If the optional argument @var{norecord} is non-@code{nil}, this
1789 function does not alter the list of most recently selected windows,
1790 nor the buffer list.
1791 @end defun
1793 @cindex window use time
1794 @cindex use time of window
1795 @cindex window order by time of last use
1796 @defun window-use-time &optional window
1797 This functions returns the use time of window @var{window}.
1798 @var{window} must be a live window and defaults to the selected one.
1800 The @dfn{use time} of a window is not really a time value, but an
1801 integer that does increase monotonically with each call of
1802 @code{select-window} with a @code{nil} @var{norecord} argument.  The
1803 window with the lowest use time is usually called the least recently
1804 used window while the window with the highest use time is called the
1805 most recently used one (@pxref{Cyclic Window Ordering}).
1806 @end defun
1809 @node Cyclic Window Ordering
1810 @section Cyclic Ordering of Windows
1811 @cindex cyclic ordering of windows
1812 @cindex ordering of windows, cyclic
1813 @cindex window ordering, cyclic
1815   When you use the command @kbd{C-x o} (@code{other-window}) to select
1816 some other window, it moves through live windows in a specific order.
1817 For any given configuration of windows, this order never varies.  It
1818 is called the @dfn{cyclic ordering of windows}.
1820   The ordering is determined by a depth-first traversal of each frame's
1821 window tree, retrieving the live windows which are the leaf nodes of the
1822 tree (@pxref{Windows and Frames}).  If the minibuffer is active, the
1823 minibuffer window is included too.  The ordering is cyclic, so the last
1824 window in the sequence is followed by the first one.
1826 @defun next-window &optional window minibuf all-frames
1827 @cindex minibuffer window, and @code{next-window}
1828 This function returns a live window, the one following @var{window} in
1829 the cyclic ordering of windows.  @var{window} should be a live window;
1830 if omitted or @code{nil}, it defaults to the selected window.
1832 The optional argument @var{minibuf} specifies whether minibuffer windows
1833 should be included in the cyclic ordering.  Normally, when @var{minibuf}
1834 is @code{nil}, a minibuffer window is included only if it is currently
1835 active; this matches the behavior of @kbd{C-x o}.  (Note that a
1836 minibuffer window is active as long as its minibuffer is in use; see
1837 @ref{Minibuffers}).
1839 If @var{minibuf} is @code{t}, the cyclic ordering includes all
1840 minibuffer windows.  If @var{minibuf} is neither @code{t} nor
1841 @code{nil}, minibuffer windows are not included even if they are active.
1843 The optional argument @var{all-frames} specifies which frames to
1844 consider:
1846 @itemize @bullet
1847 @item @code{nil}
1848 means to consider windows on @var{window}'s frame.  If the minibuffer
1849 window is considered (as specified by the @var{minibuf} argument),
1850 then frames that share the minibuffer window are considered too.
1852 @item @code{t}
1853 means to consider windows on all existing frames.
1855 @item @code{visible}
1856 means to consider windows on all visible frames.
1858 @item 0
1859 means to consider windows on all visible or iconified frames.
1861 @item A frame
1862 means to consider windows on that specific frame.
1864 @item Anything else
1865 means to consider windows on @var{window}'s frame, and no others.
1866 @end itemize
1868 If more than one frame is considered, the cyclic ordering is obtained
1869 by appending the orderings for those frames, in the same order as the
1870 list of all live frames (@pxref{Finding All Frames}).
1871 @end defun
1873 @defun previous-window &optional window minibuf all-frames
1874 This function returns a live window, the one preceding @var{window} in
1875 the cyclic ordering of windows.  The other arguments are handled like
1876 in @code{next-window}.
1877 @end defun
1879 @deffn Command other-window count &optional all-frames
1880 This function selects a live window, one @var{count} places from the
1881 selected window in the cyclic ordering of windows.  If @var{count} is
1882 a positive number, it skips @var{count} windows forwards; if
1883 @var{count} is negative, it skips @minus{}@var{count} windows
1884 backwards; if @var{count} is zero, that simply re-selects the selected
1885 window.  When called interactively, @var{count} is the numeric prefix
1886 argument.
1888 The optional argument @var{all-frames} has the same meaning as in
1889 @code{next-window}, like a @code{nil} @var{minibuf} argument to
1890 @code{next-window}.
1892 This function does not select a window that has a non-@code{nil}
1893 @code{no-other-window} window parameter (@pxref{Window Parameters}).
1894 @end deffn
1896 @defun walk-windows fun &optional minibuf all-frames
1897 This function calls the function @var{fun} once for each live window,
1898 with the window as the argument.
1900 It follows the cyclic ordering of windows.  The optional arguments
1901 @var{minibuf} and @var{all-frames} specify the set of windows
1902 included; these have the same arguments as in @code{next-window}.  If
1903 @var{all-frames} specifies a frame, the first window walked is the
1904 first window on that frame (the one returned by
1905 @code{frame-first-window}), not necessarily the selected window.
1907 If @var{fun} changes the window configuration by splitting or deleting
1908 windows, that does not alter the set of windows walked, which is
1909 determined prior to calling @var{fun} for the first time.
1910 @end defun
1912 @defun one-window-p &optional no-mini all-frames
1913 This function returns @code{t} if the selected window is the only live
1914 window, and @code{nil} otherwise.
1916 If the minibuffer window is active, it is normally considered (so that
1917 this function returns @code{nil}).  However, if the optional argument
1918 @var{no-mini} is non-@code{nil}, the minibuffer window is ignored even
1919 if active.  The optional argument @var{all-frames} has the same
1920 meaning as for @code{next-window}.
1921 @end defun
1923 @cindex finding windows
1924   The following functions return a window which satisfies some
1925 criterion, without selecting it:
1927 @cindex least recently used window
1928 @defun get-lru-window &optional all-frames dedicated not-selected
1929 This function returns a live window which is heuristically the least
1930 recently used.  The optional argument @var{all-frames} has
1931 the same meaning as in @code{next-window}.
1933 If any full-width windows are present, only those windows are
1934 considered.  A minibuffer window is never a candidate.  A dedicated
1935 window (@pxref{Dedicated Windows}) is never a candidate unless the
1936 optional argument @var{dedicated} is non-@code{nil}.  The selected
1937 window is never returned, unless it is the only candidate.  However, if
1938 the optional argument @var{not-selected} is non-@code{nil}, this
1939 function returns @code{nil} in that case.
1940 @end defun
1942 @cindex most recently used window
1943 @defun get-mru-window &optional all-frames dedicated not-selected
1944 This function is like @code{get-lru-window}, but it returns the most
1945 recently used window instead.  The meaning of the arguments is the
1946 same as described for @code{get-lru-window}.
1947 @end defun
1949 @cindex largest window
1950 @defun get-largest-window &optional all-frames dedicated not-selected
1951 This function returns the window with the largest area (height times
1952 width).  The optional argument @var{all-frames} specifies the windows to
1953 search, and has the same meaning as in @code{next-window}.
1955 A minibuffer window is never a candidate.  A dedicated window
1956 (@pxref{Dedicated Windows}) is never a candidate unless the optional
1957 argument @var{dedicated} is non-@code{nil}.  The selected window is not
1958 a candidate if the optional argument @var{not-selected} is
1959 non-@code{nil}.  If the optional argument @var{not-selected} is
1960 non-@code{nil} and the selected window is the only candidate, this
1961 function returns @code{nil}.
1963 If there are two candidate windows of the same size, this function
1964 prefers the one that comes first in the cyclic ordering of windows,
1965 starting from the selected window.
1966 @end defun
1968 @cindex window that satisfies a predicate
1969 @cindex conditional selection of windows
1970 @defun get-window-with-predicate predicate &optional minibuf all-frames default
1971 This function calls the function @var{predicate} for each of the
1972 windows in the cyclic order of windows in turn, passing it the window
1973 as an argument.  If the predicate returns non-@code{nil} for any
1974 window, this function stops and returns that window.  If no such
1975 window is found, the return value is @var{default} (which defaults to
1976 @code{nil}).
1978 The optional arguments @var{minibuf} and @var{all-frames} specify the
1979 windows to search, and have the same meanings as in
1980 @code{next-window}.
1981 @end defun
1984 @node Buffers and Windows
1985 @section Buffers and Windows
1986 @cindex examining windows
1987 @cindex windows, controlling precisely
1988 @cindex buffers, controlled in windows
1990   This section describes low-level functions for examining and setting
1991 the contents of windows.  @xref{Switching Buffers}, for higher-level
1992 functions for displaying a specific buffer in a window.
1994 @defun window-buffer &optional window
1995 This function returns the buffer that @var{window} is displaying.  If
1996 @var{window} is omitted or @code{nil} it defaults to the selected
1997 window.  If @var{window} is an internal window, this function returns
1998 @code{nil}.
1999 @end defun
2001 @defun set-window-buffer window buffer-or-name &optional keep-margins
2002 This function makes @var{window} display @var{buffer-or-name}.
2003 @var{window} should be a live window; if @code{nil}, it defaults to
2004 the selected window.  @var{buffer-or-name} should be a buffer, or the
2005 name of an existing buffer.  This function does not change which
2006 window is selected, nor does it directly change which buffer is
2007 current (@pxref{Current Buffer}).  Its return value is @code{nil}.
2009 If @var{window} is @dfn{strongly dedicated} to a buffer and
2010 @var{buffer-or-name} does not specify that buffer, this function
2011 signals an error.  @xref{Dedicated Windows}.
2013 By default, this function resets @var{window}'s position, display
2014 margins, fringe widths, and scroll bar settings, based on the local
2015 variables in the specified buffer.  However, if the optional argument
2016 @var{keep-margins} is non-@code{nil}, it leaves the display margins
2017 and fringe widths unchanged.
2019 When writing an application, you should normally use the higher-level
2020 functions described in @ref{Switching Buffers}, instead of calling
2021 @code{set-window-buffer} directly.
2023 This runs @code{window-scroll-functions}, followed by
2024 @code{window-configuration-change-hook}.  @xref{Window Hooks}.
2025 @end defun
2027 @defvar buffer-display-count
2028 This buffer-local variable records the number of times a buffer has been
2029 displayed in a window.  It is incremented each time
2030 @code{set-window-buffer} is called for the buffer.
2031 @end defvar
2033 @defvar buffer-display-time
2034 This buffer-local variable records the time at which a buffer was last
2035 displayed in a window.  The value is @code{nil} if the buffer has
2036 never been displayed.  It is updated each time
2037 @code{set-window-buffer} is called for the buffer, with the value
2038 returned by @code{current-time} (@pxref{Time of Day}).
2039 @end defvar
2041 @defun get-buffer-window &optional buffer-or-name all-frames
2042 This function returns the first window displaying @var{buffer-or-name}
2043 in the cyclic ordering of windows, starting from the selected window
2044 (@pxref{Cyclic Window Ordering}).  If no such window exists, the
2045 return value is @code{nil}.
2047 @var{buffer-or-name} should be a buffer or the name of a buffer; if
2048 omitted or @code{nil}, it defaults to the current buffer.  The
2049 optional argument @var{all-frames} specifies which windows to
2050 consider:
2052 @itemize @bullet
2053 @item
2054 @code{t} means consider windows on all existing frames.
2055 @item
2056 @code{visible} means consider windows on all visible frames.
2057 @item
2058 0 means consider windows on all visible or iconified frames.
2059 @item
2060 A frame means consider windows on that frame only.
2061 @item
2062 Any other value means consider windows on the selected frame.
2063 @end itemize
2065 Note that these meanings differ slightly from those of the
2066 @var{all-frames} argument to @code{next-window} (@pxref{Cyclic Window
2067 Ordering}).  This function may be changed in a future version of Emacs
2068 to eliminate this discrepancy.
2069 @end defun
2071 @defun get-buffer-window-list &optional buffer-or-name minibuf all-frames
2072 This function returns a list of all windows currently displaying
2073 @var{buffer-or-name}.  @var{buffer-or-name} should be a buffer or the
2074 name of an existing buffer.  If omitted or @code{nil}, it defaults to
2075 the current buffer.  If the currently selected window displays
2076 @var{buffer-or-name}, it will be the first in the list returned by
2077 this function.
2079 The arguments @var{minibuf} and @var{all-frames} have the same
2080 meanings as in the function @code{next-window} (@pxref{Cyclic Window
2081 Ordering}).  Note that the @var{all-frames} argument does @emph{not}
2082 behave exactly like in @code{get-buffer-window}.
2083 @end defun
2085 @deffn Command replace-buffer-in-windows &optional buffer-or-name
2086 This command replaces @var{buffer-or-name} with some other buffer, in
2087 all windows displaying it.  @var{buffer-or-name} should be a buffer, or
2088 the name of an existing buffer; if omitted or @code{nil}, it defaults to
2089 the current buffer.
2091 The replacement buffer in each window is chosen via
2092 @code{switch-to-prev-buffer} (@pxref{Window History}).  Any dedicated
2093 window displaying @var{buffer-or-name} is deleted if possible
2094 (@pxref{Dedicated Windows}).  If such a window is the only window on its
2095 frame and there are other frames on the same terminal, the frame is
2096 deleted as well.  If the dedicated window is the only window on the only
2097 frame on its terminal, the buffer is replaced anyway.
2098 @end deffn
2101 @node Switching Buffers
2102 @section Switching to a Buffer in a Window
2103 @cindex switching to a buffer
2104 @cindex displaying a buffer
2106 This section describes high-level functions for switching to a specified
2107 buffer in some window.  In general, ``switching to a buffer'' means to
2108 (1) show the buffer in some window, (2) make that window the selected
2109 window (and its frame the selected frame), and (3) make the buffer the
2110 current buffer.
2112   Do @emph{not} use these functions to make a buffer temporarily
2113 current just so a Lisp program can access or modify it.  They have
2114 side-effects, such as changing window histories (@pxref{Window
2115 History}), which will surprise the user if used that way.  If you want
2116 to make a buffer current to modify it in Lisp, use
2117 @code{with-current-buffer}, @code{save-current-buffer}, or
2118 @code{set-buffer}.  @xref{Current Buffer}.
2120 @deffn Command switch-to-buffer buffer-or-name &optional norecord force-same-window
2121 This command attempts to display @var{buffer-or-name} in the selected
2122 window and make it the current buffer.  It is often used interactively
2123 (as the binding of @kbd{C-x b}), as well as in Lisp programs.  The
2124 return value is the buffer switched to.
2126 If @var{buffer-or-name} is @code{nil}, it defaults to the buffer
2127 returned by @code{other-buffer} (@pxref{Buffer List}).  If
2128 @var{buffer-or-name} is a string that is not the name of any existing
2129 buffer, this function creates a new buffer with that name; the new
2130 buffer's major mode is determined by the variable @code{major-mode}
2131 (@pxref{Major Modes}).
2133 Normally, the specified buffer is put at the front of the buffer
2134 list---both the global buffer list and the selected frame's buffer
2135 list (@pxref{Buffer List}).  However, this is not done if the
2136 optional argument @var{norecord} is non-@code{nil}.
2138 Sometimes, the selected window may not be suitable for displaying the
2139 buffer.  This happens if the selected window is a minibuffer window, or
2140 if the selected window is strongly dedicated to its buffer
2141 (@pxref{Dedicated Windows}).  In such cases, the command normally tries
2142 to display the buffer in some other window, by invoking
2143 @code{pop-to-buffer} (see below).
2145 If the optional argument @var{force-same-window} is non-@code{nil} and
2146 the selected window is not suitable for displaying the buffer, this
2147 function always signals an error when called non-interactively.  In
2148 interactive use, if the selected window is a minibuffer window, this
2149 function will try to use some other window instead.  If the selected
2150 window is strongly dedicated to its buffer, the option
2151 @code{switch-to-buffer-in-dedicated-window} described next can be used
2152 to proceed.
2153 @end deffn
2155 @defopt switch-to-buffer-in-dedicated-window
2156 This option, if non-@code{nil}, allows @code{switch-to-buffer} to
2157 proceed when called interactively and the selected window is strongly
2158 dedicated to its buffer.
2160 The following values are respected:
2162 @table @code
2163 @item nil
2164 Disallows switching and signals an error as in non-interactive use.
2166 @item prompt
2167 Prompts the user whether to allow switching.
2169 @item pop
2170 Invokes @code{pop-to-buffer} to proceed.
2172 @item t
2173 Marks the selected window as non-dedicated and proceeds.
2174 @end table
2176 This option does not affect non-interactive calls of
2177 @code{switch-to-buffer}.
2178 @end defopt
2180 By default, @code{switch-to-buffer} tries to preserve
2181 @code{window-point}.  This behavior can be tuned using the following
2182 option.
2184 @defopt switch-to-buffer-preserve-window-point
2185 If this variable is @code{nil}, @code{switch-to-buffer} displays the
2186 buffer specified by @var{buffer-or-name} at the position of that
2187 buffer's @code{point}.  If this variable is @code{already-displayed}, it
2188 tries to display the buffer at its previous position in the selected
2189 window, provided the buffer is currently displayed in some other window
2190 on any visible or iconified frame.  If this variable is @code{t},
2191 @code{switch-to-buffer} unconditionally tries to display the buffer at
2192 its previous position in the selected window.
2194 This variable is ignored if the buffer is already displayed in the
2195 selected window or never appeared in it before, or if
2196 @code{switch-to-buffer} calls @code{pop-to-buffer} to display the
2197 buffer.
2198 @end defopt
2200 The next two commands are similar to @code{switch-to-buffer}, except for
2201 the described features.
2203 @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
2204 This function displays the buffer specified by @var{buffer-or-name} in
2205 some window other than the selected window.  It uses the function
2206 @code{pop-to-buffer} internally (see below).
2208 If the selected window already displays the specified buffer, it
2209 continues to do so, but another window is nonetheless found to display
2210 it as well.
2212 The @var{buffer-or-name} and @var{norecord} arguments have the same
2213 meanings as in @code{switch-to-buffer}.
2214 @end deffn
2216 @deffn Command switch-to-buffer-other-frame buffer-or-name &optional norecord
2217 This function displays the buffer specified by @var{buffer-or-name} in a
2218 new frame.  It uses the function @code{pop-to-buffer} internally (see
2219 below).
2221 If the specified buffer is already displayed in another window, in any
2222 frame on the current terminal, this switches to that window instead of
2223 creating a new frame.  However, the selected window is never used for
2224 this.
2226 The @var{buffer-or-name} and @var{norecord} arguments have the same
2227 meanings as in @code{switch-to-buffer}.
2228 @end deffn
2230 The above commands use the function @code{pop-to-buffer}, which
2231 flexibly displays a buffer in some window and selects that window for
2232 editing.  In turn, @code{pop-to-buffer} uses @code{display-buffer} for
2233 displaying the buffer.  Hence, all the variables affecting
2234 @code{display-buffer} will affect it as well.  @xref{Choosing Window},
2235 for the documentation of @code{display-buffer}.
2237 @deffn Command pop-to-buffer buffer-or-name &optional action norecord
2238 This function makes @var{buffer-or-name} the current buffer and
2239 displays it in some window, preferably not the window currently
2240 selected.  It then selects the displaying window.  If that window is
2241 on a different graphical frame, that frame is given input focus if
2242 possible (@pxref{Input Focus}).
2244 If @var{buffer-or-name} is @code{nil}, it defaults to the buffer
2245 returned by @code{other-buffer} (@pxref{Buffer List}).  If
2246 @var{buffer-or-name} is a string that is not the name of any existing
2247 buffer, this function creates a new buffer with that name; the new
2248 buffer's major mode is determined by the variable @code{major-mode}
2249 (@pxref{Major Modes}).  In any case, that buffer is made current and
2250 returned, even when no suitable window was found to display it.
2252 If @var{action} is non-@code{nil}, it should be a display action to
2253 pass to @code{display-buffer} (@pxref{Choosing Window}).
2254 Alternatively, a non-@code{nil}, non-list value means to pop to a
2255 window other than the selected one---even if the buffer is already
2256 displayed in the selected window.
2258 Like @code{switch-to-buffer}, this function updates the buffer list
2259 unless @var{norecord} is non-@code{nil}.
2260 @end deffn
2263 @node Choosing Window
2264 @section Choosing a Window for Display
2266   The command @code{display-buffer} flexibly chooses a window for
2267 display, and displays a specified buffer in that window.  It can be
2268 called interactively, via the key binding @kbd{C-x 4 C-o}.  It is also
2269 used as a subroutine by many functions and commands, including
2270 @code{switch-to-buffer} and @code{pop-to-buffer} (@pxref{Switching
2271 Buffers}).
2273 @cindex display action
2274 @cindex action function, for @code{display-buffer}
2275 @cindex action alist, for @code{display-buffer}
2276   This command performs several complex steps to find a window to
2277 display in.  These steps are described by means of @dfn{display
2278 actions}, which have the form @code{(@var{function} . @var{alist})}.
2279 Here, @var{function} is either a function or a list of functions,
2280 which we refer to as @dfn{action functions}; @var{alist} is an
2281 association list, which we refer to as an @dfn{action alist}.
2283   An action function accepts two arguments: the buffer to display and
2284 an action alist.  It attempts to display the buffer in some window,
2285 picking or creating a window according to its own criteria.  If
2286 successful, it returns the window; otherwise, it returns @code{nil}.
2287 @xref{Display Action Functions}, for a list of predefined action
2288 functions.
2290   @code{display-buffer} works by combining display actions from
2291 several sources, and calling the action functions in turn, until one
2292 of them manages to display the buffer and returns a non-@code{nil}
2293 value.
2295 @deffn Command display-buffer buffer-or-name &optional action frame
2296 This command makes @var{buffer-or-name} appear in some window, without
2297 selecting the window or making the buffer current.  The argument
2298 @var{buffer-or-name} must be a buffer or the name of an existing
2299 buffer.  The return value is the window chosen to display the buffer.
2301 The optional argument @var{action}, if non-@code{nil}, should normally
2302 be a display action (described above).  @code{display-buffer} builds a
2303 list of action functions and an action alist, by consolidating display
2304 actions from the following sources (in order):
2306 @itemize
2307 @item
2308 The variable @code{display-buffer-overriding-action}.
2310 @item
2311 The user option @code{display-buffer-alist}.
2313 @item
2314 The @var{action} argument.
2316 @item
2317 The user option @code{display-buffer-base-action}.
2319 @item
2320 The constant @code{display-buffer-fallback-action}.
2321 @end itemize
2323 @noindent
2324 Each action function is called in turn, passing the buffer as the
2325 first argument and the combined action alist as the second argument,
2326 until one of the functions returns non-@code{nil}.  The caller can
2327 pass @code{(allow-no-window . t)} as an element of the action alist to
2328 indicate its readiness to handle the case of not displaying the
2329 buffer in a window.
2331 The argument @var{action} can also have a non-@code{nil}, non-list
2332 value.  This has the special meaning that the buffer should be
2333 displayed in a window other than the selected one, even if the
2334 selected window is already displaying it.  If called interactively
2335 with a prefix argument, @var{action} is @code{t}.
2337 The optional argument @var{frame}, if non-@code{nil}, specifies which
2338 frames to check when deciding whether the buffer is already displayed.
2339 It is equivalent to adding an element @code{(reusable-frames
2340 . @var{frame})} to the action alist of @var{action}.  @xref{Display
2341 Action Functions}.
2342 @end deffn
2344 @defvar display-buffer-overriding-action
2345 The value of this variable should be a display action, which is
2346 treated with the highest priority by @code{display-buffer}.  The
2347 default value is empty, i.e., @code{(nil . nil)}.
2348 @end defvar
2350 @defopt display-buffer-alist
2351 The value of this option is an alist mapping conditions to display
2352 actions.  Each condition may be either a regular expression matching a
2353 buffer name or a function that takes two arguments: a buffer name and
2354 the @var{action} argument passed to @code{display-buffer}.  If the name
2355 of the buffer passed to @code{display-buffer} either matches a regular
2356 expression in this alist or the function specified by a condition
2357 returns non-@code{nil}, then @code{display-buffer} uses the
2358 corresponding display action to display the buffer.
2359 @end defopt
2361 @defopt display-buffer-base-action
2362 The value of this option should be a display action.  This option can
2363 be used to define a standard display action for calls to
2364 @code{display-buffer}.
2365 @end defopt
2367 @defvr Constant display-buffer-fallback-action
2368 This display action specifies the fallback behavior for
2369 @code{display-buffer} if no other display actions are given.
2370 @end defvr
2373 @node Display Action Functions
2374 @section Action Functions for @code{display-buffer}
2376 The following basic action functions are defined in Emacs.  Each of
2377 these functions takes two arguments: @var{buffer}, the buffer to
2378 display, and @var{alist}, an action alist.  Each action function
2379 returns the window if it succeeds, and @code{nil} if it fails.
2381 @defun display-buffer-same-window buffer alist
2382 This function tries to display @var{buffer} in the selected window.
2383 It fails if the selected window is a minibuffer window or is dedicated
2384 to another buffer (@pxref{Dedicated Windows}).  It also fails if
2385 @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry.
2386 @end defun
2388 @defun display-buffer-reuse-window buffer alist
2389 This function tries to display @var{buffer} by finding a window
2390 that is already displaying it.
2392 If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry,
2393 the selected window is not eligible for reuse.  If @var{alist}
2394 contains a @code{reusable-frames} entry, its value determines which
2395 frames to search for a reusable window:
2397 @itemize @bullet
2398 @item
2399 @code{nil} means consider windows on the selected frame.
2400 (Actually, the last non-minibuffer frame.)
2401 @item
2402 @code{t} means consider windows on all frames.
2403 @item
2404 @code{visible} means consider windows on all visible frames.
2405 @item
2406 0 means consider windows on all visible or iconified frames.
2407 @item
2408 A frame means consider windows on that frame only.
2409 @end itemize
2411 Note that these meanings differ slightly from those of the
2412 @var{all-frames} argument to @code{next-window} (@pxref{Cyclic Window
2413 Ordering}).
2415 If @var{alist} contains no @code{reusable-frames} entry, this function
2416 normally searches just the selected frame; however, if the variable
2417 @code{pop-up-frames} is non-@code{nil}, it searches all frames on the
2418 current terminal.  @xref{Choosing Window Options}.
2420 If this function chooses a window on another frame, it makes that frame
2421 visible and, unless @var{alist} contains an @code{inhibit-switch-frame}
2422 entry (@pxref{Choosing Window Options}), raises that frame if necessary.
2423 @end defun
2425 @defun display-buffer-reuse-mode-window buffer alist
2426 This function tries to display @var{buffer} by finding a window
2427 that is displaying a buffer in a given mode.
2429 If @var{alist} contains a @code{mode} entry, its value is a major mode
2430 (a symbol) or a list of major modes.  If @var{alist} contains no
2431 @code{mode} entry, the current major mode of @var{buffer} is used.  A
2432 window is a candidate if it displays a buffer that derives from one of
2433 the given modes.
2435 The behavior is also controlled by entries for
2436 @code{inhibit-same-window}, @code{reusable-frames} and
2437 @code{inhibit-switch-frame} as is done in the function
2438 @code{display-buffer-reuse-window}.
2440 @end defun
2442 @defun display-buffer-pop-up-frame buffer alist
2443 This function creates a new frame, and displays the buffer in that
2444 frame's window.  It actually performs the frame creation by calling
2445 the function specified in @code{pop-up-frame-function}
2446 (@pxref{Choosing Window Options}).  If @var{alist} contains a
2447 @code{pop-up-frame-parameters} entry, the associated value
2448 is added to the newly created frame's parameters.
2449 @end defun
2451 @defun display-buffer-use-some-frame buffer alist
2452 This function tries to display @var{buffer} by trying to find a
2453 frame that meets a predicate (by default any frame other than the
2454 current frame).
2456 If this function chooses a window on another frame, it makes that frame
2457 visible and, unless @var{alist} contains an @code{inhibit-switch-frame}
2458 entry (@pxref{Choosing Window Options}), raises that frame if necessary.
2460 If @var{alist} has a non-@code{nil} @code{frame-predicate} entry, its
2461 value is a function taking one argument (a frame), returning
2462 non-@code{nil} if the frame is a candidate; this function replaces the
2463 default predicate.
2465 If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry,
2466 the selected window is used; thus if the selected frame has a single
2467 window, it is not used.
2468 @end defun
2470 @defun display-buffer-pop-up-window buffer alist
2471 This function tries to display @var{buffer} by splitting the largest
2472 or least recently-used window (typically one on the selected frame).
2473 It actually performs the split by calling the function specified in
2474 @code{split-window-preferred-function} (@pxref{Choosing Window
2475 Options}).
2477 The size of the new window can be adjusted by supplying
2478 @code{window-height} and @code{window-width} entries in @var{alist}.  To
2479 adjust the window's height, use an entry whose @sc{car} is
2480 @code{window-height} and whose @sc{cdr} is one of:
2482 @itemize @bullet
2483 @item
2484 @code{nil} means to leave the height of the new window alone.
2486 @item
2487 A number specifies the desired height of the new window.  An integer
2488 specifies the number of lines of the window.  A floating-point
2489 number gives the fraction of the window's height with respect to the
2490 height of the frame's root window.
2492 @item
2493 If the @sc{cdr} specifies a function, that function is called with one
2494 argument: the new window.  The function is supposed to adjust the
2495 height of the window; its return value is ignored.  Suitable functions
2496 are @code{shrink-window-if-larger-than-buffer} and
2497 @code{fit-window-to-buffer}, see @ref{Resizing Windows}.
2498 @end itemize
2500 To adjust the window's width, use an entry whose @sc{car} is
2501 @code{window-width} and whose @sc{cdr} is one of:
2503 @itemize @bullet
2504 @item
2505 @code{nil} means to leave the width of the new window alone.
2507 @item
2508 A number specifies the desired width of the new window.  An integer
2509 specifies the number of columns of the window.  A floating-point
2510 number gives the fraction of the window's width with respect to the
2511 width of the frame's root window.
2513 @item
2514 If the @sc{cdr} specifies a function, that function is called with one
2515 argument: the new window.  The function is supposed to adjust the width
2516 of the window; its return value is ignored.
2517 @end itemize
2519 If @var{alist} contains a @code{preserve-size} entry, Emacs will try to
2520 preserve the size of the new window during future resize operations
2521 (@pxref{Preserving Window Sizes}).  The @sc{cdr} of that entry must be a
2522 cons cell whose @sc{car}, if non-@code{nil}, means to preserve the width
2523 of the window and whose @sc{cdr}, if non-@code{nil}, means to preserve
2524 the height of the window.
2526 This function can fail if no window splitting can be performed for some
2527 reason (e.g., if the selected frame has an @code{unsplittable} frame
2528 parameter; @pxref{Buffer Parameters}).
2529 @end defun
2531 @defun display-buffer-below-selected buffer alist
2532 This function tries to display @var{buffer} in a window below the
2533 selected window.  If there is a window below the selected one and that
2534 window already displays @var{buffer}, it reuses that window.
2536 If there is no such window, this function tries to create a new window
2537 by splitting the selected one and display @var{buffer} there.  It will
2538 also adjust that window's size provided @var{alist} contains a suitable
2539 @code{window-height} or @code{window-width} entry, see above.
2541 If splitting the selected window fails and there is a non-dedicated
2542 window below the selected one showing some other buffer, it uses that
2543 window for showing @var{buffer}.
2544 @end defun
2546 @defun display-buffer-in-previous-window buffer alist
2547 This function tries to display @var{buffer} in a window previously
2548 showing it.  If @var{alist} has a non-@code{nil}
2549 @code{inhibit-same-window} entry, the selected window is not eligible
2550 for reuse.  If @var{alist} contains a @code{reusable-frames} entry, its
2551 value determines which frames to search for a suitable window as with
2552 @code{display-buffer-reuse-window}.
2554 If @var{alist} has a @code{previous-window} entry, the window
2555 specified by that entry will override any other window found by the
2556 methods above, even if that window never showed @var{buffer} before.
2557 @end defun
2559 @defun display-buffer-at-bottom buffer alist
2560 This function tries to display @var{buffer} in a window at the bottom
2561 of the selected frame.
2563 This either splits the window at the bottom of the frame or the
2564 frame's root window, or reuses an existing window at the bottom of the
2565 selected frame.
2566 @end defun
2568 @defun display-buffer-use-some-window buffer alist
2569 This function tries to display @var{buffer} by choosing an existing
2570 window and displaying the buffer in that window.  It can fail if all
2571 windows are dedicated to another buffer (@pxref{Dedicated Windows}).
2572 @end defun
2574 @defun display-buffer-no-window buffer alist
2575 If @var{alist} has a non-@code{nil} @code{allow-no-window} entry, then
2576 this function does not display @code{buffer}.  This allows you to
2577 override the default action and avoid displaying the buffer.  It is
2578 assumed that when the caller specifies a non-@code{nil}
2579 @code{allow-no-window} value it can handle a @code{nil} value returned
2580 from @code{display-buffer} in this case.
2581 @end defun
2583 If the @var{alist} argument of any of these functions contains a
2584 @code{window-parameters} entry, @code{display-buffer} assigns the
2585 elements of the associated value as window parameters of the chosen
2586 window.
2588    To illustrate the use of action functions, consider the following
2589 example.
2591 @example
2592 @group
2593 (display-buffer
2594  (get-buffer-create "*foo*")
2595  '((display-buffer-reuse-window
2596     display-buffer-pop-up-window
2597     display-buffer-pop-up-frame)
2598    (reusable-frames . 0)
2599    (window-height . 10) (window-width . 40)))
2600 @end group
2601 @end example
2603 @noindent
2604 Evaluating the form above will cause @code{display-buffer} to proceed as
2605 follows: If a buffer called *foo* already appears on a visible or
2606 iconified frame, it will reuse its window.  Otherwise, it will try to
2607 pop up a new window or, if that is impossible, a new frame and show the
2608 buffer there.  If all these steps fail, it will proceed using whatever
2609 @code{display-buffer-base-action} and
2610 @code{display-buffer-fallback-action} prescribe.
2612    Furthermore, @code{display-buffer} will try to adjust a reused window
2613 (provided *foo* was put by @code{display-buffer} there before) or a
2614 popped-up window as follows: If the window is part of a vertical
2615 combination, it will set its height to ten lines.  Note that if, instead
2616 of the number 10, we specified the function
2617 @code{fit-window-to-buffer}, @code{display-buffer} would come up with a
2618 one-line window to fit the empty buffer.  If the window is part of a
2619 horizontal combination, it sets its width to 40 columns.  Whether a new
2620 window is vertically or horizontally combined depends on the shape of
2621 the window split and the values of
2622 @code{split-window-preferred-function}, @code{split-height-threshold}
2623 and @code{split-width-threshold} (@pxref{Choosing Window Options}).
2625    Now suppose we combine this call with a preexisting setup for
2626 @code{display-buffer-alist} as follows.
2628 @example
2629 @group
2630 (let ((display-buffer-alist
2631        (cons
2632         '("\\*foo\\*"
2633           (display-buffer-reuse-window display-buffer-below-selected)
2634           (reusable-frames)
2635           (window-height . 5))
2636         display-buffer-alist)))
2637   (display-buffer
2638    (get-buffer-create "*foo*")
2639    '((display-buffer-reuse-window
2640       display-buffer-pop-up-window
2641       display-buffer-pop-up-frame)
2642      (reusable-frames . 0)
2643      (window-height . 10) (window-width . 40))))
2644 @end group
2645 @end example
2647 @noindent
2648 This form will have @code{display-buffer} first try reusing a window
2649 that shows *foo* on the selected frame.  If there's no such window, it
2650 will try to split the selected window or, if that is impossible, use the
2651 window below the selected window.
2653    If there's no window below the selected one, or the window below the
2654 selected one is dedicated to its buffer, @code{display-buffer} will
2655 proceed as described in the previous example.  Note, however, that when
2656 it tries to adjust the height of any reused or popped-up window, it will
2657 in any case try to set its number of lines to 5 since that value
2658 overrides the corresponding specification in the @var{action} argument
2659 of @code{display-buffer}.
2662 @node Choosing Window Options
2663 @section Additional Options for Displaying Buffers
2665 The behavior of the standard display actions of @code{display-buffer}
2666 (@pxref{Choosing Window}) can be modified by a variety of user
2667 options.
2669 @defopt pop-up-windows
2670 If the value of this variable is non-@code{nil}, @code{display-buffer}
2671 is allowed to split an existing window to make a new window for
2672 displaying in.  This is the default.
2674 This variable is provided mainly for backward compatibility.  It is
2675 obeyed by @code{display-buffer} via a special mechanism in
2676 @code{display-buffer-fallback-action}, which only calls the action
2677 function @code{display-buffer-pop-up-window} (@pxref{Display Action
2678 Functions}) when the value is @code{nil}.  It is not consulted by
2679 @code{display-buffer-pop-up-window} itself, which the user may specify
2680 directly in @code{display-buffer-alist} etc.
2681 @end defopt
2683 @defopt split-window-preferred-function
2684 This variable specifies a function for splitting a window, in order to
2685 make a new window for displaying a buffer.  It is used by the
2686 @code{display-buffer-pop-up-window} action function to actually split
2687 the window (@pxref{Display Action Functions}).
2689 The default value is @code{split-window-sensibly}, which is documented
2690 below.  The value must be a function that takes one argument, a window,
2691 and return either a new window (which will be used to display the
2692 desired buffer) or @code{nil} (which means the splitting failed).
2693 @end defopt
2695 @defun split-window-sensibly &optional window
2696 This function tries to split @var{window}, and return the newly created
2697 window.  If @var{window} cannot be split, it returns @code{nil}.  If
2698 @var{window} is omitted or @code{nil}, it defaults to the selected
2699 window.
2701 This function obeys the usual rules that determine when a window may
2702 be split (@pxref{Splitting Windows}).  It first tries to split by
2703 placing the new window below, subject to the restriction imposed by
2704 @code{split-height-threshold} (see below), in addition to any other
2705 restrictions.  If that fails, it tries to split by placing the new
2706 window to the right, subject to @code{split-width-threshold} (see
2707 below).  If that fails, and the window is the only window on its
2708 frame, this function again tries to split and place the new window
2709 below, disregarding @code{split-height-threshold}.  If this fails as
2710 well, this function gives up and returns @code{nil}.
2711 @end defun
2713 @defopt split-height-threshold
2714 This variable, used by @code{split-window-sensibly}, specifies whether
2715 to split the window placing the new window below.  If it is an
2716 integer, that means to split only if the original window has at least
2717 that many lines.  If it is @code{nil}, that means not to split this
2718 way.
2719 @end defopt
2721 @defopt split-width-threshold
2722 This variable, used by @code{split-window-sensibly}, specifies whether
2723 to split the window placing the new window to the right.  If the value
2724 is an integer, that means to split only if the original window has at
2725 least that many columns.  If the value is @code{nil}, that means not
2726 to split this way.
2727 @end defopt
2729 @defopt even-window-sizes
2730 This variable, if non-@code{nil}, causes @code{display-buffer} to even
2731 window sizes whenever it reuses an existing window and that window is
2732 adjacent to the selected one.
2734 If its value is @code{width-only}, sizes are evened only if the reused
2735 window is on the left or right of the selected one and the selected
2736 window is wider than the reused one.  If its value is @code{height-only}
2737 sizes are evened only if the reused window is above or beneath the
2738 selected window and the selected window is higher than the reused one.
2739 Any other non-@code{nil} value means to even sizes in any of these cases
2740 provided the selected window is larger than the reused one in the sense
2741 of their combination.
2742 @end defopt
2744 @defopt pop-up-frames
2745 If the value of this variable is non-@code{nil}, that means
2746 @code{display-buffer} may display buffers by making new frames.  The
2747 default is @code{nil}.
2749 A non-@code{nil} value also means that when @code{display-buffer} is
2750 looking for a window already displaying @var{buffer-or-name}, it can
2751 search any visible or iconified frame, not just the selected frame.
2753 This variable is provided mainly for backward compatibility.  It is
2754 obeyed by @code{display-buffer} via a special mechanism in
2755 @code{display-buffer-fallback-action}, which calls the action function
2756 @code{display-buffer-pop-up-frame} (@pxref{Display Action Functions})
2757 if the value is non-@code{nil}.  (This is done before attempting to
2758 split a window.)  This variable is not consulted by
2759 @code{display-buffer-pop-up-frame} itself, which the user may specify
2760 directly in @code{display-buffer-alist} etc.
2761 @end defopt
2763 @defopt pop-up-frame-function
2764 This variable specifies a function for creating a new frame, in order
2765 to make a new window for displaying a buffer.  It is used by the
2766 @code{display-buffer-pop-up-frame} action function (@pxref{Display
2767 Action Functions}).
2769 The value should be a function that takes no arguments and returns a
2770 frame, or @code{nil} if no frame could be created.  The default value
2771 is a function that creates a frame using the parameters specified by
2772 @code{pop-up-frame-alist} (see below).
2773 @end defopt
2775 @defopt pop-up-frame-alist
2776 This variable holds an alist of frame parameters (@pxref{Frame
2777 Parameters}), which is used by the default function in
2778 @code{pop-up-frame-function} to make a new frame.  The default is
2779 @code{nil}.
2780 @end defopt
2782 @defopt same-window-buffer-names
2783 A list of buffer names for buffers that should be displayed in the
2784 selected window.  If a buffer's name is in this list,
2785 @code{display-buffer} handles the buffer by showing it in the selected
2786 window.
2787 @end defopt
2789 @defopt same-window-regexps
2790 A list of regular expressions that specify buffers that should be
2791 displayed in the selected window.  If the buffer's name matches any of
2792 the regular expressions in this list, @code{display-buffer} handles the
2793 buffer by showing it in the selected window.
2794 @end defopt
2796 @defun same-window-p buffer-name
2797 This function returns @code{t} if displaying a buffer
2798 named @var{buffer-name} with @code{display-buffer} would
2799 put it in the selected window.
2800 @end defun
2802 @node Window History
2803 @section Window History
2804 @cindex window history
2806 Each window remembers in a list the buffers it has previously displayed,
2807 and the order in which these buffers were removed from it.  This history
2808 is used, for example, by @code{replace-buffer-in-windows}
2809 (@pxref{Buffers and Windows}).  The list is automatically maintained by
2810 Emacs, but you can use the following functions to explicitly inspect or
2811 alter it:
2813 @defun window-prev-buffers &optional window
2814 This function returns a list specifying the previous contents of
2815 @var{window}.  The optional argument @var{window} should be a live
2816 window and defaults to the selected one.
2818 Each list element has the form @code{(@var{buffer} @var{window-start}
2819 @var{window-pos})}, where @var{buffer} is a buffer previously shown in
2820 the window, @var{window-start} is the window start position
2821 (@pxref{Window Start and End}) when that buffer was last shown, and
2822 @var{window-pos} is the point position (@pxref{Window Point}) when
2823 that buffer was last shown in @var{window}.
2825 The list is ordered so that earlier elements correspond to more
2826 recently-shown buffers, and the first element usually corresponds to the
2827 buffer most recently removed from the window.
2828 @end defun
2830 @defun set-window-prev-buffers window prev-buffers
2831 This function sets @var{window}'s previous buffers to the value of
2832 @var{prev-buffers}.  The argument @var{window} must be a live window
2833 and defaults to the selected one.  The argument @var{prev-buffers}
2834 should be a list of the same form as that returned by
2835 @code{window-prev-buffers}.
2836 @end defun
2838 In addition, each buffer maintains a list of @dfn{next buffers}, which
2839 is a list of buffers re-shown by @code{switch-to-prev-buffer} (see
2840 below).  This list is mainly used by @code{switch-to-prev-buffer} and
2841 @code{switch-to-next-buffer} for choosing buffers to switch to.
2843 @defun window-next-buffers &optional window
2844 This function returns the list of buffers recently re-shown in
2845 @var{window} via @code{switch-to-prev-buffer}.  The @var{window}
2846 argument must denote a live window or @code{nil} (meaning the selected
2847 window).
2848 @end defun
2850 @defun set-window-next-buffers window next-buffers
2851 This function sets the next buffer list of @var{window} to
2852 @var{next-buffers}.  The @var{window} argument should be a live window
2853 or @code{nil} (meaning the selected window).  The argument
2854 @var{next-buffers} should be a list of buffers.
2855 @end defun
2857 The following commands can be used to cycle through the global buffer
2858 list, much like @code{bury-buffer} and @code{unbury-buffer}.  However,
2859 they cycle according to the specified window's history list, rather
2860 than the global buffer list.  In addition, they restore
2861 window-specific window start and point positions, and may show a
2862 buffer even if it is already shown in another window.  The
2863 @code{switch-to-prev-buffer} command, in particular, is used by
2864 @code{replace-buffer-in-windows}, @code{bury-buffer} and
2865 @code{quit-window} to find a replacement buffer for a window.
2867 @deffn Command switch-to-prev-buffer &optional window bury-or-kill
2868 This command displays the previous buffer in @var{window}.  The
2869 argument @var{window} should be a live window or @code{nil} (meaning
2870 the selected window).  If the optional argument @var{bury-or-kill} is
2871 non-@code{nil}, this means that the buffer currently shown in
2872 @var{window} is about to be buried or killed and consequently should
2873 not be switched to in future invocations of this command.
2875 The previous buffer is usually the buffer shown before the buffer
2876 currently shown in @var{window}.  However, a buffer that has been buried
2877 or killed, or has been already shown by a recent invocation of
2878 @code{switch-to-prev-buffer}, does not qualify as previous buffer.
2880 If repeated invocations of this command have already shown all buffers
2881 previously shown in @var{window}, further invocations will show buffers
2882 from the buffer list of the frame @var{window} appears on (@pxref{Buffer
2883 List}), trying to skip buffers that are already shown in another window
2884 on that frame.
2885 @end deffn
2887 @deffn Command switch-to-next-buffer &optional window
2888 This command switches to the next buffer in @var{window}, thus undoing
2889 the effect of the last @code{switch-to-prev-buffer} command in
2890 @var{window}.  The argument @var{window} must be a live window and
2891 defaults to the selected one.
2893 If there is no recent invocation of @code{switch-to-prev-buffer} that
2894 can be undone, this function tries to show a buffer from the buffer list
2895 of the frame @var{window} appears on (@pxref{Buffer List}).
2896 @end deffn
2898 By default @code{switch-to-prev-buffer} and @code{switch-to-next-buffer}
2899 can switch to a buffer that is already shown in another window on the
2900 same frame.  The following option can be used to override this behavior.
2902 @defopt switch-to-visible-buffer
2903 If this variable is non-@code{nil}, @code{switch-to-prev-buffer} and
2904 @code{switch-to-next-buffer} may switch to a buffer that is already
2905 visible on the same frame, provided the buffer was shown in the
2906 relevant window before.  If it is @code{nil},
2907 @code{switch-to-prev-buffer} and @code{switch-to-next-buffer} always
2908 try to avoid switching to a buffer that is already visible in another
2909 window on the same frame.  The default is @code{t}.
2910 @end defopt
2913 @node Dedicated Windows
2914 @section Dedicated Windows
2915 @cindex dedicated window
2917 Functions for displaying a buffer can be told to not use specific
2918 windows by marking these windows as @dfn{dedicated} to their buffers.
2919 @code{display-buffer} (@pxref{Choosing Window}) never uses a dedicated
2920 window for displaying another buffer in it.  @code{get-lru-window} and
2921 @code{get-largest-window} (@pxref{Cyclic Window Ordering}) do not
2922 consider dedicated windows as candidates when their @var{dedicated}
2923 argument is non-@code{nil}.  The behavior of @code{set-window-buffer}
2924 (@pxref{Buffers and Windows}) with respect to dedicated windows is
2925 slightly different, see below.
2927    Functions supposed to remove a buffer from a window or a window from
2928 a frame can behave specially when a window they operate on is dedicated.
2929 We will distinguish three basic cases, namely where (1) the window is
2930 not the only window on its frame, (2) the window is the only window on
2931 its frame but there are other frames on the same terminal left, and (3)
2932 the window is the only window on the only frame on the same terminal.
2934    In particular, @code{delete-windows-on} (@pxref{Deleting Windows})
2935 handles case (2) by deleting the associated frame and case (3) by
2936 showing another buffer in that frame's only window.  The function
2937 @code{replace-buffer-in-windows} (@pxref{Buffers and Windows}) which is
2938 called when a buffer gets killed, deletes the window in case (1) and
2939 behaves like @code{delete-windows-on} otherwise.
2940 @c FIXME: Does replace-buffer-in-windows _delete_ a window in case (1)?
2942    When @code{bury-buffer} (@pxref{Buffer List}) operates on the
2943 selected window (which shows the buffer that shall be buried), it
2944 handles case (2) by calling @code{frame-auto-hide-function}
2945 (@pxref{Quitting Windows}) to deal with the selected frame.  The other
2946 two cases are handled as with @code{replace-buffer-in-windows}.
2948 @defun window-dedicated-p &optional window
2949 This function returns non-@code{nil} if @var{window} is dedicated to its
2950 buffer and @code{nil} otherwise.  More precisely, the return value is
2951 the value assigned by the last call of @code{set-window-dedicated-p} for
2952 @var{window}, or @code{nil} if that function was never called with
2953 @var{window} as its argument.  The default for @var{window} is the
2954 selected window.
2955 @end defun
2957 @defun set-window-dedicated-p window flag
2958 This function marks @var{window} as dedicated to its buffer if
2959 @var{flag} is non-@code{nil}, and non-dedicated otherwise.
2961 As a special case, if @var{flag} is @code{t}, @var{window} becomes
2962 @dfn{strongly} dedicated to its buffer.  @code{set-window-buffer}
2963 signals an error when the window it acts upon is strongly dedicated to
2964 its buffer and does not already display the buffer it is asked to
2965 display.  Other functions do not treat @code{t} differently from any
2966 non-@code{nil} value.
2967 @end defun
2970 @node Quitting Windows
2971 @section Quitting Windows
2973 When you want to get rid of a window used for displaying a buffer, you
2974 can call @code{delete-window} or @code{delete-windows-on}
2975 (@pxref{Deleting Windows}) to remove that window from its frame.  If the
2976 buffer is shown on a separate frame, you might want to call
2977 @code{delete-frame} (@pxref{Deleting Frames}) instead.  If, on the other
2978 hand, a window has been reused for displaying the buffer, you might
2979 prefer showing the buffer previously shown in that window, by calling the
2980 function @code{switch-to-prev-buffer} (@pxref{Window History}).
2981 Finally, you might want to either bury (@pxref{Buffer List}) or kill
2982 (@pxref{Killing Buffers}) the window's buffer.
2984    The following command uses information on how the window for
2985 displaying the buffer was obtained in the first place, thus attempting
2986 to automate the above decisions for you.
2988 @deffn Command quit-window &optional kill window
2989 This command quits @var{window} and buries its buffer.  The argument
2990 @var{window} must be a live window and defaults to the selected one.
2991 With prefix argument @var{kill} non-@code{nil}, it kills the buffer
2992 instead of burying it.  It calls the function @code{quit-restore-window}
2993 described next to deal with the window and its buffer.
2994 @end deffn
2996 @defun quit-restore-window &optional window bury-or-kill
2997 This function tries to restore the state of @var{window} that existed
2998 before its buffer was displayed in it.  The optional argument
2999 @var{window} must be a live window and defaults to the selected one.
3001 If @var{window} was created specially for displaying its buffer, this
3002 function deletes @var{window} provided its frame contains at least one
3003 other live window.  If @var{window} is the only window on its frame and
3004 there are other frames on the frame's terminal, the value of the
3005 optional argument @var{bury-or-kill} determines how to proceed with the
3006 window.  If @var{bury-or-kill} equals @code{kill}, the frame is deleted
3007 unconditionally.  Otherwise, the fate of the frame is determined by
3008 calling @code{frame-auto-hide-function} (see below) with that frame as
3009 sole argument.
3011 Otherwise, this function tries to redisplay the buffer previously shown
3012 in @var{window}.  It also tries to restore the window start
3013 (@pxref{Window Start and End}) and point (@pxref{Window Point})
3014 positions of the previously shown buffer.  If, in addition,
3015 @var{window}'s buffer was temporarily resized, this function will also
3016 try to restore the original height of @var{window}.
3018 The cases described so far require that the buffer shown in @var{window}
3019 is still the buffer displayed by the last buffer display function for
3020 this window.  If another buffer has been shown in the meantime, or the
3021 buffer previously shown no longer exists, this function calls
3022 @code{switch-to-prev-buffer} (@pxref{Window History}) to show some other
3023 buffer instead.
3025 The optional argument @var{bury-or-kill} specifies how to deal with
3026 @var{window}'s buffer.  The following values are handled:
3028 @table @code
3029 @item nil
3030 This means to not deal with the buffer in any particular way.  As a
3031 consequence, if @var{window} is not deleted, invoking
3032 @code{switch-to-prev-buffer} will usually show the buffer again.
3034 @item append
3035 This means that if @var{window} is not deleted, its buffer is moved to
3036 the end of @var{window}'s list of previous buffers, so it's less likely
3037 that a future invocation of @code{switch-to-prev-buffer} will switch to
3038 it.  Also, it moves the buffer to the end of the frame's buffer list.
3040 @item bury
3041 This means that if @var{window} is not deleted, its buffer is removed
3042 from @var{window}'s list of previous buffers.  Also, it moves the buffer
3043 to the end of the frame's buffer list.  This value provides the most
3044 reliable remedy to not have @code{switch-to-prev-buffer} switch to this
3045 buffer again without killing the buffer.
3047 @item kill
3048 This means to kill @var{window}'s buffer.
3049 @end table
3051 @code{quit-restore-window} bases its decisions on information stored in
3052 @var{window}'s @code{quit-restore} window parameter (@pxref{Window
3053 Parameters}), and resets that parameter to @code{nil} after it's done.
3054 @end defun
3056 The following option specifies how to deal with a frame containing just
3057 one window that should be either quit, or whose buffer should be buried.
3059 @defopt frame-auto-hide-function
3060 The function specified by this option is called to automatically hide
3061 frames.  This function is called with one argument---a frame.
3063 The function specified here is called by @code{bury-buffer}
3064 (@pxref{Buffer List}) when the selected window is dedicated and shows
3065 the buffer to bury.  It is also called by @code{quit-restore-window}
3066 (see above) when the frame of the window to quit has been specially
3067 created for displaying that window's buffer and the buffer is not
3068 killed.
3070 The default is to call @code{iconify-frame} (@pxref{Visibility of
3071 Frames}).  Alternatively, you may specify either @code{delete-frame}
3072 (@pxref{Deleting Frames}) to remove the frame from its display,
3073 @code{ignore} to leave the frame unchanged, or any other function that
3074 can take a frame as its sole argument.
3076 Note that the function specified by this option is called only if the
3077 specified frame contains just one live window and there is at least one
3078 other frame on the same terminal.
3079 @end defopt
3082 @node Side Windows
3083 @section Side Windows
3084 @cindex side windows
3085 @cindex main window
3086 @cindex main window of a frame
3088 Side windows are special windows positioned at any of the four sides of
3089 a frame's root window (@pxref{Windows and Frames}).  In practice, this
3090 means that the area of the frame's root window is subdivided into a main
3091 window and a number of side windows surrounding that main window.  The
3092 main window is either a ``normal'' live window or specifies the area
3093 containing all the normal windows.
3095    In their most simple form of use, side windows allow to display
3096 specific buffers always in the same area of a frame.  Hence they can be
3097 regarded as a generalization of the concept provided by
3098 @code{display-buffer-at-bottom} (@pxref{Display Action Functions}) to
3099 the remaining sides of a frame.  With suitable customizations, however,
3100 side windows can be also used to provide frame layouts similar to those
3101 found in so-called integrated development environments (IDEs).
3103 @menu
3104 * Displaying Buffers in Side Windows:: An action function for displaying
3105                               buffers in side windows.
3106 * Side Window Options and Functions:: Further tuning of side windows.
3107 * Frame Layouts with Side Windows:: Setting up frame layouts with side
3108                               windows.
3109 @end menu
3112 @node Displaying Buffers in Side Windows
3113 @subsection Displaying Buffers in Side Windows
3115 The following action function for @code{display-buffer} (@pxref{Display
3116 Action Functions}) creates or reuses a side window for displaying the
3117 specified buffer.
3119 @defun display-buffer-in-side-window buffer alist
3120 This function displays @var{buffer} in a side window of the selected
3121 frame.  It returns the window used for displaying @var{buffer},
3122 @code{nil} if no such window can be found or created.
3124 @var{alist} is an association list of symbols and values as for
3125 @code{display-buffer}.  The following symbols in @var{alist} are special
3126 for this function:
3128 @table @code
3129 @item side
3130 Denotes the side of the frame where the window shall be located.  Valid
3131 values are @code{left}, @code{top}, @code{right} and @code{bottom}.  If
3132 unspecified, the window is located at the bottom of the frame.
3134 @item slot
3135 Denotes a slot at the specified side where to locate the window.  A
3136 value of zero means to preferably position the window in the middle of
3137 the specified side.  A negative value means to use a slot preceding
3138 (that is, above or on the left of) the middle slot.  A positive value
3139 means to use a slot following (that is, below or on the right of) the
3140 middle slot.  Hence, all windows on a specific side are ordered by their
3141 @code{slot} value.  If unspecified, the window is located in the middle
3142 of the specified side.
3143 @end table
3145 If you specify the same slot on the same side for two or more different
3146 buffers, the buffer displayed last is shown in the corresponding window.
3147 Hence, slots can be used for sharing the same side window between
3148 buffers.
3150 This function installs the @code{window-side} and @code{window-slot}
3151 parameters (@pxref{Window Parameters}) and makes them persistent.  It
3152 does not install any other window parameters unless they have been
3153 explicitly provided via a @code{window-parameters} entry in @var{alist}.
3154 @end defun
3156 By default, side windows cannot be split via @code{split-window}
3157 (@pxref{Splitting Windows}).  Also, a side window is not reused or split
3158 by any buffer display action (@pxref{Display Action Functions}) unless
3159 it is explicitly specified as target of that action.  Note also that
3160 @code{delete-other-windows} cannot make a side window the only window on
3161 its frame (@pxref{Deleting Windows}).
3163    Once set up, side windows also change the behavior of the commands
3164 @code{switch-to-prev-buffer} and @code{switch-to-next-buffer}
3165 (@pxref{Window History}).  In particular, these commands will refrain
3166 from showing, in a side window, buffers that have not been displayed in
3167 that window before.  They will also refrain from having a normal,
3168 non-side window show a buffer that has been already displayed in a side
3169 window.  A notable exception to the latter rule occurs when an
3170 application, after displaying a buffer, resets that buffer's local
3171 variables.
3174 @node Side Window Options and Functions
3175 @subsection Side Window Options and Functions
3177 The following options provide additional control over the placement of
3178 side windows.
3180 @defopt window-sides-vertical
3181 If non-@code{nil}, the side windows on the left and right of a frame
3182 occupy the frame's full height.  Otherwise, the side windows on the top
3183 and bottom of the frame occupy the frame's full width.
3184 @end defopt
3186 @defopt window-sides-slots
3187 This option specifies the maximum number of side windows on each side of
3188 a frame.  The value is a list of four elements specifying the number of
3189 side window slots on (in this order) the left, top, right and bottom of
3190 each frame.  If an element is a number, it means to display at most that
3191 many windows on the corresponding side.  If an element is @code{nil}, it
3192 means there's no bound on the number of slots on that side.
3194 If any of the specified values is zero, no window can be created on the
3195 corresponding side.  @code{display-buffer-in-side-window} will not
3196 signal an error in that case, but will return @code{nil}.  If a specified
3197 value just forbids the creation of an additional side window, the most
3198 suitable window on that side is reused and may have its
3199 @code{window-slot} parameter changed accordingly.
3200 @end defopt
3202 @defopt window-sides-reversed
3203 This option specifies whether top/bottom side windows should appear in
3204 reverse order.  When this is @code{nil}, side windows on the top and
3205 bottom of a frame are always drawn from left to right with increasing
3206 slot values.  When this is @code{t}, the drawing order is reversed and
3207 side windows on the top and bottom of a frame are drawn from right to
3208 left with increasing slot values.
3210 When this is @code{bidi}, the drawing order is reversed if and only if
3211 the value of @code{bidi-paragraph-direction} (@pxref{Bidirectional
3212 Display}) is @code{right-to-left} in the buffer displayed in the window
3213 most recently selected within the main window area of this frame.
3214 Sometimes that window may be hard to find, so heuristics are used to
3215 avoid that the drawing order changes inadvertently when another window
3216 gets selected.
3218 The layout of side windows on the left or right of a frame is not
3219 affected by the value of this variable.
3220 @end defopt
3222 When a frame has side windows, the following function returns the main
3223 window of that frame.
3225 @defun window-main-window &optional frame
3226 This function returns the main window of the specified @var{frame}.  The
3227 optional argument @var{frame} must be a live frame and defaults to the
3228 selected one.
3230 If @var{frame} has no side windows, it returns @var{frame}'s root
3231 window.  Otherwise, it returns either an internal non-side window such
3232 that all other non-side windows on @var{frame} descend from it, or the
3233 single live non-side window of @var{frame}.  Note that the main window
3234 of a frame cannot be deleted via @code{delete-window}.
3235 @end defun
3237 The following command is handy to toggle the appearance of all side
3238 windows on a specified frame.
3240 @deffn Command window-toggle-side-windows &optional frame
3241 This command toggles side windows on the specified @var{frame}.  The
3242 optional argument @var{frame} must be a live frame and defaults to the
3243 selected one.
3245 If @var{frame} has at least one side window, this command saves the
3246 state of @var{frame}'s root window in the @var{frame}'s
3247 @code{window-state} frame parameter and deletes all side windows on
3248 @var{frame} afterwards.
3250 If @var{frame} has no side windows, but does have a @code{window-state}
3251 parameter, this command uses that parameter's value to restore the side
3252 windows on @var{frame} leaving @var{frame}'s main window alone.
3254 An error is signaled if @var{frame} has no side windows and no saved
3255 state is found for it.
3256 @end deffn
3259 @node Frame Layouts with Side Windows
3260 @subsection Frame Layouts with Side Windows
3262 Side windows can be used to create more complex frame layouts like those
3263 provided by integrated development environments (IDEs).  In such
3264 layouts, the area of the main window is where the normal editing
3265 activities take place.  Side windows are not conceived for editing in
3266 the usual sense.  Rather, they are supposed to display information
3267 complementary to the current editing activity, like lists of files, tags
3268 or buffers, help information, search or grep results or shell output.
3270    The layout of such a frame might appear as follows:
3272 @smallexample
3273 @group
3274      ___________________________________
3275     |          *Buffer List*            |
3276     |___________________________________|
3277     |     |                       |     |
3278     |  *  |                       |  *  |
3279     |  d  |                       |  T  |
3280     |  i  |                       |  a  |
3281     |  r  |   Main Window Area    |  g  |
3282     |  e  |                       |  s  |
3283     |  d  |                       |  *  |
3284     |  *  |                       |     |
3285     |_____|_______________________|_____|
3286     | *help*/*grep*/  |  *shell*/       |
3287     | *Completions*   |  *compilation*  |
3288     |_________________|_________________|
3289     |             Echo Area             |
3290     |___________________________________|
3293 @end group
3294 @end smallexample
3296 The following example illustrates how window parameters (@pxref{Window
3297 Parameters}) can be used with @code{display-buffer-in-side-window}
3298 (@pxref{Displaying Buffers in Side Windows}) to set up code for
3299 producing the frame layout sketched above.
3301 @example
3302 @group
3303 (defvar parameters
3304   '(window-parameters . ((no-other-window . t) (no-delete-other-window . t))))
3306 (setq fit-window-to-buffer-horizontally t)
3307 (setq window-resize-pixelwise t)
3309 (setq
3310  display-buffer-alist
3311  `(("\\*Buffer List\\*" display-buffer-in-side-window
3312     (side . top) (slot . 0) (window-height . fit-window-to-buffer)
3313     (preserve-size . (nil . t)) ,parameters)
3314    ("\\*Tags List\\*" display-buffer-in-side-window
3315     (side . right) (slot . 0) (window-width . fit-window-to-buffer)
3316     (preserve-size . (t . nil)) ,parameters)
3317    ("\\*\\(?:help\\|grep\\|Completions\\)\\*" display-buffer-in-side-window
3318     (side . bottom) (slot . -1) (preserve-size . (nil . t)) ,parameters)
3319    ("\\*\\(?:shell\\|compilation\\)\\*" display-buffer-in-side-window
3320     (side . bottom) (slot . 1) (preserve-size . (nil . t)) ,parameters)))
3321 @end group
3322 @end example
3324 This specifies @code{display-buffer-alist} entries (@pxref{Choosing
3325 Window}) for buffers with fixed names.  In particular, it asks for
3326 showing @file{*Buffer List*} with adjustable height at the top of the
3327 frame and @file{*Tags List*} with adjustable width on the frame's right.
3328 It also asks for having the @file{*help*}, @file{*grep*} and
3329 @file{*Completions*} buffers share a window on the bottom left side of
3330 the frame and the @file{*shell*} and @file{*compilation*} buffers appear
3331 in a window on the bottom right side of the frame.
3333    Note that the option @code{fit-window-to-buffer-horizontally} must
3334 have a non-@code{nil} value in order to allow horizontal adjustment of
3335 windows.  Entries are also added that ask for preserving the height of
3336 side windows at the top and bottom of the frame and the width of side
3337 windows at the left or right of the frame.  To assure that side windows
3338 retain their respective sizes when maximizing the frame, the variable
3339 @code{window-resize-pixelwise} is set to a non-@code{nil} value.
3340 @xref{Resizing Windows}.
3342    The last form also makes sure that none of the created side windows
3343 are accessible via @kbd{C-x o} by installing the @code{no-other-window}
3344 parameter for each of these windows.  In addition, it makes sure that
3345 side windows are not deleted via @kbd{C-x 1} by installing the
3346 @code{no-delete-other-window} parameter for each of these windows.
3348    Since @code{dired} buffers have no fixed names, we use a special
3349 function @code{dired-default-directory-on-left} in order to display a
3350 lean directory buffer on the left side of the frame.
3352 @example
3353 @group
3354 (defun dired-default-directory-on-left ()
3355   "Display `default-directory' in side window on left, hiding details."
3356   (interactive)
3357   (let ((buffer (dired-noselect default-directory)))
3358     (with-current-buffer buffer (dired-hide-details-mode t))
3359     (display-buffer-in-side-window
3360      buffer `((side . left) (slot . 0)
3361               (window-width . fit-window-to-buffer)
3362               (preserve-size . (t . nil)) ,parameters))))
3363 @end group
3364 @end example
3366 Evaluating the preceding forms and typing, in any order, @w{@kbd{M-x
3367 list-buffers}}, @kbd{C-h f}, @kbd{M-x shell}, @w{@kbd{M-x list-tags}},
3368 and @kbd{M-x dired-default-directory-on-left} should now reproduce the
3369 frame layout sketched above.
3372 @node Atomic Windows
3373 @section Atomic Windows
3374 @cindex atomic windows
3376 Atomic windows are rectangular compositions of at least two live
3377 windows.  They have the following distinctive characteristics:
3379 @itemize @bullet
3380 @item
3381 The function @code{split-window} (@pxref{Splitting Windows}), when
3382 applied to a constituent of an atomic window, will try to create the new
3383 window outside of the atomic window.
3385 @item
3386 The function @code{delete-window} (@pxref{Deleting Windows}), when
3387 applied to a constituent of an atomic window, will try to delete the
3388 entire atomic window instead.
3390 @item
3391 The function @code{delete-other-windows} (@pxref{Deleting Windows}),
3392 when applied to a constituent of an atomic window, will try to make the
3393 atomic window fill its frame or main window (@pxref{Side Windows}).
3394 @end itemize
3396 This means that the basic groups of functions that alter the window
3397 structure treat an atomic window like a live one, thus preserving the
3398 internal structure of the atomic window.
3400    Atomic windows are useful to construct and preserve window layouts
3401 that are meaningful only when all involved buffers are shown
3402 simultaneously in a specific manner, such as when showing differences
3403 between file revisions, or the same text in different languages or
3404 markups.  They can also be used to permanently display information
3405 pertinent to a specific window in bars on that window's sides.
3407 @cindex root window of atomic window
3408    Atomic windows are implemented with the help of the reserved
3409 @code{window-atom} window parameter (@pxref{Window Parameters}) and an
3410 internal window (@pxref{Basic Windows}) called the root window of the
3411 atomic window.  All windows that are part of the same atomic window have
3412 this root window as their common ancestor and are assigned a
3413 non-@code{nil} @code{window-atom} parameter.
3415   The following function returns the root of the atomic window a
3416 specified window is part of:
3418 @defun window-atom-root &optional window
3419 This functions returns the root of the atomic window @var{window} is a
3420 part of.  The specified @var{window} must be a valid window and defaults
3421 to the selected one.  It returns @code{nil} if @var{window} is not part
3422 of an atomic window.
3423 @end defun
3425 The most simple approach to make a new atomic window is to take an
3426 existing internal window and apply the following function:
3428 @defun window-make-atom window
3429 This function converts @var{window} into an atomic window.  The
3430 specified @var{window} must be an internal window.  All this function
3431 does is to set the @code{window-atom} parameter of each descendant of
3432 @var{window} to @code{t}.
3433 @end defun
3435 To create a new atomic window from an existing live window or to add a
3436 new window to an existing atomic window, the following buffer display
3437 action function (@pxref{Display Action Functions}) can be used:
3439 @defun display-buffer-in-atom-window buffer alist
3440 This function tries to display @var{buffer} in a new window that will be
3441 combined with an existing window to form an atomic window.  If the
3442 existing window is already part of an atomic window, it adds the new
3443 window to that atomic window.
3445 The specified @var{alist} is an association list of symbols and values.
3446 The following symbols have a special meaning:
3448 @table @code
3449 @item window
3450 The value of such an element specifies an existing window the new window
3451 shall be combined with.  If it specifies an internal window, all
3452 children of that window become part of the atomic window too.  If no
3453 window is specified, the new window becomes a sibling of the selected
3454 window.  The @code{window-atom} parameter of the existing window is set
3455 to @code{main} provided that window is live and its @code{window-atom}
3456 parameter was not already set.
3458 @item side
3459 The value of such an element denotes the side of the existing window
3460 where the new window shall be located.  Valid values are @code{below},
3461 @code{right}, @code{above} and @code{left}.  The default is
3462 @code{below}.  The @code{window-atom} parameter of the new window is set
3463 to this value.
3464 @end table
3466 The return value is the new window, @code{nil} when creating that window
3467 failed.
3468 @end defun
3470 Note that the value of the @code{window-atom} parameter does not really
3471 matter as long as it is non-@code{nil}.  The values assigned by
3472 @code{display-buffer-in-atom-window} just allow for easy retrieval of
3473 the original and the new window after that function has been applied.
3474 Note also that the @code{window-atom} parameter is the only window
3475 parameter assigned by @code{display-buffer-in-atom-window}.  Further
3476 parameters have to be set by the application explicitly via a
3477 @code{window-parameters} entry in @var{alist}.
3479    The following code snippet, when applied to a single-window frame,
3480 first splits the selected window and makes the selected and the new
3481 window constituents of an atomic window with their parent as root.  It
3482 then displays the buffer @file{*Messages*} in a new window at the
3483 frame's bottom and makes that new window part of the atomic window just
3484 created.
3486 @example
3487 @group
3488 (let ((window (split-window-right)))
3489   (window-make-atom (window-parent window))
3490   (display-buffer-in-atom-window
3491    (get-buffer-create "*Messages*")
3492    `((window . ,(window-parent window)) (window-height . 5))))
3493 @end group
3494 @end example
3496 At this moment typing @w{@kbd{C-x 2}} in any window of that frame
3497 produces a new window at the bottom of the frame.  Typing @w{@kbd{C-x
3498 3}} instead will put the new window at the frame's right.  In either
3499 case, typing now @w{@kbd{C-x 1}} in any window of the atomic window will
3500 remove the new window only.  Typing @w{@kbd{C-x 0}} in any window of the
3501 atomic window will make that new window fill the frame.
3504 @node Window Point
3505 @section Windows and Point
3506 @cindex window position
3507 @cindex window point
3508 @cindex position in window
3509 @cindex point in window
3511   Each window has its own value of point (@pxref{Point}), independent of
3512 the value of point in other windows displaying the same buffer.  This
3513 makes it useful to have multiple windows showing one buffer.
3515 @itemize @bullet
3516 @item
3517 The window point is established when a window is first created; it is
3518 initialized from the buffer's point, or from the window point of another
3519 window opened on the buffer if such a window exists.
3521 @item
3522 Selecting a window sets the value of point in its buffer from the
3523 window's value of point.  Conversely, deselecting a window sets the
3524 window's value of point from that of the buffer.  Thus, when you switch
3525 between windows that display a given buffer, the point value for the
3526 selected window is in effect in the buffer, while the point values for
3527 the other windows are stored in those windows.
3529 @item
3530 As long as the selected window displays the current buffer, the window's
3531 point and the buffer's point always move together; they remain equal.
3532 @end itemize
3534 @cindex cursor
3535    As far as the user is concerned, point is where the cursor is, and
3536 when the user switches to another buffer, the cursor jumps to the
3537 position of point in that buffer.
3539 @defun window-point &optional window
3540 This function returns the current position of point in @var{window}.
3541 For a nonselected window, this is the value point would have (in that
3542 window's buffer) if that window were selected.  The default for
3543 @var{window} is the selected window.
3545 When @var{window} is the selected window, the value returned is the
3546 value of point in that window's buffer.  Strictly speaking, it would be
3547 more correct to return the top-level value of point, outside of any
3548 @code{save-excursion} forms.  But that value is hard to find.
3549 @end defun
3551 @defun set-window-point window position
3552 This function positions point in @var{window} at position
3553 @var{position} in @var{window}'s buffer.  It returns @var{position}.
3555 If @var{window} is selected, this simply does @code{goto-char} in
3556 @var{window}'s buffer.
3557 @end defun
3559 @defvar window-point-insertion-type
3560 This variable specifies the marker insertion type (@pxref{Marker
3561 Insertion Types}) of @code{window-point}.  The default is @code{nil},
3562 so @code{window-point} will stay behind text inserted there.
3563 @end defvar
3565 @node Window Start and End
3566 @section The Window Start and End Positions
3567 @cindex window start position
3568 @cindex display-start position
3570   Each window maintains a marker used to keep track of a buffer position
3571 that specifies where in the buffer display should start.  This position
3572 is called the @dfn{display-start} position of the window (or just the
3573 @dfn{start}).  The character after this position is the one that appears
3574 at the upper left corner of the window.  It is usually, but not
3575 inevitably, at the beginning of a text line.
3577   After switching windows or buffers, and in some other cases, if the
3578 window start is in the middle of a line, Emacs adjusts the window
3579 start to the start of a line.  This prevents certain operations from
3580 leaving the window start at a meaningless point within a line.  This
3581 feature may interfere with testing some Lisp code by executing it
3582 using the commands of Lisp mode, because they trigger this
3583 readjustment.  To test such code, put it into a command and bind the
3584 command to a key.
3586 @defun window-start &optional window
3587 @cindex window top line
3588 This function returns the display-start position of window
3589 @var{window}.  If @var{window} is @code{nil}, the selected window is
3590 used.
3592 When you create a window, or display a different buffer in it, the
3593 display-start position is set to a display-start position recently used
3594 for the same buffer, or to @code{point-min} if the buffer doesn't have
3595 any.
3597 Redisplay updates the window-start position (if you have not specified
3598 it explicitly since the previous redisplay)---to make sure point appears
3599 on the screen.  Nothing except redisplay automatically changes the
3600 window-start position; if you move point, do not expect the window-start
3601 position to change in response until after the next redisplay.
3602 @end defun
3604 @defun window-group-start &optional window
3605 @vindex window-group-start-function
3606 This function is like @code{window-start}, except that when
3607 @var{window} is a part of a group of windows (@pxref{Window Group}),
3608 @code{window-group-start} returns the start position of the entire
3609 group.  This condition holds when the buffer local variable
3610 @code{window-group-start-function} is set to a function.  In this
3611 case, @code{window-group-start} calls the function with the single
3612 argument @var{window}, then returns its result.
3613 @end defun
3615 @cindex window end position
3616 @defun window-end &optional window update
3617 This function returns the position where display of its buffer ends in
3618 @var{window}.  The default for @var{window} is the selected window.
3620 Simply changing the buffer text or moving point does not update the
3621 value that @code{window-end} returns.  The value is updated only when
3622 Emacs redisplays and redisplay completes without being preempted.
3624 If the last redisplay of @var{window} was preempted, and did not finish,
3625 Emacs does not know the position of the end of display in that window.
3626 In that case, this function returns @code{nil}.
3628 If @var{update} is non-@code{nil}, @code{window-end} always returns an
3629 up-to-date value for where display ends, based on the current
3630 @code{window-start} value.  If a previously saved value of that position
3631 is still valid, @code{window-end} returns that value; otherwise it
3632 computes the correct value by scanning the buffer text.
3634 Even if @var{update} is non-@code{nil}, @code{window-end} does not
3635 attempt to scroll the display if point has moved off the screen, the
3636 way real redisplay would do.  It does not alter the
3637 @code{window-start} value.  In effect, it reports where the displayed
3638 text will end if scrolling is not required.
3639 @end defun
3641 @vindex window-group-end-function
3642 @defun window-group-end &optional window update
3643 This function is like @code{window-end}, except that when @var{window}
3644 is a part of a group of windows (@pxref{Window Group}),
3645 @code{window-group-end} returns the end position of the entire group.
3646 This condition holds when the buffer local variable
3647 @code{window-group-end-function} is set to a function.  In this case,
3648 @code{window-group-end} calls the function with the two arguments
3649 @var{window} and @var{update}, then returns its result.  The argument
3650 @var{update} has the same meaning as in @code{window-end}.
3651 @end defun
3653 @defun set-window-start window position &optional noforce
3654 This function sets the display-start position of @var{window} to
3655 @var{position} in @var{window}'s buffer.  It returns @var{position}.
3657 The display routines insist that the position of point be visible when a
3658 buffer is displayed.  Normally, they change the display-start position
3659 (that is, scroll the window) whenever necessary to make point visible.
3660 However, if you specify the start position with this function using
3661 @code{nil} for @var{noforce}, it means you want display to start at
3662 @var{position} even if that would put the location of point off the
3663 screen.  If this does place point off screen, the display routines move
3664 point to the left margin on the middle line in the window.
3666 For example, if point @w{is 1} and you set the start of the window
3667 @w{to 37}, the start of the next line, point will be above the top
3668 of the window.  The display routines will automatically move point if
3669 it is still 1 when redisplay occurs.  Here is an example:
3671 @example
3672 @group
3673 ;; @r{Here is what @samp{foo} looks like before executing}
3674 ;;   @r{the @code{set-window-start} expression.}
3675 @end group
3677 @group
3678 ---------- Buffer: foo ----------
3679 @point{}This is the contents of buffer foo.
3685 ---------- Buffer: foo ----------
3686 @end group
3688 @group
3689 (set-window-start
3690  (selected-window)
3691  (save-excursion
3692    (goto-char 1)
3693    (forward-line 1)
3694    (point)))
3695 @result{} 37
3696 @end group
3698 @group
3699 ;; @r{Here is what @samp{foo} looks like after executing}
3700 ;;   @r{the @code{set-window-start} expression.}
3701 ---------- Buffer: foo ----------
3704 @point{}4
3707 ---------- Buffer: foo ----------
3708 @end group
3709 @end example
3711 If @var{noforce} is non-@code{nil}, and @var{position} would place point
3712 off screen at the next redisplay, then redisplay computes a new window-start
3713 position that works well with point, and thus @var{position} is not used.
3714 @end defun
3716 @vindex set-window-group-start-function
3717 @defun set-window-group-start window position &optional noforce
3718 This function is like @code{set-window-start}, except that when
3719 @var{window} is a part of a group of windows (@pxref{Window Group}),
3720 @code{set-window-group-start} sets the start position of the entire
3721 group.  This condition holds when the buffer local variable
3722 @code{set-window-group-start-function} is set to a function.  In this
3723 case, @code{set-window-group-start} calls the function with the three
3724 arguments @var{window}, @var{position}, and @var{noforce}, then
3725 returns its result.  The arguments @var{position} and @var{noforce} in
3726 this function have the same meaning as in @code{set-window-start}.
3727 @end defun
3729 @defun pos-visible-in-window-p &optional position window partially
3730 This function returns non-@code{nil} if @var{position} is within the
3731 range of text currently visible on the screen in @var{window}.  It
3732 returns @code{nil} if @var{position} is scrolled vertically out of
3733 view.  Locations that are partially obscured are not considered
3734 visible unless @var{partially} is non-@code{nil}.  The argument
3735 @var{position} defaults to the current position of point in
3736 @var{window}; @var{window} defaults to the selected window.  If
3737 @var{position} is @code{t}, that means to check either the first
3738 visible position of the last screen line in @var{window}, or the
3739 end-of-buffer position, whichever comes first.
3741 This function considers only vertical scrolling.  If @var{position} is
3742 out of view only because @var{window} has been scrolled horizontally,
3743 @code{pos-visible-in-window-p} returns non-@code{nil} anyway.
3744 @xref{Horizontal Scrolling}.
3746 If @var{position} is visible, @code{pos-visible-in-window-p} returns
3747 @code{t} if @var{partially} is @code{nil}; if @var{partially} is
3748 non-@code{nil}, and the character following @var{position} is fully
3749 visible, it returns a list of the form @code{(@var{x} @var{y})}, where
3750 @var{x} and @var{y} are the pixel coordinates relative to the top left
3751 corner of the window; otherwise it returns an extended list of the form
3752 @code{(@var{x} @var{y} @var{rtop} @var{rbot} @var{rowh} @var{vpos})},
3753 where @var{rtop} and @var{rbot} specify the number of off-window pixels
3754 at the top and bottom of the row at @var{position}, @var{rowh} specifies
3755 the visible height of that row, and @var{vpos} specifies the vertical
3756 position (zero-based row number) of that row.
3758 Here is an example:
3760 @example
3761 @group
3762 ;; @r{If point is off the screen now, recenter it now.}
3763 (or (pos-visible-in-window-p
3764      (point) (selected-window))
3765     (recenter 0))
3766 @end group
3767 @end example
3768 @end defun
3770 @vindex pos-visible-in-window-group-p-function
3771 @defun pos-visible-in-window-group-p &optional position window partially
3772 This function is like @code{pos-visible-in-window-p}, except that when
3773 @var{window} is a part of a group of windows (@pxref{Window Group}),
3774 @code{pos-visible-in-window-group-p} tests the visibility of @var{pos}
3775 in the entire group, not just in the single @var{window}.  This
3776 condition holds when the buffer local variable
3777 @code{pos-visible-in-window-group-p-function} is set to a function.
3778 In this case @code{pos-visible-in-window-group-p} calls the function
3779 with the three arguments @var{position}, @var{window}, and
3780 @var{partially}, then returns its result.  The arguments
3781 @var{position} and @var{partially} have the same meaning as in
3782 @code{pos-visible-in-window-p}.
3783 @end defun
3785 @defun window-line-height &optional line window
3786 This function returns the height of text line @var{line} in
3787 @var{window}.  If @var{line} is one of @code{header-line} or
3788 @code{mode-line}, @code{window-line-height} returns information about
3789 the corresponding line of the window.  Otherwise, @var{line} is a text
3790 line number starting from 0.  A negative number counts from the end of
3791 the window.  The default for @var{line} is the current line in
3792 @var{window}; the default for @var{window} is the selected window.
3794 If the display is not up to date, @code{window-line-height} returns
3795 @code{nil}.  In that case, @code{pos-visible-in-window-p} may be used
3796 to obtain related information.
3798 If there is no line corresponding to the specified @var{line},
3799 @code{window-line-height} returns @code{nil}.  Otherwise, it returns
3800 a list @code{(@var{height} @var{vpos} @var{ypos} @var{offbot})},
3801 where @var{height} is the height in pixels of the visible part of the
3802 line, @var{vpos} and @var{ypos} are the vertical position in lines and
3803 pixels of the line relative to the top of the first text line, and
3804 @var{offbot} is the number of off-window pixels at the bottom of the
3805 text line.  If there are off-window pixels at the top of the (first)
3806 text line, @var{ypos} is negative.
3807 @end defun
3809 @node Textual Scrolling
3810 @section Textual Scrolling
3811 @cindex textual scrolling
3812 @cindex scrolling textually
3814   @dfn{Textual scrolling} means moving the text up or down through a
3815 window.  It works by changing the window's display-start location.  It
3816 may also change the value of @code{window-point} to keep point on the
3817 screen (@pxref{Window Point}).
3819   The basic textual scrolling functions are @code{scroll-up} (which
3820 scrolls forward) and @code{scroll-down} (which scrolls backward).  In
3821 these function names, ``up'' and ``down'' refer to the direction of
3822 motion of the buffer text relative to the window.  Imagine that the
3823 text is written on a long roll of paper and that the scrolling
3824 commands move the paper up and down.  Thus, if you are looking at the
3825 middle of a buffer and repeatedly call @code{scroll-down}, you will
3826 eventually see the beginning of the buffer.
3828   Unfortunately, this sometimes causes confusion, because some people
3829 tend to think in terms of the opposite convention: they
3830 imagine the window moving over text that remains in place, so that
3831 ``down'' commands take you to the end of the buffer.  This convention
3832 is consistent with fact that such a command is bound to a key named
3833 @key{PageDown} on modern keyboards.
3834 @ignore
3835 We have not switched to this convention as that is likely to break
3836 existing Emacs Lisp code.
3837 @end ignore
3839   Textual scrolling functions (aside from @code{scroll-other-window})
3840 have unpredictable results if the current buffer is not the one
3841 displayed in the selected window.  @xref{Current Buffer}.
3843   If the window contains a row taller than the height of the window
3844 (for example in the presence of a large image), the scroll functions
3845 will adjust the window's vertical scroll position to scroll the
3846 partially visible row.  Lisp callers can disable this feature by
3847 binding the variable @code{auto-window-vscroll} to @code{nil}
3848 (@pxref{Vertical Scrolling}).
3850 @deffn Command scroll-up &optional count
3851 This function scrolls forward by @var{count} lines in the selected
3852 window.
3854 If @var{count} is negative, it scrolls backward instead.  If
3855 @var{count} is @code{nil} (or omitted), the distance scrolled is
3856 @code{next-screen-context-lines} lines less than the height of the
3857 window's text area.
3859 If the selected window cannot be scrolled any further, this function
3860 signals an error.  Otherwise, it returns @code{nil}.
3861 @end deffn
3863 @deffn Command scroll-down &optional count
3864 This function scrolls backward by @var{count} lines in the selected
3865 window.
3867 If @var{count} is negative, it scrolls forward instead.  In other
3868 respects, it behaves the same way as @code{scroll-up} does.
3869 @end deffn
3871 @deffn Command scroll-up-command &optional count
3872 This behaves like @code{scroll-up}, except that if the selected window
3873 cannot be scrolled any further and the value of the variable
3874 @code{scroll-error-top-bottom} is @code{t}, it tries to move to the
3875 end of the buffer instead.  If point is already there, it signals an
3876 error.
3877 @end deffn
3879 @deffn Command scroll-down-command &optional count
3880 This behaves like @code{scroll-down}, except that if the selected
3881 window cannot be scrolled any further and the value of the variable
3882 @code{scroll-error-top-bottom} is @code{t}, it tries to move to the
3883 beginning of the buffer instead.  If point is already there, it
3884 signals an error.
3885 @end deffn
3887 @deffn Command scroll-other-window &optional count
3888 This function scrolls the text in another window upward @var{count}
3889 lines.  Negative values of @var{count}, or @code{nil}, are handled
3890 as in @code{scroll-up}.
3892 You can specify which buffer to scroll by setting the variable
3893 @code{other-window-scroll-buffer} to a buffer.  If that buffer isn't
3894 already displayed, @code{scroll-other-window} displays it in some
3895 window.
3897 When the selected window is the minibuffer, the next window is normally
3898 the leftmost one immediately above it.  You can specify a different
3899 window to scroll, when the minibuffer is selected, by setting the variable
3900 @code{minibuffer-scroll-window}.  This variable has no effect when any
3901 other window is selected.  When it is non-@code{nil} and the
3902 minibuffer is selected, it takes precedence over
3903 @code{other-window-scroll-buffer}.  @xref{Definition of
3904 minibuffer-scroll-window}.
3906 When the minibuffer is active, it is the next window if the selected
3907 window is the one at the bottom right corner.  In this case,
3908 @code{scroll-other-window} attempts to scroll the minibuffer.  If the
3909 minibuffer contains just one line, it has nowhere to scroll to, so the
3910 line reappears after the echo area momentarily displays the message
3911 @samp{End of buffer}.
3912 @end deffn
3914 @defvar other-window-scroll-buffer
3915 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
3916 which buffer's window to scroll.
3917 @end defvar
3919 @defopt scroll-margin
3920 This option specifies the size of the scroll margin---a minimum number
3921 of lines between point and the top or bottom of a window.  Whenever
3922 point gets within this many lines of the top or bottom of the window,
3923 redisplay scrolls the text automatically (if possible) to move point
3924 out of the margin, closer to the center of the window.
3925 @end defopt
3927 @defopt scroll-conservatively
3928 This variable controls how scrolling is done automatically when point
3929 moves off the screen (or into the scroll margin).  If the value is a
3930 positive integer @var{n}, then redisplay scrolls the text up to
3931 @var{n} lines in either direction, if that will bring point back into
3932 proper view.  This behavior is called @dfn{conservative scrolling}.
3933 Otherwise, scrolling happens in the usual way, under the control of
3934 other variables such as @code{scroll-up-aggressively} and
3935 @code{scroll-down-aggressively}.
3937 The default value is zero, which means that conservative scrolling
3938 never happens.
3939 @end defopt
3941 @defopt scroll-down-aggressively
3942 The value of this variable should be either @code{nil} or a fraction
3943 @var{f} between 0 and 1.  If it is a fraction, that specifies where on
3944 the screen to put point when scrolling down.  More precisely, when a
3945 window scrolls down because point is above the window start, the new
3946 start position is chosen to put point @var{f} part of the window
3947 height from the top.  The larger @var{f}, the more aggressive the
3948 scrolling.
3950 A value of @code{nil} is equivalent to .5, since its effect is to center
3951 point.  This variable automatically becomes buffer-local when set in any
3952 fashion.
3953 @end defopt
3955 @defopt scroll-up-aggressively
3956 Likewise, for scrolling up.  The value, @var{f}, specifies how far
3957 point should be placed from the bottom of the window; thus, as with
3958 @code{scroll-up-aggressively}, a larger value scrolls more aggressively.
3959 @end defopt
3961 @defopt scroll-step
3962 This variable is an older variant of @code{scroll-conservatively}.
3963 The difference is that if its value is @var{n}, that permits scrolling
3964 only by precisely @var{n} lines, not a smaller number.  This feature
3965 does not work with @code{scroll-margin}.  The default value is zero.
3966 @end defopt
3968 @cindex @code{scroll-command} property
3969 @defopt scroll-preserve-screen-position
3970 If this option is @code{t}, whenever a scrolling command moves point
3971 off-window, Emacs tries to adjust point to keep the cursor at its old
3972 vertical position in the window, rather than the window edge.
3974 If the value is non-@code{nil} and not @code{t}, Emacs adjusts point
3975 to keep the cursor at the same vertical position, even if the
3976 scrolling command didn't move point off-window.
3978 This option affects all scroll commands that have a non-@code{nil}
3979 @code{scroll-command} symbol property.
3980 @end defopt
3982 @defopt next-screen-context-lines
3983 The value of this variable is the number of lines of continuity to
3984 retain when scrolling by full screens.  For example, @code{scroll-up}
3985 with an argument of @code{nil} scrolls so that this many lines at the
3986 bottom of the window appear instead at the top.  The default value is
3987 @code{2}.
3988 @end defopt
3990 @defopt scroll-error-top-bottom
3991 If this option is @code{nil} (the default), @code{scroll-up-command}
3992 and @code{scroll-down-command} simply signal an error when no more
3993 scrolling is possible.
3995 If the value is @code{t}, these commands instead move point to the
3996 beginning or end of the buffer (depending on scrolling direction);
3997 only if point is already on that position do they signal an error.
3998 @end defopt
4000 @deffn Command recenter &optional count
4001 @cindex centering point
4002 This function scrolls the text in the selected window so that point is
4003 displayed at a specified vertical position within the window.  It does
4004 not move point with respect to the text.
4006 If @var{count} is a non-negative number, that puts the line containing
4007 point @var{count} lines down from the top of the window.  If
4008 @var{count} is a negative number, then it counts upward from the
4009 bottom of the window, so that @minus{}1 stands for the last usable
4010 line in the window.
4012 If @var{count} is @code{nil} (or a non-@code{nil} list),
4013 @code{recenter} puts the line containing point in the middle of the
4014 window.  If @var{count} is @code{nil}, this function may redraw the
4015 frame, according to the value of @code{recenter-redisplay}.
4017 When @code{recenter} is called interactively, @var{count} is the raw
4018 prefix argument.  Thus, typing @kbd{C-u} as the prefix sets the
4019 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
4020 @var{count} to 4, which positions the current line four lines from the
4021 top.
4023 With an argument of zero, @code{recenter} positions the current line at
4024 the top of the window.  The command @code{recenter-top-bottom} offers
4025 a more convenient way to achieve this.
4026 @end deffn
4028 @vindex recenter-window-group-function
4029 @defun recenter-window-group &optional count
4030 This function is like @code{recenter}, except that when the selected
4031 window is part of a group of windows (@pxref{Window Group}),
4032 @code{recenter-window-group} scrolls the entire group.  This condition
4033 holds when the buffer local variable
4034 @code{recenter-window-group-function} is set to a function.  In this
4035 case, @code{recenter-window-group} calls the function with the
4036 argument @var{count}, then returns its result.  The argument
4037 @var{count} has the same meaning as in @code{recenter}, but with
4038 respect to the entire window group.
4039 @end defun
4041 @defopt recenter-redisplay
4042 If this variable is non-@code{nil}, calling @code{recenter} with a
4043 @code{nil} argument redraws the frame.  The default value is
4044 @code{tty}, which means only redraw the frame if it is a tty frame.
4045 @end defopt
4047 @deffn Command recenter-top-bottom &optional count
4048 This command, which is the default binding for @kbd{C-l}, acts like
4049 @code{recenter}, except if called with no argument.  In that case,
4050 successive calls place point according to the cycling order defined
4051 by the variable @code{recenter-positions}.
4052 @end deffn
4054 @defopt recenter-positions
4055 This variable controls how @code{recenter-top-bottom} behaves when
4056 called with no argument.  The default value is @code{(middle top
4057 bottom)}, which means that successive calls of
4058 @code{recenter-top-bottom} with no argument cycle between placing
4059 point at the middle, top, and bottom of the window.
4060 @end defopt
4063 @node Vertical Scrolling
4064 @section Vertical Fractional Scrolling
4065 @cindex vertical fractional scrolling
4066 @cindex vertical scroll position
4068    @dfn{Vertical fractional scrolling} means shifting text in a window
4069 up or down by a specified multiple or fraction of a line.  Each window
4070 has a @dfn{vertical scroll position}, which is a number, never less than
4071 zero.  It specifies how far to raise the contents of the window.
4072 Raising the window contents generally makes all or part of some lines
4073 disappear off the top, and all or part of some other lines appear at the
4074 bottom.  The usual value is zero.
4076    The vertical scroll position is measured in units of the normal line
4077 height, which is the height of the default font.  Thus, if the value is
4078 .5, that means the window contents are scrolled up half the normal line
4079 height.  If it is 3.3, that means the window contents are scrolled up
4080 somewhat over three times the normal line height.
4082    What fraction of a line the vertical scrolling covers, or how many
4083 lines, depends on what the lines contain.  A value of .5 could scroll a
4084 line whose height is very short off the screen, while a value of 3.3
4085 could scroll just part of the way through a tall line or an image.
4087 @defun window-vscroll &optional window pixels-p
4088 This function returns the current vertical scroll position of
4089 @var{window}.  The default for @var{window} is the selected window.
4090 If @var{pixels-p} is non-@code{nil}, the return value is measured in
4091 pixels, rather than in units of the normal line height.
4093 @example
4094 @group
4095 (window-vscroll)
4096      @result{} 0
4097 @end group
4098 @end example
4099 @end defun
4101 @defun set-window-vscroll window lines &optional pixels-p
4102 This function sets @var{window}'s vertical scroll position to
4103 @var{lines}.  If @var{window} is @code{nil}, the selected window is
4104 used.  The argument @var{lines} should be zero or positive; if not, it
4105 is taken as zero.
4108 The actual vertical scroll position must always correspond
4109 to an integral number of pixels, so the value you specify
4110 is rounded accordingly.
4112 The return value is the result of this rounding.
4114 @example
4115 @group
4116 (set-window-vscroll (selected-window) 1.2)
4117      @result{} 1.13
4118 @end group
4119 @end example
4121 If @var{pixels-p} is non-@code{nil}, @var{lines} specifies a number of
4122 pixels.  In this case, the return value is @var{lines}.
4123 @end defun
4125 @defvar auto-window-vscroll
4126 If this variable is non-@code{nil}, the @code{line-move},
4127 @code{scroll-up}, and @code{scroll-down} functions will automatically
4128 modify the vertical scroll position to scroll through display rows
4129 that are taller than the height of the window, for example in the
4130 presence of large images.
4131 @end defvar
4133 @node Horizontal Scrolling
4134 @section Horizontal Scrolling
4135 @cindex horizontal scrolling
4137   @dfn{Horizontal scrolling} means shifting the image in the window left
4138 or right by a specified multiple of the normal character width.  Each
4139 window has a @dfn{horizontal scroll position}, which is a number, never
4140 less than zero.  It specifies how far to shift the contents left.
4141 Shifting the window contents left generally makes all or part of some
4142 characters disappear off the left, and all or part of some other
4143 characters appear at the right.  The usual value is zero.
4145   The horizontal scroll position is measured in units of the normal
4146 character width, which is the width of space in the default font.  Thus,
4147 if the value is 5, that means the window contents are scrolled left by 5
4148 times the normal character width.  How many characters actually
4149 disappear off to the left depends on their width, and could vary from
4150 line to line.
4152   Because we read from side to side in the inner loop, and from top
4153 to bottom in the outer loop, the effect of horizontal scrolling is
4154 not like that of textual or vertical scrolling.  Textual scrolling
4155 involves selection of a portion of text to display, and vertical
4156 scrolling moves the window contents contiguously; but horizontal
4157 scrolling causes part of @emph{each line} to go off screen.
4159   Usually, no horizontal scrolling is in effect; then the leftmost
4160 column is at the left edge of the window.  In this state, scrolling to
4161 the right is meaningless, since there is no data to the left of the edge
4162 to be revealed by it; so this is not allowed.  Scrolling to the left is
4163 allowed; it scrolls the first columns of text off the edge of the window
4164 and can reveal additional columns on the right that were truncated
4165 before.  Once a window has a nonzero amount of leftward horizontal
4166 scrolling, you can scroll it back to the right, but only so far as to
4167 reduce the net horizontal scroll to zero.  There is no limit to how far
4168 left you can scroll, but eventually all the text will disappear off the
4169 left edge.
4171 @vindex auto-hscroll-mode
4172   If @code{auto-hscroll-mode} is set, redisplay automatically alters
4173 the horizontal scrolling of a window as necessary to ensure that point
4174 is always visible.  However, you can still set the horizontal
4175 scrolling value explicitly.  The value you specify serves as a lower
4176 bound for automatic scrolling, i.e., automatic scrolling will not
4177 scroll a window to a column less than the specified one.
4179 @deffn Command scroll-left &optional count set-minimum
4180 This function scrolls the selected window @var{count} columns to the
4181 left (or to the right if @var{count} is negative).  The default
4182 for @var{count} is the window width, minus 2.
4184 The return value is the total amount of leftward horizontal scrolling in
4185 effect after the change---just like the value returned by
4186 @code{window-hscroll} (below).
4188 Note that text in paragraphs whose base direction is right-to-left
4189 (@pxref{Bidirectional Display}) moves in the opposite direction: e.g.,
4190 it moves to the right when @code{scroll-left} is invoked with a
4191 positive value of @var{count}.
4193 Once you scroll a window as far right as it can go, back to its normal
4194 position where the total leftward scrolling is zero, attempts to scroll
4195 any farther right have no effect.
4197 If @var{set-minimum} is non-@code{nil}, the new scroll amount becomes
4198 the lower bound for automatic scrolling; that is, automatic scrolling
4199 will not scroll a window to a column less than the value returned by
4200 this function.  Interactive calls pass non-@code{nil} for
4201 @var{set-minimum}.
4202 @end deffn
4204 @deffn Command scroll-right &optional count set-minimum
4205 This function scrolls the selected window @var{count} columns to the
4206 right (or to the left if @var{count} is negative).  The default
4207 for @var{count} is the window width, minus 2.  Aside from the direction
4208 of scrolling, this works just like @code{scroll-left}.
4209 @end deffn
4211 @defun window-hscroll &optional window
4212 This function returns the total leftward horizontal scrolling of
4213 @var{window}---the number of columns by which the text in @var{window}
4214 is scrolled left past the left margin.  (In right-to-left paragraphs,
4215 the value is the total amount of the rightward scrolling instead.)
4216 The default for @var{window} is the selected window.
4218 The return value is never negative.  It is zero when no horizontal
4219 scrolling has been done in @var{window} (which is usually the case).
4222 @example
4223 @group
4224 (window-hscroll)
4225      @result{} 0
4226 @end group
4227 @group
4228 (scroll-left 5)
4229      @result{} 5
4230 @end group
4231 @group
4232 (window-hscroll)
4233      @result{} 5
4234 @end group
4235 @end example
4236 @end defun
4238 @defun set-window-hscroll window columns
4239 This function sets horizontal scrolling of @var{window}.  The value of
4240 @var{columns} specifies the amount of scrolling, in terms of columns
4241 from the left margin (right margin in right-to-left paragraphs).  The
4242 argument @var{columns} should be zero or positive; if not, it is taken
4243 as zero.  Fractional values of @var{columns} are not supported at
4244 present.
4246 Note that @code{set-window-hscroll} may appear not to work if you test
4247 it by evaluating a call with @kbd{M-:} in a simple way.  What happens
4248 is that the function sets the horizontal scroll value and returns, but
4249 then redisplay adjusts the horizontal scrolling to make point visible,
4250 and this overrides what the function did.  You can observe the
4251 function's effect if you call it while point is sufficiently far from
4252 the left margin that it will remain visible.
4254 The value returned is @var{columns}.
4256 @example
4257 @group
4258 (set-window-hscroll (selected-window) 10)
4259      @result{} 10
4260 @end group
4261 @end example
4262 @end defun
4264    Here is how you can determine whether a given position @var{position}
4265 is off the screen due to horizontal scrolling:
4267 @c FIXME: Maybe hscroll-on-screen-p is a better name?
4268 @example
4269 @group
4270 (defun hscroll-on-screen (window position)
4271   (save-excursion
4272     (goto-char position)
4273     (and
4274      (>= (- (current-column) (window-hscroll window)) 0)
4275      (< (- (current-column) (window-hscroll window))
4276         (window-width window)))))
4277 @end group
4278 @end example
4281 @node Coordinates and Windows
4282 @section Coordinates and Windows
4283 @cindex frame-relative coordinate
4284 @cindex coordinate, relative to frame
4285 @cindex window position
4287 This section describes functions that report the position of a window.
4288 Most of these functions report positions relative to an origin at the
4289 native position of the window's frame (@pxref{Frame Geometry}).  Some
4290 functions report positions relative to the origin of the display of the
4291 window's frame.  In any case, the origin has the coordinates (0, 0) and
4292 X and Y coordinates increase rightward and downward
4293 respectively.
4295   For the following functions, X and Y coordinates are reported in
4296 integer character units, i.e., numbers of lines and columns
4297 respectively.  On a graphical display, each ``line'' and ``column''
4298 corresponds to the height and width of the default character specified by
4299 the frame's default font (@pxref{Frame Font}).
4301 @defun window-edges &optional window body absolute pixelwise
4302 This function returns a list of the edge coordinates of @var{window}.
4303 If @var{window} is omitted or @code{nil}, it defaults to the selected
4304 window.
4306 The return value has the form @code{(@var{left} @var{top} @var{right}
4307 @var{bottom})}.  These list elements are, respectively, the X
4308 coordinate of the leftmost column occupied by the window, the Y
4309 coordinate of the topmost row, the X coordinate one column to the
4310 right of the rightmost column, and the Y coordinate one row down from
4311 the bottommost row.
4313 Note that these are the actual outer edges of the window, including any
4314 header line, mode line, scroll bar, fringes, window divider and display
4315 margins.  On a text terminal, if the window has a neighbor on its right,
4316 its right edge includes the separator line between the window and its
4317 neighbor.
4319 If the optional argument @var{body} is @code{nil}, this means to
4320 return the edges corresponding to the total size of @var{window}.
4321 @var{body} non-@code{nil} means to return the edges of @var{window}'s
4322 body (aka text area).  If @var{body} is non-@code{nil}, @var{window}
4323 must specify a live window.
4325 If the optional argument @var{absolute} is @code{nil}, this means to
4326 return edges relative to the native position of @var{window}'s frame.
4327 @var{absolute} non-@code{nil} means to return coordinates relative to
4328 the origin (0, 0) of @var{window}'s display.  On non-graphical systems
4329 this argument has no effect.
4331 If the optional argument @var{pixelwise} is @code{nil}, this means to
4332 return the coordinates in terms of the default character width and
4333 height of @var{window}'s frame (@pxref{Frame Font}), rounded if
4334 necessary.  @var{pixelwise} non-@code{nil} means to return the
4335 coordinates in pixels.  Note that the pixel specified by @var{right} and
4336 @var{bottom} is immediately outside of these edges.  If @var{absolute}
4337 is non-@code{nil}, @var{pixelwise} is implicitly non-@code{nil} too.
4338 @end defun
4340 @defun window-body-edges &optional window
4341 This function returns the edges of @var{window}'s body (@pxref{Window
4342 Sizes}).  Calling @code{(window-body-edges window)} is equivalent to
4343 calling @code{(window-edges window t)}, see above.
4344 @end defun
4346 @comment The following two functions are confusing and hardly used.
4347 @ignore
4348 @defun window-left-column &optional window
4349 This function returns the leftmost column of @var{window}.  This value
4350 equals the @var{left} entry in the list returned by @code{(window-edges
4351 window)} minus the number of columns occupied by the internal border of
4352 @var{window}'s frame.
4353 @end defun
4355 @defun window-top-line &optional window
4356 This function returns the topmost row of @var{window}.  This value is
4357 equal to the @var{top} entry in the list returned by @code{(window-edges
4358 window)} minus the number of lines occupied by the internal border of
4359 @var{window}'s frame.
4360 @end defun
4361 @end ignore
4363   The following functions can be used to relate a set of
4364 frame-relative coordinates to a window:
4366 @defun window-at x y &optional frame
4367 This function returns the live window at the coordinates @var{x} and
4368 @var{y} given in default character sizes (@pxref{Frame Font}) relative
4369 to the native position of @var{frame} (@pxref{Frame Geometry}).
4371 If there is no window at that position, the return value is @code{nil}.
4372 If @var{frame} is omitted or @code{nil}, it defaults to the selected
4373 frame.
4374 @end defun
4376 @defun coordinates-in-window-p coordinates window
4377 This function checks whether a window @var{window} occupies the frame
4378 relative coordinates @var{coordinates}, and if so, which part of the
4379 window that is.  @var{window} should be a live window.
4381 @var{coordinates} should be a cons cell of the form @code{(@var{x}
4382 . @var{y})}, where @var{x} and @var{y} are given in default character
4383 sizes (@pxref{Frame Font}) relative to the native position of
4384 @var{window}'s frame (@pxref{Frame Geometry}).
4386 If there is no window at the specified position, the return value is
4387 @code{nil} .  Otherwise, the return value is one of the following:
4389 @table @code
4390 @item (@var{relx} . @var{rely})
4391 The coordinates are inside @var{window}.  The numbers @var{relx} and
4392 @var{rely} are the equivalent window-relative coordinates for the
4393 specified position, counting from 0 at the top left corner of the
4394 window.
4396 @item mode-line
4397 The coordinates are in the mode line of @var{window}.
4399 @item header-line
4400 The coordinates are in the header line of @var{window}.
4402 @item right-divider
4403 The coordinates are in the divider separating @var{window} from a
4404 window on the right.
4406 @item bottom-divider
4407 The coordinates are in the divider separating @var{window} from a
4408 window beneath.
4410 @item vertical-line
4411 The coordinates are in the vertical line between @var{window} and its
4412 neighbor to the right.  This value occurs only if the window doesn't
4413 have a scroll bar; positions in a scroll bar are considered outside the
4414 window for these purposes.
4416 @item left-fringe
4417 @itemx right-fringe
4418 The coordinates are in the left or right fringe of the window.
4420 @item left-margin
4421 @itemx right-margin
4422 The coordinates are in the left or right margin of the window.
4424 @item nil
4425 The coordinates are not in any part of @var{window}.
4426 @end table
4428 The function @code{coordinates-in-window-p} does not require a frame as
4429 argument because it always uses the frame that @var{window} is on.
4430 @end defun
4432   The following functions return window positions in pixels, rather
4433 than character units.  Though mostly useful on graphical displays,
4434 they can also be called on text terminals, where the screen area of
4435 each text character is taken to be one pixel.
4437 @defun window-pixel-edges &optional window
4438 This function returns a list of pixel coordinates for the edges of
4439 @var{window}.  Calling @code{(window-pixel-edges window)} is equivalent
4440 to calling @code{(window-edges window nil nil t)}, see above.
4441 @end defun
4443 @comment The following two functions are confusing and hardly used.
4444 @ignore
4445 @defun window-pixel-left &optional window
4446 This function returns the left pixel edge of window @var{window}.  This
4447 value equals the @var{left} entry in the list returned by
4448 @code{(window-pixel-edges window)} minus the number of pixels occupied
4449 by the internal border of @var{window}'s frame.  @var{window} must be a
4450 valid window and defaults to the selected one.
4451 @end defun
4453 @defun window-pixel-top &optional window
4454 This function returns the top pixel edge of window @var{window}.  This
4455 value is equal to the @var{top} entry in the list returned by
4456 @code{(window-pixel-edges window)} minus the number of pixels occupied
4457 by the internal border of @var{window}'s frame.  @var{window} must be a
4458 valid window and defaults to the selected one.
4459 @end defun
4460 @end ignore
4462 @defun window-body-pixel-edges &optional window
4463 This function returns the pixel edges of @var{window}'s body.  Calling
4464 @code{(window-body-pixel-edges window)} is equivalent to calling
4465 @code{(window-edges window t nil t)}, see above.
4466 @end defun
4468   The following functions return window positions in pixels, relative to
4469 the origin of the display screen rather than that of the frame:
4471 @defun window-absolute-pixel-edges &optional window
4472 This function returns the pixel coordinates of @var{window} relative to
4473 an origin at (0, 0) of the display of @var{window}'s frame.  Calling
4474 @code{(window-absolute-pixel-edges)} is equivalent to calling
4475 @code{(window-edges window nil t t)}, see above.
4476 @end defun
4478 @defun window-absolute-body-pixel-edges &optional window
4479 This function returns the pixel coordinates of @var{window}'s body
4480 relative to an origin at (0, 0) of the display of @var{window}'s frame.
4481 Calling @code{(window-absolute-body-pixel-edges window)} is equivalent
4482 to calling @code{(window-edges window t t t)}, see above.
4484 Combined with @code{set-mouse-absolute-pixel-position}, this function
4485 can be used to move the mouse pointer to an arbitrary buffer position
4486 visible in some window:
4488 @example
4489 @group
4490 (let ((edges (window-absolute-body-pixel-edges))
4491       (position (pos-visible-in-window-p nil nil t)))
4492   (set-mouse-absolute-pixel-position
4493    (+ (nth 0 edges) (nth 0 position))
4494    (+ (nth 1 edges) (nth 1 position))))
4495 @end group
4496 @end example
4498 On a graphical terminal this form ``warps'' the mouse cursor to the
4499 upper left corner of the glyph at the selected window's point.  A
4500 position calculated this way can be also used to show a tooltip window
4501 there.
4502 @end defun
4504 The following function returns the screen coordinates of a buffer
4505 position visible in a window:
4507 @defun window-absolute-pixel-position &optional position window
4508 If the buffer position @var{position} is visible in window @var{window},
4509 this function returns the display coordinates of the upper/left corner
4510 of the glyph at @var{position}.  The return value is a cons of the X-
4511 and Y-coordinates of that corner, relative to an origin at (0, 0) of
4512 @var{window}'s display.  It returns @code{nil} if @var{position} is not
4513 visible in @var{window}.
4515 @var{window} must be a live window and defaults to the selected
4516 window.  @var{position} defaults to the value of @code{window-point}
4517 of @var{window}.
4519 This means that in order to move the mouse pointer to the position of
4520 point in the selected window, it's sufficient to write:
4522 @example
4523 @group
4524 (let ((position (window-absolute-pixel-position)))
4525   (set-mouse-absolute-pixel-position
4526    (car position) (cdr position)))
4527 @end group
4528 @end example
4529 @end defun
4532 @node Window Configurations
4533 @section Window Configurations
4534 @cindex window configurations
4535 @cindex saving window information
4537 A @dfn{window configuration} records the entire layout of one
4538 frame---all windows, their sizes, which buffers they contain, how those
4539 buffers are scrolled, and their value of point; also their
4540 fringes, margins, and scroll bar settings.  It also includes the value
4541 of @code{minibuffer-scroll-window}.  As a special exception, the window
4542 configuration does not record the value of point in the selected window
4543 for the current buffer.
4545   You can bring back an entire frame layout by restoring a previously
4546 saved window configuration.  If you want to record the layout of all
4547 frames instead of just one, use a frame configuration instead of a
4548 window configuration.  @xref{Frame Configurations}.
4550 @defun current-window-configuration &optional frame
4551 This function returns a new object representing @var{frame}'s current
4552 window configuration.  The default for @var{frame} is the selected
4553 frame.  The variable @code{window-persistent-parameters} specifies
4554 which window parameters (if any) are saved by this function.
4555 @xref{Window Parameters}.
4556 @end defun
4558 @defun set-window-configuration configuration
4559 This function restores the configuration of windows and buffers as
4560 specified by @var{configuration}, for the frame that @var{configuration}
4561 was created for.
4563 The argument @var{configuration} must be a value that was previously
4564 returned by @code{current-window-configuration}.  The configuration is
4565 restored in the frame from which @var{configuration} was made, whether
4566 that frame is selected or not.  In some rare cases this may trigger
4567 execution of the @code{window-size-change-functions} (@pxref{Window
4568 Hooks}) even if the size of windows did not change at all.  The
4569 @code{window-configuration-change-hook} functions will be called if and
4570 only if at least one window was added to or deleted from the frame.
4572 If the frame from which @var{configuration} was saved is dead, all this
4573 function does is restore the three variables @code{window-min-height},
4574 @code{window-min-width} and @code{minibuffer-scroll-window}.  In this
4575 case, the function returns @code{nil}.  Otherwise, it returns @code{t}.
4577 Here is a way of using this function to get the same effect
4578 as @code{save-window-excursion}:
4580 @example
4581 @group
4582 (let ((config (current-window-configuration)))
4583   (unwind-protect
4584       (progn (split-window-below nil)
4585              @dots{})
4586     (set-window-configuration config)))
4587 @end group
4588 @end example
4589 @end defun
4591 @defmac save-window-excursion forms@dots{}
4592 This macro records the window configuration of the selected frame,
4593 executes @var{forms} in sequence, then restores the earlier window
4594 configuration.  The return value is the value of the final form in
4595 @var{forms}.
4597 Most Lisp code should not use this macro; @code{save-selected-window}
4598 is typically sufficient.  In particular, this macro cannot reliably
4599 prevent the code in @var{forms} from opening new windows, because new
4600 windows might be opened in other frames (@pxref{Choosing Window}), and
4601 @code{save-window-excursion} only saves and restores the window
4602 configuration on the current frame.
4604 Do not use this macro in @code{window-size-change-functions}; exiting
4605 the macro triggers execution of @code{window-size-change-functions},
4606 leading to an endless loop.
4607 @end defmac
4609 @defun window-configuration-p object
4610 This function returns @code{t} if @var{object} is a window configuration.
4611 @end defun
4613 @defun compare-window-configurations config1 config2
4614 This function compares two window configurations as regards the
4615 structure of windows, but ignores the values of point and the
4616 saved scrolling positions---it can return @code{t} even if those
4617 aspects differ.
4619 The function @code{equal} can also compare two window configurations; it
4620 regards configurations as unequal if they differ in any respect, even a
4621 saved point.
4622 @end defun
4624 @defun window-configuration-frame config
4625 This function returns the frame for which the window configuration
4626 @var{config} was made.
4627 @end defun
4629   Other primitives to look inside of window configurations would make
4630 sense, but are not implemented because we did not need them.  See the
4631 file @file{winner.el} for some more operations on windows
4632 configurations.
4634   The objects returned by @code{current-window-configuration} die
4635 together with the Emacs process.  In order to store a window
4636 configuration on disk and read it back in another Emacs session, you
4637 can use the functions described next.  These functions are also useful
4638 to clone the state of a frame into an arbitrary live window
4639 (@code{set-window-configuration} effectively clones the windows of a
4640 frame into the root window of that very frame only).
4642 @cindex window state
4643 @defun window-state-get &optional window writable
4644 This function returns the state of @var{window} as a Lisp object.  The
4645 argument @var{window} must be a valid window and defaults to the root
4646 window of the selected frame.
4648 If the optional argument @var{writable} is non-@code{nil}, this means to
4649 not use markers for sampling positions like @code{window-point} or
4650 @code{window-start}.  This argument should be non-@code{nil} when the
4651 state will be written to disk and read back in another session.
4653 Together, the argument @var{writable} and the variable
4654 @code{window-persistent-parameters} specify which window parameters are
4655 saved by this function.  @xref{Window Parameters}.
4656 @end defun
4658 The value returned by @code{window-state-get} can be used in the same
4659 session to make a clone of a window in another window.  It can be also
4660 written to disk and read back in another session.  In either case, use
4661 the following function to restore the state of the window.
4663 @defun window-state-put state &optional window ignore
4664 This function puts the window state @var{state} into @var{window}.
4665 The argument @var{state} should be the state of a window returned by
4666 an earlier invocation of @code{window-state-get}, see above.  The
4667 optional argument @var{window} can be either a live window or an
4668 internal window (@pxref{Windows and Frames}) and defaults to the
4669 selected one.  If @var{window} is not live, it is replaced by a live
4670 window before putting @var{state} into it.
4672 If the optional argument @var{ignore} is non-@code{nil}, it means to ignore
4673 minimum window sizes and fixed-size restrictions.  If @var{ignore}
4674 is @code{safe}, this means windows can get as small as one line
4675 and/or two columns.
4676 @end defun
4678 The functions @code{window-state-get} and @code{window-state-put} also
4679 allow to exchange the contents of two live windows.  The following
4680 function does precisely that:
4682 @deffn Command window-swap-states &optional window-1 window-2 size
4683 This command swaps the states of the two live windows @var{window-1} and
4684 @var{window-2}.  @var{window-1} must specify a live window and defaults
4685 to the selected one.  @var{window-2} must specify a live window and
4686 defaults to the window following @var{window-1} in the cyclic ordering
4687 of windows, excluding minibuffer windows and including live windows on
4688 all visible frames.
4690 Optional argument @var{size} non-@code{nil} means to try swapping the
4691 sizes of @var{window-1} and @var{window-2} as well.  A value of
4692 @code{height} means to swap heights only, a value of @code{width}
4693 means to swap widths only, while @code{t} means to swap both widths
4694 and heights, if possible.  Frames are not resized by this function.
4695 @end deffn
4698 @node Window Parameters
4699 @section Window Parameters
4700 @cindex window parameters
4702 This section describes how window parameters can be used to associate
4703 additional information with windows.
4705 @defun window-parameter window parameter
4706 This function returns @var{window}'s value for @var{parameter}.  The
4707 default for @var{window} is the selected window.  If @var{window} has no
4708 setting for @var{parameter}, this function returns @code{nil}.
4709 @end defun
4711 @defun window-parameters &optional window
4712 This function returns all parameters of @var{window} and their values.
4713 The default for @var{window} is the selected window.  The return value
4714 is either @code{nil}, or an association list whose elements have the form
4715 @code{(@var{parameter} . @var{value})}.
4716 @end defun
4718 @defun set-window-parameter window parameter value
4719 This function sets @var{window}'s value of @var{parameter} to
4720 @var{value} and returns @var{value}.  The default for @var{window}
4721 is the selected window.
4722 @end defun
4724 By default, the functions that save and restore window configurations or the
4725 states of windows (@pxref{Window Configurations}) do not care about
4726 window parameters.  This means that when you change the value of a
4727 parameter within the body of a @code{save-window-excursion}, the
4728 previous value is not restored when that macro exits.  It also means
4729 that when you restore via @code{window-state-put} a window state saved
4730 earlier by @code{window-state-get}, all cloned windows have their
4731 parameters reset to @code{nil}.  The following variable allows you to
4732 override the standard behavior:
4734 @cindex persistent window parameters
4735 @defvar window-persistent-parameters
4736 This variable is an alist specifying which parameters get saved by
4737 @code{current-window-configuration} and @code{window-state-get}, and
4738 subsequently restored by @code{set-window-configuration} and
4739 @code{window-state-put}.  @xref{Window Configurations}.
4741 The @sc{car} of each entry of this alist is a symbol specifying the
4742 parameter.  The @sc{cdr} should be one of the following:
4744 @table @asis
4745 @item @code{nil}
4746 This value means the parameter is saved neither by
4747 @code{window-state-get} nor by @code{current-window-configuration}.
4749 @item @code{t}
4750 This value specifies that the parameter is saved by
4751 @code{current-window-configuration} and (provided its @var{writable}
4752 argument is @code{nil}) by @code{window-state-get}.
4754 @item @code{writable}
4755 This means that the parameter is saved unconditionally by both
4756 @code{current-window-configuration} and @code{window-state-get}.  This
4757 value should not be used for parameters whose values do not have a read
4758 syntax.  Otherwise, invoking @code{window-state-put} in another session
4759 may fail with an @code{invalid-read-syntax} error.
4760 @end table
4761 @end defvar
4763 Some functions (notably @code{delete-window},
4764 @code{delete-other-windows} and @code{split-window}), may behave
4765 specially when the window specified by their @var{window} argument has
4766 a parameter whose name is equal to the function's name.  You can
4767 override such special behavior by binding the following variable to a
4768 non-@code{nil} value:
4770 @defvar ignore-window-parameters
4771 If this variable is non-@code{nil}, some standard functions do not
4772 process window parameters.  The functions currently affected by this are
4773 @code{split-window}, @code{delete-window}, @code{delete-other-windows},
4774 and @code{other-window}.
4776 An application can bind this variable to a non-@code{nil} value around
4777 calls to these functions.  If it does so, the application is fully
4778 responsible for correctly assigning the parameters of all involved
4779 windows when exiting that function.
4780 @end defvar
4782 The following parameters are currently used by the window management
4783 code:
4785 @table @asis
4786 @item @code{delete-window}
4787 This parameter affects the execution of @code{delete-window}
4788 (@pxref{Deleting Windows}).
4790 @item @code{delete-other-windows}
4791 This parameter affects the execution of @code{delete-other-windows}
4792 (@pxref{Deleting Windows}).
4794 @item @code{no-delete-other-window}
4795 This parameter marks the window as not deletable by
4796 @code{delete-other-windows} (@pxref{Deleting Windows}).
4798 @item @code{split-window}
4799 This parameter affects the execution of @code{split-window}
4800 (@pxref{Splitting Windows}).
4802 @item @code{other-window}
4803 This parameter affects the execution of @code{other-window}
4804 (@pxref{Cyclic Window Ordering}).
4806 @item @code{no-other-window}
4807 This parameter marks the window as not selectable by @code{other-window}
4808 (@pxref{Cyclic Window Ordering}).
4810 @item @code{clone-of}
4811 This parameter specifies the window that this one has been cloned
4812 from.  It is installed by @code{window-state-get} (@pxref{Window
4813 Configurations}).
4815 @item @code{preserved-size}
4816 This parameter specifies a buffer, a direction where @code{nil} means
4817 vertical and @code{t} horizontal, and a size in pixels.  If this window
4818 displays the specified buffer and its size in the indicated direction
4819 equals the size specified by this parameter, then Emacs will try to
4820 preserve the size of this window in the indicated direction.  This
4821 parameter is installed and updated by the function
4822 @code{window-preserve-size} (@pxref{Preserving Window Sizes}).
4824 @item @code{quit-restore}
4825 This parameter is installed by the buffer display functions
4826 (@pxref{Choosing Window}) and consulted by @code{quit-restore-window}
4827 (@pxref{Quitting Windows}).  It contains four elements:
4829 The first element is one of the symbols @code{window}, meaning that the
4830 window has been specially created by @code{display-buffer}; @code{frame},
4831 a separate frame has been created; @code{same}, the window has
4832 displayed the same buffer before; or @code{other}, the window showed
4833 another buffer before.
4835 The second element is either one of the symbols @code{window} or
4836 @code{frame}, or a list whose elements are the buffer shown in the
4837 window before, that buffer's window start and window point positions,
4838 and the window's height at that time.
4840 The third element is the window selected at the time the parameter was
4841 created.  The function @code{quit-restore-window} tries to reselect that
4842 window when it deletes the window passed to it as argument.
4844 The fourth element is the buffer whose display caused the creation of
4845 this parameter.  @code{quit-restore-window} deletes the specified window
4846 only if it still shows that buffer.
4848 @item @code{window-side} @code{window-slot}
4849 These parameters are used for implementing side windows (@pxref{Side
4850 Windows}).
4852 @item @code{window-atom}
4853 This parameter is used for implementing atomic windows, see @ref{Atomic
4854 Windows}.
4856 @item @code{min-margins}
4857 The value of this parameter is a cons cell whose @sc{car} and @sc{cdr},
4858 if non-@code{nil}, specify the minimum values (in columns) for the left
4859 and right margin of this window.  When present, Emacs will use these
4860 values instead of the actual margin widths for determining whether a
4861 window can be split or shrunk horizontally.
4863 Emacs never auto-adjusts the margins of any window after splitting or
4864 resizing it.  It is the sole responsibility of any application setting
4865 this parameter to adjust the margins of this window as well as those of
4866 any new window that inherits this window's margins due to a split.
4867 Both @code{window-configuration-change-hook} and
4868 @code{window-size-change-functions} (@pxref{Window Hooks}) should be
4869 employed for this purpose.
4871 This parameter was introduced in Emacs version 25.1 to support
4872 applications that use large margins to center buffer text within a
4873 window and should be used, with due care, exclusively by those
4874 applications.  It might be replaced by an improved solution in future
4875 versions of Emacs.
4876 @end table
4878 The @code{window-atom} parameter is used for implementing atomic windows.
4881 @node Window Hooks
4882 @section Hooks for Window Scrolling and Changes
4883 @cindex hooks for window operations
4885 This section describes how a Lisp program can take action whenever a
4886 window displays a different part of its buffer or a different buffer.
4887 There are three actions that can change this: scrolling the window,
4888 switching buffers in the window, and changing the size of the window.
4889 The first two actions run @code{window-scroll-functions}; the last runs
4890 @code{window-size-change-functions}.
4892 @defvar window-scroll-functions
4893 This variable holds a list of functions that Emacs should call before
4894 redisplaying a window with scrolling.  Displaying a different buffer in
4895 the window also runs these functions.
4897 This variable is not a normal hook, because each function is called with
4898 two arguments: the window, and its new display-start position.
4900 These functions must take care when using @code{window-end}
4901 (@pxref{Window Start and End}); if you need an up-to-date value, you
4902 must use the @var{update} argument to ensure you get it.
4904 @strong{Warning:} don't use this feature to alter the way the window
4905 is scrolled.  It's not designed for that, and such use probably won't
4906 work.
4907 @end defvar
4909 @defvar window-size-change-functions
4910 This variable holds a list of functions to be called if the size of any
4911 window changes for any reason.  The functions are called once per
4912 redisplay, and once for each frame on which size changes have occurred.
4914 Each function receives the frame as its sole argument.  To find out
4915 whether a specific window has changed size, compare the return values of
4916 @code{window-pixel-width-before-size-change} and
4917 @code{window-pixel-width} respectively
4918 @code{window-pixel-height-before-size-change} and
4919 @code{window-pixel-height} for that window (@pxref{Window Sizes}).
4921 These function are usually only called when at least one window was
4922 added or has changed size since the last time this hook was run for the
4923 associated frame.  In some rare cases this hook also runs when a window
4924 that was added intermittently has been deleted afterwards.  In these
4925 cases none of the windows on the frame will appear to have changed its
4926 size.
4928 You may use @code{save-selected-window} in these functions
4929 (@pxref{Selecting Windows}).  However, do not use
4930 @code{save-window-excursion} (@pxref{Window Configurations}); exiting
4931 that macro counts as a size change, which would cause these functions to
4932 be called again.
4933 @end defvar
4935 @defvar window-configuration-change-hook
4936 A normal hook that is run every time the window configuration of a frame
4937 changes.  Window configuration changes include splitting and deleting
4938 windows and the display of a different buffer in a window.  Resizing the
4939 frame or individual windows do not count as configuration changes.  Use
4940 @code{window-size-change-functions}, see above, when you want to track
4941 size changes that are not caused by the deletion or creation of windows.
4943 The buffer-local part of this hook is run once for each window on the
4944 affected frame, with the relevant window selected and its buffer
4945 current.  The global part is run once for the modified frame, with that
4946 frame selected.
4947 @end defvar
4949   In addition, you can use @code{jit-lock-register} to register a Font
4950 Lock fontification function, which will be called whenever parts of a
4951 buffer are (re)fontified because a window was scrolled or its size
4952 changed.  @xref{Other Font Lock Variables}.