Merge from trunk
[emacs.git] / doc / lispref / windows.texi
blob3b77fef4c3daaac3adfe0474ed0ef2fb912bd15e
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):
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-vchild
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.
305 In our canonical example @code{(window-iso-combined-p W5)} and
306 @code{(window-iso-combined-p W6 t)} both evaluate to @code{t} while
307 @code{(window-iso-combined-p W6)} is @code{nil}.
308 @end defun
310 @cindex sibling window
311 For any window that is part of a combination, the other windows in that
312 combination are called the window's @dfn{siblings}.  The only windows
313 that do not have siblings are root windows of frames and minibuffer
314 windows.  A window's siblings can be retrieved with the following two
315 functions.
317 @defun window-next &optional window
318 This function returns @var{window}'s right sibling.  The optional
319 argument @var{window} can be an arbitrary window and defaults to the
320 selected window.  It returns @code{nil} if @var{window} has no right
321 sibling.  Applying this function recursively will eventually get you to
322 the last child of @var{window}'s parent.  In our example
323 @code{(window-next W2)} is @code{W3} while @code{(window-next W3)} is
324 @code{nil}.
325 @end defun
327 @defun window-prev &optional window
328 This function returns @var{window}'s left sibling.  The optional
329 argument @var{window} can be an arbitrary window and defaults to the
330 selected window.  It returns @code{nil} if @var{window} has no left
331 sibling.  Applying this function recursively will eventually get you to
332 the first child of @var{window}'s parent.  In our example
333 @code{(window-prev W3)} is @code{W2} and @code{(window-prev W2)} is
334 @code{nil}.
335 @end defun
337 The functions @code{window-next} and @code{window-prev} should not be
338 confused with the functions @code{next-window} and
339 @code{previous-window} which respectively return the next and previous
340 window in the cyclic ordering of windows, see @ref{Cyclic Window
341 Ordering}.
343    In order to find the first live window on a frame, the following
344 function can be used.
346 @defun frame-first-window &optional frame-or-window
347 This function returns the live window at the upper left corner of the
348 frame specified by @var{frame-or-window}.  The argument
349 @var{frame-or-window} must denote a window or a live frame and defaults
350 to the selected frame.  If @var{frame-or-window} specifies a window,
351 this function returns the first window on that window's frame.  Under
352 the assumption that the frame from our canonical example is selected
353 @code{(frame-first-window)} returns @code{W2}.
354 @end defun
356 You can get the window tree of a frame with the following function.
358 @cindex window tree
359 @defun window-tree &optional frame
360 This function returns the window tree for frame @var{frame}.  The
361 optional argument @var{frame} must be a live frame and defaults to the
362 selected one.
364 The return value is a list of the form @code{(@var{root} @var{mini})},
365 where @var{root} represents the window tree of the frame's
366 root window, and @var{mini} is the frame's minibuffer window.
368 If the root window is live, @var{root} specifies the root window and
369 nothing else.  Otherwise, @var{root} is a list @code{(@var{dir}
370 @var{edges} @var{w1} @var{w2} ...)} where @var{dir} is @code{nil} for a
371 horizontal combination, and @code{t} for a vertical combination,
372 @var{edges} gives the size and position of the combination, and the
373 remaining elements are the child windows.  Each child window may again
374 be a live window or a list representing a window combination, and so on.
375 The @var{edges} element is a list @code{(@var{left}@var{ top}@var{
376 right}@var{ bottom})} similar to the value returned by
377 @code{window-edges}, see @ref{Coordinates and Windows}.
378 @end defun
381 @node Window Sizes
382 @section Window Sizes
383 @cindex window size
384 @cindex size of window
386 Emacs windows are rectangular.  The structure of a live window can be
387 roughly sketched as follows:
389 @smallexample
390 @group
391          _________________________________________ 
392       ^ |______________ Header Line_______________| 
393       | |LS|LF|LM|                       |RM|RF|RS| ^
394       | |  |  |  |                       |  |  |  | |
395  Window |  |  |  |       Text Area       |  |  |  | Window
396  Total  |  |  |  |     (Window Body)     |  |  |  | Body
397  Height |  |  |  |                       |  |  |  | Height
398       | |  |  |  |<- Window Body Width ->|  |  |  | |
399       | |__|__|__|_______________________|__|__|__| v
400       v |_______________ Mode Line _______________|
402          <----------- Window Total Width -------->
404 @end group
405 @end smallexample
407 @cindex window body
408 @cindex body of a window
409 The text area constitutes the body of the window.  In its most simple
410 form, a window consists of its body alone.  LS and RS stand for the left
411 and right scroll bar (@pxref{Scroll Bars}) respectively.  Only one of
412 them can be present at any time.  LF and RF denote the left and right
413 fringe, see @ref{Fringes}.  LM and RM, finally, stand for the left and
414 right display margin, see @ref{Display Margins}.  The header line, if
415 present, is located above theses areas, the mode line below, see
416 @ref{Mode Line Format}.
418 @cindex window height
419 @cindex total window height
420 @cindex height of a window
421 @cindex total height of a window
422 The @dfn{total height of a window} is specified as the total number of
423 lines occupied by the window.  Any mode or header line is included in a
424 window's total height.  For an internal window, the total height is
425 calculated recursively from the total heights of its child windows.
427 @cindex window width
428 @cindex total window width
429 @cindex width of a window
430 @cindex total width of a window
431 The @dfn{total width of a window} denotes the total number of columns of
432 the window.  Any scroll bar and the column of @samp{|} characters that
433 separate the window from its right sibling are included in a window's
434 total width.  On a window-system, fringes and display margins are
435 included in a window's total width too.  For an internal window, the
436 total width is calculated recursively from the total widths of its child
437 windows.
439 @cindex total size of a window
440 @cindex total window size
441 The following function is the standard interface for getting the total
442 size of any window:
444 @defun window-total-size &optional window &optional horizontal
445 This function returns the total number of lines of @var{window}.  The
446 argument @var{window} can denote any window and defaults to the selected
447 one.  If @var{window} is live, the return value includes any header or
448 mode lines of @var{window}.  If @var{window} is internal, the return
449 value is the sum of the total heights of @var{window}'s child windows
450 provided these are vertically combined and the height of @var{window}'s
451 first child if they are horizontally combined.
453    If the optional argument @var{horizontal} is non-@code{nil}, this
454 function returns the total number of columns of @var{window}.  If
455 @var{window} is live, the return value includes any vertical divider
456 column or scroll bars of @var{window}.  On a window-system, the return
457 value includes the space occupied by any margins and fringes of
458 @var{window} too.  If @var{window} is internal, the return value is the
459 sum of the total widths of @var{window}'s child windows provided these
460 are horizontally combined and the width of @var{window}'s first child
461 otherwise.
462 @end defun
464 Alternatively, the following two functions can be used to retrieve
465 either the total height of the total width of a window:
467 @defun window-total-height &optional window
468 This function returns the total number of lines of @var{window}.
469 @var{window} can be any window and defaults to the selected one.  The
470 return value includes @var{window}'s mode line and header line, if any.
471 If @var{window} is internal the return value is the sum of heights of
472 @var{window}'s child windows for a vertical combination and the height
473 of @var{window}'s first child otherwise.
474 @end defun
476 @defun window-total-width &optional window
477 This function returns the total number of columns of @var{window}.
478 @var{window} can be any window and defaults to the selected one.  The
479 return value includes any vertical dividers or scrollbars of
480 @var{window}.  On a window-system the return value also includes the
481 space occupied by any margins and fringes of @var{window}.  If
482 @var{window} is internal, the return value is the sum of the widths of
483 @var{window}'s child windows for a horizontal combination and the width
484 of @var{window}'s first child otherwise.
485 @end defun
487 The total height of any window is usually less than the height of the
488 window's frame, because the latter may also include the minibuffer
489 window.  Depending on the toolkit in use, the frame height can also
490 include the menu bar and the tool bar (@pxref{Size and Position}).
491 Therefore, in general it is not straightforward to compare window and
492 frame heights.  The following function is useful to determine whether
493 there are no other windows above or below a specified window.
495 @cindex full-height window
496 @defun window-full-height-p &optional window
497 This function returns non-@code{nil} if there is no other window above
498 or below @var{window} on the containing frame.  More precisely, this
499 function returns @code{t} if and only if the total height of
500 @var{window} equals the total height of the root window (@pxref{Windows
501 and Frames}) of @var{window}'s frame.  The @var{window} argument may
502 denote any window and defaults to the selected one.
503 @end defun
505 @cindex full-width window
506 The following function can be used to determine whether there are no
507 other windows on the left or right of a specified window.
509 @defun window-full-width-p &optional window
510 This function returns non-@code{nil} if there are no other windows on
511 the left or right of @var{window}; @code{nil} otherwise.  More
512 precisely, this function returns @code{t} if and only if the total width
513 of @var{window} equals the total width of the root window
514 (@pxref{Windows and Frames}) of @var{window}'s frame.  The @var{window}
515 argument may denote any window and defaults to the selected one.
516 @end defun
518 @cindex top line of window
519 @cindex left column of window
520   The windows of a frame are unambiguously characterized by the
521 combination of their top line and left column within that frame.
523 @defun window-top-line &optional window
524 This function returns the top line of @var{window}.  The argument
525 @var{window} can denote any window and defaults to the selected one.
526 @end defun
528 @defun window-left-column &optional window
529 This function returns the left column of @var{window}.  The argument
530 @var{window} can denote any window and defaults to the selected one.
531 @end defun
533 For a frame displaying one window only, that window's top line and left
534 column are both zero.  When a frame displays a window @var{WB} below a
535 window @var{WA}, the top line of @var{WB} can be calculated by adding
536 the total height of @var{WA} to the top line of @var{WA}.  When a frame
537 displays a window @var{WR} on the right of a window @var{WL}, the left
538 column of @var{WR} can be calculated by adding the total width of
539 @var{WL} to the left column of @var{WL}.
541 @cindex window body height
542 @cindex body height of a window
543 The @dfn{body height of a window} is specified as the total number of
544 lines occupied by the window's text area.  Mode or header lines are not
545 included in a window's body height.
547 @cindex window body width
548 @cindex body width of a window
549 The @dfn{body width of a window} denotes the total number of columns
550 occupied by the window's text area.  Scroll bars or columns of @samp{|}
551 characters that separates side-by-side windows are not included in a
552 window's body width.
554 @cindex body size of a window
555 @cindex window body size
556 The following functions retrieve height and width of the body of a live
557 window:
559 @defun window-body-size &optional window horizontal
560 This function returns the number of lines of @var{window}'s text area.
561 @var{window} must be a live window and defaults to the selected one.
562 The return value does not count any mode or header line of @var{window}.
564 Optional argument @var{horizontal} non-@code{nil} means to return the
565 number of columns of @var{window}'s text area.  In this case the return
566 value does not include any vertical divider or scroll bar owned by
567 @var{window}.  On a window-system the return value does not include the
568 number of columns used for @var{window}'s fringes or display margins
569 either.
570 @end defun
572 @defun window-body-height &optional window
573 This function returns the number of lines of @var{window}'s body.
574 @var{window} must be a live window and defaults to the selected one.
576 The return value does not include @var{window}'s mode line and header
577 line, if any.  If a line at the bottom of the window is only partially
578 visible, that line is included in the return value.  If you do not
579 want to include a partially visible bottom line in the return value,
580 use @code{window-text-height} instead.
581 @end defun
583 @defun window-body-width &optional window
584 This function returns the number of columns of @var{window}'s body.
585 @var{window} must be a live window and defaults to the selected one.
587 The return value does not include any vertical dividers or scroll bars
588 owned by @var{window}.  On a window-system the return value does not
589 include the number of columns used for @var{window}'s fringes or
590 display margins either.
591 @end defun
593 The following functions have been used in earlier versions of Emacs.
594 They are still supported but due to the confusing nomenclature they
595 should not be used any more in future code.
597 @defun window-height &optional window
598 This function is an alias for `window-total-height', see above.
599 @end defun
601 @defun window-width &optional window
602 This function is an alias for `window-body-width', see above.
603 @end defun
605 @cindex minimum window size
606   The following two options constrain the sizes of windows to a minimum
607 height and width.  Their values are honored when windows are split
608 (@pxref{Splitting Windows}) or resized (@pxref{Resizing Windows}).  Any
609 request to make a window smaller than specified here will usually result
610 in an error.
612 @defopt window-min-height
613 The value of this variable specifies how short a window may be.  The
614 value is measured in line units and has to account for any header or
615 mode line.  The default value for this option is @code{4}.  Values less
616 than @code{1} are ignored.
617 @end defopt
619 @defopt window-min-width
620 The value of this variable specifies how narrow a window may be.  The
621 value is measured in characters and includes any margins, fringes,
622 scroll bar and vertical divider column.  The default value for this
623 option is @code{10}.  A value less than @code{2} is ignored.
624 @end defopt
626 Applications should not rebind these variables.  To shrink a specific
627 window to a height or width less than the one specified here, they
628 should rather invoke @code{resize-window} (@pxref{Resizing Windows})
629 with a non-@code{nil} @var{ignore} argument.  The function
630 @code{split-window} (@pxref{Splitting Windows}) can make a window
631 smaller than specified here by calling it with a non-@code{nil}
632 @var{size} argument.  Interactively, the values specified here cannot be
633 overridden.
635    Earlier versions of Emacs could delete a window when its size dropped
636 below @code{window-min-height} or @code{window-min-width}.  As a rule,
637 the current version of Emacs does no more delete windows by side-effect.
638 The only exception to this rule are requests to resize a frame which may
639 implicitly delete windows when they do not fit on the frame any more,
640 see @ref{Size and Position}.
642    The size of a window can be fixed which means that it cannot be split
643 (@pxref{Splitting Windows}) or resized (@pxref{Resizing Windows}).
645 @cindex fixed-size window
646 @defvar window-size-fixed
647 If this variable is non-@code{nil}, in a given buffer, then the size of
648 any window displaying that buffer remains fixed unless you either
649 explicitly change it or Emacs has no other choice.
651 If the value is @code{height}, then only the window's height is fixed;
652 if the value is @code{width}, then only the window's width is fixed.
653 Any other non-@code{nil} value fixes both the width and the height.
655 This variable automatically becomes buffer-local when set.
656 @end defvar
658 Commands supposed to explicitly change the size of windows such as
659 @code{enlarge-window} (@pxref{Resizing Windows}) get an error if they
660 had to change a window size which is fixed.  Other functions like
661 @code{resize-window} (@pxref{Resizing Windows}) have an optional
662 @var{ignore} argument which allows to change the size of fixed-size
663 windows.
665    Deleting a window or changing a frame's size may change the size of a
666 fixed-size window, if there is no other alternative.
668    A vertical combination of windows cannot be resized when the height
669 of all windows in that combination is fixed.  A horizontal combination
670 cannot be resized when the width of all windows in it is fixed.  The
671 next function allows to check whether the size of an arbitrary window is
672 fixed.
674 @defun window-size-fixed-p &optional window horizontal
675 This function returns non-@code{nil} if @var{window}'s height is fixed.
676 The argument @var{window} can be an arbitrary window and defaults to the
677 selected one.  Optional argument @var{horizontal} non-@code{nil} means
678 return non-@code{nil} if @var{window}'s width is fixed.
680 If this function returns @code{nil}, this does not necessarily mean that
681 @var{window} can be resized in the desired direction.  The function
682 @code{window-resizable} (@pxref{Resizing Windows}) can tell that.
683 @end defun
686 @node Resizing Windows
687 @section Resizing Windows
688 @cindex window resizing
689 @cindex resize window
690 @cindex changing window size
691 @cindex window size, changing
693 Emacs does not permit overlapping windows or gaps between windows, so
694 changing the size of a window always affects at least one other window.
695 When a frame contains just one window, that window can be resized only
696 by resizing the window's frame.  The functions described below are
697 therefore meaningful only in the context of a frame containing at least
698 two windows.  The size of the corresponding frame never changes when
699 invoking a function described in this section.
701    The routines changing window sizes always operate in one dimension at
702 a time.  This means that windows can be resized only either vertically
703 or horizontally.  If a window shall be resized in both dimensions, it
704 must be resized in one dimension first and in the other dimension
705 afterwards.  If the second resize operation fails, the frame might end
706 up in an unsatisfactory state.  To avoid such states, it might be useful
707 to save the current window configuration (@pxref{Window Configurations})
708 before attempting the first resize operation and restore the saved
709 configuration in case the second resize operation fails.
711    Functions that resize windows are supposed to obey restrictions
712 imposed by window minimum sizes and fixed-size windows, see @ref{Window
713 Sizes}.  In order to determine whether resizing a specific window is
714 possible in the first place, the following function can be used:
716 @defun window-resizable window delta &optional horizontal ignore side noup nodown
717 This function returns @var{delta} if the size of @var{window} can be
718 changed vertically by @var{delta} lines.  Optional argument
719 @var{horizontal} non-@code{nil} means to return @var{delta} if
720 @var{window} can be resized horizontally by @var{delta} columns.  A
721 return value of zero means that @var{window} is not resizable.
723 If @var{delta} is a positive number, this means that @var{window} shall
724 be enlarged by @var{delta} lines or columns.  If @var{window} cannot be
725 enlarged by @var{delta} lines or columns this function returns the
726 maximum value in the range from 0 to @var{delta} by which @var{window}
727 can be enlarged.
729 If @var{delta} is a negative number, this means that @var{window} shall
730 be shrunk by -@var{delta} lines or columns.  If @var{window} cannot be
731 shrunk by -@var{delta} lines or columns, this function returns the
732 minimum value in the range from @var{delta} to 0 that can be used for
733 shrinking @var{window}.
735 Optional argument @var{ignore} non-@code{nil} means ignore any
736 restrictions imposed by the variables @code{window-min-height} or
737 @code{window-min-width} and @code{window-size-fixed}.  In this case the
738 minimum height of a window is specified as the minimum number of lines
739 that allow viewing any header or mode line and at least one line of the
740 text area of window.  The minimum width of a window includes any
741 fringes, margins and the scroll bar as well as two text columns.
743 If @var{ignore} denotes a window, this means to ignore restrictions for
744 that window only.  If @var{ignore} equals the constant @code{safe}, this
745 means a live window may get as small as one line or two columns.
747 Optional argument @var{noup} non-@code{nil} means don't go up in the
748 window tree but try to steal or distribute the space needed for the
749 resize operation among the other windows within @var{window}'s
750 combination.  Optional argument @var{nodown} non-@code{nil} means don't
751 check whether @var{window} and its subwindows can be resized.
752 @end defun
754 The function @code{window-resizable} does not change any window sizes.
755 The following function does:
757 @defun resize-window window delta &optional horizontal ignore
758 This function resizes @var{window} vertically by @var{delta} lines.  The
759 argument @var{window} can denote an arbitrary window and defaults to the
760 selected one.  An attempt to resize the root window of a frame will
761 raise an error.
763 Second argument @var{delta} a positive number means @var{window} shall
764 be enlarged by @var{delta} lines.  If @var{delta} is negative, that
765 means @var{window} shall be shrunk by -@var{delta} lines.
767 Optional argument @var{horizontal} non-@code{nil} means to resize
768 @var{window} horizontally by @var{delta} columns.  In this case a
769 positive @var{delta} means enlarge @var{window} by @var{delta} columns.
770 A negative @var{delta} means @var{window} shall be shrunk by
771 -@var{delta} columns.
773 Optional argument @var{ignore} has the same meaning as for the function
774 @code{window-resizable} above.
776 This function resizes other windows proportionally and never deletes any
777 windows.  If only the low (right) edge of @var{window} shall be moved,
778 the function @code{adjust-window-trailing-edge} described below should
779 be used.
780 @end defun
782 The next four commands are simple interfaces to @code{resize-window}.
783 They always operate on the selected window, never delete any window, and
784 always raise an error when resizing would violate a restriction imposed
785 by @code{window-min-height}, @code{window-min-width}, or
786 @code{window-size-fixed}.
788 @deffn Command enlarge-window delta &optional horizontal
789 This function makes the selected window @var{delta} lines taller.
790 Interactively, if no argument is given, it makes the selected window one
791 line taller.  If optional argument @var{horizontal} is non-@code{nil},
792 it makes the selected window wider by @var{delta} columns.  If
793 @var{delta} is negative, it shrinks the selected window by -@var{delta}
794 lines or columns.  The return value is @code{nil}.
795 @end deffn
797 @deffn Command enlarge-window-horizontally delta
798 This function makes the selected window @var{delta} columns wider.
799 Interactively, if no argument is given, it makes the selected window one
800 column wider.
801 @end deffn
803 @deffn Command shrink-window delta &optional horizontal
804 This function makes the selected window @var{delta} lines smaller.
805 Interactively, if no argument is given, it makes the selected window one
806 line smaller.  If optional argument @var{horizontal} is non-@code{nil},
807 it makes the selected window narrower by @var{delta} columns.  If
808 @var{delta} is negative, it enlarges the selected window by -@var{delta}
809 lines or columns.  The return value is @code{nil}.
810 @end deffn
812 @deffn Command shrink-window-horizontally delta
813 This function makes the selected window @var{delta} columns narrower.
814 Interactively, if no argument is given, it makes the selected window one
815 column narrower.
816 @end deffn
818 @defun adjust-window-trailing-edge window delta &optional horizontal
819 This function moves @var{window}'s bottom edge by @var{delta} lines.
820 Optional argument @var{horizontal} non-@code{nil} means to move
821 @var{window}'s right edge by @var{delta} columns.  The argument
822 @var{window} defaults to the selected window.
824 If the edge can't be moved by @var{delta} lines, move it as far as
825 possible in the desired direction.
826 @end defun
828 @deffn Command fit-window-to-buffer &optional window max-height min-height override
829 This command makes @var{window} the right height to display its
830 contents exactly.  The default for @var{window} is the selected window.
832 The optional argument @var{max-height} specifies the maximum height the
833 window is allowed to be; @code{nil} means use the maximum permissible
834 height of a window on @var{window}'s frame.  The optional argument
835 @var{min-height} specifies the minimum height for the window; @code{nil}
836 means use @code{window-min-height}.  All these height values include the
837 mode line and/or header line.
839 If the optional argument @var{override} is non-@code{nil}, this means to
840 ignore any restrictions imposed by @code{window-min-height} and
841 @code{window-min-width} on the size of @var{window}.
843 This function returns non-@code{nil} if it orderly resized @var{window},
844 and @code{nil} otherwise.
845 @end deffn
847 @deffn Command shrink-window-if-larger-than-buffer &optional window
848 This command shrinks @var{window} vertically to be as small as possible
849 while still showing the full contents of its buffer---but not less than
850 @code{window-min-height} lines.  The argument @var{window} must denote
851 a live window and defaults to the selected one.
853 However, this command does nothing if the window is already too small to
854 display the whole text of the buffer, or if part of the contents are
855 currently scrolled off screen, or if the window is not the full width of
856 its frame, or if the window is the only window in its frame.
858 This command returns non-@code{nil} if it actually shrank the window
859 and @code{nil} otherwise.
860 @end deffn
862 @cindex balancing window sizes
863 Emacs provides two functions to balance windows, that is, to even out
864 the sizes of windows on the same frame.  The minibuffer window and
865 fixed-size windows are not resized by these functions.
867 @deffn Command balance-windows &optional window-or-frame
868 This function balances windows in a way that gives more space to
869 full-width and/or full-height windows.  If @var{window-or-frame}
870 specifies a frame, it balances all windows on that frame.  If
871 @var{window-or-frame} specifies a window, it balances that window and
872 its siblings (@pxref{Windows and Frames}) only.
873 @end deffn
875 @deffn Command balance-windows-area
876 This function attempts to give all windows on the selected frame
877 approximately the same share of the screen area.  This means that
878 full-width or full-height windows are not given more space than other
879 windows.
880 @end deffn
882 @cindex maximizing windows
883 The following function can be used to give a window the maximum possible
884 size without deleting other ones.
886 @deffn Command maximize-window &optional window
887 This function maximizes @var{window}.  More precisely, this makes
888 @var{window} as large as possible without resizing its frame or deleting
889 other windows.  @var{window} can be any window and defaults to the
890 selected one.
891 @end deffn
893 @cindex minimizing windows
894 To make a window as small as possible without deleting it the
895 following function can be used.
897 @deffn Command minimize-window &optional window
898 This function minimizes @var{window}.  More precisely, this makes
899 @var{window} as small as possible without deleting it or resizing its
900 frame.  @var{window} can be any window and defaults to the selected one.
901 @end deffn
904 @node Splitting Windows
905 @section Splitting Windows
906 @cindex splitting windows
907 @cindex window splitting
909 The functions described below are the primitives needed for creating a
910 new window.  They do not accept a buffer as an argument.  Rather, they
911 ``split'' an existing window into two halves, both displaying the buffer
912 previously visible in the window that was split.
914 @deffn Command split-window &optional window size side
915 This function creates a new window adjacent to @var{window}.  It returns
916 the new window which is always a live window.  The argument @var{window}
917 can denote any window and defaults to the selected one.  This function
918 does not change the selected window.
920 Optional second argument @var{size} a positive number means make
921 @var{window} @var{size} lines (or columns) tall.  If @var{size} is
922 negative, make the new window @minus{}@var{size} lines (or columns)
923 tall.  If @var{size} is omitted or @code{nil}, then @var{window} is
924 divided evenly into two parts.  (If there is an odd line, it is
925 allocated to the new window.)
927 If splitting would result in making a window smaller than
928 @code{window-min-height} or @code{window-min-width} (@pxref{Window
929 Sizes}), this function usually signals an error.  However, if @var{size}
930 is non-@code{nil} and valid, a new window of the requested size is
931 created.  (A size value would be invalid if it assigned less than one
932 line or less than two columns to the new window.)
934 Optional third argument @var{side} @code{nil} (or @code{below})
935 specifies that the new window shall be located below @var{window}.  The
936 value @code{above} means the new window will be located above
937 @var{window}.  In both cases @var{size} specifies the new number of
938 lines for @var{window} (or the new window if @var{size} is negative)
939 including space reserved for the mode and/or header line.
941 If @var{side} is @code{t} or @code{right} the new window will be
942 positioned on the right side of @var{window}.  The value @code{left}
943 means the new window will be located on the left side of @var{window}.
944 In both cases @var{size} specifies the new number of columns for
945 @var{window} (or the new window provided @var{size} is negative)
946 including space reserved for margins, fringes and the scroll bar or a
947 divider column.
949 Any other non-@code{nil} value for @var{side} is currently handled like
950 @code{t} (or @code{right}).  Since this might change in the future,
951 application programs should refrain from using other values.
953 If @var{window} is live, properties of the new window like margins and
954 scroll bars are inherited from @var{window}.  If @var{window} is an
955 internal window, these properties, as well as the buffer shown in the
956 new window, are inherited from the window selected on @var{window}'s
957 frame.
959 If @code{ignore-window-parameters} is non-@code{nil}, this function
960 ignores window parameters (@pxref{Window Parameters}).  Otherwise, if
961 the @code{split-window-function} parameter of @var{window} is @code{t},
962 it splits the window disregarding any other window parameters.  If the
963 @code{split-window-function} parameter specifies a function, that
964 function is called with the arguments @var{window}, @var{size}, and
965 @var{side} to split @var{window}.  If that function is @code{ignore},
966 nothing is done.
968 Otherwise, if @var{window} is a subwindow of an atomic window
969 (@pxref{Atomic Windows}) this function splits the root of the atomic
970 window instead.  The new window does not become a subwindow of the
971 atomic window.  If @var{window} is a non-side window (@pxref{Side
972 Windows}), the new window becomes a non-side window too.  If
973 @var{window} is a side window, the new window becomes a side window too.
974 @end deffn
976 The following example starts with one window on a screen that is 50
977 lines high by 80 columns wide; then it splits the window.
979 @smallexample
980 @group
981 (setq W1 (selected-window))
982      @result{} #<window 8 on windows.texi>
983 (setq W2 (split-window W1 15))
984      @result{} #<window 28 on windows.texi>
985 @end group
986 @group
987 (window-top-line W1)
988      @result{} 0
989 (window-total-size W1)
990      @result{} 15
991 (window-top-line W2)
992      @result{} 15
993 @end group
994 @end smallexample
996 The screen looks like this:
998 @smallexample
999 @group
1000          __________
1001         |          |  line 0
1002         |    W1    |
1003         |__________|
1004         |          |  line 15
1005         |    W2    |
1006         |__________|
1007                       line 50
1008  column 0   column 80
1009 @end group
1010 @end smallexample
1012 Next, split the top window into two side-by-side windows:
1014 @smallexample
1015 @group
1016 (setq W3 (split-window W1 35 t))
1017      @result{} #<window 32 on windows.texi>
1018 @end group
1019 @group
1020 (window-left-column W1)
1021      @result{} 0
1022 (window-total-size W1 t)
1023      @result{} 35
1024 (window-left-column W3)
1025      @result{} 35
1026 @end group
1027 @end smallexample
1029 @need 3000
1030 Now the screen looks like this:
1032 @smallexample
1033 @group
1034      column 35
1035          __________
1036         |    |     |  line 0
1037         | W1 |  W3 |
1038         |____|_____|
1039         |          |  line 15
1040         |    W2    |
1041         |__________|
1042                       line 50
1043  column 0   column 80
1044 @end group
1045 @end smallexample
1047 Normally, Emacs indicates the border between two side-by-side windows
1048 with a scroll bar (@pxref{Scroll Bars}), or with @samp{|} characters.  The
1049 display table can specify alternative border characters; see @ref{Display
1050 Tables}.
1052 Below we describe how @code{split-window} can be used to create the
1053 window configuration from our earlier example (@pxref{Windows and
1054 Frames}) and how internal windows are created for this purpose.  We
1055 start with a frame containing one leaf window @code{W2} (in the
1056 following scenarios window names are assigned in an arbitrary manner in
1057 order to match the names of the example).
1058 @smallexample
1059 @group
1060      ______________________________________
1061     |                                      |
1062     |                                      |
1063     |                                      |
1064     |                                      |
1065     |                                      |
1066     |                                      |
1067     |                                      |
1068     |                                      |
1069     |                                      |
1070     |                                      |
1071     |                                      |
1072     |                                      |
1073     |__________________W2__________________|
1075 @end group
1076 @end smallexample
1078 Evaluating the form @code{(split-window W2 8 t)} creates a new internal
1079 window @code{W1} with two children---@code{W2} (the window we've split)
1080 and a new leaf window @code{W6}:
1081 @smallexample
1082 @group
1083      ______________________________________
1084     | ______  ____________________________ |
1085     ||      ||                            ||
1086     ||      ||                            ||
1087     ||      ||                            ||
1088     ||      ||                            ||
1089     ||      ||                            ||
1090     ||      ||                            ||
1091     ||      ||                            ||
1092     ||      ||                            ||
1093     ||      ||                            ||
1094     ||      ||                            ||
1095     ||__W2__||_____________W6_____________ |
1096     |__________________W1__________________|
1098 @end group
1099 @end smallexample
1101 Evaluating now @code{(split-window W6 -3)} creates another internal
1102 window @code{W3} with two children---@code{W6} and a new leaf window
1103 @code{W5}.  This leaves us with a vertically combined window @code{W3}
1104 embedded in the horizontally combined window @code{W1}:
1105 @smallexample
1106 @group
1107      ______________________________________
1108     | ______  ____________________________ |
1109     ||      || __________________________ ||
1110     ||      |||                          |||
1111     ||      |||                          |||
1112     ||      |||                          |||
1113     ||      |||                          |||
1114     ||      |||                          |||
1115     ||      |||____________W6____________|||
1116     ||      || __________________________ ||
1117     ||      |||                          |||
1118     ||      |||____________W5____________|||
1119     ||__W2__||_____________W3_____________ |
1120     |__________________W1__________________|
1122 @end group
1123 @end smallexample
1125 Finally, evaluating @code{(split-window W6 nil t)} should get us the
1126 desired configuration as depicted below.
1127 @smallexample
1128 @group
1129      ______________________________________
1130     | ______  ____________________________ |
1131     ||      || __________________________ ||
1132     ||      ||| ___________  ___________ |||
1133     ||      ||||           ||           ||||
1134     ||      ||||           ||           ||||
1135     ||      ||||_____W6____||_____W7____||||
1136     ||      |||____________W4____________|||
1137     ||      || __________________________ ||
1138     ||      |||                          |||
1139     ||      |||____________W5____________|||
1140     ||__W2__||_____________W3_____________ |
1141     |__________________W1__________________|
1143 @end group
1144 @end smallexample
1146 The scenario sketched above is the standard way to obtain the desired
1147 configuration.  In Emacs 23 it was also the only way to do that since
1148 Emacs 23 did't allow splitting internal windows.
1150 With Emacs 24 you can also proceed as follows: Split an initial window
1151 @code{W6} by evaluating @code{(split-window W6 -3)} to produce the
1152 following vertical combination:
1153 @smallexample
1154 @group
1155      ______________________________________
1156     | ____________________________________ |
1157     ||                                    ||
1158     ||                                    ||
1159     ||                                    ||
1160     ||                                    ||
1161     ||                                    ||
1162     ||                                    ||
1163     ||                                    ||
1164     ||_________________W6_________________||
1165     | ____________________________________ |
1166     ||                                    ||
1167     ||_________________W5_________________||
1168     |__________________W3__________________|
1170 @end group
1171 @end smallexample
1173 Evaluating now @code{(split-window (window-parent W6) -8 'left)} or,
1174 equivalently, @code{(split-window W3 -8 'left)} should produce the
1175 familiar configuration
1176 @smallexample
1177 @group
1178      ______________________________________
1179     | ______  ____________________________ |
1180     ||      || __________________________ ||
1181     ||      |||                          |||
1182     ||      |||                          |||
1183     ||      |||                          |||
1184     ||      |||                          |||
1185     ||      |||                          |||
1186     ||      |||____________W6____________|||
1187     ||      || __________________________ ||
1188     ||      |||                          |||
1189     ||      |||____________W5____________|||
1190     ||__W2__||_____________W3_____________ |
1191     |__________________W1__________________|
1193 @end group
1194 @end smallexample
1196 from where we can continue as described in the previous scenario.
1198    Another strategy starts with splitting an inital window @code{W6} by
1199 evaluating @code{(split-window W6 nil nil t)} with the following result:
1200 @smallexample
1201 @group
1202      ______________________________________
1203     | _________________  _________________ |
1204     ||                 ||                 ||
1205     ||                 ||                 ||
1206     ||                 ||                 ||
1207     ||                 ||                 ||
1208     ||                 ||                 ||
1209     ||                 ||                 ||
1210     ||                 ||                 ||
1211     ||                 ||                 ||
1212     ||                 ||                 ||
1213     ||                 ||                 ||
1214     ||________W6_______||________W7_______||
1215     |__________________W4__________________|
1217 @end group
1218 @end smallexample
1220 Evaluating now @code{(split-window W4 -3)} or @code{(split-window
1221 (window-parent W6) -3)} should get us a configuration as shown next.
1222 @smallexample
1223 @group
1224      ______________________________________
1225     | ____________________________________ |
1226     || ________________  ________________ ||
1227     |||                ||                |||
1228     |||                ||                |||
1229     |||                ||                |||
1230     |||                ||                |||
1231     |||                ||                |||
1232     |||_______W6_______||________W7______|||
1233     ||_________________W4_________________||
1234     | ____________________________________ |
1235     ||                                    ||
1236     ||_________________W5_________________||
1237     |__________________W3__________________|
1239 @end group
1240 @end smallexample
1242 The desired configuration can be now obtained by evaluating
1243 @code{(split-window W3 -8 'left)} or, equivalently, @code{(split-window
1244 (window-parent W5) -8 'left)}.
1246    For a final approach let's start with the configuration of two live
1247 windows @code{W6} and @code{W7} shown above.  If we now evaluate
1248 @code{(split-window W4 -8 'left)} or @code{(split-window (window-parent
1249 W6) -8 'left)} we get the following configuration.
1250 @smallexample
1251 @group
1252      ______________________________________
1253     | ______  ____________________________ |
1254     ||      || ____________  ____________ ||
1255     ||      |||            ||            |||
1256     ||      |||            ||            |||
1257     ||      |||            ||            |||
1258     ||      |||            ||            |||
1259     ||      |||            ||            |||
1260     ||      |||            ||            |||
1261     ||      |||            ||            |||
1262     ||      |||______W6____||______W7____|||
1263     ||__W2__||_____________W4_____________||
1264     |__________________W1__________________|
1266 @end group
1267 @end smallexample
1269 Evaluating now @code{(split-window W4 -3)} or, for example,
1270 @code{(split-window (window-parent W6) -3)} should produce the desired
1271 configuration.
1273   The following two option can be used to tune the operation of
1274 @code{split-window}.
1276 @defopt window-splits
1277 If this variable is nil, the function @code{split-window} can split a
1278 window if and only if that window's screen estate is sufficiently large
1279 to accomodate both itself and the new window.
1281 If this variable is non-@code{nil}, @code{split-window} tries to resize
1282 all windows belonging to the same combination as the old window in order
1283 to accomodate the new window.  Hence, the new window can be also created
1284 if the old window is otherwise too small to split.
1286 In any case, the value of this variable is assigned to the splits status
1287 of the new window and, provided old and new window form a new
1288 combination, of the old window as well.  The splits status of a window
1289 can be retrieved by invoking the function @code{window-splits} and
1290 altered by the function @code{set-window-splits}, see below.
1292 If @code{window-nest} (see below) is non-@code{nil}, the space for the
1293 new window is exclusively taken from the old window, but the splits
1294 status of any involved window is nevertheless set as descibed above.
1295 @end defopt
1297 @defopt window-nest
1298 If this variable is @code{nil}, @code{split-window} creates a new parent
1299 window if and only if the old window has no parent window or shall be
1300 split orthogonally to the combination it is part of.  If this variable
1301 is non-@code{nil}, @code{split-window} always creates a new parent
1302 window.  If this variable is always non-@code{nil}, a frame's window
1303 tree is a binary tree so every window but the frame's root window has
1304 exactly one sibling.
1306 The value of this variable is also assigned to the nest status of the
1307 new parent window.  The nest status of any window can be retrieved via
1308 the function @code{window-nest} and altered by the function
1309 @code{set-window-nest}, see below.
1310 @end defopt
1312 @defun window-splits &optional window
1313 This function returns the splits status of @var{window}.  The argument
1314 @var{window} can be any window and defaults to the selected one.
1316 @cindex splits status
1317 The @dfn{splits status} of a window specifies how resizing and deleting
1318 that window may affect the size of other windows in the same window
1319 combination.  The splits status is initially set by @code{split-window}
1320 to the current value of the variable @code{window-splits} (see above)
1321 and can be reset by the function @code{set-window-splits} (see below).
1323 More precisely, if @var{window}'s splits status is @code{nil} and
1324 @var{window} is resized, the corresponding space is preferably taken
1325 from (or given to) @var{window}'s right sibling.  When @var{window} is
1326 deleted, its space is given to its left sibling.  If @var{window}'s
1327 splits status is non-@code{nil}, resizing and deleting @var{window} may
1328 resize all windows in @var{window}'s combination.
1329 @end defun
1331 @defun set-window-splits window &optional status
1332 This function sets the splits status (see above) of @var{window} to
1333 @var{status}.  The argument @var{window} can be any window and defaults
1334 to the selected one.  The return value is @var{status}.
1335 @end defun
1337 @defun window-nest &optional window
1338 This function returns the nest status of @var{window}.  The argument
1339 @var{window} can be any window and defaults to the selected one.  Note,
1340 however, that the nest status is currently meaningful for internal
1341 windows only.
1343 @cindex nest status
1344 The @dfn{nest status} of a window secifies whether that window may be
1345 removed and its subwindows recombined with that window's siblings when
1346 such a sibling's subwindow is deleted.  The nest status is initially
1347 assigned by @code{split-window} to the current value of the variable
1348 @code{window-nest} (see above) and can be reset by the function
1349 @code{set-window-nest} (see below).
1351 If the return value is @code{nil}, subwindows of @var{window} may be
1352 recombined with @var{window}'s siblings when a window gets deleted.  A
1353 return value of @code{nil} means that subwindows of @var{window} are
1354 never (re-)combined with @var{window}'s siblings in such a case.
1355 @end defun
1357 @defun set-window-nest window &optional status
1358 This functions sets the nest status (see above) of @var{window} to
1359 @var{status}.  The argument @var{window} can be any window and defaults
1360 to the selected one.  Note that setting the nest status is meaningful
1361 for internal windows only.  The return value is @var{status}.
1362 @end defun
1364 @deffn Command split-window-above-each-other &optional size
1365 This function splits the selected window into two windows, one above the
1366 other, leaving the upper of the two windows selected, with @var{size}
1367 lines.  (If @var{size} is negative, then the lower of the two windows
1368 gets @minus{}@var{size} lines and the upper window gets the rest, but
1369 the upper window is still the one selected.)  However, if
1370 @code{split-window-keep-point} (see below) is @code{nil}, then either
1371 window can be selected.
1373    In other respects, this function is similar to @code{split-window}.
1374 In particular, the upper window is the original one and the return value
1375 is the new, lower window.
1376 @end deffn
1378 @defopt split-window-keep-point
1379 If this variable is non-@code{nil} (the default), then
1380 @code{split-window-above-each-other} behaves as described above.
1382    If it is @code{nil}, then @code{split-window-above-each-other}
1383 adjusts point in each of the two windows to avoid scrolling.  (This is
1384 useful on slow terminals.)  It selects whichever window contains the
1385 screen line that point was previously on.  Other functions are not
1386 affected by this variable.
1387 @end defopt
1389 @deffn Command split-window-side-by-side &optional size
1390 This function splits the selected window into two windows
1391 side-by-side, leaving the selected window on the left with @var{size}
1392 columns.  If @var{size} is negative, the rightmost window gets
1393 @minus{}@var{size} columns, but the leftmost window still remains
1394 selected.
1395 @end deffn
1398 @node Deleting Windows
1399 @section Deleting Windows
1400 @cindex deleting windows
1402 A window remains visible on its frame unless you @dfn{delete} it by
1403 calling certain functions that delete windows.  A deleted window cannot
1404 appear on the screen, but continues to exist as a Lisp object until
1405 there are no references to it.  There is no way to cancel the deletion
1406 of a window aside from restoring a saved window configuration
1407 (@pxref{Window Configurations}).  Restoring a window configuration also
1408 deletes any windows that aren't part of that configuration.  Erroneous
1409 information may result from using a deleted window as if it were live.
1411 @deffn Command delete-window &optional window
1412 This function removes @var{window} from display and returns @code{nil}.
1413 The argument @var{window} can denote any window and defaults to the
1414 selected one.  An error is signaled if @var{window} is the only window
1415 on its frame.  Hence @var{window} must have at least one sibling window
1416 (@pxref{Windows and Frames}) in order to get deleted.
1418 If @code{window-splits} is @code{nil}, the space @var{window} took up is
1419 given to its left sibling if such a window exists and to its right
1420 sibling otherwise.  If @code{window-splits} equals @code{nest} that
1421 space is given to the remaining sibling of @var{window}.  If
1422 @code{window-splits} equals @code{resize}, the space occupied by
1423 @var{window} is proportionally distributed among the remaining windows
1424 in the same combination.
1426 If @code{ignore-window-parameters} (@pxref{Window Parameters}) is
1427 non-@code{nil}, this function ignores window parameters.  Otherwise, if
1428 the @code{delete-window-function} parameter of @var{window} is @code{t},
1429 it deletes the window disregarding other window parameters.  If the
1430 @code{delete-window-function} parameter specifies a function, that
1431 function is called with @var{window} as its sole argument.
1433 If @var{window} is part of an atomic window (@pxref{Atomic Windows}),
1434 this function is called with the root of the atomic window as its
1435 argument.  If that window is the root window of its frame, an error is
1436 signalled.  If @var{window} is the last non-side window on its frame
1437 (@pxref{Side Windows}), this function signals an error too.
1438 @end deffn
1440 @deffn Command delete-other-windows &optional window
1441 This function makes @var{window} fill its frame and returns @code{nil}.
1442 The argument @var{window} can denote an arbitrary window and defaults to
1443 the selected one.
1445 If @code{ignore-window-parameters} (@pxref{Window Parameters}) is
1446 non-@code{nil}, this function ignores window parameters.  Otherwise, if
1447 the @code{delete-other-windows-function} parameter equals @code{t}, it
1448 deletes all other windows disregarding any remaining window parameters.
1449 If the @code{delete-other-windows-function} parameter specifies a
1450 function, it calls that function with @var{window} as its sole argument.
1452 If @var{window} is part of an atomic window (@pxref{Atomic Windows}), it
1453 calls this function with the root of the atomic window as its argument.
1454 If @var{window} is a non-side window (@pxref{Side Windows}), it makes
1455 @var{window} the only non-side window on its frame and leaves side
1456 windows alone.  If @var{window} is a side window, this function signals
1457 an error.
1458 @end deffn
1460 @deffn Command delete-windows-on &optional buffer-or-name frame
1461 This function deletes all windows showing @var{buffer-or-name} and
1462 returns nil.  If there are no windows showing @var{buffer-or-name}, it
1463 does nothing.  The optional argument @var{buffer-or-name} may be a
1464 buffer or the name of an existing buffer and defaults to the current
1465 buffer.  Invoking this command on a minibuffer signals an error.
1467 The function @code{delete-windows-on} operates by calling
1468 @code{delete-window} for each window showing @var{buffer-or-name}.  If a
1469 frame has several windows showing different buffers, then those showing
1470 @var{buffer-or-name} are removed, and the other windows expand to fill
1471 the space.  If all windows in some frame are showing
1472 @var{buffer-or-name} (including the case where there is only one
1473 window), then the frame winds up with a single window showing another
1474 buffer.  If, however, that last remaining window is dedicated to the
1475 buffer specified by @var{buffer-or-name} (@pxref{Dedicated Windows}),
1476 and there are other frames left, that window's frame is deleted.
1478 The optional argument @var{frame} specifies which frames to operate on.
1479 This function does not use it in quite the same way as the other
1480 functions which scan all live windows (@pxref{Cyclic Window Ordering});
1481 specifically, the values @code{t} and @code{nil} have the opposite of
1482 their meanings in the other functions.  Here are the full details:
1484 @itemize @bullet
1485 @item @code{nil}
1486 means operate on all frames.
1487 @item @code{t}
1488 means operate on the selected frame.
1489 @item @code{visible}
1490 means operate on all visible frames.
1491 @item @code{0}
1492 means operate on all visible or iconified frames.
1493 @item A frame
1494 means operate on that frame.
1495 @end itemize
1496 @end deffn
1499 @node Selecting Windows
1500 @section Selecting Windows
1501 @cindex selecting a window
1503 @cindex selected window
1504 In each frame, at any time, one and only one window is designated as
1505 @dfn{selected within the frame}.  Also, at any time, one frame is the
1506 selected frame (@pxref{Input Focus}).  The window selected within the
1507 selected frame is the @dfn{selected window}.  The selected window's
1508 buffer is usually the current buffer (except when @code{set-buffer} has
1509 been used); see @ref{Current Buffer}.
1511 @defun selected-window
1512 This function returns the selected window.  This is the window in which
1513 the cursor for selected windows (@pxref{Cursor Parameters}) appears and
1514 to which many commands apply.
1515 @end defun
1517 @defun select-window window &optional norecord
1518 This function makes @var{window} the selected window.  Unless
1519 @var{window} already is the selected window, this also makes
1520 @var{window}'s buffer (@pxref{Buffers and Windows}) the current buffer.
1521 Moreover, the cursor for selected windows will be displayed in
1522 @var{window} after the next redisplay.  This function returns
1523 @var{window}.
1525 Normally, @var{window}'s selected buffer is moved to the front of the
1526 buffer list (@pxref{The Buffer List}) and @var{window} becomes the most
1527 recently selected window.  But if the optional argument @var{norecord}
1528 is non-@code{nil}, the buffer list remains unchanged and @var{window}
1529 does not become the most recently selected one.
1530 @end defun
1532 @cindex most recently selected windows
1533 The sequence of calls to @code{select-window} with a non-@code{nil}
1534 @var{norecord} argument determines an ordering of windows by their
1535 selection time.  The function @code{get-lru-window} can be used to
1536 retrieve the least recently selected live window in this ordering, see
1537 @ref{Cyclic Window Ordering}.
1539 @defmac save-selected-window forms@dots{}
1540 This macro records the selected frame, as well as the selected window
1541 of each frame, executes @var{forms} in sequence, then restores the
1542 earlier selected frame and windows.  It also saves and restores the
1543 current buffer.  It returns the value of the last form in @var{forms}.
1545 This macro does not save or restore anything about the sizes,
1546 arrangement or contents of windows; therefore, if @var{forms} change
1547 them, the change persists.  If the previously selected window of some
1548 frame is no longer live at the time of exit from @var{forms}, that
1549 frame's selected window is left alone.  If the previously selected
1550 window is no longer live, then whatever window is selected at the end of
1551 @var{forms} remains selected.  The current buffer is restored if and
1552 only if it is still live when exiting @var{forms}.
1554 This macro changes neither the ordering of recently selected windows nor
1555 the buffer list.
1556 @end defmac
1558 @defmac with-selected-window window forms@dots{}
1559 This macro selects @var{window}, executes @var{forms} in sequence, then
1560 restores the previously selected window and current buffer.  The ordering
1561 of recently selected windows and the buffer list remain unchanged unless
1562 you deliberately change them within @var{forms}, for example, by calling
1563 @code{select-window} with argument @var{norecord} @code{nil}.
1565 The order of recently selected windows and the buffer list are not
1566 changed by this macro.
1567 @end defmac
1569 @cindex frame selected window
1570 @cindex window selected within frame
1571 Above we explained that at any time, exactly one window on any frame is
1572 selected within the frame.  The significance of this designation is that
1573 selecting the frame also selects this window.  Conversely, selecting a
1574 window for Emacs with @code{select-window} also makes that window
1575 selected within its frame.
1577 @defun frame-selected-window  &optional frame
1578 This function returns the window on @var{frame} that is selected within
1579 @var{frame}.  The optional argument @var{frame} must denote a live frame
1580 and defaults to the selected one.
1581 @end defun
1583 @defun set-frame-selected-window frame window &optional norecord
1584 This function sets the selected window of frame @var{frame} to
1585 @var{window}.  The argument @var{frame} must denote a live frame and
1586 defaults to the selected one.  If @var{frame} is the selected frame,
1587 this also makes @var{window} the selected window.  The argument
1588 @var{window} must denote a live window.  This function returns
1589 @var{window}.
1591 Optional argument @var{norecord} non-@code{nil} means to neither change
1592 the list of most recently selected windows (@pxref{Selecting Windows})
1593 nor the buffer list (@pxref{The Buffer List}).
1594 @end defun
1597 @node Cyclic Window Ordering
1598 @section Cyclic Ordering of Windows
1599 @cindex cyclic ordering of windows
1600 @cindex ordering of windows, cyclic
1601 @cindex window ordering, cyclic
1603 When you use the command @kbd{C-x o} (@code{other-window}) to select
1604 some other window, it moves through live windows in a specific order.
1605 For any given configuration of windows, this order never varies.  It is
1606 called the @dfn{cyclic ordering of windows}.
1608    For a particular frame, this ordering is determined by the window
1609 tree of that frame, see @ref{Windows and Frames}.  More precisely, the
1610 ordering is obtained by a depth-first traversal of the frame's window
1611 tree supplemented, if requested, by the frame's minibuffer window.
1613    If there's just one live frame, the cyclic ordering is the ordering
1614 for that frame.  Otherwise, the cyclic ordering is obtained by appending
1615 the orderings for individual frames in order of the list of all live
1616 frames, @ref{Finding All Frames}.  In any case, the ordering is made
1617 ``cyclic'' by having the last window precede the first window in the
1618 ordering.
1620 @defun next-window &optional window minibuf all-frames
1621 @cindex minibuffer window, and @code{next-window}
1622 This function returns the window following @var{window} in the cyclic
1623 ordering of windows.  The argument @var{window} must specify a live
1624 window and defaults to the selected one.
1626 The optional argument @var{minibuf} specifies whether minibuffer windows
1627 shall be included in the cyclic ordering.  Normally, when @var{minibuf}
1628 is @code{nil}, a minibuffer window is included only if it is currently
1629 ``active''; this matches the behavior of @kbd{C-x o}.  (Note that a
1630 minibuffer window is active as long as its minibuffer is in use; see
1631 @ref{Minibuffers}).
1633 If @var{minibuf} is @code{t}, the cyclic ordering includes all
1634 minibuffer windows.  If @var{minibuf} is neither @code{t} nor
1635 @code{nil}, minibuffer windows are not included even if they are active.
1637 The optional argument @var{all-frames} specifies which frames to
1638 consider.  Here are the possible values and their meanings:
1640 @itemize @bullet
1641 @item @code{nil}
1642 means consider all windows on @var{window}'s frame, plus the minibuffer
1643 window used by that frame even if it lies in some other frame.  If the
1644 minibuffer counts (as determined by @var{minibuf}), then all windows on
1645 all frames that share that minibuffer count too.
1647 @item @code{t}
1648 means consider all windows on all existing frames.
1650 @item @code{visible}
1651 means consider all windows on all visible frames.  (To get useful
1652 results, ensure that @var{window} is on a visible frame.)
1654 @item 0
1655 means consider all windows on all visible or iconified frames.
1657 @item A frame
1658 means consider all windows on that frame.
1660 @item Anything else
1661 means consider the windows on @var{window}'s frame, and no others.
1662 @end itemize
1664 This example assumes there are two windows, both displaying the
1665 buffer @samp{windows.texi}:
1667 @example
1668 @group
1669 (selected-window)
1670      @result{} #<window 56 on windows.texi>
1671 @end group
1672 @group
1673 (next-window (selected-window))
1674      @result{} #<window 52 on windows.texi>
1675 @end group
1676 @group
1677 (next-window (next-window (selected-window)))
1678      @result{} #<window 56 on windows.texi>
1679 @end group
1680 @end example
1681 @end defun
1683 @defun previous-window &optional window minibuf all-frames
1684 This function returns the window preceding @var{window} in the cyclic
1685 ordering of windows.  The other arguments specify which windows to
1686 consider as in @code{next-window}.
1687 @end defun
1689 @deffn Command other-window count &optional all-frames
1690 This function selects another window in the cyclic ordering of windows.
1691 @var{count} specifies the number of windows to skip in the ordering,
1692 starting with the selected window, before making the selection.  If
1693 @var{count} is a positive number, it skips @var{count} windows forwards.
1694 @var{count} negative means skip @minus{}@var{count} windows backwards.
1695 If @var{count} is zero, it does not skip any window, thus re-selecting
1696 the selected window.  In an interactive call, @var{count} is the numeric
1697 prefix argument.
1699 The optional argument @var{all-frames} has the same meaning as in
1700 @code{next-window}, but the @var{minibuf} argument of @code{next-window}
1701 is always effectively @code{nil}.  This function returns @code{nil}.
1703 This function does not select a window that has a non-@code{nil}
1704 @code{no-other-window} window parameter (@pxref{Window Parameters}).
1705 @end deffn
1707 The following function returns a copy of the list of windows in the
1708 cyclic odering.
1710 @defun window-list-1 &optional window &optional minibuf &optional all_frames
1711 This function returns a list of live windows.  The optional arguments
1712 @var{minibuf} and @var{all-frames} specify the set of windows to include
1713 in the list.  See the description of @code{next-window} for details.
1715 The optional argument @var{window} specifies the first window to list
1716 and defaults to the selected window.  If @var{window} is not on the list
1717 of windows returned, some other window will be listed first but no error
1718 is signalled.
1719 @end defun
1721 The functions described below use @code{window-list-1} for generating a
1722 copy of the list of all relevant windows.  Hence, any change of the
1723 window configuration that occurs while one of these functions is
1724 executed is @emph{not} reflected in the list of windows investigated.
1726 @defun walk-windows proc &optional minibuf all-frames
1727 This function cycles through live windows.  It calls the function
1728 @var{proc} once for each window, with the window as its sole argument.
1730 The optional arguments @var{minibuf} and @var{all-frames} specify the
1731 set of windows to include in the walk, see @code{next-window} above.  If
1732 @var{all-frames} specifies a frame, the first window walked is the first
1733 window on that frame as returned by @code{frame-first-window} and not
1734 necessarily the selected window.
1736 If @var{proc} changes the window configuration by splitting or deleting
1737 windows, that change is not reflected in the set of windows walked.
1738 That set is determined entirely by the set of live windows at the time
1739 this function was invoked.
1740 @end defun
1742 The following function allows to determine whether a specific window is
1743 the only live window.
1745 @defun one-window-p &optional no-mini all-frames
1746 This function returns non-@code{nil} if the selected window is the only
1747 window.
1749 The optional argument @var{no-mini}, if non-@code{nil}, means don't
1750 count the minibuffer even if it is active; otherwise, the minibuffer
1751 window is counted when it is active.  The optional argument
1752 @var{all-frames} has the same meaning as for @code{next-window}, see
1753 above.
1754 @end defun
1756 @cindex finding windows
1757   The following functions choose (but do not select) one of the windows
1758 on the screen, offering various criteria for the choice.
1760 @cindex least recently used window
1761 @defun get-lru-window &optional all-frames dedicated
1762 This function returns the window least recently ``used'' (that is,
1763 selected).  If any full-width windows are present, it only considers
1764 these.  The optional argument @var{all-frames} has the same meaning as
1765 in @code{next-window}.
1767 The selected window is returned if it is the only candidate.  A
1768 minibuffer window is never a candidate.  A dedicated window
1769 (@pxref{Dedicated Windows}) is never a candidate unless the optional
1770 argument @var{dedicated} is non-@code{nil}.
1771 @end defun
1773 @cindex largest window
1774 @defun get-largest-window &optional all-frames dedicated
1775 This function returns the window with the largest area (height times
1776 width).  If there are no side-by-side windows, then this is the window
1777 with the most lines.  A minibuffer window is never a candidate.  A
1778 dedicated window (@pxref{Dedicated Windows}) is never a candidate unless
1779 the optional argument @var{dedicated} is non-@code{nil}.
1781 If there are two candidate windows of the same size, this function
1782 prefers the one that comes first in the cyclic ordering of windows,
1783 starting from the selected window.
1785 The optional argument @var{all-frames} specifies which set of windows to
1786 consider as with @code{next-window}, see above.
1787 @end defun
1789 @cindex window that satisfies a predicate
1790 @cindex conditional selection of windows
1791 @defun get-window-with-predicate predicate &optional minibuf all-frames default
1792 This function returns a window satisfying @var{predicate}.  It cycles
1793 through all visible windows calling @var{predicate} on each one of them
1794 with that window as its argument.  The function returns the first window
1795 for which @var{predicate} returns a non-@code{nil} value; if that never
1796 happens, it returns @var{default} (which defaults to @code{nil}).
1798 The optional arguments @var{minibuf} and @var{all-frames} specify the
1799 set of windows to investigate.  See the description of
1800 @code{next-window} for details.
1801 @end defun
1804 @node Buffers and Windows
1805 @section Buffers and Windows
1806 @cindex examining windows
1807 @cindex windows, controlling precisely
1808 @cindex buffers, controlled in windows
1810 To find out which buffer is displayed in a given window the following
1811 function is used.
1813 @defun window-buffer &optional window
1814 This function returns the buffer that @var{window} is displaying.  The
1815 argument @var{window} can be any window and defaults to the selected
1816 one.  If @var{window} is an internal window, this function returns
1817 @code{nil}.
1818 @end defun
1820 The basic, low-level function to associate a window with a buffer is
1821 @code{set-window-buffer}.  Higher-level functions like
1822 @code{display-buffer} try to obey a number of user customizations
1823 regulating which windows are supposed to display which buffers.  When
1824 writing an application, programmers should therefore carefully evaluate
1825 whether they really need the power of this @code{set-window-buffer}.
1827 @defun set-window-buffer window buffer-or-name &optional keep-margins
1828 This function makes @var{window} display @var{buffer-or-name} and
1829 returns @code{nil}.  The argument @var{window} has to denote a live
1830 window and defaults to the selected one.  The argument
1831 @var{buffer-or-name} must specify a buffer or the name of an existing
1832 buffer.
1834 Normally, displaying @var{buffer-or-name} in @var{window} resets the
1835 window's position, display margins, fringe widths, and scroll bar
1836 settings based on the local variables of the specified buffer.  However,
1837 if the optional argument @var{keep-margins} is non-@code{nil}, display
1838 margins and fringe widths of @var{window} remain unchanged.
1839 @xref{Fringes}.
1841 @code{set-window-buffer} is the fundamental primitive for changing which
1842 buffer is displayed in a window, and all ways of doing that call this
1843 function.  Neither the selected window nor the current buffer are
1844 changed by this function.
1846 @code{set-window-buffer} signals an error when @var{window} is
1847 @dfn{strongly} dedicated to its buffer (@pxref{Dedicated Windows}) and
1848 does not already display @var{buffer-or-name}.
1850 This function runs @code{window-scroll-functions} before running
1851 @code{window-configuration-change-hook}, see @ref{Window Hooks}.
1852 @end defun
1854 @defvar buffer-display-count
1855 This buffer-local variable records the number of times a buffer has been
1856 displayed in a window.  It is incremented each time
1857 @code{set-window-buffer} is called for the buffer.
1858 @end defvar
1860 @defvar buffer-display-time
1861 This variable records the time at which a buffer was last made visible
1862 in a window.  It is always local in each buffer; each time
1863 @code{set-window-buffer} is called, it sets this variable to
1864 @code{(current-time)} in the specified buffer (@pxref{Time of Day}).
1865 When a buffer is first created, @code{buffer-display-time} starts out
1866 with the value @code{nil}.
1867 @end defvar
1869 @defun get-buffer-window &optional buffer-or-name all-frames
1870 This function returns a window displaying @var{buffer-or-name}, or
1871 @code{nil} if there is none.  If there are several such windows, then
1872 the function returns the first one in the cyclic ordering of windows,
1873 starting from the selected window, @xref{Cyclic Window Ordering}.
1875 The argument @var{BUFFER-OR-NAME} may be a buffer or a buffer name and
1876 defaults to the current buffer.  The optional argument @var{all-frames}
1877 specifies which windows to consider:
1879 @itemize @bullet
1880 @item
1881 @code{nil} means consider windows on the selected frame.
1882 @item
1883 @code{t} means consider windows on all existing frames.
1884 @item
1885 @code{visible} means consider windows on all visible frames.
1886 @item
1887 0 means consider windows on all visible or iconified frames.
1888 @item
1889 A frame means consider windows on that frame only.
1890 @end itemize
1892 Observe that the behavior of @code{get-buffer-window} may differ from
1893 that of @code{next-window} (@pxref{Cyclic Window Ordering}) when
1894 @var{all-frames} equals @code{nil} or any value not listed here.
1895 Perhaps we will change @code{get-buffer-window} in the future to make it
1896 compatible with the other functions.
1897 @end defun
1899 @defun get-buffer-window-list &optional buffer-or-name minibuf all-frames
1900 This function returns a list of all windows currently displaying
1901 @var{buffer-or-name}.  The argument @var{buffer-or-name} may be a buffer
1902 or the name of an existing buffer and defaults to the current buffer.
1904 The two remaining arguments work like the same-named arguments of
1905 @code{next-window} (@pxref{Cyclic Window Ordering}); they are @emph{not}
1906 like the optional arguments of @code{get-buffer-window}.
1907 @end defun
1909 The following command removes a buffer from all windows showing it.
1911 @deffn Command replace-buffer-in-windows &optional buffer-or-name
1912 This function replaces @var{buffer-or-name} in all windows displaying it
1913 with some other buffer.  It uses @code{switch-to-prev-buffer}, see
1914 below, to choose that other buffer which is usually the last buffer
1915 displayed before @var{buffer-or-name} in the respective window.
1917 The argument @var{buffer-or-name} may be a buffer or the name of an
1918 existing buffer and defaults to the current buffer.
1920 If a window displaying @var{buffer-or-name} is dedicated
1921 (@pxref{Dedicated Windows}), and is not the only window on its frame,
1922 that window is deleted.  If that window is the only window on its frame
1923 and there are other frames left, the window's frame is deleted too.  If
1924 there are no other frames left, some other buffer is displayed in that
1925 window as explained above.
1927 This function returns @code{nil}.
1928 @end deffn
1930    When @code{replace-buffer-in-windows} has to show another buffer in a
1931 window, it tries to pick the buffer shown there before.  For this
1932 purpose each window remembers the buffers it has displayed earlier and
1933 the order in which these buffers have been removed from it.
1935 The list of @dfn{previous buffers} of a window is an association list
1936 where each entry specifies a buffer, the last start position of that
1937 buffer in the window (@pxref{Window Start and End}) and the last
1938 position of that buffer's point in the window (@pxref{Window Point}).
1939 This list is ordered by the times of the removal of the respective
1940 buffers from the window.  In particular, the first element of the list
1941 references the buffer removed most recently.  The function
1942 @code{set-window-buffer} pushes an entry for the old buffer of its
1943 window argument on that list before it shows its buffer argument in the
1944 window.
1946 The list of @dfn{next buffers} of a window is a list of buffers that
1947 have been recently re-shown by the function @code{switch-to-prev-buffer}
1948 and is used to avoid that that function switches to such a buffer again
1949 before showing other interesting buffers.
1951 The lists of previous and next buffers and the global buffer list
1952 (@pxref{The Buffer List}) allow to effectively display all buffers in a
1953 window while giving preference to the buffers previously shown in that
1954 window.  The commands used for this purpose are
1955 @code{switch-to-prev-buffer} and @code{switch-to-next-buffer} described
1956 below.
1958 The following functions directly operate on the lists of previous and
1959 next buffers.
1961 @defun window-prev-buffers &optional window
1962 This function returns an alist specifying the buffers previously shown
1963 in @var{window} together with their window start and point positions.
1964 The argument @var{window} must be a live window and defaults to the
1965 selected one.
1966 @end defun
1968 @defun set-window-prev-buffers window prev-buffers
1969 This function sets @var{window}'s previous buffers to the value of
1970 @var{prev-buffers}.  The argument @var{window} must be a live window and
1971 defaults to the selected one.  This function returns
1972 @var{prev-buffers}.
1974 If non-@code{nil}, @var{prev-buffers} must specify an alist of triples
1975 specifying a buffer and two markers for that buffer's start and point
1976 position in @var{window}.
1977 @end defun
1979 @defun window-next-buffers &optional window
1980 This function returns the list of buffers recently re-shown in
1981 @var{window}.  The argument @var{window} must be a live window and
1982 defaults to the selected one.
1983 @end defun
1985 @defun set-window-next-buffers window next-buffers
1986 This function sets @var{window}'s next buffers to @var{next-buffers}.
1987 @var{window} must be a live window and defaults to the selected one.
1988 This fucntion returns @var{next-buffers}.
1990 If non-@code{nil}, the argument @var{next-buffers} should specify a list
1991 of buffers that shall be preferably not shown by the command
1992 @code{switch-to-prev-buffer}, see below.
1993 @end defun
1995 The following command is used by @code{replace-buffer-in-windows},
1996 @code{bury-buffer} and @code{quit-restore-window} to show another buffer
1997 in a window.  It can be also used interactively to cycle through the
1998 list of all buffers in a window, preferably showing the buffers recently
1999 shown (but not buried or killed) in that window.
2001 @deffn Command switch-to-prev-buffer &optional window bury-or-kill
2002 This function displays the previous buffer in @var{window}.  The
2003 argument @var{window} must be a live window and defaults to the selected
2004 one.  If the optional argument @var{bury-or-kill} is non-@code{nil},
2005 this means that the buffer currently shown in @var{window} is about to
2006 be buried or killed and consequently shall not be switched to in future
2007 invocations of this command.
2009 The previous buffer is usually the buffer shown before the buffer
2010 currently shown in @var{window}.  However, a buffer that has been buried
2011 or killed or has been already shown by a recent invocation of
2012 @code{switch-to-prev-buffer} does not qualify as previous buffer.
2014 If repeated invocations of this command have already shown all buffers
2015 previously shown in @var{window}, further invocations will show buffers
2016 from the global buffer list starting with the buffer returned by
2017 @code{last-buffer} (@pxref{The Buffer List}).
2018 @end deffn
2020 The following command can be used to undo the effect of the last undone
2021 @code{switch-to-prev-buffer} command.
2023 @deffn Command switch-to-next-buffer &optional window
2024 This functions switches to the next buffer in @var{window} thus undoing
2025 the effect of the last @code{switch-to-prev-buffer} command in
2026 @var{window}.  The argument @var{window} must be a live window and
2027 defaults to the selected one.
2029 If there is no recent invocation of a @code{switch-to-prev-buffer} that
2030 can be undone, @code{switch-to-next-buffer} will try to show the first
2031 buffer from the global buffer list as returned by @code{other-buffer}
2032 (@pxref{The Buffer List}).
2033 @end deffn
2035    Together, @code{switch-to-prev-buffer} and
2036 @code{switch-to-next-buffer} permit to navigate the global buffer list
2037 much like @code{bury-buffer} and @code{unbury-buffer}.  In contrast with
2038 the latter, however, they may show a buffer even if it is already shown
2039 in another window.  Moreover, they try to restore the window specific
2040 start and point positions of buffers which should handle viewing one and
2041 the same buffer in multiple windows more easily.
2044 @node Displaying Buffers
2045 @section Choosing a Window for Displaying a Buffer
2047 The basic facility to choose a window and display a buffer in it is
2048 @code{display-buffer}.  Many higher-level functions like
2049 @code{pop-to-buffer} (@pxref{Switching Buffers}) and
2050 @code{with-output-to-temp-buffer} (@pxref{Temporary Displays}) work by
2051 calling this function.  Here we describe how @code{display-buffer}
2052 works, how to customize its behavior, and how to get rid of the chosen
2053 window once it is no more needed.
2055 @deffn Command display-buffer &optional buffer-or-name specifiers label
2056 This command makes the buffer specified by @var{buffer-or-name} appear
2057 in some window, but it does not necessarily select that window or make
2058 the buffer current.  It returns the window chosen to display the buffer,
2059 @code{nil} if no such window can be found.
2061 The optional argument @var{buffer-or-name} has to specify a buffer or
2062 the name of a buffer and defaults to the current buffer.  If
2063 @var{buffer-or-name} is a string that does not name an existing buffer,
2064 @code{display-buffer} creates a buffer with that name.  When called
2065 interactively, it prompts for a buffer name in the minibuffer.
2067 The optional argument @var{specifiers} is usually a list of buffer
2068 display specifiers, see the description of @code{display-buffer-alist}
2069 below.  For convenience, @var{specifiers} may also consist of a single
2070 macro specifier or @code{t}, where the latter means to display the
2071 buffer in any but the selected window.  If @var{specifiers} is
2072 @code{nil} or omitted, this means to exclusively use the values provided
2073 by the variable @code{display-buffer-alist}.  If that variable is nil
2074 too, default specifiers are used.
2076 The optional third argument @var{label}, if non-@code{nil}, is a symbol
2077 specifying the buffer display label.  Applications should set this when
2078 the buffer shall be displayed in some special way but
2079 @var{buffer-or-name} alone does not identify the buffer as special.
2080 Typical buffers that fit into this category are those whose names are
2081 derived from the name of the file they are visiting.  A user can then
2082 override @var{specifiers} by adding an entry to
2083 @code{display-buffer-alist} whose @sc{car} contains @var{label} and
2084 whose @sc{cdr} specifies the preferred alternative display method.
2085 @end deffn                                                                      
2087 Precisely how @code{display-buffer} finds or creates a window depends on
2088 the @var{specifiers} argument and the two variables described next.
2090 @defopt display-buffer-alist
2091 @cindex buffer identifier
2092 The value of this option is a list associating buffer identifiers with
2093 buffer display specifiers.  The @sc{car} of each element of this list is
2094 built from cons cells called @dfn{buffer identifiers}.  The function
2095 @code{display-buffer} shows a buffer according to the display specifiers
2096 in the element's @sc{cdr} (elements are true lists) if at least one of
2097 these buffer identifiers matches the first or third argument of
2098 @code{display-buffer}.  Such a match occurs in one of the following
2099 three cases:
2101 @itemize @bullet
2102 @item
2103 The @sc{car} of the buffer identifier is the symbol @code{name} and its
2104 @sc{cdr} is a string equalling the name of the buffer specified by the
2105 @var{buffer-or-name} argument of @code{display-buffer}.
2107 @item
2108 The @sc{car} is the symbol @code{regexp} and the @sc{cdr} is a regular
2109 expression matching the name of the buffer specified by the first
2110 @var{buffer-or-name} argument of @code{display-buffer}.
2112 @item
2113 The @sc{car} is the symbol @code{label} and the @sc{cdr} is a symbol
2114 equalling the @var{label} argument of @code{display-buffer}.
2115 @end itemize
2117 @cindex buffer display specifier
2118 @cindex method specifier
2119 A @dfn{buffer display specifier} is a symbol, a cons cell, or a list,
2120 telling @code{display-buffer} where and how to display a given buffer.
2121 Four specifiers allow to indicate the basic method for displaying the
2122 buffer: @code{reuse-window}, @code{pop-up-window}, @code{pop-up-frame}
2123 and @code{use-side-window}.
2125    A list whose @sc{car} is the symbol @code{reuse-window} indicates
2126 that an existing window shall be reused for displaying the buffer.  The
2127 second element of this list specifies the window to reuse and can be one
2128 of the following symbols:
2130 @itemize @bullet
2131 @item
2132 @code{nil} stands for any window.
2134 @item
2135 @code{same} stands for the selected window.
2137 @item
2138 @code{other} stands for any but the selected window.
2139 @end itemize
2141 The third element specifies whether the buffer shown in the window that
2142 shall be reused must be the same buffer that shall be displayed or
2143 another buffer and can be one of the following:
2145 @itemize @bullet
2146 @item
2147 @code{nil} means to not care about the window's buffer.
2149 @item
2150 @code{same} means the window must show the buffer already.
2152 @item
2153 @code{other} means the window must not show the buffer yet.
2154 @end itemize
2156 The fourth element specifies the set of frames to search for a suitable
2157 window and can be one of the following:
2159 @itemize @bullet
2160 @item
2161 @code{nil} to stay on the selected frame.
2163 @item
2164 @code{visible} to search visible frames only.
2166 @item
2167 @code{other} stands for any visible frame but the selected one.
2169 @item
2170 0 (the number zero) to search visible and iconified frames.
2172 @item
2173 @code{t} to search arbitrary frames including invisible ones.
2174 @end itemize
2176 If more than one window fits the constraints imposed by these elements,
2177 the least recently used among them is chosen.  A side window
2178 (@pxref{Side Windows}) is reused if and only if it already shows the
2179 buffer that shall be displayed.
2181 Two specifiers are useful when the method equals @code{reuse-window}:
2183 @itemize @bullet
2184 @item
2185 A cons cell whose @sc{car} is the symbol @code{reuse-window-even-sizes}
2186 and whose @sc{cdr} is non-@code{nil} means to even out the sizes of the
2187 reused and the selected window provided they (1) are adjacent to each
2188 other and (2) the selected window is larger than the window chosen.  If
2189 the @sc{cdr} is @code{nil}, this means that the window sizes are left
2190 alone.
2192 @item
2193 A cons cell whose @sc{car} is the symbol @code{reuse-window-dedicated}
2194 and whose @sc{cdr} is non-@code{nil} means that a window can be reused
2195 even if it's dedicated to its buffer.  If the @sc{cdr} is @code{t}, a
2196 strongly dedicated window can be reused to show the buffer.  Any other
2197 non-@code{nil} value means only weakly dedicated windows can be reused.
2198 If the @sc{cdr} is @code{nil}, dedicated windows are not reused.
2200 This specifier should be used in special cases only since windows are
2201 usually made dedicated in order to prevent @code{display-buffer} from
2202 reusing them.
2203 @end itemize
2205 A list whose @sc{car} is the symbol @code{pop-up-window} and whose
2206 @sc{cdr} is built from window/side tuples indicates that a new window
2207 shall be made for displaying the buffer on the selected frame.
2209 Window/side tuples are cons cells.  The @sc{car} of such a tuple
2210 identifies the window that shall be split.  Possible values are
2211 @code{largest}, @code{lru}, @code{selected}, and @code{root} to
2212 respectively split the largest, least recently used, selected or root
2213 window of the selected frame.
2215 The @sc{cdr} of each pair specifies on which side of the window to split
2216 the new window shall appear and can be one of @code{below},
2217 @code{right}, @code{above}, or @code{left} with the obvious meanings.
2218 If the @sc{cdr} is @code{nil}, the window is split in a fashion suitable
2219 for its current dimensions.  If the @sc{cdr} specifies a function, that
2220 function is called with one argument---the window that shall be split.
2221 The function is supposed to split that window and return the new window.
2223 The function @code{display-buffer} scans these tuples until it can
2224 either produce a suitable window or fails.  The default value for
2225 @code{display-buffer-alist} contains the tuples
2227 @smallexample
2228 (largest . nil) (lru . nil)
2229 @end smallexample
2231 in order to split the largest window first and, if that fails, the least
2232 recently used one.
2234 The following additional specifiers are useful with the
2235 @code{pop-up-window} method specifier.
2237 @itemize @bullet
2238 @item
2239 A cons cell whose @sc{car} is the symbol @code{pop-up-window-min-height}
2240 specifies the minimum height of the new window.  If the @sc{cdr} is an
2241 integer number, it specifies the minimum number of lines of the window.
2242 A floating point number gives the minimum fraction of the window height
2243 with respect to the height of the frame's root window.  A new window is
2244 created only if it can be made at least as high as specified by the
2245 number.  If the @sc{cdr} is @code{nil}, this means to use the value of
2246 @code{window-min-height}.
2248 @item
2249 A cons cell whose @sc{car} is the symbol @code{pop-up-window-min-width}
2250 specifies the minimum width of the new window.  If the @sc{cdr} is an
2251 integer number, it specifies the minimum number of columns of the
2252 window.  A floating point number gives the minimum fraction of the
2253 window width with respect to the width of the frame's root window.  A
2254 new window is created only if it can be made at least as wide as
2255 specified by the number.  If the @sc{cdr} is @code{nil}, the value of
2256 @code{window-min-width} is used.
2258 @item
2259 A cons cell whose @sc{car} is @code{pop-up-window-set-height} with
2260 the following interpretations for the @sc{cdr}:
2262 @itemize @minus
2263 @item
2264 @code{nil} means leave the height of the new window alone.
2266 @item
2267 A number specifies the desired height of the new window.  An integer
2268 number specifies the number of lines of the window.  A floating point
2269 number gives the fraction of the window's height with respect to the
2270 height of the frame's root window.
2272 @item
2273 If the @sc{cdr} specifies a function, that function is called with one
2274 argument - the new window.  The function is supposed to adjust the
2275 height of the window; its return value is ignored.  Suitable functions
2276 to call here are @code{shrink-window-if-larger-than-buffer} and
2277 @code{fit-window-to-buffer}, see @ref{Resizing Windows}.
2278 @end itemize
2280 @item
2281 A cons cell whose @sc{car} equals @code{pop-up-window-set-width} with
2282 the following interpretations for the @sc{cdr}:
2284 @itemize @minus
2285 @item
2286 @code{nil} means leave the width of the new window alone.
2288 @item
2289 A number specifies the desired width of the new window.  An integer
2290 number specifies the number of columns of the window.  A floating point
2291 number gives the fraction of the window's width with respect to the
2292 width of the frame's root window.
2294 @item
2295 If the @sc{cdr} specifies a function, that function is called with one
2296 argument - the new window.  The function is supposed to adjust the width
2297 of the window; its return value is ignored.
2298 @end itemize
2300 Observe that specifying @code{pop-up-window-set-height} and
2301 @code{pop-up-window-set-width} may override restrictions given by the
2302 @code{pop-up-window-min-height} and @code{pop-up-window-min-width}
2303 specifiers.
2305 @item
2306 A cons cell whose @sc{car} is @code{pop-up-window-split-unsplittable}
2307 and whose @sc{cdr} is non-@code{nil} allows to make a new window on an
2308 unsplittable frame.  If the @sc{cdr} is @code{nil}, unsplittable frames
2309 are not split.  This specifier should be used in special cases only
2310 since frames are usually made unsplittable in order to prevent
2311 @code{display-buffer} from splitting them.
2312 @end itemize
2314 A list of two elements whose @sc{car} is the symbol @code{pop-up-frame}
2315 states that a new frame shall be made for displaying the buffer.  The
2316 second element of this list, if non-nil, allows to make a new frame on
2317 graphic displays only.
2319 The following additional specifiers are useful with the
2320 @code{pop-up-frame} method specifier.
2322 @itemize @bullet
2323 @item
2324 A list whose @sc{car} is the symbol @code{popup-frame-function} together
2325 with a valid function as @sc{cdr} specifies the function for creating a
2326 new frame.  If the @sc{cdr} is @code{nil}, the default function
2327 @code{make-frame} is called.  The function is called with the parameters
2328 and values provided by the specifier described next.
2330 @item
2331 A list whose @sc{car} is the symbol @code{popup-frame-alist} followed by
2332 an arbitrary number of frame parameter/value tuples, each given as a
2333 cons cell, specifies the parameters passed to the popup frame function.
2334 @end itemize
2336 A list of three elements whose @sc{car} is the symbol
2337 @code{use-side-window} specifies that the buffer shall be displayed in a
2338 side window (@pxref{Side Windows}) of the selected frame.  The second
2339 element denotes the side of the frame where the window shall appear and
2340 must be one of @code{left}, @code{top}, @code{right} and @code{bottom}.
2341 If no window on the specified side exists yet, @code{display-buffer}
2342 creates one.
2344 The third element is a number and denotes the slot within the specified
2345 side.  Slots are numbers where the number zero stands for the window in
2346 the middle of the side.  A slot less than zero indicates that the window
2347 shall be shown on the left (for the top and bottom side window) or above
2348 (for the left and right side window) of the window in the middle.  A
2349 slot larger than zero indicates that the window shall be shown on the
2350 right (for the top and bottom side window) or below (for the left and
2351 right side window) of the window in the middle.
2353 If a side window with the specified slot exists already and is not
2354 dedicated to its buffer, @code{display-buffer} reuses that window.  If
2355 no such window exists, @code{display-buffer} tries to make a new window
2356 with the specified slot by splitting the side window with the nearest
2357 matching slot.  If creating a new side window is impossible,
2358 @code{display-buffer} tries to reuse the side window with the nearest
2359 matching slot.  The option @code{window-sides-slots} (@pxref{Side
2360 Windows}) can be used to restrict the number of windows on each side.
2362 In conjunction with the @code{use-side-window} method specifier, the
2363 specifiers @code{reuse-window-dedicated},
2364 @code{pop-up-window-min-height}, @code{pop-up-window-min-width},
2365 @code{pop-up-window-set-height} and @code{pop-up-window-set-width}
2366 described above can be used.
2368 A list whose @sc{car} is the symbol @code{fun-with-args} specifies that
2369 the buffer shall be displayed by the function that appears as second
2370 element of that list.  The third element is a list of arguments that are
2371 passed as second argument to that function---the first argument is the
2372 buffer that shall be displayed.  The function is not passed any
2373 specifiers.
2375 The function shoul choose or create a window, display the specified
2376 buffer in it, and return the window.  It is also responsible for giving
2377 the variable @code{display-buffer-window} a meaningful value, see below
2378 for an explanation.  Moreover, the function should set up the
2379 @code{quit-restore} window parameter which is required for proper
2380 functioning of the command @code{quit-restore-window}, see below.
2382 It's hardly a good idea to call @code{display-buffer} within the body of
2383 the function specified here since this may lead to infinite recursion.
2385 @cindex macro specifier
2386 Instead of writing method specifiers it's often more convenient to use a
2387 predefined macro specifier.  The following macro specifiers are
2388 provided:
2390 @itemize @bullet
2391 @item
2392 @code{same-frame} to make or use a window on the selected frame.
2394 @item
2395 @code{other-window} to make or use any window but the selected one.
2397 @item
2398 @code{same-frame-other-window} to make or use any window on the
2399 selected frame with exception of the selected window.
2401 @item
2402 @code{other-frame} to make sure the window appears on any visible frame
2403 but the selected one.
2405 @item
2406 @code{default} to use the specifier of the default value of
2407 @code{display-buffer-alist} as described below.
2408 @end itemize
2410 In addition it's possible to specify whether the window chosen shall
2411 become dedicated to the buffer (@pxref{Dedicated Windows}).  This is
2412 accomplished with the help of a cons cell whose @sc{car} is the symbol
2413 @code{dedicated} and whose @sc{cdr} is one of the following values:
2415 @itemize @bullet
2416 @item
2417 @code{nil} which means to not dedicate the window to the buffer,
2419 @item
2420 @code{weak} which means the window shall be weakly dedicated to its
2421 buffer, or
2423 @item
2424 @code{t} to strongly dedicate the window to the buffer.
2425 @end itemize
2427 Moreover you can specify whether the function @code{other-window}
2428 (@pxref{Cyclic Window Ordering}) is allowed to select the window used
2429 for displaying the buffer.  This is accomplished with the help of a cons
2430 cell whose @sc{car} is the symbol @code{no-other-window} and whose
2431 @sc{cdr} is non-@code{nil}.
2433 In general, an application is free to ignore the specifiers of
2434 @code{display-buffer-alist} by explicitly passing a non-@code{nil}
2435 second argument to @code{display-buffer}.  For any
2436 @code{display-buffer-alist} entry one can, however, add a cons cell
2437 whose @sc{car} is the symbol @code{override} and whose @sc{cdr} is
2438 non-@code{nil} to explicitly override the value supplied by the
2439 application.
2441 Overriding arguments supplied by the calling application is, in general,
2442 not advisable.  It permits, for example, to change the semantics of
2443 commands like @code{switch-to-buffer-other-window} by setting the method
2444 specifier to @code{same-window} or @code{other-frame}.
2445 @end defopt
2447 The value of @code{display-buffer-alist} may contain scalar elements
2448 which are used by the customization interface and are ignored by
2449 @code{display-buffer}.  The normalized default specifiers are:
2451 @example
2452  ((reuse-window nil same visible)
2453   (pop-up-window (largest) (lru))
2454   (pop-up-frame)
2455   (reuse-window nil other visible)
2456   (reuse-window-even-sizes . t))
2457 @end example
2459 It means to proceed as follows:
2461 @itemize @bullet
2462 @item
2463 First try reusing a window showing the buffer on some visible frame.  If
2464 a window above or below the selected window is reused, the sizes of
2465 those windows are evened out.
2467 @item
2468 Next try to pop up a window on the selected frame by splitting either
2469 the largest or the least recently used window in a system dependent way.
2471 @item
2472 Try to pop up a new frame using the default function @code{make-frame}.
2474 @item
2475 Try to reuse a window showing some other buffer on a visible frame.
2476 @end itemize
2478 If these specifiers fail to produce a suitable window,
2479 @code{display-buffer} uses a number of heuristics that do not
2480 necessarily observe the value of @code{display-buffer-alist}.
2482 An application calling @code{display-buffer} can, in some cases, replace
2483 fixed references to windows or buffers within display specifiers by
2484 references to Lisp objects like windows or buffers.  In particular the
2485 following are possible:
2487 @itemize @bullet
2488 @item
2489 The @code{reuse-window} specifier accepts as second element a live
2490 window and as third element a live buffer.
2492 @item
2493 In window/side tuples of the @code{pop-up-window} specifier an arbitrary
2494 window can be used as first element.
2495 @end itemize
2497 In order to understand how @code{display-buffer} combines the values of
2498 @code{display-buffer-alist} with the @var{specifiers} argument suppose
2499 the following item
2501 @example
2502 (((name . "*text*"))
2503  ((pop-up-window (selected . below) (root . below))
2504   (override . t)))
2505 @end example
2507 has been added to @code{display-buffer-alist} and @code{display-buffer}
2508 is called as
2510 @example
2511 (display-buffer "*text*" '((reuse-window same)))
2512 @end example
2514 Since the entry from @code{display-buffer-alist} matches the buffer name
2515 and has the @code{override} specifier set, @code{display-buffer} will
2516 first try to split either the selected or the root window of the
2517 selected frame.
2519    If neither of these windows can be split, @code{display-buffer} will
2520 try to display the buffer in the selected window as requested by the
2521 @var{specifiers} argument.  If this fails as well, for example, because
2522 the selected window is dedicated to another buffer,
2523 @code{display-buffer} will apply the default specifiers from
2524 @code{display-buffer-alist} as sketched above.  Observe that in this
2525 case @code{display-buffer} will not necessarily try to split the
2526 selected or the frame's root window because the corresponding specifiers
2527 from @code{display-buffer-alist} have been already consumed at that
2528 time.
2530    So the order of precedence is to try the overriding specifiers from
2531 @code{display-buffer-alist} first.  Next come the specifiers from the
2532 @var{specifiers} argument of @code{display-buffer}.  Finally,
2533 non-overriding specifiers from @code{display-buffer-alist} are tried.
2535    In case you observe any unexpected behavior of @code{display-buffer}
2536 keep in mind the following:
2538 @itemize @bullet
2539 @item
2540 Specifiers are consumed in the order sketched above, which means that
2541 the value of the first specifier found prevails.  When
2542 @code{display-buffer} applies a method specifier, any specifiers
2543 preceding the method specifier have been consumed already and do no more
2544 affect the work of @code{display-buffer}.
2546 @item
2547 Displaying a buffer on a new or other frame will always raise that frame
2548 and give it input focus.  This contrasts with the behavior of
2549 @code{display-buffer} up to Emacs 22.  While not raising the frame seems
2550 like the correct behavior, it is presently not done due to possible bad
2551 interaction with window managers on various platforms.
2553 @item
2554 The customization interface does not allow to assign every conceivable
2555 value to the option @code{display-buffer-alist}.  You have to set these
2556 by hand to achieve more exotic behavior.
2557 @end itemize
2559    Next we describe how to manually transcribe the buffer display
2560 options of Emacs 23 with @code{display-buffer-alist}.  For a mechanized
2561 way to do this see the command @code{display-buffer-alist-set} descibed
2562 below.
2564 @itemize @bullet
2565 @item
2566 The options @code{same-window-buffer-names} and
2567 @code{same-window-regexps} are handled by the @code{same-window} macro
2568 specifier.
2570 @item
2571 For @code{display-buffer-reuse-frames} use the @code{reuse-window}
2572 specifier with a non-@code{nil} third element and as fourth element the
2573 set of frames that should be considered.
2575 @item
2576 The options @code{special-display-buffer-names} and
2577 @code{special-display-regexps} are replaced by
2578 @code{display-buffer-alist} itself because, in a sense, all buffers are
2579 special now.
2581 @item
2582 The @code{special-display-function} option is emulated by setting the
2583 @code{pop-up-frame-function} specifier.
2585 @item
2586 The @code{special-display-frame-alist} option is now handled by the
2587 @code{popup-frame-alist} specifier.
2589 @item
2590 The option @code{pop-up-frames} is replaced by the @code{pop-up-frame}
2591 method specifier.
2593 @item
2594 The option @code{pop-up-frame-function} has become the homonymous
2595 specifier.
2597 @item
2598 The option @code{pop-up-frame-alist} has become the homonymous specifier.
2600 @item
2601 The option @code{pop-up-windows} is replaces by the @code{pop-up-window}
2602 method specifier.
2604 @item
2605 A @code{split-window-preferred-function} can be specified as the second
2606 in a window/side tuple of the @code{pop-up-window} specifier.
2608 @item
2609 @code{split-height-threshold} and @code{split-width-threshold} are
2610 handled by the @code{pop-up-window-min-height} and
2611 @code{pop-up-window-min-width} specifiers respectively.  The sizes you
2612 specify there are, however, no more the original sizes of the window to
2613 split but the desired minimum sizes of the new window.
2615 @item
2616 @code{even-window-heights} is handled by setting the @sc{cdr} of the
2617 @code{reuse-window-even-sizes} specifier to a non-@code{nil} value.
2618 @end itemize
2620 @defopt display-buffer-function
2621 This variable is the most flexible way to customize the behavior of
2622 @code{display-buffer}.  If it is non-@code{nil}, it should be a function
2623 that @code{display-buffer} calls to do the work.  The function must
2624 accept two arguments, the buffer to display and a list of normalized
2625 buffer display specifiers as produced by
2626 @code{display-buffer-normalize-specifiers}, see below.
2628 It should choose or create a window, display the specified buffer in it,
2629 and then return the window.  It is also responsible for giving the
2630 variable @code{display-buffer-window} a meaningful value, see below for
2631 an explanation.  Moreover, the function should set up the
2632 @code{quit-restore} window parameter which is required for proper
2633 functioning of the command @code{quit-restore-window}, see below.
2635 The function specified here is free to ignore any specifiers passed to
2636 it as second argument.  If you intend to call @code{display-buffer}
2637 within the body of the function specified here, it's a good idea to bind
2638 @code{display-buffer-function} to @code{nil} around each such call to
2639 avoid running into an infinite recursion.
2640 @end defopt
2642 Above we described how to manually obtain the settings of
2643 @code{display-buffer-alist} from Emacs 23 buffer display options.  The
2644 function described next should do this automatically.
2646 @defun display-buffer-alist-set &optional no-custom add
2647 This fucntion sets @code{display-buffer-alist} from Emacs 23 buffer
2648 display options.  The optional argument @var{no-custom} @code{nil} means
2649 to apply the function @code{customize-set-variable} to set the value of
2650 @code{display-buffer-alist}.  If @var{no-custom} is non-@code{nil}, this
2651 means to use @code{setq} instead.
2653 The optional argument @var{add} @code{nil} means to replace the actual
2654 value of @code{display-buffer-alist} with the value calculated here.  If
2655 @var{add} is non-@code{nil}, this means to prepend the value calculated
2656 here to the current value of @code{display-buffer-alist}.
2657 @end defun
2659 Applications setting or binding Emacs 23 buffer display options will
2660 usually fail to achieve the desired effect if they do not set the
2661 @var{specifiers} argument of @code{display-buffer} accordingly.  Binding
2662 or setting @code{display-buffer-function} to the function sketched below
2663 can bypass this problem until the @var{specifiers} argument has been
2664 rewritten.
2666 @example
2667 (defun my-display-buffer (buffer specifiers)
2668   "Run `display-buffer' with Emacs 23 buffer display options."
2669   (let (display-buffer-alist display-buffer-function)
2670     (display-buffer-alist-set t)
2671     (display-buffer buffer)))
2672 @end example
2674 The function @code{my-display-buffer} applies
2675 @code{display-buffer-alist-set} to a locally bound, pristine copy of
2676 @code{display-buffer-alist} and calls @code{display-buffer} without any
2677 specifiers.  Note the local binding of @code{display-buffer-function}
2678 which avoids that @code{display-buffer} calls @code{my-display-buffer}
2679 recursively.
2681    In this context note that the purpose of the buffer display options
2682 of Emacs 23 was to give users an instrument to control the behavior of
2683 how buffers are displayed.  Setting or binding such an option within an
2684 application did constitutes bad programming practice just like setting
2685 or binding @code{display-buffer-alist} would.  Applications are supposed
2686 to @emph{exclusively} use the @var{specifiers} argument in order to
2687 affect the behavior of @code{display-buffer}.
2689 The function @code{display-buffer} tries hard to find a new window for
2690 displaying the buffer and fails (that is, returns @code{nil}) only in
2691 rare cases.  The functions described next are called by
2692 @code{display-buffer} but can be occasionally useful for applications
2693 that want more deterministic behavior.  These functions must be called
2694 with normalized specifiers which means that all macro specifiers must
2695 have been already expanded and the scalar symbols used by the
2696 customization interface removed.  To get normalized specifiers you can
2697 use the function described next.
2699 @defun display-buffer-normalize-specifiers buffer-name specifiers label
2700 This function returns the normalized specifiers for a buffer matching
2701 @var{buffer-name} or @var{label}.  The argument @var{buffer-name} must
2702 be a string specifying a valid buffer name.  The arguments
2703 @var{specifiers} and @var{label} are the homonymous arguments of
2704 @code{display-buffer}.
2705 @end defun
2707 In the four functions described next, the optional argument
2708 @var{specifiers} must be a list of normalized buffer display specifiers
2709 as returned by @code{display-buffer-normalize-specifiers}.  These
2710 functions return the window displaying the @var{buffer} if they
2711 succeeded, @code{nil} otherwise.
2713 @defun display-buffer-reuse-window buffer method &optional specifiers
2714 This function tries to display @var{buffer} in an existing window.  The
2715 argument @var{method} must be a list in the form of the @sc{cdr} of a
2716 @code{reuse-window} buffer display specifier.  The first element must
2717 specifiy the window to use, and can be either @code{nil}, @code{same},
2718 @code{other}, or a live window.  The second element specifies whether
2719 the window's buffer must be the same as @var{buffer} or another one and
2720 can be either @code{nil}, @code{same}, @code{other}.  It can be also a
2721 live buffer which means to reuse a window only if @var{buffer} is the
2722 buffer it displays.  The third element is the frame to use - either
2723 @code{nil}, 0 (the number zero), @code{visible}, @code{t}, or a live
2724 frame.
2725 @end defun
2727 @defun display-buffer-pop-up-window buffer methods &optional specifiers
2728 This function tries to display @var{buffer} in a new window.  The
2729 argument @var{methods} must be a list of window/side tuples like those
2730 forming the @sc{cdr} of the @code{pop-up-window} buffer display
2731 specifier.  As a special case, the @sc{car} of such a tuple can be also
2732 a live window.
2733 @end defun
2735 @defun display-buffer-pop-up-frame buffer &optional graphic-only specifiers
2736 This function tries to make a new frame for displaying @var{buffer}.
2737 The optional argument @var{graphic-only} non-@code{nil} means to make a
2738 new frame on graphic displays only.
2739 @end defun
2741 @defun display-buffer-in-side-window buffer side &optional slot specifiers
2742 This function tries to display @var{buffer} in a window on @var{side} of
2743 the selected frame (@pxref{Side Windows}).  The argument @var{slot}, if
2744 non-@code{nil}, specifies the window slot where to display the
2745 @var{buffer}.  If @var{slot} is zero or @code{nil}, this means use the
2746 central slot on @var{side}.  A negative value means to use a slot
2747 preceding the central window.  A positive value means to use a slot
2748 following the central window.
2749 @end defun
2751 The following functions are simple interfaces to @code{display-buffer}.
2753 @defun display-buffer-same-window &optional buffer-or-name label
2754 This function is like @code{display-buffer} but preferably displays the
2755 buffer specified by @var{buffer-or-name} in the selected window.
2756 Another window will be used only if the buffer can't be shown in the
2757 selected window, usually because it is dedicated to some other buffer.
2758 @end defun
2760 @defun display-buffer-same-frame &optional buffer-or-name label
2761 This function is like @code{display-buffer} but tries to avoid using
2762 another frame.
2763 @end defun
2765 @defun display-buffer-other-window &optional buffer-or-name label
2766 This function is like @code{display-buffer} but tries to avoid using the
2767 selected window.
2768 @end defun
2770 @defun display-buffer-other-window-same-frame &optional buffer-or-name label
2771 This function is like @code{display-buffer-other-window} but tries to
2772 avoid using another frame.
2773 @end defun
2775 The following variable conveys some information about the last
2776 @code{display-buffer} action performed and is used mainly when popping
2777 up a @samp{*Help*} buffer.
2779 @defvar display-buffer-window
2780 After @code{display-buffer} has shown a buffer in some window this
2781 variable should be a cons cell whose @sc{car} denotes the window used to
2782 display the buffer.  The @sc{cdr} is either @code{new-window} (which
2783 means a new window has been made), @code{new-frame} (a new frame has
2784 been created), @code{reuse-buffer-window} (a window showing the buffer
2785 has been reused), @code{reuse-other-window} (some other window has been
2786 reused).
2788 If @code{display-buffer-function} is non-@code{nil}, the function called
2789 here becomes responsible for assigning a meaningful value to this
2790 variable.  Otherwise, the @code{display-buffer} code takes care of this.
2791 @end defvar
2793 The command described next allows to quit the window chosen by
2794 @code{display-buffer} and restore the previous state without undoing
2795 changes to the window configuration that happend @emph{after}
2796 @code{display-buffer} was called.  A more drastic solution is to save
2797 the window configuration before calling @code{display-buffer} and
2798 eventually restoring the saved configuration, @ref{Window
2799 Configurations}.  That solution sometimes has the undesirable
2800 side-effect that all changes that happened after the configuration was
2801 saved are undone too.
2803 @deffn Command quit-restore-window &optional window kill
2804 This command ``quits'' @var{window} restoring its previous contents if
2805 possible.  The argument @var{window} must be a live window and defaults
2806 to the selected one.  This function always returns @code{nil}.
2808 According to information stored in @var{window}'s @code{quit-restore}
2809 window parameter (@pxref{Window Parameters}) this function performs one
2810 of the following actions.
2812 @itemize @bullet
2814 @item
2815 Delete @var{window} and its frame.  This action is useful when
2816 @var{window} was created on a standalone frame and there are other
2817 frames left.
2819 @item
2820 Delete @var{window}.  This action is usually taken when @var{window} was
2821 obtained by splitting some existing window.
2823 @item
2824 Restore the buffer previously displayed in @var{window}.  This action
2825 is taken when @var{window} was temporarily reused for displaying some
2826 other buffer.
2828 @item
2829 Make @var{window} display some other buffer.  This action is usually
2830 taken when the three preceding ones are not applicable.
2831 @end itemize
2833 If the optional argument @var{kill} is non-@code{nil}, this means in
2834 addition kill @var{window}'s buffer.  If @var{kill} is @code{nil}, this
2835 simply puts @var{window}'s buffer at the end of the buffer list.
2836 Interactively, @var{kill} is the prefix argument.
2837 @end deffn
2840 @node Switching Buffers
2841 @section Switching to a Buffer in Some Window
2842 @cindex switching to a buffer
2843 @cindex popping to a buffer
2845 In this section we describe convenient functions for switching to a
2846 specified buffer in some window.  These functions can also split an
2847 existing window or create a new frame in certain circumstances.  In any
2848 case, the window chosen becomes the selected window and the buffer
2849 current.
2851    Do not use the functions in this section in order to make a buffer
2852 current so that a Lisp program can access or modify it; they are too
2853 drastic for that purpose, since they change the display of buffers in
2854 windows, which would be gratuitous and surprise the user.  Instead, use
2855 @code{set-buffer} and @code{save-current-buffer} (@pxref{Current
2856 Buffer}), which designate buffers as current for programmed access
2857 without affecting the display of buffers in windows.
2859    The functions described here can be roughly divided into two groups
2860 whose major representatives are the functions @code{switch-to-buffer}
2861 and @code{pop-to-buffer} respectively.  Functions in the
2862 @code{switch-to-buffer} group have the following distinguishing
2863 characteristics:
2865 @itemize @bullet
2866 @item
2867 They are reserved for interactive use; many of them have a predefined
2868 keybinding.  Lisp code should @emph{never} call them.
2870 @item
2871 They can show a buffer in a window even if that window is dedicated to
2872 another buffer.
2874 @item
2875 They do not have a @code{specifiers} or a @var{label} argument like
2876 @code{display-buffer}.
2878 @item
2879 When the argument specifying the buffer that shall be displayed is
2880 @code{nil}, they display the buffer returned by @code{other-buffer}.
2881 @end itemize
2883 Functions in the @code{pop-to-buffer} group have the following
2884 characteristics.
2886 @itemize @bullet
2887 @item
2888 They can be called interactively and from Lisp code.
2890 @item
2891 They respect the user customizations of @code{display-buffer-alist} and
2892 @code{display-buffer-function}.  In particular, they try to not reuse a
2893 dedicated window unless they are explicitly advised to do so.
2895 @item
2896 They can be passed a @code{specifiers} and a @var{label} argument, just
2897 as @code{display-buffer}.
2899 @item
2900 When the argument specifying the buffer that shall be displayed is
2901 @code{nil}, they try to display the current buffer.
2902 @end itemize
2904 For historical reasons, many Lisp function call @code{switch-to-buffer}.
2905 These calls should be converted to @code{pop-to-buffer} calls.
2907 @deffn Command switch-to-buffer buffer-or-name &optional norecord
2908 This function makes the buffer specified by @var{buffer-or-name}
2909 current, displays it in the selected window, and returns the buffer.
2910 This means that a human can see the buffer and subsequent keyboard
2911 commands will apply to it.  Contrast this with @code{set-buffer}, which
2912 makes @var{buffer-or-name} the current buffer but does not display it in
2913 the selected window; see @ref{Current Buffer}.
2915 If @var{buffer-or-name} is @code{nil}, @code{switch-to-buffer} chooses a
2916 buffer using @code{other-buffer}.  If @var{buffer-or-name} is a string
2917 that does not identify an existing buffer, then a new buffer by that
2918 name is created.  The major mode for the new buffer is set according to
2919 the variable @code{major-mode}; see @ref{Auto Major Mode}.
2921 If called interactively, it prompts for the buffer name using the
2922 minibuffer.  The variable @code{confirm-nonexistent-file-or-buffer}
2923 determines whether to request confirmation before creating a new buffer.
2925 When the selected window is the minibuffer window or is strongly
2926 dedicated to its buffer (@pxref{Dedicated Windows}), this function calls
2927 @code{pop-to-buffer} (see below) to display the buffer in some other
2928 window.
2930 Normally, the specified buffer is put at the front of the buffer list
2931 (both the selected frame's buffer list and the frame-independent buffer
2932 list, see @ref{The Buffer List}).  This affects the operation of
2933 @code{other-buffer}.  However, if @var{norecord} is non-@code{nil}, this
2934 is not done.  Also, if @var{norecord} is non-@code{nil}, the window
2935 chosen for displaying the buffer is not automatically made the most
2936 recently selected one.
2938 This function is intended for interactive use, as the binding of
2939 @kbd{C-x b}.  Do @emph{not} call this function from Lisp code.  The
2940 function @code{pop-to-buffer-same-window} should be used for that
2941 purpose.
2942 @end deffn
2944 The next functions are similar to @code{switch-to-buffer}, except for
2945 the described features.
2947 @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
2948 This command makes the buffer specified by @var{buffer-or-name} current
2949 and tries to display it in a window not currently selected, by using the
2950 function @code{pop-to-buffer} (see below).  It returns the buffer
2951 switched to.
2953 This function tries hard to avoid using the selected window for doing
2954 the job.  If the selected window already displays @var{buffer-or-name},
2955 then it continues to do so, but another window is nonetheless found to
2956 display it in as well.
2958 The arguments @var{buffer-or-name} and @var{norecord} have the same
2959 meaning as for @code{switch-to-buffer}.
2961 This function is for interactive use, as the binding of @kbd{C-x 4 b}.
2962 Do @emph{not} call this function from Lisp code.  The function
2963 @code{pop-to-buffer-other-window} should be used for this purpose.
2964 @end deffn
2966 @deffn Command switch-to-buffer-same-frame buffer-or-name &optional norecord
2967 This command is like @code{switch-to-buffer-other-window} but does not
2968 necessarily avoid the selected window.  It does, however, try to use or
2969 make a window on the selected frame.
2970 @end deffn
2972 @deffn Command switch-to-buffer-other-window-same-frame buffer-or-name &optional norecord
2973 This command is like @code{switch-to-buffer-other-window} but tries to
2974 use or make a window on the selected frame.
2975 @end deffn
2977 @deffn Command switch-to-buffer-other-frame buffer-or-name &optional norecord
2978 This command is like @code{switch-to-buffer-other-window} but tries to
2979 display the buffer on another frame.  This function has the binding
2980 @kbd{C-x 4 b}.
2981 @end deffn
2983 The following functions take a @var{specifiers} and a @var{label}
2984 argument and respect the same customizations as @code{display-buffer}.
2985 Their only difference to the latter is that they @emph{always} select
2986 the window chosen for displaying the buffer argument.
2988 @deffn Command pop-to-buffer buffer-or-name &optional specifiers norecord label
2989 This command makes @var{buffer-or-name} the current buffer and switches
2990 to it in some window.  The ``popped-to'' window becomes the selected
2991 window.  Its frame is given the X server's focus, if possible; see
2992 @ref{Input Focus}.  The return value is the buffer that was switched to
2993 or @code{nil} if no suitable window could be found.
2995    The optional argument @var{buffer-or-name} may be a buffer, a string
2996 (a buffer name), or @code{nil}.  If @var{buffer-or-name} is a string not
2997 naming an existent buffer, it creates a buffer with that name.  If
2998 @var{buffer-or-name} is @code{nil} or omitted, it displays the current
2999 buffer.
3001    The optional second argument @var{specifiers} must be a list of
3002 buffer display specifiers or a single macro specifier, see the
3003 documentations of @code{display-buffer} and @code{display-buffer-alist}.
3004 If @var{specifiers} is @code{t}, it means to pop to the buffer in any
3005 but the selected window.  If @var{specifiers} is @code{nil} or omitted,
3006 this means to exclusively use the values provided by
3007 @code{display-buffer-alist} (@pxref{Displaying Buffers}).  If these
3008 values are nil too, default specifiers are used.
3010    The optional third argument @var{norecord} is handled just as by
3011 @code{switch-to-buffer}.  The optional fourth argument @var{label}
3012 specifies the buffer display label just as for @code{display-buffer}.
3013 @end deffn
3015 The following commands are similar to @code{pop-to-buffer} but for the
3016 mentioned differences.
3018 @deffn Command pop-to-buffer-same-window &optional buffer-or-name norecord label
3019 This command is like @code{pop-to-buffer} but tries to display the
3020 buffer in the selected window.  Another window will be used only if the
3021 buffer can't be shown in the selected window, usually because the window
3022 is dedicated to another buffer.
3023 @end deffn
3025 @deffn Command pop-to-buffer-same-frame &optional buffer-or-name norecord label
3026 This command is like @code{pop-to-buffer} but tries to make or use a
3027 window on the selected frame.
3028 @end deffn
3030 @deffn Command pop-to-buffer-other-window &optional buffer-or-name norecord label
3031 This command is like @code{pop-to-buffer} but tries to avoid the
3032 selected window.  Windows on the selected frame are preferred to windows
3033 on other frames.
3034 @end deffn
3036 @deffn Command pop-to-buffer-other-window-same-frame &optional buffer-or-name norecord label
3037 This command is like @code{pop-to-buffer-other-window} but tries to make
3038 or use a window on the selected frame.
3039 @end deffn
3041 @deffn Command pop-to-buffer-other-frame &optional buffer-or-name norecord label
3042 This command is like @code{pop-to-buffer} but preferably displays the
3043 buffer on another frame.
3044 @end deffn
3047 @node Dedicated Windows
3048 @section Dedicated Windows
3049 @cindex dedicated window
3051 Functions for displaying a buffer can be told to not use specific
3052 windows by marking these windows as @dfn{dedicated} to their buffers.
3053 The function @code{display-buffer} (@pxref{Displaying Buffers}) never
3054 uses a dedicated window for displaying another buffer in it.  The
3055 functions @code{get-lru-window} and @code{get-largest-window}
3056 (@pxref{Selecting Windows}) do not consider dedicated windows as
3057 candidates when their @var{dedicated} argument is non-@code{nil}.  The
3058 behavior of @code{set-window-buffer} (@pxref{Buffers and Windows}) with
3059 respect to dedicated windows is slightly different, see below.
3061 When @code{delete-windows-on} (@pxref{Deleting Windows}) wants to delete
3062 a dedicated window and that window is the only window on its frame, it
3063 deletes the window's frame too, provided there are other frames left.
3064 The function @code{replace-buffer-in-windows} (@pxref{Displaying
3065 Buffers}) tries to delete all dedicated windows showing its buffer
3066 argument.  When such a window is the only window on its frame, that
3067 frame is deleted, provided there are other frames left.  If there are no
3068 more frames left, some other buffer is displayed in the window, and the
3069 window is marked as non-dedicated.
3071 When you kill a buffer (@pxref{Killing Buffers}) displayed in a
3072 dedicated window, any such window usually gets deleted too, since
3073 @code{kill-buffer} calls @code{replace-buffer-in-windows} for cleaning
3074 up windows.  Burying a buffer (@pxref{The Buffer List}) deletes the
3075 selected window if it is dedicated to that buffer.  If, however, that
3076 window is the only window on its frame, @code{bury-buffer} displays
3077 another buffer in it and iconifies the frame.
3079 @defun window-dedicated-p &optional window
3080 This function returns non-@code{nil} if @var{window} is dedicated to its
3081 buffer and @code{nil} otherwise.  More precisely, the return value is
3082 the value assigned by the last call of @code{set-window-dedicated-p} for
3083 @var{window} or @code{nil} if that function was never called with
3084 @var{window} as its argument.  The default for @var{window} is the
3085 selected window.
3086 @end defun
3088 @defun set-window-dedicated-p window flag
3089 This function marks @var{window} as dedicated to its buffer if
3090 @var{flag} is non-@code{nil}, and non-dedicated otherwise.
3092 As a special case, if @var{flag} is @code{t}, @var{window} becomes
3093 @dfn{strongly} dedicated to its buffer.  @code{set-window-buffer}
3094 signals an error when the window it acts upon is strongly dedicated to
3095 its buffer and does not already display the buffer it is asked to
3096 display.  Other functions do not treat @code{t} differently from any
3097 non-@code{nil} value.
3098 @end defun
3101 @node Window Point
3102 @section Windows and Point
3103 @cindex window position
3104 @cindex window point
3105 @cindex position in window
3106 @cindex point in window
3108 Each window has its own value of point (@pxref{Point}), independent of
3109 the value of point in other windows displaying the same buffer.  This
3110 makes it useful to have multiple windows showing one buffer.
3112 @itemize @bullet
3113 @item
3114 The window point is established when a window is first created; it is
3115 initialized from the buffer's point, or from the window point of another
3116 window opened on the buffer if such a window exists.
3118 @item
3119 Selecting a window sets the value of point in its buffer from the
3120 window's value of point.  Conversely, deselecting a window sets the
3121 window's value of point from that of the buffer.  Thus, when you switch
3122 between windows that display a given buffer, the point value for the
3123 selected window is in effect in the buffer, while the point values for
3124 the other windows are stored in those windows.
3126 @item
3127 As long as the selected window displays the current buffer, the window's
3128 point and the buffer's point always move together; they remain equal.
3129 @end itemize
3131 @cindex cursor
3132    As far as the user is concerned, point is where the cursor is, and
3133 when the user switches to another buffer, the cursor jumps to the
3134 position of point in that buffer.
3136 @defun window-point &optional window
3137 This function returns the current position of point in @var{window}.
3138 For a nonselected window, this is the value point would have (in that
3139 window's buffer) if that window were selected.  The default for
3140 @var{window} is the selected window.
3142 When @var{window} is the selected window and its buffer is also the
3143 current buffer, the value returned is the same as point in that buffer.
3144 Strictly speaking, it would be more correct to return the ``top-level''
3145 value of point, outside of any @code{save-excursion} forms.  But that
3146 value is hard to find.
3147 @end defun
3149 @defun set-window-point window position
3150 This function positions point in @var{window} at position
3151 @var{position} in @var{window}'s buffer.  It returns @var{position}.
3153 If @var{window} is selected, and its buffer is current,
3154 this simply does @code{goto-char}.
3155 @end defun
3157 @defvar window-point-insertion-type
3158 This variable specifies the marker insertion type (@pxref{Marker
3159 Insertion Types}) of @code{window-point}.  The default is @code{nil},
3160 so @code{window-point} will stay behind text inserted there.
3161 @end defvar
3164 @node Window Start and End
3165 @section The Window Start and End Positions
3166 @cindex window start position
3168   Each window maintains a marker used to keep track of a buffer position
3169 that specifies where in the buffer display should start.  This position
3170 is called the @dfn{display-start} position of the window (or just the
3171 @dfn{start}).  The character after this position is the one that appears
3172 at the upper left corner of the window.  It is usually, but not
3173 inevitably, at the beginning of a text line.
3175   After switching windows or buffers, and in some other cases, if the
3176 window start is in the middle of a line, Emacs adjusts the window
3177 start to the start of a line.  This prevents certain operations from
3178 leaving the window start at a meaningless point within a line.  This
3179 feature may interfere with testing some Lisp code by executing it
3180 using the commands of Lisp mode, because they trigger this
3181 readjustment.  To test such code, put it into a command and bind the
3182 command to a key.
3184 @defun window-start &optional window
3185 @cindex window top line
3186 This function returns the display-start position of window
3187 @var{window}.  If @var{window} is @code{nil}, the selected window is
3188 used.  For example,
3190 @example
3191 @group
3192 (window-start)
3193      @result{} 7058
3194 @end group
3195 @end example
3197 When you create a window, or display a different buffer in it, the
3198 display-start position is set to a display-start position recently used
3199 for the same buffer, or to @code{point-min} if the buffer doesn't have
3200 any.
3202 Redisplay updates the window-start position (if you have not specified
3203 it explicitly since the previous redisplay)---to make sure point appears
3204 on the screen.  Nothing except redisplay automatically changes the
3205 window-start position; if you move point, do not expect the window-start
3206 position to change in response until after the next redisplay.
3208 For a realistic example of using @code{window-start}, see the
3209 description of @code{count-lines}.  @xref{Definition of count-lines}.
3210 @end defun
3212 @cindex window end position
3213 @defun window-end &optional window update
3214 This function returns the position where display of its buffer ends in
3215 @var{window}.  The default for @var{window} is the selected window.
3217 Simply changing the buffer text or moving point does not update the
3218 value that @code{window-end} returns.  The value is updated only when
3219 Emacs redisplays and redisplay completes without being preempted.
3221 If the last redisplay of @var{window} was preempted, and did not finish,
3222 Emacs does not know the position of the end of display in that window.
3223 In that case, this function returns @code{nil}.
3225 If @var{update} is non-@code{nil}, @code{window-end} always returns an
3226 up-to-date value for where display ends, based on the current
3227 @code{window-start} value.  If a previously saved value of that position
3228 is still valid, @code{window-end} returns that value; otherwise it
3229 computes the correct value by scanning the buffer text.
3231 Even if @var{update} is non-@code{nil}, @code{window-end} does not
3232 attempt to scroll the display if point has moved off the screen, the
3233 way real redisplay would do.  It does not alter the
3234 @code{window-start} value.  In effect, it reports where the displayed
3235 text will end if scrolling is not required.
3236 @end defun
3238 @defun set-window-start window position &optional noforce
3239 This function sets the display-start position of @var{window} to
3240 @var{position} in @var{window}'s buffer.  It returns @var{position}.
3242 The display routines insist that the position of point be visible when a
3243 buffer is displayed.  Normally, they change the display-start position
3244 (that is, scroll the window) whenever necessary to make point visible.
3245 However, if you specify the start position with this function using
3246 @code{nil} for @var{noforce}, it means you want display to start at
3247 @var{position} even if that would put the location of point off the
3248 screen.  If this does place point off screen, the display routines move
3249 point to the left margin on the middle line in the window.
3251 For example, if point @w{is 1} and you set the start of the window
3252 @w{to 37}, the start of the next line, point will be ``above'' the top
3253 of the window.  The display routines will automatically move point if
3254 it is still 1 when redisplay occurs.  Here is an example:
3256 @example
3257 @group
3258 ;; @r{Here is what @samp{foo} looks like before executing}
3259 ;;   @r{the @code{set-window-start} expression.}
3260 @end group
3262 @group
3263 ---------- Buffer: foo ----------
3264 @point{}This is the contents of buffer foo.
3270 ---------- Buffer: foo ----------
3271 @end group
3273 @group
3274 (set-window-start
3275  (selected-window)
3276  (save-excursion
3277    (goto-char 1)
3278    (forward-line 1)
3279    (point)))
3280 @result{} 37
3281 @end group
3283 @group
3284 ;; @r{Here is what @samp{foo} looks like after executing}
3285 ;;   @r{the @code{set-window-start} expression.}
3286 ---------- Buffer: foo ----------
3289 @point{}4
3292 ---------- Buffer: foo ----------
3293 @end group
3294 @end example
3296 If @var{noforce} is non-@code{nil}, and @var{position} would place point
3297 off screen at the next redisplay, then redisplay computes a new window-start
3298 position that works well with point, and thus @var{position} is not used.
3299 @end defun
3301 @defun pos-visible-in-window-p &optional position window partially
3302 This function returns non-@code{nil} if @var{position} is within the
3303 range of text currently visible on the screen in @var{window}.  It
3304 returns @code{nil} if @var{position} is scrolled vertically out of view.
3305 Locations that are partially obscured are not considered visible unless
3306 @var{partially} is non-@code{nil}.  The argument @var{position} defaults
3307 to the current position of point in @var{window}; @var{window}, to the
3308 selected window.  If @var{position} is @code{t}, that means to check the
3309 last visible position in @var{window}.
3311 The @code{pos-visible-in-window-p} function considers only vertical
3312 scrolling.  If @var{position} is out of view only because @var{window}
3313 has been scrolled horizontally, @code{pos-visible-in-window-p} returns
3314 non-@code{nil} anyway.  @xref{Horizontal Scrolling}.
3316 If @var{position} is visible, @code{pos-visible-in-window-p} returns
3317 @code{t} if @var{partially} is @code{nil}; if @var{partially} is
3318 non-@code{nil}, and the character following @var{position} is fully
3319 visible, it returns a list of the form @code{(@var{x} @var{y})}, where
3320 @var{x} and @var{y} are the pixel coordinates relative to the top left
3321 corner of the window; otherwise it returns an extended list of the form
3322 @code{(@var{x} @var{y} @var{rtop} @var{rbot} @var{rowh} @var{vpos})},
3323 where @var{rtop} and @var{rbot} specify the number of off-window pixels
3324 at the top and bottom of the row at @var{position}, @var{rowh} specifies
3325 the visible height of that row, and @var{vpos} specifies the vertical
3326 position (zero-based row number) of that row.
3328 Here is an example:
3330 @example
3331 @group
3332 ;; @r{If point is off the screen now, recenter it now.}
3333 (or (pos-visible-in-window-p
3334      (point) (selected-window))
3335     (recenter 0))
3336 @end group
3337 @end example
3338 @end defun
3340 @defun window-line-height &optional line window
3341 This function returns the height of text line @var{line} in
3342 @var{window}.  If @var{line} is one of @code{header-line} or
3343 @code{mode-line}, @code{window-line-height} returns information about
3344 the corresponding line of the window.  Otherwise, @var{line} is a text
3345 line number starting from 0.  A negative number counts from the end of
3346 the window.  The default for @var{line} is the current line in
3347 @var{window}; the default for @var{window} is the selected window.
3349 If the display is not up to date, @code{window-line-height} returns
3350 @code{nil}.  In that case, @code{pos-visible-in-window-p} may be used
3351 to obtain related information.
3353 If there is no line corresponding to the specified @var{line},
3354 @code{window-line-height} returns @code{nil}.  Otherwise, it returns
3355 a list @code{(@var{height} @var{vpos} @var{ypos} @var{offbot})},
3356 where @var{height} is the height in pixels of the visible part of the
3357 line, @var{vpos} and @var{ypos} are the vertical position in lines and
3358 pixels of the line relative to the top of the first text line, and
3359 @var{offbot} is the number of off-window pixels at the bottom of the
3360 text line.  If there are off-window pixels at the top of the (first)
3361 text line, @var{ypos} is negative.
3362 @end defun
3365 @node Textual Scrolling
3366 @section Textual Scrolling
3367 @cindex textual scrolling
3368 @cindex scrolling textually
3370   @dfn{Textual scrolling} means moving the text up or down through a
3371 window.  It works by changing the value of the window's display-start
3372 location.  It may also change the value of @code{window-point} to keep
3373 point on the screen.
3375   Textual scrolling was formerly called ``vertical scrolling,'' but we
3376 changed its name to distinguish it from the new vertical fractional
3377 scrolling feature (@pxref{Vertical Scrolling}).
3379   In the commands @code{scroll-up} and @code{scroll-down}, the directions
3380 ``up'' and ``down'' refer to the motion of the text in the buffer at which
3381 you are looking through the window.  Imagine that the text is
3382 written on a long roll of paper and that the scrolling commands move the
3383 paper up and down.  Thus, if you are looking at text in the middle of a
3384 buffer and repeatedly call @code{scroll-down}, you will eventually see
3385 the beginning of the buffer.
3387   Some people have urged that the opposite convention be used: they
3388 imagine that the window moves over text that remains in place.  Then
3389 ``down'' commands would take you to the end of the buffer.  This view is
3390 more consistent with the actual relationship between windows and the
3391 text in the buffer, but it is less like what the user sees.  The
3392 position of a window on the terminal does not move, and short scrolling
3393 commands clearly move the text up or down on the screen.  We have chosen
3394 names that fit the user's point of view.
3396   The textual scrolling functions (aside from
3397 @code{scroll-other-window}) have unpredictable results if the current
3398 buffer is different from the buffer that is displayed in the selected
3399 window.  @xref{Current Buffer}.
3401   If the window contains a row which is taller than the height of the
3402 window (for example in the presence of a large image), the scroll
3403 functions will adjust the window's vertical scroll position to scroll
3404 the partially visible row.  To disable this feature, Lisp code may bind
3405 the variable @code{auto-window-vscroll} to @code{nil} (@pxref{Vertical
3406 Scrolling}).
3408 @deffn Command scroll-up &optional count
3409 This function scrolls the text in the selected window upward
3410 @var{count} lines.  If @var{count} is negative, scrolling is actually
3411 downward.
3413 If @var{count} is @code{nil} (or omitted), then the length of scroll
3414 is @code{next-screen-context-lines} lines less than the usable height of
3415 the window (not counting its mode line).
3417 @code{scroll-up} returns @code{nil}, unless it gets an error
3418 because it can't scroll any further.
3419 @end deffn
3421 @deffn Command scroll-down &optional count
3422 This function scrolls the text in the selected window downward
3423 @var{count} lines.  If @var{count} is negative, scrolling is actually
3424 upward.
3426 If @var{count} is omitted or @code{nil}, then the length of the scroll
3427 is @code{next-screen-context-lines} lines less than the usable height of
3428 the window (not counting its mode line).
3430 @code{scroll-down} returns @code{nil}, unless it gets an error because
3431 it can't scroll any further.
3432 @end deffn
3434 @deffn Command scroll-other-window &optional count
3435 This function scrolls the text in another window upward @var{count}
3436 lines.  Negative values of @var{count}, or @code{nil}, are handled
3437 as in @code{scroll-up}.
3439 You can specify which buffer to scroll by setting the variable
3440 @code{other-window-scroll-buffer} to a buffer.  If that buffer isn't
3441 already displayed, @code{scroll-other-window} displays it in some
3442 window.
3444 When the selected window is the minibuffer, the next window is normally
3445 the one at the top left corner.  You can specify a different window to
3446 scroll, when the minibuffer is selected, by setting the variable
3447 @code{minibuffer-scroll-window}.  This variable has no effect when any
3448 other window is selected.  When it is non-@code{nil} and the
3449 minibuffer is selected, it takes precedence over
3450 @code{other-window-scroll-buffer}.  @xref{Definition of
3451 minibuffer-scroll-window}.
3453 When the minibuffer is active, it is the next window if the selected
3454 window is the one at the bottom right corner.  In this case,
3455 @code{scroll-other-window} attempts to scroll the minibuffer.  If the
3456 minibuffer contains just one line, it has nowhere to scroll to, so the
3457 line reappears after the echo area momentarily displays the message
3458 @samp{Beginning of buffer}.
3459 @end deffn
3461 @c Emacs 19 feature
3462 @defvar other-window-scroll-buffer
3463 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
3464 which buffer's window to scroll.
3465 @end defvar
3467 @defopt scroll-margin
3468 This option specifies the size of the scroll margin---a minimum number
3469 of lines between point and the top or bottom of a window.  Whenever
3470 point gets within this many lines of the top or bottom of the window,
3471 redisplay scrolls the text automatically (if possible) to move point
3472 out of the margin, closer to the center of the window.
3473 @end defopt
3475 @defopt scroll-conservatively
3476 This variable controls how scrolling is done automatically when point
3477 moves off the screen (or into the scroll margin).  If the value is a
3478 positive integer @var{n}, then redisplay scrolls the text up to
3479 @var{n} lines in either direction, if that will bring point back into
3480 proper view.  This behavior is called @dfn{conservative scrolling}.
3481 Otherwise, scrolling happens in the usual way, under the control of
3482 other variables such as @code{scroll-up-aggressively} and
3483 @code{scroll-down-aggressively}.
3485 The default value is zero, which means that conservative scrolling
3486 never happens.
3487 @end defopt
3489 @defopt scroll-down-aggressively
3490 The value of this variable should be either @code{nil} or a fraction
3491 @var{f} between 0 and 1.  If it is a fraction, that specifies where on
3492 the screen to put point when scrolling down.  More precisely, when a
3493 window scrolls down because point is above the window start, the new
3494 start position is chosen to put point @var{f} part of the window
3495 height from the top.  The larger @var{f}, the more aggressive the
3496 scrolling.
3498 A value of @code{nil} is equivalent to .5, since its effect is to center
3499 point.  This variable automatically becomes buffer-local when set in any
3500 fashion.
3501 @end defopt
3503 @defopt scroll-up-aggressively
3504 Likewise, for scrolling up.  The value, @var{f}, specifies how far
3505 point should be placed from the bottom of the window; thus, as with
3506 @code{scroll-up-aggressively}, a larger value scrolls more aggressively.
3507 @end defopt
3509 @defopt scroll-step
3510 This variable is an older variant of @code{scroll-conservatively}.  The
3511 difference is that it if its value is @var{n}, that permits scrolling
3512 only by precisely @var{n} lines, not a smaller number.  This feature
3513 does not work with @code{scroll-margin}.  The default value is zero.
3514 @end defopt
3516 @defopt scroll-preserve-screen-position
3517 If this option is @code{t}, scrolling which would move the current
3518 point position out of the window chooses the new position of point
3519 so that the vertical position of the cursor is unchanged, if possible.
3521 If it is non-@code{nil} and not @code{t}, then the scrolling functions
3522 always preserve the vertical position of point, if possible.
3523 @end defopt
3525 @defopt next-screen-context-lines
3526 The value of this variable is the number of lines of continuity to
3527 retain when scrolling by full screens.  For example, @code{scroll-up}
3528 with an argument of @code{nil} scrolls so that this many lines at the
3529 bottom of the window appear instead at the top.  The default value is
3530 @code{2}.
3531 @end defopt
3533 @deffn Command recenter &optional count
3534 @cindex centering point
3535 This function scrolls the text in the selected window so that point is
3536 displayed at a specified vertical position within the window.  It does
3537 not ``move point'' with respect to the text.
3539 If @var{count} is a nonnegative number, that puts the line containing
3540 point @var{count} lines down from the top of the window.  If
3541 @var{count} is a negative number, then it counts upward from the
3542 bottom of the window, so that @minus{}1 stands for the last usable
3543 line in the window.  If @var{count} is a non-@code{nil} list, then it
3544 stands for the line in the middle of the window.
3546 If @var{count} is @code{nil}, @code{recenter} puts the line containing
3547 point in the middle of the window, then clears and redisplays the entire
3548 selected frame.
3550 When @code{recenter} is called interactively, @var{count} is the raw
3551 prefix argument.  Thus, typing @kbd{C-u} as the prefix sets the
3552 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
3553 @var{count} to 4, which positions the current line four lines from the
3554 top.
3556 With an argument of zero, @code{recenter} positions the current line at
3557 the top of the window.  This action is so handy that some people make a
3558 separate key binding to do this.  For example,
3560 @example
3561 @group
3562 (defun line-to-top-of-window ()
3563   "Scroll current line to top of window.
3564 Replaces three keystroke sequence C-u 0 C-l."
3565   (interactive)
3566   (recenter 0))
3568 (global-set-key [kp-multiply] 'line-to-top-of-window)
3569 @end group
3570 @end example
3571 @end deffn
3574 @node Vertical Scrolling
3575 @section Vertical Fractional Scrolling
3576 @cindex vertical fractional scrolling
3577 @cindex vertical scroll position
3579    @dfn{Vertical fractional scrolling} means shifting text in a window
3580 up or down by a specified multiple or fraction of a line.  Each window
3581 has a @dfn{vertical scroll position}, which is a number, never less than
3582 zero.  It specifies how far to raise the contents of the window.
3583 Raising the window contents generally makes all or part of some lines
3584 disappear off the top, and all or part of some other lines appear at the
3585 bottom.  The usual value is zero.
3587    The vertical scroll position is measured in units of the normal line
3588 height, which is the height of the default font.  Thus, if the value is
3589 .5, that means the window contents are scrolled up half the normal line
3590 height.  If it is 3.3, that means the window contents are scrolled up
3591 somewhat over three times the normal line height.
3593    What fraction of a line the vertical scrolling covers, or how many
3594 lines, depends on what the lines contain.  A value of .5 could scroll a
3595 line whose height is very short off the screen, while a value of 3.3
3596 could scroll just part of the way through a tall line or an image.
3598 @defun window-vscroll &optional window pixels-p
3599 This function returns the current vertical scroll position of
3600 @var{window}.  The default for @var{window} is the selected window.
3601 If @var{pixels-p} is non-@code{nil}, the return value is measured in
3602 pixels, rather than in units of the normal line height.
3604 @example
3605 @group
3606 (window-vscroll)
3607      @result{} 0
3608 @end group
3609 @end example
3610 @end defun
3612 @defun set-window-vscroll window lines &optional pixels-p
3613 This function sets @var{window}'s vertical scroll position to
3614 @var{lines}.  If @var{window} is @code{nil}, the selected window is
3615 used.  The argument @var{lines} should be zero or positive; if not, it
3616 is taken as zero.
3619 The actual vertical scroll position must always correspond
3620 to an integral number of pixels, so the value you specify
3621 is rounded accordingly.
3623 The return value is the result of this rounding.
3625 @example
3626 @group
3627 (set-window-vscroll (selected-window) 1.2)
3628      @result{} 1.13
3629 @end group
3630 @end example
3632 If @var{pixels-p} is non-@code{nil}, @var{lines} specifies a number of
3633 pixels.  In this case, the return value is @var{lines}.
3634 @end defun
3636 @defvar auto-window-vscroll
3637 If this variable is non-@code{nil}, the line-move, scroll-up, and
3638 scroll-down functions will automatically modify the vertical scroll
3639 position to scroll through display rows that are taller than the height
3640 of the window, for example in the presence of large images.
3641 @end defvar
3644 @node Horizontal Scrolling
3645 @section Horizontal Scrolling
3646 @cindex horizontal scrolling
3648   @dfn{Horizontal scrolling} means shifting the image in the window left
3649 or right by a specified multiple of the normal character width.  Each
3650 window has a @dfn{horizontal scroll position}, which is a number, never
3651 less than zero.  It specifies how far to shift the contents left.
3652 Shifting the window contents left generally makes all or part of some
3653 characters disappear off the left, and all or part of some other
3654 characters appear at the right.  The usual value is zero.
3656   The horizontal scroll position is measured in units of the normal
3657 character width, which is the width of space in the default font.  Thus,
3658 if the value is 5, that means the window contents are scrolled left by 5
3659 times the normal character width.  How many characters actually
3660 disappear off to the left depends on their width, and could vary from
3661 line to line.
3663   Because we read from side to side in the ``inner loop,'' and from top
3664 to bottom in the ``outer loop,'' the effect of horizontal scrolling is
3665 not like that of textual or vertical scrolling.  Textual scrolling
3666 involves selection of a portion of text to display, and vertical
3667 scrolling moves the window contents contiguously; but horizontal
3668 scrolling causes part of @emph{each line} to go off screen.
3670   Usually, no horizontal scrolling is in effect; then the leftmost
3671 column is at the left edge of the window.  In this state, scrolling to
3672 the right is meaningless, since there is no data to the left of the edge
3673 to be revealed by it; so this is not allowed.  Scrolling to the left is
3674 allowed; it scrolls the first columns of text off the edge of the window
3675 and can reveal additional columns on the right that were truncated
3676 before.  Once a window has a nonzero amount of leftward horizontal
3677 scrolling, you can scroll it back to the right, but only so far as to
3678 reduce the net horizontal scroll to zero.  There is no limit to how far
3679 left you can scroll, but eventually all the text will disappear off the
3680 left edge.
3682 @vindex auto-hscroll-mode
3683   If @code{auto-hscroll-mode} is set, redisplay automatically alters
3684 the horizontal scrolling of a window as necessary to ensure that point
3685 is always visible.  However, you can still set the horizontal
3686 scrolling value explicitly.  The value you specify serves as a lower
3687 bound for automatic scrolling, i.e. automatic scrolling will not
3688 scroll a window to a column less than the specified one.
3690 @deffn Command scroll-left &optional count set-minimum
3691 This function scrolls the selected window @var{count} columns to the
3692 left (or to the right if @var{count} is negative).  The default
3693 for @var{count} is the window width, minus 2.
3695 The return value is the total amount of leftward horizontal scrolling in
3696 effect after the change---just like the value returned by
3697 @code{window-hscroll} (below).
3699 Once you scroll a window as far right as it can go, back to its normal
3700 position where the total leftward scrolling is zero, attempts to scroll
3701 any farther right have no effect.
3703 If @var{set-minimum} is non-@code{nil}, the new scroll amount becomes
3704 the lower bound for automatic scrolling; that is, automatic scrolling
3705 will not scroll a window to a column less than the value returned by
3706 this function.  Interactive calls pass non-@code{nil} for
3707 @var{set-minimum}.
3708 @end deffn
3710 @deffn Command scroll-right &optional count set-minimum
3711 This function scrolls the selected window @var{count} columns to the
3712 right (or to the left if @var{count} is negative).  The default
3713 for @var{count} is the window width, minus 2.  Aside from the direction
3714 of scrolling, this works just like @code{scroll-left}.
3715 @end deffn
3717 @defun window-hscroll &optional window
3718 This function returns the total leftward horizontal scrolling of
3719 @var{window}---the number of columns by which the text in @var{window}
3720 is scrolled left past the left margin.  The default for
3721 @var{window} is the selected window.
3723 The return value is never negative.  It is zero when no horizontal
3724 scrolling has been done in @var{window} (which is usually the case).
3727 @example
3728 @group
3729 (window-hscroll)
3730      @result{} 0
3731 @end group
3732 @group
3733 (scroll-left 5)
3734      @result{} 5
3735 @end group
3736 @group
3737 (window-hscroll)
3738      @result{} 5
3739 @end group
3740 @end example
3741 @end defun
3743 @defun set-window-hscroll window columns
3744 This function sets horizontal scrolling of @var{window}.  The value of
3745 @var{columns} specifies the amount of scrolling, in terms of columns
3746 from the left margin.  The argument @var{columns} should be zero or
3747 positive; if not, it is taken as zero.  Fractional values of
3748 @var{columns} are not supported at present.
3750 Note that @code{set-window-hscroll} may appear not to work if you test
3751 it by evaluating a call with @kbd{M-:} in a simple way.  What happens
3752 is that the function sets the horizontal scroll value and returns, but
3753 then redisplay adjusts the horizontal scrolling to make point visible,
3754 and this overrides what the function did.  You can observe the
3755 function's effect if you call it while point is sufficiently far from
3756 the left margin that it will remain visible.
3758 The value returned is @var{columns}.
3760 @example
3761 @group
3762 (set-window-hscroll (selected-window) 10)
3763      @result{} 10
3764 @end group
3765 @end example
3766 @end defun
3768    Here is how you can determine whether a given position @var{position}
3769 is off the screen due to horizontal scrolling:
3771 @example
3772 @group
3773 (defun hscroll-on-screen (window position)
3774   (save-excursion
3775     (goto-char position)
3776     (and
3777      (>= (- (current-column) (window-hscroll window)) 0)
3778      (< (- (current-column) (window-hscroll window))
3779         (window-width window)))))
3780 @end group
3781 @end example
3784 @node Coordinates and Windows
3785 @section Coordinates and Windows
3787 This section describes how to relate edges and screen coordinates to
3788 windows.
3790 @defun window-edges &optional window
3791 This function returns a list of the edge coordinates of @var{window}.
3792 The default for @var{window} is the selected window.
3794 The order of the list is @code{(@var{left} @var{top} @var{right}
3795 @var{bottom})}, all elements relative to 0, 0 at the top left corner of
3796 the frame.  The element @var{right} of the value is one more than the
3797 rightmost column used by @var{window}, and @var{bottom} is one more than
3798 the bottommost row used by @var{window} and its mode-line.
3800 The edges include the space used by the window's scroll bar, display
3801 margins, fringes, header line, and mode line, if it has them.  Also,
3802 if the window has a neighbor on the right, its right edge value
3803 includes the width of the separator line between the window and that
3804 neighbor.  Since the width of the window does not include this
3805 separator, the width does not usually equal the difference between the
3806 right and left edges.
3807 @end defun
3809 @defun window-inside-edges &optional window
3810 This is similar to @code{window-edges}, but the edge values
3811 it returns include only the text area of the window.  They
3812 do not include the header line, mode line, scroll bar or
3813 vertical separator, fringes, or display margins.
3814 @end defun
3816 Here are the results obtained on a typical 24-line terminal with just
3817 one window, with menu bar enabled:
3819 @example
3820 @group
3821 (window-edges (selected-window))
3822      @result{} (0 1 80 23)
3823 @end group
3824 @group
3825 (window-inside-edges (selected-window))
3826      @result{} (0 1 80 22)
3827 @end group
3828 @end example
3830 @noindent
3831 The bottom edge is at line 23 because the last line is the echo area.
3832 The bottom inside edge is at line 22, which is the window's mode line.
3834 If @var{window} is at the upper left corner of its frame, and there is
3835 no menu bar, then @var{bottom} returned by @code{window-edges} is the
3836 same as the value of @code{(window-total-height)}, @var{right} is the
3837 same as the value of @code{(window-total-width)}, and @var{top} and
3838 @var{left} are zero.  For example, the edges of the following window are
3839 @w{@samp{0 0 8 5}}.  Assuming that the frame has more than 8 columns,
3840 the last column of the window (column 7) holds a border rather than
3841 text.  The last row (row 4) holds the mode line, shown here with
3842 @samp{xxxxxxxxx}.
3844 @example
3845 @group
3846            0
3847            _______
3848         0 |       |
3849           |       |
3850           |       |
3851           |       |
3852           xxxxxxxxx  4
3854                   7
3855 @end group
3856 @end example
3858 In the following example, let's suppose that the frame is 7
3859 columns wide.  Then the edges of the left window are @w{@samp{0 0 4 3}}
3860 and the edges of the right window are @w{@samp{4 0 7 3}}.
3861 The inside edges of the left window are @w{@samp{0 0 3 2}},
3862 and the inside edges of the right window are @w{@samp{4 0 7 2}},
3864 @example
3865 @group
3866            ___ ___
3867           |   |   |
3868           |   |   |
3869           xxxxxxxxx
3871            0  34  7
3872 @end group
3873 @end example
3875 @defun window-pixel-edges &optional window
3876 This function is like @code{window-edges} except that, on a graphical
3877 display, the edge values are measured in pixels instead of in
3878 character lines and columns.
3879 @end defun
3881 @defun window-inside-pixel-edges &optional window
3882 This function is like @code{window-inside-edges} except that, on a
3883 graphical display, the edge values are measured in pixels instead of
3884 in character lines and columns.
3885 @end defun
3887 @defun window-at x y &optional frame
3888 This function returns the window containing the specified cursor
3889 position in the frame @var{frame}.  The coordinates @var{x} and @var{y}
3890 are measured in characters and count from the top left corner of the
3891 frame.  If they are out of range, @code{window-at} returns @code{nil}.
3893 If you omit @var{frame}, the selected frame is used.
3894 @end defun
3896 @defun coordinates-in-window-p coordinates window
3897 This function checks whether a particular frame position falls within
3898 the window @var{window}.
3900 The argument @var{coordinates} is a cons cell of the form @code{(@var{x}
3901 . @var{y})}.  The coordinates @var{x} and @var{y} are measured in
3902 characters, and count from the top left corner of the screen or frame.
3904 The value returned by @code{coordinates-in-window-p} is non-@code{nil}
3905 if the coordinates are inside @var{window}.  The value also indicates
3906 what part of the window the position is in, as follows:
3908 @table @code
3909 @item (@var{relx} . @var{rely})
3910 The coordinates are inside @var{window}.  The numbers @var{relx} and
3911 @var{rely} are the equivalent window-relative coordinates for the
3912 specified position, counting from 0 at the top left corner of the
3913 window.
3915 @item mode-line
3916 The coordinates are in the mode line of @var{window}.
3918 @item header-line
3919 The coordinates are in the header line of @var{window}.
3921 @item vertical-line
3922 The coordinates are in the vertical line between @var{window} and its
3923 neighbor to the right.  This value occurs only if the window doesn't
3924 have a scroll bar; positions in a scroll bar are considered outside the
3925 window for these purposes.
3927 @item left-fringe
3928 @itemx right-fringe
3929 The coordinates are in the left or right fringe of the window.
3931 @item left-margin
3932 @itemx right-margin
3933 The coordinates are in the left or right margin of the window.
3935 @item nil
3936 The coordinates are not in any part of @var{window}.
3937 @end table
3939 The function @code{coordinates-in-window-p} does not require a frame as
3940 argument because it always uses the frame that @var{window} is on.
3941 @end defun
3944 @node Window Configurations
3945 @section Window Configurations
3946 @cindex window configurations
3947 @cindex saving window information
3949   A @dfn{window configuration} records the entire layout of one
3950 frame---all windows, their sizes, which buffers they contain, how those
3951 buffers are scrolled, and their values of point and the mark; also their
3952 fringes, margins, and scroll bar settings.  It also includes the value
3953 of @code{minibuffer-scroll-window}.  As a special exception, the window
3954 configuration does not record the value of point in the selected window
3955 for the current buffer.
3957   You can bring back an entire frame layout by restoring a previously
3958 saved window configuration.  If you want to record the layout of all
3959 frames instead of just one, use a frame configuration instead of a
3960 window configuration; see @ref{Frame Configurations}.
3962 @defun current-window-configuration &optional frame
3963 This function returns a new object representing @var{frame}'s current
3964 window configuration.  The default for @var{frame} is the selected
3965 frame.
3966 @end defun
3968 @defun set-window-configuration configuration
3969 This function restores the configuration of windows and buffers as
3970 specified by @var{configuration}, for the frame that @var{configuration}
3971 was created for.
3973 The argument @var{configuration} must be a value that was previously
3974 returned by @code{current-window-configuration}.  The configuration is
3975 restored in the frame from which @var{configuration} was made, whether
3976 that frame is selected or not.  This always counts as a window size
3977 change and triggers execution of the @code{window-size-change-functions}
3978 (@pxref{Window Hooks}), because @code{set-window-configuration} doesn't
3979 know how to tell whether the new configuration actually differs from the
3980 old one.
3982 If the frame which @var{configuration} was saved from is dead, all this
3983 function does is restore the three variables @code{window-min-height},
3984 @code{window-min-width} and @code{minibuffer-scroll-window}. In this
3985 case, the function returns @code{nil}.  Otherwise, it returns @code{t}.
3987 Here is a way of using this function to get the same effect
3988 as @code{save-window-excursion}:
3990 @example
3991 @group
3992 (let ((config (current-window-configuration)))
3993   (unwind-protect
3994       (progn (split-window-vertically nil)
3995              @dots{})
3996     (set-window-configuration config)))
3997 @end group
3998 @end example
3999 @end defun
4001 @defspec save-window-excursion forms@dots{}
4002 This special form records the window configuration, executes @var{forms}
4003 in sequence, then restores the earlier window configuration.  The window
4004 configuration includes, for each window, the value of point and the
4005 portion of the buffer that is visible.  It also includes the choice of
4006 selected window.  However, it does not include the value of point in
4007 the current buffer; use @code{save-excursion} also, if you wish to
4008 preserve that.
4010 Don't use this construct when @code{save-selected-window} is sufficient.
4012 Exit from @code{save-window-excursion} always triggers execution of
4013 @code{window-size-change-functions}.  (It doesn't know how to tell
4014 whether the restored configuration actually differs from the one in
4015 effect at the end of the @var{forms}.)
4017 The return value is the value of the final form in @var{forms}.
4018 For example:
4020 @example
4021 @group
4022 (split-window)
4023      @result{} #<window 25 on control.texi>
4024 @end group
4025 @group
4026 (setq w (selected-window))
4027      @result{} #<window 19 on control.texi>
4028 @end group
4029 @group
4030 (save-window-excursion
4031   (delete-other-windows w)
4032   (switch-to-buffer "foo")
4033   'do-something)
4034      @result{} do-something
4035      ;; @r{The screen is now split again.}
4036 @end group
4037 @end example
4038 @end defspec
4040 @defun window-configuration-p object
4041 This function returns @code{t} if @var{object} is a window configuration.
4042 @end defun
4044 @defun compare-window-configurations config1 config2
4045 This function compares two window configurations as regards the
4046 structure of windows, but ignores the values of point and mark and the
4047 saved scrolling positions---it can return @code{t} even if those
4048 aspects differ.
4050 The function @code{equal} can also compare two window configurations; it
4051 regards configurations as unequal if they differ in any respect, even a
4052 saved point or mark.
4053 @end defun
4055 @defun window-configuration-frame config
4056 This function returns the frame for which the window configuration
4057 @var{config} was made.
4058 @end defun
4060   Other primitives to look inside of window configurations would make
4061 sense, but are not implemented because we did not need them.  See the
4062 file @file{winner.el} for some more operations on windows
4063 configurations.
4065   The objects returned by @code{current-window-configuration} die
4066 together with the Emacs process.  In order to store a window
4067 configuration on disk and read it back in another Emacs session the
4068 following two functions can be used.
4070 @defun window-state-get &optional window markers
4071 This function returns the state of @var{window} as a Lisp object.  The
4072 argument @var{window} can be any window and defaults to the root window
4073 of the selected frame.
4075 The optional argument @var{markers} non-@code{nil} means to use markers
4076 for sampling positions like @code{window-point} or @code{window-start}.
4077 This argument should be non-@code{nil} only if the value is used for
4078 putting the state back in the same session since markers slow down
4079 processing.
4081 The return value can be used as argument for @code{window-state-put},
4082 see below, to put the state recorded here into an arbitrary window.  The
4083 value can be also stored on disk and read back in a new session.
4084 @end defun
4086 The value returned by @code{window-state-get} can be converted by using
4087 one of the functions defined by Desktop Save Mode (@pxref{Desktop Save
4088 Mode}) to an object that can be written to a file.  Such objects can be
4089 read back and converted to a Lisp object representing the state of the
4090 window.  That Lisp object can be used as argument for the following
4091 function in order to restore the state window in anothe window.
4093 @defun window-state-put state &optional window ignore
4094 This function puts the window state @var{state} into @var{window}.  The
4095 argument @var{state} should be the state of a window returned by an
4096 earlier invocation of @code{window-state-get}, see above.  The optional
4097 argument @var{window} must specify a live window and defaults to the
4098 selected one.
4100 The optional argument @var{ignore} non-@code{nil} means to ignore
4101 minimum window sizes and fixed size restrictions.  If @var{ignore}
4102 equals @code{safe}, this means subwindows can get as small as
4103 @code{window-safe-min-height} and @code{window-safe-min-width}.
4104 @end defun
4107 @node Window Parameters
4108 @section Window Parameters
4109 @cindex window parameters
4111 This section describes how window parameters can be used to associate
4112 additional information with windows.
4114 @defun window-parameter window parameter
4115 This function returns @var{window}'s value for @var{parameter}.  The
4116 default for @var{window} is the selected window.  If @var{window} has no
4117 setting for @var{parameter}, this function returns @code{nil}.
4118 @end defun
4120 @defun window-parameters &optional window
4121 This function returns all parameters of @var{window} and their values.
4122 The default for @var{window} is the selected window.  The return value,
4123 if non-@code{nil} is an association list whose elements have the form
4124 @code{(@var{parameter} . @var{value})}.
4125 @end defun
4127 @defun set-window-parameter window parameter value
4128 This function sets @var{window}'s value of @var{parameter} to
4129 @var{value} and returns @var{value}.  The default for @var{window}
4130 is the selected window.
4131 @end defun
4133    A list of windows whose parameter equals some value is produced by
4134 the following function.
4136 @defun windows-with-parameter parameter &optional value frame any values
4137 This function returns a list of all windows on @var{frame} whose
4138 @var{parameter} is non-@code{nil}.  The optional argument @var{frame}
4139 must denote a live frame and defaults to the selected one.
4141 If the optional argument @var{value} is non-@code{nil}, this means to
4142 only return windows whose @var{parameter} equals @var{value} (comparison
4143 is done using @code{equal}).  Optional argument @var{any} non-@code{nil}
4144 means list internal windows a well.  Optional argument @var{values}
4145 non-@code{nil} means return a list of cons cells whose @sc{car} is the
4146 value of the parameter and whose @sc{cdr} is the window.
4147 @end defun
4149    The first window with a specified parameter can be retrieved with the
4150 following function.
4152 @defun window-with-parameter parameter &optional value frame any
4153 This function returns the first window on @var{frame} whose
4154 @var{parameter} is non-@code{nil}.  The optional argument @var{frame}
4155 must denote a live frame and defaults to the selected one.
4157 If the optional argument @var{value} is non-@code{nil}, this means to
4158 only return a window whose @var{parameter} equals @var{value}
4159 (comparison is done with @code{equal}).  If the optional argument
4160 @var{any} is non-@code{nil}, this means to consider internal windows
4161 too.
4162 @end defun
4164 Some functions, notably @code{split-window}, @code{delete-window}, and
4165 @code{delete-other-windows} behave specially when their @var{window}
4166 argument has a parameter set.  For example, @code{delete-window} when
4167 invoked on the main window of an atomic window (@pxref{Atomic Windows})
4168 calls @code{delete-window} with the root window of the atomic window as
4169 argument instead.  The entire information for retrieving the appropriate
4170 root window is maintained with the help of window parameters.
4172 You can override that special behavior by binding the following variable
4173 to a non-@code{nil} value:
4175 @defvar ignore-window-parameters
4176 If this variable is non-@code{nil}, some standard functions ignore
4177 window parameters.  The functions currently affected by this are
4178 @code{split-window}, @code{delete-window}, @code{delete-other-windows}
4179 and @code{other-window}.
4181 An application can bind this variable to a non-@code{nil} value around
4182 calls to these functions.  If it does so, the application is fully
4183 responsible for correctly assigning the parameters of windows when
4184 exiting that function.
4185 @end defvar
4187 The following parameters are currently used by the window management
4188 code.
4190 @table @asis
4191 @item @code{window-atom}
4192 This symbol designates the associated window as part of an atomic
4193 window (@pxref{Atomic Windows}).
4195 @item @code{window-side}
4196 This symbol designates the associated window as part of a side or
4197 non-side window (@pxref{Side Windows}).
4199 @item @code{delete-window-function}
4200 This parameter is used by @code{delete-window} (@pxref{Deleting
4201 Windows}).
4203 @item @code{delete-other-windows-function}
4204 This parameter is used by @code{delete-other-windows} (@pxref{Deleting
4205 Windows}).
4207 @item @code{split-window-function}
4208 This parameter is used by @code{split-window} (@pxref{Splitting
4209 Windows}).
4211 @item @code{other-window-function}
4212 This parameter is used by @code{other-window} (@pxref{Cyclic Window
4213 Ordering}).
4215 @item @code{no-other-window}
4216 This parameter marks the window as not selectable by @code{other-window}
4217 (@pxref{Cyclic Window Ordering}).
4218 @end table
4220 The @code{quit-restore} parameter tells how to proceed with a window
4221 when the user ``quits'' it by invoking @code{quit-restore-window}, see
4222 @ref{Displaying Buffers}.  The following non-@code{nil} values of this
4223 parameter have a special meaning.
4225 @table @asis
4226 @item @code{t}
4227 This means to delete the associated window.  By default, @code{t} is
4228 used for a ``temporary'' window that was obtained by splitting an
4229 existing window.
4231 @item @code{frame}
4232 This means to delete the associated window's frame.  This value
4233 indicates that the associated windows was obtained by popping up a new
4234 frame showing just this window.  If the window is no more needed, it
4235 should be deleted together with the containing frame.
4237 @item A list
4238 This option is useful when the associated window was borrowed to
4239 temporarily display some buffer and quitting shall ``restore'' the
4240 previous contents of the window.  The first three elements of the list
4241 must specify a buffer, a window start position, and a window point.
4242 Quitting the window will then try to display the indicated buffer with
4243 the given start position and point in that window.
4245   The fourth element, if non-@code{nil}, must denote a live buffer.  If
4246 specified, quitting will restore the previous window contents if and
4247 only if the buffer shown in the window is the buffer named by this
4248 element.
4250   The fifth element, if non-@code{nil}, should specify the desired
4251 height of the window when its buffer is restored.  This value is applied
4252 if the buffer temporarily shown in the window was in
4253 @code{temp-buffer-resize-mode} to restore the original height of the
4254 window.
4255 @end table
4258 @node Atomic Windows
4259 @section Atomic Windows
4260 @cindex atomic windows
4262 An @dfn{atomic window} is an internal window (@pxref{Basic Windows})
4263 built from two or more subwindows.  For any subwindow of an atomic
4264 window the behavior of a number of operations changes in the sense that
4265 the operation is suitably applied to the entire atomic window instead.
4267    Atomic windows are useful when you're using two side-by-side windows
4268 to compare or merge buffers.  In this case, you probably don't want
4269 commands like @code{display-buffer} or @kbd{C-x 2} break your window
4270 layout by splitting one of these windows.  Making these windows part of
4271 an atomic window guarantees that the entire atomic window is split
4272 instead.
4274    Another use of atomic windows is that of a sidebar, toolbar or tabbar
4275 appearing on the left or above a ``main'' window.  In this case,
4276 splitting the main window should not break the correspondence between
4277 the bar and the main window.  With atomic windows the relationship
4278 between the bar and the main window remains untouched.
4280    Atomic windows can be created by calling @code{display-buffer}
4281 (@pxref{Displaying Buffers}) with a non-@code{nil} @code{pop-up-window}
4282 and @code{atomic} specifier.  The following call displays a buffer named
4283 ``*bar*'' in a 10 columns wide window on the left of the selected
4284 window.
4286 @example
4287 (display-buffer
4288  (get-buffer-create "*bar*")
4289  '((pop-up-window (selected . left))
4290    (pop-up-window-set-width . 10)
4291    (atomic . t)))
4292 @end example
4294 Alternatively, applications can use @code{display-buffer-pop-up-window}
4295 (@pxref{Displaying Buffers}) in order to make sure that the buffer is
4296 not displayed in some other window provided the selected window can't be
4297 split.
4299 @example
4300 (display-buffer-pop-up-window
4301  (get-buffer-create "*bar*")
4302  '((selected . left))
4303  '((pop-up-window-set-width . 10) (atomic . nest)))
4304 @end example
4306 To make an internal window atomic use the following function:
4308 @defun make-window-atom window
4309 This function make @var{window} an atomic window.  The argument
4310 @var{window} must be an internal window.  It returns @var{window}.
4311 @end defun
4313    Atomic windows are implemented by setting their @code{window-atom}
4314 parameter (@pxref{Window Parameters}) and that of their subwindows to
4315 @code{t}.  To check whether a given window is or is part of an atomic
4316 window simply look at that parameter.  If
4318 @smallexample
4319 (window-parameter window 'window-atom)
4320 @end smallexample
4322 returns @code{t}, the window is part of an atomic window.  To find the
4323 atomic window a given window is part of, use the following function:
4325 @defun window-atom-root window
4326 This function returns the atomic window @var{window} belongs to;
4327 @code{nil} if @var{window} is not part of an atomic window.
4328 @end defun
4330    By default, the behavior of the following commands changes when their
4331 window argument is a member of an atomic window and the variable
4332 @code{ignore-window-parameters} is non-@code{nil}.
4334 @table @asis
4335 @item @code{split-window} (@pxref{Splitting Windows})
4336 When @var{window} is part of an atomic window, @code{split-window} tries
4337 to split the atomic window instead.
4339 @item @code{delete-window} (@pxref{Deleting Windows})
4340 When @var{window} is part of an atomic window, @code{delete-window}
4341 deletes the atomic window instead.  If that window is the root window of
4342 its containing frame, an error is signalled.
4344 @item @code{delete-other-windows} (@pxref{Deleting Windows})
4345 When @var{window} is part of an atomic window,
4346 @code{delete-other-windows} makes the atomic window fill its frame.  If
4347 the atomic window is a non-side window (@pxref{Side Windows}), all other
4348 non-side windows are removed.  If the atomic window is a side window, an
4349 error is signalled.
4350 @end table
4352 You can override the default behavior of these commands by using an
4353 appropriate @code{split-window-function}, @code{delete-window-function}
4354 or @code{delete-other-windows-function}.
4356 The following two invariants must be maintained by all operations on
4357 atomic windows:
4359 @itemize @bullet
4360 @item
4361 An atomic window must contain at least two subwindows.
4363 @item
4364 The @code{window-atom} parameter of an atomic window and of any of its
4365 subwindows must be @code{t}.
4366 @end itemize
4368 Atomic windows violating these invariants are automatically dissolved.
4369 Their component windows continue to exist as normal windows.  Operating
4370 on them, however, is no more different from operating on any other
4371 window.
4374 @node Side Windows
4375 @section Side Windows
4376 @cindex side windows
4377 @cindex non-side windows
4379 A @dfn{side window} is a special window located at one of the four sides
4380 of a frame.  Side windows are useful for assigning buffers always the
4381 same location within a frame whenever they are shown there.  Typically,
4382 side windows would be used for viewing compiler or grep output, buffer
4383 or file listings, completions, or system messages.  They would be
4384 arranged around a set of ``non-side'' windows used for buffers that are
4385 edited.
4387    The following option specifies the layout of side windows on a frame.
4389 @defopt window-sides-vertical
4390 If non-@code{nil}, this variable specifies that left and right side
4391 windows are as high as the containing frame.  Otherwise, top and bottom
4392 side windows are as wide as the containing frame.
4394 Changing this option while side-windows are displayed may lead to
4395 unexpected layouts and should be avoided.
4396 @end defopt
4398 If @code{window-sides-vertical} is @code{nil}, side windows appear as
4399 follows:
4401 @smallexample
4402 @group
4403          ______________________________________ 
4404         |                                      |
4405         |              Top Window              |
4406         |______________________________________|
4407         |        |                    |        |
4408         | Left   |                    | Right  |
4409         | Side   |   Non-side Window  | Side   |
4410         | Window |                    | Window |
4411         |________|____________________|________|
4412         |                                      |
4413         |             Bottom Window            |
4414         |______________________________________|
4416 @end group
4417 @end smallexample
4419 If @code{window-sides-vertical} is non-@code{nil}, side windows are
4420 displayed as follows:
4422 @smallexample
4423 @group
4424          ______________________________________ 
4425         |        |                    |        |
4426         |        |     Top Window     |        |
4427         |        |____________________|        |
4428         |        |                    |        |
4429         | Left   |                    | Right  |
4430         | Side   |   Non-side Window  | Side   |
4431         | Window |                    | Window |
4432         |        |____________________|        |
4433         |        |                    |        |
4434         |        |    Bottom Window   |        |
4435         |________|____________________|________|
4437 @end group
4438 @end smallexample
4440    Side windows can be arbitrarily subdivided.  For each side of a frame
4441 there exists at most one dominating side window which contains all other
4442 windows on the same side as subwindows.  As a rule, windows on the left
4443 or right side of a frame should be vertical combinations.  Windows on
4444 the top or bottom of a frame should be horizontal combinations.  This
4445 makes it easier to assign each life side window a corresponding slot.
4447 @cindex side window slot
4448 A @dfn{side window slot} indicates the relative position of a side
4449 window within the dominating window on that side.  Slots are arbitrary
4450 numbers where the value zero roughly stands for a window in the middle
4451 of that side.  Negative numbers indicate a position above the middle
4452 window (for left and right side windows) or on the left (for the top and
4453 bottom side windows).  Positive numbers stand for windows below the
4454 middle window (for left and right side windows) or on the right (for top
4455 and bottom side windows).
4457 The example below depicts a layout with three subwindows on the top and
4458 two subwindows at the bottom of the frame.
4460 @smallexample
4461 @group
4462          ______________________________________ 
4463         | Left Top   | Middle Top |  Right Top |
4464         | Window     | Window     |  Window    |
4465         |____________|____________|____________|
4466         |        |                    |        |
4467         | Left   |                    | Right  |
4468         | Side   |   Non-side Window  | Side   |
4469         | Window |                    | Window |
4470         |________|____________________|________|
4471         | Left Bottom      |      Right Bottom |
4472         | Window           |      Window       |
4473         |__________________|___________________|
4475 @end group
4476 @end smallexample
4478 The following option can be used to limit the number of subwindows that
4479 may appear on any side of a frame.
4481 @defopt window-sides-slots
4482 This is a list of four elements specifying the number of side window
4483 slots on (in this order) the left, top, right and bottom side of each
4484 frame.  If an element is a number, this means to display at most that
4485 many side windows on the corresponding side.  If an element is
4486 @code{nil}, this means there's no bound on the number of slots on that
4487 side.
4488 @end defopt
4490    Side windows are implemented with the help of @code{window-side}
4491 parameters (@pxref{Window Parameters}).  This parameter is @code{left},
4492 @code{top}, @code{right} or @code{bottom} for a window on the
4493 corresponding side and @code{none} for a non-side window.  The
4494 dominating window on each side as well as the dominating non-side window
4495 have parents whose @code{window-side} parameter is nil.  To get the
4496 dominating side window on the left, for example, use the function
4497 @code{window-with-parameter} like
4499 @smallexample
4500 (window-with-parameter 'window-side 'left nil t)
4501 @end smallexample
4503    If you create side windows by calling @code{display-buffer}
4504 (@pxref{Displaying Buffers}) with the @code{use-side-window} specifier,
4505 this will set up these parameters automatically.  If you want to manage
4506 side windows manually, you should preserve the following invariants:
4508 @itemize @bullet
4509 @item
4510 If a frame has a side window, a non-side window must exist on that frame
4511 as well.  If a frame has a non-side window, at least one side window
4512 must exist on that frame too.
4514 @item
4515 If a window has a non-@code{nil} @code{window-side} parameter, it must
4516 have a parent window and the parent window's @code{window-side}
4517 parameter must be either @code{nil} or the same as for the window.
4519 @item
4520 For any of the values @code{left}, @code{top}, @code{right},
4521 @code{bottom} and @code{none} there can be only one dominating window
4522 whose @code{window-side} parameter equals that value.  More precisely,
4523 this means that at most one window can have its @code{window-side}
4524 parameter set to such a value and have a parent window whose
4525 @code{window-side} parameter is @code{nil}.
4527 @item
4528 Live windows whose @code{window-side} parameter is @code{nil} are
4529 invalid.
4530 @end itemize
4532 If a setup of @code{window-side} parameters fails to satisfy these
4533 invariants, Emacs will reset all @code{window-side} parameters on that
4534 frame to @code{nil}.  Otherwise, the window configuration remains
4535 unchanged.
4537 The behavior of the following commands and functions changes in the
4538 presence of side windows.
4540 @table @asis
4541 @item @code{split-window} (@pxref{Splitting Windows})
4542 If the function @code{split-window} splits a window with a
4543 non-@code{nil} @code{window-side} parameter it assigns the new window
4544 the same parameter value.
4546 @item @code{delete-window} (@pxref{Deleting Windows})
4547 The function @code{delete-window} signal an error when it is invoked
4548 with a non-side window as argument and there are side windows on the
4549 associated frame.
4551 @item @code{delete-other-windows} (@pxref{Deleting Windows})
4552 When @code{delete-other-windows} is invoked with a non-side window as
4553 argument, it will delete all other non-side windows (for an internal
4554 window all non-side windows that are not a subwindow of this window),
4555 When @code{delete-other-windows} is called with a side window as
4556 argument it signals an error.
4557 @end table
4560 @node Window Hooks
4561 @section Hooks for Window Scrolling and Changes
4562 @cindex hooks for window operations
4564 This section describes how a Lisp program can take action whenever a
4565 window displays a different part of its buffer or a different buffer.
4566 There are three actions that can change this: scrolling the window,
4567 switching buffers in the window, and changing the size of the window.
4568 The first two actions run @code{window-scroll-functions}; the last runs
4569 @code{window-size-change-functions}.
4571 @defvar window-scroll-functions
4572 This variable holds a list of functions that Emacs should call before
4573 redisplaying a window with scrolling.  Displaying a different buffer in
4574 the window also runs these functions.
4576 This variable is not a normal hook, because each function is called with
4577 two arguments: the window, and its new display-start position.
4579 These functions must be careful in using @code{window-end}
4580 (@pxref{Window Start and End}); if you need an up-to-date value, you
4581 must use the @var{update} argument to ensure you get it.
4583 @strong{Warning:} don't use this feature to alter the way the window
4584 is scrolled.  It's not designed for that, and such use probably won't
4585 work.
4586 @end defvar
4588 @defvar window-size-change-functions
4589 This variable holds a list of functions to be called if the size of any
4590 window changes for any reason.  The functions are called just once per
4591 redisplay, and just once for each frame on which size changes have
4592 occurred.
4594 Each function receives the frame as its sole argument.  There is no
4595 direct way to find out which windows on that frame have changed size, or
4596 precisely how.  However, if a size-change function records, at each
4597 call, the existing windows and their sizes, it can also compare the
4598 present sizes and the previous sizes.
4600 Creating or deleting windows counts as a size change, and therefore
4601 causes these functions to be called.  Changing the frame size also
4602 counts, because it changes the sizes of the existing windows.
4604 It is not a good idea to use @code{save-window-excursion} (@pxref{Window
4605 Configurations}) in these functions, because that always counts as a
4606 size change, and it would cause these functions to be called over and
4607 over.  In most cases, @code{save-selected-window} (@pxref{Selecting
4608 Windows}) is what you need here.
4609 @end defvar
4611 @defvar window-configuration-change-hook
4612 A normal hook that is run every time you change the window configuration
4613 of an existing frame.  This includes splitting or deleting windows,
4614 changing the sizes of windows, or displaying a different buffer in a
4615 window.
4617 The buffer-local part of this hook is run once per each window on the
4618 affected frame, with the relevant window selected and its buffer
4619 current.  The global part is run once for the modified frame, with that
4620 frame selected.
4621 @end defvar
4623   In addition, you can use @code{jit-lock-register} to register a Font
4624 Lock fontification function, which will be called whenever parts of a
4625 buffer are (re)fontified because a window was scrolled or its size
4626 changed.  @xref{Other Font Lock Variables}.