Fix typos and minor wording issues in ELisp manual
[emacs.git] / doc / lispref / windows.texi
blobf5de2fc90ba2f5bac19748a9bc8c6cd5f815a664
1 @c -*-texinfo-*-
2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 1990-1995, 1998-1999, 2001-2018 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 * Mouse Window Auto-selection:: Automatically selecting windows with the mouse.
46 * Window Configurations::   Saving and restoring the state of the screen.
47 * Window Parameters::       Associating additional information with windows.
48 * Window Hooks::            Hooks for scrolling, window size changes,
49                               redisplay going past a certain point,
50                               or window configuration changes.
51 @end menu
54 @node Basic Windows
55 @section Basic Concepts of Emacs Windows
56 @cindex window
58 A @dfn{window} is an area of the screen that is used to display a buffer
59 (@pxref{Buffers}).  In Emacs Lisp, windows are represented by a special
60 Lisp object type.
62 @cindex multiple windows
63   Windows are grouped into frames (@pxref{Frames}).  Each frame
64 contains at least one window; the user can subdivide it into multiple,
65 non-overlapping windows to view several buffers at once.  Lisp
66 programs can use multiple windows for a variety of purposes.  In
67 Rmail, for example, you can view a summary of message titles in one
68 window, and the contents of the selected message in another window.
70 @cindex terminal screen
71 @cindex screen of terminal
72   Emacs uses the word ``window'' with a different meaning than in
73 graphical desktop environments and window systems, such as the X
74 Window System.  When Emacs is run on X, each of its graphical X
75 windows is an Emacs frame (containing one or more Emacs windows).
76 When Emacs is run on a text terminal, the frame fills the entire
77 terminal screen.
79 @cindex tiled windows
80   Unlike X windows, Emacs windows are @dfn{tiled}; they never overlap
81 within the area of the frame.  When a window is created, resized, or
82 deleted, the change in window space is taken from or given to the
83 adjacent windows, so that the total area of the frame is unchanged.
85 @defun windowp object
86 This function returns @code{t} if @var{object} is a window (whether or
87 not it displays a buffer).  Otherwise, it returns @code{nil}.
88 @end defun
90 @cindex live windows
91 A @dfn{live window} is one that is actually displaying a buffer in a
92 frame.
94 @defun window-live-p object
95 This function returns @code{t} if @var{object} is a live window and
96 @code{nil} otherwise.  A live window is one that displays a buffer.
97 @end defun
99 @cindex internal windows
100 The windows in each frame are organized into a @dfn{window tree}.
101 @xref{Windows and Frames}.  The leaf nodes of each window tree are live
102 windows---the ones actually displaying buffers.  The internal nodes of
103 the window tree are @dfn{internal windows}, which are not live.
105 @cindex valid windows
106    A @dfn{valid window} is one that is either live or internal.  A valid
107 window can be @dfn{deleted}, i.e., removed from its frame
108 (@pxref{Deleting Windows}); then it is no longer valid, but the Lisp
109 object representing it might be still referenced from other Lisp
110 objects.  A deleted window may be made valid again by restoring a saved
111 window configuration (@pxref{Window Configurations}).
113    You can distinguish valid windows from deleted windows with
114 @code{window-valid-p}.
116 @defun window-valid-p object
117 This function returns @code{t} if @var{object} is a live window, or an
118 internal window in a window tree.  Otherwise, it returns @code{nil},
119 including for the case where @var{object} is a deleted window.
120 @end defun
122 @cindex selected window
123 @cindex window selected within a frame
124   In each frame, at any time, exactly one Emacs window is designated
125 as @dfn{selected within the frame}.  For the selected frame, that
126 window is called the @dfn{selected window}---the one in which most
127 editing takes place, and in which the cursor for selected windows
128 appears (@pxref{Cursor Parameters}).  Keyboard input that inserts or
129 deletes text is also normally directed to this window.   The selected
130 window's buffer is usually also the current buffer, except when
131 @code{set-buffer} has been used (@pxref{Current Buffer}).  As for
132 non-selected frames, the window selected within the frame becomes the
133 selected window if the frame is ever selected.  @xref{Selecting
134 Windows}.
136 @defun selected-window
137 This function returns the selected window (which is always a live
138 window).
139 @end defun
141 @anchor{Window Group}Sometimes several windows collectively and
142 cooperatively display a buffer, for example, under the management of
143 Follow Mode (@pxref{Follow Mode,,, emacs}), where the windows together
144 display a bigger portion of the buffer than one window could alone.
145 It is often useful to consider such a @dfn{window group} as a single
146 entity.  Several functions such as @code{window-group-start}
147 (@pxref{Window Start and End}) allow you to do this by supplying, as
148 an argument, one of the windows as a stand in for the whole group.
150 @defun selected-window-group
151 @vindex selected-window-group-function
152 When the selected window is a member of a group of windows, this
153 function returns a list of the windows in the group, ordered such that
154 the first window in the list is displaying the earliest part of the
155 buffer, and so on.  Otherwise the function returns a list containing
156 just the selected window.
158 The selected window is considered part of a group when the buffer
159 local variable @code{selected-window-group-function} is set to a
160 function.  In this case, @code{selected-window-group} calls it with no
161 arguments and returns its result (which should be the list of windows
162 in the group).
163 @end defun
165 @node Windows and Frames
166 @section Windows and Frames
168 Each window belongs to exactly one frame (@pxref{Frames}).
170 @defun window-frame &optional window
171 This function returns the frame that the window @var{window} belongs
172 to.  If @var{window} is @code{nil}, it defaults to the selected
173 window.
174 @end defun
176 @defun window-list &optional frame minibuffer window
177 This function returns a list of live windows belonging to the frame
178 @var{frame}.  If @var{frame} is omitted or @code{nil}, it defaults to
179 the selected frame.
181 The optional argument @var{minibuffer} specifies whether to include
182 the minibuffer window in the returned list.  If @var{minibuffer} is
183 @code{t}, the minibuffer window is included.  If @var{minibuffer} is
184 @code{nil} or omitted, the minibuffer window is included only if it is
185 active.  If @var{minibuffer} is neither @code{nil} nor @code{t}, the
186 minibuffer window is never included.
188 The optional argument @var{window}, if non-@code{nil}, should be a live
189 window on the specified frame; then @var{window} will be the first
190 element in the returned list.  If @var{window} is omitted or @code{nil},
191 the window selected within the frame is the first element.
192 @end defun
194 @cindex window tree
195 @cindex root window
196   Windows in the same frame are organized into a @dfn{window tree},
197 whose leaf nodes are the live windows.  The internal nodes of a window
198 tree are not live; they exist for the purpose of organizing the
199 relationships between live windows.  The root node of a window tree is
200 called the @dfn{root window}.  It can be either a live window (if the
201 frame has just one window), or an internal window.
203   A minibuffer window (@pxref{Minibuffer Windows}) is not part of its
204 frame's window tree unless the frame is a minibuffer-only frame.
205 Nonetheless, most of the functions in this section accept the
206 minibuffer window as an argument.  Also, the function
207 @code{window-tree} described at the end of this section lists the
208 minibuffer window alongside the actual window tree.
210 @defun frame-root-window &optional frame-or-window
211 This function returns the root window for @var{frame-or-window}.  The
212 argument @var{frame-or-window} should be either a window or a frame;
213 if omitted or @code{nil}, it defaults to the selected frame.  If
214 @var{frame-or-window} is a window, the return value is the root window
215 of that window's frame.
216 @end defun
218 @cindex parent window
219 @cindex child window
220 @cindex sibling window
221   When a window is split, there are two live windows where previously
222 there was one.  One of these is represented by the same Lisp window
223 object as the original window, and the other is represented by a
224 newly-created Lisp window object.  Both of these live windows become
225 leaf nodes of the window tree, as @dfn{child windows} of a single
226 internal window.  If necessary, Emacs automatically creates this
227 internal window, which is also called the @dfn{parent window}, and
228 assigns it to the appropriate position in the window tree.  A set of
229 windows that share the same parent are called @dfn{siblings}.
231 @cindex parent window
232 @defun window-parent &optional window
233 This function returns the parent window of @var{window}.  If
234 @var{window} is omitted or @code{nil}, it defaults to the selected
235 window.  The return value is @code{nil} if @var{window} has no parent
236 (i.e., it is a minibuffer window or the root window of its frame).
237 @end defun
239   Each internal window always has at least two child windows.  If this
240 number falls to one as a result of window deletion, Emacs
241 automatically deletes the internal window, and its sole remaining
242 child window takes its place in the window tree.
244   Each child window can be either a live window, or an internal window
245 (which in turn would have its own child windows).  Therefore, each
246 internal window can be thought of as occupying a certain rectangular
247 @dfn{screen area}---the union of the areas occupied by the live
248 windows that are ultimately descended from it.
250 @cindex window combination
251 @cindex vertical combination
252 @cindex horizontal combination
253   For each internal window, the screen areas of the immediate children
254 are arranged either vertically or horizontally (never both).  If the
255 child windows are arranged one above the other, they are said to form
256 a @dfn{vertical combination}; if they are arranged side by side, they
257 are said to form a @dfn{horizontal combination}.  Consider the
258 following example:
260 @smallexample
261 @group
262      ______________________________________
263     | ______  ____________________________ |
264     ||      || __________________________ ||
265     ||      |||                          |||
266     ||      |||                          |||
267     ||      |||                          |||
268     ||      |||____________W4____________|||
269     ||      || __________________________ ||
270     ||      |||                          |||
271     ||      |||                          |||
272     ||      |||____________W5____________|||
273     ||__W2__||_____________W3_____________ |
274     |__________________W1__________________|
276 @end group
277 @end smallexample
279 @noindent
280 The root window of this frame is an internal window, @var{W1}.  Its
281 child windows form a horizontal combination, consisting of the live
282 window @var{W2} and the internal window @var{W3}.  The child windows
283 of @var{W3} form a vertical combination, consisting of the live
284 windows @var{W4} and @var{W5}.  Hence, the live windows in this
285 window tree are @var{W2}, @var{W4}, and @var{W5}.
287   The following functions can be used to retrieve a child window of an
288 internal window, and the siblings of a child window.
290 @defun window-top-child &optional window
291 This function returns the topmost child window of @var{window}, if
292 @var{window} is an internal window whose children form a vertical
293 combination.  For any other type of window, the return value is
294 @code{nil}.
295 @end defun
297 @defun window-left-child &optional window
298 This function returns the leftmost child window of @var{window}, if
299 @var{window} is an internal window whose children form a horizontal
300 combination.  For any other type of window, the return value is
301 @code{nil}.
302 @end defun
304 @defun window-child window
305 This function returns the first child window of the internal window
306 @var{window}---the topmost child window for a vertical combination, or
307 the leftmost child window for a horizontal combination.  If
308 @var{window} is a live window, the return value is @code{nil}.
309 @end defun
311 @defun window-combined-p &optional window horizontal
312 This function returns a non-@code{nil} value if and only if
313 @var{window} is part of a vertical combination.  If @var{window} is
314 omitted or @code{nil}, it defaults to the selected one.
316 If the optional argument @var{horizontal} is non-@code{nil}, this
317 means to return non-@code{nil} if and only if @var{window} is part of
318 a horizontal combination.
319 @end defun
321 @defun window-next-sibling &optional window
322 This function returns the next sibling of the window @var{window}.  If
323 omitted or @code{nil}, @var{window} defaults to the selected window.
324 The return value is @code{nil} if @var{window} is the last child of
325 its parent.
326 @end defun
328 @defun window-prev-sibling &optional window
329 This function returns the previous sibling of the window @var{window}.
330 If omitted or @code{nil}, @var{window} defaults to the selected
331 window.  The return value is @code{nil} if @var{window} is the first
332 child of its parent.
333 @end defun
335 The functions @code{window-next-sibling} and
336 @code{window-prev-sibling} should not be confused with the functions
337 @code{next-window} and @code{previous-window}, which return the next
338 and previous window, respectively, in the cyclic ordering of windows
339 (@pxref{Cyclic Window Ordering}).
341   The following functions can be useful to locate a window within its
342 frame.
344 @defun frame-first-window &optional frame-or-window
345 This function returns the live window at the upper left corner of the
346 frame specified by @var{frame-or-window}.  The argument
347 @var{frame-or-window} must denote a window or a live frame and defaults
348 to the selected frame.  If @var{frame-or-window} specifies a window,
349 this function returns the first window on that window's frame.  Under
350 the assumption that the frame from our canonical example is selected
351 @code{(frame-first-window)} returns @var{W2}.
352 @end defun
354 @defun window-at-side-p &optional window side
355 This function returns @code{t} if @var{window} is located at
356 @var{side} of its containing frame.  The argument @var{window} must be
357 a valid window and defaults to the selected one.  The argument
358 @var{side} can be any of the symbols @code{left}, @code{top},
359 @code{right} or @code{bottom}.  The default value @code{nil} is
360 handled like @code{bottom}.
362 Note that this function disregards the minibuffer window
363 (@pxref{Minibuffer Windows}).  Hence, with @var{side} equal to
364 @code{bottom} it may return @code{t} also when the minibuffer window
365 appears right below @var{window}.
366 @end defun
368 @cindex window in direction
369 @defun window-in-direction direction &optional window ignore sign wrap mini
370 This function returns the nearest live window in direction
371 @var{direction} as seen from the position of @code{window-point} in
372 window @var{window}.  The argument @var{direction} must be one of
373 @code{above}, @code{below}, @code{left} or @code{right}.  The optional
374 argument @var{window} must denote a live window and defaults to the
375 selected one.
377 This function does not return a window whose @code{no-other-window}
378 parameter is non-@code{nil} (@pxref{Window Parameters}).  If the nearest
379 window's @code{no-other-window} parameter is non-@code{nil}, this
380 function tries to find another window in the indicated direction whose
381 @code{no-other-window} parameter is @code{nil}.  If the optional
382 argument @var{ignore} is non-@code{nil}, a window may be returned even
383 if its @code{no-other-window} parameter is non-@code{nil}.
385 If the optional argument @var{sign} is a negative number, it means to
386 use the right or bottom edge of @var{window} as reference position
387 instead of @code{window-point}.  If @var{sign} is a positive number, it
388 means to use the left or top edge of @var{window} as reference position.
390 If the optional argument @var{wrap} is non-@code{nil}, this means to
391 wrap @var{direction} around frame borders.  For example, if @var{window}
392 is at the top of the frame and @var{direction} is @code{above}, then
393 this function usually returns the frame's minibuffer window if it's
394 active and a window at the bottom of the frame otherwise.
396 If the optional argument @var{mini} is @code{nil}, this means to return
397 the minibuffer window if and only if it is currently active.  If
398 @var{mini} is non-@code{nil}, this function may return the minibuffer
399 window even when it's not active.  However, if @var{wrap} is
400 non-@code{nil}, it always acts as if @var{mini} were @code{nil}.
402 If it doesn't find a suitable window, this function returns
403 @code{nil}.
405 Don't use this function to check whether there is @emph{no} window in
406 @var{direction}.  Calling @code{window-at-side-p} described above is a
407 much more efficient way to do that.
408 @end defun
410 The following function allows the entire window tree of a frame to be
411 retrieved:
413 @defun window-tree &optional frame
414 This function returns a list representing the window tree for frame
415 @var{frame}.  If @var{frame} is omitted or @code{nil}, it defaults to
416 the selected frame.
418 The return value is a list of the form @code{(@var{root} @var{mini})},
419 where @var{root} represents the window tree of the frame's root
420 window, and @var{mini} is the frame's minibuffer window.
422 If the root window is live, @var{root} is that window itself.
423 Otherwise, @var{root} is a list @code{(@var{dir} @var{edges} @var{w1}
424 @var{w2} ...)} where @var{dir} is @code{nil} for a horizontal
425 combination and @code{t} for a vertical combination, @var{edges} gives
426 the size and position of the combination, and the remaining elements
427 are the child windows.  Each child window may again be a window object
428 (for a live window) or a list with the same format as above (for an
429 internal window).  The @var{edges} element is a list @code{(@var{left}
430 @var{top} @var{right} @var{bottom})}, similar to the value returned by
431 @code{window-edges} (@pxref{Coordinates and Windows}).
432 @end defun
435 @node Window Sizes
436 @section Window Sizes
437 @cindex window size
438 @cindex size of window
440   The following schematic shows the structure of a live window:
442 @smallexample
443 @group
444         ____________________________________________
445        |______________ Header Line ______________|RD| ^
446      ^ |LS|LM|LF|                       |RF|RM|RS|  | |
447      | |  |  |  |                       |  |  |  |  | |
448 Window |  |  |  |       Text Area       |  |  |  |  | Window
449 Body | |  |  |  |     (Window Body)     |  |  |  |  | Total
450 Height |  |  |  |                       |  |  |  |  | Height
451      | |  |  |  |<- Window Body Width ->|  |  |  |  | |
452      v |__|__|__|_______________________|__|__|__|  | |
453        |_________ Horizontal Scroll Bar _________|  | |
454        |_______________ Mode Line _______________|__| |
455        |_____________ Bottom Divider _______________| v
456         <---------- Window Total Width ------------>
458 @end group
459 @end smallexample
461 @cindex window body
462 @cindex text area of a window
463 @cindex body of a window
464   At the center of the window is the @dfn{text area}, or @dfn{body},
465 where the buffer text is displayed.  The text area can be surrounded by
466 a series of optional areas.  On the left and right, from innermost to
467 outermost, these are the left and right fringes, denoted by LF and RF
468 (@pxref{Fringes}); the left and right margins, denoted by LM and RM in
469 the schematic (@pxref{Display Margins}); the left or right vertical
470 scroll bar, only one of which is present at any time, denoted by LS and
471 RS (@pxref{Scroll Bars}); and the right divider, denoted by RD
472 (@pxref{Window Dividers}).  At the top of the window is the header line
473 (@pxref{Header Lines}).  At the bottom of the window are the horizontal
474 scroll bar (@pxref{Scroll Bars}); the mode line (@pxref{Mode Line
475 Format}); and the bottom divider (@pxref{Window Dividers}).
477   Emacs provides miscellaneous functions for finding the height and
478 width of a window.  The return value of many of these functions can be
479 specified either in units of pixels or in units of lines and columns.
480 On a graphical display, the latter actually correspond to the height and
481 width of a default character specified by the frame's default font
482 as returned by @code{frame-char-height} and @code{frame-char-width}
483 (@pxref{Frame Font}).  Thus, if a window is displaying text with a
484 different font or size, the reported line height and column width for
485 that window may differ from the actual number of text lines or columns
486 displayed within it.
488 @cindex window height
489 @cindex height of a window
490 @cindex total height of a window
491   The @dfn{total height} of a window is the number of lines comprising
492 the window's body, the header line, the horizontal scroll bar, the mode
493 line and the bottom divider (if any).
495 @defun window-total-height &optional window round
496 This function returns the total height, in lines, of the window
497 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults to
498 the selected window.  If @var{window} is an internal window, the return
499 value is the total height occupied by its descendant windows.
501   If a window's pixel height is not an integral multiple of its frame's
502 default character height, the number of lines occupied by the window is
503 rounded internally.  This is done in a way such that, if the window is a
504 parent window, the sum of the total heights of all its child windows
505 internally equals the total height of their parent.  This means that
506 although two windows have the same pixel height, their internal total
507 heights may differ by one line.  This means also, that if window is
508 vertically combined and has a next sibling, the topmost row of that
509 sibling can be calculated as the sum of this window's topmost row and
510 total height (@pxref{Coordinates and Windows})
512   If the optional argument @var{round} is @code{ceiling}, this
513 function returns the smallest integer larger than @var{window}'s pixel
514 height divided by the character height of its frame; if it is
515 @code{floor}, it returns the largest integer smaller than said value;
516 with any other @var{round} it returns the internal value of
517 @var{windows}'s total height.
518 @end defun
520 @cindex window width
521 @cindex width of a window
522 @cindex total width of a window
523 The @dfn{total width} of a window is the number of lines comprising the
524 window's body, its margins, fringes, scroll bars and a right divider (if
525 any).
527 @defun window-total-width &optional window round
528 This function returns the total width, in columns, of the window
529 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults to
530 the selected window.  If @var{window} is internal, the return value is
531 the total width occupied by its descendant windows.
533   If a window's pixel width is not an integral multiple of its frame's
534 character width, the number of lines occupied by the window is rounded
535 internally.  This is done in a way such that, if the window is a parent
536 window, the sum of the total widths of all its children internally
537 equals the total width of their parent.  This means that although two
538 windows have the same pixel width, their internal total widths may
539 differ by one column.  This means also, that if this window is
540 horizontally combined and has a next sibling, the leftmost column of
541 that sibling can be calculated as the sum of this window's leftmost
542 column and total width (@pxref{Coordinates and Windows}).  The optional
543 argument @var{round} behaves as it does for @code{window-total-height}.
544 @end defun
546 @defun window-total-size &optional window horizontal round
547 This function returns either the total height in lines or the total
548 width in columns of the window @var{window}.  If @var{horizontal} is
549 omitted or @code{nil}, this is equivalent to calling
550 @code{window-total-height} for @var{window}; otherwise it is equivalent
551 to calling @code{window-total-width} for @var{window}.  The optional
552 argument @var{round} behaves as it does for @code{window-total-height}.
553 @end defun
555 The following two functions can be used to return the total size of a
556 window in units of pixels.
558 @cindex window pixel height
559 @cindex pixel height of a window
560 @cindex total pixel height of a window
562 @defun window-pixel-height &optional window
563 This function returns the total height of window @var{window} in pixels.
564 @var{window} must be a valid window and defaults to the selected one.
566 The return value includes mode and header line, a horizontal scroll bar
567 and a bottom divider, if any.  If @var{window} is an internal window,
568 its pixel height is the pixel height of the screen areas spanned by its
569 children.
570 @end defun
572 @defun window-pixel-height-before-size-change &optional Lisp_Object &optional window
573 This function returns the height of window @var{window} in pixels at the
574 time @code{window-size-change-functions} was run for the last time on
575 @var{window}'s frame (@pxref{Window Hooks}).
576 @end defun
578 @cindex window pixel width
579 @cindex pixel width of a window
580 @cindex total pixel width of a window
582 @defun window-pixel-width &optional window
583 This function returns the width of window @var{window} in pixels.
584 @var{window} must be a valid window and defaults to the selected one.
586 The return value includes the fringes and margins of @var{window} as
587 well as any vertical dividers or scroll bars belonging to @var{window}.
588 If @var{window} is an internal window, its pixel width is the width of
589 the screen areas spanned by its children.
590 @end defun
592 @defun window-pixel-width-before-size-change &optional Lisp_Object &optional window
593 This function returns the width of window @var{window} in pixels at the
594 time @code{window-size-change-functions} was run for the last time on
595 @var{window}'s frame (@pxref{Window Hooks}).
596 @end defun
598 @cindex full-width window
599 @cindex full-height window
600   The following functions can be used to determine whether a given
601 window has any adjacent windows.
603 @defun window-full-height-p &optional window
604 This function returns non-@code{nil} if @var{window} has no other window
605 above or below it in its frame.  More precisely, this means that the
606 total height of @var{window} equals the total height of the root window
607 on that frame.  The minibuffer window does not count in this regard.  If
608 @var{window} is omitted or @code{nil}, it defaults to the selected
609 window.
610 @end defun
612 @defun window-full-width-p &optional window
613 This function returns non-@code{nil} if @var{window} has no other
614 window to the left or right in its frame, i.e., its total width equals
615 that of the root window on that frame.  If @var{window} is omitted or
616 @code{nil}, it defaults to the selected window.
617 @end defun
619 @cindex window body height
620 @cindex body height of a window
621 The @dfn{body height} of a window is the height of its text area, which
622 does not include a mode or header line, a horizontal scroll bar, or a
623 bottom divider.
625 @defun window-body-height &optional window pixelwise
626 This function returns the height, in lines, of the body of window
627 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults to
628 the selected window; otherwise it must be a live window.
630 If the optional argument @var{pixelwise} is non-@code{nil}, this
631 function returns the body height of @var{window} counted in pixels.
633 If @var{pixelwise} is @code{nil}, the return value is rounded down to
634 the nearest integer, if necessary.  This means that if a line at the
635 bottom of the text area is only partially visible, that line is not
636 counted.  It also means that the height of a window's body can never
637 exceed its total height as returned by @code{window-total-height}.
638 @end defun
640 @cindex window body width
641 @cindex body width of a window
642 The @dfn{body width} of a window is the width of its text area, which
643 does not include the scroll bar, fringes, margins or a right divider.
644 Note that when one or both fringes are removed (by setting their width
645 to zero), the display engine reserves two character cells, one on each
646 side of the window, for displaying the continuation and truncation
647 glyphs, which leaves 2 columns less for text display.  (The function
648 @code{window-max-chars-per-line}, described below, takes this
649 peculiarity into account.)
651 @defun window-body-width &optional window pixelwise
652 This function returns the width, in columns, of the body of window
653 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults to
654 the selected window; otherwise it must be a live window.
656 If the optional argument @var{pixelwise} is non-@code{nil}, this
657 function returns the body width of @var{window} in units of pixels.
659 If @var{pixelwise} is @code{nil}, the return value is rounded down to
660 the nearest integer, if necessary.  This means that if a column on the
661 right of the text area is only partially visible, that column is not
662 counted.  It also means that the width of a window's body can never
663 exceed its total width as returned by @code{window-total-width}.
664 @end defun
666 @cindex window body size
667 @cindex body size of a window
668 @defun window-body-size &optional window horizontal pixelwise
669 This function returns the body height or body width of @var{window}.  If
670 @var{horizontal} is omitted or @code{nil}, it is equivalent to calling
671 @code{window-body-height} for @var{window}; otherwise it is equivalent
672 to calling @code{window-body-width}.  In either case, the optional
673 argument @var{pixelwise} is passed to the function called.
674 @end defun
676 For compatibility with previous versions of Emacs,
677 @code{window-height} is an alias for @code{window-total-height}, and
678 @code{window-width} is an alias for @code{window-body-width}.  These
679 aliases are considered obsolete and will be removed in the future.
681    The pixel heights of a window's mode and header line can be retrieved
682 with the functions given below.  Their return value is usually accurate
683 unless the window has not been displayed before: In that case, the
684 return value is based on an estimate of the font used for the window's
685 frame.
687 @defun window-mode-line-height &optional window
688 This function returns the height in pixels of @var{window}'s mode line.
689 @var{window} must be a live window and defaults to the selected one.  If
690 @var{window} has no mode line, the return value is zero.
691 @end defun
693 @defun window-header-line-height &optional window
694 This function returns the height in pixels of @var{window}'s header
695 line.  @var{window} must be a live window and defaults to the selected
696 one.  If @var{window} has no header line, the return value is zero.
697 @end defun
699 Functions for retrieving the height and/or width of window dividers
700 (@pxref{Window Dividers}), fringes (@pxref{Fringes}), scroll bars
701 (@pxref{Scroll Bars}), and display margins (@pxref{Display Margins}) are
702 described in the corresponding sections.
704 If your Lisp program needs to make layout decisions, you will find the
705 following function useful:
707 @defun window-max-chars-per-line &optional window face
708 This function returns the number of characters displayed in the
709 specified face @var{face} in the specified window @var{window} (which
710 must be a live window).  If @var{face} was remapped (@pxref{Face
711 Remapping}), the information is returned for the remapped face.  If
712 omitted or @code{nil}, @var{face} defaults to the default face, and
713 @var{window} defaults to the selected window.
715 Unlike @code{window-body-width}, this function accounts for the actual
716 size of @var{face}'s font, instead of working in units of the canonical
717 character width of @var{window}'s frame (@pxref{Frame Font}).  It also
718 accounts for space used by the continuation glyph, if @var{window} lacks
719 one or both of its fringes.
720 @end defun
722 @cindex fixed-size window
723 @vindex window-min-height
724 @vindex window-min-width
725   Commands that change the size of windows (@pxref{Resizing Windows}),
726 or split them (@pxref{Splitting Windows}), obey the variables
727 @code{window-min-height} and @code{window-min-width}, which specify the
728 smallest allowable window height and width.  They also obey the variable
729 @code{window-size-fixed}, with which a window can be @dfn{fixed} in
730 size (@pxref{Preserving Window Sizes}).
732 @defopt window-min-height
733 This option specifies the minimum total height, in lines, of any window.
734 Its value has to accommodate at least one text line as well as a mode
735 and header line, a horizontal scroll bar and a bottom divider, if
736 present.
737 @end defopt
739 @defopt window-min-width
740 This option specifies the minimum total width, in columns, of any
741 window.  Its value has to accommodate two text columns as well as
742 margins, fringes, a scroll bar and a right divider, if present.
743 @end defopt
745 The following function tells how small a specific window can get taking
746 into account the sizes of its areas and the values of
747 @code{window-min-height}, @code{window-min-width} and
748 @code{window-size-fixed} (@pxref{Preserving Window Sizes}).
750 @defun window-min-size &optional window horizontal ignore pixelwise
751 This function returns the minimum size of @var{window}.  @var{window}
752 must be a valid window and defaults to the selected one.  The optional
753 argument @var{horizontal} non-@code{nil} means to return the minimum
754 number of columns of @var{window}; otherwise return the minimum number
755 of @var{window}'s lines.
757 The return value makes sure that all components of @var{window} remain
758 fully visible if @var{window}'s size were actually set to it.  With
759 @var{horizontal} @code{nil} it includes the mode and header line, the
760 horizontal scroll bar and the bottom divider, if present.  With
761 @var{horizontal} non-@code{nil} it includes the margins and fringes, the
762 vertical scroll bar and the right divider, if present.
764 The optional argument @var{ignore}, if non-@code{nil}, means ignore
765 restrictions imposed by fixed size windows, @code{window-min-height} or
766 @code{window-min-width} settings.  If @var{ignore} equals @code{safe},
767 live windows may get as small as @code{window-safe-min-height} lines and
768 @code{window-safe-min-width} columns.  If @var{ignore} is a window,
769 ignore restrictions for that window only.  Any other non-@code{nil}
770 value means ignore all of the above restrictions for all windows.
772 The optional argument @var{pixelwise} non-@code{nil} means to return the
773 minimum size of @var{window} counted in pixels.
774 @end defun
777 @node Resizing Windows
778 @section Resizing Windows
779 @cindex window resizing
780 @cindex resize window
781 @cindex changing window size
782 @cindex window size, changing
784   This section describes functions for resizing a window without
785 changing the size of its frame.  Because live windows do not overlap,
786 these functions are meaningful only on frames that contain two or more
787 windows: resizing a window also changes the size of a neighboring
788 window.  If there is just one window on a frame, its size cannot be
789 changed except by resizing the frame (@pxref{Frame Size}).
791   Except where noted, these functions also accept internal windows as
792 arguments.  Resizing an internal window causes its child windows to be
793 resized to fit the same space.
795 @defun window-resizable window delta &optional horizontal ignore pixelwise
796 This function returns @var{delta} if the size of @var{window} can be
797 changed vertically by @var{delta} lines.  If the optional argument
798 @var{horizontal} is non-@code{nil}, it instead returns @var{delta} if
799 @var{window} can be resized horizontally by @var{delta} columns.  It
800 does not actually change the window size.
802 If @var{window} is @code{nil}, it defaults to the selected window.
804 A positive value of @var{delta} means to check whether the window can be
805 enlarged by that number of lines or columns; a negative value of
806 @var{delta} means to check whether the window can be shrunk by that many
807 lines or columns.  If @var{delta} is non-zero, a return value of 0 means
808 that the window cannot be resized.
810 Normally, the variables @code{window-min-height} and
811 @code{window-min-width} specify the smallest allowable window size
812 (@pxref{Window Sizes}).  However, if the optional argument @var{ignore}
813 is non-@code{nil}, this function ignores @code{window-min-height} and
814 @code{window-min-width}, as well as @code{window-size-fixed}.  Instead,
815 it considers the minimum-height window to be one consisting of a header
816 and a mode line, a horizontal scrollbar and a bottom divider (if any),
817 plus a text area one line tall; and a minimum-width window as one
818 consisting of fringes, margins, a scroll bar and a right divider (if
819 any), plus a text area two columns wide.
821 If the optional argument @var{pixelwise} is non-@code{nil},
822 @var{delta} is interpreted as pixels.
823 @end defun
825 @defun window-resize window delta &optional horizontal ignore pixelwise
826 This function resizes @var{window} by @var{delta} increments.  If
827 @var{horizontal} is @code{nil}, it changes the height by @var{delta}
828 lines; otherwise, it changes the width by @var{delta} columns.  A
829 positive @var{delta} means to enlarge the window, and a negative
830 @var{delta} means to shrink it.
832 If @var{window} is @code{nil}, it defaults to the selected window.  If
833 the window cannot be resized as demanded, an error is signaled.
835 The optional argument @var{ignore} has the same meaning as for the
836 function @code{window-resizable} above.
838 If the optional argument @var{pixelwise} is non-@code{nil},
839 @var{delta} will be interpreted as pixels.
841 The choice of which window edges this function alters depends on the
842 values of the option @code{window-combination-resize} and the
843 combination limits of the involved windows; in some cases, it may alter
844 both edges.  @xref{Recombining Windows}.  To resize by moving only the
845 bottom or right edge of a window, use the function
846 @code{adjust-window-trailing-edge}.
847 @end defun
849 @c The commands enlarge-window, enlarge-window-horizontally,
850 @c shrink-window, and shrink-window-horizontally are documented in the
851 @c Emacs manual.  They are not preferred for calling from Lisp.
853 @defun adjust-window-trailing-edge window delta &optional horizontal pixelwise
854 This function moves @var{window}'s bottom edge by @var{delta} lines.
855 If optional argument @var{horizontal} is non-@code{nil}, it instead
856 moves the right edge by @var{delta} columns.  If @var{window} is
857 @code{nil}, it defaults to the selected window.
859 If the optional argument @var{pixelwise} is non-@code{nil},
860 @var{delta} is interpreted as pixels.
862 A positive @var{delta} moves the edge downwards or to the right; a
863 negative @var{delta} moves it upwards or to the left.  If the edge
864 cannot be moved as far as specified by @var{delta}, this function
865 moves it as far as possible but does not signal an error.
867 This function tries to resize windows adjacent to the edge that is
868 moved.  If this is not possible for some reason (e.g., if that adjacent
869 window is fixed-size), it may resize other windows.
870 @end defun
872 @cindex pixelwise, resizing windows
873 @defopt window-resize-pixelwise
874 If the value of this option is non-@code{nil}, Emacs resizes windows in
875 units of pixels.  This currently affects functions like
876 @code{split-window} (@pxref{Splitting Windows}), @code{maximize-window},
877 @code{minimize-window}, @code{fit-window-to-buffer},
878 @code{fit-frame-to-buffer} and
879 @code{shrink-window-if-larger-than-buffer} (all listed below).
881 Note that when a frame's pixel size is not a multiple of its character
882 size, at least one window may get resized pixelwise even if this
883 option is @code{nil}.  The default value is @code{nil}.
884 @end defopt
886   The following commands resize windows in more specific ways.  When
887 called interactively, they act on the selected window.
889 @deffn Command fit-window-to-buffer &optional window max-height min-height max-width min-width preserve-size
890 This command adjusts the height or width of @var{window} to fit the text
891 in it.  It returns non-@code{nil} if it was able to resize @var{window},
892 and @code{nil} otherwise.  If @var{window} is omitted or @code{nil}, it
893 defaults to the selected window.  Otherwise, it should be a live window.
895 If @var{window} is part of a vertical combination, this function adjusts
896 @var{window}'s height.  The new height is calculated from the actual
897 height of the accessible portion of its buffer.  The optional argument
898 @var{max-height}, if non-@code{nil}, specifies the maximum total height
899 that this function can give @var{window}.  The optional argument
900 @var{min-height}, if non-@code{nil}, specifies the minimum total height
901 that it can give, which overrides the variable @code{window-min-height}.
902 Both @var{max-height} and @var{min-height} are specified in lines and
903 include mode and header line and a bottom divider, if any.
905 If @var{window} is part of a horizontal combination and the value of the
906 option @code{fit-window-to-buffer-horizontally} (see below) is
907 non-@code{nil}, this function adjusts @var{window}'s width.  The new
908 width of @var{window} is calculated from the maximum length of its
909 buffer's lines that follow the current start position of @var{window}.
910 The optional argument @var{max-width} specifies a maximum width and
911 defaults to the width of @var{window}'s frame.  The optional argument
912 @var{min-width} specifies a minimum width and defaults to
913 @code{window-min-width}.  Both @var{max-width} and @var{min-width} are
914 specified in columns and include fringes, margins and scrollbars, if
915 any.
917 The optional argument @var{preserve-size}, if non-@code{nil}, will
918 install a parameter to preserve the size of @var{window} during future
919 resize operations (@pxref{Preserving Window Sizes}).
921 If the option @code{fit-frame-to-buffer} (see below) is non-@code{nil},
922 this function will try to resize the frame of @var{window} to fit its
923 contents by calling @code{fit-frame-to-buffer} (see below).
924 @end deffn
926 @defopt fit-window-to-buffer-horizontally
927 If this is non-@code{nil}, @code{fit-window-to-buffer} can resize
928 windows horizontally.  If this is @code{nil} (the default)
929 @code{fit-window-to-buffer} never resizes windows horizontally.  If this
930 is @code{only}, it can resize windows horizontally only.  Any other
931 value means @code{fit-window-to-buffer} can resize windows in both
932 dimensions.
933 @end defopt
935 @defopt fit-frame-to-buffer
936 If this option is non-@code{nil}, @code{fit-window-to-buffer} can fit a
937 frame to its buffer.  A frame is fit if and only if its root window is a
938 live window and this option is non-@code{nil}.  If this is
939 @code{horizontally}, frames are fit horizontally only.  If this is
940 @code{vertically}, frames are fit vertically only.  Any other
941 non-@code{nil} value means frames can be resized in both dimensions.
942 @end defopt
944 If you have a frame that displays only one window, you can fit that
945 frame to its buffer using the command @code{fit-frame-to-buffer}.
947 @deffn Command fit-frame-to-buffer &optional frame max-height min-height max-width min-width only
948 This command adjusts the size of @var{frame} to display the contents of
949 its buffer exactly.  @var{frame} can be any live frame and defaults to
950 the selected one.  Fitting is done only if @var{frame}'s root window is
951 live.  The arguments @var{max-height}, @var{min-height}, @var{max-width}
952 and @var{min-width} specify bounds on the new total size of
953 @var{frame}'s root window.  @var{min-height} and @var{min-width} default
954 to the values of @code{window-min-height} and @code{window-min-width}
955 respectively.
957 If the optional argument @var{only} is @code{vertically}, this function
958 may resize the frame vertically only.  If @var{only} is
959 @code{horizontally}, it may resize the frame horizontally only.
960 @end deffn
962 The behavior of @code{fit-frame-to-buffer} can be controlled with the
963 help of the two options listed next.
965 @defopt fit-frame-to-buffer-margins
966 This option can be used to specify margins around frames to be fit by
967 @code{fit-frame-to-buffer}.  Such margins can be useful to avoid, for
968 example, that the resized frame overlaps the taskbar or parts of its
969 parent frame.
971 It specifies the numbers of pixels to be left free on the left, above,
972 the right, and below a frame that shall be fit.  The default specifies
973 @code{nil} for each which means to use no margins.  The value specified
974 here can be overridden for a specific frame by that frame's
975 @code{fit-frame-to-buffer-margins} parameter, if present.
976 @end defopt
978 @defopt fit-frame-to-buffer-sizes
979 This option specifies size boundaries for @code{fit-frame-to-buffer}.
980 It specifies the total maximum and minimum lines and maximum and minimum
981 columns of the root window of any frame that shall be fit to its buffer.
982 If any of these values is non-@code{nil}, it overrides the corresponding
983 argument of @code{fit-frame-to-buffer}.
984 @end defopt
986 @deffn Command shrink-window-if-larger-than-buffer &optional window
987 This command attempts to reduce @var{window}'s height as much as
988 possible while still showing its full buffer, but no less than
989 @code{window-min-height} lines.  The return value is non-@code{nil} if
990 the window was resized, and @code{nil} otherwise.  If @var{window} is
991 omitted or @code{nil}, it defaults to the selected window.  Otherwise,
992 it should be a live window.
994 This command does nothing if the window is already too short to
995 display all of its buffer, or if any of the buffer is scrolled
996 off-screen, or if the window is the only live window in its frame.
998 This command calls @code{fit-window-to-buffer} (see above) to do its
999 work.
1000 @end deffn
1003 @cindex balancing window sizes
1004 @deffn Command balance-windows &optional window-or-frame
1005 This function balances windows in a way that gives more space to
1006 full-width and/or full-height windows.  If @var{window-or-frame}
1007 specifies a frame, it balances all windows on that frame.  If
1008 @var{window-or-frame} specifies a window, it balances only that window
1009 and its siblings (@pxref{Windows and Frames}).
1010 @end deffn
1012 @deffn Command balance-windows-area
1013 This function attempts to give all windows on the selected frame
1014 approximately the same share of the screen area.  Full-width or
1015 full-height windows are not given more space than other windows.
1016 @end deffn
1018 @cindex maximizing windows
1019 @deffn Command maximize-window &optional window
1020 This function attempts to make @var{window} as large as possible, in
1021 both dimensions, without resizing its frame or deleting other windows.
1022 If @var{window} is omitted or @code{nil}, it defaults to the selected
1023 window.
1024 @end deffn
1026 @cindex minimizing windows
1027 @deffn Command minimize-window &optional window
1028 This function attempts to make @var{window} as small as possible, in
1029 both dimensions, without deleting it or resizing its frame.  If
1030 @var{window} is omitted or @code{nil}, it defaults to the selected
1031 window.
1032 @end deffn
1035 @node Preserving Window Sizes
1036 @section Preserving Window Sizes
1037 @cindex preserving window sizes
1039 A window can get resized explicitly by using one of the functions from
1040 the preceding section or implicitly, for example, when resizing an
1041 adjacent window, when splitting or deleting a window (@pxref{Splitting
1042 Windows}, @pxref{Deleting Windows}) or when resizing the window's frame
1043 (@pxref{Frame Size}).
1045   It is possible to avoid implicit resizing of a specific window when
1046 there are one or more other resizable windows on the same frame.  For
1047 this purpose, Emacs must be advised to @dfn{preserve} the size of that
1048 window.  There are two basic ways to do that.
1050 @defvar window-size-fixed
1051 If this buffer-local variable is non-@code{nil}, the size of any window
1052 displaying the buffer cannot normally be changed.  Deleting a window or
1053 changing the frame's size may still change the window's size, if there
1054 is no choice.
1056 If the value is @code{height}, then only the window's height is fixed;
1057 if the value is @code{width}, then only the window's width is fixed.
1058 Any other non-@code{nil} value fixes both the width and the height.
1060 If this variable is @code{nil}, this does not necessarily mean that any
1061 window showing the buffer can be resized in the desired direction.  To
1062 determine that, use the function @code{window-resizable}.
1063 @xref{Resizing Windows}.
1064 @end defvar
1066 Often @code{window-size-fixed} is overly aggressive because it inhibits
1067 any attempt to explicitly resize or split an affected window as well.
1068 This may even happen after the window has been resized implicitly, for
1069 example, when deleting an adjacent window or resizing the window's
1070 frame.  The following function tries hard to never disallow resizing
1071 such a window explicitly:
1073 @defun window-preserve-size &optional window horizontal preserve
1074 This function (un-)marks the height of window @var{window} as preserved
1075 for future resize operations.  @var{window} must be a live window and
1076 defaults to the selected one.  If the optional argument @var{horizontal}
1077 is non-@code{nil}, it (un-)marks the width of @var{window} as preserved.
1079 If the optional argument @var{preserve} is @code{t}, this means to
1080 preserve the current height/width of @var{window}'s body.  The
1081 height/width of @var{window} will change only if Emacs has no better
1082 choice.  Resizing a window whose height/width is preserved by this
1083 function never throws an error.
1085 If @var{preserve} is @code{nil}, this means to stop preserving the
1086 height/width of @var{window}, lifting any respective restraint induced
1087 by a previous call of this function for @var{window}.  Calling
1088 @code{enlarge-window}, @code{shrink-window} or
1089 @code{fit-window-to-buffer} with @var{window} as argument may also
1090 remove the respective restraint.
1091 @end defun
1093 @code{window-preserve-size} is currently invoked by the following
1094 functions:
1096 @table @code
1097 @item fit-window-to-buffer
1098 If the optional argument @var{preserve-size} of that function
1099 (@pxref{Resizing Windows}) is non-@code{nil}, the size established by
1100 that function is preserved.
1102 @item display-buffer
1103 If the @var{alist} argument of that function (@pxref{Choosing Window})
1104 contains a @code{preserve-size} entry, the size of the window produced
1105 by that function is preserved.
1106 @end table
1108   @code{window-preserve-size} installs a window parameter (@pxref{Window
1109 Parameters}) called @code{window-preserved-size} which is consulted by the
1110 window resizing functions.  This parameter will not prevent resizing the
1111 window when the window shows another buffer than the one when
1112 @code{window-preserve-size} was invoked or if its size has changed since
1113 then.
1115 The following function can be used to check whether the height of a
1116 particular window is preserved:
1118 @defun window-preserved-size &optional window horizontal
1119 This function returns the preserved height of window @var{window} in
1120 pixels.  @var{window} must be a live window and defaults to the selected
1121 one.  If the optional argument @var{horizontal} is non-@code{nil}, it
1122 returns the preserved width of @var{window}.  It returns @code{nil} if
1123 the size of @var{window} is not preserved.
1124 @end defun
1127 @node Splitting Windows
1128 @section Splitting Windows
1129 @cindex splitting windows
1130 @cindex window splitting
1132 This section describes functions for creating a new window by
1133 @dfn{splitting} an existing one.  Note that some windows are special in
1134 the sense that these functions may fail to split them as described here.
1135 Examples of such windows are side windows (@pxref{Side Windows}) and
1136 atomic windows (@pxref{Atomic Windows}).
1138 @defun split-window &optional window size side pixelwise
1139 This function creates a new live window next to the window
1140 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults
1141 to the selected window.  That window is split, and reduced in
1142 size.  The space is taken up by the new window, which is returned.
1144 The optional second argument @var{size} determines the sizes of
1145 @var{window} and/or the new window.  If it is omitted or @code{nil},
1146 both windows are given equal sizes; if there is an odd line, it is
1147 allocated to the new window.  If @var{size} is a positive number,
1148 @var{window} is given @var{size} lines (or columns, depending on the
1149 value of @var{side}).  If @var{size} is a negative number, the new
1150 window is given @minus{}@var{size} lines (or columns).
1152 If @var{size} is @code{nil}, this function obeys the variables
1153 @code{window-min-height} and @code{window-min-width} (@pxref{Window
1154 Sizes}).  Thus, it signals an error if splitting would result in making
1155 a window smaller than those variables specify.  However, a
1156 non-@code{nil} value for @var{size} causes those variables to be
1157 ignored; in that case, the smallest allowable window is considered to be
1158 one that has space for a text area one line tall and/or two columns
1159 wide.
1161 Hence, if @var{size} is specified, it's the caller's responsibility to
1162 check whether the emanating windows are large enough to encompass all
1163 areas like a mode line or a scroll bar.  The function
1164 @code{window-min-size} (@pxref{Window Sizes}) can be used to determine
1165 the minimum requirements of @var{window} in this regard.  Since the new
1166 window usually inherits areas like the mode line or the scroll bar
1167 from @var{window}, that function is also a good guess for the minimum
1168 size of the new window.  The caller should specify a smaller size only
1169 if it correspondingly removes an inherited area before the next
1170 redisplay.
1172 The optional third argument @var{side} determines the position of the
1173 new window relative to @var{window}.  If it is @code{nil} or
1174 @code{below}, the new window is placed below @var{window}.  If it is
1175 @code{above}, the new window is placed above @var{window}.  In both
1176 these cases, @var{size} specifies a total window height, in lines.
1178 If @var{side} is @code{t} or @code{right}, the new window is placed on
1179 the right of @var{window}.  If @var{side} is @code{left}, the new
1180 window is placed on the left of @var{window}.  In both these cases,
1181 @var{size} specifies a total window width, in columns.
1183 The optional fourth argument @var{pixelwise}, if non-@code{nil}, means
1184 to interpret @var{size} in units of pixels, instead of lines and
1185 columns.
1187 If @var{window} is a live window, the new window inherits various
1188 properties from it, including margins and scroll bars.  If
1189 @var{window} is an internal window, the new window inherits the
1190 properties of the window selected within @var{window}'s frame.
1192 The behavior of this function may be altered by the window parameters
1193 of @var{window}, so long as the variable
1194 @code{ignore-window-parameters} is @code{nil}.  If the value of
1195 the @code{split-window} window parameter is @code{t}, this function
1196 ignores all other window parameters.  Otherwise, if the value of the
1197 @code{split-window} window parameter is a function, that function is
1198 called with the arguments @var{window}, @var{size}, and @var{side}, in
1199 lieu of the usual action of @code{split-window}.  Otherwise, this
1200 function obeys the @code{window-atom} or @code{window-side} window
1201 parameter, if any.  @xref{Window Parameters}.
1202 @end defun
1204   As an example, here is a sequence of @code{split-window} calls that
1205 yields the window configuration discussed in @ref{Windows and Frames}.
1206 This example demonstrates splitting a live window as well as splitting
1207 an internal window.  We begin with a frame containing a single window
1208 (a live root window), which we denote by @var{W4}.  Calling
1209 @code{(split-window W4)} yields this window configuration:
1211 @smallexample
1212 @group
1213      ______________________________________
1214     | ____________________________________ |
1215     ||                                    ||
1216     ||                                    ||
1217     ||                                    ||
1218     ||_________________W4_________________||
1219     | ____________________________________ |
1220     ||                                    ||
1221     ||                                    ||
1222     ||                                    ||
1223     ||_________________W5_________________||
1224     |__________________W3__________________|
1226 @end group
1227 @end smallexample
1229 @noindent
1230 The @code{split-window} call has created a new live window, denoted by
1231 @var{W5}.  It has also created a new internal window, denoted by
1232 @var{W3}, which becomes the root window and the parent of both
1233 @var{W4} and @var{W5}.
1235   Next, we call @code{(split-window W3 nil 'left)}, passing the
1236 internal window @var{W3} as the argument.  The result:
1238 @smallexample
1239 @group
1240      ______________________________________
1241     | ______  ____________________________ |
1242     ||      || __________________________ ||
1243     ||      |||                          |||
1244     ||      |||                          |||
1245     ||      |||                          |||
1246     ||      |||____________W4____________|||
1247     ||      || __________________________ ||
1248     ||      |||                          |||
1249     ||      |||                          |||
1250     ||      |||____________W5____________|||
1251     ||__W2__||_____________W3_____________ |
1252     |__________________W1__________________|
1253 @end group
1254 @end smallexample
1256 @noindent
1257 A new live window @var{W2} is created, to the left of the internal
1258 window @var{W3}.  A new internal window @var{W1} is created, becoming
1259 the new root window.
1261    For interactive use, Emacs provides two commands which always split
1262 the selected window.  These call @code{split-window} internally.
1264 @deffn Command split-window-right &optional size
1265 This function splits the selected window into two side-by-side
1266 windows, putting the selected window on the left.  If @var{size} is
1267 positive, the left window gets @var{size} columns; if @var{size} is
1268 negative, the right window gets @minus{}@var{size} columns.
1269 @end deffn
1271 @deffn Command split-window-below &optional size
1272 This function splits the selected window into two windows, one above
1273 the other, leaving the upper window selected.  If @var{size} is
1274 positive, the upper window gets @var{size} lines; if @var{size} is
1275 negative, the lower window gets @minus{}@var{size} lines.
1276 @end deffn
1278 @defopt split-window-keep-point
1279 If the value of this variable is non-@code{nil} (the default),
1280 @code{split-window-below} behaves as described above.
1282 If it is @code{nil}, @code{split-window-below} adjusts point in each
1283 of the two windows to minimize redisplay.  (This is useful on slow
1284 terminals.)  It selects whichever window contains the screen line that
1285 point was previously on.  Note that this only affects
1286 @code{split-window-below}, not the lower-level @code{split-window}
1287 function.
1288 @end defopt
1291 @node Deleting Windows
1292 @section Deleting Windows
1293 @cindex deleting windows
1295   @dfn{Deleting} a window removes it from the frame's window tree.  If
1296 the window is a live window, it disappears from the screen.  If the
1297 window is an internal window, its child windows are deleted too.
1299   Even after a window is deleted, it continues to exist as a Lisp
1300 object, until there are no more references to it.  Window deletion can
1301 be reversed, by restoring a saved window configuration (@pxref{Window
1302 Configurations}).
1304 @deffn Command delete-window &optional window
1305 This function removes @var{window} from display and returns
1306 @code{nil}.  If @var{window} is omitted or @code{nil}, it defaults to
1307 the selected window.
1309 If deleting the window would leave no more windows in the window tree
1310 (e.g., if it is the only live window in the frame) or all remaining
1311 windows on @var{window}'s frame are side windows (@pxref{Side Windows}),
1312 an error is signaled.
1314 By default, the space taken up by @var{window} is given to one of its
1315 adjacent sibling windows, if any.  However, if the variable
1316 @code{window-combination-resize} is non-@code{nil}, the space is
1317 proportionally distributed among any remaining windows in the same
1318 window combination.  @xref{Recombining Windows}.
1320 The behavior of this function may be altered by the window parameters of
1321 @var{window}, so long as the variable @code{ignore-window-parameters} is
1322 @code{nil}.  If the value of the @code{delete-window} window parameter
1323 is @code{t}, this function ignores all other window parameters.
1324 Otherwise, if the value of the @code{delete-window} window parameter is
1325 a function, that function is called with the argument @var{window}, in
1326 lieu of the usual action of @code{delete-window}.  @xref{Window
1327 Parameters}.
1328 @end deffn
1330 @deffn Command delete-other-windows &optional window
1331 This function makes @var{window} fill its frame, deleting other windows
1332 as necessary.  If @var{window} is omitted or @code{nil}, it defaults to
1333 the selected window.  An error is signaled if @var{window} is a side
1334 window (@pxref{Side Windows}).  The return value is @code{nil}.
1336 The behavior of this function may be altered by the window parameters of
1337 @var{window}, so long as the variable @code{ignore-window-parameters} is
1338 @code{nil}.  If the value of the @code{delete-other-windows} window
1339 parameter is @code{t}, this function ignores all other window
1340 parameters.  Otherwise, if the value of the @code{delete-other-windows}
1341 window parameter is a function, that function is called with the
1342 argument @var{window}, in lieu of the usual action of
1343 @code{delete-other-windows}.  @xref{Window Parameters}.
1345 Also, if @code{ignore-window-parameters} is @code{nil}, this function
1346 does not delete any window whose @code{no-delete-other-windows}
1347 parameter is non-@code{nil}.
1348 @end deffn
1350 @deffn Command delete-windows-on &optional buffer-or-name frame
1351 This function deletes all windows showing @var{buffer-or-name}, by
1352 calling @code{delete-window} on those windows.  @var{buffer-or-name}
1353 should be a buffer, or the name of a buffer; if omitted or @code{nil},
1354 it defaults to the current buffer.  If there are no windows showing
1355 the specified buffer, this function does nothing.  If the specified
1356 buffer is a minibuffer, an error is signaled.
1358 If there is a dedicated window showing the buffer, and that window is
1359 the only one on its frame, this function also deletes that frame if it
1360 is not the only frame on the terminal.
1362 The optional argument @var{frame} specifies which frames to operate
1365 @itemize @bullet
1366 @item @code{nil}
1367 means operate on all frames.
1368 @item @code{t}
1369 means operate on the selected frame.
1370 @item @code{visible}
1371 means operate on all visible frames.
1372 @item @code{0}
1373 means operate on all visible or iconified frames.
1374 @item A frame
1375 means operate on that frame.
1376 @end itemize
1378 Note that this argument does not have the same meaning as in other
1379 functions which scan all live windows (@pxref{Cyclic Window
1380 Ordering}).  Specifically, the meanings of @code{t} and @code{nil} here
1381 are the opposite of what they are in those other functions.
1382 @end deffn
1385 @node Recombining Windows
1386 @section Recombining Windows
1387 @cindex recombining windows
1388 @cindex windows, recombining
1390 When deleting the last sibling of a window @var{W}, its parent window
1391 is deleted too, with @var{W} replacing it in the window tree.  This
1392 means that @var{W} must be recombined with its parent's siblings to
1393 form a new window combination (@pxref{Windows and Frames}).  In some
1394 occasions, deleting a live window may even entail the deletion of two
1395 internal windows.
1397 @smallexample
1398 @group
1399      ______________________________________
1400     | ______  ____________________________ |
1401     ||      || __________________________ ||
1402     ||      ||| ___________  ___________ |||
1403     ||      ||||           ||           ||||
1404     ||      ||||____W6_____||_____W7____||||
1405     ||      |||____________W4____________|||
1406     ||      || __________________________ ||
1407     ||      |||                          |||
1408     ||      |||                          |||
1409     ||      |||____________W5____________|||
1410     ||__W2__||_____________W3_____________ |
1411     |__________________W1__________________|
1413 @end group
1414 @end smallexample
1416 @noindent
1417 Deleting @var{W5} in this configuration normally causes the deletion of
1418 @var{W3} and @var{W4}.  The remaining live windows @var{W2},
1419 @var{W6} and @var{W7} are recombined to form a new horizontal
1420 combination with parent @var{W1}.
1422    Sometimes, however, it makes sense to not delete a parent window like
1423 @var{W4}.  In particular, a parent window should not be removed when it
1424 was used to preserve a combination embedded in a combination of the same
1425 type.  Such embeddings make sense to assure that when you split a window
1426 and subsequently delete the new window, Emacs reestablishes the layout
1427 of the associated frame as it existed before the splitting.
1429    Consider a scenario starting with two live windows @var{W2} and
1430 @var{W3} and their parent @var{W1}.
1432 @smallexample
1433 @group
1434      ______________________________________
1435     | ____________________________________ |
1436     ||                                    ||
1437     ||                                    ||
1438     ||                                    ||
1439     ||                                    ||
1440     ||                                    ||
1441     ||                                    ||
1442     ||_________________W2_________________||
1443     | ____________________________________ |
1444     ||                                    ||
1445     ||                                    ||
1446     ||_________________W3_________________||
1447     |__________________W1__________________|
1449 @end group
1450 @end smallexample
1452 @noindent
1453 Split @var{W2} to make a new window @var{W4} as follows.
1455 @smallexample
1456 @group
1457      ______________________________________
1458     | ____________________________________ |
1459     ||                                    ||
1460     ||                                    ||
1461     ||_________________W2_________________||
1462     | ____________________________________ |
1463     ||                                    ||
1464     ||                                    ||
1465     ||_________________W4_________________||
1466     | ____________________________________ |
1467     ||                                    ||
1468     ||                                    ||
1469     ||_________________W3_________________||
1470     |__________________W1__________________|
1472 @end group
1473 @end smallexample
1475 @noindent
1476 Now, when enlarging a window vertically, Emacs tries to obtain the
1477 corresponding space from its lower sibling, provided such a window
1478 exists.  In our scenario, enlarging @var{W4} will steal space from
1479 @var{W3}.
1481 @smallexample
1482 @group
1483      ______________________________________
1484     | ____________________________________ |
1485     ||                                    ||
1486     ||                                    ||
1487     ||_________________W2_________________||
1488     | ____________________________________ |
1489     ||                                    ||
1490     ||                                    ||
1491     ||                                    ||
1492     ||                                    ||
1493     ||_________________W4_________________||
1494     | ____________________________________ |
1495     ||_________________W3_________________||
1496     |__________________W1__________________|
1498 @end group
1499 @end smallexample
1501 @noindent
1502 Deleting @var{W4} will now give its entire space to @var{W2},
1503 including the space earlier stolen from @var{W3}.
1505 @smallexample
1506 @group
1507      ______________________________________
1508     | ____________________________________ |
1509     ||                                    ||
1510     ||                                    ||
1511     ||                                    ||
1512     ||                                    ||
1513     ||                                    ||
1514     ||                                    ||
1515     ||                                    ||
1516     ||                                    ||
1517     ||_________________W2_________________||
1518     | ____________________________________ |
1519     ||_________________W3_________________||
1520     |__________________W1__________________|
1522 @end group
1523 @end smallexample
1525 @noindent
1526 This can be counterintuitive, in particular if @var{W4} were used for
1527 displaying a buffer only temporarily (@pxref{Temporary Displays}), and
1528 you want to continue working with the initial layout.
1530 The behavior can be fixed by making a new parent window when splitting
1531 @var{W2}.  The variable described next allows that to be done.
1533 @defopt window-combination-limit
1534 This variable controls whether splitting a window shall make a new
1535 parent window.  The following values are recognized:
1537 @table @code
1538 @item nil
1539 This means that the new live window is allowed to share the existing
1540 parent window, if one exists, provided the split occurs in the same
1541 direction as the existing window combination (otherwise, a new internal
1542 window is created anyway).
1544 @item window-size
1545 This means that @code{display-buffer} makes a new parent window when it
1546 splits a window and is passed a @code{window-height} or
1547 @code{window-width} entry in the @var{alist} argument (@pxref{Display
1548 Action Functions}).  Otherwise, window splitting behaves as for a value
1549 of @code{nil}.
1551 @item temp-buffer-resize
1552 In this case @code{with-temp-buffer-window} makes a new parent window
1553 when it splits a window and @code{temp-buffer-resize-mode} is enabled
1554 (@pxref{Temporary Displays}).  Otherwise, window splitting behaves as
1555 for @code{nil}.
1557 @item temp-buffer
1558 In this case @code{with-temp-buffer-window} always makes a new parent
1559 window when it splits an existing window (@pxref{Temporary Displays}).
1560 Otherwise, window splitting behaves as for @code{nil}.
1562 @item display-buffer
1563 This means that when @code{display-buffer} (@pxref{Choosing Window})
1564 splits a window it always makes a new parent window.  Otherwise, window
1565 splitting behaves as for @code{nil}.
1567 @item t
1568 This means that splitting a window always creates a new parent window.
1569 Thus, if the value of this variable is at all times @code{t}, then at
1570 all times every window tree is a binary tree (a tree where each window
1571 except the root window has exactly one sibling).
1572 @end table
1574 The default is @code{window-size}.  Other values are reserved for future
1575 use.
1577 If, as a consequence of this variable's setting, @code{split-window}
1578 makes a new parent window, it also calls
1579 @code{set-window-combination-limit} (see below) on the newly-created
1580 internal window.  This affects how the window tree is rearranged when
1581 the child windows are deleted (see below).
1582 @end defopt
1584   If @code{window-combination-limit} is @code{t}, splitting @var{W2} in
1585 the initial configuration of our scenario would have produced this:
1587 @smallexample
1588 @group
1589      ______________________________________
1590     | ____________________________________ |
1591     || __________________________________ ||
1592     |||                                  |||
1593     |||________________W2________________|||
1594     || __________________________________ ||
1595     |||                                  |||
1596     |||________________W4________________|||
1597     ||_________________W5_________________||
1598     | ____________________________________ |
1599     ||                                    ||
1600     ||                                    ||
1601     ||_________________W3_________________||
1602     |__________________W1__________________|
1604 @end group
1605 @end smallexample
1607 @noindent
1608 A new internal window @var{W5} has been created; its children are
1609 @var{W2} and the new live window @var{W4}.  Now, @var{W2} is the only
1610 sibling of @var{W4}, so enlarging @var{W4} will try to shrink
1611 @var{W2}, leaving @var{W3} unaffected.  Observe that @var{W5}
1612 represents a vertical combination of two windows embedded in the
1613 vertical combination @var{W1}.
1615 @cindex window combination limit
1616 @defun set-window-combination-limit window limit
1617 This function sets the @dfn{combination limit} of the window
1618 @var{window} to @var{limit}.  This value can be retrieved via the
1619 function @code{window-combination-limit}.  See below for its effects;
1620 note that it is only meaningful for internal windows.  The
1621 @code{split-window} function automatically calls this function, passing
1622 it @code{t} as @var{limit}, provided the value of the variable
1623 @code{window-combination-limit} is @code{t} when it is called.
1624 @end defun
1626 @defun window-combination-limit window
1627 This function returns the combination limit for @var{window}.
1629 The combination limit is meaningful only for an internal window.  If it
1630 is @code{nil}, then Emacs is allowed to automatically delete
1631 @var{window}, in response to a window deletion, in order to group the
1632 child windows of @var{window} with its sibling windows to form a new
1633 window combination.  If the combination limit is @code{t}, the child
1634 windows of @var{window} are never automatically recombined with its
1635 siblings.
1637 If, in the configuration shown at the beginning of this section, the
1638 combination limit of @var{W4} (the parent window of @var{W6} and
1639 @var{W7}) is @code{t}, deleting @var{W5} will not implicitly delete
1640 @var{W4} too.
1641 @end defun
1643 Alternatively, the problems sketched above can be avoided by always
1644 resizing all windows in the same combination whenever one of its windows
1645 is split or deleted.  This also permits splitting windows that would be
1646 otherwise too small for such an operation.
1648 @defopt window-combination-resize
1649 If this variable is @code{nil}, @code{split-window} can only split a
1650 window (denoted by @var{window}) if @var{window}'s screen area is large
1651 enough to accommodate both itself and the new window.
1653 If this variable is @code{t}, @code{split-window} tries to resize all
1654 windows that are part of the same combination as @var{window}, in order
1655 to accommodate the new window.  In particular, this may allow
1656 @code{split-window} to succeed even if @var{window} is a fixed-size
1657 window or too small to ordinarily split.  Furthermore, subsequently
1658 resizing or deleting @var{window} may resize all other windows in its
1659 combination.
1661 The default is @code{nil}.  Other values are reserved for future use.  A
1662 specific split operation may ignore the value of this variable if it is
1663 affected by a non-@code{nil} value of @code{window-combination-limit}.
1664 @end defopt
1666   To illustrate the effect of @code{window-combination-resize}, consider
1667 the following frame layout.
1669 @smallexample
1670 @group
1671      ______________________________________
1672     | ____________________________________ |
1673     ||                                    ||
1674     ||                                    ||
1675     ||                                    ||
1676     ||                                    ||
1677     ||_________________W2_________________||
1678     | ____________________________________ |
1679     ||                                    ||
1680     ||                                    ||
1681     ||                                    ||
1682     ||                                    ||
1683     ||_________________W3_________________||
1684     |__________________W1__________________|
1686 @end group
1687 @end smallexample
1689 @noindent
1690 If @code{window-combination-resize} is @code{nil}, splitting window
1691 @var{W3} leaves the size of @var{W2} unchanged:
1693 @smallexample
1694 @group
1695      ______________________________________
1696     | ____________________________________ |
1697     ||                                    ||
1698     ||                                    ||
1699     ||                                    ||
1700     ||                                    ||
1701     ||_________________W2_________________||
1702     | ____________________________________ |
1703     ||                                    ||
1704     ||_________________W3_________________||
1705     | ____________________________________ |
1706     ||                                    ||
1707     ||_________________W4_________________||
1708     |__________________W1__________________|
1710 @end group
1711 @end smallexample
1713 @noindent
1714 If @code{window-combination-resize} is @code{t}, splitting @var{W3}
1715 instead leaves all three live windows with approximately the same
1716 height:
1718 @smallexample
1719 @group
1720      ______________________________________
1721     | ____________________________________ |
1722     ||                                    ||
1723     ||                                    ||
1724     ||_________________W2_________________||
1725     | ____________________________________ |
1726     ||                                    ||
1727     ||                                    ||
1728     ||_________________W3_________________||
1729     | ____________________________________ |
1730     ||                                    ||
1731     ||                                    ||
1732     ||_________________W4_________________||
1733     |__________________W1__________________|
1735 @end group
1736 @end smallexample
1738 @noindent
1739 Deleting any of the live windows @var{W2}, @var{W3} or @var{W4} will
1740 distribute its space proportionally among the two remaining live
1741 windows.
1744 @node Selecting Windows
1745 @section Selecting Windows
1746 @cindex selecting a window
1748 @defun select-window window &optional norecord
1749 This function makes @var{window} the selected window and the window
1750 selected within its frame (@pxref{Basic Windows}), and selects that
1751 frame.  It also makes @var{window}'s buffer (@pxref{Buffers and
1752 Windows}) current and sets that buffer's value of @code{point} to the
1753 value of @code{window-point} (@pxref{Window Point}) in @var{window}.
1754 @var{window} must be a live window.  The return value is @var{window}.
1756 By default, this function also moves @var{window}'s buffer to the front
1757 of the buffer list (@pxref{Buffer List}) and makes @var{window} the most
1758 recently selected window.  If the optional argument @var{norecord} is
1759 non-@code{nil}, these additional actions are omitted.
1761 In addition, this function by default also tells the display engine to
1762 update the display of @var{window} when its frame gets redisplayed the
1763 next time.  If @var{norecord} is non-@code{nil}, such updates are
1764 usually not performed.  If, however, @var{norecord} equals the special
1765 symbol @code{mark-for-redisplay}, the additional actions mentioned above
1766 are omitted but @var{window} will be nevertheless updated.
1768 Note that sometimes selecting a window is not enough to show it, or
1769 make its frame the top-most frame on display: you may also need to
1770 raise the frame or make sure input focus is directed to that frame.
1771 @xref{Input Focus}.
1772 @end defun
1774 @cindex select window hook
1775 @cindex running a hook when a window gets selected
1776 For historical reasons, Emacs does not run a separate hook whenever a
1777 window gets selected.  Applications and internal routines often
1778 temporarily select a window to perform a few actions on it.  They do
1779 that either to simplify coding---because many functions by default
1780 operate on the selected window when no @var{window} argument is
1781 specified---or because some functions did not (and still do not) take a
1782 window as argument and always operate(d) on the selected window instead.
1783 Running a hook every time a window gets selected for a short time and
1784 once more when the previously selected window gets restored is not
1785 useful.
1787   However, when its @var{norecord} argument is @code{nil},
1788 @code{select-window} updates the buffer list and thus indirectly runs
1789 the normal hook @code{buffer-list-update-hook} (@pxref{Buffer List}).
1790 Consequently, that hook provides a reasonable way to run a function
1791 whenever a window gets selected more ``permanently''.
1793   Since @code{buffer-list-update-hook} is also run by functions that are
1794 not related to window management, it will usually make sense to save the
1795 value of the selected window somewhere and compare it with the value of
1796 @code{selected-window} while running that hook.  Also, to avoid false
1797 positives when using @code{buffer-list-update-hook}, it is good practice
1798 that every @code{select-window} call supposed to select a window only
1799 temporarily passes a non-@code{nil} @var{norecord} argument.  If
1800 possible, the macro @code{with-selected-window} (see below) should be
1801 used in such cases.
1803 @cindex most recently selected windows
1804   The sequence of calls to @code{select-window} with a non-@code{nil}
1805 @var{norecord} argument determines an ordering of windows by their
1806 selection time.  The function @code{get-lru-window} can be used to
1807 retrieve the least recently selected live window (@pxref{Cyclic Window
1808 Ordering}).
1810 @defmac save-selected-window forms@dots{}
1811 This macro records the selected frame, as well as the selected window
1812 of each frame, executes @var{forms} in sequence, then restores the
1813 earlier selected frame and windows.  It also saves and restores the
1814 current buffer.  It returns the value of the last form in @var{forms}.
1816 This macro does not save or restore anything about the sizes,
1817 arrangement or contents of windows; therefore, if @var{forms} change
1818 them, the change persists.  If the previously selected window of some
1819 frame is no longer live at the time of exit from @var{forms}, that
1820 frame's selected window is left alone.  If the previously selected
1821 window is no longer live, then whatever window is selected at the end of
1822 @var{forms} remains selected.  The current buffer is restored if and
1823 only if it is still live when exiting @var{forms}.
1825 This macro changes neither the ordering of recently selected windows nor
1826 the buffer list.
1827 @end defmac
1829 @defmac with-selected-window window forms@dots{}
1830 This macro selects @var{window}, executes @var{forms} in sequence, then
1831 restores the previously selected window and current buffer.  The
1832 ordering of recently selected windows and the buffer list remain
1833 unchanged unless you deliberately change them within @var{forms}; for
1834 example, by calling @code{select-window} with argument @var{norecord}
1835 @code{nil}.  Hence, this macro is the preferred way to temporarily work
1836 with @var{window} as the selected window without needlessly running
1837 @code{buffer-list-update-hook}.
1838 @end defmac
1840 @defun frame-selected-window &optional frame
1841 This function returns the window on @var{frame} that is selected
1842 within that frame.  @var{frame} should be a live frame; if omitted or
1843 @code{nil}, it defaults to the selected frame.
1844 @end defun
1846 @defun set-frame-selected-window frame window &optional norecord
1847 This function makes @var{window} the window selected within the frame
1848 @var{frame}.  @var{frame} should be a live frame; if @code{nil}, it
1849 defaults to the selected frame.  @var{window} should be a live window;
1850 if @code{nil}, it defaults to the selected window.
1852 If @var{frame} is the selected frame, this makes @var{window} the
1853 selected window.
1855 If the optional argument @var{norecord} is non-@code{nil}, this
1856 function does not alter the list of most recently selected windows,
1857 nor the buffer list.
1858 @end defun
1860 @cindex window use time
1861 @cindex use time of window
1862 @cindex window order by time of last use
1863 @defun window-use-time &optional window
1864 This functions returns the use time of window @var{window}.
1865 @var{window} must be a live window and defaults to the selected one.
1867 The @dfn{use time} of a window is not really a time value, but an
1868 integer that does increase monotonically with each call of
1869 @code{select-window} with a @code{nil} @var{norecord} argument.  The
1870 window with the lowest use time is usually called the least recently
1871 used window while the window with the highest use time is called the
1872 most recently used one (@pxref{Cyclic Window Ordering}).
1873 @end defun
1876 @node Cyclic Window Ordering
1877 @section Cyclic Ordering of Windows
1878 @cindex cyclic ordering of windows
1879 @cindex ordering of windows, cyclic
1880 @cindex window ordering, cyclic
1882   When you use the command @kbd{C-x o} (@code{other-window}) to select
1883 some other window, it moves through live windows in a specific order.
1884 For any given configuration of windows, this order never varies.  It
1885 is called the @dfn{cyclic ordering of windows}.
1887   The ordering is determined by a depth-first traversal of each frame's
1888 window tree, retrieving the live windows which are the leaf nodes of the
1889 tree (@pxref{Windows and Frames}).  If the minibuffer is active, the
1890 minibuffer window is included too.  The ordering is cyclic, so the last
1891 window in the sequence is followed by the first one.
1893 @defun next-window &optional window minibuf all-frames
1894 @cindex minibuffer window, and @code{next-window}
1895 This function returns a live window, the one following @var{window} in
1896 the cyclic ordering of windows.  @var{window} should be a live window;
1897 if omitted or @code{nil}, it defaults to the selected window.
1899 The optional argument @var{minibuf} specifies whether minibuffer windows
1900 should be included in the cyclic ordering.  Normally, when @var{minibuf}
1901 is @code{nil}, a minibuffer window is included only if it is currently
1902 active; this matches the behavior of @kbd{C-x o}.  (Note that a
1903 minibuffer window is active as long as its minibuffer is in use; see
1904 @ref{Minibuffers}).
1906 If @var{minibuf} is @code{t}, the cyclic ordering includes all
1907 minibuffer windows.  If @var{minibuf} is neither @code{t} nor
1908 @code{nil}, minibuffer windows are not included even if they are active.
1910 The optional argument @var{all-frames} specifies which frames to
1911 consider:
1913 @itemize @bullet
1914 @item @code{nil}
1915 means to consider windows on @var{window}'s frame.  If the minibuffer
1916 window is considered (as specified by the @var{minibuf} argument),
1917 then frames that share the minibuffer window are considered too.
1919 @item @code{t}
1920 means to consider windows on all existing frames.
1922 @item @code{visible}
1923 means to consider windows on all visible frames.
1925 @item 0
1926 means to consider windows on all visible or iconified frames.
1928 @item A frame
1929 means to consider windows on that specific frame.
1931 @item Anything else
1932 means to consider windows on @var{window}'s frame, and no others.
1933 @end itemize
1935 If more than one frame is considered, the cyclic ordering is obtained
1936 by appending the orderings for those frames, in the same order as the
1937 list of all live frames (@pxref{Finding All Frames}).
1938 @end defun
1940 @defun previous-window &optional window minibuf all-frames
1941 This function returns a live window, the one preceding @var{window} in
1942 the cyclic ordering of windows.  The other arguments are handled like
1943 in @code{next-window}.
1944 @end defun
1946 @deffn Command other-window count &optional all-frames
1947 This function selects a live window, one @var{count} places from the
1948 selected window in the cyclic ordering of windows.  If @var{count} is
1949 a positive number, it skips @var{count} windows forwards; if
1950 @var{count} is negative, it skips @minus{}@var{count} windows
1951 backwards; if @var{count} is zero, that simply re-selects the selected
1952 window.  When called interactively, @var{count} is the numeric prefix
1953 argument.
1955 The optional argument @var{all-frames} has the same meaning as in
1956 @code{next-window}, like a @code{nil} @var{minibuf} argument to
1957 @code{next-window}.
1959 This function does not select a window that has a non-@code{nil}
1960 @code{no-other-window} window parameter (@pxref{Window Parameters}).
1961 @end deffn
1963 @defun walk-windows fun &optional minibuf all-frames
1964 This function calls the function @var{fun} once for each live window,
1965 with the window as the argument.
1967 It follows the cyclic ordering of windows.  The optional arguments
1968 @var{minibuf} and @var{all-frames} specify the set of windows
1969 included; these have the same arguments as in @code{next-window}.  If
1970 @var{all-frames} specifies a frame, the first window walked is the
1971 first window on that frame (the one returned by
1972 @code{frame-first-window}), not necessarily the selected window.
1974 If @var{fun} changes the window configuration by splitting or deleting
1975 windows, that does not alter the set of windows walked, which is
1976 determined prior to calling @var{fun} for the first time.
1977 @end defun
1979 @defun one-window-p &optional no-mini all-frames
1980 This function returns @code{t} if the selected window is the only live
1981 window, and @code{nil} otherwise.
1983 If the minibuffer window is active, it is normally considered (so that
1984 this function returns @code{nil}).  However, if the optional argument
1985 @var{no-mini} is non-@code{nil}, the minibuffer window is ignored even
1986 if active.  The optional argument @var{all-frames} has the same
1987 meaning as for @code{next-window}.
1988 @end defun
1990 @cindex finding windows
1991   The following functions return a window which satisfies some
1992 criterion, without selecting it:
1994 @cindex least recently used window
1995 @defun get-lru-window &optional all-frames dedicated not-selected
1996 This function returns a live window which is heuristically the least
1997 recently used.  The optional argument @var{all-frames} has
1998 the same meaning as in @code{next-window}.
2000 If any full-width windows are present, only those windows are
2001 considered.  A minibuffer window is never a candidate.  A dedicated
2002 window (@pxref{Dedicated Windows}) is never a candidate unless the
2003 optional argument @var{dedicated} is non-@code{nil}.  The selected
2004 window is never returned, unless it is the only candidate.  However, if
2005 the optional argument @var{not-selected} is non-@code{nil}, this
2006 function returns @code{nil} in that case.
2007 @end defun
2009 @cindex most recently used window
2010 @defun get-mru-window &optional all-frames dedicated not-selected
2011 This function is like @code{get-lru-window}, but it returns the most
2012 recently used window instead.  The meaning of the arguments is the
2013 same as described for @code{get-lru-window}.
2014 @end defun
2016 @cindex largest window
2017 @defun get-largest-window &optional all-frames dedicated not-selected
2018 This function returns the window with the largest area (height times
2019 width).  The optional argument @var{all-frames} specifies the windows to
2020 search, and has the same meaning as in @code{next-window}.
2022 A minibuffer window is never a candidate.  A dedicated window
2023 (@pxref{Dedicated Windows}) is never a candidate unless the optional
2024 argument @var{dedicated} is non-@code{nil}.  The selected window is not
2025 a candidate if the optional argument @var{not-selected} is
2026 non-@code{nil}.  If the optional argument @var{not-selected} is
2027 non-@code{nil} and the selected window is the only candidate, this
2028 function returns @code{nil}.
2030 If there are two candidate windows of the same size, this function
2031 prefers the one that comes first in the cyclic ordering of windows,
2032 starting from the selected window.
2033 @end defun
2035 @cindex window that satisfies a predicate
2036 @cindex conditional selection of windows
2037 @defun get-window-with-predicate predicate &optional minibuf all-frames default
2038 This function calls the function @var{predicate} for each of the
2039 windows in the cyclic order of windows in turn, passing it the window
2040 as an argument.  If the predicate returns non-@code{nil} for any
2041 window, this function stops and returns that window.  If no such
2042 window is found, the return value is @var{default} (which defaults to
2043 @code{nil}).
2045 The optional arguments @var{minibuf} and @var{all-frames} specify the
2046 windows to search, and have the same meanings as in
2047 @code{next-window}.
2048 @end defun
2051 @node Buffers and Windows
2052 @section Buffers and Windows
2053 @cindex examining windows
2054 @cindex windows, controlling precisely
2055 @cindex buffers, controlled in windows
2057   This section describes low-level functions for examining and setting
2058 the contents of windows.  @xref{Switching Buffers}, for higher-level
2059 functions for displaying a specific buffer in a window.
2061 @defun window-buffer &optional window
2062 This function returns the buffer that @var{window} is displaying.  If
2063 @var{window} is omitted or @code{nil} it defaults to the selected
2064 window.  If @var{window} is an internal window, this function returns
2065 @code{nil}.
2066 @end defun
2068 @defun set-window-buffer window buffer-or-name &optional keep-margins
2069 This function makes @var{window} display @var{buffer-or-name}.
2070 @var{window} should be a live window; if @code{nil}, it defaults to
2071 the selected window.  @var{buffer-or-name} should be a buffer, or the
2072 name of an existing buffer.  This function does not change which
2073 window is selected, nor does it directly change which buffer is
2074 current (@pxref{Current Buffer}).  Its return value is @code{nil}.
2076 If @var{window} is @dfn{strongly dedicated} to a buffer and
2077 @var{buffer-or-name} does not specify that buffer, this function
2078 signals an error.  @xref{Dedicated Windows}.
2080 By default, this function resets @var{window}'s position, display
2081 margins, fringe widths, and scroll bar settings, based on the local
2082 variables in the specified buffer.  However, if the optional argument
2083 @var{keep-margins} is non-@code{nil}, it leaves @var{window}'s display
2084 margins, fringes and scroll bar settings alone.
2086 When writing an application, you should normally use the higher-level
2087 functions described in @ref{Switching Buffers}, instead of calling
2088 @code{set-window-buffer} directly.
2090 This runs @code{window-scroll-functions}, followed by
2091 @code{window-configuration-change-hook}.  @xref{Window Hooks}.
2092 @end defun
2094 @defvar buffer-display-count
2095 This buffer-local variable records the number of times a buffer has been
2096 displayed in a window.  It is incremented each time
2097 @code{set-window-buffer} is called for the buffer.
2098 @end defvar
2100 @defvar buffer-display-time
2101 This buffer-local variable records the time at which a buffer was last
2102 displayed in a window.  The value is @code{nil} if the buffer has
2103 never been displayed.  It is updated each time
2104 @code{set-window-buffer} is called for the buffer, with the value
2105 returned by @code{current-time} (@pxref{Time of Day}).
2106 @end defvar
2108 @defun get-buffer-window &optional buffer-or-name all-frames
2109 This function returns the first window displaying @var{buffer-or-name}
2110 in the cyclic ordering of windows, starting from the selected window
2111 (@pxref{Cyclic Window Ordering}).  If no such window exists, the
2112 return value is @code{nil}.
2114 @var{buffer-or-name} should be a buffer or the name of a buffer; if
2115 omitted or @code{nil}, it defaults to the current buffer.  The
2116 optional argument @var{all-frames} specifies which windows to
2117 consider:
2119 @itemize @bullet
2120 @item
2121 @code{t} means consider windows on all existing frames.
2122 @item
2123 @code{visible} means consider windows on all visible frames.
2124 @item
2125 0 means consider windows on all visible or iconified frames.
2126 @item
2127 A frame means consider windows on that frame only.
2128 @item
2129 Any other value means consider windows on the selected frame.
2130 @end itemize
2132 Note that these meanings differ slightly from those of the
2133 @var{all-frames} argument to @code{next-window} (@pxref{Cyclic Window
2134 Ordering}).  This function may be changed in a future version of Emacs
2135 to eliminate this discrepancy.
2136 @end defun
2138 @defun get-buffer-window-list &optional buffer-or-name minibuf all-frames
2139 This function returns a list of all windows currently displaying
2140 @var{buffer-or-name}.  @var{buffer-or-name} should be a buffer or the
2141 name of an existing buffer.  If omitted or @code{nil}, it defaults to
2142 the current buffer.  If the currently selected window displays
2143 @var{buffer-or-name}, it will be the first in the list returned by
2144 this function.
2146 The arguments @var{minibuf} and @var{all-frames} have the same
2147 meanings as in the function @code{next-window} (@pxref{Cyclic Window
2148 Ordering}).  Note that the @var{all-frames} argument does @emph{not}
2149 behave exactly like in @code{get-buffer-window}.
2150 @end defun
2152 @deffn Command replace-buffer-in-windows &optional buffer-or-name
2153 This command replaces @var{buffer-or-name} with some other buffer, in
2154 all windows displaying it.  @var{buffer-or-name} should be a buffer, or
2155 the name of an existing buffer; if omitted or @code{nil}, it defaults to
2156 the current buffer.
2158 The replacement buffer in each window is chosen via
2159 @code{switch-to-prev-buffer} (@pxref{Window History}).  Any dedicated
2160 window displaying @var{buffer-or-name} is deleted if possible
2161 (@pxref{Dedicated Windows}).  If such a window is the only window on its
2162 frame and there are other frames on the same terminal, the frame is
2163 deleted as well.  If the dedicated window is the only window on the only
2164 frame on its terminal, the buffer is replaced anyway.
2165 @end deffn
2168 @node Switching Buffers
2169 @section Switching to a Buffer in a Window
2170 @cindex switching to a buffer
2171 @cindex displaying a buffer
2173 This section describes high-level functions for switching to a specified
2174 buffer in some window.  In general, ``switching to a buffer'' means to
2175 (1) show the buffer in some window, (2) make that window the selected
2176 window (and its frame the selected frame), and (3) make the buffer the
2177 current buffer.
2179   Do @emph{not} use these functions to make a buffer temporarily
2180 current just so a Lisp program can access or modify it.  They have
2181 side-effects, such as changing window histories (@pxref{Window
2182 History}), which will surprise the user if used that way.  If you want
2183 to make a buffer current to modify it in Lisp, use
2184 @code{with-current-buffer}, @code{save-current-buffer}, or
2185 @code{set-buffer}.  @xref{Current Buffer}.
2187 @deffn Command switch-to-buffer buffer-or-name &optional norecord force-same-window
2188 This command attempts to display @var{buffer-or-name} in the selected
2189 window and make it the current buffer.  It is often used interactively
2190 (as the binding of @kbd{C-x b}), as well as in Lisp programs.  The
2191 return value is the buffer switched to.
2193 If @var{buffer-or-name} is @code{nil}, it defaults to the buffer
2194 returned by @code{other-buffer} (@pxref{Buffer List}).  If
2195 @var{buffer-or-name} is a string that is not the name of any existing
2196 buffer, this function creates a new buffer with that name; the new
2197 buffer's major mode is determined by the variable @code{major-mode}
2198 (@pxref{Major Modes}).
2200 Normally, the specified buffer is put at the front of the buffer
2201 list---both the global buffer list and the selected frame's buffer
2202 list (@pxref{Buffer List}).  However, this is not done if the
2203 optional argument @var{norecord} is non-@code{nil}.
2205 Sometimes, the selected window may not be suitable for displaying the
2206 buffer.  This happens if the selected window is a minibuffer window, or
2207 if the selected window is strongly dedicated to its buffer
2208 (@pxref{Dedicated Windows}).  In such cases, the command normally tries
2209 to display the buffer in some other window, by invoking
2210 @code{pop-to-buffer} (see below).
2212 If the optional argument @var{force-same-window} is non-@code{nil} and
2213 the selected window is not suitable for displaying the buffer, this
2214 function always signals an error when called non-interactively.  In
2215 interactive use, if the selected window is a minibuffer window, this
2216 function will try to use some other window instead.  If the selected
2217 window is strongly dedicated to its buffer, the option
2218 @code{switch-to-buffer-in-dedicated-window} described next can be used
2219 to proceed.
2220 @end deffn
2222 @defopt switch-to-buffer-in-dedicated-window
2223 This option, if non-@code{nil}, allows @code{switch-to-buffer} to
2224 proceed when called interactively and the selected window is strongly
2225 dedicated to its buffer.
2227 The following values are respected:
2229 @table @code
2230 @item nil
2231 Disallows switching and signals an error as in non-interactive use.
2233 @item prompt
2234 Prompts the user whether to allow switching.
2236 @item pop
2237 Invokes @code{pop-to-buffer} to proceed.
2239 @item t
2240 Marks the selected window as non-dedicated and proceeds.
2241 @end table
2243 This option does not affect non-interactive calls of
2244 @code{switch-to-buffer}.
2245 @end defopt
2247 By default, @code{switch-to-buffer} tries to preserve
2248 @code{window-point}.  This behavior can be tuned using the following
2249 option.
2251 @defopt switch-to-buffer-preserve-window-point
2252 If this variable is @code{nil}, @code{switch-to-buffer} displays the
2253 buffer specified by @var{buffer-or-name} at the position of that
2254 buffer's @code{point}.  If this variable is @code{already-displayed}, it
2255 tries to display the buffer at its previous position in the selected
2256 window, provided the buffer is currently displayed in some other window
2257 on any visible or iconified frame.  If this variable is @code{t},
2258 @code{switch-to-buffer} unconditionally tries to display the buffer at
2259 its previous position in the selected window.
2261 This variable is ignored if the buffer is already displayed in the
2262 selected window or never appeared in it before, or if
2263 @code{switch-to-buffer} calls @code{pop-to-buffer} to display the
2264 buffer.
2265 @end defopt
2267 The next two commands are similar to @code{switch-to-buffer}, except for
2268 the described features.
2270 @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
2271 This function displays the buffer specified by @var{buffer-or-name} in
2272 some window other than the selected window.  It uses the function
2273 @code{pop-to-buffer} internally (see below).
2275 If the selected window already displays the specified buffer, it
2276 continues to do so, but another window is nonetheless found to display
2277 it as well.
2279 The @var{buffer-or-name} and @var{norecord} arguments have the same
2280 meanings as in @code{switch-to-buffer}.
2281 @end deffn
2283 @deffn Command switch-to-buffer-other-frame buffer-or-name &optional norecord
2284 This function displays the buffer specified by @var{buffer-or-name} in a
2285 new frame.  It uses the function @code{pop-to-buffer} internally (see
2286 below).
2288 If the specified buffer is already displayed in another window, in any
2289 frame on the current terminal, this switches to that window instead of
2290 creating a new frame.  However, the selected window is never used for
2291 this.
2293 The @var{buffer-or-name} and @var{norecord} arguments have the same
2294 meanings as in @code{switch-to-buffer}.
2295 @end deffn
2297 The above commands use the function @code{pop-to-buffer}, which
2298 flexibly displays a buffer in some window and selects that window for
2299 editing.  In turn, @code{pop-to-buffer} uses @code{display-buffer} for
2300 displaying the buffer.  Hence, all the variables affecting
2301 @code{display-buffer} will affect it as well.  @xref{Choosing Window},
2302 for the documentation of @code{display-buffer}.
2304 @deffn Command pop-to-buffer buffer-or-name &optional action norecord
2305 This function makes @var{buffer-or-name} the current buffer and
2306 displays it in some window, preferably not the window currently
2307 selected.  It then selects the displaying window.  If that window is
2308 on a different graphical frame, that frame is given input focus if
2309 possible (@pxref{Input Focus}).
2311 If @var{buffer-or-name} is @code{nil}, it defaults to the buffer
2312 returned by @code{other-buffer} (@pxref{Buffer List}).  If
2313 @var{buffer-or-name} is a string that is not the name of any existing
2314 buffer, this function creates a new buffer with that name; the new
2315 buffer's major mode is determined by the variable @code{major-mode}
2316 (@pxref{Major Modes}).  In any case, that buffer is made current and
2317 returned, even when no suitable window was found to display it.
2319 If @var{action} is non-@code{nil}, it should be a display action to
2320 pass to @code{display-buffer} (@pxref{Choosing Window}).
2321 Alternatively, a non-@code{nil}, non-list value means to pop to a
2322 window other than the selected one---even if the buffer is already
2323 displayed in the selected window.
2325 Like @code{switch-to-buffer}, this function updates the buffer list
2326 unless @var{norecord} is non-@code{nil}.
2327 @end deffn
2330 @node Choosing Window
2331 @section Choosing a Window for Display
2333   The command @code{display-buffer} flexibly chooses a window for
2334 display, and displays a specified buffer in that window.  It can be
2335 called interactively, via the key binding @kbd{C-x 4 C-o}.  It is also
2336 used as a subroutine by many functions and commands, including
2337 @code{switch-to-buffer} and @code{pop-to-buffer} (@pxref{Switching
2338 Buffers}).
2340 @cindex display action
2341 @cindex action function, for @code{display-buffer}
2342 @cindex action alist, for @code{display-buffer}
2343   This command performs several complex steps to find a window to
2344 display in.  These steps are described by means of @dfn{display
2345 actions}, which have the form @code{(@var{function} . @var{alist})}.
2346 Here, @var{function} is either a function or a list of functions,
2347 which we refer to as @dfn{action functions}; @var{alist} is an
2348 association list, which we refer to as an @dfn{action alist}.
2350   An action function accepts two arguments: the buffer to display and
2351 an action alist.  It attempts to display the buffer in some window,
2352 picking or creating a window according to its own criteria.  If
2353 successful, it returns the window; otherwise, it returns @code{nil}.
2354 @xref{Display Action Functions}, for a list of predefined action
2355 functions.
2357   @code{display-buffer} works by combining display actions from
2358 several sources, and calling the action functions in turn, until one
2359 of them manages to display the buffer and returns a non-@code{nil}
2360 value.
2362 @deffn Command display-buffer buffer-or-name &optional action frame
2363 This command makes @var{buffer-or-name} appear in some window, without
2364 selecting the window or making the buffer current.  The argument
2365 @var{buffer-or-name} must be a buffer or the name of an existing
2366 buffer.  The return value is the window chosen to display the buffer.
2368 The optional argument @var{action}, if non-@code{nil}, should normally
2369 be a display action (described above).  @code{display-buffer} builds a
2370 list of action functions and an action alist, by consolidating display
2371 actions from the following sources (in order):
2373 @itemize
2374 @item
2375 The variable @code{display-buffer-overriding-action}.
2377 @item
2378 The user option @code{display-buffer-alist}.
2380 @item
2381 The @var{action} argument.
2383 @item
2384 The user option @code{display-buffer-base-action}.
2386 @item
2387 The constant @code{display-buffer-fallback-action}.
2388 @end itemize
2390 @noindent
2391 Each action function is called in turn, passing the buffer as the
2392 first argument and the combined action alist as the second argument,
2393 until one of the functions returns non-@code{nil}.  The caller can
2394 pass @code{(allow-no-window . t)} as an element of the action alist to
2395 indicate its readiness to handle the case of not displaying the
2396 buffer in a window.
2398 The argument @var{action} can also have a non-@code{nil}, non-list
2399 value.  This has the special meaning that the buffer should be
2400 displayed in a window other than the selected one, even if the
2401 selected window is already displaying it.  If called interactively
2402 with a prefix argument, @var{action} is @code{t}.
2404 The optional argument @var{frame}, if non-@code{nil}, specifies which
2405 frames to check when deciding whether the buffer is already displayed.
2406 It is equivalent to adding an element @code{(reusable-frames
2407 . @var{frame})} to the action alist of @var{action}.  @xref{Display
2408 Action Functions}.
2409 @end deffn
2411 @defvar display-buffer-overriding-action
2412 The value of this variable should be a display action, which is
2413 treated with the highest priority by @code{display-buffer}.  The
2414 default value is empty, i.e., @code{(nil . nil)}.
2415 @end defvar
2417 @defopt display-buffer-alist
2418 The value of this option is an alist mapping conditions to display
2419 actions.  Each condition may be either a regular expression matching a
2420 buffer name or a function that takes two arguments: a buffer name and
2421 the @var{action} argument passed to @code{display-buffer}.  If the name
2422 of the buffer passed to @code{display-buffer} either matches a regular
2423 expression in this alist or the function specified by a condition
2424 returns non-@code{nil}, then @code{display-buffer} uses the
2425 corresponding display action to display the buffer.
2426 @end defopt
2428 @defopt display-buffer-base-action
2429 The value of this option should be a display action.  This option can
2430 be used to define a standard display action for calls to
2431 @code{display-buffer}.
2432 @end defopt
2434 @defvr Constant display-buffer-fallback-action
2435 This display action specifies the fallback behavior for
2436 @code{display-buffer} if no other display actions are given.
2437 @end defvr
2440 @node Display Action Functions
2441 @section Action Functions for @code{display-buffer}
2443 The following basic action functions are defined in Emacs.  Each of
2444 these functions takes two arguments: @var{buffer}, the buffer to
2445 display, and @var{alist}, an action alist.  Each action function
2446 returns the window if it succeeds, and @code{nil} if it fails.
2448 @defun display-buffer-same-window buffer alist
2449 This function tries to display @var{buffer} in the selected window.
2450 It fails if the selected window is a minibuffer window or is dedicated
2451 to another buffer (@pxref{Dedicated Windows}).  It also fails if
2452 @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry.
2453 @end defun
2455 @defun display-buffer-reuse-window buffer alist
2456 This function tries to display @var{buffer} by finding a window
2457 that is already displaying it.
2459 If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry,
2460 the selected window is not eligible for reuse.  If @var{alist}
2461 contains a @code{reusable-frames} entry, its value determines which
2462 frames to search for a reusable window:
2464 @itemize @bullet
2465 @item
2466 @code{nil} means consider windows on the selected frame.
2467 (Actually, the last non-minibuffer frame.)
2468 @item
2469 @code{t} means consider windows on all frames.
2470 @item
2471 @code{visible} means consider windows on all visible frames.
2472 @item
2473 0 means consider windows on all visible or iconified frames.
2474 @item
2475 A frame means consider windows on that frame only.
2476 @end itemize
2478 Note that these meanings differ slightly from those of the
2479 @var{all-frames} argument to @code{next-window} (@pxref{Cyclic Window
2480 Ordering}).
2482 If @var{alist} contains no @code{reusable-frames} entry, this function
2483 normally searches just the selected frame; however, if the variable
2484 @code{pop-up-frames} is non-@code{nil}, it searches all frames on the
2485 current terminal.  @xref{Choosing Window Options}.
2487 If this function chooses a window on another frame, it makes that frame
2488 visible and, unless @var{alist} contains an @code{inhibit-switch-frame}
2489 entry (@pxref{Choosing Window Options}), raises that frame if necessary.
2490 @end defun
2492 @defun display-buffer-reuse-mode-window buffer alist
2493 This function tries to display @var{buffer} by finding a window
2494 that is displaying a buffer in a given mode.
2496 If @var{alist} contains a @code{mode} entry, its value is a major mode
2497 (a symbol) or a list of major modes.  If @var{alist} contains no
2498 @code{mode} entry, the current major mode of @var{buffer} is used.  A
2499 window is a candidate if it displays a buffer that derives from one of
2500 the given modes.
2502 The behavior is also controlled by entries for
2503 @code{inhibit-same-window}, @code{reusable-frames} and
2504 @code{inhibit-switch-frame} as is done in the function
2505 @code{display-buffer-reuse-window}.
2507 @end defun
2509 @defun display-buffer-pop-up-frame buffer alist
2510 This function creates a new frame, and displays the buffer in that
2511 frame's window.  It actually performs the frame creation by calling
2512 the function specified in @code{pop-up-frame-function}
2513 (@pxref{Choosing Window Options}).  If @var{alist} contains a
2514 @code{pop-up-frame-parameters} entry, the associated value
2515 is added to the newly created frame's parameters.
2516 @end defun
2518 @defun display-buffer-in-child-frame buffer alist
2519 This function tries to display @var{buffer} in a child frame
2520 (@pxref{Child Frames}) of the selected frame, either reusing an existing
2521 child frame or by making a new one.  If @var{alist} has a non-@code{nil}
2522 @code{child-frame-parameters} entry, the corresponding value is an alist
2523 of frame parameters to give the new frame.  A @code{parent-frame}
2524 parameter specifying the selected frame is provided by default.  If the
2525 child frame should be or become the child of another frame, a
2526 corresponding entry must be added to @var{alist}.
2528 The appearance of child frames is largely dependent on the parameters
2529 provided via @var{alist}.  It is advisable to use at least ratios to
2530 specify the size (@pxref{Size Parameters}) and the position
2531 (@pxref{Position Parameters}) of the child frame and to add the
2532 @code{keep-ratio} in order to make sure that the child frame remains
2533 visible.  For other parameters that should be considered see @ref{Child
2534 Frames}.
2535 @end defun
2537 @defun display-buffer-use-some-frame buffer alist
2538 This function tries to display @var{buffer} by trying to find a
2539 frame that meets a predicate (by default any frame other than the
2540 current frame).
2542 If this function chooses a window on another frame, it makes that frame
2543 visible and, unless @var{alist} contains an @code{inhibit-switch-frame}
2544 entry (@pxref{Choosing Window Options}), raises that frame if necessary.
2546 If @var{alist} has a non-@code{nil} @code{frame-predicate} entry, its
2547 value is a function taking one argument (a frame), returning
2548 non-@code{nil} if the frame is a candidate; this function replaces the
2549 default predicate.
2551 If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry,
2552 the selected window is used; thus if the selected frame has a single
2553 window, it is not used.
2554 @end defun
2556 @defun display-buffer-pop-up-window buffer alist
2557 This function tries to display @var{buffer} by splitting the largest
2558 or least recently-used window (typically one on the selected frame).
2559 It actually performs the split by calling the function specified in
2560 @code{split-window-preferred-function} (@pxref{Choosing Window
2561 Options}).
2563 The size of the new window can be adjusted by supplying
2564 @code{window-height} and @code{window-width} entries in @var{alist}.  To
2565 adjust the window's height, use an entry whose @sc{car} is
2566 @code{window-height} and whose @sc{cdr} is one of:
2568 @itemize @bullet
2569 @item
2570 @code{nil} means to leave the height of the new window alone.
2572 @item
2573 A number specifies the desired height of the new window.  An integer
2574 specifies the number of lines of the window.  A floating-point
2575 number gives the fraction of the window's height with respect to the
2576 height of the frame's root window.
2578 @item
2579 If the @sc{cdr} specifies a function, that function is called with one
2580 argument: the new window.  The function is supposed to adjust the
2581 height of the window; its return value is ignored.  Suitable functions
2582 are @code{shrink-window-if-larger-than-buffer} and
2583 @code{fit-window-to-buffer}, see @ref{Resizing Windows}.
2584 @end itemize
2586 To adjust the window's width, use an entry whose @sc{car} is
2587 @code{window-width} and whose @sc{cdr} is one of:
2589 @itemize @bullet
2590 @item
2591 @code{nil} means to leave the width of the new window alone.
2593 @item
2594 A number specifies the desired width of the new window.  An integer
2595 specifies the number of columns of the window.  A floating-point
2596 number gives the fraction of the window's width with respect to the
2597 width of the frame's root window.
2599 @item
2600 If the @sc{cdr} specifies a function, that function is called with one
2601 argument: the new window.  The function is supposed to adjust the width
2602 of the window; its return value is ignored.
2603 @end itemize
2605 If @var{alist} contains a @code{preserve-size} entry, Emacs will try to
2606 preserve the size of the new window during future resize operations
2607 (@pxref{Preserving Window Sizes}).  The @sc{cdr} of that entry must be a
2608 cons cell whose @sc{car}, if non-@code{nil}, means to preserve the width
2609 of the window and whose @sc{cdr}, if non-@code{nil}, means to preserve
2610 the height of the window.
2612 This function can fail if no window splitting can be performed for some
2613 reason (e.g., if the selected frame has an @code{unsplittable} frame
2614 parameter; @pxref{Buffer Parameters}).
2615 @end defun
2617 @defun display-buffer-below-selected buffer alist
2618 This function tries to display @var{buffer} in a window below the
2619 selected window.  If there is a window below the selected one and that
2620 window already displays @var{buffer}, it reuses that window.
2622 If there is no such window, this function tries to create a new window
2623 by splitting the selected one and display @var{buffer} there.  It will
2624 also adjust that window's size provided @var{alist} contains a suitable
2625 @code{window-height} or @code{window-width} entry, see above.
2627 If splitting the selected window fails and there is a non-dedicated
2628 window below the selected one showing some other buffer, it uses that
2629 window for showing @var{buffer}.
2630 @end defun
2632 @defun display-buffer-in-previous-window buffer alist
2633 This function tries to display @var{buffer} in a window previously
2634 showing it.  If @var{alist} has a non-@code{nil}
2635 @code{inhibit-same-window} entry, the selected window is not eligible
2636 for reuse.  If @var{alist} contains a @code{reusable-frames} entry, its
2637 value determines which frames to search for a suitable window as with
2638 @code{display-buffer-reuse-window}.
2640 If @var{alist} has a @code{previous-window} entry, the window
2641 specified by that entry will override any other window found by the
2642 methods above, even if that window never showed @var{buffer} before.
2643 @end defun
2645 @defun display-buffer-at-bottom buffer alist
2646 This function tries to display @var{buffer} in a window at the bottom
2647 of the selected frame.
2649 This either splits the window at the bottom of the frame or the
2650 frame's root window, or reuses an existing window at the bottom of the
2651 selected frame.
2652 @end defun
2654 @defun display-buffer-use-some-window buffer alist
2655 This function tries to display @var{buffer} by choosing an existing
2656 window and displaying the buffer in that window.  It can fail if all
2657 windows are dedicated to another buffer (@pxref{Dedicated Windows}).
2658 @end defun
2660 @defun display-buffer-no-window buffer alist
2661 If @var{alist} has a non-@code{nil} @code{allow-no-window} entry, then
2662 this function does not display @code{buffer}.  This allows you to
2663 override the default action and avoid displaying the buffer.  It is
2664 assumed that when the caller specifies a non-@code{nil}
2665 @code{allow-no-window} value it can handle a @code{nil} value returned
2666 from @code{display-buffer} in this case.
2667 @end defun
2669 If the @var{alist} argument of any of these functions contains a
2670 @code{window-parameters} entry, @code{display-buffer} assigns the
2671 elements of the associated value as window parameters of the chosen
2672 window.
2674    To illustrate the use of action functions, consider the following
2675 example.
2677 @example
2678 @group
2679 (display-buffer
2680  (get-buffer-create "*foo*")
2681  '((display-buffer-reuse-window
2682     display-buffer-pop-up-window
2683     display-buffer-pop-up-frame)
2684    (reusable-frames . 0)
2685    (window-height . 10) (window-width . 40)))
2686 @end group
2687 @end example
2689 @noindent
2690 Evaluating the form above will cause @code{display-buffer} to proceed as
2691 follows: If a buffer called *foo* already appears on a visible or
2692 iconified frame, it will reuse its window.  Otherwise, it will try to
2693 pop up a new window or, if that is impossible, a new frame and show the
2694 buffer there.  If all these steps fail, it will proceed using whatever
2695 @code{display-buffer-base-action} and
2696 @code{display-buffer-fallback-action} prescribe.
2698    Furthermore, @code{display-buffer} will try to adjust a reused window
2699 (provided *foo* was put by @code{display-buffer} there before) or a
2700 popped-up window as follows: If the window is part of a vertical
2701 combination, it will set its height to ten lines.  Note that if, instead
2702 of the number 10, we specified the function
2703 @code{fit-window-to-buffer}, @code{display-buffer} would come up with a
2704 one-line window to fit the empty buffer.  If the window is part of a
2705 horizontal combination, it sets its width to 40 columns.  Whether a new
2706 window is vertically or horizontally combined depends on the shape of
2707 the window split and the values of
2708 @code{split-window-preferred-function}, @code{split-height-threshold}
2709 and @code{split-width-threshold} (@pxref{Choosing Window Options}).
2711    Now suppose we combine this call with a preexisting setup for
2712 @code{display-buffer-alist} as follows.
2714 @example
2715 @group
2716 (let ((display-buffer-alist
2717        (cons
2718         '("\\*foo\\*"
2719           (display-buffer-reuse-window display-buffer-below-selected)
2720           (reusable-frames)
2721           (window-height . 5))
2722         display-buffer-alist)))
2723   (display-buffer
2724    (get-buffer-create "*foo*")
2725    '((display-buffer-reuse-window
2726       display-buffer-pop-up-window
2727       display-buffer-pop-up-frame)
2728      (reusable-frames . 0)
2729      (window-height . 10) (window-width . 40))))
2730 @end group
2731 @end example
2733 @noindent
2734 This form will have @code{display-buffer} first try reusing a window
2735 that shows *foo* on the selected frame.  If there's no such window, it
2736 will try to split the selected window or, if that is impossible, use the
2737 window below the selected window.
2739    If there's no window below the selected one, or the window below the
2740 selected one is dedicated to its buffer, @code{display-buffer} will
2741 proceed as described in the previous example.  Note, however, that when
2742 it tries to adjust the height of any reused or popped-up window, it will
2743 in any case try to set its number of lines to 5 since that value
2744 overrides the corresponding specification in the @var{action} argument
2745 of @code{display-buffer}.
2748 @node Choosing Window Options
2749 @section Additional Options for Displaying Buffers
2751 The behavior of the standard display actions of @code{display-buffer}
2752 (@pxref{Choosing Window}) can be modified by a variety of user
2753 options.
2755 @defopt pop-up-windows
2756 If the value of this variable is non-@code{nil}, @code{display-buffer}
2757 is allowed to split an existing window to make a new window for
2758 displaying in.  This is the default.
2760 This variable is provided mainly for backward compatibility.  It is
2761 obeyed by @code{display-buffer} via a special mechanism in
2762 @code{display-buffer-fallback-action}, which only calls the action
2763 function @code{display-buffer-pop-up-window} (@pxref{Display Action
2764 Functions}) when the value is @code{nil}.  It is not consulted by
2765 @code{display-buffer-pop-up-window} itself, which the user may specify
2766 directly in @code{display-buffer-alist} etc.
2767 @end defopt
2769 @defopt split-window-preferred-function
2770 This variable specifies a function for splitting a window, in order to
2771 make a new window for displaying a buffer.  It is used by the
2772 @code{display-buffer-pop-up-window} action function to actually split
2773 the window (@pxref{Display Action Functions}).
2775 The default value is @code{split-window-sensibly}, which is documented
2776 below.  The value must be a function that takes one argument, a window,
2777 and return either a new window (which will be used to display the
2778 desired buffer) or @code{nil} (which means the splitting failed).
2779 @end defopt
2781 @defun split-window-sensibly &optional window
2782 This function tries to split @var{window}, and return the newly created
2783 window.  If @var{window} cannot be split, it returns @code{nil}.  If
2784 @var{window} is omitted or @code{nil}, it defaults to the selected
2785 window.
2787 This function obeys the usual rules that determine when a window may
2788 be split (@pxref{Splitting Windows}).  It first tries to split by
2789 placing the new window below, subject to the restriction imposed by
2790 @code{split-height-threshold} (see below), in addition to any other
2791 restrictions.  If that fails, it tries to split by placing the new
2792 window to the right, subject to @code{split-width-threshold} (see
2793 below).  If that fails, and the window is the only window on its
2794 frame, this function again tries to split and place the new window
2795 below, disregarding @code{split-height-threshold}.  If this fails as
2796 well, this function gives up and returns @code{nil}.
2797 @end defun
2799 @defopt split-height-threshold
2800 This variable, used by @code{split-window-sensibly}, specifies whether
2801 to split the window placing the new window below.  If it is an
2802 integer, that means to split only if the original window has at least
2803 that many lines.  If it is @code{nil}, that means not to split this
2804 way.
2805 @end defopt
2807 @defopt split-width-threshold
2808 This variable, used by @code{split-window-sensibly}, specifies whether
2809 to split the window placing the new window to the right.  If the value
2810 is an integer, that means to split only if the original window has at
2811 least that many columns.  If the value is @code{nil}, that means not
2812 to split this way.
2813 @end defopt
2815 @defopt even-window-sizes
2816 This variable, if non-@code{nil}, causes @code{display-buffer} to even
2817 window sizes whenever it reuses an existing window and that window is
2818 adjacent to the selected one.
2820 If its value is @code{width-only}, sizes are evened only if the reused
2821 window is on the left or right of the selected one and the selected
2822 window is wider than the reused one.  If its value is @code{height-only}
2823 sizes are evened only if the reused window is above or beneath the
2824 selected window and the selected window is higher than the reused one.
2825 Any other non-@code{nil} value means to even sizes in any of these cases
2826 provided the selected window is larger than the reused one in the sense
2827 of their combination.
2828 @end defopt
2830 @defopt pop-up-frames
2831 If the value of this variable is non-@code{nil}, that means
2832 @code{display-buffer} may display buffers by making new frames.  The
2833 default is @code{nil}.
2835 A non-@code{nil} value also means that when @code{display-buffer} is
2836 looking for a window already displaying @var{buffer-or-name}, it can
2837 search any visible or iconified frame, not just the selected frame.
2839 This variable is provided mainly for backward compatibility.  It is
2840 obeyed by @code{display-buffer} via a special mechanism in
2841 @code{display-buffer-fallback-action}, which calls the action function
2842 @code{display-buffer-pop-up-frame} (@pxref{Display Action Functions})
2843 if the value is non-@code{nil}.  (This is done before attempting to
2844 split a window.)  This variable is not consulted by
2845 @code{display-buffer-pop-up-frame} itself, which the user may specify
2846 directly in @code{display-buffer-alist} etc.
2847 @end defopt
2849 @defopt pop-up-frame-function
2850 This variable specifies a function for creating a new frame, in order
2851 to make a new window for displaying a buffer.  It is used by the
2852 @code{display-buffer-pop-up-frame} action function (@pxref{Display
2853 Action Functions}).
2855 The value should be a function that takes no arguments and returns a
2856 frame, or @code{nil} if no frame could be created.  The default value
2857 is a function that creates a frame using the parameters specified by
2858 @code{pop-up-frame-alist} (see below).
2859 @end defopt
2861 @defopt pop-up-frame-alist
2862 This variable holds an alist of frame parameters (@pxref{Frame
2863 Parameters}), which is used by the default function in
2864 @code{pop-up-frame-function} to make a new frame.  The default is
2865 @code{nil}.
2866 @end defopt
2868 @defopt same-window-buffer-names
2869 A list of buffer names for buffers that should be displayed in the
2870 selected window.  If a buffer's name is in this list,
2871 @code{display-buffer} handles the buffer by showing it in the selected
2872 window.
2873 @end defopt
2875 @defopt same-window-regexps
2876 A list of regular expressions that specify buffers that should be
2877 displayed in the selected window.  If the buffer's name matches any of
2878 the regular expressions in this list, @code{display-buffer} handles the
2879 buffer by showing it in the selected window.
2880 @end defopt
2882 @defun same-window-p buffer-name
2883 This function returns @code{t} if displaying a buffer
2884 named @var{buffer-name} with @code{display-buffer} would
2885 put it in the selected window.
2886 @end defun
2888 @node Window History
2889 @section Window History
2890 @cindex window history
2892 Each window remembers in a list the buffers it has previously
2893 displayed, and the order in which these buffers were removed from it.
2894 This history is used, for example, by @code{replace-buffer-in-windows}
2895 (@pxref{Buffers and Windows}), and when quitting windows
2896 (@pxref{Quitting Windows}).  The list is automatically maintained by
2897 Emacs, but you can use the following functions to explicitly inspect
2898 or alter it:
2900 @defun window-prev-buffers &optional window
2901 This function returns a list specifying the previous contents of
2902 @var{window}.  The optional argument @var{window} should be a live
2903 window and defaults to the selected one.
2905 Each list element has the form @code{(@var{buffer} @var{window-start}
2906 @var{window-pos})}, where @var{buffer} is a buffer previously shown in
2907 the window, @var{window-start} is the window start position
2908 (@pxref{Window Start and End}) when that buffer was last shown, and
2909 @var{window-pos} is the point position (@pxref{Window Point}) when
2910 that buffer was last shown in @var{window}.
2912 The list is ordered so that earlier elements correspond to more
2913 recently-shown buffers, and the first element usually corresponds to the
2914 buffer most recently removed from the window.
2915 @end defun
2917 @defun set-window-prev-buffers window prev-buffers
2918 This function sets @var{window}'s previous buffers to the value of
2919 @var{prev-buffers}.  The argument @var{window} must be a live window
2920 and defaults to the selected one.  The argument @var{prev-buffers}
2921 should be a list of the same form as that returned by
2922 @code{window-prev-buffers}.
2923 @end defun
2925 In addition, each buffer maintains a list of @dfn{next buffers}, which
2926 is a list of buffers re-shown by @code{switch-to-prev-buffer} (see
2927 below).  This list is mainly used by @code{switch-to-prev-buffer} and
2928 @code{switch-to-next-buffer} for choosing buffers to switch to.
2930 @defun window-next-buffers &optional window
2931 This function returns the list of buffers recently re-shown in
2932 @var{window} via @code{switch-to-prev-buffer}.  The @var{window}
2933 argument must denote a live window or @code{nil} (meaning the selected
2934 window).
2935 @end defun
2937 @defun set-window-next-buffers window next-buffers
2938 This function sets the next buffer list of @var{window} to
2939 @var{next-buffers}.  The @var{window} argument should be a live window
2940 or @code{nil} (meaning the selected window).  The argument
2941 @var{next-buffers} should be a list of buffers.
2942 @end defun
2944 The following commands can be used to cycle through the global buffer
2945 list, much like @code{bury-buffer} and @code{unbury-buffer}.  However,
2946 they cycle according to the specified window's history list, rather
2947 than the global buffer list.  In addition, they restore
2948 window-specific window start and point positions, and may show a
2949 buffer even if it is already shown in another window.  The
2950 @code{switch-to-prev-buffer} command, in particular, is used by
2951 @code{replace-buffer-in-windows}, @code{bury-buffer} and
2952 @code{quit-window} to find a replacement buffer for a window.
2954 @deffn Command switch-to-prev-buffer &optional window bury-or-kill
2955 This command displays the previous buffer in @var{window}.  The
2956 argument @var{window} should be a live window or @code{nil} (meaning
2957 the selected window).  If the optional argument @var{bury-or-kill} is
2958 non-@code{nil}, this means that the buffer currently shown in
2959 @var{window} is about to be buried or killed and consequently should
2960 not be switched to in future invocations of this command.
2962 The previous buffer is usually the buffer shown before the buffer
2963 currently shown in @var{window}.  However, a buffer that has been buried
2964 or killed, or has been already shown by a recent invocation of
2965 @code{switch-to-prev-buffer}, does not qualify as previous buffer.
2967 If repeated invocations of this command have already shown all buffers
2968 previously shown in @var{window}, further invocations will show buffers
2969 from the buffer list of the frame @var{window} appears on (@pxref{Buffer
2970 List}), trying to skip buffers that are already shown in another window
2971 on that frame.
2972 @end deffn
2974 @deffn Command switch-to-next-buffer &optional window
2975 This command switches to the next buffer in @var{window}, thus undoing
2976 the effect of the last @code{switch-to-prev-buffer} command in
2977 @var{window}.  The argument @var{window} must be a live window and
2978 defaults to the selected one.
2980 If there is no recent invocation of @code{switch-to-prev-buffer} that
2981 can be undone, this function tries to show a buffer from the buffer list
2982 of the frame @var{window} appears on (@pxref{Buffer List}).
2983 @end deffn
2985 By default @code{switch-to-prev-buffer} and @code{switch-to-next-buffer}
2986 can switch to a buffer that is already shown in another window on the
2987 same frame.  The following option can be used to override this behavior.
2989 @defopt switch-to-visible-buffer
2990 If this variable is non-@code{nil}, @code{switch-to-prev-buffer} and
2991 @code{switch-to-next-buffer} may switch to a buffer that is already
2992 visible on the same frame, provided the buffer was shown in the
2993 relevant window before.  If it is @code{nil},
2994 @code{switch-to-prev-buffer} and @code{switch-to-next-buffer} always
2995 try to avoid switching to a buffer that is already visible in another
2996 window on the same frame.  The default is @code{t}.
2997 @end defopt
3000 @node Dedicated Windows
3001 @section Dedicated Windows
3002 @cindex dedicated window
3004 Functions for displaying a buffer can be told to not use specific
3005 windows by marking these windows as @dfn{dedicated} to their buffers.
3006 @code{display-buffer} (@pxref{Choosing Window}) never uses a dedicated
3007 window for displaying another buffer in it.  @code{get-lru-window} and
3008 @code{get-largest-window} (@pxref{Cyclic Window Ordering}) do not
3009 consider dedicated windows as candidates when their @var{dedicated}
3010 argument is non-@code{nil}.  The behavior of @code{set-window-buffer}
3011 (@pxref{Buffers and Windows}) with respect to dedicated windows is
3012 slightly different, see below.
3014    Functions supposed to remove a buffer from a window or a window from
3015 a frame can behave specially when a window they operate on is dedicated.
3016 We will distinguish three basic cases, namely where (1) the window is
3017 not the only window on its frame, (2) the window is the only window on
3018 its frame but there are other frames on the same terminal left, and (3)
3019 the window is the only window on the only frame on the same terminal.
3021    In particular, @code{delete-windows-on} (@pxref{Deleting Windows})
3022 handles case (2) by deleting the associated frame and case (3) by
3023 showing another buffer in that frame's only window.  The function
3024 @code{replace-buffer-in-windows} (@pxref{Buffers and Windows}) which is
3025 called when a buffer gets killed, deletes the window in case (1) and
3026 behaves like @code{delete-windows-on} otherwise.
3027 @c FIXME: Does replace-buffer-in-windows _delete_ a window in case (1)?
3029    When @code{bury-buffer} (@pxref{Buffer List}) operates on the
3030 selected window (which shows the buffer that shall be buried), it
3031 handles case (2) by calling @code{frame-auto-hide-function}
3032 (@pxref{Quitting Windows}) to deal with the selected frame.  The other
3033 two cases are handled as with @code{replace-buffer-in-windows}.
3035 @defun window-dedicated-p &optional window
3036 This function returns non-@code{nil} if @var{window} is dedicated to its
3037 buffer and @code{nil} otherwise.  More precisely, the return value is
3038 the value assigned by the last call of @code{set-window-dedicated-p} for
3039 @var{window}, or @code{nil} if that function was never called with
3040 @var{window} as its argument.  The default for @var{window} is the
3041 selected window.
3042 @end defun
3044 @defun set-window-dedicated-p window flag
3045 This function marks @var{window} as dedicated to its buffer if
3046 @var{flag} is non-@code{nil}, and non-dedicated otherwise.
3048 As a special case, if @var{flag} is @code{t}, @var{window} becomes
3049 @dfn{strongly} dedicated to its buffer.  @code{set-window-buffer}
3050 signals an error when the window it acts upon is strongly dedicated to
3051 its buffer and does not already display the buffer it is asked to
3052 display.  Other functions do not treat @code{t} differently from any
3053 non-@code{nil} value.
3054 @end defun
3057 @node Quitting Windows
3058 @section Quitting Windows
3060 When you want to get rid of a window used for displaying a buffer, you
3061 can call @code{delete-window} or @code{delete-windows-on}
3062 (@pxref{Deleting Windows}) to remove that window from its frame.  If the
3063 buffer is shown on a separate frame, you might want to call
3064 @code{delete-frame} (@pxref{Deleting Frames}) instead.  If, on the other
3065 hand, a window has been reused for displaying the buffer, you might
3066 prefer showing the buffer previously shown in that window, by calling the
3067 function @code{switch-to-prev-buffer} (@pxref{Window History}).
3068 Finally, you might want to either bury (@pxref{Buffer List}) or kill
3069 (@pxref{Killing Buffers}) the window's buffer.
3071    The following command uses information on how the window for
3072 displaying the buffer was obtained in the first place, thus attempting
3073 to automate the above decisions for you.
3075 @deffn Command quit-window &optional kill window
3076 This command quits @var{window} and buries its buffer.  The argument
3077 @var{window} must be a live window and defaults to the selected one.
3078 With prefix argument @var{kill} non-@code{nil}, it kills the buffer
3079 instead of burying it.  It calls the function @code{quit-restore-window}
3080 described next to deal with the window and its buffer.
3081 @end deffn
3083 @defun quit-restore-window &optional window bury-or-kill
3084 This function handles @var{window} and its buffer after quitting.  The
3085 optional argument @var{window} must be a live window and defaults to
3086 the selected one. The function's behavior is determined by the four
3087 elements of the @code{quit-restore} window parameter (@pxref{Window
3088 Parameters}), which is set to @code{nil} afterwards.
3090 The window is deleted entirely if: 1) the first element of the
3091 @code{quit-restore} parameter is one of 'window or 'frame, 2) the
3092 window has no history of previously-displayed buffers, and 3) the
3093 displayed buffer matches the one in the fourth element of the
3094 @code{quit-restore} parameter.  If @var{window} is the
3095 only window on its frame and there are other frames on the frame's
3096 terminal, the value of the optional argument @var{bury-or-kill}
3097 determines how to proceed with the window.  If @var{bury-or-kill}
3098 equals @code{kill}, the frame is deleted unconditionally.  Otherwise,
3099 the fate of the frame is determined by calling
3100 @code{frame-auto-hide-function} (see below) with that frame as sole
3101 argument.
3103 If the third element of the @code{quit-restore} parameter is a list of
3104 buffer, window start (@pxref{Window Start and End}), and point
3105 (@pxref{Window Point}), and that buffer is still live, the buffer will
3106 be displayed, and start and point set accordingly.  If, in addition,
3107 @var{window}'s buffer was temporarily resized, this function will also
3108 try to restore the original height of @var{window}.
3110 Otherwise, if @var{window} was previously used for displaying other
3111 buffers (@pxref{Window History}), the most recent buffer in that
3112 history will be displayed.
3114 The optional argument @var{bury-or-kill} specifies how to deal with
3115 @var{window}'s buffer.  The following values are handled:
3117 @table @code
3118 @item nil
3119 This means to not deal with the buffer in any particular way.  As a
3120 consequence, if @var{window} is not deleted, invoking
3121 @code{switch-to-prev-buffer} will usually show the buffer again.
3123 @item append
3124 This means that if @var{window} is not deleted, its buffer is moved to
3125 the end of @var{window}'s list of previous buffers, so it's less likely
3126 that a future invocation of @code{switch-to-prev-buffer} will switch to
3127 it.  Also, it moves the buffer to the end of the frame's buffer list.
3129 @item bury
3130 This means that if @var{window} is not deleted, its buffer is removed
3131 from @var{window}'s list of previous buffers.  Also, it moves the buffer
3132 to the end of the frame's buffer list.  This value provides the most
3133 reliable remedy to not have @code{switch-to-prev-buffer} switch to this
3134 buffer again without killing the buffer.
3136 @item kill
3137 This means to kill @var{window}'s buffer.
3138 @end table
3140 Typically, the display routines run by @code{display-buffer} will set
3141 the @code{quit-restore} window parameter correctly.  It's also
3142 possible to set it manually, using the following code for displaying
3143 @var{buffer} in @var{window}:
3145 @example
3146 @group
3147 (display-buffer-record-window type window buffer)
3149 (set-window-buffer window buffer)
3151 (set-window-prev-buffers window nil)
3152 @end group
3153 @end example
3155 Setting the window history to @code{nil} ensures that a future call to
3156 @code{quit-window} can delete the window altogether.
3158 @end defun
3160 The following option specifies how to deal with a frame containing just
3161 one window that should be either quit, or whose buffer should be buried.
3163 @defopt frame-auto-hide-function
3164 The function specified by this option is called to automatically hide
3165 frames.  This function is called with one argument---a frame.
3167 The function specified here is called by @code{bury-buffer}
3168 (@pxref{Buffer List}) when the selected window is dedicated and shows
3169 the buffer to bury.  It is also called by @code{quit-restore-window}
3170 (see above) when the frame of the window to quit has been specially
3171 created for displaying that window's buffer and the buffer is not
3172 killed.
3174 The default is to call @code{iconify-frame} (@pxref{Visibility of
3175 Frames}).  Alternatively, you may specify either @code{delete-frame}
3176 (@pxref{Deleting Frames}) to remove the frame from its display,
3177 @code{make-frame-invisible} to make the frame invisible, @code{ignore}
3178 to leave the frame unchanged, or any other function that can take a
3179 frame as its sole argument.
3181 Note that the function specified by this option is called only if the
3182 specified frame contains just one live window and there is at least one
3183 other frame on the same terminal.
3185 For a particular frame, the value specified here may be overridden by
3186 that frame's @code{auto-hide-function} frame parameter (@pxref{Frame
3187 Interaction Parameters}).
3188 @end defopt
3191 @node Side Windows
3192 @section Side Windows
3193 @cindex side windows
3194 @cindex main window
3195 @cindex main window of a frame
3197 Side windows are special windows positioned at any of the four sides of
3198 a frame's root window (@pxref{Windows and Frames}).  In practice, this
3199 means that the area of the frame's root window is subdivided into a main
3200 window and a number of side windows surrounding that main window.  The
3201 main window is either a ``normal'' live window or specifies the area
3202 containing all the normal windows.
3204    In their most simple form of use, side windows allow to display
3205 specific buffers always in the same area of a frame.  Hence they can be
3206 regarded as a generalization of the concept provided by
3207 @code{display-buffer-at-bottom} (@pxref{Display Action Functions}) to
3208 the remaining sides of a frame.  With suitable customizations, however,
3209 side windows can be also used to provide frame layouts similar to those
3210 found in so-called integrated development environments (IDEs).
3212 @menu
3213 * Displaying Buffers in Side Windows:: An action function for displaying
3214                               buffers in side windows.
3215 * Side Window Options and Functions:: Further tuning of side windows.
3216 * Frame Layouts with Side Windows:: Setting up frame layouts with side
3217                               windows.
3218 @end menu
3221 @node Displaying Buffers in Side Windows
3222 @subsection Displaying Buffers in Side Windows
3224 The following action function for @code{display-buffer} (@pxref{Display
3225 Action Functions}) creates or reuses a side window for displaying the
3226 specified buffer.
3228 @defun display-buffer-in-side-window buffer alist
3229 This function displays @var{buffer} in a side window of the selected
3230 frame.  It returns the window used for displaying @var{buffer},
3231 @code{nil} if no such window can be found or created.
3233 @var{alist} is an association list of symbols and values as for
3234 @code{display-buffer}.  The following symbols in @var{alist} are special
3235 for this function:
3237 @table @code
3238 @item side
3239 Denotes the side of the frame where the window shall be located.  Valid
3240 values are @code{left}, @code{top}, @code{right} and @code{bottom}.  If
3241 unspecified, the window is located at the bottom of the frame.
3243 @item slot
3244 Denotes a slot at the specified side where to locate the window.  A
3245 value of zero means to preferably position the window in the middle of
3246 the specified side.  A negative value means to use a slot preceding
3247 (that is, above or on the left of) the middle slot.  A positive value
3248 means to use a slot following (that is, below or on the right of) the
3249 middle slot.  Hence, all windows on a specific side are ordered by their
3250 @code{slot} value.  If unspecified, the window is located in the middle
3251 of the specified side.
3252 @end table
3254 If you specify the same slot on the same side for two or more different
3255 buffers, the buffer displayed last is shown in the corresponding window.
3256 Hence, slots can be used for sharing the same side window between
3257 buffers.
3259 This function installs the @code{window-side} and @code{window-slot}
3260 parameters (@pxref{Window Parameters}) and makes them persistent.  It
3261 does not install any other window parameters unless they have been
3262 explicitly provided via a @code{window-parameters} entry in @var{alist}.
3263 @end defun
3265 By default, side windows cannot be split via @code{split-window}
3266 (@pxref{Splitting Windows}).  Also, a side window is not reused or split
3267 by any buffer display action (@pxref{Display Action Functions}) unless
3268 it is explicitly specified as target of that action.  Note also that
3269 @code{delete-other-windows} cannot make a side window the only window on
3270 its frame (@pxref{Deleting Windows}).
3272    Once set up, side windows also change the behavior of the commands
3273 @code{switch-to-prev-buffer} and @code{switch-to-next-buffer}
3274 (@pxref{Window History}).  In particular, these commands will refrain
3275 from showing, in a side window, buffers that have not been displayed in
3276 that window before.  They will also refrain from having a normal,
3277 non-side window show a buffer that has been already displayed in a side
3278 window.  A notable exception to the latter rule occurs when an
3279 application, after displaying a buffer, resets that buffer's local
3280 variables.
3283 @node Side Window Options and Functions
3284 @subsection Side Window Options and Functions
3286 The following options provide additional control over the placement of
3287 side windows.
3289 @defopt window-sides-vertical
3290 If non-@code{nil}, the side windows on the left and right of a frame
3291 occupy the frame's full height.  Otherwise, the side windows on the top
3292 and bottom of the frame occupy the frame's full width.
3293 @end defopt
3295 @defopt window-sides-slots
3296 This option specifies the maximum number of side windows on each side of
3297 a frame.  The value is a list of four elements specifying the number of
3298 side window slots on (in this order) the left, top, right and bottom of
3299 each frame.  If an element is a number, it means to display at most that
3300 many windows on the corresponding side.  If an element is @code{nil}, it
3301 means there's no bound on the number of slots on that side.
3303 If any of the specified values is zero, no window can be created on the
3304 corresponding side.  @code{display-buffer-in-side-window} will not
3305 signal an error in that case, but will return @code{nil}.  If a specified
3306 value just forbids the creation of an additional side window, the most
3307 suitable window on that side is reused and may have its
3308 @code{window-slot} parameter changed accordingly.
3309 @end defopt
3311 @defopt window-sides-reversed
3312 This option specifies whether top/bottom side windows should appear in
3313 reverse order.  When this is @code{nil}, side windows on the top and
3314 bottom of a frame are always drawn from left to right with increasing
3315 slot values.  When this is @code{t}, the drawing order is reversed and
3316 side windows on the top and bottom of a frame are drawn from right to
3317 left with increasing slot values.
3319 When this is @code{bidi}, the drawing order is reversed if and only if
3320 the value of @code{bidi-paragraph-direction} (@pxref{Bidirectional
3321 Display}) is @code{right-to-left} in the buffer displayed in the window
3322 most recently selected within the main window area of this frame.
3323 Sometimes that window may be hard to find, so heuristics are used to
3324 avoid that the drawing order changes inadvertently when another window
3325 gets selected.
3327 The layout of side windows on the left or right of a frame is not
3328 affected by the value of this variable.
3329 @end defopt
3331 When a frame has side windows, the following function returns the main
3332 window of that frame.
3334 @defun window-main-window &optional frame
3335 This function returns the main window of the specified @var{frame}.  The
3336 optional argument @var{frame} must be a live frame and defaults to the
3337 selected one.
3339 If @var{frame} has no side windows, it returns @var{frame}'s root
3340 window.  Otherwise, it returns either an internal non-side window such
3341 that all other non-side windows on @var{frame} descend from it, or the
3342 single live non-side window of @var{frame}.  Note that the main window
3343 of a frame cannot be deleted via @code{delete-window}.
3344 @end defun
3346 The following command is handy to toggle the appearance of all side
3347 windows on a specified frame.
3349 @deffn Command window-toggle-side-windows &optional frame
3350 This command toggles side windows on the specified @var{frame}.  The
3351 optional argument @var{frame} must be a live frame and defaults to the
3352 selected one.
3354 If @var{frame} has at least one side window, this command saves the
3355 state of @var{frame}'s root window in the @var{frame}'s
3356 @code{window-state} frame parameter and deletes all side windows on
3357 @var{frame} afterwards.
3359 If @var{frame} has no side windows, but does have a @code{window-state}
3360 parameter, this command uses that parameter's value to restore the side
3361 windows on @var{frame} leaving @var{frame}'s main window alone.
3363 An error is signaled if @var{frame} has no side windows and no saved
3364 state is found for it.
3365 @end deffn
3368 @node Frame Layouts with Side Windows
3369 @subsection Frame Layouts with Side Windows
3371 Side windows can be used to create more complex frame layouts like those
3372 provided by integrated development environments (IDEs).  In such
3373 layouts, the area of the main window is where the normal editing
3374 activities take place.  Side windows are not conceived for editing in
3375 the usual sense.  Rather, they are supposed to display information
3376 complementary to the current editing activity, like lists of files, tags
3377 or buffers, help information, search or grep results or shell output.
3379    The layout of such a frame might appear as follows:
3381 @smallexample
3382 @group
3383      ___________________________________
3384     |          *Buffer List*            |
3385     |___________________________________|
3386     |     |                       |     |
3387     |  *  |                       |  *  |
3388     |  d  |                       |  T  |
3389     |  i  |                       |  a  |
3390     |  r  |   Main Window Area    |  g  |
3391     |  e  |                       |  s  |
3392     |  d  |                       |  *  |
3393     |  *  |                       |     |
3394     |_____|_______________________|_____|
3395     | *help*/*grep*/  |  *shell*/       |
3396     | *Completions*   |  *compilation*  |
3397     |_________________|_________________|
3398     |             Echo Area             |
3399     |___________________________________|
3402 @end group
3403 @end smallexample
3405 The following example illustrates how window parameters (@pxref{Window
3406 Parameters}) can be used with @code{display-buffer-in-side-window}
3407 (@pxref{Displaying Buffers in Side Windows}) to set up code for
3408 producing the frame layout sketched above.
3410 @example
3411 @group
3412 (defvar parameters
3413   '(window-parameters . ((no-other-window . t)
3414                          (no-delete-other-windows . t))))
3416 (setq fit-window-to-buffer-horizontally t)
3417 (setq window-resize-pixelwise t)
3419 (setq
3420  display-buffer-alist
3421  `(("\\*Buffer List\\*" display-buffer-in-side-window
3422     (side . top) (slot . 0) (window-height . fit-window-to-buffer)
3423     (preserve-size . (nil . t)) ,parameters)
3424    ("\\*Tags List\\*" display-buffer-in-side-window
3425     (side . right) (slot . 0) (window-width . fit-window-to-buffer)
3426     (preserve-size . (t . nil)) ,parameters)
3427    ("\\*\\(?:help\\|grep\\|Completions\\)\\*"
3428     display-buffer-in-side-window
3429     (side . bottom) (slot . -1) (preserve-size . (nil . t))
3430     ,parameters)
3431    ("\\*\\(?:shell\\|compilation\\)\\*" display-buffer-in-side-window
3432     (side . bottom) (slot . 1) (preserve-size . (nil . t))
3433     ,parameters)))
3434 @end group
3435 @end example
3437 This specifies @code{display-buffer-alist} entries (@pxref{Choosing
3438 Window}) for buffers with fixed names.  In particular, it asks for
3439 showing @file{*Buffer List*} with adjustable height at the top of the
3440 frame and @file{*Tags List*} with adjustable width on the frame's right.
3441 It also asks for having the @file{*help*}, @file{*grep*} and
3442 @file{*Completions*} buffers share a window on the bottom left side of
3443 the frame and the @file{*shell*} and @file{*compilation*} buffers appear
3444 in a window on the bottom right side of the frame.
3446    Note that the option @code{fit-window-to-buffer-horizontally} must
3447 have a non-@code{nil} value in order to allow horizontal adjustment of
3448 windows.  Entries are also added that ask for preserving the height of
3449 side windows at the top and bottom of the frame and the width of side
3450 windows at the left or right of the frame.  To assure that side windows
3451 retain their respective sizes when maximizing the frame, the variable
3452 @code{window-resize-pixelwise} is set to a non-@code{nil} value.
3453 @xref{Resizing Windows}.
3455    The last form also makes sure that none of the created side windows
3456 are accessible via @kbd{C-x o} by installing the @code{no-other-window}
3457 parameter for each of these windows.  In addition, it makes sure that
3458 side windows are not deleted via @kbd{C-x 1} by installing the
3459 @code{no-delete-other-windows} parameter for each of these windows.
3461    Since @code{dired} buffers have no fixed names, we use a special
3462 function @code{dired-default-directory-on-left} in order to display a
3463 lean directory buffer on the left side of the frame.
3465 @example
3466 @group
3467 (defun dired-default-directory-on-left ()
3468   "Display `default-directory' in side window on left, hiding details."
3469   (interactive)
3470   (let ((buffer (dired-noselect default-directory)))
3471     (with-current-buffer buffer (dired-hide-details-mode t))
3472     (display-buffer-in-side-window
3473      buffer `((side . left) (slot . 0)
3474               (window-width . fit-window-to-buffer)
3475               (preserve-size . (t . nil)) ,parameters))))
3476 @end group
3477 @end example
3479 Evaluating the preceding forms and typing, in any order, @w{@kbd{M-x
3480 list-buffers}}, @kbd{C-h f}, @kbd{M-x shell}, @w{@kbd{M-x list-tags}},
3481 and @kbd{M-x dired-default-directory-on-left} should now reproduce the
3482 frame layout sketched above.
3485 @node Atomic Windows
3486 @section Atomic Windows
3487 @cindex atomic windows
3489 Atomic windows are rectangular compositions of at least two live
3490 windows.  They have the following distinctive characteristics:
3492 @itemize @bullet
3493 @item
3494 The function @code{split-window} (@pxref{Splitting Windows}), when
3495 applied to a constituent of an atomic window, will try to create the new
3496 window outside of the atomic window.
3498 @item
3499 The function @code{delete-window} (@pxref{Deleting Windows}), when
3500 applied to a constituent of an atomic window, will try to delete the
3501 entire atomic window instead.
3503 @item
3504 The function @code{delete-other-windows} (@pxref{Deleting Windows}),
3505 when applied to a constituent of an atomic window, will try to make the
3506 atomic window fill its frame or main window (@pxref{Side Windows}).
3507 @end itemize
3509 This means that the basic groups of functions that alter the window
3510 structure treat an atomic window like a live one, thus preserving the
3511 internal structure of the atomic window.
3513    Atomic windows are useful to construct and preserve window layouts
3514 that are meaningful only when all involved buffers are shown
3515 simultaneously in a specific manner, such as when showing differences
3516 between file revisions, or the same text in different languages or
3517 markups.  They can also be used to permanently display information
3518 pertinent to a specific window in bars on that window's sides.
3520 @cindex root window of atomic window
3521    Atomic windows are implemented with the help of the reserved
3522 @code{window-atom} window parameter (@pxref{Window Parameters}) and an
3523 internal window (@pxref{Basic Windows}) called the root window of the
3524 atomic window.  All windows that are part of the same atomic window have
3525 this root window as their common ancestor and are assigned a
3526 non-@code{nil} @code{window-atom} parameter.
3528   The following function returns the root of the atomic window a
3529 specified window is part of:
3531 @defun window-atom-root &optional window
3532 This functions returns the root of the atomic window @var{window} is a
3533 part of.  The specified @var{window} must be a valid window and defaults
3534 to the selected one.  It returns @code{nil} if @var{window} is not part
3535 of an atomic window.
3536 @end defun
3538 The most simple approach to make a new atomic window is to take an
3539 existing internal window and apply the following function:
3541 @defun window-make-atom window
3542 This function converts @var{window} into an atomic window.  The
3543 specified @var{window} must be an internal window.  All this function
3544 does is to set the @code{window-atom} parameter of each descendant of
3545 @var{window} to @code{t}.
3546 @end defun
3548 To create a new atomic window from an existing live window or to add a
3549 new window to an existing atomic window, the following buffer display
3550 action function (@pxref{Display Action Functions}) can be used:
3552 @defun display-buffer-in-atom-window buffer alist
3553 This function tries to display @var{buffer} in a new window that will be
3554 combined with an existing window to form an atomic window.  If the
3555 existing window is already part of an atomic window, it adds the new
3556 window to that atomic window.
3558 The specified @var{alist} is an association list of symbols and values.
3559 The following symbols have a special meaning:
3561 @table @code
3562 @item window
3563 The value of such an element specifies an existing window the new window
3564 shall be combined with.  If it specifies an internal window, all
3565 children of that window become part of the atomic window too.  If no
3566 window is specified, the new window becomes a sibling of the selected
3567 window.  The @code{window-atom} parameter of the existing window is set
3568 to @code{main} provided that window is live and its @code{window-atom}
3569 parameter was not already set.
3571 @item side
3572 The value of such an element denotes the side of the existing window
3573 where the new window shall be located.  Valid values are @code{below},
3574 @code{right}, @code{above} and @code{left}.  The default is
3575 @code{below}.  The @code{window-atom} parameter of the new window is set
3576 to this value.
3577 @end table
3579 The return value is the new window, @code{nil} when creating that window
3580 failed.
3581 @end defun
3583 Note that the value of the @code{window-atom} parameter does not really
3584 matter as long as it is non-@code{nil}.  The values assigned by
3585 @code{display-buffer-in-atom-window} just allow for easy retrieval of
3586 the original and the new window after that function has been applied.
3587 Note also that the @code{window-atom} parameter is the only window
3588 parameter assigned by @code{display-buffer-in-atom-window}.  Further
3589 parameters have to be set by the application explicitly via a
3590 @code{window-parameters} entry in @var{alist}.
3592    The following code snippet, when applied to a single-window frame,
3593 first splits the selected window and makes the selected and the new
3594 window constituents of an atomic window with their parent as root.  It
3595 then displays the buffer @file{*Messages*} in a new window at the
3596 frame's bottom and makes that new window part of the atomic window just
3597 created.
3599 @example
3600 @group
3601 (let ((window (split-window-right)))
3602   (window-make-atom (window-parent window))
3603   (display-buffer-in-atom-window
3604    (get-buffer-create "*Messages*")
3605    `((window . ,(window-parent window)) (window-height . 5))))
3606 @end group
3607 @end example
3609 At this moment typing @w{@kbd{C-x 2}} in any window of that frame
3610 produces a new window at the bottom of the frame.  Typing @w{@kbd{C-x
3611 3}} instead will put the new window at the frame's right.  In either
3612 case, typing now @w{@kbd{C-x 1}} in any window of the atomic window will
3613 remove the new window only.  Typing @w{@kbd{C-x 0}} in any window of the
3614 atomic window will make that new window fill the frame.
3617 @node Window Point
3618 @section Windows and Point
3619 @cindex window position
3620 @cindex window point
3621 @cindex position in window
3622 @cindex point in window
3624   Each window has its own value of point (@pxref{Point}), independent of
3625 the value of point in other windows displaying the same buffer.  This
3626 makes it useful to have multiple windows showing one buffer.
3628 @itemize @bullet
3629 @item
3630 The window point is established when a window is first created; it is
3631 initialized from the buffer's point, or from the window point of another
3632 window opened on the buffer if such a window exists.
3634 @item
3635 Selecting a window sets the value of point in its buffer from the
3636 window's value of point.  Conversely, deselecting a window sets the
3637 window's value of point from that of the buffer.  Thus, when you switch
3638 between windows that display a given buffer, the point value for the
3639 selected window is in effect in the buffer, while the point values for
3640 the other windows are stored in those windows.
3642 @item
3643 As long as the selected window displays the current buffer, the window's
3644 point and the buffer's point always move together; they remain equal.
3645 @end itemize
3647 @cindex cursor
3648    Emacs displays the cursor, by default as a rectangular block, in
3649 each window at the position of that window's point.  When the user
3650 switches to another buffer in a window, Emacs moves that window's
3651 cursor to where point is in that buffer.  If the exact position of
3652 point is hidden behind some display element, such as a display string
3653 or an image, Emacs displays the cursor immediately before or after
3654 that display element.
3656 @defun window-point &optional window
3657 This function returns the current position of point in @var{window}.
3658 For a nonselected window, this is the value point would have (in that
3659 window's buffer) if that window were selected.  The default for
3660 @var{window} is the selected window.
3662 When @var{window} is the selected window, the value returned is the
3663 value of point in that window's buffer.  Strictly speaking, it would be
3664 more correct to return the top-level value of point, outside of any
3665 @code{save-excursion} forms.  But that value is hard to find.
3666 @end defun
3668 @defun set-window-point window position
3669 This function positions point in @var{window} at position
3670 @var{position} in @var{window}'s buffer.  It returns @var{position}.
3672 If @var{window} is selected, this simply does @code{goto-char} in
3673 @var{window}'s buffer.
3674 @end defun
3676 @defvar window-point-insertion-type
3677 This variable specifies the marker insertion type (@pxref{Marker
3678 Insertion Types}) of @code{window-point}.  The default is @code{nil},
3679 so @code{window-point} will stay behind text inserted there.
3680 @end defvar
3682 @node Window Start and End
3683 @section The Window Start and End Positions
3684 @cindex window start position
3685 @cindex display-start position
3687   Each window maintains a marker used to keep track of a buffer position
3688 that specifies where in the buffer display should start.  This position
3689 is called the @dfn{display-start} position of the window (or just the
3690 @dfn{start}).  The character after this position is the one that appears
3691 at the upper left corner of the window.  It is usually, but not
3692 inevitably, at the beginning of a text line.
3694   After switching windows or buffers, and in some other cases, if the
3695 window start is in the middle of a line, Emacs adjusts the window
3696 start to the start of a line.  This prevents certain operations from
3697 leaving the window start at a meaningless point within a line.  This
3698 feature may interfere with testing some Lisp code by executing it
3699 using the commands of Lisp mode, because they trigger this
3700 readjustment.  To test such code, put it into a command and bind the
3701 command to a key.
3703 @defun window-start &optional window
3704 @cindex window top line
3705 This function returns the display-start position of window
3706 @var{window}.  If @var{window} is @code{nil}, the selected window is
3707 used.
3709 When you create a window, or display a different buffer in it, the
3710 display-start position is set to a display-start position recently used
3711 for the same buffer, or to @code{point-min} if the buffer doesn't have
3712 any.
3714 Redisplay updates the window-start position (if you have not specified
3715 it explicitly since the previous redisplay)---to make sure point appears
3716 on the screen.  Nothing except redisplay automatically changes the
3717 window-start position; if you move point, do not expect the window-start
3718 position to change in response until after the next redisplay.
3719 @end defun
3721 @defun window-group-start &optional window
3722 @vindex window-group-start-function
3723 This function is like @code{window-start}, except that when
3724 @var{window} is a part of a group of windows (@pxref{Window Group}),
3725 @code{window-group-start} returns the start position of the entire
3726 group.  This condition holds when the buffer local variable
3727 @code{window-group-start-function} is set to a function.  In this
3728 case, @code{window-group-start} calls the function with the single
3729 argument @var{window}, then returns its result.
3730 @end defun
3732 @cindex window end position
3733 @defun window-end &optional window update
3734 This function returns the position where display of its buffer ends in
3735 @var{window}.  The default for @var{window} is the selected window.
3737 Simply changing the buffer text or moving point does not update the
3738 value that @code{window-end} returns.  The value is updated only when
3739 Emacs redisplays and redisplay completes without being preempted.
3741 If the last redisplay of @var{window} was preempted, and did not finish,
3742 Emacs does not know the position of the end of display in that window.
3743 In that case, this function returns @code{nil}.
3745 If @var{update} is non-@code{nil}, @code{window-end} always returns an
3746 up-to-date value for where display ends, based on the current
3747 @code{window-start} value.  If a previously saved value of that position
3748 is still valid, @code{window-end} returns that value; otherwise it
3749 computes the correct value by scanning the buffer text.
3751 Even if @var{update} is non-@code{nil}, @code{window-end} does not
3752 attempt to scroll the display if point has moved off the screen, the
3753 way real redisplay would do.  It does not alter the
3754 @code{window-start} value.  In effect, it reports where the displayed
3755 text will end if scrolling is not required.
3756 @end defun
3758 @vindex window-group-end-function
3759 @defun window-group-end &optional window update
3760 This function is like @code{window-end}, except that when @var{window}
3761 is a part of a group of windows (@pxref{Window Group}),
3762 @code{window-group-end} returns the end position of the entire group.
3763 This condition holds when the buffer local variable
3764 @code{window-group-end-function} is set to a function.  In this case,
3765 @code{window-group-end} calls the function with the two arguments
3766 @var{window} and @var{update}, then returns its result.  The argument
3767 @var{update} has the same meaning as in @code{window-end}.
3768 @end defun
3770 @defun set-window-start window position &optional noforce
3771 This function sets the display-start position of @var{window} to
3772 @var{position} in @var{window}'s buffer.  It returns @var{position}.
3774 The display routines insist that the position of point be visible when a
3775 buffer is displayed.  Normally, they change the display-start position
3776 (that is, scroll the window) whenever necessary to make point visible.
3777 However, if you specify the start position with this function using
3778 @code{nil} for @var{noforce}, it means you want display to start at
3779 @var{position} even if that would put the location of point off the
3780 screen.  If this does place point off screen, the display routines move
3781 point to the left margin on the middle line in the window.
3783 For example, if point @w{is 1} and you set the start of the window
3784 @w{to 37}, the start of the next line, point will be above the top
3785 of the window.  The display routines will automatically move point if
3786 it is still 1 when redisplay occurs.  Here is an example:
3788 @example
3789 @group
3790 ;; @r{Here is what @samp{foo} looks like before executing}
3791 ;;   @r{the @code{set-window-start} expression.}
3792 @end group
3794 @group
3795 ---------- Buffer: foo ----------
3796 @point{}This is the contents of buffer foo.
3802 ---------- Buffer: foo ----------
3803 @end group
3805 @group
3806 (set-window-start
3807  (selected-window)
3808  (save-excursion
3809    (goto-char 1)
3810    (forward-line 1)
3811    (point)))
3812 @result{} 37
3813 @end group
3815 @group
3816 ;; @r{Here is what @samp{foo} looks like after executing}
3817 ;;   @r{the @code{set-window-start} expression.}
3818 ---------- Buffer: foo ----------
3821 @point{}4
3824 ---------- Buffer: foo ----------
3825 @end group
3826 @end example
3828 If @var{noforce} is non-@code{nil}, and @var{position} would place point
3829 off screen at the next redisplay, then redisplay computes a new window-start
3830 position that works well with point, and thus @var{position} is not used.
3831 @end defun
3833 @vindex set-window-group-start-function
3834 @defun set-window-group-start window position &optional noforce
3835 This function is like @code{set-window-start}, except that when
3836 @var{window} is a part of a group of windows (@pxref{Window Group}),
3837 @code{set-window-group-start} sets the start position of the entire
3838 group.  This condition holds when the buffer local variable
3839 @code{set-window-group-start-function} is set to a function.  In this
3840 case, @code{set-window-group-start} calls the function with the three
3841 arguments @var{window}, @var{position}, and @var{noforce}, then
3842 returns its result.  The arguments @var{position} and @var{noforce} in
3843 this function have the same meaning as in @code{set-window-start}.
3844 @end defun
3846 @defun pos-visible-in-window-p &optional position window partially
3847 This function returns non-@code{nil} if @var{position} is within the
3848 range of text currently visible on the screen in @var{window}.  It
3849 returns @code{nil} if @var{position} is scrolled vertically out of
3850 view.  Locations that are partially obscured are not considered
3851 visible unless @var{partially} is non-@code{nil}.  The argument
3852 @var{position} defaults to the current position of point in
3853 @var{window}; @var{window} defaults to the selected window.  If
3854 @var{position} is @code{t}, that means to check either the first
3855 visible position of the last screen line in @var{window}, or the
3856 end-of-buffer position, whichever comes first.
3858 This function considers only vertical scrolling.  If @var{position} is
3859 out of view only because @var{window} has been scrolled horizontally,
3860 @code{pos-visible-in-window-p} returns non-@code{nil} anyway.
3861 @xref{Horizontal Scrolling}.
3863 If @var{position} is visible, @code{pos-visible-in-window-p} returns
3864 @code{t} if @var{partially} is @code{nil}; if @var{partially} is
3865 non-@code{nil}, and the character following @var{position} is fully
3866 visible, it returns a list of the form @code{(@var{x} @var{y})}, where
3867 @var{x} and @var{y} are the pixel coordinates relative to the top left
3868 corner of the window; otherwise it returns an extended list of the form
3869 @code{(@var{x} @var{y} @var{rtop} @var{rbot} @var{rowh} @var{vpos})},
3870 where @var{rtop} and @var{rbot} specify the number of off-window pixels
3871 at the top and bottom of the row at @var{position}, @var{rowh} specifies
3872 the visible height of that row, and @var{vpos} specifies the vertical
3873 position (zero-based row number) of that row.
3875 Here is an example:
3877 @example
3878 @group
3879 ;; @r{If point is off the screen now, recenter it now.}
3880 (or (pos-visible-in-window-p
3881      (point) (selected-window))
3882     (recenter 0))
3883 @end group
3884 @end example
3885 @end defun
3887 @vindex pos-visible-in-window-group-p-function
3888 @defun pos-visible-in-window-group-p &optional position window partially
3889 This function is like @code{pos-visible-in-window-p}, except that when
3890 @var{window} is a part of a group of windows (@pxref{Window Group}),
3891 @code{pos-visible-in-window-group-p} tests the visibility of @var{pos}
3892 in the entire group, not just in the single @var{window}.  This
3893 condition holds when the buffer local variable
3894 @code{pos-visible-in-window-group-p-function} is set to a function.
3895 In this case @code{pos-visible-in-window-group-p} calls the function
3896 with the three arguments @var{position}, @var{window}, and
3897 @var{partially}, then returns its result.  The arguments
3898 @var{position} and @var{partially} have the same meaning as in
3899 @code{pos-visible-in-window-p}.
3900 @end defun
3902 @defun window-line-height &optional line window
3903 This function returns the height of text line @var{line} in
3904 @var{window}.  If @var{line} is one of @code{header-line} or
3905 @code{mode-line}, @code{window-line-height} returns information about
3906 the corresponding line of the window.  Otherwise, @var{line} is a text
3907 line number starting from 0.  A negative number counts from the end of
3908 the window.  The default for @var{line} is the current line in
3909 @var{window}; the default for @var{window} is the selected window.
3911 If the display is not up to date, @code{window-line-height} returns
3912 @code{nil}.  In that case, @code{pos-visible-in-window-p} may be used
3913 to obtain related information.
3915 If there is no line corresponding to the specified @var{line},
3916 @code{window-line-height} returns @code{nil}.  Otherwise, it returns
3917 a list @code{(@var{height} @var{vpos} @var{ypos} @var{offbot})},
3918 where @var{height} is the height in pixels of the visible part of the
3919 line, @var{vpos} and @var{ypos} are the vertical position in lines and
3920 pixels of the line relative to the top of the first text line, and
3921 @var{offbot} is the number of off-window pixels at the bottom of the
3922 text line.  If there are off-window pixels at the top of the (first)
3923 text line, @var{ypos} is negative.
3924 @end defun
3926 @node Textual Scrolling
3927 @section Textual Scrolling
3928 @cindex textual scrolling
3929 @cindex scrolling textually
3931   @dfn{Textual scrolling} means moving the text up or down through a
3932 window.  It works by changing the window's display-start location.  It
3933 may also change the value of @code{window-point} to keep point on the
3934 screen (@pxref{Window Point}).
3936   The basic textual scrolling functions are @code{scroll-up} (which
3937 scrolls forward) and @code{scroll-down} (which scrolls backward).  In
3938 these function names, ``up'' and ``down'' refer to the direction of
3939 motion of the buffer text relative to the window.  Imagine that the
3940 text is written on a long roll of paper and that the scrolling
3941 commands move the paper up and down.  Thus, if you are looking at the
3942 middle of a buffer and repeatedly call @code{scroll-down}, you will
3943 eventually see the beginning of the buffer.
3945   Unfortunately, this sometimes causes confusion, because some people
3946 tend to think in terms of the opposite convention: they
3947 imagine the window moving over text that remains in place, so that
3948 ``down'' commands take you to the end of the buffer.  This convention
3949 is consistent with fact that such a command is bound to a key named
3950 @key{PageDown} on modern keyboards.
3951 @ignore
3952 We have not switched to this convention as that is likely to break
3953 existing Emacs Lisp code.
3954 @end ignore
3956   Textual scrolling functions (aside from @code{scroll-other-window})
3957 have unpredictable results if the current buffer is not the one
3958 displayed in the selected window.  @xref{Current Buffer}.
3960   If the window contains a row taller than the height of the window
3961 (for example in the presence of a large image), the scroll functions
3962 will adjust the window's vertical scroll position to scroll the
3963 partially visible row.  Lisp callers can disable this feature by
3964 binding the variable @code{auto-window-vscroll} to @code{nil}
3965 (@pxref{Vertical Scrolling}).
3967 @deffn Command scroll-up &optional count
3968 This function scrolls forward by @var{count} lines in the selected
3969 window.
3971 If @var{count} is negative, it scrolls backward instead.  If
3972 @var{count} is @code{nil} (or omitted), the distance scrolled is
3973 @code{next-screen-context-lines} lines less than the height of the
3974 window's text area.
3976 If the selected window cannot be scrolled any further, this function
3977 signals an error.  Otherwise, it returns @code{nil}.
3978 @end deffn
3980 @deffn Command scroll-down &optional count
3981 This function scrolls backward by @var{count} lines in the selected
3982 window.
3984 If @var{count} is negative, it scrolls forward instead.  In other
3985 respects, it behaves the same way as @code{scroll-up} does.
3986 @end deffn
3988 @deffn Command scroll-up-command &optional count
3989 This behaves like @code{scroll-up}, except that if the selected window
3990 cannot be scrolled any further and the value of the variable
3991 @code{scroll-error-top-bottom} is @code{t}, it tries to move to the
3992 end of the buffer instead.  If point is already there, it signals an
3993 error.
3994 @end deffn
3996 @deffn Command scroll-down-command &optional count
3997 This behaves like @code{scroll-down}, except that if the selected
3998 window cannot be scrolled any further and the value of the variable
3999 @code{scroll-error-top-bottom} is @code{t}, it tries to move to the
4000 beginning of the buffer instead.  If point is already there, it
4001 signals an error.
4002 @end deffn
4004 @deffn Command scroll-other-window &optional count
4005 This function scrolls the text in another window upward @var{count}
4006 lines.  Negative values of @var{count}, or @code{nil}, are handled
4007 as in @code{scroll-up}.
4009 You can specify which buffer to scroll by setting the variable
4010 @code{other-window-scroll-buffer} to a buffer.  If that buffer isn't
4011 already displayed, @code{scroll-other-window} displays it in some
4012 window.
4014 When the selected window is the minibuffer, the next window is normally
4015 the leftmost one immediately above it.  You can specify a different
4016 window to scroll, when the minibuffer is selected, by setting the variable
4017 @code{minibuffer-scroll-window}.  This variable has no effect when any
4018 other window is selected.  When it is non-@code{nil} and the
4019 minibuffer is selected, it takes precedence over
4020 @code{other-window-scroll-buffer}.  @xref{Definition of
4021 minibuffer-scroll-window}.
4023 When the minibuffer is active, it is the next window if the selected
4024 window is the one at the bottom right corner.  In this case,
4025 @code{scroll-other-window} attempts to scroll the minibuffer.  If the
4026 minibuffer contains just one line, it has nowhere to scroll to, so the
4027 line reappears after the echo area momentarily displays the message
4028 @samp{End of buffer}.
4029 @end deffn
4031 @defvar other-window-scroll-buffer
4032 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
4033 which buffer's window to scroll.
4034 @end defvar
4036 @defopt scroll-margin
4037 This option specifies the size of the scroll margin---a minimum number
4038 of lines between point and the top or bottom of a window.  Whenever
4039 point gets within this many lines of the top or bottom of the window,
4040 redisplay scrolls the text automatically (if possible) to move point
4041 out of the margin, closer to the center of the window.
4042 @end defopt
4044 @defopt maximum-scroll-margin
4045 This variable limits the effective value of @code{scroll-margin} to a
4046 fraction of the current window line height.  For example, if the
4047 current window has 20 lines and @code{maximum-scroll-margin} is 0.1,
4048 then the scroll margins will never be larger than 2 lines, no matter
4049 how big @code{scroll-margin} is.
4051 @code{maximum-scroll-margin} itself has a maximum value of 0.5, which
4052 allows setting margins large to keep the cursor at the middle line of
4053 the window (or two middle lines if the window has an even number of
4054 lines).  If it's set to a larger value (or any value other than a
4055 float between 0.0 and 0.5) then the default value of 0.25 will be used
4056 instead.
4057 @end defopt
4059 @defopt scroll-conservatively
4060 This variable controls how scrolling is done automatically when point
4061 moves off the screen (or into the scroll margin).  If the value is a
4062 positive integer @var{n}, then redisplay scrolls the text up to
4063 @var{n} lines in either direction, if that will bring point back into
4064 proper view.  This behavior is called @dfn{conservative scrolling}.
4065 Otherwise, scrolling happens in the usual way, under the control of
4066 other variables such as @code{scroll-up-aggressively} and
4067 @code{scroll-down-aggressively}.
4069 The default value is zero, which means that conservative scrolling
4070 never happens.
4071 @end defopt
4073 @defopt scroll-down-aggressively
4074 The value of this variable should be either @code{nil} or a fraction
4075 @var{f} between 0 and 1.  If it is a fraction, that specifies where on
4076 the screen to put point when scrolling down.  More precisely, when a
4077 window scrolls down because point is above the window start, the new
4078 start position is chosen to put point @var{f} part of the window
4079 height from the top.  The larger @var{f}, the more aggressive the
4080 scrolling.
4082 A value of @code{nil} is equivalent to .5, since its effect is to center
4083 point.  This variable automatically becomes buffer-local when set in any
4084 fashion.
4085 @end defopt
4087 @defopt scroll-up-aggressively
4088 Likewise, for scrolling up.  The value, @var{f}, specifies how far
4089 point should be placed from the bottom of the window; thus, as with
4090 @code{scroll-up-aggressively}, a larger value scrolls more aggressively.
4091 @end defopt
4093 @defopt scroll-step
4094 This variable is an older variant of @code{scroll-conservatively}.
4095 The difference is that if its value is @var{n}, that permits scrolling
4096 only by precisely @var{n} lines, not a smaller number.  This feature
4097 does not work with @code{scroll-margin}.  The default value is zero.
4098 @end defopt
4100 @cindex @code{scroll-command} property
4101 @defopt scroll-preserve-screen-position
4102 If this option is @code{t}, whenever a scrolling command moves point
4103 off-window, Emacs tries to adjust point to keep the cursor at its old
4104 vertical position in the window, rather than the window edge.
4106 If the value is non-@code{nil} and not @code{t}, Emacs adjusts point
4107 to keep the cursor at the same vertical position, even if the
4108 scrolling command didn't move point off-window.
4110 This option affects all scroll commands that have a non-@code{nil}
4111 @code{scroll-command} symbol property.
4112 @end defopt
4114 @defopt next-screen-context-lines
4115 The value of this variable is the number of lines of continuity to
4116 retain when scrolling by full screens.  For example, @code{scroll-up}
4117 with an argument of @code{nil} scrolls so that this many lines at the
4118 bottom of the window appear instead at the top.  The default value is
4119 @code{2}.
4120 @end defopt
4122 @defopt scroll-error-top-bottom
4123 If this option is @code{nil} (the default), @code{scroll-up-command}
4124 and @code{scroll-down-command} simply signal an error when no more
4125 scrolling is possible.
4127 If the value is @code{t}, these commands instead move point to the
4128 beginning or end of the buffer (depending on scrolling direction);
4129 only if point is already on that position do they signal an error.
4130 @end defopt
4132 @deffn Command recenter &optional count
4133 @cindex centering point
4134 This function scrolls the text in the selected window so that point is
4135 displayed at a specified vertical position within the window.  It does
4136 not move point with respect to the text.
4138 If @var{count} is a non-negative number, that puts the line containing
4139 point @var{count} lines down from the top of the window.  If
4140 @var{count} is a negative number, then it counts upward from the
4141 bottom of the window, so that @minus{}1 stands for the last usable
4142 line in the window.
4144 If @var{count} is @code{nil} (or a non-@code{nil} list),
4145 @code{recenter} puts the line containing point in the middle of the
4146 window.  If @var{count} is @code{nil}, this function may redraw the
4147 frame, according to the value of @code{recenter-redisplay}.
4149 When @code{recenter} is called interactively, @var{count} is the raw
4150 prefix argument.  Thus, typing @kbd{C-u} as the prefix sets the
4151 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
4152 @var{count} to 4, which positions the current line four lines from the
4153 top.
4155 With an argument of zero, @code{recenter} positions the current line at
4156 the top of the window.  The command @code{recenter-top-bottom} offers
4157 a more convenient way to achieve this.
4158 @end deffn
4160 @vindex recenter-window-group-function
4161 @defun recenter-window-group &optional count
4162 This function is like @code{recenter}, except that when the selected
4163 window is part of a group of windows (@pxref{Window Group}),
4164 @code{recenter-window-group} scrolls the entire group.  This condition
4165 holds when the buffer local variable
4166 @code{recenter-window-group-function} is set to a function.  In this
4167 case, @code{recenter-window-group} calls the function with the
4168 argument @var{count}, then returns its result.  The argument
4169 @var{count} has the same meaning as in @code{recenter}, but with
4170 respect to the entire window group.
4171 @end defun
4173 @defopt recenter-redisplay
4174 If this variable is non-@code{nil}, calling @code{recenter} with a
4175 @code{nil} argument redraws the frame.  The default value is
4176 @code{tty}, which means only redraw the frame if it is a tty frame.
4177 @end defopt
4179 @deffn Command recenter-top-bottom &optional count
4180 This command, which is the default binding for @kbd{C-l}, acts like
4181 @code{recenter}, except if called with no argument.  In that case,
4182 successive calls place point according to the cycling order defined
4183 by the variable @code{recenter-positions}.
4184 @end deffn
4186 @defopt recenter-positions
4187 This variable controls how @code{recenter-top-bottom} behaves when
4188 called with no argument.  The default value is @code{(middle top
4189 bottom)}, which means that successive calls of
4190 @code{recenter-top-bottom} with no argument cycle between placing
4191 point at the middle, top, and bottom of the window.
4192 @end defopt
4195 @node Vertical Scrolling
4196 @section Vertical Fractional Scrolling
4197 @cindex vertical fractional scrolling
4198 @cindex vertical scroll position
4200    @dfn{Vertical fractional scrolling} means shifting text in a window
4201 up or down by a specified multiple or fraction of a line.  Each window
4202 has a @dfn{vertical scroll position}, which is a number, never less than
4203 zero.  It specifies how far to raise the contents of the window.
4204 Raising the window contents generally makes all or part of some lines
4205 disappear off the top, and all or part of some other lines appear at the
4206 bottom.  The usual value is zero.
4208    The vertical scroll position is measured in units of the normal line
4209 height, which is the height of the default font.  Thus, if the value is
4210 .5, that means the window contents are scrolled up half the normal line
4211 height.  If it is 3.3, that means the window contents are scrolled up
4212 somewhat over three times the normal line height.
4214    What fraction of a line the vertical scrolling covers, or how many
4215 lines, depends on what the lines contain.  A value of .5 could scroll a
4216 line whose height is very short off the screen, while a value of 3.3
4217 could scroll just part of the way through a tall line or an image.
4219 @defun window-vscroll &optional window pixels-p
4220 This function returns the current vertical scroll position of
4221 @var{window}.  The default for @var{window} is the selected window.
4222 If @var{pixels-p} is non-@code{nil}, the return value is measured in
4223 pixels, rather than in units of the normal line height.
4225 @example
4226 @group
4227 (window-vscroll)
4228      @result{} 0
4229 @end group
4230 @end example
4231 @end defun
4233 @defun set-window-vscroll window lines &optional pixels-p
4234 This function sets @var{window}'s vertical scroll position to
4235 @var{lines}.  If @var{window} is @code{nil}, the selected window is
4236 used.  The argument @var{lines} should be zero or positive; if not, it
4237 is taken as zero.
4240 The actual vertical scroll position must always correspond
4241 to an integral number of pixels, so the value you specify
4242 is rounded accordingly.
4244 The return value is the result of this rounding.
4246 @example
4247 @group
4248 (set-window-vscroll (selected-window) 1.2)
4249      @result{} 1.13
4250 @end group
4251 @end example
4253 If @var{pixels-p} is non-@code{nil}, @var{lines} specifies a number of
4254 pixels.  In this case, the return value is @var{lines}.
4255 @end defun
4257 @defvar auto-window-vscroll
4258 If this variable is non-@code{nil}, the @code{line-move},
4259 @code{scroll-up}, and @code{scroll-down} functions will automatically
4260 modify the vertical scroll position to scroll through display rows
4261 that are taller than the height of the window, for example in the
4262 presence of large images.
4263 @end defvar
4265 @node Horizontal Scrolling
4266 @section Horizontal Scrolling
4267 @cindex horizontal scrolling
4269   @dfn{Horizontal scrolling} means shifting the image in the window left
4270 or right by a specified multiple of the normal character width.  Each
4271 window has a @dfn{horizontal scroll position}, which is a number, never
4272 less than zero.  It specifies how far to shift the contents left.
4273 Shifting the window contents left generally makes all or part of some
4274 characters disappear off the left, and all or part of some other
4275 characters appear at the right.  The usual value is zero.
4277   The horizontal scroll position is measured in units of the normal
4278 character width, which is the width of space in the default font.  Thus,
4279 if the value is 5, that means the window contents are scrolled left by 5
4280 times the normal character width.  How many characters actually
4281 disappear off to the left depends on their width, and could vary from
4282 line to line.
4284   Because we read from side to side in the inner loop, and from top
4285 to bottom in the outer loop, the effect of horizontal scrolling is
4286 not like that of textual or vertical scrolling.  Textual scrolling
4287 involves selection of a portion of text to display, and vertical
4288 scrolling moves the window contents contiguously; but horizontal
4289 scrolling causes part of @emph{each line} to go off screen.
4291   Usually, no horizontal scrolling is in effect; then the leftmost
4292 column is at the left edge of the window.  In this state, scrolling to
4293 the right is meaningless, since there is no data to the left of the edge
4294 to be revealed by it; so this is not allowed.  Scrolling to the left is
4295 allowed; it scrolls the first columns of text off the edge of the window
4296 and can reveal additional columns on the right that were truncated
4297 before.  Once a window has a nonzero amount of leftward horizontal
4298 scrolling, you can scroll it back to the right, but only so far as to
4299 reduce the net horizontal scroll to zero.  There is no limit to how far
4300 left you can scroll, but eventually all the text will disappear off the
4301 left edge.
4303 @vindex auto-hscroll-mode
4304   If @code{auto-hscroll-mode} is set, redisplay automatically alters
4305 the horizontal scrolling of a window as necessary to ensure that point
4306 is always visible.  However, you can still set the horizontal
4307 scrolling value explicitly.  The value you specify serves as a lower
4308 bound for automatic scrolling, i.e., automatic scrolling will not
4309 scroll a window to a column less than the specified one.
4311   The default value of @code{auto-hscroll-mode} is @code{t}; setting
4312 it to @code{current-line} activates a variant of automatic horizontal
4313 scrolling whereby only the line showing the cursor is horizontally
4314 scrolled to make point visible, the rest of the window is left either
4315 unscrolled, or at the minimum scroll amount set by @code{scroll-left}
4316 and @code{scroll-right}, see below.
4318 @deffn Command scroll-left &optional count set-minimum
4319 This function scrolls the selected window @var{count} columns to the
4320 left (or to the right if @var{count} is negative).  The default
4321 for @var{count} is the window width, minus 2.
4323 The return value is the total amount of leftward horizontal scrolling in
4324 effect after the change---just like the value returned by
4325 @code{window-hscroll} (below).
4327 Note that text in paragraphs whose base direction is right-to-left
4328 (@pxref{Bidirectional Display}) moves in the opposite direction: e.g.,
4329 it moves to the right when @code{scroll-left} is invoked with a
4330 positive value of @var{count}.
4332 Once you scroll a window as far right as it can go, back to its normal
4333 position where the total leftward scrolling is zero, attempts to scroll
4334 any farther right have no effect.
4336 If @var{set-minimum} is non-@code{nil}, the new scroll amount becomes
4337 the lower bound for automatic scrolling; that is, automatic scrolling
4338 will not scroll a window to a column less than the value returned by
4339 this function.  Interactive calls pass non-@code{nil} for
4340 @var{set-minimum}.
4341 @end deffn
4343 @deffn Command scroll-right &optional count set-minimum
4344 This function scrolls the selected window @var{count} columns to the
4345 right (or to the left if @var{count} is negative).  The default
4346 for @var{count} is the window width, minus 2.  Aside from the direction
4347 of scrolling, this works just like @code{scroll-left}.
4348 @end deffn
4350 @defun window-hscroll &optional window
4351 This function returns the total leftward horizontal scrolling of
4352 @var{window}---the number of columns by which the text in @var{window}
4353 is scrolled left past the left margin.  (In right-to-left paragraphs,
4354 the value is the total amount of the rightward scrolling instead.)
4355 The default for @var{window} is the selected window.
4357 The return value is never negative.  It is zero when no horizontal
4358 scrolling has been done in @var{window} (which is usually the case).
4361 @example
4362 @group
4363 (window-hscroll)
4364      @result{} 0
4365 @end group
4366 @group
4367 (scroll-left 5)
4368      @result{} 5
4369 @end group
4370 @group
4371 (window-hscroll)
4372      @result{} 5
4373 @end group
4374 @end example
4375 @end defun
4377 @defun set-window-hscroll window columns
4378 This function sets horizontal scrolling of @var{window}.  The value of
4379 @var{columns} specifies the amount of scrolling, in terms of columns
4380 from the left margin (right margin in right-to-left paragraphs).  The
4381 argument @var{columns} should be zero or positive; if not, it is taken
4382 as zero.  Fractional values of @var{columns} are not supported at
4383 present.
4385 Note that @code{set-window-hscroll} may appear not to work if you test
4386 it by evaluating a call with @kbd{M-:} in a simple way.  What happens
4387 is that the function sets the horizontal scroll value and returns, but
4388 then redisplay adjusts the horizontal scrolling to make point visible,
4389 and this overrides what the function did.  You can observe the
4390 function's effect if you call it while point is sufficiently far from
4391 the left margin that it will remain visible.
4393 The value returned is @var{columns}.
4395 @example
4396 @group
4397 (set-window-hscroll (selected-window) 10)
4398      @result{} 10
4399 @end group
4400 @end example
4401 @end defun
4403    Here is how you can determine whether a given position @var{position}
4404 is off the screen due to horizontal scrolling:
4406 @c FIXME: Maybe hscroll-on-screen-p is a better name?
4407 @example
4408 @group
4409 (defun hscroll-on-screen (window position)
4410   (save-excursion
4411     (goto-char position)
4412     (and
4413      (>= (- (current-column) (window-hscroll window)) 0)
4414      (< (- (current-column) (window-hscroll window))
4415         (window-width window)))))
4416 @end group
4417 @end example
4420 @node Coordinates and Windows
4421 @section Coordinates and Windows
4422 @cindex frame-relative coordinate
4423 @cindex coordinate, relative to frame
4424 @cindex window position
4426 This section describes functions that report positions of and within a
4427 window.  Most of these functions report positions relative to an origin
4428 at the native position of the window's frame (@pxref{Frame Geometry}).
4429 Some functions report positions relative to the origin of the display of
4430 the window's frame.  In any case, the origin has the coordinates (0, 0)
4431 and X and Y coordinates increase rightward and downward respectively.
4433   For the following functions, X and Y coordinates are reported in
4434 integer character units, i.e., numbers of lines and columns
4435 respectively.  On a graphical display, each ``line'' and ``column''
4436 corresponds to the height and width of the default character specified by
4437 the frame's default font (@pxref{Frame Font}).
4439 @defun window-edges &optional window body absolute pixelwise
4440 This function returns a list of the edge coordinates of @var{window}.
4441 If @var{window} is omitted or @code{nil}, it defaults to the selected
4442 window.
4444 The return value has the form @code{(@var{left} @var{top} @var{right}
4445 @var{bottom})}.  These list elements are, respectively, the X
4446 coordinate of the leftmost column occupied by the window, the Y
4447 coordinate of the topmost row, the X coordinate one column to the
4448 right of the rightmost column, and the Y coordinate one row down from
4449 the bottommost row.
4451 Note that these are the actual outer edges of the window, including any
4452 header line, mode line, scroll bar, fringes, window divider and display
4453 margins.  On a text terminal, if the window has a neighbor on its right,
4454 its right edge includes the separator line between the window and its
4455 neighbor.
4457 If the optional argument @var{body} is @code{nil}, this means to
4458 return the edges corresponding to the total size of @var{window}.
4459 @var{body} non-@code{nil} means to return the edges of @var{window}'s
4460 body (aka text area).  If @var{body} is non-@code{nil}, @var{window}
4461 must specify a live window.
4463 If the optional argument @var{absolute} is @code{nil}, this means to
4464 return edges relative to the native position of @var{window}'s frame.
4465 @var{absolute} non-@code{nil} means to return coordinates relative to
4466 the origin (0, 0) of @var{window}'s display.  On non-graphical systems
4467 this argument has no effect.
4469 If the optional argument @var{pixelwise} is @code{nil}, this means to
4470 return the coordinates in terms of the default character width and
4471 height of @var{window}'s frame (@pxref{Frame Font}), rounded if
4472 necessary.  @var{pixelwise} non-@code{nil} means to return the
4473 coordinates in pixels.  Note that the pixel specified by @var{right} and
4474 @var{bottom} is immediately outside of these edges.  If @var{absolute}
4475 is non-@code{nil}, @var{pixelwise} is implicitly non-@code{nil} too.
4476 @end defun
4478 @defun window-body-edges &optional window
4479 This function returns the edges of @var{window}'s body (@pxref{Window
4480 Sizes}).  Calling @code{(window-body-edges window)} is equivalent to
4481 calling @code{(window-edges window t)}, see above.
4482 @end defun
4484 @comment The following two functions are confusing and hardly used.
4485 @ignore
4486 @defun window-left-column &optional window
4487 This function returns the leftmost column of @var{window}.  This value
4488 equals the @var{left} entry in the list returned by @code{(window-edges
4489 window)} minus the number of columns occupied by the internal border of
4490 @var{window}'s frame.
4491 @end defun
4493 @defun window-top-line &optional window
4494 This function returns the topmost row of @var{window}.  This value is
4495 equal to the @var{top} entry in the list returned by @code{(window-edges
4496 window)} minus the number of lines occupied by the internal border of
4497 @var{window}'s frame.
4498 @end defun
4499 @end ignore
4501   The following functions can be used to relate a set of
4502 frame-relative coordinates to a window:
4504 @defun window-at x y &optional frame
4505 This function returns the live window at the coordinates @var{x} and
4506 @var{y} given in default character sizes (@pxref{Frame Font}) relative
4507 to the native position of @var{frame} (@pxref{Frame Geometry}).
4509 If there is no window at that position, the return value is @code{nil}.
4510 If @var{frame} is omitted or @code{nil}, it defaults to the selected
4511 frame.
4512 @end defun
4514 @defun coordinates-in-window-p coordinates window
4515 This function checks whether a window @var{window} occupies the frame
4516 relative coordinates @var{coordinates}, and if so, which part of the
4517 window that is.  @var{window} should be a live window.
4519 @var{coordinates} should be a cons cell of the form @code{(@var{x}
4520 . @var{y})}, where @var{x} and @var{y} are given in default character
4521 sizes (@pxref{Frame Font}) relative to the native position of
4522 @var{window}'s frame (@pxref{Frame Geometry}).
4524 If there is no window at the specified position, the return value is
4525 @code{nil} .  Otherwise, the return value is one of the following:
4527 @table @code
4528 @item (@var{relx} . @var{rely})
4529 The coordinates are inside @var{window}.  The numbers @var{relx} and
4530 @var{rely} are the equivalent window-relative coordinates for the
4531 specified position, counting from 0 at the top left corner of the
4532 window.
4534 @item mode-line
4535 The coordinates are in the mode line of @var{window}.
4537 @item header-line
4538 The coordinates are in the header line of @var{window}.
4540 @item right-divider
4541 The coordinates are in the divider separating @var{window} from a
4542 window on the right.
4544 @item bottom-divider
4545 The coordinates are in the divider separating @var{window} from a
4546 window beneath.
4548 @item vertical-line
4549 The coordinates are in the vertical line between @var{window} and its
4550 neighbor to the right.  This value occurs only if the window doesn't
4551 have a scroll bar; positions in a scroll bar are considered outside the
4552 window for these purposes.
4554 @item left-fringe
4555 @itemx right-fringe
4556 The coordinates are in the left or right fringe of the window.
4558 @item left-margin
4559 @itemx right-margin
4560 The coordinates are in the left or right margin of the window.
4562 @item nil
4563 The coordinates are not in any part of @var{window}.
4564 @end table
4566 The function @code{coordinates-in-window-p} does not require a frame as
4567 argument because it always uses the frame that @var{window} is on.
4568 @end defun
4570   The following functions return window positions in pixels, rather
4571 than character units.  Though mostly useful on graphical displays,
4572 they can also be called on text terminals, where the screen area of
4573 each text character is taken to be one pixel.
4575 @defun window-pixel-edges &optional window
4576 This function returns a list of pixel coordinates for the edges of
4577 @var{window}.  Calling @code{(window-pixel-edges window)} is equivalent
4578 to calling @code{(window-edges window nil nil t)}, see above.
4579 @end defun
4581 @comment The following two functions are confusing and hardly used.
4582 @ignore
4583 @defun window-pixel-left &optional window
4584 This function returns the left pixel edge of window @var{window}.  This
4585 value equals the @var{left} entry in the list returned by
4586 @code{(window-pixel-edges window)} minus the number of pixels occupied
4587 by the internal border of @var{window}'s frame.  @var{window} must be a
4588 valid window and defaults to the selected one.
4589 @end defun
4591 @defun window-pixel-top &optional window
4592 This function returns the top pixel edge of window @var{window}.  This
4593 value is equal to the @var{top} entry in the list returned by
4594 @code{(window-pixel-edges window)} minus the number of pixels occupied
4595 by the internal border of @var{window}'s frame.  @var{window} must be a
4596 valid window and defaults to the selected one.
4597 @end defun
4598 @end ignore
4600 @defun window-body-pixel-edges &optional window
4601 This function returns the pixel edges of @var{window}'s body.  Calling
4602 @code{(window-body-pixel-edges window)} is equivalent to calling
4603 @code{(window-edges window t nil t)}, see above.
4604 @end defun
4606   The following functions return window positions in pixels, relative to
4607 the origin of the display screen rather than that of the frame:
4609 @defun window-absolute-pixel-edges &optional window
4610 This function returns the pixel coordinates of @var{window} relative to
4611 an origin at (0, 0) of the display of @var{window}'s frame.  Calling
4612 @code{(window-absolute-pixel-edges)} is equivalent to calling
4613 @code{(window-edges window nil t t)}, see above.
4614 @end defun
4616 @defun window-absolute-body-pixel-edges &optional window
4617 This function returns the pixel coordinates of @var{window}'s body
4618 relative to an origin at (0, 0) of the display of @var{window}'s frame.
4619 Calling @code{(window-absolute-body-pixel-edges window)} is equivalent
4620 to calling @code{(window-edges window t t t)}, see above.
4622 Combined with @code{set-mouse-absolute-pixel-position}, this function
4623 can be used to move the mouse pointer to an arbitrary buffer position
4624 visible in some window:
4626 @example
4627 @group
4628 (let ((edges (window-absolute-body-pixel-edges))
4629       (position (pos-visible-in-window-p nil nil t)))
4630   (set-mouse-absolute-pixel-position
4631    (+ (nth 0 edges) (nth 0 position))
4632    (+ (nth 1 edges) (nth 1 position))))
4633 @end group
4634 @end example
4636 On a graphical terminal this form ``warps'' the mouse cursor to the
4637 upper left corner of the glyph at the selected window's point.  A
4638 position calculated this way can be also used to show a tooltip window
4639 there.
4640 @end defun
4642 The following function returns the screen coordinates of a buffer
4643 position visible in a window:
4645 @defun window-absolute-pixel-position &optional position window
4646 If the buffer position @var{position} is visible in window @var{window},
4647 this function returns the display coordinates of the upper/left corner
4648 of the glyph at @var{position}.  The return value is a cons of the X-
4649 and Y-coordinates of that corner, relative to an origin at (0, 0) of
4650 @var{window}'s display.  It returns @code{nil} if @var{position} is not
4651 visible in @var{window}.
4653 @var{window} must be a live window and defaults to the selected
4654 window.  @var{position} defaults to the value of @code{window-point}
4655 of @var{window}.
4657 This means that in order to move the mouse pointer to the position of
4658 point in the selected window, it's sufficient to write:
4660 @example
4661 @group
4662 (let ((position (window-absolute-pixel-position)))
4663   (set-mouse-absolute-pixel-position
4664    (car position) (cdr position)))
4665 @end group
4666 @end example
4667 @end defun
4669 The following function returns the largest rectangle that can be
4670 inscribed in a window without covering text displayed in that window.
4672 @defun window-largest-empty-rectangle &optional window count min-width min-height positions left
4673 This function calculates the dimensions of the largest empty rectangle
4674 that can be inscribed in the specified @var{window}'s text area.
4675 @var{window} must be a live window and defaults to the selected one.
4677 The return value is a triple of the width and the start and end
4678 y-coordinates of the largest rectangle that can be inscribed into the
4679 empty space (space not displaying any text) of the text area of
4680 @var{window}.  No x-coordinates are returned by this function---any such
4681 rectangle is assumed to end at the right edge of @var{window}'s text
4682 area.  If no empty space can be found, the return value is @code{nil}.
4684 The optional argument @var{count}, if non-@code{nil}, specifies a
4685 maximum number of rectangles to return.  This means that the return
4686 value is a list of triples specifying rectangles with the largest
4687 rectangle first.  @var{count} can be also a cons cell whose car
4688 specifies the number of rectangles to return and whose @sc{cdr}, if
4689 non-@code{nil}, states that all rectangles returned must be disjoint.
4691 The optional arguments @var{min-width} and @var{min-height}, if
4692 non-@code{nil}, specify the minimum width and height of any rectangle
4693 returned.
4695 The optional argument @var{positions}, if non-@code{nil}, is a cons cell
4696 whose @sc{car} specifies the uppermost and whose @sc{cdr} specifies the
4697 lowermost pixel position that must be covered by any rectangle returned.
4698 These positions measure from the start of the text area of @var{window}.
4700 The optional argument @var{left}, if non-@code{nil}, means to return
4701 values suitable for buffers displaying right to left text.  In that
4702 case, any rectangle returned is assumed to start at the left edge of
4703 @var{window}'s text area.
4705 Note that this function has to retrieve the dimensions of each line of
4706 @var{window}'s glyph matrix via @code{window-lines-pixel-dimensions}
4707 (@pxref{Size of Displayed Text}).  Hence, this function may also return
4708 @code{nil} when the current glyph matrix of @var{window} is not
4709 up-to-date.
4710 @end defun
4713 @node Mouse Window Auto-selection
4714 @section Mouse Window Auto-selection
4715 @cindex window auto-selection
4716 @cindex auto-selection of window
4717 The following option allows to automatically select the window under the
4718 mouse pointer.  This accomplishes a policy similar to that of window
4719 managers that give focus to a frame (and thus trigger its subsequent
4720 selection) whenever the mouse pointer enters its window-system window
4721 (@pxref{Input Focus}).
4723 @defopt mouse-autoselect-window
4724 If this variable is non-@code{nil}, Emacs will try to automatically
4725 select the window under the mouse pointer.  The following values are
4726 meaningful:
4728 @table @asis
4729 @item A positive number
4730 This specifies a delay in seconds after which auto-selection triggers.
4731 The window under the mouse pointer is selected after the mouse has
4732 remained in it for the entire duration of the delay.
4734 @item A negative number
4735 A negative number has a similar effect as a positive number, but selects
4736 the window under the mouse pointer only after the mouse pointer has
4737 remained in it for the entire duration of the absolute value of that
4738 number and in addition has stopped moving.
4740 @item Other value
4741 Any other non-@code{nil} value means to select a window instantaneously
4742 as soon as the mouse pointer enters it.
4743 @end table
4745 In either case, the mouse pointer must enter the text area of a window in
4746 order to trigger its selection.  Dragging the scroll bar slider or the
4747 mode line of a window conceptually should not cause its auto-selection.
4749 Mouse auto-selection selects the minibuffer window only if it is active,
4750 and never deselects the active minibuffer window.
4751 @end defopt
4753 Mouse auto-selection can be used to emulate a focus follows mouse policy
4754 for child frames (@pxref{Child Frames}) which usually are not tracked by
4755 the window manager.  This requires to set the value of
4756 @code{focus-follows-mouse} (@pxref{Input Focus}) to a non-@code{nil}
4757 value.  If the value of @code{focus-follows-mouse} is @code{auto-raise},
4758 entering a child frame with the mouse will raise it automatically above
4759 all other child frames of that frame's parent frame.
4762 @node Window Configurations
4763 @section Window Configurations
4764 @cindex window configurations
4765 @cindex saving window information
4767 A @dfn{window configuration} records the entire layout of one
4768 frame---all windows, their sizes, which buffers they contain, how those
4769 buffers are scrolled, and their value of point; also their
4770 fringes, margins, and scroll bar settings.  It also includes the value
4771 of @code{minibuffer-scroll-window}.  As a special exception, the window
4772 configuration does not record the value of point in the selected window
4773 for the current buffer.
4775   You can bring back an entire frame layout by restoring a previously
4776 saved window configuration.  If you want to record the layout of all
4777 frames instead of just one, use a frame configuration instead of a
4778 window configuration.  @xref{Frame Configurations}.
4780 @defun current-window-configuration &optional frame
4781 This function returns a new object representing @var{frame}'s current
4782 window configuration.  The default for @var{frame} is the selected
4783 frame.  The variable @code{window-persistent-parameters} specifies
4784 which window parameters (if any) are saved by this function.
4785 @xref{Window Parameters}.
4786 @end defun
4788 @defun set-window-configuration configuration
4789 This function restores the configuration of windows and buffers as
4790 specified by @var{configuration}, for the frame that @var{configuration}
4791 was created for.
4793 The argument @var{configuration} must be a value that was previously
4794 returned by @code{current-window-configuration}.  The configuration is
4795 restored in the frame from which @var{configuration} was made, whether
4796 that frame is selected or not.  In some rare cases this may trigger
4797 execution of the @code{window-size-change-functions} (@pxref{Window
4798 Hooks}) even if the size of windows did not change at all.  The
4799 @code{window-configuration-change-hook} functions will be called if and
4800 only if at least one window was added to or deleted from the frame.
4802 If the frame from which @var{configuration} was saved is dead, all this
4803 function does is restore the three variables @code{window-min-height},
4804 @code{window-min-width} and @code{minibuffer-scroll-window}.  In this
4805 case, the function returns @code{nil}.  Otherwise, it returns @code{t}.
4807 Here is a way of using this function to get the same effect
4808 as @code{save-window-excursion}:
4810 @example
4811 @group
4812 (let ((config (current-window-configuration)))
4813   (unwind-protect
4814       (progn (split-window-below nil)
4815              @dots{})
4816     (set-window-configuration config)))
4817 @end group
4818 @end example
4819 @end defun
4821 @defmac save-window-excursion forms@dots{}
4822 This macro records the window configuration of the selected frame,
4823 executes @var{forms} in sequence, then restores the earlier window
4824 configuration.  The return value is the value of the final form in
4825 @var{forms}.
4827 Most Lisp code should not use this macro; @code{save-selected-window}
4828 is typically sufficient.  In particular, this macro cannot reliably
4829 prevent the code in @var{forms} from opening new windows, because new
4830 windows might be opened in other frames (@pxref{Choosing Window}), and
4831 @code{save-window-excursion} only saves and restores the window
4832 configuration on the current frame.
4834 Do not use this macro in @code{window-size-change-functions}; exiting
4835 the macro triggers execution of @code{window-size-change-functions},
4836 leading to an endless loop.
4837 @end defmac
4839 @defun window-configuration-p object
4840 This function returns @code{t} if @var{object} is a window configuration.
4841 @end defun
4843 @defun compare-window-configurations config1 config2
4844 This function compares two window configurations as regards the
4845 structure of windows, but ignores the values of point and the
4846 saved scrolling positions---it can return @code{t} even if those
4847 aspects differ.
4849 The function @code{equal} can also compare two window configurations; it
4850 regards configurations as unequal if they differ in any respect, even a
4851 saved point.
4852 @end defun
4854 @defun window-configuration-frame config
4855 This function returns the frame for which the window configuration
4856 @var{config} was made.
4857 @end defun
4859   Other primitives to look inside of window configurations would make
4860 sense, but are not implemented because we did not need them.  See the
4861 file @file{winner.el} for some more operations on windows
4862 configurations.
4864   The objects returned by @code{current-window-configuration} die
4865 together with the Emacs process.  In order to store a window
4866 configuration on disk and read it back in another Emacs session, you
4867 can use the functions described next.  These functions are also useful
4868 to clone the state of a frame into an arbitrary live window
4869 (@code{set-window-configuration} effectively clones the windows of a
4870 frame into the root window of that very frame only).
4872 @cindex window state
4873 @defun window-state-get &optional window writable
4874 This function returns the state of @var{window} as a Lisp object.  The
4875 argument @var{window} must be a valid window and defaults to the root
4876 window of the selected frame.
4878 If the optional argument @var{writable} is non-@code{nil}, this means to
4879 not use markers for sampling positions like @code{window-point} or
4880 @code{window-start}.  This argument should be non-@code{nil} when the
4881 state will be written to disk and read back in another session.
4883 Together, the argument @var{writable} and the variable
4884 @code{window-persistent-parameters} specify which window parameters are
4885 saved by this function.  @xref{Window Parameters}.
4886 @end defun
4888 The value returned by @code{window-state-get} can be used in the same
4889 session to make a clone of a window in another window.  It can be also
4890 written to disk and read back in another session.  In either case, use
4891 the following function to restore the state of the window.
4893 @defun window-state-put state &optional window ignore
4894 This function puts the window state @var{state} into @var{window}.
4895 The argument @var{state} should be the state of a window returned by
4896 an earlier invocation of @code{window-state-get}, see above.  The
4897 optional argument @var{window} can be either a live window or an
4898 internal window (@pxref{Windows and Frames}) and defaults to the
4899 selected one.  If @var{window} is not live, it is replaced by a live
4900 window before putting @var{state} into it.
4902 If the optional argument @var{ignore} is non-@code{nil}, it means to ignore
4903 minimum window sizes and fixed-size restrictions.  If @var{ignore}
4904 is @code{safe}, this means windows can get as small as one line
4905 and/or two columns.
4906 @end defun
4908 The functions @code{window-state-get} and @code{window-state-put} also
4909 allow to exchange the contents of two live windows.  The following
4910 function does precisely that:
4912 @deffn Command window-swap-states &optional window-1 window-2 size
4913 This command swaps the states of the two live windows @var{window-1} and
4914 @var{window-2}.  @var{window-1} must specify a live window and defaults
4915 to the selected one.  @var{window-2} must specify a live window and
4916 defaults to the window following @var{window-1} in the cyclic ordering
4917 of windows, excluding minibuffer windows and including live windows on
4918 all visible frames.
4920 Optional argument @var{size} non-@code{nil} means to try swapping the
4921 sizes of @var{window-1} and @var{window-2} as well.  A value of
4922 @code{height} means to swap heights only, a value of @code{width}
4923 means to swap widths only, while @code{t} means to swap both widths
4924 and heights, if possible.  Frames are not resized by this function.
4925 @end deffn
4928 @node Window Parameters
4929 @section Window Parameters
4930 @cindex window parameters
4932 This section describes how window parameters can be used to associate
4933 additional information with windows.
4935 @defun window-parameter window parameter
4936 This function returns @var{window}'s value for @var{parameter}.  The
4937 default for @var{window} is the selected window.  If @var{window} has no
4938 setting for @var{parameter}, this function returns @code{nil}.
4939 @end defun
4941 @defun window-parameters &optional window
4942 This function returns all parameters of @var{window} and their values.
4943 The default for @var{window} is the selected window.  The return value
4944 is either @code{nil}, or an association list whose elements have the form
4945 @code{(@var{parameter} . @var{value})}.
4946 @end defun
4948 @defun set-window-parameter window parameter value
4949 This function sets @var{window}'s value of @var{parameter} to
4950 @var{value} and returns @var{value}.  The default for @var{window}
4951 is the selected window.
4952 @end defun
4954 By default, the functions that save and restore window configurations or the
4955 states of windows (@pxref{Window Configurations}) do not care about
4956 window parameters.  This means that when you change the value of a
4957 parameter within the body of a @code{save-window-excursion}, the
4958 previous value is not restored when that macro exits.  It also means
4959 that when you restore via @code{window-state-put} a window state saved
4960 earlier by @code{window-state-get}, all cloned windows have their
4961 parameters reset to @code{nil}.  The following variable allows you to
4962 override the standard behavior:
4964 @cindex persistent window parameters
4965 @defvar window-persistent-parameters
4966 This variable is an alist specifying which parameters get saved by
4967 @code{current-window-configuration} and @code{window-state-get}, and
4968 subsequently restored by @code{set-window-configuration} and
4969 @code{window-state-put}.  @xref{Window Configurations}.
4971 The @sc{car} of each entry of this alist is a symbol specifying the
4972 parameter.  The @sc{cdr} should be one of the following:
4974 @table @asis
4975 @item @code{nil}
4976 This value means the parameter is saved neither by
4977 @code{window-state-get} nor by @code{current-window-configuration}.
4979 @item @code{t}
4980 This value specifies that the parameter is saved by
4981 @code{current-window-configuration} and (provided its @var{writable}
4982 argument is @code{nil}) by @code{window-state-get}.
4984 @item @code{writable}
4985 This means that the parameter is saved unconditionally by both
4986 @code{current-window-configuration} and @code{window-state-get}.  This
4987 value should not be used for parameters whose values do not have a read
4988 syntax.  Otherwise, invoking @code{window-state-put} in another session
4989 may fail with an @code{invalid-read-syntax} error.
4990 @end table
4991 @end defvar
4993 Some functions (notably @code{delete-window},
4994 @code{delete-other-windows} and @code{split-window}), may behave
4995 specially when the window specified by their @var{window} argument has
4996 a parameter whose name is equal to the function's name.  You can
4997 override such special behavior by binding the following variable to a
4998 non-@code{nil} value:
5000 @defvar ignore-window-parameters
5001 If this variable is non-@code{nil}, some standard functions do not
5002 process window parameters.  The functions currently affected by this are
5003 @code{split-window}, @code{delete-window}, @code{delete-other-windows},
5004 and @code{other-window}.
5006 An application can bind this variable to a non-@code{nil} value around
5007 calls to these functions.  If it does so, the application is fully
5008 responsible for correctly assigning the parameters of all involved
5009 windows when exiting that function.
5010 @end defvar
5012 The following parameters are currently used by the window management
5013 code:
5015 @table @code
5016 @item delete-window
5017 @vindex delete-window@r{, a window parameter}
5018 This parameter affects the execution of @code{delete-window}
5019 (@pxref{Deleting Windows}).
5021 @item delete-other-windows
5022 @vindex delete-other-windows@r{, a window parameter}
5023 This parameter affects the execution of @code{delete-other-windows}
5024 (@pxref{Deleting Windows}).
5026 @item no-delete-other-windows
5027 @vindex no-delete-other-windows@r{, a window parameter}
5028 This parameter marks the window as not deletable by
5029 @code{delete-other-windows} (@pxref{Deleting Windows}).
5031 @item split-window
5032 @vindex split-window@r{, a window parameter}
5033 This parameter affects the execution of @code{split-window}
5034 (@pxref{Splitting Windows}).
5036 @item other-window
5037 @vindex other-window@r{, a window parameter}
5038 This parameter affects the execution of @code{other-window}
5039 (@pxref{Cyclic Window Ordering}).
5041 @item no-other-window
5042 @vindex no-other-window@r{, a window parameter}
5043 This parameter marks the window as not selectable by @code{other-window}
5044 (@pxref{Cyclic Window Ordering}).
5046 @item clone-of
5047 @vindex clone-of@r{, a window parameter}
5048 This parameter specifies the window that this one has been cloned
5049 from.  It is installed by @code{window-state-get} (@pxref{Window
5050 Configurations}).
5052 @item window-preserved-size
5053 @vindex window-preserved-size@r{, a window parameter}
5054 This parameter specifies a buffer, a direction where @code{nil} means
5055 vertical and @code{t} horizontal, and a size in pixels.  If this window
5056 displays the specified buffer and its size in the indicated direction
5057 equals the size specified by this parameter, then Emacs will try to
5058 preserve the size of this window in the indicated direction.  This
5059 parameter is installed and updated by the function
5060 @code{window-preserve-size} (@pxref{Preserving Window Sizes}).
5062 @item quit-restore
5063 @vindex quit-restore@r{, a window parameter}
5064 This parameter is installed by the buffer display functions
5065 (@pxref{Choosing Window}) and consulted by @code{quit-restore-window}
5066 (@pxref{Quitting Windows}).  It contains four elements:
5068 The first element is one of the symbols @code{window}, meaning that
5069 the window has been specially created by @code{display-buffer};
5070 @code{frame}, a separate frame has been created; @code{same}, the
5071 window has only ever displayed this buffer; or @code{other}, the
5072 window showed another buffer before.  @code{frame} and @code{window}
5073 affect how the window is quit, while @code{same} and @code{other}
5074 affect the redisplay of buffers previously shown in this window.
5076 The second element is either one of the symbols @code{window} or
5077 @code{frame}, or a list whose elements are the buffer shown in the
5078 window before, that buffer's window start and window point positions,
5079 and the window's height at that time.  If that buffer is still live
5080 when the window is quit, then the function @code{quit-restore-window}
5081 reuses the window to display the buffer.
5083 The third element is the window selected at the time the parameter was
5084 created.  If @code{quit-restore-window} deletes the window passed to
5085 it as argument, it then tries to reselect this window.
5087 The fourth element is the buffer whose display caused the creation of
5088 this parameter.  @code{quit-restore-window} deletes the specified window
5089 only if it still shows that buffer.
5091 See the description of @code{quit-restore-window} in @ref{Quitting
5092 Windows} for details.
5094 @item window-side window-slot
5095 @vindex window-side@r{, a window parameter}
5096 @vindex window-slot@r{, a window parameter}
5097 These parameters are used for implementing side windows (@pxref{Side
5098 Windows}).
5100 @item window-atom
5101 @vindex window-atom@r{, a window parameter}
5102 This parameter is used for implementing atomic windows, see @ref{Atomic
5103 Windows}.
5105 @item mode-line-format
5106 @vindex mode-line-format@r{, a window parameter}
5107 This parameter replaces the value of the buffer-local variable
5108 @code{mode-line-format} (@pxref{Mode Line Basics}) of this window's
5109 buffer whenever this window is displayed.  The symbol @code{none} means
5110 to suppress display of a mode line for this window.  Display and
5111 contents of the mode line on other windows showing this buffer are not
5112 affected.
5114 @item header-line-format
5115 @vindex header-line-format@r{, a window parameter}
5116 This parameter replaces the value of the buffer-local variable
5117 @code{header-line-format} (@pxref{Mode Line Basics}) of this window's
5118 buffer whenever this window is displayed.  The symbol @code{none} means
5119 to suppress display of a header line for this window.  Display and
5120 contents of the header line on other windows showing this buffer are not
5121 affected.
5123 @item min-margins
5124 @vindex min-margins@r{, a window parameter}
5125 The value of this parameter is a cons cell whose @sc{car} and @sc{cdr},
5126 if non-@code{nil}, specify the minimum values (in columns) for the left
5127 and right margin of this window.  When present, Emacs will use these
5128 values instead of the actual margin widths for determining whether a
5129 window can be split or shrunk horizontally.
5131 Emacs never auto-adjusts the margins of any window after splitting or
5132 resizing it.  It is the sole responsibility of any application setting
5133 this parameter to adjust the margins of this window as well as those of
5134 any new window that inherits this window's margins due to a split.
5135 Both @code{window-configuration-change-hook} and
5136 @code{window-size-change-functions} (@pxref{Window Hooks}) should be
5137 employed for this purpose.
5139 This parameter was introduced in Emacs version 25.1 to support
5140 applications that use large margins to center buffer text within a
5141 window and should be used, with due care, exclusively by those
5142 applications.  It might be replaced by an improved solution in future
5143 versions of Emacs.
5144 @end table
5146 @node Window Hooks
5147 @section Hooks for Window Scrolling and Changes
5148 @cindex hooks for window operations
5150 This section describes how a Lisp program can take action whenever a
5151 window displays a different part of its buffer or a different buffer.
5152 There are three actions that can change this: scrolling the window,
5153 switching buffers in the window, and changing the size of the window.
5154 The first two actions run @code{window-scroll-functions}; the last runs
5155 @code{window-size-change-functions}.
5157 @defvar window-scroll-functions
5158 This variable holds a list of functions that Emacs should call before
5159 redisplaying a window with scrolling.  Displaying a different buffer in
5160 the window also runs these functions.
5162 This variable is not a normal hook, because each function is called with
5163 two arguments: the window, and its new display-start position.  At the
5164 time of the call, the display-start position of the window argument is
5165 already set to its new value, and the buffer to be displayed in the
5166 window is already set as the current buffer.
5168 These functions must take care when using @code{window-end}
5169 (@pxref{Window Start and End}); if you need an up-to-date value, you
5170 must use the @var{update} argument to ensure you get it.
5172 @strong{Warning:} don't use this feature to alter the way the window
5173 is scrolled.  It's not designed for that, and such use probably won't
5174 work.
5175 @end defvar
5177 @defun run-window-scroll-functions &optional window
5178 This function calls @code{window-scroll-functions} for the specified
5179 @var{window}, which defaults to the selected window.
5180 @end defun
5182 @defvar window-size-change-functions
5183 This variable holds a list of functions to be called if the size of any
5184 window changes for any reason.  The functions are called once per
5185 redisplay, and once for each frame on which size changes have occurred.
5187 Each function receives the frame as its sole argument.  To find out
5188 whether a specific window has changed size, compare the return values of
5189 @code{window-pixel-width-before-size-change} and
5190 @code{window-pixel-width} respectively
5191 @code{window-pixel-height-before-size-change} and
5192 @code{window-pixel-height} for that window (@pxref{Window Sizes}).
5194 These function are usually only called when at least one window was
5195 added or has changed size since the last time this hook was run for the
5196 associated frame.  In some rare cases this hook also runs when a window
5197 that was added intermittently has been deleted afterwards.  In these
5198 cases none of the windows on the frame will appear to have changed its
5199 size.
5201 You may use @code{save-selected-window} in these functions
5202 (@pxref{Selecting Windows}).  However, do not use
5203 @code{save-window-excursion} (@pxref{Window Configurations}); exiting
5204 that macro counts as a size change, which would cause these functions to
5205 be called again.
5206 @end defvar
5208 @defvar window-configuration-change-hook
5209 A normal hook that is run every time the window configuration of a frame
5210 changes.  Window configuration changes include splitting and deleting
5211 windows, and the display of a different buffer in a window.  Resizing the
5212 frame or individual windows do not count as configuration changes.  Use
5213 @code{window-size-change-functions}, see above, when you want to track
5214 size changes that are not caused by the deletion or creation of windows.
5216 The buffer-local value of this hook is run once for each window on the
5217 affected frame, with the relevant window selected and its buffer
5218 current.  The global value of this hook is run once for the modified
5219 frame, with that frame selected.
5220 @end defvar
5222 @defun run-window-configuration-change-hook &optional frame
5223 This function runs @code{window-configuration-change-hook} for the
5224 specified @var{frame}, which defaults to the selected frame.
5225 @end defun
5227   In addition, you can use @code{jit-lock-register} to register a Font
5228 Lock fontification function, which will be called whenever parts of a
5229 buffer are (re)fontified because a window was scrolled or its size
5230 changed.  @xref{Other Font Lock Variables}.