Merge from trunk
[emacs.git] / doc / lispref / windows.texi
blob173628cacab107afe93d8127d8f05455235bc633
1 @c -*-texinfo-*-
2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 1990-1995, 1998-1999, 2001-2011
4 @c   Free Software Foundation, Inc.
5 @c See the file elisp.texi for copying conditions.
6 @setfilename ../../info/windows
7 @node Windows, Positions, Frames, Top
8 @chapter Windows
10   This chapter describes the functions and variables related to Emacs
11 windows.  @xref{Display}, for information on how text is displayed in
12 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 * Splitting Windows::       Splitting one window into two windows.
20 * Deleting Windows::        Deleting a window gives its space to other windows.
21 * Selecting Windows::       The selected window is the one that you edit in.
22 * Cyclic Window Ordering::  Moving around the existing windows.
23 * Buffers and Windows::     Each live window displays the contents of a buffer.
24 * Displaying Buffers::      How to choose a window for displaying a buffer.
25 * Switching Buffers::       Higher-level functions for switching to a buffer
26                               in some window.
27 * Dedicated Windows::       How to avoid displaying another buffer in
28                               a specific window.
29 * Window Point::            Each window has its own location of point.
30 * Window Start and End::    Buffer positions indicating which text is
31                               on-screen in a window.
32 * Textual Scrolling::       Moving text up and down through the window.
33 * Vertical Scrolling::      Moving the contents up and down on the window.
34 * Horizontal Scrolling::    Moving the contents sideways on the window.
35 * Coordinates and Windows:: Determining a window's edges and
36                               converting coordinates to windows.
37 * Window Configurations::   Saving and restoring the state of the screen.
38 * Window Parameters::       Associating additional information with windows.
39 * Atomic Windows::          Gluing windows together.
40 * Side Windows::            Grouping side windows around a main window.
41 * Window Hooks::            Hooks for scrolling, window size changes,
42                               redisplay going past a certain point,
43                               or window configuration changes.
44 @end menu
47 @node Basic Windows
48 @section Basic Concepts of Emacs Windows
49 @cindex window
51 A @dfn{window} in Emacs is the physical area of the screen in which a
52 buffer is displayed.  The term is also used to refer to a Lisp object
53 that represents that screen area in Emacs Lisp.  It should be clear from
54 the context which is meant.
56 @cindex multiple windows
57   Emacs groups windows into frames; see @ref{Frames}.  Each frame always
58 contains at least one window, but you can subdivide it into multiple,
59 non-overlapping Emacs windows.  Users create multiple windows so they
60 can look at several buffers at once.  Lisp libraries use multiple
61 windows for a variety of reasons, but most often to display related
62 information.  In Rmail, for example, you can move through a summary
63 buffer in one window while the other window shows messages one at a time
64 as they are reached.
66 @cindex terminal screen
67 @cindex screen of terminal
68   The meaning of ``window'' in Emacs is similar to what it means in the
69 context of general-purpose window systems such as X, but not identical.
70 The X Window System places X windows on the screen; Emacs uses one or
71 more X windows as frames, and subdivides them into Emacs windows.  When
72 you use Emacs on a character-only terminal, Emacs treats the whole
73 terminal screen as one frame.
75 @cindex tiled windows
76   Most window systems support arbitrarily located overlapping windows.
77 In contrast, Emacs windows are @dfn{tiled}; they never overlap, and
78 together they fill the whole screen or frame.  Because of the way in
79 which Emacs creates new windows (@pxref{Splitting Windows}) and resizes
80 them (@pxref{Resizing Windows}), not all conceivable tilings of windows
81 on an Emacs frame are actually possible.
83   For practical purposes, a window exists only while it is displayed in
84 a frame.  Once removed from the frame, the window is effectively deleted
85 and should not be used, @emph{even though there may still be references
86 to it} from other Lisp objects; see @ref{Deleting Windows}.  Restoring a
87 saved window configuration is the only way for a window no longer on the
88 screen to come back to life; see @ref{Window Configurations}.
90 @defun windowp object
91 This function returns @code{t} if @var{object} is a window and
92 @code{nil} otherwise.
93 @end defun
95 @cindex live windows
96 @cindex internal windows
97    For historical reasons a window is considered @dfn{live} if and only
98 if it currently displays a buffer; see @ref{Buffers and Windows}.  In
99 order to show multiple windows within one and the same frame, Emacs
100 organizes them in form of a tree called window tree; see @ref{Windows
101 and Frames}.  The internal nodes of a window tree are called internal
102 windows and are not considered live.  The leaf nodes of a window tree
103 constitute the windows displaying buffers and only they will be called
104 live here.  The selected window (@pxref{Selecting Windows}) is always a
105 live window.
107 @defun window-live-p object
108 This function returns @code{t} if @var{object} is a live window and
109 @code{nil} otherwise.  A live window is a window that displays a buffer.
110 @end defun
112 @defun window-any-p object
113 This function returns @code{t} if @var{object} denotes a live or an
114 internal window and @code{nil} otherwise.  In particular, this function
115 returns @code{nil} if @var{object} is a window that has been
116 deleted.
117 @end defun
119    The window handling functions can be roughly grouped into functions
120 operating on live windows only and functions that accept any window as
121 argument.  Many of these functions accept the value @code{nil} to
122 specify the selected window.  The two functions below can be used to
123 ``normalize'' arguments specifying windows in a uniform manner.
125 @defun normalize-any-window window
126 This function returns the normalized value for @var{window} which can be
127 any window that has not been deleted.  More precisely, if @var{window}
128 is @code{nil} it returns the selected window.  If @var{window} is
129 non-@code{nil} and denotes a live or an internal window, this function
130 returns @var{window}.  In any other case this function signals an error.
131 @end defun
133 @defun normalize-live-window window
134 This functions returns the normalized value for a live window
135 @var{window}.  More precisely, if @var{window} is @code{nil} it returns
136 the selected window.  Otherwise, if @var{window} is a live window this
137 function returns @var{window}.  If @var{window} is neither @code{nil}
138 nor a live window this function signals an error.
139 @end defun
142 @node Windows and Frames
143 @section Windows and Frames
145 Each window is part of one and only one frame (@pxref{Frames}); you can
146 get that frame with the function described next.
148 @defun window-frame window
149 This function returns the frame that @var{window} is on.  The argument
150 @var{window} can be any window and defaults to the selected one.
151 @end defun
153 The following function returns a list of all live windows on a specific
154 frame.
156 @defun window-list &optional frame minibuf window
157 This function returns a list of @var{frame}'s live windows, starting
158 with @var{window}.  The argument @var{frame} has to denote a live frame
159 and defaults to the selected frame.  The argument @var{window} has to
160 denote a live window on the frame specified by @var{frame} and defaults
161 to the selected one.
163 The argument @var{minibuf} specifies if the minibuffer window shall be
164 included in the return value.  If @var{minibuf} is @code{t}, the result
165 always includes the minibuffer window.  If @var{minibuf} is @code{nil}
166 or omitted, that includes the minibuffer window only if it is active.
167 If @var{minibuf} is neither @code{nil} nor @code{t}, the result never
168 includes the minibuffer window.
169 @end defun
171 @cindex window tree
172 Windows within one and the same frame are organized in form of a tree
173 called @dfn{window tree}.  The leaf nodes of a window tree constitute
174 the windows visible to the user.  These are the windows associated with
175 buffers and are usually called live or leaf windows.  The internal nodes
176 of a window tree are needed for finding, traversing and displaying the
177 leaf windows.
179    A minibuffer window (@pxref{Minibuffer Windows}) is not considered
180 part of its frame's window tree unless the frame is a minibuffer-only
181 frame.  Most functions covered in this section accept, however, the
182 minibuffer window as argument.  Also, the minibuffer window is listed by
183 the function @code{window-tree} described at the end of this section.
185    A window tree is rooted at the root window of its frame.
187 @defun frame-root-window &optional frame-or-window
188 This function returns the root window of @var{frame-or-window}.  The
189 argument @var{frame-or-window} has to denote either a window or a frame
190 and defaults to the selected frame.  If @var{frame-or-window} denotes a
191 window, the return value is the root window of that window's frame.
192 This function always returns a window; a live window if the frame
193 specified by @var{frame-or-window} contains no other live windows and an
194 internal window otherwise.
195 @end defun
197 @cindex subwindow
198 All other windows of a frame with the exception of the minibuffer window
199 are subwindows of the frame's root window.  A window is considered a
200 @dfn{subwindow} of another window if it occupies a part of that other
201 window's screen area.
203 The functions described next allow to access the members of a window
204 tree and take an arbitrary window as argument.
206 @cindex parent window
207 @defun window-parent &optional window
208 Return @var{window}'s parent in the window tree.  The optional argument
209 @var{window} can denote an arbitrary window and defaults to the selected
210 one.  The return value is @code{nil} if @var{window} is a minibuffer
211 window or the root window of its frame and an internal window otherwise.
212 @end defun
214 @cindex child window
215    Parent windows do not appear on the screen.  The screen area of a
216 parent window is the rectangular part of the window's frame occupied by
217 the window's @dfn{child windows}, that is, the set of windows having
218 that window as their parent.  Each parent window has at least two child
219 windows, so there are no ``Matryoshka'' windows.  Minibuffer windows do
220 not have child windows.
222 @cindex window combination
223 @cindex vertical combination
224 @cindex horizontal combination
225 The children of any parent window form either a vertical or a horizontal
226 combination of windows.  A @dfn{vertical combination} is a set of
227 windows arranged one above each other.  A @dfn{horizontal combination}
228 is a set of windows arranged side by side.  Consider the frame shown
229 below (for simplicity we assume that the frame does not contain a
230 minibuffer window):
232 @smallexample
233 @group
234      ______________________________________
235     | ______  ____________________________ |
236     ||      || __________________________ ||
237     ||      ||| ___________  ___________ |||
238     ||      ||||           ||           ||||
239     ||      ||||           ||           ||||
240     ||      ||||_____W6____||_____W7____||||
241     ||      |||____________W4____________|||
242     ||      || __________________________ ||
243     ||      |||                          |||
244     ||      |||____________W5____________|||
245     ||__W2__||_____________W3_____________ |
246     |__________________W1__________________|
248 @end group
249 @end smallexample
251 The root window of the frame is @code{W1}---a horizontal combination of
252 the leaf window @code{W2} and @code{W3}.  Hence @code{(window-parent
253 W1)} is @code{nil} while @code{(window-parent W2)} and
254 @code{(window-parent W3)} both evaluate to (the window object
255 representing) @code{W1}.
257    The internal window @code{W3} is a vertical combination of @code{W4}
258 and the leaf window @code{W5}.  The internal window @code{W4} is a
259 horizontal combination of the leaf windows @code{W6} and @code{W7}.  The
260 windows you actually see on your screen are @code{W2}, @code{W5},
261 @code{W6} and @code{W7}.
263    For any parent window, the first child window can be retrieved by the
264 functions given next.
266 @defun window-vchild &optional window
267 This function returns @var{window}'s first vertical child window.  The
268 optional argument @var{window} can be an arbitrary window and defaults
269 to the selected one.  The return value is @code{nil} if @var{window} is
270 a leaf window or its children form a horizontal combination.  In the
271 example above @code{(window-vchild W3)} is @code{W4} while
272 @code{(window-vchild W4)} is @code{nil}.
273 @end defun
275 @defun window-hchild &optional window
276 This function returns @var{window}'s first horizontal child window.  The
277 optional argument @var{window} can be an arbitrary window and defaults
278 to the selected one.  The return value is @code{nil} if @var{window} is
279 a leaf window or its children form a vertical combination.  In the
280 example above @code{(window-hchild W4)} is @code{W6} while
281 @code{(window-vchild W3)} is @code{nil}.
282 @end defun
284 @defun window-child window
285 This function return @var{window}'s first child window.  The return
286 value is @code{nil} if @var{window} is a leaf window.  In the example
287 above @code{(window-child W3)} is @code{W4} while @code{(window-child
288 W4)} is @code{W6}.
289 @end defun
291 The following function is useful to determine whether a window is part
292 of a vertical or horizontal combination.
294 @defun window-iso-combined-p &optional window horizontal
295 This function returns non-@code{nil} if and only if @var{window} is
296 vertically combined.  The argument @var{window} can specify any window
297 and defaults to the selected one.  The actual return value is the first
298 vertical child of window.
300 If the optional argument @var{horizontal} is non-@code{nil}, this means
301 to return non-@code{nil} if and only if @var{window} is horizontally
302 combined.  The actual return value is the first horizontal child of
303 window.
304 @end defun
306 @cindex sibling window
307 For any window that is part of a combination, the other windows in that
308 combination are called the window's @dfn{siblings}.  The only windows
309 that do not have siblings are root windows of frames and minibuffer
310 windows.  A window's siblings can be retrieved with the following two
311 functions.
313 @defun window-next &optional window
314 This function returns @var{window}'s right sibling.  The optional
315 argument @var{window} can be an arbitrary window and defaults to the
316 selected window.  It returns @code{nil} if @var{window} has no right
317 sibling.  Applying this function recursively will eventually get you to
318 the last child of @var{window}'s parent.  In our example
319 @code{(window-next W2)} is @code{W3} while @code{(window-next W3)} is
320 @code{nil}.
321 @end defun
323 @defun window-prev &optional window
324 This function returns @var{window}'s left sibling.  The optional
325 argument @var{window} can be an arbitrary window and defaults to the
326 selected window.  It returns @code{nil} if @var{window} has no left
327 sibling.  Applying this function recursively will eventually get you to
328 the first child of @var{window}'s parent.  In our example
329 @code{(window-prev W3)} is @code{W2} and @code{(window-prev W2)} is
330 @code{nil}.
331 @end defun
333 The functions @code{window-next} and @code{window-prev} should not be
334 confused with the functions @code{next-window} and
335 @code{previous-window} which respectively return the next and previous
336 window in the cyclic ordering of windows, see @ref{Cyclic Window
337 Ordering}.
339    In order to find the first live window on a frame, the following
340 function can be used.
342 @defun frame-first-window &optional frame-or-window
343 This function returns the live window at the upper left corner of the
344 frame specified by @var{frame-or-window}.  The argument
345 @var{frame-or-window} must denote a window or a live frame and defaults
346 to the selected frame.  If @var{frame-or-window} specifies a window,
347 this function returns the first window on that window's frame.  Under
348 the assumption that the frame from our canonical example is selected
349 @code{(frame-first-window)} returns @code{W2}.
350 @end defun
352 You can get the window tree of a frame with the following function.
354 @cindex window tree
355 @defun window-tree &optional frame
356 This function returns the window tree for frame @var{frame}.  The
357 optional argument @var{frame} must be a live frame and defaults to the
358 selected one.
360 The return value is a list of the form @code{(@var{root} @var{mini})},
361 where @var{root} represents the window tree of the frame's
362 root window, and @var{mini} is the frame's minibuffer window.
364 If the root window is live, @var{root} specifies the root window and
365 nothing else.  Otherwise, @var{root} is a list @code{(@var{dir}
366 @var{edges} @var{w1} @var{w2} ...)} where @var{dir} is @code{nil} for a
367 horizontal combination, and @code{t} for a vertical combination,
368 @var{edges} gives the size and position of the combination, and the
369 remaining elements are the child windows.  Each child window may again
370 be a live window or a list representing a window combination, and so on.
371 The @var{edges} element is a list @code{(@var{left}@var{ top}@var{
372 right}@var{ bottom})} similar to the value returned by
373 @code{window-edges}, see @ref{Coordinates and Windows}.
374 @end defun
377 @node Window Sizes
378 @section Window Sizes
379 @cindex window size
380 @cindex size of window
382 Emacs windows are rectangular.  The structure of a live window can be
383 roughly sketched as follows:
385 @smallexample
386 @group
387          _________________________________________ 
388       ^ |______________ Header Line_______________| 
389       | |LS|LF|LM|                       |RM|RF|RS| ^
390       | |  |  |  |                       |  |  |  | |
391  Window |  |  |  |       Text Area       |  |  |  | Window
392  Total  |  |  |  |     (Window Body)     |  |  |  | Body
393  Height |  |  |  |                       |  |  |  | Height
394       | |  |  |  |<- Window Body Width ->|  |  |  | |
395       | |__|__|__|_______________________|__|__|__| v
396       v |_______________ Mode Line _______________|
398          <----------- Window Total Width -------->
400 @end group
401 @end smallexample
403 @cindex window body
404 @cindex body of a window
405 The text area constitutes the body of the window.  In its most simple
406 form, a window consists of its body alone.  LS and RS stand for the left
407 and right scroll bar (@pxref{Scroll Bars}) respectively.  Only one of
408 them can be present at any time.  LF and RF denote the left and right
409 fringe, see @ref{Fringes}.  LM and RM, finally, stand for the left and
410 right display margin, see @ref{Display Margins}.  The header line, if
411 present, is located above theses areas, the mode line below, see
412 @ref{Mode Line Format}.
414 @cindex window height
415 @cindex total window height
416 @cindex height of a window
417 @cindex total height of a window
418 The @dfn{total height of a window} is specified as the total number of
419 lines occupied by the window.  Any mode or header line is included in a
420 window's total height.  For an internal window, the total height is
421 calculated recursively from the total heights of its child windows.
423 @cindex window width
424 @cindex total window width
425 @cindex width of a window
426 @cindex total width of a window
427 The @dfn{total width of a window} denotes the total number of columns of
428 the window.  Any scroll bar and the column of @samp{|} characters that
429 separate the window from its right sibling are included in a window's
430 total width.  On a window-system, fringes and display margins are
431 included in a window's total width too.  For an internal window, the
432 total width is calculated recursively from the total widths of its child
433 windows.
435 @cindex total size of a window
436 @cindex total window size
437 The following function is the standard interface for getting the total
438 size of any window:
440 @defun window-total-size &optional window &optional horizontal
441 This function returns the total number of lines of @var{window}.  The
442 argument @var{window} can denote any window and defaults to the selected
443 one.  If @var{window} is live, the return value includes any header or
444 mode lines of @var{window}.  If @var{window} is internal, the return
445 value is the sum of the total heights of @var{window}'s child windows
446 provided these are vertically combined and the height of @var{window}'s
447 first child if they are horizontally combined.
449    If the optional argument @var{horizontal} is non-@code{nil}, this
450 function returns the total number of columns of @var{window}.  If
451 @var{window} is live, the return value includes any vertical divider
452 column or scroll bars of @var{window}.  On a window-system, the return
453 value includes the space occupied by any margins and fringes of
454 @var{window} too.  If @var{window} is internal, the return value is the
455 sum of the total widths of @var{window}'s child windows provided these
456 are horizontally combined and the width of @var{window}'s first child
457 otherwise.
458 @end defun
460 Alternatively, the following two functions can be used to retrieve
461 either the total height or the total width of a window:
463 @defun window-total-height &optional window
464 This function returns the total number of lines of @var{window}.
465 @var{window} can be any window and defaults to the selected one.  The
466 return value includes @var{window}'s mode line and header line, if any.
467 If @var{window} is internal the return value is the sum of heights of
468 @var{window}'s child windows for a vertical combination and the height
469 of @var{window}'s first child otherwise.
470 @end defun
472 @defun window-total-width &optional window
473 This function returns the total number of columns of @var{window}.
474 @var{window} can be any window and defaults to the selected one.  The
475 return value includes any vertical dividers or scrollbars of
476 @var{window}.  On a window-system the return value also includes the
477 space occupied by any margins and fringes of @var{window}.  If
478 @var{window} is internal, the return value is the sum of the widths of
479 @var{window}'s child windows for a horizontal combination and the width
480 of @var{window}'s first child otherwise.
481 @end defun
483 The total height of any window is usually less than the height of the
484 window's frame, because the latter may also include the minibuffer
485 window.  Depending on the toolkit in use, the frame height can also
486 include the menu bar and the tool bar (@pxref{Size and Position}).
487 Therefore, in general it is not straightforward to compare window and
488 frame heights.  The following function is useful to determine whether
489 there are no other windows above or below a specified window.
491 @cindex full-height window
492 @defun window-full-height-p &optional window
493 This function returns non-@code{nil} if there is no other window above
494 or below @var{window} on the containing frame.  More precisely, this
495 function returns @code{t} if and only if the total height of
496 @var{window} equals the total height of the root window (@pxref{Windows
497 and Frames}) of @var{window}'s frame.  The @var{window} argument may
498 denote any window and defaults to the selected one.
499 @end defun
501 @cindex full-width window
502 The following function can be used to determine whether there are no
503 other windows on the left or right of a specified window.
505 @defun window-full-width-p &optional window
506 This function returns non-@code{nil} if there are no other windows on
507 the left or right of @var{window}; @code{nil} otherwise.  More
508 precisely, this function returns @code{t} if and only if the total width
509 of @var{window} equals the total width of the root window
510 (@pxref{Windows and Frames}) of @var{window}'s frame.  The @var{window}
511 argument may denote any window and defaults to the selected one.
512 @end defun
514 @cindex top line of window
515 @cindex left column of window
516   The windows of a frame are unambiguously characterized by the
517 combination of their top line and left column within that frame.
519 @defun window-top-line &optional window
520 This function returns the top line of @var{window}.  The argument
521 @var{window} can denote any window and defaults to the selected one.
522 @end defun
524 @defun window-left-column &optional window
525 This function returns the left column of @var{window}.  The argument
526 @var{window} can denote any window and defaults to the selected one.
527 @end defun
529 For a frame displaying one window only, that window's top line and left
530 column are both zero.  When a frame displays a window @var{WB} below a
531 window @var{WA}, the top line of @var{WB} can be calculated by adding
532 the total height of @var{WA} to the top line of @var{WA}.  When a frame
533 displays a window @var{WR} on the right of a window @var{WL}, the left
534 column of @var{WR} can be calculated by adding the total width of
535 @var{WL} to the left column of @var{WL}.
537 @cindex window body height
538 @cindex body height of a window
539 The @dfn{body height of a window} is specified as the total number of
540 lines occupied by the window's text area.  Mode or header lines are not
541 included in a window's body height.
543 @cindex window body width
544 @cindex body width of a window
545 The @dfn{body width of a window} denotes the total number of columns
546 occupied by the window's text area.  Scroll bars or columns of @samp{|}
547 characters that separate side-by-side windows are not included in a
548 window's body width.
550 @cindex body size of a window
551 @cindex window body size
552 The following functions retrieve height and width of the body of a live
553 window:
555 @defun window-body-size &optional window horizontal
556 This function returns the number of lines of @var{window}'s text area.
557 @var{window} must be a live window and defaults to the selected one.
558 The return value does not count any mode or header line of @var{window}.
560 Optional argument @var{horizontal} non-@code{nil} means to return the
561 number of columns of @var{window}'s text area.  In this case the return
562 value does not include any vertical divider or scroll bar owned by
563 @var{window}.  On a window-system the return value does not include the
564 number of columns used for @var{window}'s fringes or display margins
565 either.
566 @end defun
568 @defun window-body-height &optional window
569 This function returns the number of lines of @var{window}'s body.
570 @var{window} must be a live window and defaults to the selected one.
572 The return value does not include @var{window}'s mode line and header
573 line, if any.  If a line at the bottom of the window is only partially
574 visible, that line is included in the return value.  If you do not
575 want to include a partially visible bottom line in the return value,
576 use @code{window-text-height} instead.
577 @end defun
579 @defun window-body-width &optional window
580 This function returns the number of columns of @var{window}'s body.
581 @var{window} must be a live window and defaults to the selected one.
583 The return value does not include any vertical dividers or scroll bars
584 owned by @var{window}.  On a window-system the return value does not
585 include the number of columns used for @var{window}'s fringes or
586 display margins either.
587 @end defun
589 The following functions have been used in earlier versions of Emacs.
590 They are still supported but due to the confusing nomenclature they
591 should not be used any more in future code.
593 @defun window-height &optional window
594 This function is an alias for `window-total-height', see above.
595 @end defun
597 @defun window-width &optional window
598 This function is an alias for `window-body-width', see above.
599 @end defun
601 @cindex minimum window size
602   The following two options constrain the sizes of windows to a minimum
603 height and width.  Their values are honored when windows are split
604 (@pxref{Splitting Windows}) or resized (@pxref{Resizing Windows}).  Any
605 request to make a window smaller than specified here will usually result
606 in an error.
608 @defopt window-min-height
609 The value of this variable specifies how short a window may be.  The
610 value is measured in line units and has to account for any header or
611 mode line.  The default value for this option is @code{4}.  Values less
612 than @code{1} are ignored.
613 @end defopt
615 @defopt window-min-width
616 The value of this variable specifies how narrow a window may be.  The
617 value is measured in characters and includes any margins, fringes,
618 scroll bar and vertical divider column.  The default value for this
619 option is @code{10}.  A value less than @code{2} is ignored.
620 @end defopt
622 Applications should not rebind these variables.  To shrink a specific
623 window to a height or width less than the one specified here, they
624 should rather invoke @code{resize-window} (@pxref{Resizing Windows})
625 with a non-@code{nil} @var{ignore} argument.  The function
626 @code{split-window} (@pxref{Splitting Windows}) can make a window
627 smaller than specified here by calling it with a non-@code{nil}
628 @var{size} argument.  Interactively, the values specified here cannot be
629 overridden.
631    Earlier versions of Emacs could delete a window when its size dropped
632 below @code{window-min-height} or @code{window-min-width}.  As a rule,
633 the current version of Emacs does no more delete windows by side-effect.
634 The only exception to this rule are requests to resize a frame which may
635 implicitly delete windows when they do not fit on the frame any more,
636 see @ref{Size and Position}.
638    The size of a window can be fixed which means that it cannot be split
639 (@pxref{Splitting Windows}) or resized (@pxref{Resizing Windows}).
641 @cindex fixed-size window
642 @defvar window-size-fixed
643 If this variable is non-@code{nil}, in a given buffer, then the size of
644 any window displaying that buffer remains fixed unless you either
645 explicitly change it or Emacs has no other choice.
647 If the value is @code{height}, then only the window's height is fixed;
648 if the value is @code{width}, then only the window's width is fixed.
649 Any other non-@code{nil} value fixes both the width and the height.
651 This variable automatically becomes buffer-local when set.
652 @end defvar
654 Commands supposed to explicitly change the size of windows such as
655 @code{enlarge-window} (@pxref{Resizing Windows}) get an error if they
656 had to change a window size which is fixed.  Other functions like
657 @code{resize-window} (@pxref{Resizing Windows}) have an optional
658 @var{ignore} argument which allows to change the size of fixed-size
659 windows.
661    Deleting a window or changing a frame's size may change the size of a
662 fixed-size window, if there is no other alternative.
664    A vertical combination of windows cannot be resized when the height
665 of all windows in that combination is fixed.  A horizontal combination
666 cannot be resized when the width of all windows in it is fixed.  The
667 next function allows to check whether the size of an arbitrary window is
668 fixed.
670 @defun window-size-fixed-p &optional window horizontal
671 This function returns non-@code{nil} if @var{window}'s height is fixed.
672 The argument @var{window} can be an arbitrary window and defaults to the
673 selected one.  Optional argument @var{horizontal} non-@code{nil} means
674 return non-@code{nil} if @var{window}'s width is fixed.
676 If this function returns @code{nil}, this does not necessarily mean that
677 @var{window} can be resized in the desired direction.  The function
678 @code{window-resizable} (@pxref{Resizing Windows}) can tell that.
679 @end defun
682 @node Resizing Windows
683 @section Resizing Windows
684 @cindex window resizing
685 @cindex resize window
686 @cindex changing window size
687 @cindex window size, changing
689 Emacs does not permit overlapping windows or gaps between windows, so
690 changing the size of a window always affects at least one other window.
691 When a frame contains just one window, that window can be resized only
692 by resizing the window's frame.  The functions described below are
693 therefore meaningful only in the context of a frame containing at least
694 two windows.  The size of the corresponding frame never changes when
695 invoking a function described in this section.
697    The routines changing window sizes always operate in one dimension at
698 a time.  This means that windows can be resized only either vertically
699 or horizontally.  If a window shall be resized in both dimensions, it
700 must be resized in one dimension first and in the other dimension
701 afterwards.  If the second resize operation fails, the frame might end
702 up in an unsatisfactory state.  To avoid such states, it might be useful
703 to save the current window configuration (@pxref{Window Configurations})
704 before attempting the first resize operation and restore the saved
705 configuration in case the second resize operation fails.
707    Functions that resize windows are supposed to obey restrictions
708 imposed by window minimum sizes and fixed-size windows, see @ref{Window
709 Sizes}.  In order to determine whether resizing a specific window is
710 possible in the first place, the following function can be used:
712 @defun window-resizable window delta &optional horizontal ignore side noup nodown
713 This function returns @var{delta} if the size of @var{window} can be
714 changed vertically by @var{delta} lines.  Optional argument
715 @var{horizontal} non-@code{nil} means to return @var{delta} if
716 @var{window} can be resized horizontally by @var{delta} columns.  A
717 return value of zero means that @var{window} is not resizable.
719 If @var{delta} is a positive number, this means that @var{window} shall
720 be enlarged by @var{delta} lines or columns.  If @var{window} cannot be
721 enlarged by @var{delta} lines or columns, this function returns the
722 maximum value in the range from 0 to @var{delta} by which @var{window}
723 can be enlarged.
725 If @var{delta} is a negative number, this means that @var{window} shall
726 be shrunk by -@var{delta} lines or columns.  If @var{window} cannot be
727 shrunk by -@var{delta} lines or columns, this function returns the
728 minimum value in the range from @var{delta} to 0 that can be used for
729 shrinking @var{window}.
731 Optional argument @var{ignore} non-@code{nil} means ignore any
732 restrictions imposed by the variables @code{window-min-height} or
733 @code{window-min-width} and @code{window-size-fixed}.  In this case the
734 minimum height of a window is specified as the minimum number of lines
735 that allow viewing any header or mode line and at least one line of the
736 text area of window.  The minimum width of a window includes any
737 fringes, margins and the scroll bar as well as two text columns.
739 If @var{ignore} denotes a window, this means to ignore restrictions for
740 that window only.  If @var{ignore} equals the constant @code{safe}, this
741 means a live window may get as small as one line or two columns.
743 Optional argument @var{noup} non-@code{nil} means don't go up in the
744 window tree but try to steal or distribute the space needed for the
745 resize operation among the other windows within @var{window}'s
746 combination.  Optional argument @var{nodown} non-@code{nil} means don't
747 check whether @var{window} itself and its subwindows can be resized.
748 @end defun
750 The function @code{window-resizable} does not change any window sizes.
751 The following function does:
753 @defun resize-window window delta &optional horizontal ignore
754 This function resizes @var{window} vertically by @var{delta} lines.  The
755 argument @var{window} can denote an arbitrary window and defaults to the
756 selected one.  An attempt to resize the root window of a frame will
757 raise an error.
759 Second argument @var{delta} a positive number means @var{window} shall
760 be enlarged by @var{delta} lines.  If @var{delta} is negative, that
761 means @var{window} shall be shrunk by -@var{delta} lines.
763 Optional argument @var{horizontal} non-@code{nil} means to resize
764 @var{window} horizontally by @var{delta} columns.  In this case a
765 positive @var{delta} means enlarge @var{window} by @var{delta} columns.
766 A negative @var{delta} means @var{window} shall be shrunk by
767 -@var{delta} columns.
769 Optional argument @var{ignore} has the same meaning as for the function
770 @code{window-resizable} above.
772 This function can simultaneously move two edges of WINDOW.  Exactly
773 which edges of @var{window} are moved and which other windows are
774 resized along with @var{window} is determined by the splits and nest
775 status of the involved windows (@pxref{Splitting Windows}).  If only the
776 low (right) edge of @var{window} shall be moved, the function
777 @code{adjust-window-trailing-edge} described below should be used.
778 @end defun
780 The next four commands are simple interfaces to @code{resize-window}.
781 They always operate on the selected window, never delete any window, and
782 always raise an error when resizing would violate a restriction imposed
783 by @code{window-min-height}, @code{window-min-width}, or
784 @code{window-size-fixed}.
786 @deffn Command enlarge-window delta &optional horizontal
787 This function makes the selected window @var{delta} lines taller.
788 Interactively, if no argument is given, it makes the selected window one
789 line taller.  If optional argument @var{horizontal} is non-@code{nil},
790 it makes the selected window wider by @var{delta} columns.  If
791 @var{delta} is negative, it shrinks the selected window by -@var{delta}
792 lines or columns.  The return value is @code{nil}.
793 @end deffn
795 @deffn Command enlarge-window-horizontally delta
796 This function makes the selected window @var{delta} columns wider.
797 Interactively, if no argument is given, it makes the selected window one
798 column wider.
799 @end deffn
801 @deffn Command shrink-window delta &optional horizontal
802 This function makes the selected window @var{delta} lines smaller.
803 Interactively, if no argument is given, it makes the selected window one
804 line smaller.  If optional argument @var{horizontal} is non-@code{nil},
805 it makes the selected window narrower by @var{delta} columns.  If
806 @var{delta} is negative, it enlarges the selected window by -@var{delta}
807 lines or columns.  The return value is @code{nil}.
808 @end deffn
810 @deffn Command shrink-window-horizontally delta
811 This function makes the selected window @var{delta} columns narrower.
812 Interactively, if no argument is given, it makes the selected window one
813 column narrower.
814 @end deffn
816 @defun adjust-window-trailing-edge window delta &optional horizontal
817 This function moves @var{window}'s bottom edge by @var{delta} lines.
818 Optional argument @var{horizontal} non-@code{nil} means to move
819 @var{window}'s right edge by @var{delta} columns.  The argument
820 @var{window} defaults to the selected window.
822 If @var{delta} is greater zero, this moves the edge downwards or to the
823 right.  If @var{delta} is less than zero, this moves the edge upwards or
824 to the left. If the edge can't be moved by @var{delta} lines or columns,
825 it is moved as far as possible in the desired direction but no error is
826 signalled.
828 This function tries to resize windows adjacent to the edge that is
829 moved.  Only if this is insufficient, it will also resize windows not
830 adjacent to that edge.  As a consequence, if you move an edge in one
831 direction and back in the other direction by the same amount, the
832 resulting window configuration will not be necessarily identical to the
833 one before the first move.  So if your intend to just resize
834 @var{window}, you should not use this function but call
835 @code{resize-window} (see above) instead.
836 @end defun
838 @deffn Command fit-window-to-buffer &optional window max-height min-height override
839 This command makes @var{window} the right height to display its
840 contents exactly.  The default for @var{window} is the selected window.
842 The optional argument @var{max-height} specifies the maximum total
843 height the window is allowed to be; @code{nil} means use the maximum
844 permissible height of a window on @var{window}'s frame.  The optional
845 argument @var{min-height} specifies the minimum toatl height for the
846 window; @code{nil} means use @code{window-min-height}.  All these height
847 values include the mode line and/or header line.
849 If the optional argument @var{override} is non-@code{nil}, this means to
850 ignore any restrictions imposed by @code{window-min-height} and
851 @code{window-min-width} on the size of @var{window}.
853 This function returns non-@code{nil} if it orderly resized @var{window},
854 and @code{nil} otherwise.
855 @end deffn
857 @deffn Command shrink-window-if-larger-than-buffer &optional window
858 This command shrinks @var{window} vertically to be as small as possible
859 while still showing the full contents of its buffer---but not less than
860 @code{window-min-height} lines.  The argument @var{window} must denote
861 a live window and defaults to the selected one.
863 However, this command does nothing if the window is already too small to
864 display the whole text of the buffer, or if part of the contents are
865 currently scrolled off screen, or if the window is not the full width of
866 its frame, or if the window is the only window in its frame.
868 This command returns non-@code{nil} if it actually shrank the window
869 and @code{nil} otherwise.
870 @end deffn
872 @cindex balancing window sizes
873 Emacs provides two functions to balance windows, that is, to even out
874 the sizes of all windows on the same frame.  The minibuffer window and
875 fixed-size windows are not resized by these functions.
877 @deffn Command balance-windows &optional window-or-frame
878 This function balances windows in a way that gives more space to
879 full-width and/or full-height windows.  If @var{window-or-frame}
880 specifies a frame, it balances all windows on that frame.  If
881 @var{window-or-frame} specifies a window, it balances that window and
882 its siblings (@pxref{Windows and Frames}) only.
883 @end deffn
885 @deffn Command balance-windows-area
886 This function attempts to give all windows on the selected frame
887 approximately the same share of the screen area.  This means that
888 full-width or full-height windows are not given more space than other
889 windows.
890 @end deffn
892 @cindex maximizing windows
893 The following function can be used to give a window the maximum possible
894 size without deleting other ones.
896 @deffn Command maximize-window &optional window
897 This function maximizes @var{window}.  More precisely, this makes
898 @var{window} as large as possible without resizing its frame or deleting
899 other windows.  @var{window} can be any window and defaults to the
900 selected one.
901 @end deffn
903 @cindex minimizing windows
904 To make a window as small as possible without deleting it the
905 following function can be used.
907 @deffn Command minimize-window &optional window
908 This function minimizes @var{window}.  More precisely, this makes
909 @var{window} as small as possible without deleting it or resizing its
910 frame.  @var{window} can be any window and defaults to the selected one.
911 @end deffn
914 @node Splitting Windows
915 @section Splitting Windows
916 @cindex splitting windows
917 @cindex window splitting
919 The functions described below are the primitives needed for creating a
920 new window.  They do not accept a buffer as an argument.  Rather, they
921 ``split'' an existing window into two halves, both displaying the buffer
922 previously visible in the window that was split.
924 @deffn Command split-window &optional window size side
925 This function creates a new window adjacent to @var{window}.  It returns
926 the new window which is always a live window.  The argument @var{window}
927 can denote any window and defaults to the selected one.  This function
928 does not change the selected window.
930 Optional second argument @var{size} a positive number means make
931 @var{window} @var{size} lines (or columns) tall.  If @var{size} is
932 negative, make the new window @minus{}@var{size} lines (or columns)
933 tall.  If @var{size} is omitted or @code{nil}, then @var{window} is
934 divided evenly into two parts.  (If there is an odd line, it is
935 allocated to the new window.)
937 If splitting would result in making a window smaller than
938 @code{window-min-height} or @code{window-min-width} (@pxref{Window
939 Sizes}), this function usually signals an error.  However, if @var{size}
940 is non-@code{nil} and valid, a new window of the requested size is
941 created.  (A size value would be invalid if it assigned less than one
942 line or less than two columns to the new window.)
944 Optional third argument @var{side} @code{nil} (or @code{below})
945 specifies that the new window shall be located below @var{window}.  The
946 value @code{above} means the new window will be located above
947 @var{window}.  In both cases @var{size} specifies the new number of
948 lines for @var{window} (or the new window if @var{size} is negative)
949 including space reserved for the mode and/or header line.
951 If @var{side} is @code{t} or @code{right} the new window will be
952 positioned on the right side of @var{window}.  The value @code{left}
953 means the new window will be located on the left side of @var{window}.
954 In both cases @var{size} specifies the new number of columns for
955 @var{window} (or the new window provided @var{size} is negative)
956 including space reserved for margins, fringes and the scroll bar or a
957 divider column.
959 Any other non-@code{nil} value for @var{side} is currently handled like
960 @code{t} (or @code{right}).  Since this might change in the future,
961 application programs should refrain from using other values.
963 If @var{window} is live, properties of the new window like margins and
964 scroll bars are inherited from @var{window}.  If @var{window} is an
965 internal window, these properties, as well as the buffer shown in the
966 new window, are inherited from the window selected on @var{window}'s
967 frame.
969 If @code{ignore-window-parameters} is non-@code{nil}, this function
970 ignores window parameters (@pxref{Window Parameters}).  Otherwise, if
971 the @code{split-window} parameter of @var{window} is @code{t}, it splits
972 the window disregarding any other window parameters.  If the
973 @code{split-window} parameter specifies a function, that function is
974 called with the arguments @var{window}, @var{size}, and @var{side} to
975 split @var{window}.  If that function is @code{ignore}, nothing is done.
977 Otherwise, if @var{window} is a subwindow of an atomic window
978 (@pxref{Atomic Windows}) this function splits the root of the atomic
979 window instead.  The new window does not become a subwindow of the
980 atomic window.  If @var{window} is a non-side window (@pxref{Side
981 Windows}), the new window becomes a non-side window too.  If
982 @var{window} is a side window, the new window becomes a side window too.
983 @end deffn
985 The following example starts with one window on a screen that is 50
986 lines high by 80 columns wide; then it splits the window.
988 @smallexample
989 @group
990 (setq W1 (selected-window))
991      @result{} #<window 8 on windows.texi>
992 (setq W2 (split-window W1 15))
993      @result{} #<window 28 on windows.texi>
994 @end group
995 @group
996 (window-top-line W1)
997      @result{} 0
998 (window-total-size W1)
999      @result{} 15
1000 (window-top-line W2)
1001      @result{} 15
1002 @end group
1003 @end smallexample
1005 The screen looks like this:
1007 @smallexample
1008 @group
1009          __________
1010         |          |  line 0
1011         |    W1    |
1012         |__________|
1013         |          |  line 15
1014         |    W2    |
1015         |__________|
1016                       line 50
1017  column 0   column 80
1018 @end group
1019 @end smallexample
1021 Next, split the top window into two side-by-side windows:
1023 @smallexample
1024 @group
1025 (setq W3 (split-window W1 35 t))
1026      @result{} #<window 32 on windows.texi>
1027 @end group
1028 @group
1029 (window-left-column W1)
1030      @result{} 0
1031 (window-total-size W1 t)
1032      @result{} 35
1033 (window-left-column W3)
1034      @result{} 35
1035 @end group
1036 @end smallexample
1038 @need 3000
1039 Now the screen looks like this:
1041 @smallexample
1042 @group
1043      column 35
1044          __________
1045         |    |     |  line 0
1046         | W1 |  W3 |
1047         |____|_____|
1048         |          |  line 15
1049         |    W2    |
1050         |__________|
1051                       line 50
1052  column 0   column 80
1053 @end group
1054 @end smallexample
1056 Normally, Emacs indicates the border between two side-by-side windows
1057 with a scroll bar (@pxref{Scroll Bars}), or with @samp{|} characters.  The
1058 display table can specify alternative border characters; see @ref{Display
1059 Tables}.
1061 Below we describe how @code{split-window} can be used to create the
1062 window configuration from our earlier example (@pxref{Windows and
1063 Frames}) and how internal windows are created for this purpose.  We
1064 start with a frame containing one leaf window @code{W2} (in the
1065 following scenarios window names are assigned in an arbitrary manner in
1066 order to match the names of the example).  Evaluating the form
1067 @code{(split-window W2 8 t)} creates a new internal window @code{W1}
1068 with two children---@code{W2} (the window we've split) and a new leaf
1069 window @code{W6}:
1070 @smallexample
1071 @group
1072      ______________________________________
1073     | ______  ____________________________ |
1074     ||      ||                            ||
1075     ||      ||                            ||
1076     ||      ||                            ||
1077     ||      ||                            ||
1078     ||      ||                            ||
1079     ||      ||                            ||
1080     ||      ||                            ||
1081     ||      ||                            ||
1082     ||      ||                            ||
1083     ||      ||                            ||
1084     ||__W2__||_____________W6_____________ |
1085     |__________________W1__________________|
1087 @end group
1088 @end smallexample
1090 Evaluating now @code{(split-window W6 -3)} creates another internal
1091 window @code{W3} with two children---@code{W6} and a new leaf window
1092 @code{W5}.  This leaves us with a vertically combined window @code{W3}
1093 embedded in the horizontally combined window @code{W1}:
1094 @smallexample
1095 @group
1096      ______________________________________
1097     | ______  ____________________________ |
1098     ||      || __________________________ ||
1099     ||      |||                          |||
1100     ||      |||                          |||
1101     ||      |||                          |||
1102     ||      |||                          |||
1103     ||      |||                          |||
1104     ||      |||____________W6____________|||
1105     ||      || __________________________ ||
1106     ||      |||                          |||
1107     ||      |||____________W5____________|||
1108     ||__W2__||_____________W3_____________ |
1109     |__________________W1__________________|
1111 @end group
1112 @end smallexample
1114 Finally, evaluating @code{(split-window W6 nil t)} should get us the
1115 desired configuration as depicted below.
1116 @smallexample
1117 @group
1118      ______________________________________
1119     | ______  ____________________________ |
1120     ||      || __________________________ ||
1121     ||      ||| ___________  ___________ |||
1122     ||      ||||           ||           ||||
1123     ||      ||||           ||           ||||
1124     ||      ||||_____W6____||_____W7____||||
1125     ||      |||____________W4____________|||
1126     ||      || __________________________ ||
1127     ||      |||                          |||
1128     ||      |||____________W5____________|||
1129     ||__W2__||_____________W3_____________ |
1130     |__________________W1__________________|
1132 @end group
1133 @end smallexample
1135 The scenario sketched above is the standard way to obtain the desired
1136 configuration.  In Emacs 23 it was also the only way to do that since
1137 Emacs 23 did't allow splitting internal windows.
1139 With Emacs 24 you can also proceed as follows: Split an initial window
1140 @code{W6} by evaluating @code{(split-window W6 -3)} to produce the
1141 following vertical combination:
1142 @smallexample
1143 @group
1144      ______________________________________
1145     | ____________________________________ |
1146     ||                                    ||
1147     ||                                    ||
1148     ||                                    ||
1149     ||                                    ||
1150     ||                                    ||
1151     ||                                    ||
1152     ||                                    ||
1153     ||_________________W6_________________||
1154     | ____________________________________ |
1155     ||                                    ||
1156     ||_________________W5_________________||
1157     |__________________W3__________________|
1159 @end group
1160 @end smallexample
1162 Evaluating now @code{(split-window (window-parent W6) -8 'left)} or,
1163 equivalently, @code{(split-window W3 -8 'left)} should now produce the
1164 penultimate configuration from the previous scenario from where we can
1165 continue as described before.
1167    Another strategy starts with splitting an inital window @code{W6} by
1168 evaluating @code{(split-window W6 nil nil t)} with the following result:
1169 @smallexample
1170 @group
1171      ______________________________________
1172     | _________________  _________________ |
1173     ||                 ||                 ||
1174     ||                 ||                 ||
1175     ||                 ||                 ||
1176     ||                 ||                 ||
1177     ||                 ||                 ||
1178     ||                 ||                 ||
1179     ||                 ||                 ||
1180     ||                 ||                 ||
1181     ||                 ||                 ||
1182     ||                 ||                 ||
1183     ||________W6_______||________W7_______||
1184     |__________________W4__________________|
1186 @end group
1187 @end smallexample
1189 Evaluating now @code{(split-window W4 -3)} or @code{(split-window
1190 (window-parent W6) -3)} should get us a configuration as shown next.
1191 @smallexample
1192 @group
1193      ______________________________________
1194     | ____________________________________ |
1195     || ________________  ________________ ||
1196     |||                ||                |||
1197     |||                ||                |||
1198     |||                ||                |||
1199     |||                ||                |||
1200     |||                ||                |||
1201     |||_______W6_______||________W7______|||
1202     ||_________________W4_________________||
1203     | ____________________________________ |
1204     ||                                    ||
1205     ||_________________W5_________________||
1206     |__________________W3__________________|
1208 @end group
1209 @end smallexample
1211 The desired configuration can be now obtained by evaluating
1212 @code{(split-window W3 -8 'left)} or, equivalently, @code{(split-window
1213 (window-parent W5) -8 'left)}.
1215    For a final approach let's start with the configuration of two live
1216 windows @code{W6} and @code{W7} shown above.  If we now evaluate
1217 @code{(split-window W4 -8 'left)} or @code{(split-window (window-parent
1218 W6) -8 'left)} we get the following configuration.
1219 @smallexample
1220 @group
1221      ______________________________________
1222     | ______  ____________________________ |
1223     ||      || ____________  ____________ ||
1224     ||      |||            ||            |||
1225     ||      |||            ||            |||
1226     ||      |||            ||            |||
1227     ||      |||            ||            |||
1228     ||      |||            ||            |||
1229     ||      |||            ||            |||
1230     ||      |||            ||            |||
1231     ||      |||______W6____||______W7____|||
1232     ||__W2__||_____________W4_____________||
1233     |__________________W1__________________|
1235 @end group
1236 @end smallexample
1238 Evaluating now @code{(split-window W4 -3)} or, for example,
1239 @code{(split-window (window-parent W6) -3)} should produce the desired
1240 configuration.
1242   The two options described next can be used to tune the operation of
1243 @code{split-window}.
1245 @defopt window-splits
1246 If this variable is nil, the function @code{split-window} can split a
1247 window if and only if that window's screen estate is sufficiently large
1248 to accomodate both--itself and the new window.
1250 If this variable is non-@code{nil}, @code{split-window} tries to resize
1251 all windows that are part of the same combination as the old window to
1252 accomodate the new window.  Hence, the new window can be also created if
1253 the old window is of fixed size or too small to split (@pxref{Window
1254 Sizes}).
1256 In any case, the value of this variable is assigned to the splits status
1257 of the new window and, provided old and new window form a new
1258 combination, of the old window as well.  The splits status of a window
1259 can be retrieved by invoking the function @code{window-splits} and
1260 altered by the function @code{set-window-splits} described next.
1262 If @code{window-nest} (see below) is non-@code{nil}, the space for the
1263 new window is exclusively taken from the old window, but the splits
1264 status of the involved windows is nevertheless set as described here.
1265 @end defopt
1267 @defun window-splits &optional window
1268 This function returns the splits status of @var{window}.  The argument
1269 @var{window} can be any window and defaults to the selected one.
1271 @cindex splits status
1272 The @dfn{splits status} of a window specifies how resizing and deleting
1273 that window may affect the size of other windows in the same window
1274 combination.  More precisely, if @var{window}'s splits status is
1275 @code{nil} and @var{window} is resized, the corresponding space is
1276 preferably taken from (or given to) @var{window}'s right sibling.  When
1277 @var{window} is deleted, its space is given to its left sibling.  If
1278 @var{window}'s splits status is non-@code{nil}, resizing and deleting
1279 @var{window} may resize @emph{all} windows in @var{window}'s
1280 combination.
1282 The splits status is initially set by @code{split-window}
1283 from the current value of the variable @code{window-splits} (see above)
1284 and can be reset by the function @code{set-window-splits} (see below).
1285 @end defun
1287 @defun set-window-splits window &optional status
1288 This function sets the splits status (see above) of @var{window} to
1289 @var{status}.  The argument @var{window} can be any window and defaults
1290 to the selected one.  The return value is @var{status}.
1291 @end defun
1293 To illustrate the use of @code{window-splits} consider the following
1294 window configuration:
1295 @smallexample
1296 @group
1297      ______________________________________
1298     | ____________________________________ |
1299     ||                                    ||
1300     ||                                    ||
1301     ||                                    ||
1302     ||                                    ||
1303     ||_________________W2_________________||
1304     | ____________________________________ |
1305     ||                                    ||
1306     ||                                    ||
1307     ||                                    ||
1308     ||                                    ||
1309     ||_________________W3_________________||
1310     |__________________W1__________________|
1312 @end group
1313 @end smallexample
1315 Splitting window @code{W3} with @code{window-splits} @code{nil}
1316 produces a configuration where the size of @code{W2} remains unchanged:
1317 @smallexample
1318 @group
1319      ______________________________________
1320     | ____________________________________ |
1321     ||                                    ||
1322     ||                                    ||
1323     ||                                    ||
1324     ||                                    ||
1325     ||_________________W2_________________||
1326     | ____________________________________ |
1327     ||                                    ||
1328     ||_________________W3_________________||
1329     | ____________________________________ |
1330     ||                                    ||
1331     ||_________________W4_________________||
1332     |__________________W1__________________|
1334 @end group
1335 @end smallexample
1337 Splitting @code{W3} with @code{window-splits} non-@code{nil} instead
1338 produces a configuration where all windows have approximately the same
1339 height:
1341 @smallexample
1342 @group
1343      ______________________________________
1344     | ____________________________________ |
1345     ||                                    ||
1346     ||                                    ||
1347     ||_________________W2_________________||
1348     | ____________________________________ |
1349     ||                                    ||
1350     ||                                    ||
1351     ||_________________W3_________________||
1352     | ____________________________________ |
1353     ||                                    ||
1354     ||                                    ||
1355     ||_________________W4_________________||
1356     |__________________W1__________________|
1358 @end group
1359 @end smallexample
1361 @defopt window-nest
1362 If this variable is @code{nil}, @code{split-window} creates a new parent
1363 window if and only if the old window has no parent window or shall be
1364 split orthogonally to the combination it is part of.  If this variable
1365 is non-@code{nil}, @code{split-window} always creates a new parent
1366 window.  If this variable is always non-@code{nil}, a frame's window
1367 tree is a binary tree so every window but the frame's root window has
1368 exactly one sibling.
1370 The value of this variable is also assigned to the nest status of the
1371 new parent window.  The nest status of any window can be retrieved via
1372 the function @code{window-nest} and altered by the function
1373 @code{set-window-nest}, see below.
1374 @end defopt
1376 @defun window-nest &optional window
1377 This function returns the nest status of @var{window}.  The argument
1378 @var{window} can be any window and defaults to the selected one.  Note,
1379 however, that the nest status is currently meaningful for internal
1380 windows only.
1382 @cindex nest status
1383 The @dfn{nest status} of a window specifies whether that window may be
1384 removed and its subwindows recombined with that window's siblings when
1385 such a sibling's subwindow is deleted.  The nest status is initially
1386 assigned by @code{split-window} from the current value of the variable
1387 @code{window-nest} (see above) and can be reset by the function
1388 @code{set-window-nest} (see below).
1390 If the return value is @code{nil}, subwindows of @var{window} may be
1391 recombined with @var{window}'s siblings when a window gets deleted.  A
1392 return value of @code{nil} means that subwindows of @var{window} are
1393 never (re-)combined with @var{window}'s siblings in such a case.
1394 @end defun
1396 @defun set-window-nest window &optional status
1397 This functions sets the nest status (see above) of @var{window} to
1398 @var{status}.  The argument @var{window} can be any window and defaults
1399 to the selected one.  Note that setting the nest status is meaningful
1400 for internal windows only.  The return value is @var{status}.
1401 @end defun
1403 To illustrate the use of @code{window-nest} consider the following
1404 configuration (throughout the following examples we shall assume that
1405 @code{window-splits} invariantly is @code{nil}).
1406 @smallexample
1407 @group
1408      ______________________________________
1409     | ____________________________________ |
1410     ||                                    ||
1411     ||                                    ||
1412     ||                                    ||
1413     ||                                    ||
1414     ||                                    ||
1415     ||                                    ||
1416     ||_________________W2_________________||
1417     | ____________________________________ |
1418     ||                                    ||
1419     ||                                    ||
1420     ||_________________W3_________________||
1421     |__________________W1__________________|
1423 @end group
1424 @end smallexample
1426 Splitting @code{W2} into two windows above each other with
1427 @code{window-nest} equal @code{nil} will get you a configuration like:
1428 @smallexample
1429 @group
1430      ______________________________________
1431     | ____________________________________ |
1432     ||                                    ||
1433     ||                                    ||
1434     ||_________________W2_________________||
1435     | ____________________________________ |
1436     ||                                    ||
1437     ||                                    ||
1438     ||_________________W4_________________||
1439     | ____________________________________ |
1440     ||                                    ||
1441     ||                                    ||
1442     ||_________________W3_________________||
1443     |__________________W1__________________|
1445 @end group
1446 @end smallexample
1448 If you now enlarge window @code{W4}, Emacs steals the necessary space
1449 from window @code{W3} resulting in a configuration like:
1450 @smallexample
1451 @group
1452      ______________________________________
1453     | ____________________________________ |
1454     ||                                    ||
1455     ||                                    ||
1456     ||_________________W2_________________||
1457     | ____________________________________ |
1458     ||                                    ||
1459     ||                                    ||
1460     ||                                    ||
1461     ||_________________W4_________________||
1462     | ____________________________________ |
1463     ||                                    ||
1464     ||_________________W3_________________||
1465     |__________________W1__________________|
1467 @end group
1468 @end smallexample
1470 Deleting window @code{W4}, will return its space to @code{W2} as
1471 follows:
1472 @smallexample
1473 @group
1474      ______________________________________
1475     | ____________________________________ |
1476     ||                                    ||
1477     ||                                    ||
1478     ||                                    ||
1479     ||                                    ||
1480     ||                                    ||
1481     ||                                    ||
1482     ||                                    ||
1483     ||_________________W2_________________||
1484     | ____________________________________ |
1485     ||                                    ||
1486     ||_________________W3_________________||
1487     |__________________W1__________________|
1489 @end group
1490 @end smallexample
1492 Hence, with respect to the initial configuration, window @code{W2} has
1493 grown at the expense of window @code{W3}.  If, however, in the initial
1494 configuration you had split @code{W2} with @code{window-nest} bound to
1495 @code{t}, a new internal window @code{W5} would have been created as
1496 depicted below.
1497 @smallexample
1498 @group
1499      ______________________________________
1500     | ____________________________________ |
1501     || __________________________________ ||
1502     |||                                  |||
1503     |||________________W2________________|||
1504     || __________________________________ ||
1505     |||                                  |||
1506     |||________________W4________________|||
1507     ||_________________W5_________________||
1508     | ____________________________________ |
1509     ||                                    ||
1510     ||                                    ||
1511     ||_________________W3_________________||
1512     |__________________W1__________________|
1514 @end group
1515 @end smallexample
1517 Enlarging @code{W4} would now have stolen the necessary space from
1518 @code{W2} instead of @code{W3} as
1519 @smallexample
1520 @group
1521      ______________________________________
1522     | ____________________________________ |
1523     || __________________________________ ||
1524     |||________________W2________________|||
1525     || __________________________________ ||
1526     |||                                  |||
1527     |||                                  |||
1528     |||________________W4________________|||
1529     ||_________________W5_________________||
1530     | ____________________________________ |
1531     ||                                    ||
1532     ||                                    ||
1533     ||_________________W3_________________||
1534     |__________________W1__________________|
1536 @end group
1537 @end smallexample
1539 and the subsequent deletion of @code{W4} would have restored the initial
1540 configuration.
1542 For interactive use, Emacs provides two commands which always split the
1543 selected window.
1545 @deffn Command split-window-above-each-other &optional size
1546 This function splits the selected window into two windows, one above the
1547 other, leaving the upper of the two windows selected, with @var{size}
1548 lines.  (If @var{size} is negative, then the lower of the two windows
1549 gets @minus{}@var{size} lines and the upper window gets the rest, but
1550 the upper window is still the one selected.)  However, if
1551 @code{split-window-keep-point} (see below) is @code{nil}, then either
1552 window can be selected.
1554    In other respects, this function is similar to @code{split-window}.
1555 In particular, the upper window is the original one and the return value
1556 is the new, lower window.
1557 @end deffn
1559 @defopt split-window-keep-point
1560 If this variable is non-@code{nil} (the default), then
1561 @code{split-window-above-each-other} behaves as described above.
1563    If it is @code{nil}, then @code{split-window-above-each-other}
1564 adjusts point in each of the two windows to avoid scrolling.  (This is
1565 useful on slow terminals.)  It selects whichever window contains the
1566 screen line that point was previously on.  Other functions are not
1567 affected by this variable.
1568 @end defopt
1570 @deffn Command split-window-side-by-side &optional size
1571 This function splits the selected window into two windows
1572 side-by-side, leaving the selected window on the left with @var{size}
1573 columns.  If @var{size} is negative, the rightmost window gets
1574 @minus{}@var{size} columns, but the leftmost window still remains
1575 selected.
1576 @end deffn
1579 @node Deleting Windows
1580 @section Deleting Windows
1581 @cindex deleting windows
1583 A window remains visible on its frame unless you @dfn{delete} it by
1584 calling certain functions that delete windows.  A deleted window cannot
1585 appear on the screen, but continues to exist as a Lisp object until
1586 there are no references to it.  There is no way to cancel the deletion
1587 of a window aside from restoring a saved window configuration
1588 (@pxref{Window Configurations}).  Restoring a window configuration also
1589 deletes any windows that aren't part of that configuration.  Erroneous
1590 information may result from using a deleted window as if it were live.
1592 @deffn Command delete-window &optional window
1593 This function removes @var{window} from display and returns @code{nil}.
1594 The argument @var{window} can denote any window and defaults to the
1595 selected one.  An error is signaled if @var{window} is the only window
1596 on its frame.  Hence @var{window} must have at least one sibling window
1597 (@pxref{Windows and Frames}) in order to get deleted.
1599 If the variable @code{ignore-window-parameters} (@pxref{Window
1600 Parameters}) is non-@code{nil}, this function ignores all parameters of
1601 @var{window}.  Otherwise, if the @code{delete-window} parameter of
1602 @var{window} is @code{t}, it deletes the window disregarding other
1603 window parameters.  If the @code{delete-window} parameter specifies a
1604 function, that function is called with @var{window} as its sole
1605 argument.
1607 Otherwise, if @var{window} is part of an atomic window (@pxref{Atomic
1608 Windows}), this function is called with the root of the atomic window as
1609 its argument.  If that window is the root window of its frame, an error
1610 is signalled.  If @var{window} is the last non-side window on its frame
1611 (@pxref{Side Windows}), this function signals an error too.
1613 If the splits status of @var{window} (@pxref{Splitting Windows}) is
1614 @code{nil}, the space @var{window} took up is given to its left sibling
1615 if such a window exists and to its right sibling otherwise.  If the
1616 splits status of @var{window} is non-@code{nil}, its space is
1617 proportionally distributed among the remaining windows in the same
1618 combination.
1619 @end deffn
1621 @deffn Command delete-other-windows &optional window
1622 This function makes @var{window} fill its frame and returns @code{nil}.
1623 The argument @var{window} can denote an arbitrary window and defaults to
1624 the selected one.
1626 If the variable @code{ignore-window-parameters} (@pxref{Window
1627 Parameters}) is non-@code{nil}, this function ignores all parameters of
1628 @var{window}.  Otherwise, if the @code{delete-other-windows} parameter
1629 of @var{window} equals @code{t}, it deletes all other windows
1630 disregarding any remaining window parameters.  If the
1631 @code{delete-other-windows} parameter of @var{window} specifies a
1632 function, it calls that function with @var{window} as its sole argument.
1634 Otherwise, if @var{window} is part of an atomic window (@pxref{Atomic
1635 Windows}), it calls this function with the root of the atomic window as
1636 its argument.  If @var{window} is a non-side window (@pxref{Side
1637 Windows}), it makes @var{window} the only non-side window on its frame
1638 and leaves side windows alone.  If @var{window} is a side window, this
1639 function signals an error.
1640 @end deffn
1642 @deffn Command delete-windows-on &optional buffer-or-name frame
1643 This function deletes all windows showing @var{buffer-or-name} and
1644 returns nil.  If there are no windows showing @var{buffer-or-name}, it
1645 does nothing.  The optional argument @var{buffer-or-name} may be a
1646 buffer or the name of an existing buffer and defaults to the current
1647 buffer.  Invoking this command on a minibuffer signals an error.
1649 The function @code{delete-windows-on} operates by calling
1650 @code{delete-window} for each window showing @var{buffer-or-name}.  If a
1651 frame has several windows showing different buffers, then those showing
1652 @var{buffer-or-name} are removed, and the other windows expand to fill
1653 the space.
1655 If all windows in some frame are showing @var{buffer-or-name} (including
1656 the case where there is only one window), then that frame winds up with
1657 a single window showing another buffer.  If, however, that last
1658 remaining window is dedicated to the buffer specified by
1659 @var{buffer-or-name} (@pxref{Dedicated Windows}) or that window's
1660 @code{quit-restore} parameter (@pxref{Window Parameters}) is set
1661 appropriately, that window's frame is deleted provided there are other
1662 frames left.
1664 The optional argument @var{frame} specifies which frames to operate on.
1665 This function does not use it in quite the same way as the other
1666 functions which scan all live windows (@pxref{Cyclic Window Ordering});
1667 specifically, the values @code{t} and @code{nil} have the opposite of
1668 their meanings in the other functions.  Here are the full details:
1670 @itemize @bullet
1671 @item @code{nil}
1672 means operate on all frames.
1673 @item @code{t}
1674 means operate on the selected frame.
1675 @item @code{visible}
1676 means operate on all visible frames.
1677 @item @code{0}
1678 means operate on all visible or iconified frames.
1679 @item A frame
1680 means operate on that frame.
1681 @end itemize
1682 @end deffn
1685 @node Selecting Windows
1686 @section Selecting Windows
1687 @cindex selecting a window
1689 @cindex selected window
1690 In each frame, at any time, one and only one window is designated as
1691 @dfn{selected within the frame}.  Also, at any time, one frame is the
1692 selected frame (@pxref{Input Focus}).  The window selected within the
1693 selected frame is the @dfn{selected window}.  The selected window's
1694 buffer is usually the current buffer (except when @code{set-buffer} has
1695 been used); see @ref{Current Buffer}.
1697 @defun selected-window
1698 This function returns the selected window.  This is the window in which
1699 the cursor for selected windows (@pxref{Cursor Parameters}) appears and
1700 to which many commands apply.
1701 @end defun
1703 @defun select-window window &optional norecord
1704 This function makes @var{window} the selected window.  Unless
1705 @var{window} already is the selected window, this also makes
1706 @var{window}'s buffer (@pxref{Buffers and Windows}) the current buffer.
1707 Moreover, the cursor for selected windows will be displayed in
1708 @var{window} after the next redisplay.  This function returns
1709 @var{window}.
1711 Normally, @var{window}'s selected buffer is moved to the front of the
1712 buffer list (@pxref{The Buffer List}) and @var{window} becomes the most
1713 recently selected window.  But if the optional argument @var{norecord}
1714 is non-@code{nil}, the buffer list remains unchanged and @var{window}
1715 does not become the most recently selected one.
1716 @end defun
1718 @cindex most recently selected windows
1719 The sequence of calls to @code{select-window} with a non-@code{nil}
1720 @var{norecord} argument determines an ordering of windows by their
1721 selection time.  The function @code{get-lru-window} can be used to
1722 retrieve the least recently selected live window in this ordering, see
1723 @ref{Cyclic Window Ordering}.
1725 @defmac save-selected-window forms@dots{}
1726 This macro records the selected frame, as well as the selected window
1727 of each frame, executes @var{forms} in sequence, then restores the
1728 earlier selected frame and windows.  It also saves and restores the
1729 current buffer.  It returns the value of the last form in @var{forms}.
1731 This macro does not save or restore anything about the sizes,
1732 arrangement or contents of windows; therefore, if @var{forms} change
1733 them, the change persists.  If the previously selected window of some
1734 frame is no longer live at the time of exit from @var{forms}, that
1735 frame's selected window is left alone.  If the previously selected
1736 window is no longer live, then whatever window is selected at the end of
1737 @var{forms} remains selected.  The current buffer is restored if and
1738 only if it is still live when exiting @var{forms}.
1740 This macro changes neither the ordering of recently selected windows nor
1741 the buffer list.
1742 @end defmac
1744 @defmac with-selected-window window forms@dots{}
1745 This macro selects @var{window}, executes @var{forms} in sequence, then
1746 restores the previously selected window and current buffer.  The ordering
1747 of recently selected windows and the buffer list remain unchanged unless
1748 you deliberately change them within @var{forms}, for example, by calling
1749 @code{select-window} with argument @var{norecord} @code{nil}.
1751 The order of recently selected windows and the buffer list are not
1752 changed by this macro.
1753 @end defmac
1755 @cindex frame selected window
1756 @cindex window selected within frame
1757 Above we explained that at any time, exactly one window on any frame is
1758 selected within the frame.  The significance of this designation is that
1759 selecting the frame also selects this window.  Conversely, selecting a
1760 window for Emacs with @code{select-window} also makes that window
1761 selected within its frame.
1763 @defun frame-selected-window  &optional frame
1764 This function returns the window on @var{frame} that is selected within
1765 @var{frame}.  The optional argument @var{frame} must denote a live frame
1766 and defaults to the selected one.
1767 @end defun
1769 @defun set-frame-selected-window frame window &optional norecord
1770 This function sets the selected window of frame @var{frame} to
1771 @var{window}.  The argument @var{frame} must denote a live frame and
1772 defaults to the selected one.  If @var{frame} is the selected frame,
1773 this also makes @var{window} the selected window.  The argument
1774 @var{window} must denote a live window.  This function returns
1775 @var{window}.
1777 Optional argument @var{norecord} non-@code{nil} means to neither change
1778 the list of most recently selected windows (@pxref{Selecting Windows})
1779 nor the buffer list (@pxref{The Buffer List}).
1780 @end defun
1783 @node Cyclic Window Ordering
1784 @section Cyclic Ordering of Windows
1785 @cindex cyclic ordering of windows
1786 @cindex ordering of windows, cyclic
1787 @cindex window ordering, cyclic
1789 When you use the command @kbd{C-x o} (@code{other-window}) to select
1790 some other window, it moves through live windows in a specific order.
1791 For any given configuration of windows, this order never varies.  It is
1792 called the @dfn{cyclic ordering of windows}.
1794    For a particular frame, this ordering is determined by the window
1795 tree of that frame, see @ref{Windows and Frames}.  More precisely, the
1796 ordering is obtained by a depth-first traversal of the frame's window
1797 tree supplemented, if requested, by the frame's minibuffer window.
1799    If there's just one live frame, the cyclic ordering is the ordering
1800 for that frame.  Otherwise, the cyclic ordering is obtained by appending
1801 the orderings for individual frames in order of the list of all live
1802 frames, @ref{Finding All Frames}.  In any case, the ordering is made
1803 ``cyclic'' by having the last window precede the first window in the
1804 ordering.
1806 @defun next-window &optional window minibuf all-frames
1807 @cindex minibuffer window, and @code{next-window}
1808 This function returns the window following @var{window} in the cyclic
1809 ordering of windows.  The argument @var{window} must specify a live
1810 window and defaults to the selected one.
1812 The optional argument @var{minibuf} specifies whether minibuffer windows
1813 shall be included in the cyclic ordering.  Normally, when @var{minibuf}
1814 is @code{nil}, a minibuffer window is included only if it is currently
1815 ``active''; this matches the behavior of @kbd{C-x o}.  (Note that a
1816 minibuffer window is active as long as its minibuffer is in use; see
1817 @ref{Minibuffers}).
1819 If @var{minibuf} is @code{t}, the cyclic ordering includes all
1820 minibuffer windows.  If @var{minibuf} is neither @code{t} nor
1821 @code{nil}, minibuffer windows are not included even if they are active.
1823 The optional argument @var{all-frames} specifies which frames to
1824 consider.  Here are the possible values and their meanings:
1826 @itemize @bullet
1827 @item @code{nil}
1828 means consider all windows on @var{window}'s frame, plus the minibuffer
1829 window used by that frame even if it lies in some other frame.  If the
1830 minibuffer counts (as determined by @var{minibuf}), then all windows on
1831 all frames that share that minibuffer count too.
1833 @item @code{t}
1834 means consider all windows on all existing frames.
1836 @item @code{visible}
1837 means consider all windows on all visible frames.  (To get useful
1838 results, ensure that @var{window} is on a visible frame.)
1840 @item 0
1841 means consider all windows on all visible or iconified frames.
1843 @item A frame
1844 means consider all windows on that frame.
1846 @item Anything else
1847 means consider the windows on @var{window}'s frame, and no others.
1848 @end itemize
1850 This example assumes there are two windows, both displaying the
1851 buffer @samp{windows.texi}:
1853 @example
1854 @group
1855 (selected-window)
1856      @result{} #<window 56 on windows.texi>
1857 @end group
1858 @group
1859 (next-window (selected-window))
1860      @result{} #<window 52 on windows.texi>
1861 @end group
1862 @group
1863 (next-window (next-window (selected-window)))
1864      @result{} #<window 56 on windows.texi>
1865 @end group
1866 @end example
1867 @end defun
1869 @defun previous-window &optional window minibuf all-frames
1870 This function returns the window preceding @var{window} in the cyclic
1871 ordering of windows.  The other arguments specify which windows to
1872 consider as in @code{next-window}.
1873 @end defun
1875 @deffn Command other-window count &optional all-frames
1876 This function selects another window in the cyclic ordering of windows.
1877 @var{count} specifies the number of windows to skip in the ordering,
1878 starting with the selected window, before making the selection.  If
1879 @var{count} is a positive number, it skips @var{count} windows forwards.
1880 @var{count} negative means skip @minus{}@var{count} windows backwards.
1881 If @var{count} is zero, it does not skip any window, thus re-selecting
1882 the selected window.  In an interactive call, @var{count} is the numeric
1883 prefix argument.
1885 The optional argument @var{all-frames} has the same meaning as in
1886 @code{next-window}, but the @var{minibuf} argument of @code{next-window}
1887 is always effectively @code{nil}.  This function returns @code{nil}.
1889 This function does not select a window that has a non-@code{nil}
1890 @code{no-other-window} window parameter (@pxref{Window Parameters}).
1891 @end deffn
1893 The following function returns a copy of the list of windows in the
1894 cyclic odering.
1896 @defun window-list-1 &optional window &optional minibuf &optional all_frames
1897 This function returns a list of live windows.  The optional arguments
1898 @var{minibuf} and @var{all-frames} specify the set of windows to include
1899 in the list.  See the description of @code{next-window} for details.
1901 The optional argument @var{window} specifies the first window to list
1902 and defaults to the selected window.  If @var{window} is not on the list
1903 of windows returned, some other window will be listed first but no error
1904 is signalled.
1905 @end defun
1907 The functions described below use @code{window-list-1} for generating a
1908 copy of the list of all relevant windows.  Hence, any change of the
1909 window configuration that occurs while one of these functions is
1910 executed is @emph{not} reflected in the list of windows investigated.
1912 @defun walk-windows proc &optional minibuf all-frames
1913 This function cycles through live windows.  It calls the function
1914 @var{proc} once for each window, with the window as its sole argument.
1916 The optional arguments @var{minibuf} and @var{all-frames} specify the
1917 set of windows to include in the walk, see @code{next-window} above.  If
1918 @var{all-frames} specifies a frame, the first window walked is the first
1919 window on that frame as returned by @code{frame-first-window} and not
1920 necessarily the selected window.
1922 If @var{proc} changes the window configuration by splitting or deleting
1923 windows, that change is not reflected in the set of windows walked.
1924 That set is determined entirely by the set of live windows at the time
1925 this function was invoked.
1926 @end defun
1928 The following function allows to determine whether a specific window is
1929 the only live window.
1931 @defun one-window-p &optional no-mini all-frames
1932 This function returns non-@code{nil} if the selected window is the only
1933 window.
1935 The optional argument @var{no-mini}, if non-@code{nil}, means don't
1936 count the minibuffer even if it is active; otherwise, the minibuffer
1937 window is counted when it is active.  The optional argument
1938 @var{all-frames} has the same meaning as for @code{next-window}, see
1939 above.
1940 @end defun
1942 @cindex finding windows
1943   The following functions choose (but do not select) one of the windows
1944 on the screen, offering various criteria for the choice.
1946 @cindex least recently used window
1947 @defun get-lru-window &optional all-frames dedicated
1948 This function returns the window least recently ``used'' (that is,
1949 selected).  If any full-width windows are present, it only considers
1950 these.  The optional argument @var{all-frames} has the same meaning as
1951 in @code{next-window}.
1953 The selected window is returned if it is the only candidate.  A
1954 minibuffer window is never a candidate.  A dedicated window
1955 (@pxref{Dedicated Windows}) is never a candidate unless the optional
1956 argument @var{dedicated} is non-@code{nil}.
1957 @end defun
1959 @cindex largest window
1960 @defun get-largest-window &optional all-frames dedicated
1961 This function returns the window with the largest area (height times
1962 width).  If there are no side-by-side windows, then this is the window
1963 with the most lines.  A minibuffer window is never a candidate.  A
1964 dedicated window (@pxref{Dedicated Windows}) is never a candidate unless
1965 the optional argument @var{dedicated} is non-@code{nil}.
1967 If there are two candidate windows of the same size, this function
1968 prefers the one that comes first in the cyclic ordering of windows,
1969 starting from the selected window.
1971 The optional argument @var{all-frames} specifies which set of windows to
1972 consider as with @code{next-window}, see above.
1973 @end defun
1975 @cindex window that satisfies a predicate
1976 @cindex conditional selection of windows
1977 @defun get-window-with-predicate predicate &optional minibuf all-frames default
1978 This function returns a window satisfying @var{predicate}.  It cycles
1979 through all visible windows calling @var{predicate} on each one of them
1980 with that window as its argument.  The function returns the first window
1981 for which @var{predicate} returns a non-@code{nil} value; if that never
1982 happens, it returns @var{default} (which defaults to @code{nil}).
1984 The optional arguments @var{minibuf} and @var{all-frames} specify the
1985 set of windows to investigate.  See the description of
1986 @code{next-window} for details.
1987 @end defun
1990 @node Buffers and Windows
1991 @section Buffers and Windows
1992 @cindex examining windows
1993 @cindex windows, controlling precisely
1994 @cindex buffers, controlled in windows
1996 To find out which buffer is displayed in a given window the following
1997 function is used.
1999 @defun window-buffer &optional window
2000 This function returns the buffer that @var{window} is displaying.  The
2001 argument @var{window} can be any window and defaults to the selected
2002 one.  If @var{window} is an internal window, this function returns
2003 @code{nil}.
2004 @end defun
2006 The basic, low-level function to associate a window with a buffer is
2007 @code{set-window-buffer}.  Higher-level functions like
2008 @code{display-buffer} try to obey a number of user customizations
2009 regulating which windows are supposed to display which buffers.  When
2010 writing an application, programmers should therefore carefully evaluate
2011 whether they really need the power of @code{set-window-buffer}.
2013 @defun set-window-buffer window buffer-or-name &optional keep-margins
2014 This function makes @var{window} display @var{buffer-or-name} and
2015 returns @code{nil}.  The argument @var{window} has to denote a live
2016 window and defaults to the selected one.  The argument
2017 @var{buffer-or-name} must specify a buffer or the name of an existing
2018 buffer.  An error is signalled when @var{window} is @dfn{strongly}
2019 dedicated to its buffer (@pxref{Dedicated Windows}) and does not already
2020 display @var{buffer-or-name}.
2022 Normally, displaying @var{buffer-or-name} in @var{window} resets the
2023 window's position, display margins, fringe widths, and scroll bar
2024 settings based on the local variables of the specified buffer.  However,
2025 if the optional argument @var{keep-margins} is non-@code{nil}, display
2026 margins and fringe widths of @var{window} remain unchanged.
2027 @xref{Fringes}.
2029 This function is the fundamental primitive for changing which buffer is
2030 displayed in a window, and all ways of doing that call this function.
2031 Neither the selected window nor the current buffer are changed by this
2032 function.
2034 This function runs @code{window-scroll-functions} before running
2035 @code{window-configuration-change-hook}, see @ref{Window Hooks}.
2036 @end defun
2038 @defvar buffer-display-count
2039 This buffer-local variable records the number of times a buffer has been
2040 displayed in a window.  It is incremented each time
2041 @code{set-window-buffer} is called for the buffer.
2042 @end defvar
2044 @defvar buffer-display-time
2045 This variable records the time at which a buffer was last made visible
2046 in a window.  It is always local in each buffer; each time
2047 @code{set-window-buffer} is called, it sets this variable to
2048 @code{(current-time)} in the specified buffer (@pxref{Time of Day}).
2049 When a buffer is first created, @code{buffer-display-time} starts out
2050 with the value @code{nil}.
2051 @end defvar
2053 @defun get-buffer-window &optional buffer-or-name all-frames
2054 This function returns a window displaying @var{buffer-or-name}, or
2055 @code{nil} if there is none.  If there are several such windows, then
2056 the function returns the first one in the cyclic ordering of windows,
2057 starting from the selected window, @xref{Cyclic Window Ordering}.
2059 The argument @var{BUFFER-OR-NAME} may be a buffer or a buffer name and
2060 defaults to the current buffer.  The optional argument @var{all-frames}
2061 specifies which windows to consider:
2063 @itemize @bullet
2064 @item
2065 @code{nil} means consider windows on the selected frame.
2066 @item
2067 @code{t} means consider windows on all existing frames.
2068 @item
2069 @code{visible} means consider windows on all visible frames.
2070 @item
2071 0 means consider windows on all visible or iconified frames.
2072 @item
2073 A frame means consider windows on that frame only.
2074 @end itemize
2076 Observe that the behavior of @code{get-buffer-window} may differ from
2077 that of @code{next-window} (@pxref{Cyclic Window Ordering}) when
2078 @var{all-frames} equals @code{nil} or any value not listed here.
2079 Perhaps we will change @code{get-buffer-window} in the future to make it
2080 compatible with the other functions.
2081 @end defun
2083 @defun get-buffer-window-list &optional buffer-or-name minibuf all-frames
2084 This function returns a list of all windows currently displaying
2085 @var{buffer-or-name}.  The argument @var{buffer-or-name} may be a buffer
2086 or the name of an existing buffer and defaults to the current buffer.
2088 The two remaining arguments work like the same-named arguments of
2089 @code{next-window} (@pxref{Cyclic Window Ordering}); they are @emph{not}
2090 like the optional arguments of @code{get-buffer-window}.
2091 @end defun
2093 The following command removes a buffer from all windows showing it.
2095 @deffn Command replace-buffer-in-windows &optional buffer-or-name
2096 This function replaces @var{buffer-or-name} in all windows displaying it
2097 with some other buffer.  It uses @code{switch-to-prev-buffer}, see
2098 below, to choose that other buffer which is usually the last buffer
2099 displayed before @var{buffer-or-name} in the respective window.
2101 The argument @var{buffer-or-name} may be a buffer or the name of an
2102 existing buffer and defaults to the current buffer.
2104 If a window displaying @var{buffer-or-name} is dedicated
2105 (@pxref{Dedicated Windows}) or its @code{quit-restore} parameter
2106 (@pxref{Window Parameters}) is set appropriately, and the window is not
2107 the only window on its frame, that window is deleted.  If that window is
2108 the only window on its frame and there are other frames left, the
2109 window's frame is deleted too.  If there are no other frames left, some
2110 other buffer is displayed in that window as explained above.
2112 This function returns @code{nil}.
2113 @end deffn
2115    When @code{replace-buffer-in-windows} has to show another buffer in a
2116 window, it tries to pick the buffer shown there before.  For this
2117 purpose each window remembers the buffers it has displayed earlier and
2118 the order in which these buffers have been removed from it.
2120 The list of @dfn{previous buffers} of a window is an association list
2121 where each entry specifies a buffer, the last start position of that
2122 buffer in the window (@pxref{Window Start and End}) and the last
2123 position of that buffer's point in the window (@pxref{Window Point}).
2124 This list is ordered by the times of the removal of the respective
2125 buffers from the window.  In particular, the first element of the list
2126 references the buffer removed most recently.  The function
2127 @code{set-window-buffer} pushes an entry for the old buffer of its
2128 window argument on that list before it shows its buffer argument in the
2129 window.
2131 The list of @dfn{next buffers} of a window is a list of buffers that
2132 have been recently re-shown by the function @code{switch-to-prev-buffer}
2133 and is used to avoid that that function switches to such a buffer again
2134 before showing other interesting buffers.
2136 The lists of previous and next buffers and the global buffer list
2137 (@pxref{The Buffer List}) allow to effectively display all buffers in a
2138 window while giving preference to the buffers previously shown in that
2139 window.  The commands used for this purpose are
2140 @code{switch-to-prev-buffer} and @code{switch-to-next-buffer} described
2141 below.
2143 The following functions directly operate on the lists of previous and
2144 next buffers.
2146 @defun window-prev-buffers &optional window
2147 This function returns an alist specifying the buffers previously shown
2148 in @var{window} together with their window start and point positions.
2149 The argument @var{window} must be a live window and defaults to the
2150 selected one.
2151 @end defun
2153 @defun set-window-prev-buffers window prev-buffers
2154 This function sets @var{window}'s previous buffers to the value of
2155 @var{prev-buffers}.  The argument @var{window} must be a live window and
2156 defaults to the selected one.  This function returns
2157 @var{prev-buffers}.
2159 If non-@code{nil}, @var{prev-buffers} must specify an alist of triples
2160 specifying a buffer and two markers for that buffer's start and point
2161 position in @var{window}.
2162 @end defun
2164 @defun window-next-buffers &optional window
2165 This function returns the list of buffers recently re-shown in
2166 @var{window}.  The argument @var{window} must be a live window and
2167 defaults to the selected one.
2168 @end defun
2170 @defun set-window-next-buffers window next-buffers
2171 This function sets @var{window}'s next buffers to @var{next-buffers}.
2172 @var{window} must be a live window and defaults to the selected one.
2173 This fucntion returns @var{next-buffers}.
2175 If non-@code{nil}, the argument @var{next-buffers} should specify a list
2176 of buffers that shall be preferably not shown by the command
2177 @code{switch-to-prev-buffer}, see below.
2178 @end defun
2180 The following command is used by @code{replace-buffer-in-windows},
2181 @code{bury-buffer} and @code{quit-restore-window} to show another buffer
2182 in a window.  It can be also used interactively to cycle through the
2183 list of all buffers in a window, preferably showing the buffers recently
2184 shown (but not buried or killed) in that window.
2186 @deffn Command switch-to-prev-buffer &optional window bury-or-kill
2187 This function displays the previous buffer in @var{window}.  The
2188 argument @var{window} must be a live window and defaults to the selected
2189 one.  If the optional argument @var{bury-or-kill} is non-@code{nil},
2190 this means that the buffer currently shown in @var{window} is about to
2191 be buried or killed and consequently shall not be switched to in future
2192 invocations of this command.
2194 The previous buffer is usually the buffer shown before the buffer
2195 currently shown in @var{window}.  However, a buffer that has been buried
2196 or killed or has been already shown by a recent invocation of
2197 @code{switch-to-prev-buffer} does not qualify as previous buffer.
2199 If repeated invocations of this command have already shown all buffers
2200 previously shown in @var{window}, further invocations will show buffers
2201 from the global buffer list starting with the buffer returned by
2202 @code{last-buffer} (@pxref{The Buffer List}).
2203 @end deffn
2205 The following command can be used to undo the effect of the last undone
2206 @code{switch-to-prev-buffer} command.
2208 @deffn Command switch-to-next-buffer &optional window
2209 This functions switches to the next buffer in @var{window} thus undoing
2210 the effect of the last @code{switch-to-prev-buffer} command in
2211 @var{window}.  The argument @var{window} must be a live window and
2212 defaults to the selected one.
2214 If there is no recent invocation of a @code{switch-to-prev-buffer} that
2215 can be undone, @code{switch-to-next-buffer} will try to show the first
2216 buffer from the global buffer list as returned by @code{other-buffer}
2217 (@pxref{The Buffer List}).
2218 @end deffn
2220    Together, @code{switch-to-prev-buffer} and
2221 @code{switch-to-next-buffer} permit to navigate the global buffer list
2222 much like @code{bury-buffer} and @code{unbury-buffer}.  In contrast with
2223 the latter, however, they may show a buffer even if it is already shown
2224 in another window.  Moreover, they try to restore the window specific
2225 start and point positions of buffers which should handle viewing one and
2226 the same buffer in multiple windows more easily.
2229 @node Displaying Buffers
2230 @section Choosing a Window for Displaying a Buffer
2232 The basic facility to choose a window and display a buffer in it is
2233 @code{display-buffer}.  Many higher-level functions like
2234 @code{pop-to-buffer} (@pxref{Switching Buffers}) and
2235 @code{with-output-to-temp-buffer} (@pxref{Temporary Displays}) work by
2236 calling this function.  Here we describe how @code{display-buffer}
2237 works, how to customize its behavior, and how to get rid of the chosen
2238 window once it is no more needed.
2240 @deffn Command display-buffer &optional buffer-or-name specifiers label
2241 This command makes the buffer specified by @var{buffer-or-name} appear
2242 in some window, but it does not necessarily select that window or make
2243 the buffer current.  It returns the window chosen to display the buffer,
2244 @code{nil} if no such window can be found.
2246 The optional argument @var{buffer-or-name} has to specify a buffer or
2247 the name of a buffer and defaults to the current buffer.  If
2248 @var{buffer-or-name} is a string that does not name an existing buffer,
2249 @code{display-buffer} creates a buffer with that name.  When called
2250 interactively, it prompts for a buffer name in the minibuffer.
2252 The optional argument @var{specifiers} is usually a list of buffer
2253 display specifiers, see the description of @code{display-buffer-alist}
2254 below.  For convenience, @var{specifiers} may also consist of a single
2255 macro specifier or @code{t}, where the latter means to display the
2256 buffer in any but the selected window.  If @var{specifiers} is
2257 @code{nil} or omitted, this means to exclusively use the values provided
2258 by the variable @code{display-buffer-alist}.  If that variable is nil
2259 too, default specifiers are used.
2261 The optional third argument @var{label}, if non-@code{nil}, is a symbol
2262 specifying the buffer display label.  Applications should set this when
2263 the buffer shall be displayed in some special way but
2264 @var{buffer-or-name} alone does not identify the buffer as special.
2265 Typical buffers that fit into this category are those whose names are
2266 derived from the name of the file they are visiting.  A user can then
2267 override @var{specifiers} by adding an entry to
2268 @code{display-buffer-alist} whose @sc{car} contains @var{label} and
2269 whose @sc{cdr} specifies the preferred alternative display method.
2270 @end deffn                                                                      
2272 Precisely how @code{display-buffer} finds or creates a window depends on
2273 the @var{specifiers} argument and the two variables described next.
2275 @defopt display-buffer-alist
2276 @cindex buffer identifier
2277 The value of this option is a list associating buffer identifiers with
2278 buffer display specifiers.  The @sc{car} of each element of this list is
2279 built from cons cells called @dfn{buffer identifiers}.  The function
2280 @code{display-buffer} shows a buffer according to the display specifiers
2281 in the element's @sc{cdr} (elements are true lists) if at least one of
2282 these buffer identifiers matches the first or third argument of
2283 @code{display-buffer}.  Such a match occurs in one of the following
2284 three cases:
2286 @itemize @bullet
2287 @item
2288 The @sc{car} of the buffer identifier is the symbol @code{name} and its
2289 @sc{cdr} is a string equalling the name of the buffer specified by the
2290 @var{buffer-or-name} argument of @code{display-buffer}.
2292 @item
2293 The @sc{car} is the symbol @code{regexp} and the @sc{cdr} is a regular
2294 expression matching the name of the buffer specified by the first
2295 @var{buffer-or-name} argument of @code{display-buffer}.
2297 @item
2298 The @sc{car} is the symbol @code{label} and the @sc{cdr} is a symbol
2299 equalling the @var{label} argument of @code{display-buffer}.
2300 @end itemize
2302 @cindex buffer display specifier
2303 @cindex method specifier
2304 A @dfn{buffer display specifier} is a symbol, a cons cell, or a list,
2305 telling @code{display-buffer} where and how to display a given buffer.
2306 Four specifiers allow to indicate the basic method for displaying the
2307 buffer: @code{reuse-window}, @code{pop-up-window}, @code{pop-up-frame}
2308 and @code{use-side-window}.
2310    A list whose @sc{car} is the symbol @code{reuse-window} indicates
2311 that an existing window shall be reused for displaying the buffer.  The
2312 second element of this list specifies the window to reuse and can be one
2313 of the following symbols:
2315 @itemize @bullet
2316 @item
2317 @code{nil} stands for any window.
2319 @item
2320 @code{same} stands for the selected window.
2322 @item
2323 @code{other} stands for any but the selected window.
2324 @end itemize
2326 The third element specifies whether the buffer shown in the window that
2327 shall be reused must be the same buffer that shall be displayed or
2328 another buffer and can be one of the following:
2330 @itemize @bullet
2331 @item
2332 @code{nil} means to not care about the window's buffer.
2334 @item
2335 @code{same} means the window must show the buffer already.
2337 @item
2338 @code{other} means the window must not show the buffer yet.
2339 @end itemize
2341 The fourth element specifies the set of frames to search for a suitable
2342 window and can be one of the following:
2344 @itemize @bullet
2345 @item
2346 @code{nil} to stay on the selected frame.
2348 @item
2349 @code{visible} to search visible frames only.
2351 @item
2352 @code{other} stands for any visible frame but the selected one.
2354 @item
2355 0 (the number zero) to search visible and iconified frames.
2357 @item
2358 @code{t} to search arbitrary frames including invisible ones.
2359 @end itemize
2361 If more than one window fits the constraints imposed by these elements,
2362 the least recently used among them is chosen.  A side window
2363 (@pxref{Side Windows}) is reused if and only if it already shows the
2364 buffer that shall be displayed.
2366 Two specifiers are useful when the method equals @code{reuse-window}:
2368 @itemize @bullet
2369 @item
2370 A cons cell whose @sc{car} is the symbol @code{reuse-window-even-sizes}
2371 and whose @sc{cdr} is non-@code{nil} means to even out the sizes of the
2372 reused and the selected window provided they (1) are adjacent to each
2373 other and (2) the selected window is larger than the window chosen.  If
2374 the @sc{cdr} is @code{nil}, this means that the window sizes are left
2375 alone.
2377 @item
2378 A cons cell whose @sc{car} is the symbol @code{reuse-window-dedicated}
2379 and whose @sc{cdr} is non-@code{nil} means that a window can be reused
2380 even if it's dedicated to its buffer.  If the @sc{cdr} is @code{t}, a
2381 strongly dedicated window can be reused to show the buffer.  Any other
2382 non-@code{nil} value means only weakly dedicated windows can be reused.
2383 If the @sc{cdr} is @code{nil}, dedicated windows are not reused.
2385 This specifier should be used in special cases only since windows are
2386 usually made dedicated in order to prevent @code{display-buffer} from
2387 reusing them.
2388 @end itemize
2390 A list whose @sc{car} is the symbol @code{pop-up-window} and whose
2391 @sc{cdr} is built from window/side tuples indicates that a new window
2392 shall be made for displaying the buffer on the selected frame.
2394 Window/side tuples are cons cells.  The @sc{car} of such a tuple
2395 identifies the window that shall be split.  Possible values are
2396 @code{largest}, @code{lru}, @code{selected}, and @code{root} to
2397 respectively split the largest, least recently used, selected or root
2398 window of the selected frame.
2400 The @sc{cdr} of each pair specifies on which side of the window to split
2401 the new window shall appear and can be one of @code{below},
2402 @code{right}, @code{above}, or @code{left} with the obvious meanings.
2403 If the @sc{cdr} is @code{nil}, the window is split in a fashion suitable
2404 for its current dimensions.  If the @sc{cdr} specifies a function, that
2405 function is called with one argument---the window that shall be split.
2406 The function is supposed to split that window and return the new window.
2408 The function @code{display-buffer} scans these tuples until it can
2409 either produce a suitable window or fails.  The default value for
2410 @code{display-buffer-alist} contains the tuples
2412 @smallexample
2413 (largest . nil) (lru . nil)
2414 @end smallexample
2416 in order to split the largest window first and, if that fails, the least
2417 recently used one.
2419 The following additional specifiers are useful with the
2420 @code{pop-up-window} method specifier.
2422 @itemize @bullet
2423 @item
2424 A cons cell whose @sc{car} is the symbol @code{pop-up-window-min-height}
2425 specifies the minimum height of the new window.  If the @sc{cdr} is an
2426 integer number, it specifies the minimum number of lines of the window.
2427 A floating point number gives the minimum fraction of the window height
2428 with respect to the height of the frame's root window.  A new window is
2429 created only if it can be made at least as high as specified by the
2430 number.  If the @sc{cdr} is @code{nil}, this means to use the value of
2431 @code{window-min-height}.
2433 @item
2434 A cons cell whose @sc{car} is the symbol @code{pop-up-window-min-width}
2435 specifies the minimum width of the new window.  If the @sc{cdr} is an
2436 integer number, it specifies the minimum number of columns of the
2437 window.  A floating point number gives the minimum fraction of the
2438 window width with respect to the width of the frame's root window.  A
2439 new window is created only if it can be made at least as wide as
2440 specified by the number.  If the @sc{cdr} is @code{nil}, the value of
2441 @code{window-min-width} is used.
2443 @item
2444 A cons cell whose @sc{car} is @code{pop-up-window-set-height} with
2445 the following interpretations for the @sc{cdr}:
2447 @itemize @minus
2448 @item
2449 @code{nil} means leave the height of the new window alone.
2451 @item
2452 A number specifies the desired height of the new window.  An integer
2453 number specifies the number of lines of the window.  A floating point
2454 number gives the fraction of the window's height with respect to the
2455 height of the frame's root window.
2457 @item
2458 If the @sc{cdr} specifies a function, that function is called with one
2459 argument - the new window.  The function is supposed to adjust the
2460 height of the window; its return value is ignored.  Suitable functions
2461 to call here are @code{shrink-window-if-larger-than-buffer} and
2462 @code{fit-window-to-buffer}, see @ref{Resizing Windows}.
2463 @end itemize
2465 @item
2466 A cons cell whose @sc{car} equals @code{pop-up-window-set-width} with
2467 the following interpretations for the @sc{cdr}:
2469 @itemize @minus
2470 @item
2471 @code{nil} means leave the width of the new window alone.
2473 @item
2474 A number specifies the desired width of the new window.  An integer
2475 number specifies the number of columns of the window.  A floating point
2476 number gives the fraction of the window's width with respect to the
2477 width of the frame's root window.
2479 @item
2480 If the @sc{cdr} specifies a function, that function is called with one
2481 argument - the new window.  The function is supposed to adjust the width
2482 of the window; its return value is ignored.
2483 @end itemize
2485 Observe that specifying @code{pop-up-window-set-height} and
2486 @code{pop-up-window-set-width} may override restrictions given by the
2487 @code{pop-up-window-min-height} and @code{pop-up-window-min-width}
2488 specifiers.
2490 @item
2491 A cons cell whose @sc{car} is @code{pop-up-window-split-unsplittable}
2492 and whose @sc{cdr} is non-@code{nil} allows to make a new window on an
2493 unsplittable frame.  If the @sc{cdr} is @code{nil}, unsplittable frames
2494 are not split.  This specifier should be used in special cases only
2495 since frames are usually made unsplittable in order to prevent
2496 @code{display-buffer} from splitting them.
2497 @end itemize
2499 A list of two elements whose @sc{car} is the symbol @code{pop-up-frame}
2500 states that a new frame shall be made for displaying the buffer.  The
2501 second element of this list, if non-nil, allows to make a new frame on
2502 graphic displays only.
2504 The following additional specifiers are useful with the
2505 @code{pop-up-frame} method specifier.
2507 @itemize @bullet
2508 @item
2509 A list whose @sc{car} is the symbol @code{popup-frame-function} together
2510 with a valid function as @sc{cdr} specifies the function for creating a
2511 new frame.  If the @sc{cdr} is @code{nil}, the default function
2512 @code{make-frame} is called.  The function is called with the parameters
2513 and values provided by the specifier described next.
2515 @item
2516 A list whose @sc{car} is the symbol @code{popup-frame-alist} followed by
2517 an arbitrary number of frame parameter/value tuples, each given as a
2518 cons cell, specifies the parameters passed to the popup frame function.
2519 @end itemize
2521 A list of three elements whose @sc{car} is the symbol
2522 @code{use-side-window} specifies that the buffer shall be displayed in a
2523 side window (@pxref{Side Windows}) of the selected frame.  The second
2524 element denotes the side of the frame where the window shall appear and
2525 must be one of @code{left}, @code{top}, @code{right} and @code{bottom}.
2526 If no window on the specified side exists yet, @code{display-buffer}
2527 creates one.
2529 The third element is a number and denotes the slot within the specified
2530 side.  Slots are numbers where the number zero stands for the window in
2531 the middle of the side.  A slot less than zero indicates that the window
2532 shall be shown on the left (for the top and bottom side window) or above
2533 (for the left and right side window) of the window in the middle.  A
2534 slot larger than zero indicates that the window shall be shown on the
2535 right (for the top and bottom side window) or below (for the left and
2536 right side window) of the window in the middle.
2538 If a side window with the specified slot exists already and is not
2539 dedicated to its buffer, @code{display-buffer} reuses that window.  If
2540 no such window exists, @code{display-buffer} tries to make a new window
2541 with the specified slot by splitting the side window with the nearest
2542 matching slot.  If creating a new side window is impossible,
2543 @code{display-buffer} tries to reuse the side window with the nearest
2544 matching slot.  The option @code{window-sides-slots} (@pxref{Side
2545 Windows}) can be used to restrict the number of windows on each side.
2547 In conjunction with the @code{use-side-window} method specifier, the
2548 specifiers @code{reuse-window-dedicated},
2549 @code{pop-up-window-min-height}, @code{pop-up-window-min-width},
2550 @code{pop-up-window-set-height} and @code{pop-up-window-set-width}
2551 described above can be used.
2553 A list whose @sc{car} is the symbol @code{fun-with-args} specifies that
2554 the buffer shall be displayed by the function that appears as second
2555 element of that list.  The third element is a list of arguments that are
2556 passed as second argument to that function---the first argument is the
2557 buffer that shall be displayed.  The function is not passed any
2558 specifiers.
2560 The function should choose or create a window, display the specified
2561 buffer in it, and return the window.  It is also responsible for giving
2562 the variable @code{display-buffer-window} a meaningful value, see below
2563 for an explanation.  Moreover, the function should set up the
2564 @code{quit-restore} window parameter which is required for proper
2565 functioning of the command @code{quit-restore-window}, see below.
2567 It's hardly a good idea to call @code{display-buffer} within the body of
2568 the function specified here since this may lead to infinite recursion.
2570 @cindex macro specifier
2571 Instead of writing method specifiers it's often more convenient to use a
2572 predefined macro specifier.  The following macro specifiers are
2573 provided:
2575 @itemize @bullet
2576 @item
2577 @code{same-frame} to make or use a window on the selected frame.
2579 @item
2580 @code{other-window} to make or use any window but the selected one.
2582 @item
2583 @code{same-frame-other-window} to make or use any window on the
2584 selected frame with exception of the selected window.
2586 @item
2587 @code{other-frame} to make sure the window appears on any visible frame
2588 but the selected one.
2590 @item
2591 @code{default} to use the specifier of the default value of
2592 @code{display-buffer-alist} as described below.
2593 @end itemize
2595 In addition it's possible to specify whether the window chosen shall
2596 become dedicated to the buffer (@pxref{Dedicated Windows}).  This is
2597 accomplished with the help of a cons cell whose @sc{car} is the symbol
2598 @code{dedicated} and whose @sc{cdr} is one of the following values:
2600 @itemize @bullet
2601 @item
2602 @code{nil} which means to not dedicate the window to the buffer,
2604 @item
2605 @code{weak} which means the window shall be weakly dedicated to its
2606 buffer, or
2608 @item
2609 @code{t} to strongly dedicate the window to the buffer.
2610 @end itemize
2612 Moreover you can specify whether the function @code{other-window}
2613 (@pxref{Cyclic Window Ordering}) is allowed to select the window used
2614 for displaying the buffer.  This is accomplished with the help of a cons
2615 cell whose @sc{car} is the symbol @code{no-other-window} and whose
2616 @sc{cdr} is non-@code{nil}.
2618 In general, an application is free to ignore the specifiers of
2619 @code{display-buffer-alist} by explicitly passing a non-@code{nil}
2620 second argument to @code{display-buffer}.  For any
2621 @code{display-buffer-alist} entry one can, however, add a cons cell
2622 whose @sc{car} is the symbol @code{override} and whose @sc{cdr} is
2623 non-@code{nil} to explicitly override the value supplied by the
2624 application.
2626 Overriding arguments supplied by the calling application is, in general,
2627 not advisable.  It permits, for example, to change the semantics of
2628 commands like @code{switch-to-buffer-other-window} by setting the method
2629 specifier to @code{same-window} or @code{other-frame}.
2630 @end defopt
2632 The value of @code{display-buffer-alist} may contain scalar elements
2633 which are used by the customization interface and are ignored by
2634 @code{display-buffer}.  The normalized default specifiers are:
2636 @example
2637  ((reuse-window nil same visible)
2638   (pop-up-window (largest) (lru))
2639   (pop-up-frame)
2640   (reuse-window nil other visible)
2641   (reuse-window-even-sizes . t))
2642 @end example
2644 It means to proceed as follows:
2646 @itemize @bullet
2647 @item
2648 First try reusing a window showing the buffer on some visible frame.  If
2649 a window above or below the selected window is reused, the sizes of
2650 those windows are evened out.
2652 @item
2653 Next try to pop up a window on the selected frame by splitting either
2654 the largest or the least recently used window in a system dependent way.
2656 @item
2657 Try to pop up a new frame using the default function @code{make-frame}.
2659 @item
2660 Try to reuse a window showing some other buffer on a visible frame.
2661 @end itemize
2663 If these specifiers fail to produce a suitable window,
2664 @code{display-buffer} uses a number of heuristics that do not
2665 necessarily observe the value of @code{display-buffer-alist}.
2667 An application calling @code{display-buffer} can, in some cases, replace
2668 fixed references to windows or buffers within display specifiers by
2669 references to Lisp objects like windows or buffers.  In particular the
2670 following are possible:
2672 @itemize @bullet
2673 @item
2674 The @code{reuse-window} specifier accepts as second element a live
2675 window and as third element a live buffer.
2677 @item
2678 In window/side tuples of the @code{pop-up-window} specifier an arbitrary
2679 window can be used as first element.
2680 @end itemize
2682 In order to understand how @code{display-buffer} combines the values of
2683 @code{display-buffer-alist} with the @var{specifiers} argument suppose
2684 the following item
2686 @example
2687 (((name . "*text*"))
2688  ((pop-up-window (selected . below) (root . below))
2689   (override . t)))
2690 @end example
2692 has been added to @code{display-buffer-alist} and @code{display-buffer}
2693 is called as
2695 @example
2696 (display-buffer "*text*" '((reuse-window same)))
2697 @end example
2699 Since the entry from @code{display-buffer-alist} matches the buffer name
2700 and has the @code{override} specifier set, @code{display-buffer} will
2701 first try to split either the selected or the root window of the
2702 selected frame.
2704    If neither of these windows can be split, @code{display-buffer} will
2705 try to display the buffer in the selected window as requested by the
2706 @var{specifiers} argument.  If this fails as well, for example, because
2707 the selected window is dedicated to another buffer,
2708 @code{display-buffer} will apply the default specifiers from
2709 @code{display-buffer-alist} as sketched above.  Observe that in this
2710 case @code{display-buffer} will not necessarily try to split the
2711 selected or the frame's root window because the corresponding specifiers
2712 from @code{display-buffer-alist} have been already consumed at that
2713 time.
2715    So the order of precedence is to try the overriding specifiers from
2716 @code{display-buffer-alist} first.  Next come the specifiers from the
2717 @var{specifiers} argument of @code{display-buffer}.  Finally,
2718 non-overriding specifiers from @code{display-buffer-alist} are tried.
2720    In case you observe any unexpected behavior of @code{display-buffer}
2721 keep in mind the following:
2723 @itemize @bullet
2724 @item
2725 Specifiers are consumed in the order sketched above, which means that
2726 the value of the first specifier found prevails.  When
2727 @code{display-buffer} applies a method specifier, any specifiers
2728 preceding the method specifier have been consumed already and do no more
2729 affect the work of @code{display-buffer}.
2731 @item
2732 Displaying a buffer on a new or other frame will always raise that frame
2733 and give it input focus.  This contrasts with the behavior of
2734 @code{display-buffer} up to Emacs 22.  While not raising the frame seems
2735 like the correct behavior, it is presently not done due to possible bad
2736 interaction with window managers on various platforms.
2738 @item
2739 The customization interface does not allow to assign every conceivable
2740 value to the option @code{display-buffer-alist}.  You have to set these
2741 by hand to achieve more exotic behavior.
2742 @end itemize
2744    Next we describe how to manually transcribe the buffer display
2745 options of Emacs 23 with @code{display-buffer-alist}.  For a mechanized
2746 way to do this see the command @code{display-buffer-alist-set} descibed
2747 below.
2749 @itemize @bullet
2750 @item
2751 The options @code{same-window-buffer-names} and
2752 @code{same-window-regexps} are handled by the @code{same-window} macro
2753 specifier.
2755 @item
2756 For @code{display-buffer-reuse-frames} use the @code{reuse-window}
2757 specifier with a non-@code{nil} third element and as fourth element the
2758 set of frames that should be considered.
2760 @item
2761 The options @code{special-display-buffer-names} and
2762 @code{special-display-regexps} are replaced by
2763 @code{display-buffer-alist} itself because, in a sense, all buffers are
2764 special now.
2766 @item
2767 The @code{special-display-function} option is emulated by setting the
2768 @code{pop-up-frame-function} specifier.
2770 @item
2771 The @code{special-display-frame-alist} option is now handled by the
2772 @code{popup-frame-alist} specifier.
2774 @item
2775 The option @code{pop-up-frames} is replaced by the @code{pop-up-frame}
2776 method specifier.
2778 @item
2779 The option @code{pop-up-frame-function} has become the homonymous
2780 specifier.
2782 @item
2783 The option @code{pop-up-frame-alist} has become the homonymous specifier.
2785 @item
2786 The option @code{pop-up-windows} is replaces by the @code{pop-up-window}
2787 method specifier.
2789 @item
2790 A @code{split-window-preferred-function} can be specified as the second
2791 in a window/side tuple of the @code{pop-up-window} specifier.
2793 @item
2794 @code{split-height-threshold} and @code{split-width-threshold} are
2795 handled by the @code{pop-up-window-min-height} and
2796 @code{pop-up-window-min-width} specifiers respectively.  The sizes you
2797 specify there are, however, no more the original sizes of the window to
2798 split but the desired minimum sizes of the new window.
2800 @item
2801 @code{even-window-heights} is handled by setting the @sc{cdr} of the
2802 @code{reuse-window-even-sizes} specifier to a non-@code{nil} value.
2803 @end itemize
2805 @defopt display-buffer-function
2806 This variable is the most flexible way to customize the behavior of
2807 @code{display-buffer}.  If it is non-@code{nil}, it should be a function
2808 that @code{display-buffer} calls to do the work.  The function must
2809 accept two arguments, the buffer to display and a list of normalized
2810 buffer display specifiers as produced by
2811 @code{display-buffer-normalize-specifiers}, see below.
2813 It should choose or create a window, display the specified buffer in it,
2814 and then return the window.  It is also responsible for giving the
2815 variable @code{display-buffer-window} a meaningful value, see below for
2816 an explanation.  Moreover, the function should set up the
2817 @code{quit-restore} window parameter which is required for proper
2818 functioning of the command @code{quit-restore-window}, see below.
2820 The function specified here is free to ignore any specifiers passed to
2821 it as second argument.  If you intend to call @code{display-buffer}
2822 within the body of the function specified here, it's a good idea to bind
2823 @code{display-buffer-function} to @code{nil} around each such call to
2824 avoid running into an infinite recursion.
2825 @end defopt
2827 Above we described how to manually obtain the settings of
2828 @code{display-buffer-alist} from Emacs 23 buffer display options.  The
2829 function described next should do this automatically.
2831 @defun display-buffer-alist-set &optional no-custom add
2832 This fucntion sets @code{display-buffer-alist} from Emacs 23 buffer
2833 display options.  The optional argument @var{no-custom} @code{nil} means
2834 to apply the function @code{customize-set-variable} to set the value of
2835 @code{display-buffer-alist}.  If @var{no-custom} is non-@code{nil}, this
2836 means to use @code{setq} instead.
2838 The optional argument @var{add} @code{nil} means to replace the actual
2839 value of @code{display-buffer-alist} with the value calculated here.  If
2840 @var{add} is non-@code{nil}, this means to prepend the value calculated
2841 here to the current value of @code{display-buffer-alist}.
2842 @end defun
2844 Applications setting or binding Emacs 23 buffer display options will
2845 usually fail to achieve the desired effect if they do not set the
2846 @var{specifiers} argument of @code{display-buffer} accordingly.  Binding
2847 or setting @code{display-buffer-function} to the function sketched below
2848 can bypass this problem until the @var{specifiers} argument has been
2849 rewritten.
2851 @example
2852 (defun my-display-buffer (buffer specifiers)
2853   "Run `display-buffer' with Emacs 23 buffer display options."
2854   (let (display-buffer-alist display-buffer-function)
2855     (display-buffer-alist-set t)
2856     (display-buffer buffer)))
2857 @end example
2859 The function @code{my-display-buffer} applies
2860 @code{display-buffer-alist-set} to a locally bound, pristine copy of
2861 @code{display-buffer-alist} and calls @code{display-buffer} without any
2862 specifiers.  Note the local binding of @code{display-buffer-function}
2863 which avoids that @code{display-buffer} calls @code{my-display-buffer}
2864 recursively.
2866    In this context note that the purpose of the buffer display options
2867 of Emacs 23 was to give users an instrument to control the behavior of
2868 how buffers are displayed.  Setting or binding such an option within an
2869 application did constitutes bad programming practice just like setting
2870 or binding @code{display-buffer-alist} would.  Applications are supposed
2871 to @emph{exclusively} use the @var{specifiers} argument in order to
2872 affect the behavior of @code{display-buffer}.
2874 The function @code{display-buffer} tries hard to find a new window for
2875 displaying the buffer and fails (that is, returns @code{nil}) only in
2876 rare cases.  The functions described next are called by
2877 @code{display-buffer} but can be occasionally useful for applications
2878 that want more deterministic behavior.  These functions must be called
2879 with normalized specifiers which means that all macro specifiers must
2880 have been already expanded and the scalar symbols used by the
2881 customization interface removed.  To get normalized specifiers you can
2882 use the function described next.
2884 @defun display-buffer-normalize-specifiers buffer-name specifiers label
2885 This function returns the normalized specifiers for a buffer matching
2886 @var{buffer-name} or @var{label}.  The argument @var{buffer-name} must
2887 be a string specifying a valid buffer name.  The arguments
2888 @var{specifiers} and @var{label} are the homonymous arguments of
2889 @code{display-buffer}.
2890 @end defun
2892 In the four functions described next, the optional argument
2893 @var{specifiers} must be a list of normalized buffer display specifiers
2894 as returned by @code{display-buffer-normalize-specifiers}.  These
2895 functions return the window displaying the @var{buffer} if they
2896 succeeded, @code{nil} otherwise.
2898 @defun display-buffer-reuse-window buffer method &optional specifiers
2899 This function tries to display @var{buffer} in an existing window.  The
2900 argument @var{method} must be a list in the form of the @sc{cdr} of a
2901 @code{reuse-window} buffer display specifier.  The first element must
2902 specifiy the window to use, and can be either @code{nil}, @code{same},
2903 @code{other}, or a live window.  The second element specifies whether
2904 the window's buffer must be the same as @var{buffer} or another one and
2905 can be either @code{nil}, @code{same}, @code{other}.  It can be also a
2906 live buffer which means to reuse a window only if @var{buffer} is the
2907 buffer it displays.  The third element is the frame to use - either
2908 @code{nil}, 0 (the number zero), @code{visible}, @code{t}, or a live
2909 frame.
2910 @end defun
2912 @defun display-buffer-pop-up-window buffer methods &optional specifiers
2913 This function tries to display @var{buffer} in a new window.  The
2914 argument @var{methods} must be a list of window/side tuples like those
2915 forming the @sc{cdr} of the @code{pop-up-window} buffer display
2916 specifier.  As a special case, the @sc{car} of such a tuple can be also
2917 a live window.
2918 @end defun
2920 @defun display-buffer-pop-up-frame buffer &optional graphic-only specifiers
2921 This function tries to make a new frame for displaying @var{buffer}.
2922 The optional argument @var{graphic-only} non-@code{nil} means to make a
2923 new frame on graphic displays only.
2924 @end defun
2926 @defun display-buffer-in-side-window buffer side &optional slot specifiers
2927 This function tries to display @var{buffer} in a window on @var{side} of
2928 the selected frame (@pxref{Side Windows}).  The argument @var{slot}, if
2929 non-@code{nil}, specifies the window slot where to display the
2930 @var{buffer}.  If @var{slot} is zero or @code{nil}, this means use the
2931 central slot on @var{side}.  A negative value means to use a slot
2932 preceding the central window.  A positive value means to use a slot
2933 following the central window.
2934 @end defun
2936 The following functions are simple interfaces to @code{display-buffer}.
2938 @defun display-buffer-same-window &optional buffer-or-name label
2939 This function is like @code{display-buffer} but preferably displays the
2940 buffer specified by @var{buffer-or-name} in the selected window.
2941 Another window will be used only if the buffer can't be shown in the
2942 selected window, usually because it is dedicated to some other buffer.
2943 @end defun
2945 @defun display-buffer-same-frame &optional buffer-or-name label
2946 This function is like @code{display-buffer} but tries to avoid using
2947 another frame.
2948 @end defun
2950 @defun display-buffer-other-window &optional buffer-or-name label
2951 This function is like @code{display-buffer} but tries to avoid using the
2952 selected window.
2953 @end defun
2955 @defun display-buffer-other-window-same-frame &optional buffer-or-name label
2956 This function is like @code{display-buffer-other-window} but tries to
2957 avoid using another frame.
2958 @end defun
2960 The following variable conveys some information about the last
2961 @code{display-buffer} action performed and is used mainly when popping
2962 up a @samp{*Help*} buffer.
2964 @defvar display-buffer-window
2965 After @code{display-buffer} has shown a buffer in some window this
2966 variable should be a cons cell whose @sc{car} denotes the window used to
2967 display the buffer.  The @sc{cdr} is either @code{new-window} (which
2968 means a new window has been made), @code{new-frame} (a new frame has
2969 been created), @code{reuse-buffer-window} (a window showing the buffer
2970 has been reused), @code{reuse-other-window} (some other window has been
2971 reused).
2973 If @code{display-buffer-function} is non-@code{nil}, the function called
2974 here becomes responsible for assigning a meaningful value to this
2975 variable.  Otherwise, the @code{display-buffer} code takes care of this.
2976 @end defvar
2978 The command described next allows to quit the window chosen by
2979 @code{display-buffer} and restore the previous state without undoing
2980 changes to the window configuration that happend @emph{after}
2981 @code{display-buffer} was called.  A more drastic solution is to save
2982 the window configuration before calling @code{display-buffer} and
2983 eventually restoring the saved configuration, @ref{Window
2984 Configurations}.  That solution sometimes has the undesirable
2985 side-effect that all changes that happened after the configuration was
2986 saved are undone too.
2988 @deffn Command quit-restore-window &optional window kill
2989 This command ``quits'' @var{window} restoring its previous contents if
2990 possible.  The argument @var{window} must be a live window and defaults
2991 to the selected one.  This function always returns @code{nil}.
2993 According to information stored in @var{window}'s @code{quit-restore}
2994 window parameter (@pxref{Window Parameters}) this function performs one
2995 of the following actions.
2997 @itemize @bullet
2999 @item
3000 Delete @var{window} and its frame.  This action is useful when
3001 @var{window} was created on a standalone frame and there are other
3002 frames left.
3004 @item
3005 Delete @var{window}.  This action is usually taken when @var{window} was
3006 obtained by splitting some existing window.
3008 @item
3009 Restore the buffer previously displayed in @var{window}.  This action
3010 is taken when @var{window} was temporarily reused for displaying some
3011 other buffer.
3013 @item
3014 Make @var{window} display some other buffer.  This action is usually
3015 taken when the three preceding ones are not applicable.
3016 @end itemize
3018 If the optional argument @var{kill} is non-@code{nil}, this means in
3019 addition kill @var{window}'s buffer.  If @var{kill} is @code{nil}, this
3020 simply puts @var{window}'s buffer at the end of the buffer list.
3021 Interactively, @var{kill} is the prefix argument.
3022 @end deffn
3025 @node Switching Buffers
3026 @section Switching to a Buffer in Some Window
3027 @cindex switching to a buffer
3028 @cindex popping to a buffer
3030 In this section we describe convenient functions for switching to a
3031 specified buffer in some window.  These functions can also split an
3032 existing window or create a new frame in certain circumstances.  In any
3033 case, the window chosen becomes the selected window and the buffer
3034 current.
3036    Do not use the functions in this section in order to make a buffer
3037 current so that a Lisp program can access or modify it; they are too
3038 drastic for that purpose, since they change the display of buffers in
3039 windows, which would be gratuitous and surprise the user.  Instead, use
3040 @code{set-buffer} and @code{save-current-buffer} (@pxref{Current
3041 Buffer}), which designate buffers as current for programmed access
3042 without affecting the display of buffers in windows.
3044    The functions described here can be roughly divided into two groups
3045 whose major representatives are the functions @code{switch-to-buffer}
3046 and @code{pop-to-buffer} respectively.  Functions in the
3047 @code{switch-to-buffer} group have the following distinguishing
3048 characteristics:
3050 @itemize @bullet
3051 @item
3052 They are reserved for interactive use; many of them have a predefined
3053 keybinding.  Lisp code should @emph{never} call them.
3055 @item
3056 They can show a buffer in a window even if that window is dedicated to
3057 another buffer.
3059 @item
3060 They do not have a @code{specifiers} or a @var{label} argument like
3061 @code{display-buffer}.
3063 @item
3064 When the argument specifying the buffer that shall be displayed is
3065 @code{nil}, they display the buffer returned by @code{other-buffer}.
3066 @end itemize
3068 Functions in the @code{pop-to-buffer} group have the following
3069 characteristics.
3071 @itemize @bullet
3072 @item
3073 They can be called interactively and from Lisp code.
3075 @item
3076 They respect the user customizations of @code{display-buffer-alist} and
3077 @code{display-buffer-function}.  In particular, they try to not reuse a
3078 dedicated window unless they are explicitly advised to do so.
3080 @item
3081 They can be passed a @code{specifiers} and a @var{label} argument, just
3082 as @code{display-buffer}.
3084 @item
3085 When the argument specifying the buffer that shall be displayed is
3086 @code{nil}, they try to display the current buffer.
3087 @end itemize
3089 For historical reasons, many Lisp function call @code{switch-to-buffer}.
3090 These calls should be converted to @code{pop-to-buffer} calls.
3092 @deffn Command switch-to-buffer buffer-or-name &optional norecord
3093 This function makes the buffer specified by @var{buffer-or-name}
3094 current, displays it in the selected window, and returns the buffer.
3095 This means that a human can see the buffer and subsequent keyboard
3096 commands will apply to it.  Contrast this with @code{set-buffer}, which
3097 makes @var{buffer-or-name} the current buffer but does not display it in
3098 the selected window; see @ref{Current Buffer}.
3100 If @var{buffer-or-name} is @code{nil}, @code{switch-to-buffer} chooses a
3101 buffer using @code{other-buffer}.  If @var{buffer-or-name} is a string
3102 that does not identify an existing buffer, then a new buffer by that
3103 name is created.  The major mode for the new buffer is set according to
3104 the variable @code{major-mode}; see @ref{Auto Major Mode}.
3106 If called interactively, it prompts for the buffer name using the
3107 minibuffer.  The variable @code{confirm-nonexistent-file-or-buffer}
3108 determines whether to request confirmation before creating a new buffer.
3110 When the selected window is the minibuffer window or is strongly
3111 dedicated to its buffer (@pxref{Dedicated Windows}), this function calls
3112 @code{pop-to-buffer} (see below) to display the buffer in some other
3113 window.
3115 Normally, the specified buffer is put at the front of the buffer list
3116 (both the selected frame's buffer list and the frame-independent buffer
3117 list, see @ref{The Buffer List}).  This affects the operation of
3118 @code{other-buffer}.  However, if @var{norecord} is non-@code{nil}, this
3119 is not done.  Also, if @var{norecord} is non-@code{nil}, the window
3120 chosen for displaying the buffer is not automatically made the most
3121 recently selected one.
3123 This function is intended for interactive use, as the binding of
3124 @kbd{C-x b}.  Do @emph{not} call this function from Lisp code.  The
3125 function @code{pop-to-buffer-same-window} should be used for that
3126 purpose.
3127 @end deffn
3129 The next functions are similar to @code{switch-to-buffer}, except for
3130 the described features.
3132 @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
3133 This command makes the buffer specified by @var{buffer-or-name} current
3134 and tries to display it in a window not currently selected, by using the
3135 function @code{pop-to-buffer} (see below).  It returns the buffer
3136 switched to.
3138 This function tries hard to avoid using the selected window for doing
3139 the job.  If the selected window already displays @var{buffer-or-name},
3140 then it continues to do so, but another window is nonetheless found to
3141 display it in as well.
3143 The arguments @var{buffer-or-name} and @var{norecord} have the same
3144 meaning as for @code{switch-to-buffer}.
3146 This function is for interactive use, as the binding of @kbd{C-x 4 b}.
3147 Do @emph{not} call this function from Lisp code.  The function
3148 @code{pop-to-buffer-other-window} should be used for this purpose.
3149 @end deffn
3151 @deffn Command switch-to-buffer-same-frame buffer-or-name &optional norecord
3152 This command is like @code{switch-to-buffer-other-window} but does not
3153 necessarily avoid the selected window.  It does, however, try to use or
3154 make a window on the selected frame.
3155 @end deffn
3157 @deffn Command switch-to-buffer-other-window-same-frame buffer-or-name &optional norecord
3158 This command is like @code{switch-to-buffer-other-window} but tries to
3159 use or make a window on the selected frame.
3160 @end deffn
3162 @deffn Command switch-to-buffer-other-frame buffer-or-name &optional norecord
3163 This command is like @code{switch-to-buffer-other-window} but tries to
3164 display the buffer on another frame.  This function has the binding
3165 @kbd{C-x 4 b}.
3166 @end deffn
3168 The following functions take a @var{specifiers} and a @var{label}
3169 argument and respect the same customizations as @code{display-buffer}.
3170 Their only difference to the latter is that they @emph{always} select
3171 the window chosen for displaying the buffer argument.
3173 @deffn Command pop-to-buffer buffer-or-name &optional specifiers norecord label
3174 This command makes @var{buffer-or-name} the current buffer and switches
3175 to it in some window.  The ``popped-to'' window becomes the selected
3176 window.  Its frame is given the X server's focus, if possible; see
3177 @ref{Input Focus}.  The return value is the buffer that was switched to
3178 or @code{nil} if no suitable window could be found.
3180    The optional argument @var{buffer-or-name} may be a buffer, a string
3181 (a buffer name), or @code{nil}.  If @var{buffer-or-name} is a string not
3182 naming an existent buffer, it creates a buffer with that name.  If
3183 @var{buffer-or-name} is @code{nil} or omitted, it displays the current
3184 buffer.
3186    The optional second argument @var{specifiers} must be a list of
3187 buffer display specifiers or a single macro specifier, see the
3188 documentations of @code{display-buffer} and @code{display-buffer-alist}.
3189 If @var{specifiers} is @code{t}, it means to pop to the buffer in any
3190 but the selected window.  If @var{specifiers} is @code{nil} or omitted,
3191 this means to exclusively use the values provided by
3192 @code{display-buffer-alist} (@pxref{Displaying Buffers}).  If these
3193 values are nil too, default specifiers are used.
3195    The optional third argument @var{norecord} is handled just as by
3196 @code{switch-to-buffer}.  The optional fourth argument @var{label}
3197 specifies the buffer display label just as for @code{display-buffer}.
3198 @end deffn
3200 The following commands are similar to @code{pop-to-buffer} but for the
3201 mentioned differences.
3203 @deffn Command pop-to-buffer-same-window &optional buffer-or-name norecord label
3204 This command is like @code{pop-to-buffer} but tries to display the
3205 buffer in the selected window.  Another window will be used only if the
3206 buffer can't be shown in the selected window, usually because the window
3207 is dedicated to another buffer.
3208 @end deffn
3210 @deffn Command pop-to-buffer-same-frame &optional buffer-or-name norecord label
3211 This command is like @code{pop-to-buffer} but tries to make or use a
3212 window on the selected frame.
3213 @end deffn
3215 @deffn Command pop-to-buffer-other-window &optional buffer-or-name norecord label
3216 This command is like @code{pop-to-buffer} but tries to avoid the
3217 selected window.  Windows on the selected frame are preferred to windows
3218 on other frames.
3219 @end deffn
3221 @deffn Command pop-to-buffer-other-window-same-frame &optional buffer-or-name norecord label
3222 This command is like @code{pop-to-buffer-other-window} but tries to make
3223 or use a window on the selected frame.
3224 @end deffn
3226 @deffn Command pop-to-buffer-other-frame &optional buffer-or-name norecord label
3227 This command is like @code{pop-to-buffer} but preferably displays the
3228 buffer on another frame.
3229 @end deffn
3232 @node Dedicated Windows
3233 @section Dedicated Windows
3234 @cindex dedicated window
3236 Functions for displaying a buffer can be told to not use specific
3237 windows by marking these windows as @dfn{dedicated} to their buffers.
3238 The function @code{display-buffer} (@pxref{Displaying Buffers}) never
3239 uses a dedicated window for displaying another buffer in it.  The
3240 functions @code{get-lru-window} and @code{get-largest-window}
3241 (@pxref{Selecting Windows}) do not consider dedicated windows as
3242 candidates when their @var{dedicated} argument is non-@code{nil}.  The
3243 behavior of @code{set-window-buffer} (@pxref{Buffers and Windows}) with
3244 respect to dedicated windows is slightly different, see below.
3246 When @code{delete-windows-on} (@pxref{Deleting Windows}) wants to delete
3247 a dedicated window and that window is the only window on its frame, it
3248 deletes the window's frame too, provided there are other frames left.
3249 The function @code{replace-buffer-in-windows} (@pxref{Displaying
3250 Buffers}) tries to delete all dedicated windows showing its buffer
3251 argument.  When such a window is the only window on its frame, that
3252 frame is deleted, provided there are other frames left.  If there are no
3253 more frames left, some other buffer is displayed in the window, and the
3254 window is marked as non-dedicated.
3256 When you kill a buffer (@pxref{Killing Buffers}) displayed in a
3257 dedicated window, any such window usually gets deleted too, since
3258 @code{kill-buffer} calls @code{replace-buffer-in-windows} for cleaning
3259 up windows.  Burying a buffer (@pxref{The Buffer List}) deletes the
3260 selected window if it is dedicated to that buffer.  If, however, that
3261 window is the only window on its frame, @code{bury-buffer} displays
3262 another buffer in it and iconifies the frame.
3264 @defun window-dedicated-p &optional window
3265 This function returns non-@code{nil} if @var{window} is dedicated to its
3266 buffer and @code{nil} otherwise.  More precisely, the return value is
3267 the value assigned by the last call of @code{set-window-dedicated-p} for
3268 @var{window} or @code{nil} if that function was never called with
3269 @var{window} as its argument.  The default for @var{window} is the
3270 selected window.
3271 @end defun
3273 @defun set-window-dedicated-p window flag
3274 This function marks @var{window} as dedicated to its buffer if
3275 @var{flag} is non-@code{nil}, and non-dedicated otherwise.
3277 As a special case, if @var{flag} is @code{t}, @var{window} becomes
3278 @dfn{strongly} dedicated to its buffer.  @code{set-window-buffer}
3279 signals an error when the window it acts upon is strongly dedicated to
3280 its buffer and does not already display the buffer it is asked to
3281 display.  Other functions do not treat @code{t} differently from any
3282 non-@code{nil} value.
3283 @end defun
3286 @node Window Point
3287 @section Windows and Point
3288 @cindex window position
3289 @cindex window point
3290 @cindex position in window
3291 @cindex point in window
3293 Each window has its own value of point (@pxref{Point}), independent of
3294 the value of point in other windows displaying the same buffer.  This
3295 makes it useful to have multiple windows showing one buffer.
3297 @itemize @bullet
3298 @item
3299 The window point is established when a window is first created; it is
3300 initialized from the buffer's point, or from the window point of another
3301 window opened on the buffer if such a window exists.
3303 @item
3304 Selecting a window sets the value of point in its buffer from the
3305 window's value of point.  Conversely, deselecting a window sets the
3306 window's value of point from that of the buffer.  Thus, when you switch
3307 between windows that display a given buffer, the point value for the
3308 selected window is in effect in the buffer, while the point values for
3309 the other windows are stored in those windows.
3311 @item
3312 As long as the selected window displays the current buffer, the window's
3313 point and the buffer's point always move together; they remain equal.
3314 @end itemize
3316 @cindex cursor
3317    As far as the user is concerned, point is where the cursor is, and
3318 when the user switches to another buffer, the cursor jumps to the
3319 position of point in that buffer.
3321 @defun window-point &optional window
3322 This function returns the current position of point in @var{window}.
3323 For a nonselected window, this is the value point would have (in that
3324 window's buffer) if that window were selected.  The default for
3325 @var{window} is the selected window.
3327 When @var{window} is the selected window and its buffer is also the
3328 current buffer, the value returned is the same as point in that buffer.
3329 Strictly speaking, it would be more correct to return the ``top-level''
3330 value of point, outside of any @code{save-excursion} forms.  But that
3331 value is hard to find.
3332 @end defun
3334 @defun set-window-point window position
3335 This function positions point in @var{window} at position
3336 @var{position} in @var{window}'s buffer.  It returns @var{position}.
3338 If @var{window} is selected, and its buffer is current,
3339 this simply does @code{goto-char}.
3340 @end defun
3342 @defvar window-point-insertion-type
3343 This variable specifies the marker insertion type (@pxref{Marker
3344 Insertion Types}) of @code{window-point}.  The default is @code{nil},
3345 so @code{window-point} will stay behind text inserted there.
3346 @end defvar
3349 @node Window Start and End
3350 @section The Window Start and End Positions
3351 @cindex window start position
3353   Each window maintains a marker used to keep track of a buffer position
3354 that specifies where in the buffer display should start.  This position
3355 is called the @dfn{display-start} position of the window (or just the
3356 @dfn{start}).  The character after this position is the one that appears
3357 at the upper left corner of the window.  It is usually, but not
3358 inevitably, at the beginning of a text line.
3360   After switching windows or buffers, and in some other cases, if the
3361 window start is in the middle of a line, Emacs adjusts the window
3362 start to the start of a line.  This prevents certain operations from
3363 leaving the window start at a meaningless point within a line.  This
3364 feature may interfere with testing some Lisp code by executing it
3365 using the commands of Lisp mode, because they trigger this
3366 readjustment.  To test such code, put it into a command and bind the
3367 command to a key.
3369 @defun window-start &optional window
3370 @cindex window top line
3371 This function returns the display-start position of window
3372 @var{window}.  If @var{window} is @code{nil}, the selected window is
3373 used.  For example,
3375 @example
3376 @group
3377 (window-start)
3378      @result{} 7058
3379 @end group
3380 @end example
3382 When you create a window, or display a different buffer in it, the
3383 display-start position is set to a display-start position recently used
3384 for the same buffer, or to @code{point-min} if the buffer doesn't have
3385 any.
3387 Redisplay updates the window-start position (if you have not specified
3388 it explicitly since the previous redisplay)---to make sure point appears
3389 on the screen.  Nothing except redisplay automatically changes the
3390 window-start position; if you move point, do not expect the window-start
3391 position to change in response until after the next redisplay.
3393 For a realistic example of using @code{window-start}, see the
3394 description of @code{count-lines}.  @xref{Definition of count-lines}.
3395 @end defun
3397 @cindex window end position
3398 @defun window-end &optional window update
3399 This function returns the position where display of its buffer ends in
3400 @var{window}.  The default for @var{window} is the selected window.
3402 Simply changing the buffer text or moving point does not update the
3403 value that @code{window-end} returns.  The value is updated only when
3404 Emacs redisplays and redisplay completes without being preempted.
3406 If the last redisplay of @var{window} was preempted, and did not finish,
3407 Emacs does not know the position of the end of display in that window.
3408 In that case, this function returns @code{nil}.
3410 If @var{update} is non-@code{nil}, @code{window-end} always returns an
3411 up-to-date value for where display ends, based on the current
3412 @code{window-start} value.  If a previously saved value of that position
3413 is still valid, @code{window-end} returns that value; otherwise it
3414 computes the correct value by scanning the buffer text.
3416 Even if @var{update} is non-@code{nil}, @code{window-end} does not
3417 attempt to scroll the display if point has moved off the screen, the
3418 way real redisplay would do.  It does not alter the
3419 @code{window-start} value.  In effect, it reports where the displayed
3420 text will end if scrolling is not required.
3421 @end defun
3423 @defun set-window-start window position &optional noforce
3424 This function sets the display-start position of @var{window} to
3425 @var{position} in @var{window}'s buffer.  It returns @var{position}.
3427 The display routines insist that the position of point be visible when a
3428 buffer is displayed.  Normally, they change the display-start position
3429 (that is, scroll the window) whenever necessary to make point visible.
3430 However, if you specify the start position with this function using
3431 @code{nil} for @var{noforce}, it means you want display to start at
3432 @var{position} even if that would put the location of point off the
3433 screen.  If this does place point off screen, the display routines move
3434 point to the left margin on the middle line in the window.
3436 For example, if point @w{is 1} and you set the start of the window
3437 @w{to 37}, the start of the next line, point will be ``above'' the top
3438 of the window.  The display routines will automatically move point if
3439 it is still 1 when redisplay occurs.  Here is an example:
3441 @example
3442 @group
3443 ;; @r{Here is what @samp{foo} looks like before executing}
3444 ;;   @r{the @code{set-window-start} expression.}
3445 @end group
3447 @group
3448 ---------- Buffer: foo ----------
3449 @point{}This is the contents of buffer foo.
3455 ---------- Buffer: foo ----------
3456 @end group
3458 @group
3459 (set-window-start
3460  (selected-window)
3461  (save-excursion
3462    (goto-char 1)
3463    (forward-line 1)
3464    (point)))
3465 @result{} 37
3466 @end group
3468 @group
3469 ;; @r{Here is what @samp{foo} looks like after executing}
3470 ;;   @r{the @code{set-window-start} expression.}
3471 ---------- Buffer: foo ----------
3474 @point{}4
3477 ---------- Buffer: foo ----------
3478 @end group
3479 @end example
3481 If @var{noforce} is non-@code{nil}, and @var{position} would place point
3482 off screen at the next redisplay, then redisplay computes a new window-start
3483 position that works well with point, and thus @var{position} is not used.
3484 @end defun
3486 @defun pos-visible-in-window-p &optional position window partially
3487 This function returns non-@code{nil} if @var{position} is within the
3488 range of text currently visible on the screen in @var{window}.  It
3489 returns @code{nil} if @var{position} is scrolled vertically out of view.
3490 Locations that are partially obscured are not considered visible unless
3491 @var{partially} is non-@code{nil}.  The argument @var{position} defaults
3492 to the current position of point in @var{window}; @var{window}, to the
3493 selected window.  If @var{position} is @code{t}, that means to check the
3494 last visible position in @var{window}.
3496 This function considers only vertical scrolling.  If @var{position} is
3497 out of view only because @var{window} has been scrolled horizontally,
3498 @code{pos-visible-in-window-p} returns non-@code{nil} anyway.
3499 @xref{Horizontal Scrolling}.
3501 If @var{position} is visible, @code{pos-visible-in-window-p} returns
3502 @code{t} if @var{partially} is @code{nil}; if @var{partially} is
3503 non-@code{nil}, and the character following @var{position} is fully
3504 visible, it returns a list of the form @code{(@var{x} @var{y})}, where
3505 @var{x} and @var{y} are the pixel coordinates relative to the top left
3506 corner of the window; otherwise it returns an extended list of the form
3507 @code{(@var{x} @var{y} @var{rtop} @var{rbot} @var{rowh} @var{vpos})},
3508 where @var{rtop} and @var{rbot} specify the number of off-window pixels
3509 at the top and bottom of the row at @var{position}, @var{rowh} specifies
3510 the visible height of that row, and @var{vpos} specifies the vertical
3511 position (zero-based row number) of that row.
3513 Here is an example:
3515 @example
3516 @group
3517 ;; @r{If point is off the screen now, recenter it now.}
3518 (or (pos-visible-in-window-p
3519      (point) (selected-window))
3520     (recenter 0))
3521 @end group
3522 @end example
3523 @end defun
3525 @defun window-line-height &optional line window
3526 This function returns the height of text line @var{line} in
3527 @var{window}.  If @var{line} is one of @code{header-line} or
3528 @code{mode-line}, @code{window-line-height} returns information about
3529 the corresponding line of the window.  Otherwise, @var{line} is a text
3530 line number starting from 0.  A negative number counts from the end of
3531 the window.  The default for @var{line} is the current line in
3532 @var{window}; the default for @var{window} is the selected window.
3534 If the display is not up to date, @code{window-line-height} returns
3535 @code{nil}.  In that case, @code{pos-visible-in-window-p} may be used
3536 to obtain related information.
3538 If there is no line corresponding to the specified @var{line},
3539 @code{window-line-height} returns @code{nil}.  Otherwise, it returns
3540 a list @code{(@var{height} @var{vpos} @var{ypos} @var{offbot})},
3541 where @var{height} is the height in pixels of the visible part of the
3542 line, @var{vpos} and @var{ypos} are the vertical position in lines and
3543 pixels of the line relative to the top of the first text line, and
3544 @var{offbot} is the number of off-window pixels at the bottom of the
3545 text line.  If there are off-window pixels at the top of the (first)
3546 text line, @var{ypos} is negative.
3547 @end defun
3550 @node Textual Scrolling
3551 @section Textual Scrolling
3552 @cindex textual scrolling
3553 @cindex scrolling textually
3555   @dfn{Textual scrolling} means moving the text up or down through a
3556 window.  It works by changing the value of the window's display-start
3557 location.  It may also change the value of @code{window-point} to keep
3558 point on the screen.
3560   Textual scrolling was formerly called ``vertical scrolling,'' but we
3561 changed its name to distinguish it from the new vertical fractional
3562 scrolling feature (@pxref{Vertical Scrolling}).
3564   In the commands @code{scroll-up} and @code{scroll-down}, the directions
3565 ``up'' and ``down'' refer to the motion of the text in the buffer at which
3566 you are looking through the window.  Imagine that the text is
3567 written on a long roll of paper and that the scrolling commands move the
3568 paper up and down.  Thus, if you are looking at text in the middle of a
3569 buffer and repeatedly call @code{scroll-down}, you will eventually see
3570 the beginning of the buffer.
3572   Some people have urged that the opposite convention be used: they
3573 imagine that the window moves over text that remains in place.  Then
3574 ``down'' commands would take you to the end of the buffer.  This view is
3575 more consistent with the actual relationship between windows and the
3576 text in the buffer, but it is less like what the user sees.  The
3577 position of a window on the terminal does not move, and short scrolling
3578 commands clearly move the text up or down on the screen.  We have chosen
3579 names that fit the user's point of view.
3581   The textual scrolling functions (aside from
3582 @code{scroll-other-window}) have unpredictable results if the current
3583 buffer is different from the buffer that is displayed in the selected
3584 window.  @xref{Current Buffer}.
3586   If the window contains a row which is taller than the height of the
3587 window (for example in the presence of a large image), the scroll
3588 functions will adjust the window's vertical scroll position to scroll
3589 the partially visible row.  To disable this feature, Lisp code may bind
3590 the variable @code{auto-window-vscroll} to @code{nil} (@pxref{Vertical
3591 Scrolling}).
3593 @deffn Command scroll-up &optional count
3594 This function scrolls the text in the selected window upward
3595 @var{count} lines.  If @var{count} is negative, scrolling is actually
3596 downward.
3598 If @var{count} is @code{nil} (or omitted), then the length of scroll
3599 is @code{next-screen-context-lines} lines less than the usable height of
3600 the window (not counting its mode line).
3602 @code{scroll-up} returns @code{nil}, unless it gets an error
3603 because it can't scroll any further.
3604 @end deffn
3606 @deffn Command scroll-down &optional count
3607 This function scrolls the text in the selected window downward
3608 @var{count} lines.  If @var{count} is negative, scrolling is actually
3609 upward.
3611 If @var{count} is omitted or @code{nil}, then the length of the scroll
3612 is @code{next-screen-context-lines} lines less than the usable height of
3613 the window (not counting its mode line).
3615 @code{scroll-down} returns @code{nil}, unless it gets an error because
3616 it can't scroll any further.
3617 @end deffn
3619 @deffn Command scroll-other-window &optional count
3620 This function scrolls the text in another window upward @var{count}
3621 lines.  Negative values of @var{count}, or @code{nil}, are handled
3622 as in @code{scroll-up}.
3624 You can specify which buffer to scroll by setting the variable
3625 @code{other-window-scroll-buffer} to a buffer.  If that buffer isn't
3626 already displayed, @code{scroll-other-window} displays it in some
3627 window.
3629 When the selected window is the minibuffer, the next window is normally
3630 the one at the top left corner.  You can specify a different window to
3631 scroll, when the minibuffer is selected, by setting the variable
3632 @code{minibuffer-scroll-window}.  This variable has no effect when any
3633 other window is selected.  When it is non-@code{nil} and the
3634 minibuffer is selected, it takes precedence over
3635 @code{other-window-scroll-buffer}.  @xref{Definition of
3636 minibuffer-scroll-window}.
3638 When the minibuffer is active, it is the next window if the selected
3639 window is the one at the bottom right corner.  In this case,
3640 @code{scroll-other-window} attempts to scroll the minibuffer.  If the
3641 minibuffer contains just one line, it has nowhere to scroll to, so the
3642 line reappears after the echo area momentarily displays the message
3643 @samp{Beginning of buffer}.
3644 @end deffn
3646 @c Emacs 19 feature
3647 @defvar other-window-scroll-buffer
3648 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
3649 which buffer's window to scroll.
3650 @end defvar
3652 @defopt scroll-margin
3653 This option specifies the size of the scroll margin---a minimum number
3654 of lines between point and the top or bottom of a window.  Whenever
3655 point gets within this many lines of the top or bottom of the window,
3656 redisplay scrolls the text automatically (if possible) to move point
3657 out of the margin, closer to the center of the window.
3658 @end defopt
3660 @defopt scroll-conservatively
3661 This variable controls how scrolling is done automatically when point
3662 moves off the screen (or into the scroll margin).  If the value is a
3663 positive integer @var{n}, then redisplay scrolls the text up to
3664 @var{n} lines in either direction, if that will bring point back into
3665 proper view.  This behavior is called @dfn{conservative scrolling}.
3666 Otherwise, scrolling happens in the usual way, under the control of
3667 other variables such as @code{scroll-up-aggressively} and
3668 @code{scroll-down-aggressively}.
3670 The default value is zero, which means that conservative scrolling
3671 never happens.
3672 @end defopt
3674 @defopt scroll-down-aggressively
3675 The value of this variable should be either @code{nil} or a fraction
3676 @var{f} between 0 and 1.  If it is a fraction, that specifies where on
3677 the screen to put point when scrolling down.  More precisely, when a
3678 window scrolls down because point is above the window start, the new
3679 start position is chosen to put point @var{f} part of the window
3680 height from the top.  The larger @var{f}, the more aggressive the
3681 scrolling.
3683 A value of @code{nil} is equivalent to .5, since its effect is to center
3684 point.  This variable automatically becomes buffer-local when set in any
3685 fashion.
3686 @end defopt
3688 @defopt scroll-up-aggressively
3689 Likewise, for scrolling up.  The value, @var{f}, specifies how far
3690 point should be placed from the bottom of the window; thus, as with
3691 @code{scroll-up-aggressively}, a larger value scrolls more aggressively.
3692 @end defopt
3694 @defopt scroll-step
3695 This variable is an older variant of @code{scroll-conservatively}.  The
3696 difference is that it if its value is @var{n}, that permits scrolling
3697 only by precisely @var{n} lines, not a smaller number.  This feature
3698 does not work with @code{scroll-margin}.  The default value is zero.
3699 @end defopt
3701 @defopt scroll-preserve-screen-position
3702 If this option is @code{t}, scrolling which would move the current
3703 point position out of the window chooses the new position of point
3704 so that the vertical position of the cursor is unchanged, if possible.
3706 If it is non-@code{nil} and not @code{t}, then the scrolling functions
3707 always preserve the vertical position of point, if possible.
3708 @end defopt
3710 @defopt next-screen-context-lines
3711 The value of this variable is the number of lines of continuity to
3712 retain when scrolling by full screens.  For example, @code{scroll-up}
3713 with an argument of @code{nil} scrolls so that this many lines at the
3714 bottom of the window appear instead at the top.  The default value is
3715 @code{2}.
3716 @end defopt
3718 @deffn Command recenter &optional count
3719 @cindex centering point
3720 This function scrolls the text in the selected window so that point is
3721 displayed at a specified vertical position within the window.  It does
3722 not ``move point'' with respect to the text.
3724 If @var{count} is a nonnegative number, that puts the line containing
3725 point @var{count} lines down from the top of the window.  If
3726 @var{count} is a negative number, then it counts upward from the
3727 bottom of the window, so that @minus{}1 stands for the last usable
3728 line in the window.  If @var{count} is a non-@code{nil} list, then it
3729 stands for the line in the middle of the window.
3731 If @var{count} is @code{nil}, @code{recenter} puts the line containing
3732 point in the middle of the window, then clears and redisplays the entire
3733 selected frame.
3735 When @code{recenter} is called interactively, @var{count} is the raw
3736 prefix argument.  Thus, typing @kbd{C-u} as the prefix sets the
3737 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
3738 @var{count} to 4, which positions the current line four lines from the
3739 top.
3741 With an argument of zero, @code{recenter} positions the current line at
3742 the top of the window.  This action is so handy that some people make a
3743 separate key binding to do this.  For example,
3745 @example
3746 @group
3747 (defun line-to-top-of-window ()
3748   "Scroll current line to top of window.
3749 Replaces three keystroke sequence C-u 0 C-l."
3750   (interactive)
3751   (recenter 0))
3753 (global-set-key [kp-multiply] 'line-to-top-of-window)
3754 @end group
3755 @end example
3756 @end deffn
3759 @node Vertical Scrolling
3760 @section Vertical Fractional Scrolling
3761 @cindex vertical fractional scrolling
3762 @cindex vertical scroll position
3764    @dfn{Vertical fractional scrolling} means shifting text in a window
3765 up or down by a specified multiple or fraction of a line.  Each window
3766 has a @dfn{vertical scroll position}, which is a number, never less than
3767 zero.  It specifies how far to raise the contents of the window.
3768 Raising the window contents generally makes all or part of some lines
3769 disappear off the top, and all or part of some other lines appear at the
3770 bottom.  The usual value is zero.
3772    The vertical scroll position is measured in units of the normal line
3773 height, which is the height of the default font.  Thus, if the value is
3774 .5, that means the window contents are scrolled up half the normal line
3775 height.  If it is 3.3, that means the window contents are scrolled up
3776 somewhat over three times the normal line height.
3778    What fraction of a line the vertical scrolling covers, or how many
3779 lines, depends on what the lines contain.  A value of .5 could scroll a
3780 line whose height is very short off the screen, while a value of 3.3
3781 could scroll just part of the way through a tall line or an image.
3783 @defun window-vscroll &optional window pixels-p
3784 This function returns the current vertical scroll position of
3785 @var{window}.  The default for @var{window} is the selected window.
3786 If @var{pixels-p} is non-@code{nil}, the return value is measured in
3787 pixels, rather than in units of the normal line height.
3789 @example
3790 @group
3791 (window-vscroll)
3792      @result{} 0
3793 @end group
3794 @end example
3795 @end defun
3797 @defun set-window-vscroll window lines &optional pixels-p
3798 This function sets @var{window}'s vertical scroll position to
3799 @var{lines}.  If @var{window} is @code{nil}, the selected window is
3800 used.  The argument @var{lines} should be zero or positive; if not, it
3801 is taken as zero.
3804 The actual vertical scroll position must always correspond
3805 to an integral number of pixels, so the value you specify
3806 is rounded accordingly.
3808 The return value is the result of this rounding.
3810 @example
3811 @group
3812 (set-window-vscroll (selected-window) 1.2)
3813      @result{} 1.13
3814 @end group
3815 @end example
3817 If @var{pixels-p} is non-@code{nil}, @var{lines} specifies a number of
3818 pixels.  In this case, the return value is @var{lines}.
3819 @end defun
3821 @defvar auto-window-vscroll
3822 If this variable is non-@code{nil}, the line-move, scroll-up, and
3823 scroll-down functions will automatically modify the vertical scroll
3824 position to scroll through display rows that are taller than the height
3825 of the window, for example in the presence of large images.
3826 @end defvar
3829 @node Horizontal Scrolling
3830 @section Horizontal Scrolling
3831 @cindex horizontal scrolling
3833   @dfn{Horizontal scrolling} means shifting the image in the window left
3834 or right by a specified multiple of the normal character width.  Each
3835 window has a @dfn{horizontal scroll position}, which is a number, never
3836 less than zero.  It specifies how far to shift the contents left.
3837 Shifting the window contents left generally makes all or part of some
3838 characters disappear off the left, and all or part of some other
3839 characters appear at the right.  The usual value is zero.
3841   The horizontal scroll position is measured in units of the normal
3842 character width, which is the width of space in the default font.  Thus,
3843 if the value is 5, that means the window contents are scrolled left by 5
3844 times the normal character width.  How many characters actually
3845 disappear off to the left depends on their width, and could vary from
3846 line to line.
3848   Because we read from side to side in the ``inner loop,'' and from top
3849 to bottom in the ``outer loop,'' the effect of horizontal scrolling is
3850 not like that of textual or vertical scrolling.  Textual scrolling
3851 involves selection of a portion of text to display, and vertical
3852 scrolling moves the window contents contiguously; but horizontal
3853 scrolling causes part of @emph{each line} to go off screen.
3855   Usually, no horizontal scrolling is in effect; then the leftmost
3856 column is at the left edge of the window.  In this state, scrolling to
3857 the right is meaningless, since there is no data to the left of the edge
3858 to be revealed by it; so this is not allowed.  Scrolling to the left is
3859 allowed; it scrolls the first columns of text off the edge of the window
3860 and can reveal additional columns on the right that were truncated
3861 before.  Once a window has a nonzero amount of leftward horizontal
3862 scrolling, you can scroll it back to the right, but only so far as to
3863 reduce the net horizontal scroll to zero.  There is no limit to how far
3864 left you can scroll, but eventually all the text will disappear off the
3865 left edge.
3867 @vindex auto-hscroll-mode
3868   If @code{auto-hscroll-mode} is set, redisplay automatically alters
3869 the horizontal scrolling of a window as necessary to ensure that point
3870 is always visible.  However, you can still set the horizontal
3871 scrolling value explicitly.  The value you specify serves as a lower
3872 bound for automatic scrolling, i.e. automatic scrolling will not
3873 scroll a window to a column less than the specified one.
3875 @deffn Command scroll-left &optional count set-minimum
3876 This function scrolls the selected window @var{count} columns to the
3877 left (or to the right if @var{count} is negative).  The default
3878 for @var{count} is the window width, minus 2.
3880 The return value is the total amount of leftward horizontal scrolling in
3881 effect after the change---just like the value returned by
3882 @code{window-hscroll} (below).
3884 Once you scroll a window as far right as it can go, back to its normal
3885 position where the total leftward scrolling is zero, attempts to scroll
3886 any farther right have no effect.
3888 If @var{set-minimum} is non-@code{nil}, the new scroll amount becomes
3889 the lower bound for automatic scrolling; that is, automatic scrolling
3890 will not scroll a window to a column less than the value returned by
3891 this function.  Interactive calls pass non-@code{nil} for
3892 @var{set-minimum}.
3893 @end deffn
3895 @deffn Command scroll-right &optional count set-minimum
3896 This function scrolls the selected window @var{count} columns to the
3897 right (or to the left if @var{count} is negative).  The default
3898 for @var{count} is the window width, minus 2.  Aside from the direction
3899 of scrolling, this works just like @code{scroll-left}.
3900 @end deffn
3902 @defun window-hscroll &optional window
3903 This function returns the total leftward horizontal scrolling of
3904 @var{window}---the number of columns by which the text in @var{window}
3905 is scrolled left past the left margin.  The default for
3906 @var{window} is the selected window.
3908 The return value is never negative.  It is zero when no horizontal
3909 scrolling has been done in @var{window} (which is usually the case).
3912 @example
3913 @group
3914 (window-hscroll)
3915      @result{} 0
3916 @end group
3917 @group
3918 (scroll-left 5)
3919      @result{} 5
3920 @end group
3921 @group
3922 (window-hscroll)
3923      @result{} 5
3924 @end group
3925 @end example
3926 @end defun
3928 @defun set-window-hscroll window columns
3929 This function sets horizontal scrolling of @var{window}.  The value of
3930 @var{columns} specifies the amount of scrolling, in terms of columns
3931 from the left margin.  The argument @var{columns} should be zero or
3932 positive; if not, it is taken as zero.  Fractional values of
3933 @var{columns} are not supported at present.
3935 Note that @code{set-window-hscroll} may appear not to work if you test
3936 it by evaluating a call with @kbd{M-:} in a simple way.  What happens
3937 is that the function sets the horizontal scroll value and returns, but
3938 then redisplay adjusts the horizontal scrolling to make point visible,
3939 and this overrides what the function did.  You can observe the
3940 function's effect if you call it while point is sufficiently far from
3941 the left margin that it will remain visible.
3943 The value returned is @var{columns}.
3945 @example
3946 @group
3947 (set-window-hscroll (selected-window) 10)
3948      @result{} 10
3949 @end group
3950 @end example
3951 @end defun
3953    Here is how you can determine whether a given position @var{position}
3954 is off the screen due to horizontal scrolling:
3956 @example
3957 @group
3958 (defun hscroll-on-screen (window position)
3959   (save-excursion
3960     (goto-char position)
3961     (and
3962      (>= (- (current-column) (window-hscroll window)) 0)
3963      (< (- (current-column) (window-hscroll window))
3964         (window-width window)))))
3965 @end group
3966 @end example
3969 @node Coordinates and Windows
3970 @section Coordinates and Windows
3972 This section describes how to relate edges and screen coordinates to
3973 windows.
3975 @defun window-edges &optional window
3976 This function returns a list of the edge coordinates of @var{window}.
3977 The default for @var{window} is the selected window.
3979 The order of the list is @code{(@var{left} @var{top} @var{right}
3980 @var{bottom})}, all elements relative to 0, 0 at the top left corner of
3981 the frame.  The element @var{right} of the value is one more than the
3982 rightmost column used by @var{window}, and @var{bottom} is one more than
3983 the bottommost row used by @var{window} and its mode-line.
3985 The edges include the space used by the window's scroll bar, display
3986 margins, fringes, header line, and mode line, if it has them.  Also,
3987 if the window has a neighbor on the right, its right edge value
3988 includes the width of the separator line between the window and that
3989 neighbor.  Since the width of the window does not include this
3990 separator, the width does not usually equal the difference between the
3991 right and left edges.
3992 @end defun
3994 @defun window-inside-edges &optional window
3995 This is similar to @code{window-edges}, but the edge values
3996 it returns include only the text area of the window.  They
3997 do not include the header line, mode line, scroll bar or
3998 vertical separator, fringes, or display margins.
3999 @end defun
4001 Here are the results obtained on a typical 24-line terminal with just
4002 one window, with menu bar enabled:
4004 @example
4005 @group
4006 (window-edges (selected-window))
4007      @result{} (0 1 80 23)
4008 @end group
4009 @group
4010 (window-inside-edges (selected-window))
4011      @result{} (0 1 80 22)
4012 @end group
4013 @end example
4015 @noindent
4016 The bottom edge is at line 23 because the last line is the echo area.
4017 The bottom inside edge is at line 22, which is the window's mode line.
4019 If @var{window} is at the upper left corner of its frame, and there is
4020 no menu bar, then @var{bottom} returned by @code{window-edges} is the
4021 same as the value of @code{(window-total-height)}, @var{right} is the
4022 same as the value of @code{(window-total-width)}, and @var{top} and
4023 @var{left} are zero.  For example, the edges of the following window are
4024 @w{@samp{0 0 8 5}}.  Assuming that the frame has more than 8 columns,
4025 the last column of the window (column 7) holds a border rather than
4026 text.  The last row (row 4) holds the mode line, shown here with
4027 @samp{xxxxxxxxx}.
4029 @example
4030 @group
4031            0
4032            _______
4033         0 |       |
4034           |       |
4035           |       |
4036           |       |
4037           xxxxxxxxx  4
4039                   7
4040 @end group
4041 @end example
4043 In the following example, let's suppose that the frame is 7
4044 columns wide.  Then the edges of the left window are @w{@samp{0 0 4 3}}
4045 and the edges of the right window are @w{@samp{4 0 7 3}}.
4046 The inside edges of the left window are @w{@samp{0 0 3 2}},
4047 and the inside edges of the right window are @w{@samp{4 0 7 2}},
4049 @example
4050 @group
4051            ___ ___
4052           |   |   |
4053           |   |   |
4054           xxxxxxxxx
4056            0  34  7
4057 @end group
4058 @end example
4060 @defun window-pixel-edges &optional window
4061 This function is like @code{window-edges} except that, on a graphical
4062 display, the edge values are measured in pixels instead of in
4063 character lines and columns.
4064 @end defun
4066 @defun window-inside-pixel-edges &optional window
4067 This function is like @code{window-inside-edges} except that, on a
4068 graphical display, the edge values are measured in pixels instead of
4069 in character lines and columns.
4070 @end defun
4072 @defun window-at x y &optional frame
4073 This function returns the window containing the specified cursor
4074 position in the frame @var{frame}.  The coordinates @var{x} and @var{y}
4075 are measured in characters and count from the top left corner of the
4076 frame.  If they are out of range, @code{window-at} returns @code{nil}.
4078 If you omit @var{frame}, the selected frame is used.
4079 @end defun
4081 @defun coordinates-in-window-p coordinates window
4082 This function checks whether a particular frame position falls within
4083 the window @var{window}.
4085 The argument @var{coordinates} is a cons cell of the form @code{(@var{x}
4086 . @var{y})}.  The coordinates @var{x} and @var{y} are measured in
4087 characters, and count from the top left corner of the screen or frame.
4089 The value returned by @code{coordinates-in-window-p} is non-@code{nil}
4090 if the coordinates are inside @var{window}.  The value also indicates
4091 what part of the window the position is in, as follows:
4093 @table @code
4094 @item (@var{relx} . @var{rely})
4095 The coordinates are inside @var{window}.  The numbers @var{relx} and
4096 @var{rely} are the equivalent window-relative coordinates for the
4097 specified position, counting from 0 at the top left corner of the
4098 window.
4100 @item mode-line
4101 The coordinates are in the mode line of @var{window}.
4103 @item header-line
4104 The coordinates are in the header line of @var{window}.
4106 @item vertical-line
4107 The coordinates are in the vertical line between @var{window} and its
4108 neighbor to the right.  This value occurs only if the window doesn't
4109 have a scroll bar; positions in a scroll bar are considered outside the
4110 window for these purposes.
4112 @item left-fringe
4113 @itemx right-fringe
4114 The coordinates are in the left or right fringe of the window.
4116 @item left-margin
4117 @itemx right-margin
4118 The coordinates are in the left or right margin of the window.
4120 @item nil
4121 The coordinates are not in any part of @var{window}.
4122 @end table
4124 The function @code{coordinates-in-window-p} does not require a frame as
4125 argument because it always uses the frame that @var{window} is on.
4126 @end defun
4129 @node Window Configurations
4130 @section Window Configurations
4131 @cindex window configurations
4132 @cindex saving window information
4134   A @dfn{window configuration} records the entire layout of one
4135 frame---all windows, their sizes, which buffers they contain, how those
4136 buffers are scrolled, and their values of point and the mark; also their
4137 fringes, margins, and scroll bar settings.  It also includes the value
4138 of @code{minibuffer-scroll-window}.  As a special exception, the window
4139 configuration does not record the value of point in the selected window
4140 for the current buffer.
4142   You can bring back an entire frame layout by restoring a previously
4143 saved window configuration.  If you want to record the layout of all
4144 frames instead of just one, use a frame configuration instead of a
4145 window configuration; see @ref{Frame Configurations}.
4147 @defun current-window-configuration &optional frame
4148 This function returns a new object representing @var{frame}'s current
4149 window configuration.  The default for @var{frame} is the selected
4150 frame.
4151 @end defun
4153 @defun set-window-configuration configuration
4154 This function restores the configuration of windows and buffers as
4155 specified by @var{configuration}, for the frame that @var{configuration}
4156 was created for.
4158 The argument @var{configuration} must be a value that was previously
4159 returned by @code{current-window-configuration}.  The configuration is
4160 restored in the frame from which @var{configuration} was made, whether
4161 that frame is selected or not.  This always counts as a window size
4162 change and triggers execution of the @code{window-size-change-functions}
4163 (@pxref{Window Hooks}), because @code{set-window-configuration} doesn't
4164 know how to tell whether the new configuration actually differs from the
4165 old one.
4167 If the frame which @var{configuration} was saved from is dead, all this
4168 function does is restore the three variables @code{window-min-height},
4169 @code{window-min-width} and @code{minibuffer-scroll-window}. In this
4170 case, the function returns @code{nil}.  Otherwise, it returns @code{t}.
4172 Here is a way of using this function to get the same effect
4173 as @code{save-window-excursion}:
4175 @example
4176 @group
4177 (let ((config (current-window-configuration)))
4178   (unwind-protect
4179       (progn (split-window-vertically nil)
4180              @dots{})
4181     (set-window-configuration config)))
4182 @end group
4183 @end example
4184 @end defun
4186 @defspec save-window-excursion forms@dots{}
4187 This special form records the window configuration, executes @var{forms}
4188 in sequence, then restores the earlier window configuration.  The window
4189 configuration includes, for each window, the value of point and the
4190 portion of the buffer that is visible.  It also includes the choice of
4191 selected window.  However, it does not include the value of point in
4192 the current buffer; use @code{save-excursion} also, if you wish to
4193 preserve that.
4195 Don't use this construct when @code{save-selected-window} is sufficient.
4197 Exit from @code{save-window-excursion} always triggers execution of
4198 @code{window-size-change-functions}.  (It doesn't know how to tell
4199 whether the restored configuration actually differs from the one in
4200 effect at the end of the @var{forms}.)
4202 The return value is the value of the final form in @var{forms}.
4203 For example:
4205 @example
4206 @group
4207 (split-window)
4208      @result{} #<window 25 on control.texi>
4209 @end group
4210 @group
4211 (setq w (selected-window))
4212      @result{} #<window 19 on control.texi>
4213 @end group
4214 @group
4215 (save-window-excursion
4216   (delete-other-windows w)
4217   (switch-to-buffer "foo")
4218   'do-something)
4219      @result{} do-something
4220      ;; @r{The screen is now split again.}
4221 @end group
4222 @end example
4223 @end defspec
4225 @defun window-configuration-p object
4226 This function returns @code{t} if @var{object} is a window configuration.
4227 @end defun
4229 @defun compare-window-configurations config1 config2
4230 This function compares two window configurations as regards the
4231 structure of windows, but ignores the values of point and mark and the
4232 saved scrolling positions---it can return @code{t} even if those
4233 aspects differ.
4235 The function @code{equal} can also compare two window configurations; it
4236 regards configurations as unequal if they differ in any respect, even a
4237 saved point or mark.
4238 @end defun
4240 @defun window-configuration-frame config
4241 This function returns the frame for which the window configuration
4242 @var{config} was made.
4243 @end defun
4245   Other primitives to look inside of window configurations would make
4246 sense, but are not implemented because we did not need them.  See the
4247 file @file{winner.el} for some more operations on windows
4248 configurations.
4250   The objects returned by @code{current-window-configuration} die
4251 together with the Emacs process.  In order to store a window
4252 configuration on disk and read it back in another Emacs session the
4253 following two functions can be used.
4255 @defun window-state-get &optional window markers
4256 This function returns the state of @var{window} as a Lisp object.  The
4257 argument @var{window} can be any window and defaults to the root window
4258 of the selected frame.
4260 The optional argument @var{markers} non-@code{nil} means to use markers
4261 for sampling positions like @code{window-point} or @code{window-start}.
4262 This argument should be non-@code{nil} only if the value is used for
4263 putting the state back in the same session since markers slow down
4264 processing.
4266 The return value can be used as argument for @code{window-state-put},
4267 see below, to put the state recorded here into an arbitrary window.  The
4268 value can be also stored on disk and read back in a new session.
4269 @end defun
4271 The value returned by @code{window-state-get} can be converted by using
4272 one of the functions defined by Desktop Save Mode (@pxref{Desktop Save
4273 Mode}) to an object that can be written to a file.  Such objects can be
4274 read back and converted to a Lisp object representing the state of the
4275 window.  That Lisp object can be used as argument for the following
4276 function in order to restore the state window in anothe window.
4278 @defun window-state-put state &optional window ignore
4279 This function puts the window state @var{state} into @var{window}.  The
4280 argument @var{state} should be the state of a window returned by an
4281 earlier invocation of @code{window-state-get}, see above.  The optional
4282 argument @var{window} must specify a live window and defaults to the
4283 selected one.
4285 The optional argument @var{ignore} non-@code{nil} means to ignore
4286 minimum window sizes and fixed size restrictions.  If @var{ignore}
4287 equals @code{safe}, this means subwindows can get as small as
4288 @code{window-safe-min-height} and @code{window-safe-min-width}.
4289 @end defun
4292 @node Window Parameters
4293 @section Window Parameters
4294 @cindex window parameters
4296 This section describes how window parameters can be used to associate
4297 additional information with windows.
4299 @defun window-parameter window parameter
4300 This function returns @var{window}'s value for @var{parameter}.  The
4301 default for @var{window} is the selected window.  If @var{window} has no
4302 setting for @var{parameter}, this function returns @code{nil}.
4303 @end defun
4305 @defun window-parameters &optional window
4306 This function returns all parameters of @var{window} and their values.
4307 The default for @var{window} is the selected window.  The return value,
4308 if non-@code{nil} is an association list whose elements have the form
4309 @code{(@var{parameter} . @var{value})}.
4310 @end defun
4312 @defun set-window-parameter window parameter value
4313 This function sets @var{window}'s value of @var{parameter} to
4314 @var{value} and returns @var{value}.  The default for @var{window}
4315 is the selected window.
4316 @end defun
4318    A list of windows whose parameter equals some value is produced by
4319 the following function.
4321 @defun windows-with-parameter parameter &optional value frame any values
4322 This function returns a list of all windows on @var{frame} whose
4323 @var{parameter} is non-@code{nil}.  The optional argument @var{frame}
4324 must denote a live frame and defaults to the selected one.
4326 If the optional argument @var{value} is non-@code{nil}, this means to
4327 only return windows whose @var{parameter} equals @var{value} (comparison
4328 is done using @code{equal}).  Optional argument @var{any} non-@code{nil}
4329 means list internal windows a well.  Optional argument @var{values}
4330 non-@code{nil} means return a list of cons cells whose @sc{car} is the
4331 value of the parameter and whose @sc{cdr} is the window.
4332 @end defun
4334    The first window with a specified parameter can be retrieved with the
4335 following function.
4337 @defun window-with-parameter parameter &optional value frame any
4338 This function returns the first window on @var{frame} whose
4339 @var{parameter} is non-@code{nil}.  The optional argument @var{frame}
4340 must denote a live frame and defaults to the selected one.
4342 If the optional argument @var{value} is non-@code{nil}, this means to
4343 only return a window whose @var{parameter} equals @var{value}
4344 (comparison is done with @code{equal}).  If the optional argument
4345 @var{any} is non-@code{nil}, this means to consider internal windows
4346 too.
4347 @end defun
4349 Some functions, notably @code{delete-window},
4350 @code{delete-other-windows} and @code{split-window} may behave specially
4351 when their @var{window} argument has a parameter set.  For example,
4352 @code{delete-window}, when invoked on a subwindow of an atomic window
4353 (@pxref{Atomic Windows}), calls itself with the root of the atomic
4354 window as argument instead.
4356 You can override such special behavior by binding the following variable
4357 to a non-@code{nil} value:
4359 @defvar ignore-window-parameters
4360 If this variable is non-@code{nil}, some standard functions do not
4361 process window parameters.  The functions currently affected by this are
4362 @code{split-window}, @code{delete-window}, @code{delete-other-windows}
4363 and @code{other-window}.
4365 An application can bind this variable to a non-@code{nil} value around
4366 calls to these functions.  If it does so, the application is fully
4367 responsible for correctly assigning the parameters of all involved
4368 windows when exiting that function.
4369 @end defvar
4371 The following parameters are currently used by the window management
4372 code.
4374 @table @asis
4375 @item @code{window-atom}
4376 This parameter designates the associated window as part of an atomic
4377 window (@pxref{Atomic Windows}).
4379 @item @code{window-side}
4380 This parameter designates the associated window as part of a side or
4381 non-side window (@pxref{Side Windows}).
4383 @item @code{delete-window}
4384 This parameter affects the execution of @code{delete-window}
4385 (@pxref{Deleting Windows}).
4387 @item @code{delete-other-windows}
4388 This parameter affects the execution of @code{delete-other-windows}
4389 (@pxref{Deleting Windows}).
4391 @item @code{split-window}
4392 This parameter affects the execution of @code{split-window}
4393 (@pxref{Splitting Windows}).
4395 @item @code{other-window}
4396 This parameter affects the execution of @code{other-window}
4397 (@pxref{Cyclic Window Ordering}).
4399 @item @code{no-other-window}
4400 This parameter marks the window as not selectable by @code{other-window}
4401 (@pxref{Cyclic Window Ordering}).
4402 @end table
4404 The @code{quit-restore} parameter tells how to proceed with a window
4405 when the buffer it shows is no more needed.  This parameter is installed
4406 by the buffer display functions (@pxref{Displaying Buffers}) and
4407 consulted by functions that remove a buffer from display like
4408 @code{delete-windows-on} (@pxref{Deleting Windows}),
4409 @code{replace-buffer-in-windows} (@pxref{Buffers and Windows}), and
4410 @code{quit-restore-window} (@pxref{Displaying Buffers}).  The parameter
4411 should be a list which is interpreted as sketched next.
4413    If the first element of the list is the symbol @code{new-window},
4414 this means that the window was specially created for displaying a
4415 buffer.  The second element of the list specifies that buffer, and the
4416 third element is the window selected at the time this window was
4417 created.  The standard action in this case is to delete the window
4418 provided its frame contains at least on other window.
4420   If the first element of the list is the symbol @code{new-frame}, this
4421 means that the associated frame was created for displaying a buffer.
4422 The remaining elements are as above.  The standard action in this case
4423 is to delete the frame provided there are other frames left.
4425   In any other case, the list should consist of five elements: A buffer
4426 that was shown in the window before, the start position of that buffer
4427 in the window, the position of @code{window-point} for that buffer in
4428 the window, the total height of the window before another buffer was
4429 displayed in it, and the window selected at the time that other buffer
4430 was displayed.  The standard action here is to keep the window alive and
4431 to restore its contents to the state provided by these elements.
4434 @node Atomic Windows
4435 @section Atomic Windows
4436 @cindex atomic windows
4438 An @dfn{atomic window} is an internal window (@pxref{Basic Windows})
4439 built from two or more subwindows.  For any subwindow of an atomic
4440 window the behavior of a number of operations changes in the sense that
4441 the operation is suitably applied to the entire atomic window instead.
4443    Atomic windows are useful when you're using two side-by-side windows
4444 to compare or merge buffers.  In this case, you probably don't want
4445 commands like @code{display-buffer} or @kbd{C-x 2} break your window
4446 layout by splitting one of these windows.  Making these windows part of
4447 an atomic window guarantees that the entire atomic window is split
4448 instead.
4450    Another use of atomic windows is that of a sidebar, toolbar or tabbar
4451 appearing on the left or above a ``main'' window.  In this case,
4452 splitting the main window should not break the correspondence between
4453 the bar and the main window.  With atomic windows the relationship
4454 between the bar and the main window remains untouched.
4456    Atomic windows can be created by calling @code{display-buffer}
4457 (@pxref{Displaying Buffers}) with a non-@code{nil} @code{pop-up-window}
4458 and @code{atomic} specifier.  The following call displays a buffer named
4459 ``*bar*'' in a 10 columns wide window on the left of the selected
4460 window.
4462 @example
4463 (display-buffer
4464  (get-buffer-create "*bar*")
4465  '((pop-up-window (selected . left))
4466    (pop-up-window-set-width . 10)
4467    (atomic . t)))
4468 @end example
4470 Alternatively, applications can use @code{display-buffer-pop-up-window}
4471 (@pxref{Displaying Buffers}) in order to make sure that the buffer is
4472 not displayed in some other window provided the selected window can't be
4473 split.
4475 @example
4476 (display-buffer-pop-up-window
4477  (get-buffer-create "*bar*")
4478  '((selected . left))
4479  '((pop-up-window-set-width . 10) (atomic . nest)))
4480 @end example
4482 To make an internal window atomic use the following function:
4484 @defun make-window-atom window
4485 This function make @var{window} an atomic window.  The argument
4486 @var{window} must be an internal window.  It returns @var{window}.
4487 @end defun
4489    Atomic windows are implemented by setting their @code{window-atom}
4490 parameter (@pxref{Window Parameters}) and that of their subwindows to
4491 @code{t}.  To check whether a given window is or is part of an atomic
4492 window simply look at that parameter.  If
4494 @smallexample
4495 (window-parameter window 'window-atom)
4496 @end smallexample
4498 returns @code{t}, the window is part of an atomic window.  To find the
4499 atomic window a given window is part of, use the following function:
4501 @defun window-atom-root window
4502 This function returns the atomic window @var{window} belongs to;
4503 @code{nil} if @var{window} is not part of an atomic window.
4504 @end defun
4506    By default, the behavior of the following commands changes when their
4507 window argument is a member of an atomic window and the variable
4508 @code{ignore-window-parameters} is non-@code{nil}.
4510 @table @asis
4511 @item @code{split-window} (@pxref{Splitting Windows})
4512 When @var{window} is part of an atomic window, @code{split-window} tries
4513 to split the atomic window instead.
4515 @item @code{delete-window} (@pxref{Deleting Windows})
4516 When @var{window} is part of an atomic window, @code{delete-window}
4517 deletes the atomic window instead.  If that window is the root window of
4518 its containing frame, an error is signalled.
4520 @item @code{delete-other-windows} (@pxref{Deleting Windows})
4521 When @var{window} is part of an atomic window,
4522 @code{delete-other-windows} makes the atomic window fill its frame.  If
4523 the atomic window is a non-side window (@pxref{Side Windows}), all other
4524 non-side windows are removed.  If the atomic window is a side window, an
4525 error is signalled.
4526 @end table
4528 You can override the default behavior of these commands by using an
4529 appropriate @code{split-window-function}, @code{delete-window-function}
4530 or @code{delete-other-windows-function}.
4532 The following two invariants must be maintained by all operations on
4533 atomic windows:
4535 @itemize @bullet
4536 @item
4537 An atomic window must contain at least two subwindows.
4539 @item
4540 The @code{window-atom} parameter of an atomic window and of any of its
4541 subwindows must be @code{t}.
4542 @end itemize
4544 Atomic windows violating these invariants are automatically dissolved.
4545 Their component windows continue to exist as normal windows.  Operating
4546 on them, however, is no more different from operating on any other
4547 window.
4550 @node Side Windows
4551 @section Side Windows
4552 @cindex side windows
4553 @cindex non-side windows
4555 A @dfn{side window} is a special window located at one of the four sides
4556 of a frame.  Side windows are useful for assigning buffers always the
4557 same location within a frame whenever they are shown there.  Typically,
4558 side windows would be used for viewing compiler or grep output, buffer
4559 or file listings, completions, or system messages.  They would be
4560 arranged around a set of ``non-side'' windows used for buffers that are
4561 edited.
4563    The following option specifies the layout of side windows on a frame.
4565 @defopt window-sides-vertical
4566 If non-@code{nil}, this variable specifies that left and right side
4567 windows are as high as the containing frame.  Otherwise, top and bottom
4568 side windows are as wide as the containing frame.
4570 Changing this option while side-windows are displayed may lead to
4571 unexpected layouts and should be avoided.
4572 @end defopt
4574 If @code{window-sides-vertical} is @code{nil}, side windows appear as
4575 follows:
4577 @smallexample
4578 @group
4579          ______________________________________ 
4580         |                                      |
4581         |              Top Window              |
4582         |______________________________________|
4583         |        |                    |        |
4584         | Left   |                    | Right  |
4585         | Side   |   Non-side Window  | Side   |
4586         | Window |                    | Window |
4587         |________|____________________|________|
4588         |                                      |
4589         |             Bottom Window            |
4590         |______________________________________|
4592 @end group
4593 @end smallexample
4595 If @code{window-sides-vertical} is non-@code{nil}, side windows are
4596 displayed as follows:
4598 @smallexample
4599 @group
4600          ______________________________________ 
4601         |        |                    |        |
4602         |        |     Top Window     |        |
4603         |        |____________________|        |
4604         |        |                    |        |
4605         | Left   |                    | Right  |
4606         | Side   |   Non-side Window  | Side   |
4607         | Window |                    | Window |
4608         |        |____________________|        |
4609         |        |                    |        |
4610         |        |    Bottom Window   |        |
4611         |________|____________________|________|
4613 @end group
4614 @end smallexample
4616    Side windows can be arbitrarily subdivided.  For each side of a frame
4617 there exists at most one dominating side window which contains all other
4618 windows on the same side as subwindows.  As a rule, windows on the left
4619 or right side of a frame should be vertical combinations.  Windows on
4620 the top or bottom of a frame should be horizontal combinations.  This
4621 makes it easier to assign each life side window a corresponding slot.
4623 @cindex side window slot
4624 A @dfn{side window slot} indicates the relative position of a side
4625 window within the dominating window on that side.  Slots are arbitrary
4626 numbers where the value zero roughly stands for a window in the middle
4627 of that side.  Negative numbers indicate a position above the middle
4628 window (for left and right side windows) or on the left (for the top and
4629 bottom side windows).  Positive numbers stand for windows below the
4630 middle window (for left and right side windows) or on the right (for top
4631 and bottom side windows).
4633 The example below depicts a layout with three subwindows on the top and
4634 two subwindows at the bottom of the frame.
4636 @smallexample
4637 @group
4638          ______________________________________ 
4639         | Left Top   | Middle Top |  Right Top |
4640         | Window     | Window     |  Window    |
4641         |____________|____________|____________|
4642         |        |                    |        |
4643         | Left   |                    | Right  |
4644         | Side   |   Non-side Window  | Side   |
4645         | Window |                    | Window |
4646         |________|____________________|________|
4647         | Left Bottom      |      Right Bottom |
4648         | Window           |      Window       |
4649         |__________________|___________________|
4651 @end group
4652 @end smallexample
4654 The following option can be used to limit the number of subwindows that
4655 may appear on any side of a frame.
4657 @defopt window-sides-slots
4658 This is a list of four elements specifying the number of side window
4659 slots on (in this order) the left, top, right and bottom side of each
4660 frame.  If an element is a number, this means to display at most that
4661 many side windows on the corresponding side.  If an element is
4662 @code{nil}, this means there's no bound on the number of slots on that
4663 side.
4664 @end defopt
4666    Side windows are implemented with the help of @code{window-side}
4667 parameters (@pxref{Window Parameters}).  This parameter is @code{left},
4668 @code{top}, @code{right} or @code{bottom} for a window on the
4669 corresponding side and @code{none} for a non-side window.  The
4670 dominating window on each side as well as the dominating non-side window
4671 have parents whose @code{window-side} parameter is nil.  To get the
4672 dominating side window on the left, for example, use the function
4673 @code{window-with-parameter} like
4675 @smallexample
4676 (window-with-parameter 'window-side 'left nil t)
4677 @end smallexample
4679    If you create side windows by calling @code{display-buffer}
4680 (@pxref{Displaying Buffers}) with the @code{use-side-window} specifier,
4681 this will set up these parameters automatically.  For example
4683 @example
4684 (display-buffer
4685  (get-buffer-create "*bar*")
4686  '((use-side-window bottom 0)
4687    (pop-up-window-set-height . 6)))
4688 @end example
4690 can be used to display a buffer ``*bar*'' in a six lines high
4691 side-window at the bottom of the selected frame.
4693 If you intend to manage side windows manually, you should preserve the
4694 following invariants:
4696 @itemize @bullet
4697 @item
4698 If a frame has a side window, a non-side window must exist on that frame
4699 as well.  If a frame has a non-side window, at least one side window
4700 must exist on that frame too.
4702 @item
4703 If a window has a non-@code{nil} @code{window-side} parameter, it must
4704 have a parent window and the parent window's @code{window-side}
4705 parameter must be either @code{nil} or the same as for the window.
4707 @item
4708 For any of the values @code{left}, @code{top}, @code{right},
4709 @code{bottom} and @code{none} there can be only one dominating window
4710 whose @code{window-side} parameter equals that value.  More precisely,
4711 this means that at most one window can have its @code{window-side}
4712 parameter set to such a value and have a parent window whose
4713 @code{window-side} parameter is @code{nil}.
4715 @item
4716 If a frame contains at least one window with a non-@code{nil}
4717 @code{window-side} parameter, the @code{window-side} parameter of all
4718 other live windows must be non-@code{nil} as well.
4719 @end itemize
4721 If a setup of @code{window-side} parameters fails to satisfy these
4722 invariants, Emacs will reset all @code{window-side} parameters on that
4723 frame to @code{nil}.  Otherwise, the window configuration remains
4724 unchanged.
4726 The behavior of the following commands and functions changes in the
4727 presence of side windows.
4729 @table @asis
4730 @item @code{split-window} (@pxref{Splitting Windows})
4731 If the function @code{split-window} splits a window with a
4732 non-@code{nil} @code{window-side} parameter it assigns the new window
4733 the same parameter value.
4735 @item @code{delete-window} (@pxref{Deleting Windows})
4736 The function @code{delete-window} signal an error when it is invoked
4737 with a non-side window as argument and there are side windows on the
4738 associated frame.
4740 @item @code{delete-other-windows} (@pxref{Deleting Windows})
4741 When @code{delete-other-windows} is invoked with a non-side window as
4742 argument, it will delete all other non-side windows (for an internal
4743 window all non-side windows that are not a subwindow of this window),
4744 When @code{delete-other-windows} is called with a side window as
4745 argument it signals an error.
4746 @end table
4749 @node Window Hooks
4750 @section Hooks for Window Scrolling and Changes
4751 @cindex hooks for window operations
4753 This section describes how a Lisp program can take action whenever a
4754 window displays a different part of its buffer or a different buffer.
4755 There are three actions that can change this: scrolling the window,
4756 switching buffers in the window, and changing the size of the window.
4757 The first two actions run @code{window-scroll-functions}; the last runs
4758 @code{window-size-change-functions}.
4760 @defvar window-scroll-functions
4761 This variable holds a list of functions that Emacs should call before
4762 redisplaying a window with scrolling.  Displaying a different buffer in
4763 the window also runs these functions.
4765 This variable is not a normal hook, because each function is called with
4766 two arguments: the window, and its new display-start position.
4768 These functions must be careful in using @code{window-end}
4769 (@pxref{Window Start and End}); if you need an up-to-date value, you
4770 must use the @var{update} argument to ensure you get it.
4772 @strong{Warning:} don't use this feature to alter the way the window
4773 is scrolled.  It's not designed for that, and such use probably won't
4774 work.
4775 @end defvar
4777 @defvar window-size-change-functions
4778 This variable holds a list of functions to be called if the size of any
4779 window changes for any reason.  The functions are called just once per
4780 redisplay, and just once for each frame on which size changes have
4781 occurred.
4783 Each function receives the frame as its sole argument.  There is no
4784 direct way to find out which windows on that frame have changed size, or
4785 precisely how.  However, if a size-change function records, at each
4786 call, the existing windows and their sizes, it can also compare the
4787 present sizes and the previous sizes.
4789 Creating or deleting windows counts as a size change, and therefore
4790 causes these functions to be called.  Changing the frame size also
4791 counts, because it changes the sizes of the existing windows.
4793 It is not a good idea to use @code{save-window-excursion} (@pxref{Window
4794 Configurations}) in these functions, because that always counts as a
4795 size change, and it would cause these functions to be called over and
4796 over.  In most cases, @code{save-selected-window} (@pxref{Selecting
4797 Windows}) is what you need here.
4798 @end defvar
4800 @defvar window-configuration-change-hook
4801 A normal hook that is run every time you change the window configuration
4802 of an existing frame.  This includes splitting or deleting windows,
4803 changing the sizes of windows, or displaying a different buffer in a
4804 window.
4806 The buffer-local part of this hook is run once per each window on the
4807 affected frame, with the relevant window selected and its buffer
4808 current.  The global part is run once for the modified frame, with that
4809 frame selected.
4810 @end defvar
4812   In addition, you can use @code{jit-lock-register} to register a Font
4813 Lock fontification function, which will be called whenever parts of a
4814 buffer are (re)fontified because a window was scrolled or its size
4815 changed.  @xref{Other Font Lock Variables}.