Rewrite window splitting part of display-buffer so that windows are split evenly.
[emacs.git] / doc / lispref / windows.texi
blob0f1cb085cdad68cc6e982d5f706d2abab5222382
1 @c -*-texinfo-*-
2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001,
4 @c   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 @c   Free Software Foundation, Inc.
6 @c See the file elisp.texi for copying conditions.
7 @setfilename ../../info/windows
8 @node Windows, Positions, Frames, Top
9 @chapter Windows
11   This chapter describes the functions and variables related to Emacs
12 windows.  @xref{Display}, for information on how text is displayed in
13 windows.
15 @menu
16 * Basic Windows::           Basic information on using windows.
17 * Frames and Windows::      Relating windows to the frame they appear on.
18 * Window Sizes::            Accessing a window's size.
19 * Resizing Windows::        Changing the sizes of windows.
20 * Splitting Windows::       Splitting one window into two windows.
21 * Deleting Windows::        Deleting a window gives its space to other windows.
22 * Selecting Windows::       The selected window is the one that you edit in.
23 * Cyclic Window Ordering::  Moving around the existing windows.
24 * Buffers and Windows::     Each live window displays the contents of a buffer.
25 * Displaying Buffers::      How to choose a window for displaying a buffer.
26 * Switching Buffers::       Higher-level functions for switching to a buffer
27                               in some window.
28 * Dedicated Windows::       How to avoid displaying another buffer in
29                               a specific window.
30 * Window Point::            Each window has its own location of point.
31 * Window Start and End::    Buffer positions indicating which text is
32                               on-screen in a window.
33 * Textual Scrolling::       Moving text up and down through the window.
34 * Vertical Scrolling::      Moving the contents up and down on the window.
35 * Horizontal Scrolling::    Moving the contents sideways on the window.
36 * Coordinates and Windows:: Determining a window's edges and
37                               converting coordinates to windows.
38 * Window Configurations::   Saving and restoring the state of the screen.
39 * Window Parameters::       Associating additional information with windows.
40 * Composite Windows::       Composing aggregations of windows.
41 * Compound Windows::        Making several windows behave like a single one.
42 * Window Groups::           Implementing IDE style window compositions.
43 * Window Hooks::            Hooks for scrolling, window size changes,
44                               redisplay going past a certain point,
45                               or window configuration changes.
46 @end menu
48 @node Basic Windows
49 @section Basic Concepts of Emacs Windows
50 @cindex window
52 A @dfn{window} in Emacs is the physical area of the screen in which a
53 buffer is displayed.  The term is also used to refer to a Lisp object
54 that represents that screen area in Emacs Lisp.  It should be clear from
55 the context which is meant.
57 @cindex multiple windows
58   Emacs groups windows into frames; see @ref{Frames}.  Each frame always
59 contains at least one window, but you can subdivide it into multiple,
60 non-overlapping Emacs windows.  Users create multiple windows so they
61 can look at several buffers at once.  Lisp libraries use multiple
62 windows for a variety of reasons, but most often to display related
63 information.  In Rmail, for example, you can move through a summary
64 buffer in one window while the other window shows messages one at a time
65 as they are reached.
67 @cindex terminal screen
68 @cindex screen of terminal
69   The meaning of ``window'' in Emacs is similar to what it means in the
70 context of general-purpose window systems such as X, but not identical.
71 The X Window System places X windows on the screen; Emacs uses one or
72 more X windows as frames, and subdivides them into Emacs windows.  When
73 you use Emacs on a character-only terminal, Emacs treats the whole
74 terminal screen as one frame.
76 @cindex tiled windows
77   Most window systems support arbitrarily located overlapping windows.
78 In contrast, Emacs windows are @dfn{tiled}; they never overlap, and
79 together they fill the whole screen or frame.  Because of the way in
80 which Emacs creates new windows (@pxref{Splitting Windows}) and resizes
81 them (@pxref{Resizing Windows}), not all conceivable tilings of windows
82 on an Emacs frame are actually possible.
84   For practical purposes, a window exists only while it is displayed in
85 a frame.  Once removed from the frame, the window is effectively deleted
86 and should not be used, @emph{even though there may still be references
87 to it} from other Lisp objects; see @ref{Deleting Windows}.  Restoring a
88 saved window configuration is the only way for a window no longer on the
89 screen to come back to life; see @ref{Window Configurations}.
91 @defun windowp object
92 This function returns @code{t} if @var{object} is a window and
93 @code{nil} otherwise.
94 @end defun
96 @cindex live windows
97 @cindex internal windows
98    For historical reasons a window is considered @dfn{live} if and only
99 if it currently displays a buffer; see @ref{Buffers and Windows}.  In
100 order to show multiple windows within one and the same frame, Emacs
101 organizes them in form of a tree called window tree; see @ref{Frames and
102 Windows}.  The internal nodes of a window tree are called internal
103 windows and are not considered live.  The leaf nodes of a window tree
104 constitute the windows displaying buffers and only they will be called
105 live here.  The selected window (@pxref{Selecting Windows}) is always a
106 live window.
108 @defun window-live-p object
109 This function returns @code{t} if @var{object} is a live window and
110 @code{nil} otherwise.  A live window is a window that is currently used
111 to display a buffer.
112 @end defun
114 @defun window-internal-p object
115 This function returns @code{t} if @var{object} denotes an internal
116 window and @code{nil} otherwise.  An internal window is a window that
117 currently has at least two child windows, see @ref{Frames and Windows}.
118 @end defun
120 @defun window-any-p object
121 This function returns @code{t} if @var{object} denotes a live or an
122 internal window and @code{nil} otherwise.  In particular, this function
123 returns @code{nil} if @var{object} is a window that has been
124 deleted.
125 @end defun
127    The window handling functions can be roughly grouped into functions
128 operating on live windows only and functions that accept any window as
129 argument.  Many of these function accept the value @code{nil} to specify
130 the selected window.  The two functions below can be used to
131 ``normalize'' arguments specifying windows in a uniform manner.
133 @defun normalize-any-window window
134 This function returns the normalized value for @var{window} which can be
135 any window that has not been deleted.  More precisely, if @var{window}
136 is @code{nil} it returns the selected window.  If @var{window} is
137 non-@code{nil} and denotes a live or an internal window, this function
138 returns @var{window}.  In any other case this function signals an error.
139 @end defun
141 @defun normalize-live-window window
142 This functions returns the normalized value for a live window
143 @var{window}.  More precisely, if @var{window} is @code{nil} it returns
144 the selected window.  Otherwise, if @var{window} is a live window this
145 function returns @var{window}.  If @var{window} is neither @code{nil}
146 nor a live window this function signals an error.
147 @end defun
149 @node Frames and Windows
150 @section Frames and Windows
152 Each window is part of one and only one frame (@pxref{Frames}); you can
153 get that frame with the following function.
155 @defun window-frame window
156 This function returns the frame that @var{window} is on.  The argument
157 @var{window} can be any window and defaults to the selected one.
158 @end defun
160 A list of all live windows on a specific frame can be obtained by
161 calling the following function.
163 @defun window-list &optional frame minibuf window
164 This function returns a list of @var{frame}'s live windows, starting
165 with @var{window}.  The argument @var{frame} has to denote a live frame
166 and defaults to the selected frame.  The argument @var{window} has to
167 denote a live window on the frame specified by @var{frame} and defaults
168 to the selected one.
170 The argument @var{minibuf} specifies if the minibuffer window shall be
171 included in the return value.  If @var{minibuf} is @code{t}, the result
172 always includes the minibuffer window.  If @var{minibuf} is @code{nil}
173 or omitted, that includes the minibuffer window only if it is active.
174 If @var{minibuf} is neither @code{nil} nor @code{t}, the result never
175 includes the minibuffer window.
176 @end defun
178 @cindex window tree
179 Windows within one and the same frame are organized in form of a tree
180 called @dfn{window tree}.  The leaf nodes of a window tree constitute
181 the windows visible to the user.  These are the windows associated with
182 buffers and are usually called live or leaf windows.  The internal nodes
183 of a window tree are needed for finding, traversing and displaying the
184 leaf windows.
186    A minibuffer window (@pxref{Minibuffer Windows}) is not considered
187 part of its frame's window tree unless the frame is a minibuffer-only
188 frame.  Most functions covered in this section accept, however, the
189 minibuffer window as argument.  Also, the minibuffer window is listed by
190 the function @code{window-tree} described at the end of this section.
192    Most window functions can be used without understanding the internals
193 of window trees.  Some aspects, in particular the implementation of
194 compound windows (@pxref{Compound Windows}) and window groups
195 (@pxref{Window Groups}) require, however, a basic understanding of
196 window trees.
198    A window tree is rooted at the root window of its frame.
200 @defun frame-root-window &optional frame-or-window
201 This function returns the root window of @var{frame-or-window}.  The
202 argument @var{frame-or-window} has to denote either a window or a frame
203 and defaults to the selected frame.  If @var{frame-or-window} denotes a
204 window, the return value is the root window of that window's frame.
205 This function always returns a window; a live window if the frame
206 specified by @var{frame-or-window} contains no other live windows and an
207 internal window otherwise.
208 @end defun
210 @cindex subwindow
211 All other windows of a frame with the exception of the minibuffer window
212 are subwindows of the frame's root window.  A window is considered a
213 @dfn{subwindow} of another window if and only if it occupies a part of
214 that other window's screen area.
216 The functions described next allow to access the members of a window
217 tree with an arbitrary window as argument.
219 @cindex parent window
220 @defun window-parent &optional window
221 Return @var{window}'s parent in the window tree.  The optional argument
222 @var{window} can denote an arbitrary window and defaults to the selected
223 one.  The return value is either an internal window or @code{nil} if
224 @var{window} is a minibuffer window or the root window of its frame.
225 @end defun
227 @cindex child window
228    Parent windows do not appear on the screen.  The screen area of a
229 parent window is the rectangular part of the window's frame occupied by
230 the window's @dfn{child windows}, that is the set of windows having that
231 window as their parent.  Each parent window has at least two child
232 windows, so there are no ``Matryoshka'' windows.  Minibuffer windows do
233 not have child windows.
235 @cindex window combination
236 @cindex vertical combination
237 @cindex horizontal combination
238 The children of any parent window form either a vertical or a horizontal
239 combination of windows.  A @dfn{vertical combination} is a set of
240 windows arranged one above each other.  A @dfn{horizontal combination}
241 is a set of windows arranged side by side.  For any parent window, the
242 first child window is accessible by the functions given next.
244 @defun window-vchild &optional window
245 This function returns @var{window}'s first vertical child window.  The
246 optional argument @var{window} can be an arbitrary window and defaults
247 to the selected one.  The return value is @code{nil} if @var{window} is
248 a leaf window or its children form a horizontal combination.
249 @end defun
251 @defun window-hchild &optional window
252 This function returns @var{window}'s first horizontal child window.  The
253 optional argument @var{window} can be an arbitrary window and defaults
254 to the selected one.  The return value is @code{nil} if @var{window} is
255 a leaf window or its children form a vertical combination.
256 @end defun
258 @defun window-child window
259 This function return @var{window}'s first child window.  The return
260 value is @code{nil} if @var{window} is a leaf window.
261 @end defun
263 The following function is useful to determine whether a window is part
264 of a vertical or horizontal combination.
266 @defun window-iso-combined-p &optional window horizontal
267 This function returns a non-@code{nil} value if and only if @var{window}
268 is vertically combined.  The argument @var{window} can specify any
269 window and defaults to the selected one.  The actual return value is the
270 first vertical child of window.
272 If the optional argument @var{horizontal} is non-@code{nil}, this means
273 to return non-@code{nil} if and only if @var{window} is horizontally
274 combined.  The actual return value is the first horizontal child of
275 window.
276 @end defun
278 @cindex sibling window
279 For any window that is part of a combination, the other windows in that
280 combination are called the window's @dfn{siblings}.  The only windows
281 that do not have any siblings are the frames' root windows and the
282 minibuffer windows.  A window's siblings can be retrieved with the
283 following two functions.
285 @defun window-next &optional window
286 This function returns @var{window}'s right sibling.  The optional
287 argument @var{window} can be an arbitrary window and defaults to the
288 selected window.  It returns @code{nil} if @var{window} has no right
289 sibling.  Applying this function recursively will eventually get you to
290 the last child of @var{window}'s parent.
291 @end defun
293 @defun window-prev &optional window
294 This function returns @var{window}'s left sibling.  The optional
295 argument @var{window} can be an arbitrary window and defaults to the
296 selected window.  It returns @code{nil} if @var{window} has no left
297 sibling.  Applying this function recursively will eventually get you to
298 the first child of @var{window}'s parent.
299 @end defun
301 The functions @code{window-next} and @code{window-prev} should not be
302 confused with the functions @code{next-window} and
303 @code{previous-window} which respectively return the next and previous
304 window in the cyclic ordering of windows, see @ref{Cyclic Window
305 Ordering}.
307    In order to find the first live window on a frame, the following
308 function can be used.
310 @defun frame-first-window &optional frame-or-window
311 This function returns the window at the upper left corner of the frame
312 specified by @var{frame-or-window}.  The argument @var{frame-or-window}
313 must denote a window or a live frame and defaults to the selected frame.
314 If @var{frame-or-window} specifies a window, this function returns the
315 first window on that window's frame.
316 @end defun
318 You can get the window tree of a frame with the following function.
320 @cindex window tree
321 @defun window-tree &optional frame
322 This function returns the window tree for frame @var{frame}.  The
323 optional argument @var{frame} must be a live frame and defaults to the
324 selected one.
326 The return value is a list of the form @code{(@var{root} @var{mini})},
327 where @var{root} represents the window tree of the frame's
328 root window, and @var{mini} is the frame's minibuffer window.
330 If the root window is live, @var{root} specifies the root window and
331 nothing else.  Otherwise, @var{root} is a list @code{(@var{dir}
332 @var{edges} @var{w1} @var{w2} ...)} where @var{dir} is @code{nil} for a
333 horizontal combination, and @code{t} for a vertical combination,
334 @var{edges} gives the size and position of the combination, and the
335 remaining elements are the child windows.  Each child window may again
336 be a live window or a list representing a window combination, and so on.
337 The @var{edges} element is a list @code{(@var{left}@var{ top}@var{
338 right}@var{ bottom})} similar to the value returned by
339 @code{window-edges}, see @ref{Coordinates and Windows}.
340 @end defun
342 @node Window Sizes
343 @section Window Sizes
344 @cindex window size
345 @cindex size of window
347 Emacs windows are rectangular.  The structure of a live window can be
348 roughly sketched as follows:
350 @smallexample
351 @group
352          _________________________________________ 
353       ^ |______________ Header Line_______________| 
354       | |LS|LF|LM|                       |RM|RF|RS| ^
355       | |  |  |  |                       |  |  |  | |
356  Window |  |  |  |       Text Area       |  |  |  | Window
357  Total  |  |  |  |     (Window Body)     |  |  |  | Body
358  Height |  |  |  |                       |  |  |  | Height
359       | |  |  |  |<- Window Body Width ->|  |  |  | |
360       | |__|__|__|_______________________|__|__|__| v
361       v |_______________ Mode Line _______________|
363          <----------- Window Total Width -------->
365 @end group
366 @end smallexample
368 @cindex window body
369 @cindex body of a window
370 The text area constitutes the body of the window.  In its most simple
371 form, a window consists of its body alone.  LS and RS stand for the left
372 and right scroll bar (@pxref{Scroll Bars}) respectively.  Only one of
373 them can be present, in practice.  LF and RF denote the left and right
374 fringe, see @ref{Fringes}.  LM and RM, finally, stand for the left and
375 right display margin, see @ref{Display Margins}.  Any header line is
376 located above theses areas, any mode line below, see @ref{Mode Line
377 Format}.
379 @cindex window height
380 @cindex total window height
381 @cindex height of a window
382 @cindex total height of a window
383 The @dfn{total height of a window} is specified as the total number of
384 lines occupied by the window.  Any mode or header line is included in a
385 window's total height.  For an internal window, the total height is
386 calculated recursively from the total heights of its child windows.
388 @cindex window width
389 @cindex total window width
390 @cindex width of a window
391 @cindex total width of a window
392 The @dfn{total width of a window} denotes the total number of columns of
393 the window.  Any scroll bar and the column of @samp{|} characters that
394 separate the window from its right sibling are included in a window's
395 total width.  On a window-system also fringes and display margins are
396 included in a window's total width.  For an internal window, the total
397 width is calculated recursively from the total widths of its child
398 windows.
400 @cindex total size of a window
401 @cindex total window size
402 The following function is the standard interface for getting the total
403 size of any window:
405 @defun window-total-size &optional window &optional horizontal
406 This function returns the total number of lines of @var{window}.  The
407 argument @var{window} can denote any window and defaults to the selected
408 one.  If @var{window} is live, the return value includes any header or
409 mode lines of @var{window}.  If @var{window} is internal, the return
410 value is the sum of the total heights of @var{window}'s child windows
411 provided these are vertically combined and the height of @var{window}'s
412 first child if they are horizontally combined.
414 If optional argument @var{horizontal} is non-@code{nil}, this function
415 returns the total number of columns of @var{window}.  If @var{window} is
416 live, the return value includes any vertical divider column or scroll
417 bars owned by @var{window}.  On a window-system the return value also
418 includes the space occupied by any margins and fringes of @var{window}.
419 If @var{window} is internal, the return value is the sum of the total
420 widths of @var{window}'s child windows provided these are horizontally
421 combined and the width of @var{window}'s first child otherwise.
422 @end defun
424 Alternatively, the following two functions can be used to retrieve
425 either the total height of the total width of a window:
427 @defun window-total-height &optional window
428 This function returns the total number of lines of @var{window}.
429 @var{window} can be any window and defaults to the selected one.  The
430 return value includes @var{window}'s mode line and header line, if any.
431 If @var{window} is internal the return value is the sum of heights of
432 @var{window}'s child windows for a vertical combination and the height
433 of @var{window}'s first child otherwise.
434 @end defun
436 @defun window-total-width &optional window
437 This function returns the total number of columns of @var{window}.
438 @var{window} can be any window and defaults to the selected one.  The
439 return value includes any vertical dividers or scrollbars of
440 @var{window}.  On a window-system the return value also includes the
441 space occupied by any margins and fringes of @var{window}.  If
442 @var{window} is internal, the return value is the sum of the widths of
443 @var{window}'s child windows for a horizontal combination and the width
444 of @var{window}'s first child otherwise.
445 @end defun
447 The total height of any window is usually less than the height of the
448 associated frame, because the latter may also include the minibuffer
449 window.  Depending on the toolkit in use, the frame height can also
450 include the menu bar and the tool bar (@pxref{Size and Position}).
451 Therefore, in general it is not straightforward to compare window and
452 frame heights.  The following function can be used to determine whether
453 a window is as high as the containing frame:
455 @cindex full-height window
456 @defun window-full-height-p &optional window
457 This function returns non-@code{nil} if there is no other window above
458 or below @var{window} on the containing frame.  More precisely, this
459 function returns @code{t} if and only if the total height of
460 @var{window} equals the total height of the root window (@pxref{Frames
461 and Windows}) of @var{window}'s frame.  The @var{window} argument may
462 denote any window and defaults to the selected one.
463 @end defun
465 @cindex full-width window
466 The following function can be used to determine whether a window is as
467 wide as the containing frame.
469 @defun window-full-width-p &optional window
470 This function returns non-@code{nil} if @var{window} is as wide as the
471 frame that contains it; otherwise @code{nil}.  More precisely, this
472 function returns @code{t} if and only if the total width of @var{window}
473 equals the total width of the root window (@pxref{Frames and Windows})
474 of @var{window}'s frame.  The @var{window} argument may denote any
475 window and defaults to the selected one.
476 @end defun
478 @cindex top line of window
479 @cindex left column of window
480   Each window in a frame is unambiguously characterized by the
481 combination of its top line and its left column within that frame.
483 @defun window-top-line &optional window
484 This function returns the top line of @var{window}.  The argument
485 @var{window} can denote any window and defaults to the selected one.
486 @end defun
488 @defun window-left-column &optional window
489 This function returns the left column of @var{window}.  The argument
490 @var{window} can denote any window and defaults to the selected one.
491 @end defun
493 For a frame displaying one window only, that window's top line and left
494 column are both zero.  When a frame displays a window @var{WB} below a
495 window @var{WA}, the top line of @var{WB} can be calculated by adding
496 the total height of @var{WA} to the top line of @var{WA}.  When a frame
497 displays a window @var{WR} on the right of a window @var{WL}, the left
498 column of @var{WR} can be calculated by adding the total width of
499 @var{WL} to the left column of @var{WL}.
501 @cindex window body height
502 @cindex body height of a window
503 The @dfn{body height of a window} is specified as the total number of
504 lines occupied by the window's text area.  Any mode or header line is
505 not included in a window's body height.
507 @cindex window body width
508 @cindex body width of a window
509 The @dfn{body width of a window} denotes the total number of columns
510 occupied by the window's text area.  Any scroll bar or column of
511 @samp{|} characters that separates side-by-side windows is not included
512 in a window's body width.
514 @cindex body size of a window
515 @cindex window body size
516 The following functions retrieve height and width of the body of a live
517 window:
519 @defun window-body-size &optional window horizontal
520 This function returns the number of lines of @var{window}'s text area.
521 @var{window} must be a live window and defaults to the selected one.
522 The return value does not count any mode or header line of @var{window}.
524 Optional argument @var{horizontal} non-@code{nil} means to return the
525 number of columns of @var{window}'s text area.  In this case the return
526 value does not include any vertical divider or scroll bar owned by
527 @var{window}.  On a window-system the return value does not include the
528 number of columns used for @var{window}'s fringes or display margins
529 either.
530 @end defun
532 @defun window-body-height &optional window
533 This function returns the number of lines of @var{window}'s body.
534 @var{window} must be a live window and defaults to the selected one.
536 The return value does not include @var{window}'s mode line and header
537 line, if any.  If a line at the bottom of the window is only partially
538 visible, that line is included in the return value.  If you do not
539 want to include a partially visible bottom line in the return value,
540 use @code{window-text-height} instead.
541 @end defun
543 @defun window-body-width &optional window
544 This function returns the number of columns of @var{window}'s body.
545 @var{window} must be a live window and defaults to the selected one.
547 The return value does not include any vertical dividers or scroll bars
548 owned by @var{window}.  On a window-system the return value does not
549 include the number of columns used for @var{window}'s fringes or
550 display margins either.
551 @end defun
553 The following functions have been used in earlier versions of Emacs.
554 They are still supported but due to the confusing nomenclature they
555 should not be used any more in future code.
557 @defun window-height &optional window
558 This function is an alias for `window-total-height', see above.
559 @end defun
561 @defun window-width &optional window
562 This function is an alias for `window-body-width', see above.
563 @end defun
565 @cindex minimum window size
566   The following two options constrain the sizes of windows to a minimum
567 height and width.  Their values are honored when windows are split
568 (@pxref{Splitting Windows}) or resized.  Any request to make a window
569 smaller than specified here will usually result in an error.
571 @defopt window-min-height
572 The value of this variable specifies how short a window may be.  The
573 value is measured in line units and has to account for any header or
574 mode line.  The default value for this option is @code{4}.  Any value
575 less than @code{1} is ignored.
576 @end defopt
578 @defopt window-min-width
579 The value of this variable specifies how narrow a window may be.  The
580 value is measured in characters and includes any margins, fringes,
581 scroll bar and vertical divider column.  The default value for this
582 option is @code{10}.  A value less than @code{2} is ignored.
583 @end defopt
585 An application should not rebind these variables.  To shrink a specific
586 window to a height or width less than the one specified here, it should
587 rather invoke @code{resize-window} with a non-@code{nil} @var{ignore}
588 argument.  The function @code{split-window} (@pxref{Splitting Windows})
589 can make a window smaller than specified here by setting its @var{size}
590 argument to a non-@code{nil} value.  Interactively, the values specified
591 here cannot be overridden.
593    Earlier versions of Emacs could delete a window when its size dropped
594 below @code{window-min-height} or @code{window-min-width}.  The current
595 version of Emacs does no more implicitly delete windows.  The only
596 exception to this rule are requests to resize a frame which may
597 implicitly delete windows when they do not fit on the frame any more,
598 see @ref{Size and Position}.
600    The size of a window can be fixed which means that it cannot be split
601 (@pxref{Splitting Windows}) or resized (@pxref{Resizing Windows}).
603 @cindex fixed-size window
604 @defvar window-size-fixed
605 If this variable is non-@code{nil}, in a given buffer, then the size of
606 any window displaying that buffer remains fixed unless you either
607 explicitly change it or Emacs has no other choice.
609 If the value is @code{height}, then only the window's height is fixed;
610 if the value is @code{width}, then only the window's width is fixed.
611 Any other non-@code{nil} value fixes both the width and the height.
613 This variable automatically becomes buffer-local when set.
614 @end defvar
616 Commands supposed to explicitly change the size of windows such as
617 @code{enlarge-window} (@pxref{Resizing Windows}) get an error if they
618 would have to change a window size which is fixed.  Other functions like
619 @code{resize-window} (@pxref{Resizing Windows}) have an optional
620 @var{ignore} argument which allows to change the size of fixed-size
621 windows.
623    Deleting a window or changing a frame's size may change the size of a
624 fixed-size window, if there is no other alternative.
626    A vertical combination of windows cannot be resized when the height
627 of all windows in that combination is fixed.  A horizontal combination
628 cannot be resized when the width of all windows in it is fixed.  The
629 next function allows to check whether the size of an arbitrary window is
630 fixed.
632 @defun window-size-fixed-p &optional window horizontal
633 This function returns non-@code{nil} if @var{window}'s height is fixed.
634 The argument @var{window} can be an arbitrary window and defaults to the
635 selected one.  Optional argument @var{horizontal} non-@code{nil} means
636 return non-@code{nil} if @var{window}'s width is fixed.
638 If this function returns @code{nil}, this does not necessarily mean that
639 @var{window} can be resized in the desired direction.  The function
640 @code{window-resizable} (@pxref{Resizing Windows}) can tell that.
641 @end defun
643 @node Resizing Windows
644 @section Resizing Windows
645 @cindex window resizing
646 @cindex resize window
647 @cindex changing window size
648 @cindex window size, changing
650 Emacs does not permit overlapping windows or gaps between windows, so
651 changing the size of a window always affects at least one other window.
652 When a frame contains just one window, that window can be resized only
653 implicitly by resizing the window's frame.  The functions described
654 below are therefore meaningful exclusively in the context of a frame
655 containing at least two windows.  The size of that frame never changes
656 when invoking a function described in this section.
658    The routines changing window sizes always operate in one dimension at
659 a time.  This means that windows can be resized only either vertically
660 or horizontally.  If a window shall be resized in both dimensions, it
661 must be resized in one dimension first and in the other dimension
662 afterwards.  If the second resize operation fails, the frame might end
663 up in an unsatisfactory state.  To avoid such states, it might be useful
664 to save the current window configuration (@pxref{Window Configurations})
665 before attempting the first resize operation and restore the saved
666 configuration in case the second resize operation fails.
668    Functions that resize windows are supposed to obey restrictions
669 imposed by window minimum sizes and fixed-size windows, see @ref{Window
670 Sizes}.  In order to determine whether resizing a specific window is
671 possible in the first place, the following function can be used:
673 @defun window-resizable window delta &optional horizontal ignore side noup nodown
674 This function returns @var{delta} if the size of @var{window} can be
675 changed vertically by @var{delta} lines.  Optional argument
676 @var{horizontal} non-@code{nil} means to return @var{delta} if
677 @var{window} can be resized horizontally by @var{delta} columns.  A
678 return value of zero means that @var{window} is not resizable.
680 If @var{delta} is a positive number, this means that @var{window} shall
681 be enlarged by @var{delta} lines or columns.  If @var{window} cannot be
682 enlarged by @var{delta} lines or columns this function returns the
683 maximum value in the range from 0 to @var{delta} by which @var{window}
684 can be enlarged.
686 If @var{delta} is a negative number, this means that @var{window} shall
687 be shrunk by -@var{delta} lines or columns.  If @var{window} cannot be
688 shrunk by -@var{delta} lines or columns, this function returns the
689 minimum value in the range from @var{delta} to 0 that can be used for
690 shrinking @var{window}.
692 Optional argument @var{ignore} non-@code{nil} means ignore any
693 restrictions imposed by the variables @code{window-min-height} or
694 @code{window-min-width} and @code{window-size-fixed}.  In this case the
695 minimum height of a window is specified as the minimum number of lines
696 that allow viewing any header or mode line and at least one line of the
697 text area of window.  The minimum width of a window includes any
698 fringes, margins and the scroll bar as well as two text columns.
700 If @var{ignore} denotes a window, this means to ignore restrictions for
701 that window only.  If @var{ignore} equals the constant @code{safe}, this
702 means a live window may get as small as one line or two columns.
704 Optional argument @var{noup} non-@code{nil} means don't go up in the
705 window tree but try to steal or distribute the space needed for the
706 resize operation among the other windows within @var{window}'s
707 combination.  Optional argument @var{nodown} non-@code{nil} means don't
708 check whether @var{window} and its subwindows can be resized.
709 @end defun
711 The function @code{window-resizable} does not change any window sizes.
712 The following function does:
714 @defun resize-window window delta &optional horizontal ignore
715 This function resizes @var{window} vertically by @var{delta} lines.  The
716 argument @var{window} can denote an arbitrary window and defaults to the
717 selected one.  An attempt to resize the root window of a frame will
718 raise an error.
720 Second argument @var{delta} a positive number means @var{window} shall
721 be enlarged by @var{delta} lines.  If @var{delta} is negative, that
722 means @var{window} shall be shrunk by -@var{delta} lines.
724 Optional argument @var{horizontal} non-@code{nil} means to resize
725 @var{window} horizontally by @var{delta} columns.  In this case a
726 positive @var{delta} means enlarge @var{window} by @var{delta} columns.
727 A negative @var{delta} means @var{window} shall be shrunk by
728 -@var{delta} columns.
730 Optional argument @var{ignore} has the same meaning as for the function
731 @code{window-resizable} above.
733 This function resizes other windows proportionally and never deletes any
734 windows.  If only the low (right) edge of @var{window} shall be moved,
735 the function @code{adjust-window-trailing-edge} described below should
736 be used.
737 @end defun
739 The next four commands are simple interfaces to @code{resize-window}.
740 They always operate on the selected window, never delete any window, and
741 always raise an error when resizing would violate a restriction imposed
742 by @code{window-min-height}, @code{window-min-width}, or
743 @code{window-size-fixed}.
745 @deffn Command enlarge-window delta &optional horizontal
746 This function makes the selected window @var{delta} lines taller.
747 Interactively, if no argument is given, it makes the selected window one
748 line taller.  If optional argument @var{horizontal} is non-@code{nil},
749 it makes the selected window wider by @var{delta} columns.  If
750 @var{delta} is negative, it shrinks the selected window by -@var{delta}
751 lines or columns.  The return value is @code{nil}.
752 @end deffn
754 @deffn Command enlarge-window-horizontally delta
755 This function makes the selected window @var{delta} columns wider.
756 Interactively, if no argument is given, it makes the selected window one
757 column wider.
758 @end deffn
760 @deffn Command shrink-window delta &optional horizontal
761 This function makes the selected window @var{delta} lines smaller.
762 Interactively, if no argument is given, it makes the selected window one
763 line smaller.  If optional argument @var{horizontal} is non-@code{nil},
764 it makes the selected window narrower by @var{delta} columns.  If
765 @var{delta} is negative, it enlarges the selected window by -@var{delta}
766 lines or columns.  The return value is @code{nil}.
767 @end deffn
769 @deffn Command shrink-window-horizontally delta
770 This function makes the selected window @var{delta} columns narrower.
771 Interactively, if no argument is given, it makes the selected window one
772 column narrower.
773 @end deffn
775 @defun adjust-window-trailing-edge window delta &optional horizontal
776 Move @var{window}'s bottom edge by @var{delta} lines.  Optional
777 argument @var{horizontal} non-@code{nil} means move @var{window}'s
778 right edge by @var{delta} columns.  @var{window} defaults to the
779 selected window.
781 If the edge can't be moved by @var{delta} lines, move it as far as
782 possible in the desired direction.
783 @end defun
785 @deffn Command fit-window-to-buffer &optional window max-height min-height override
786 This command makes @var{window} the right height to display its
787 contents exactly.  The default for @var{window} is the selected window.
789 The optional argument @var{max-height} specifies the maximum height the
790 window is allowed to be; @code{nil} means use the maximum permissible
791 height of a window on @var{window}'s frame.  The optional argument
792 @var{min-height} specifies the minimum height for the window; @code{nil}
793 means use @code{window-min-height}.  All these height values include the
794 mode line and/or header line.
796 If the optional argument @var{override} is non-@code{nil}, this means to
797 ignore any restrictions imposed by @code{window-min-height} and
798 @code{window-min-width} on the size of @var{window}.
800 This function returns non-@code{nil} if it orderly resized @var{window},
801 and @code{nil} otherwise.
802 @end deffn
804 @deffn Command shrink-window-if-larger-than-buffer &optional window
805 This command shrinks @var{window} vertically to be as small as possible
806 while still showing the full contents of its buffer---but not less than
807 @code{window-min-height} lines.  The argument @var{window} must denote
808 a live window and defaults to the selected one.
810 However, this command does nothing if the window is already too small to
811 display the whole text of the buffer, or if part of the contents are
812 currently scrolled off screen, or if the window is not the full width of
813 its frame, or if the window is the only window in its frame.
815 This command returns non-@code{nil} if it actually shrank the window
816 and @code{nil} otherwise.
817 @end deffn
819 @cindex balancing window sizes
820 Emacs provides two functions to balance windows, that is, to even out
821 the sizes of windows on the same frame.  The minibuffer window and
822 fixed-size windows are not resized by these functions.
824 @deffn Command balance-windows &optional window-or-frame
825 This function balances windows in a way that gives more space to
826 full-width and/or full-height windows.  If @var{window-or-frame}
827 specifies a frame, it balances all windows on that frame.  If
828 @var{window-or-frame} specifies a window, it balances that window and
829 its siblings (@pxref{Frames and Windows}) only.
830 @end deffn
832 @deffn Command balance-windows-area
833 This function attempts to give all windows on the selected frame
834 approximately the same share of the screen area.  This means that
835 full-width or full-height windows are not given more space than other
836 windows.
837 @end deffn
839 @cindex maximizing windows
840 The following function can be used to give a window the maximum possible
841 size on its frame.
843 @deffn Command maximize-window &optional window
844 This function maximizes @var{window}.  More precisely, this makes
845 @var{window} as large as possible without resizing its frame or deleting
846 other windows.  @var{window} can be any window and defaults to the
847 selected one.
848 @end deffn
850 @cindex minimizing windows
851 To make a window as small as possible without deleting it the
852 following function can be used.
854 @deffn Command minimize-window &optional window
855 This function minimizes @var{window}.  More precisely, this makes
856 @var{window} as small as possible without deleting it or resizing its
857 frame.  @var{window} can be any window and defaults to the selected one.
858 @end deffn
860 @node Splitting Windows
861 @section Splitting Windows
862 @cindex splitting windows
863 @cindex window splitting
865 The functions described below are the primitives needed for creating a
866 new window.  They do not accept a buffer as an argument.  Rather, they
867 apparently ``split'' an existing window into two halves, both displaying
868 the buffer previously visible in the window that was split.
870 @deffn Command split-window &optional window size horizontal
871 This function creates a new window adjacent to @var{window}.  It returns
872 the new window which is always a live window.  The argument @var{window}
873 can denote any window and defaults to the selected one.  This function
874 does not change the selected window.
876 Optional second argument @var{size} a positive number means make
877 @var{window} @var{size} lines (or columns) tall.  If @var{size} is
878 negative, make the new window @minus{}@var{size} lines (or columns)
879 tall.  If @var{size} is omitted or @code{nil}, then @var{window} is
880 divided evenly into two parts.  (If there is an odd line, it is
881 allocated to the new window.)
883 If splitting would result in making a window smaller than
884 @code{window-min-height} or @code{window-min-width} (@pxref{Window
885 Sizes}), this function usually signals an error.  However, if @var{size}
886 is negative and its absolute value is valid, a new window of the
887 requested size is created.  (A size value would be invalid if it
888 assigned less than one line or less than two columns to the new window.)
890 Optional third argument @var{horizontal} @code{nil} (or @code{below})
891 specifies that the new window shall be located below @var{window}.  The
892 value @code{above} means the new window will be located above
893 @var{window}.  In both cases @var{size} specifies the new number of
894 lines for @var{window} (or the new window if @var{size} is negative)
895 including space reserved for the mode and/or header line.
897 If @var{horizontal} is @code{t} or @code{right} the new window will be
898 positioned on the right side of @var{window}.  The value @code{left}
899 means the new window will be located on the left side of @var{window}.
900 In both cases @var{size} specifies the new number of columns for
901 @var{window} (or the new window provided @var{size} is negative)
902 including space reserved for margins, fringes and the scroll bar or a
903 divider column.
905 Any other non-@code{nil} value for @var{horizontal} is currently handled
906 like @code{t} (or @code{right}).  Since this might change in the future,
907 application programs should refrain from using other values.
909 If @var{window} is live, properties of the new window like margins and
910 scroll bars are inherited from @var{window}.  If @var{window} is an
911 internal window, these properties, as well as the buffer shown in the
912 new window, are inherited from the window selected on @var{window}'s
913 frame.
915 This function respects the variable @code{ignore-window-parameters}
916 (@pxref{Window Parameters}) when processing window parameters so any
917 processing of @var{window}'s parameters may be suppressed.
919 If the @code{split-window} parameter of @var{window} equals @code{t},
920 any other parameters for @var{window} are ignored and @var{window} is
921 split as described above.  If the @code{split-window} parameter of
922 @var{window} specifies a function, that function is called with the
923 @var{window}, @var{size}, and @var{horizontal} arguments to do the
924 split.  If that function is @code{ignore}, nothing is done.  It's the
925 responsibility of that function to adjust all window parameters.
927 If neither @code{ignore-window-parameters} nor the @code{split-window}
928 parameter come in the way, this function may behave specially when
929 @var{window} is a composite window or part of a composite window, see
930 @ref{Composite Windows}.  If @var{window} is a component of a compound
931 window (@pxref{Compound Windows}) this function operates on the root of
932 the compound window instead.  The new window does not become a member of
933 the compound window.  If @var{window} is a main window of a window group
934 (@pxref{Window Groups}), the new window becomes a main window in that
935 window group.  If @var{window} is a non-main component of a window group
936 this function signals an error.
937 @end deffn
939 The following example starts with one window on a screen that is 50
940 lines high by 80 columns wide; then it splits the window.
942 @smallexample
943 @group
944 (setq w1 (selected-window))
945      @result{} #<window 8 on windows.texi>
946 (setq w2 (split-window w1 15))
947      @result{} #<window 28 on windows.texi>
948 @end group
949 @group
950 (window-top-line w1)
951      @result{} 0
952 (window-total-size w1)
953      @result{} 15
954 (window-top-line w2)
955      @result{} 15
956 @end group
957 @end smallexample
959 The screen looks like this:
961 @smallexample
962 @group
963          __________
964         |          |  line 0
965         |    w1    |
966         |__________|
967         |          |  line 15
968         |    w2    |
969         |__________|
970                       line 50
971  column 0   column 80
972 @end group
973 @end smallexample
975 Next, split the top window horizontally:
977 @smallexample
978 @group
979 (setq w3 (split-window w1 35 t))
980      @result{} #<window 32 on windows.texi>
981 @end group
982 @group
983 (window-left-column w1)
984      @result{} 0
985 (window-total-size w1 t)
986      @result{} 35
987 (window-left-column w3)
988      @result{} 35
989 @end group
990 @end smallexample
992 @need 3000
993 Now the screen looks like this:
995 @smallexample
996 @group
997      column 35
998          __________
999         |    |     |  line 0
1000         | w1 |  w3 |
1001         |____|_____|
1002         |          |  line 15
1003         |    w2    |
1004         |__________|
1005                       line 50
1006  column 0   column 80
1007 @end group
1008 @end smallexample
1010 Normally, Emacs indicates the border between two side-by-side windows
1011 with a scroll bar (@pxref{Scroll Bars}), or with @samp{|} characters.  The
1012 display table can specify alternative border characters; see @ref{Display
1013 Tables}.
1015 The following option affects the behavior of a number of functions
1016 operating on a window that is part of a window combination, see
1017 @ref{Frames and Windows}.
1019 @defopt window-splits
1020 If this variable is @code{nil}, @code{split-window} creates a new parent
1021 window if and only if either @var{window} has no parent window or
1022 @var{window} shall be split in another direction than the combination
1023 @var{window} is part of.  @code{resize-window} preferably resizes
1024 @var{window}'s right sibling.  @code{delete-window} preferably returns
1025 space to @var{window}'s left sibling.
1027 If this variable equals @code{nest}, @code{split-window} always creates
1028 a new parent window.  As a consequence, any frame's window tree is a
1029 binary tree and every window has at most one (left or right) sibling.
1030 @code{resize-window} preferably resizes @var{window}'s sibling.
1031 @code{delete-window} preferably returns space to @var{window}'s sibling.
1033 If this variable equals @code{resize}, @code{split-window} tries to
1034 resize all windows belnging to the same combination as @var{window} to
1035 accomodate the new window.  Hence, the new window can be also created if
1036 @var{window} is otherwise too small to be split.  Resizing or deleting
1037 any window of a combination tries to distribute space proportionally
1038 among all other windows of the combination.
1040 Application programs should never rebind this variable to any value but
1041 @code{nest}.
1042 @end defopt
1044 @deffn Command split-window-vertically &optional size
1045 This function splits the selected window into two windows, one above the
1046 other, leaving the upper of the two windows selected, with @var{size}
1047 lines.  (If @var{size} is negative, then the lower of the two windows
1048 gets @minus{}@var{size} lines and the upper window gets the rest, but
1049 the upper window is still the one selected.)  However, if
1050 @code{split-window-keep-point} (see below) is @code{nil}, then either
1051 window can be selected.
1053 In other respects, this function is similar to @code{split-window}.
1054 In particular, the upper window is the original one and the return
1055 value is the new, lower window.
1056 @end deffn
1058 @defopt split-window-keep-point
1059 If this variable is non-@code{nil} (the default), then
1060 @code{split-window-vertically} behaves as described above.
1062 If it is @code{nil}, then @code{split-window-vertically} adjusts point
1063 in each of the two windows to avoid scrolling.  (This is useful on
1064 slow terminals.)  It selects whichever window contains the screen line
1065 that point was previously on.
1067 This variable affects the behavior of @code{split-window-vertically}
1068 only.  It has no effect on the other functions described here.
1069 @end defopt
1071 @deffn Command split-window-horizontally &optional size
1072 This function splits the selected window into two windows
1073 side-by-side, leaving the selected window on the left with @var{size}
1074 columns.  If @var{size} is negative, the rightmost window gets
1075 @minus{}@var{size} columns, but the leftmost window still remains
1076 selected.
1077 @end deffn
1079 @node Deleting Windows
1080 @section Deleting Windows
1081 @cindex deleting windows
1083 A window remains visible on its frame unless you @dfn{delete} it by
1084 calling certain functions that delete windows.  A deleted window cannot
1085 appear on the screen, but continues to exist as a Lisp object until
1086 there are no references to it.  There is no way to cancel the deletion
1087 of a window aside from restoring a saved window configuration
1088 (@pxref{Window Configurations}).  Restoring a window configuration also
1089 deletes any windows that aren't part of that configuration.
1091 @strong{Warning:} Erroneous information or fatal errors may result from
1092 using a deleted window as if it were live.
1094 @deffn Command delete-window &optional window
1095 This function removes @var{window} from display and returns @code{nil}.
1096 The argument @var{window} can denote any window and defaults to the
1097 selected one.  An error is signaled if @var{window} is the only window
1098 on its frame.  Hence @var{window} must have at least one sibling window
1099 (@pxref{Frames and Windows}) in order to get deleted.
1101 If @code{window-splits} is @code{nil}, the space @var{window} took up is
1102 given to its left sibling if such a window exists and to its right
1103 sibling otherwise.  If @code{window-splits} equals @code{nest} that
1104 space is given to the sole remaining sibling of @var{window}.  If
1105 @code{window-splits} equals @code{resize}, the space occupied by
1106 @var{window} is distributed proportionally among the other windows in
1107 the same combination as @var{window}.
1109 This function respects the variable @code{ignore-window-parameters}
1110 (@pxref{Window Parameters}) when processing window parameters.  If
1111 parameters are not ignored and the @code{delete-window} parameter of
1112 @var{window} equals @code{t}, this function deletes @var{window}
1113 ignoring any other window parameters.  If the @code{delete-window}
1114 parameter specifies a function, that function is called with
1115 @var{window} as its sole argument.  It's the responsibility of that
1116 function to adjust the parameters of all remaining windows.
1118 Otherwise, if @var{window} is part of a compound window (@pxref{Compound
1119 Windows}), this function is called with the root of the compound window
1120 as its argument.  If @var{window} is a support window or the last main
1121 window of a window group (@pxref{Window Groups}), this function signals
1122 an error.
1123 @end deffn
1125 @deffn Command delete-other-windows &optional window
1126 This function makes @var{window} fill its frame and returns @code{nil}.
1127 The argument @var{window} can denote an arbitrary window and defaults to
1128 the selected one.
1130 This function respects the variable @code{ignore-window-parameters}
1131 when processing window parameters so any processing of @var{window}'s
1132 parameters may be suppressed.
1134 If the @code{delete-other-windows} parameter of @var{window} equals
1135 @code{t}, this function deletes the remaining windows ignoring all other
1136 parameters.  If the @code{delete-other-windows} parameter specifies a
1137 function, it calls that function with @var{window} as its sole argument.
1139 Otherwise, if @var{window} is part of a compound window, it calls this
1140 function with the root of the compound window as its argument.  If
1141 @var{window} is a main window in a window group, it makes @var{window}
1142 the only main window in that group.  Any support windows of the group
1143 are left alone.  If @var{window} is a support window of a window group,
1144 this function signals an error and doesn't delete any windows.
1145 @end deffn
1147 @deffn Command delete-windows-on &optional buffer-or-name frame
1148 This function deletes all windows showing @var{buffer-or-name} and
1149 returns nil.  If there are no windows showing @var{buffer-or-name}, it
1150 does nothing.  The optional argument @var{buffer-or-name} may be a
1151 buffer or the name of an existing buffer and defaults to the current
1152 buffer.  Invoking this command on a minibuffer signals an error.
1154 @code{delete-windows-on} operates by calling @code{delete-window} for
1155 each window showing @var{buffer-or-name}.  If a frame has several
1156 windows showing different buffers, then those showing
1157 @var{buffer-or-name} are removed, and the other windows expand to fill
1158 the space.  If all windows in some frame are showing
1159 @var{buffer-or-name} (including the case where there is only one
1160 window), then the frame winds up with a single window showing another
1161 buffer chosen with @code{other-buffer}, see @ref{The Buffer List}.  If,
1162 however, that last remaining window is dedicated to the buffer specified
1163 by @var{buffer-or-name} (@pxref{Dedicated Windows}), and there are other
1164 frames left, that window's frame is deleted.
1166 The optional argument @var{frame} specifies which frames to operate on.
1167 This function does not use it in quite the same way as the other
1168 functions which scan all live windows (@pxref{Cyclic Window Ordering});
1169 specifically, the values @code{t} and @code{nil} have the opposite of
1170 their meanings in the other functions.  Here are the full details:
1172 @itemize @bullet
1173 @item @code{nil}
1174 means operate on all frames.
1175 @item @code{t}
1176 means operate on the selected frame.
1177 @item @code{visible}
1178 means operate on all visible frames.
1179 @item @code{0}
1180 means operate on all visible or iconified frames.
1181 @item A frame
1182 means operate on that frame.
1183 @end itemize
1184 @end deffn
1186 @node Selecting Windows
1187 @section Selecting Windows
1188 @cindex selecting a window
1190 @cindex selected window
1191 In each frame, at any time, one and only one window is designated as
1192 @dfn{selected within the frame}.  Also, at any time, one frame is the
1193 selected frame (@pxref{Input Focus}).  The window selected within the
1194 selected frame is the @dfn{selected window}.  The selected window's
1195 buffer is usually the current buffer (except when @code{set-buffer} has
1196 been used); see @ref{Current Buffer}.
1198 @defun selected-window
1199 This function returns the selected window.  This is the window in which
1200 the cursor for selected windows (@pxref{Cursor Parameters}) appears and
1201 to which many commands apply.
1202 @end defun
1204 @defun select-window window &optional norecord
1205 This function makes @var{window} the selected window.  Unless
1206 @var{window} already is the selected window, this also makes
1207 @var{window}'s buffer (@pxref{Buffers and Windows}) the current buffer.
1208 Moreover, the cursor for selected windows will be displayed in
1209 @var{window} after the next redisplay.  This function returns
1210 @var{window}.
1212 Normally, @var{window}'s selected buffer is moved to the front of the
1213 buffer list (@pxref{The Buffer List}) and @var{window} becomes the most
1214 recently selected window.  But if the optional argument @var{norecord}
1215 is non-@code{nil}, the buffer list remains unchanged and @var{window}
1216 does not become the most recently selected one.
1217 @end defun
1219 @cindex most recently selected windows
1220 The sequence of calls to @code{select-window} with a non-@code{nil}
1221 @var{norecord} argument determines an ordering of windows by their
1222 selection time.  The function @code{get-lru-window} can be used to
1223 retrieve the least recently selected live window in this ordering, see
1224 @ref{Cyclic Window Ordering}.
1226 @defmac save-selected-window forms@dots{}
1227 This macro records the selected frame, as well as the selected window
1228 of each frame, executes @var{forms} in sequence, then restores the
1229 earlier selected frame and windows.  It also saves and restores the
1230 current buffer.  It returns the value of the last form in @var{forms}.
1232 This macro does not save or restore anything about the sizes,
1233 arrangement or contents of windows; therefore, if @var{forms} change
1234 them, the change persists.  If the previously selected window of some
1235 frame is no longer live at the time of exit from @var{forms}, that
1236 frame's selected window is left alone.  If the previously selected
1237 window is no longer live, then whatever window is selected at the end of
1238 @var{forms} remains selected.  The current buffer is restored if and
1239 only if it is still live when exiting @var{forms}.
1241 This macro changes neither the ordering of recently selected windows nor
1242 the buffer list.
1243 @end defmac
1245 @defmac with-selected-window window forms@dots{}
1246 This macro selects @var{window}, executes @var{forms} in sequence, then
1247 restores the previously selected window and current buffer.  The ordering
1248 of recently selected windows and the buffer list remain unchanged unless
1249 you deliberately change them within @var{forms}, for example, by calling
1250 @code{select-window} with argument @var{norecord} @code{nil}.
1252 The order of recently selected windows and the buffer list are not
1253 changed by this macro.
1254 @end defmac
1256 @cindex frame selected window
1257 @cindex window selected within frame
1258 Above we explained that at any time, exactly one window on any frame is
1259 selected within the frame.  The significance of this designation is that
1260 selecting the frame also selects this window.  Conversely, selecting a
1261 window for Emacs with @code{select-window} also makes that window
1262 selected within its frame.
1264 @defun frame-selected-window  &optional frame
1265 This function returns the window on @var{frame} that is selected within
1266 @var{frame}.  The optional argument @var{frame} must denote a live frame
1267 and defaults to the selected one.
1268 @end defun
1270 @defun set-frame-selected-window frame window &optional norecord
1271 This function sets the selected window of frame @var{frame} to
1272 @var{window}.  The argument @var{frame} must denote a live frame and
1273 defaults to the selected one.  If @var{frame} is the selected frame,
1274 this also makes @var{window} the selected window.  The argument
1275 @var{window} must denote a live window.  This function returns
1276 @var{window}.
1278 Optional argument @var{norecord} non-@code{nil} means to neither change
1279 the list of most recently selected windows (@pxref{Selecting Windows})
1280 nor the buffer list (@pxref{The Buffer List}).
1281 @end defun
1283 @node Cyclic Window Ordering
1284 @section Cyclic Ordering of Windows
1285 @cindex cyclic ordering of windows
1286 @cindex ordering of windows, cyclic
1287 @cindex window ordering, cyclic
1289 When you use the command @kbd{C-x o} (@code{other-window}) to select
1290 some other window, it moves through live windows in a specific order.
1291 For any given configuration of windows, this order never varies.  It is
1292 called the @dfn{cyclic ordering of windows}.
1294    For a particular frame, this ordering is determined by the window
1295 tree of that frame, see @ref{Frames and Windows}.  More precisely, the
1296 ordering is obtained by a depth-first traversal of the frame's window
1297 tree supplemented, if requested, by the frame's minibuffer window.
1299    If there's just one live frame, the cyclic ordering is the ordering
1300 for that frame.  Otherwise, the cyclic ordering is obtained by appending
1301 the orderings for individual frames in order of the list of all live
1302 frames, @ref{Finding All Frames}.  In any case, the ordering is made
1303 ``cyclic'' by having the last window precede the first window in the
1304 ordering.
1306 @defun next-window &optional window minibuf all-frames
1307 @cindex minibuffer window, and @code{next-window}
1308 This function returns the window following @var{window} in the cyclic
1309 ordering of windows.  This is the window @kbd{C-x o} selects if typed
1310 when @var{window} is selected.  The argument @var{window} must specify a
1311 live window and defaults to the selected one.
1313 The optional argument @var{minibuf} specifies whether minibuffer windows
1314 shall be included in the cyclic ordering.  Normally, when @var{minibuf}
1315 is @code{nil}, a minibuffer window is included only if it is currently
1316 ``active''; this matches the behavior of @kbd{C-x o}.  (Note that a
1317 minibuffer window is active as long as its minibuffer is in use; see
1318 @ref{Minibuffers}).
1320 If @var{minibuf} is @code{t}, the cyclic ordering includes all
1321 minibuffer windows.  If @var{minibuf} is neither @code{t} nor
1322 @code{nil}, minibuffer windows are not included even if they are active.
1324 The optional argument @var{all-frames} specifies which frames to
1325 consider.  Here are the possible values and their meanings:
1327 @itemize @bullet
1328 @item @code{nil}
1329 means consider all windows on @var{window}'s frame, plus the minibuffer
1330 window used by that frame even if it lies in some other frame.  If the
1331 minibuffer counts (as determined by @var{minibuf}), then all windows on
1332 all frames that share that minibuffer count too.
1334 @item @code{t}
1335 means consider all windows on all existing frames.
1337 @item @code{visible}
1338 means consider all windows on all visible frames.  (To get useful
1339 results, ensure that @var{window} is on a visible frame.)
1341 @item 0
1342 means consider all windows on all visible or iconified frames.
1344 @item A frame
1345 means consider all windows on that frame.
1347 @item Anything else
1348 means consider the windows on @var{window}'s frame, and no others.
1349 @end itemize
1351 This example assumes there are two windows, both displaying the
1352 buffer @samp{windows.texi}:
1354 @example
1355 @group
1356 (selected-window)
1357      @result{} #<window 56 on windows.texi>
1358 @end group
1359 @group
1360 (next-window (selected-window))
1361      @result{} #<window 52 on windows.texi>
1362 @end group
1363 @group
1364 (next-window (next-window (selected-window)))
1365      @result{} #<window 56 on windows.texi>
1366 @end group
1367 @end example
1368 @end defun
1370 @defun previous-window &optional window minibuf all-frames
1371 This function returns the window preceding @var{window} in the cyclic
1372 ordering of windows.  The other arguments specify which windows to
1373 consider as in @code{next-window}.
1374 @end defun
1376 @deffn Command other-window count &optional all-frames
1377 This function selects another window in the cyclic ordering of windows.
1378 @var{count} specifies the number of windows to skip in the ordering,
1379 starting with the selected window, before making the selection.  If
1380 @var{count} is a positive number, it skips @var{count} windows forwards.
1381 @var{count} negative means skip @minus{}@var{count} windows backwards.
1382 If @var{count} is zero, it does not skip any window, thus re-selecting
1383 the selected window.  In an interactive call, @var{count} is the numeric
1384 prefix argument.
1386 The optional argument @var{all-frames} has the same meaning as in
1387 @code{next-window}, but the @var{minibuf} argument of @code{next-window}
1388 is always effectively @code{nil}.  This function returns @code{nil}.
1389 @end deffn
1391 The following function returns a copy of the list of windows in the
1392 cyclic odering.
1394 @defun window-list-1 &optional window &optional minibuf &optional all_frames
1395 This function returns a list of live windows.  The optional arguments
1396 @var{minibuf} and @var{all-frames} specify the set of windows to include
1397 in the list.  See the description of @code{next-window} for details.
1399 The optional argument @var{window} specifies the first window to list
1400 and defaults to the selected window.  If @var{window} is not on the list
1401 of windows returned, some other window will be listed first but no error
1402 is signalled.
1403 @end defun
1405 The functions described below use @code{window-list-1} for generating a
1406 copy of the list of all relevant windows.  Hence, any change of the
1407 window configuration that occurs while one of these functions is
1408 executed is @emph{not} reflected in the list of windows investigated.
1410 @defun walk-windows proc &optional minibuf all-frames
1411 This function cycles through live windows.  It calls the function
1412 @var{proc} once for each window, with the window as its sole argument.
1414 The optional arguments @var{minibuf} and @var{all-frames} specify the
1415 set of windows to include in the walk, see @code{next-window} above.  If
1416 @var{all-frames} specifies a frame, the first window walked is the first
1417 window on that frame as returned by @code{frame-first-window} and not
1418 necessarily the selected window.
1420 If @var{proc} changes the window configuration by splitting or deleting
1421 windows, that change is not reflected in the set of windows walked.
1422 That set is determined entirely by the set of live windows at the time
1423 this function was invoked.
1424 @end defun
1426 The following function allows to determine whether a specific window is
1427 the only live window.
1429 @defun one-window-p &optional no-mini all-frames
1430 This function returns non-@code{nil} if the selected window is the only
1431 window.
1433 The optional argument @var{no-mini}, if non-@code{nil}, means don't
1434 count the minibuffer even if it is active; otherwise, the minibuffer
1435 window is counted when it is active.  The optional argument
1436 @var{all-frames} has the same meaning as for @code{next-window}, see
1437 above.
1438 @end defun
1440 @cindex finding windows
1441   The following functions choose (but do not select) one of the windows
1442 on the screen, offering various criteria for the choice.
1444 @cindex least recently used window
1445 @defun get-lru-window &optional all-frames dedicated
1446 This function returns the window least recently ``used'' (that is,
1447 selected).  If any full-width windows are present, it only considers
1448 these.  The optional argument @var{all-frames} has the same meaning as
1449 in @code{next-window}.
1451 The selected window is returned if it is the only candidate.  A
1452 minibuffer window is never a candidate.  A dedicated window
1453 (@pxref{Dedicated Windows}) is never a candidate unless the optional
1454 argument @var{dedicated} is non-@code{nil}.
1455 @end defun
1457 @cindex largest window
1458 @defun get-largest-window &optional all-frames dedicated
1459 This function returns the window with the largest area (height times
1460 width).  If there are no side-by-side windows, then this is the window
1461 with the most lines.  A minibuffer window is never a candidate.  A
1462 dedicated window (@pxref{Dedicated Windows}) is never a candidate unless
1463 the optional argument @var{dedicated} is non-@code{nil}.
1465 If there are two candidate windows of the same size, this function
1466 prefers the one that comes first in the cyclic ordering of windows,
1467 starting from the selected window.
1469 The optional argument @var{all-frames} specifies which set of windows to
1470 consider as with @code{next-window}, see above.
1471 @end defun
1473 @cindex window that satisfies a predicate
1474 @cindex conditional selection of windows
1475 @defun get-window-with-predicate predicate &optional minibuf all-frames default
1476 This function returns a window satisfying @var{predicate}.  It cycles
1477 through all visible windows calling @var{predicate} on each one of them
1478 with that window as its argument.  The function returns the first window
1479 for which @var{predicate} returns a non-@code{nil} value; if that never
1480 happens, it returns @var{default} (which defaults to @code{nil}).
1482 The optional arguments @var{minibuf} and @var{all-frames} specify the
1483 set of windows to investigate.  See the description of
1484 @code{next-window} for details.
1485 @end defun
1487 @node Buffers and Windows
1488 @section Buffers and Windows
1489 @cindex examining windows
1490 @cindex windows, controlling precisely
1491 @cindex buffers, controlled in windows
1493 To find out which buffer is displayed in a given window the following
1494 function is used.
1496 @defun window-buffer &optional window
1497 This function returns the buffer that @var{window} is displaying.  The
1498 argument @var{window} can be any window and defaults to the selected
1499 one.  If @var{window} is an internal window, this function returns
1500 @code{nil}.
1501 @end defun
1503 Next we describe the basic, low-level function to associate a window
1504 with a buffer.  Higher-level functions like @code{display-buffer} try to
1505 obey a number of user customizations regulating which windows are
1506 supposed to display which buffers.  When writing an application,
1507 programmers should therefore carefully evaluate whether they really need
1508 the power of this function.
1510 @defun set-window-buffer window buffer-or-name &optional keep-margins
1511 This function makes @var{window} display @var{buffer-or-name} and
1512 returns @code{nil}.  The argument @var{window} has to denote a live
1513 window and defaults to the selected one.  The argument
1514 @var{buffer-or-name} must specify a buffer or the name of an existing
1515 buffer.
1517 Normally, displaying @var{buffer-or-name} in @var{window} resets the
1518 window's position, display margins, fringe widths, and scroll bar
1519 settings based on the local variables of the specified buffer.  However,
1520 if the optional argument @var{keep-margins} is non-@code{nil}, display
1521 margins and fringe widths of @var{window} remain unchanged.
1522 @xref{Fringes}.
1524 @code{set-window-buffer} is the fundamental primitive for changing which
1525 buffer is displayed in a window, and all ways of doing that call this
1526 function.  Neither the selected window nor the current buffer are
1527 changed by this function.
1529 @code{set-window-buffer} signals an error when @var{window} is
1530 @dfn{strongly} dedicated to its buffer (@pxref{Dedicated Windows}) and
1531 does not already display @var{buffer-or-name}.
1533 This function runs @code{window-scroll-functions} before running
1534 @code{window-configuration-change-hook}, see @ref{Window Hooks}.
1535 @end defun
1537 @defvar buffer-display-count
1538 This buffer-local variable records the number of times a buffer has been
1539 displayed in a window.  It is incremented each time
1540 @code{set-window-buffer} is called for the buffer.
1541 @end defvar
1543 @defvar buffer-display-time
1544 This variable records the time at which a buffer was last made visible
1545 in a window.  It is always local in each buffer; each time
1546 @code{set-window-buffer} is called, it sets this variable to
1547 @code{(current-time)} in the specified buffer (@pxref{Time of Day}).
1548 When a buffer is first created, @code{buffer-display-time} starts out
1549 with the value @code{nil}.
1550 @end defvar
1552 @defun get-buffer-window &optional buffer-or-name all-frames
1553 This function returns a window displaying @var{buffer-or-name}, or
1554 @code{nil} if there is none.  If there are several such windows, then
1555 the function returns the first one in the cyclic ordering of windows,
1556 starting from the selected window, @xref{Cyclic Window Ordering}.
1558 The argument @var{BUFFER-OR-NAME} may be a buffer or a buffer name and
1559 defaults to the current buffer.  The optional argument @var{all-frames}
1560 specifies which windows to consider:
1562 @itemize @bullet
1563 @item
1564 @code{nil} means consider windows on the selected frame.
1565 @item
1566 @code{t} means consider windows on all existing frames.
1567 @item
1568 @code{visible} means consider windows on all visible frames.
1569 @item
1570 0 means consider windows on all visible or iconified frames.
1571 @item
1572 A frame means consider windows on that frame only.
1573 @end itemize
1575 Observe that the behavior of @code{get-buffer-window} may differ from
1576 that of @code{next-window} (@pxref{Cyclic Window Ordering}) when
1577 @var{all-frames} equals @code{nil} or any value not listed here.
1578 Perhaps we will change @code{get-buffer-window} in the future to make it
1579 compatible with the other functions.
1580 @end defun
1582 @defun get-buffer-window-list &optional buffer-or-name minibuf all-frames
1583 This function returns a list of all windows currently displaying
1584 @var{buffer-or-name}.  The argument @var{buffer-or-name} may be a buffer
1585 or the name of an existing buffer and defaults to the current buffer.
1587 The two remaining arguments work like the same-named arguments of
1588 @code{next-window} (@pxref{Cyclic Window Ordering}); they are @emph{not}
1589 like the optional arguments of @code{get-buffer-window}.
1590 @end defun
1592 The following command removes a buffer from all windows showing it.
1594 @deffn Command replace-buffer-in-windows &optional buffer-or-name
1595 This function replaces @var{buffer-or-name} in all windows displaying it
1596 with some other buffer.  It uses @code{switch-to-prev-buffer}, see
1597 below, to choose that other buffer which is usually the last buffer
1598 displayed before @var{buffer-or-name} in the respective window.
1600 The argument @var{buffer-or-name} may be a buffer or the name of an
1601 existing buffer and defaults to the current buffer.
1603 If a window displaying @var{buffer-or-name} is dedicated
1604 (@pxref{Dedicated Windows}), and is not the only window on its frame,
1605 that window is deleted.  If that window is the only window on its frame
1606 and there are other frames left, the window's frame is deleted too.  If
1607 there are no other frames left, some other buffer is displayed in that
1608 window as explained above.
1610 This function returns @code{nil}.
1611 @end deffn
1613    When @code{replace-buffer-in-windows} has to show another buffer in a
1614 window, it tries to pick the buffer shown there before.  For this
1615 purpose each window remembers the buffers it has displayed earlier and
1616 the order in which these buffers have been removed from it.
1618 The list of @dfn{previous buffers} of a window is an association list
1619 where each entry specifies a buffer, the last start position of that
1620 buffer in the window (@pxref{Window Start and End}) and the last
1621 position of that buffer's point in the window (@pxref{Window Point}).
1622 This list is ordered by the times of the removal of the respective
1623 buffers from the window.  In particular, the first element of the list
1624 references the buffer removed most recently.  The function
1625 @code{set-window-buffer} pushes an entry for the old buffer of its
1626 window argument on that list before it shows its buffer argument in the
1627 window.
1629 The list of @dfn{next buffers} of a window is a list of buffers that
1630 have been recently re-shown by the function @code{switch-to-prev-buffer}
1631 and is used to avoid that that function switches to such a buffer again
1632 before showing other interesting buffers.
1634 The lists of previous and next buffers and the global buffer list
1635 (@pxref{The Buffer List}) allow to effectively display all buffers in a
1636 window while giving preference to the buffers previously shown in that
1637 window.  The commands used for this purpose are
1638 @code{switch-to-prev-buffer} and @code{switch-to-next-buffer} described
1639 below.
1641 The following functions directly operate on the lists of previous and
1642 next buffers.
1644 @defun window-prev-buffers &optional window
1645 This function returns an alist specifying the buffers previously shown
1646 in @var{window} together with their window start and point positions.
1647 The argument @var{window} must be a live window and defaults to the
1648 selected one.
1649 @end defun
1651 @defun set-window-prev-buffers window prev-buffers
1652 This function sets @var{window}'s previous buffers to the value of
1653 @var{prev-buffers}.  The argument @var{window} must be a live window and
1654 defaults to the selected one.  This function returns
1655 @var{prev-buffers}.
1657 If non-@code{nil}, @var{prev-buffers} must specify an alist of triples
1658 specifying a buffer and two markers for that buffer's start and point
1659 position in @var{window}.
1660 @end defun
1662 @defun window-next-buffers &optional window
1663 This function returns the list of buffers recently re-shown in
1664 @var{window}.  The argument @var{window} must be a live window and
1665 defaults to the selected one.
1666 @end defun
1668 @defun set-window-next-buffers window next-buffers
1669 This function sets @var{window}'s next buffers to @var{next-buffers}.
1670 @var{window} must be a live window and defaults to the selected one.
1671 This fucntion returns @var{next-buffers}.
1673 If non-@code{nil}, the argument @var{next-buffers} should specify a list
1674 of buffers that shall be preferably not shown by the command
1675 @code{switch-to-prev-buffer}, see below.
1676 @end defun
1678 The following command is used by @code{replace-buffer-in-windows},
1679 @code{bury-buffer} and @code{quit-restore-window} to show another buffer
1680 in a window.  It can be also used interactively to cycle through the
1681 list of all buffers in a window, preferably showing the buffers recently
1682 shown (but not buried or killed) in that window.
1684 @deffn Command switch-to-prev-buffer &optional window bury-or-kill
1685 This function displays the previous buffer in @var{window}.  The
1686 argument @var{window} must be a live window and defaults to the selected
1687 one.  If the optional argument @var{bury-or-kill} is non-@code{nil},
1688 this means that the buffer currently shown in @var{window} is about to
1689 be buried or killed and consequently shall not be switched to in future
1690 invocations of this command.
1692 The previous buffer is usually the buffer shown before the buffer
1693 currently shown in @var{window}.  However, a buffer that has been buried
1694 or killed or has been already shown by a recent invocation of
1695 @code{switch-to-prev-buffer} does not qualify as previous buffer.
1697 If repeated invocations of this command have already shown all buffers
1698 previously shown in @var{window}, further invocations will show buffers
1699 from the global buffer list starting with the buffer returned by
1700 @code{last-buffer} (@pxref{The Buffer List}).
1701 @end deffn
1703 The following command can be used to undo the effect of the last undone
1704 @code{switch-to-prev-buffer} command.
1706 @deffn Command switch-to-next-buffer &optional window
1707 This functions switches to the next buffer in @var{window} thus undoing
1708 the effect of the last @code{switch-to-prev-buffer} command in
1709 @var{window}.  The argument @var{window} must be a live window and
1710 defaults to the selected one.
1712 If there is no recent invocation of a @code{switch-to-prev-buffer} that
1713 can be undone, @code{switch-to-next-buffer} will try to show the first
1714 buffer from the global buffer list as returned by @code{other-buffer}
1715 (@pxref{The Buffer List}).
1716 @end deffn
1718    Together, @code{switch-to-prev-buffer} and
1719 @code{switch-to-next-buffer} permit to navigate the global buffer list
1720 much like @code{bury-buffer} and @code{unbury-buffer}.  In contrast with
1721 the latter, however, they may show a buffer even if it is already shown
1722 in another window.  Moreover, they try to restore the window specific
1723 start and point positions of buffers which should handle viewing one and
1724 the same buffer in multiple windows more easily.
1726 @node Displaying Buffers
1727 @section Choosing a Window for Displaying a Buffer
1729 The basic facility to choose a window and display a buffer in it is
1730 @code{display-buffer}.  Many higher-level functions like
1731 @code{pop-to-buffer} (@pxref{Switching Buffers}) and
1732 @code{with-output-to-temp-buffer} (@pxref{Temporary Displays}) work by
1733 calling this function.  Here we describe how @code{display-buffer}
1734 works, how to customize its behavior, and how to get rid of the chosen
1735 window once it is no more needed.
1737 @deffn Command display-buffer &optional buffer-or-name specifiers ignore
1738 This command makes the buffer specified by @var{buffer-or-name} appear
1739 in some window, but it does not necessarily select that window or make
1740 the buffer current.  It returns the window chosen to display the buffer
1741 or @code{nil} if no such window can be found.
1743    The optional argument @var{buffer-or-name} has to specify a buffer or
1744 the name of a buffer and defaults to the current buffer.  If
1745 @var{buffer-or-name} is a string that does not name an existing buffer,
1746 @code{display-buffer} creates a buffer with that name.  When called
1747 interactively, it prompts for a buffer name in the minibuffer.
1749    The optional argument @var{specifiers} is usually a list of buffer
1750 display specifiers, see below.  For convenience, @var{specifiers} may
1751 also consist of a single location specifier or @code{t}, where the
1752 latter means to display the buffer in any but the selected window.  If
1753 @var{specifiers} is @code{nil} or omitted, this means to exclusively use
1754 the values provided by the variables @code{display-buffer-names} and
1755 @code{display-buffer-regexps} described below.  If their values are nil
1756 too, default specifiers are used.
1758    The @code{not-this-window} specifier described below allows as
1759 @sc{cdr} also to specify an arbitrary window.  This means that the
1760 window specified here shall not be used for displaying the buffer.  The
1761 @code{not-this-frame} specifier described below allows as @sc{cdr} to
1762 also specify an arbitrary frame.  This means that the frame specified
1763 here shall not be used for displaying the buffer.
1765 The optional third argument @var{ignore} is ignored.                            
1766 @end deffn                                                                      
1768 Precisely how @code{display-buffer} finds or creates a window depends on
1769 the @var{specifiers} argument and the two variables described next.
1771 @defopt display-buffer-names
1772 The value of this option is a list associating buffer names with buffer
1773 display specifiers.  The @sc{car} of each element of this list is a list
1774 specifying a set of buffer names.  A buffer whose name is a member of
1775 that set is handled by @code{display-buffer} according to the list of
1776 specifiers that form the @sc{cdr} of the element.
1778 @cindex buffer display specifier
1779 @cindex location specifier
1780 A @dfn{buffer display specifier} is a symbol, a cons cell, or a list,
1781 telling @code{display-buffer} where or how to display a given buffer.  A
1782 buffer display specifier that is a symbol provides the location where
1783 the buffer shall be displayed.  Three location specifiers are
1784 predefined:
1786 @itemize @bullet
1787 @item
1788 @code{same-window} stands for the selected window,
1790 @item
1791 @code{same-frame} for a window on the selected frame,
1793 @item
1794 @code{other-frame} for a window on another frame.
1795 @end itemize
1797 Any other symbol with a function definition means to call that function
1798 to display the buffer.  The function is called with two arguments - the
1799 buffer to display and a list of specifiers - and is supposed to display
1800 the buffer and return the window used for that purpose.  That function
1801 is also responsible for giving the variable @code{display-buffer-window}
1802 a meaningful value, see below for an explanation.  Moreover, the
1803 function should set up the @code{quit-restore} window parameter which is
1804 required for proper functioning of the command
1805 @code{quit-restore-window}, see below.
1807    The remaining buffer display specifiers are cons cells or lists whose
1808 @sc{car} is one of the symbols listed next.
1810 @itemize @bullet
1811 @item
1812 @code{not-this-window} with a non-@code{nil} @sc{cdr} means that the
1813 selected window shall not be used for displaying the buffer.
1815 @item
1816 @code{reuse-buffer-window} specifies whether a window currently showing
1817 the buffer may be returned and which frame that window must be on.  The
1818 possible values for the @sc{cdr} and their meanings are:
1820 @itemize @minus
1821 @item
1822 @code{never} means to never reuse a window showing the buffer.
1824 @item
1825 @code{nil} means to stay on the selected frame.
1827 @item
1828 @code{visible} means to consider visible frames only.
1830 @item
1831 0 (the number zero) means that any such window must be on a visible or
1832 iconified frame.
1834 @item
1835 @code{t} means the window may be on an arbitrary frame, including
1836 invisible ones.
1837 @end itemize
1839    Observe that the @code{not-this-window} specifier (and the
1840 @code{not-this-frame} specifier described below) with a non-@code{nil}
1841 @sc{cdr} forbid reusing the selected window disregarding what is
1842 specified here.
1844 @item
1845 @code{reuse-other-window} specifies whether a window currently
1846 @emph{not} showing the buffer may be returned and which frame that
1847 window must be on.  The possible values for the @sc{cdr} are the same
1848 as for the @code{reuse-buffer-window} specifier.
1849 @end itemize
1851 @item
1852 @code{even-window-sizes} with a non-@code{nil} @sc{cdr} means to even
1853 the sizes of any window reused for displaying the buffer with the size
1854 of the selected window, provided these windows are adjacent to each
1855 other and the selected window is larger than the reused one.
1857 The additional specifiers listed so far are useful if the location
1858 specifier equals @code{same-frame} or @code{other-frame}.  The
1859 specifiers we describe next are mainly useful in the @code{same-frame}
1860 case.
1862 @itemize @bullet
1863 @item
1864 @code{new-window} specifies how a new window shall be made on the
1865 selected frame.  This specifier is a list whose @sc{car} is the symbol
1866 @code{new-window}.  The @sc{cdr} consists of window/side pairings, that
1867 is, cons cells whose @sc{car} identifies the window that shall be split.
1868 Currently recognized are the symbols @code{largest}, @code{lru},
1869 @code{selected}, @code{root} and @code{first} to respectively split the
1870 largest, least recently used, selected, root or first window of the
1871 selected frame.
1873   The @sc{cdr} of such a pairing specifies on which side of the window
1874 to split the new window shall appear and can be one of the symbols
1875 @code{below}, @code{right}, @code{above}, or @code{left} with the
1876 obvious meanings.  If the @sc{cdr} is @code{nil}, the window is split in
1877 a fashion suitable for the current dimensions of the window to split.
1878 If the @sc{cdr} specifies a function, that function is called with two
1879 arguments - the window to split and a list of buffer display specifiers.
1880 The function is supposed to split that window and return the new window.
1882   The pairings will be tried by @code{display-buffer} in turn until
1883 either a suitable window is found or creating a new window fails.  The
1884 default value for the option @code{display-buffer-regexps}, see below,
1885 uses
1887 @example
1888 @code{(new-window (largest . nil) (lru . nil))}
1889 @end example
1891 in order to try splitting the largest window first and, if that fails,
1892 the least recently used one.
1894 @item
1895 The symbols @code{min-height} and @code{min-width}.  In this case, the
1896 @sc{cdr} must be a number specifying the minimum height or width of a
1897 new window to display the buffer.  An integer number specifies the
1898 minimum number of lines or columns of the new window.  A floating point
1899 number gives the minimum fraction of the window's size with respect to
1900 the frame's root window.
1902 A new window will be made if and only if it can be made at least as
1903 large as specified by the number.  As a special case, if a window is the
1904 only window on its frame, it can be split vertically regardless of the
1905 value specified by the @code{min-height} specifier.  Reusing a window or
1906 making a new frame are not affected by these specifiers.
1909 @item
1910 The symbol @code{split-unsplittable-frame} with a non-@code{nil}
1911 @sc{cdr} allows to make a new window on an unsplittable frame.  This
1912 specifier should be used in special cases only since frames are usually
1913 unsplittable in order to prevent @code{display-buffer} from splitting
1914 them (@pxref{Buffer Parameters}).
1916 @item
1917 @code{adjust-height} with the following semantics for the @sc{cdr}:
1919 @itemize @minus
1920 @item
1921 @code{nil} means do not adjust the height of the new window.
1923 @item
1924 A number specifies the height of the new window.  An integer number
1925 specifies the desired number of lines of the new window.  A floating
1926 point number gives the desired fraction of the window's height with
1927 respect to the frame's root window.
1929 @item
1930 A function to call for adjusting the height of the new window.  The
1931 function is called with one argument, the new window.  Its return value
1932 is ignored.  Suitable candidates are
1933 @code{shrink-window-if-larger-than-buffer} and
1934 @code{fit-window-to-buffer}.
1935 @end itemize
1937 @item
1938 @code{adjust-width} with the following semantics for the @sc{cdr}:
1940 @itemize @minus
1941 @item
1942 @code{nil} means do not adjust the width of the new window.
1944 @item
1945 A number specifies the width of the new window.  An integer number
1946 specifies the desired number of columns of the new window.  A floating
1947 point number gives the desired fraction of the window's width with
1948 respect to the frame's root window.
1950 @item
1951 A function to call for adjusting the width of the new window.  The
1952 function is called with one argument, the new window.  Its return value
1953 is ignored.
1954 @end itemize
1956 Observe that a non-@code{nil} value for the @sc{cdr} of
1957 @code{adjust-height} or @code{adjust-width} can override restrictions
1958 given earlier by the @code{min-height} and @code{min-width} specifiers.
1959 @end itemize
1961 The following specifiers are useful when the location is specified as
1962 @code{other-frame}:
1964 @itemize @bullet
1965 @item
1966 @code{not-this-frame} with a non-@code{nil} @sc{cdr} means that the
1967 selected frame shall not be used for displaying the buffer.
1969 @item
1970 @code{graphic-only} with a non-@code{nil} @sc{cdr} means that a new
1971 frame shall be made on graphic displays only.
1973 @item
1974 @code{popup-frame-function} together with a valid function as @sc{cdr}
1975 specifies the function for creating a new frame.  By default,
1976 @code{make-frame} is called here.  The function is called with the
1977 parameters and values provided by the specifier described next.
1979 @item
1980 @code{popup-frame-alist} followed by an arbitrary number of frame
1981 parameter/value pairs, each given as a cons cell, specifies the
1982 parameters passed to the popup frame function.  For convenience, this
1983 specifier is not a cons cell but a list whose first element is the
1984 symbol @code{popup-frame-alist} and whose remaining elements are pairs
1985 of parameters and values.
1986 @end itemize
1988    It's also possible to specify whether the window chosen shall become
1989 dedicated to the buffer (@pxref{Dedicated Windows}).  This is
1990 accomplished with the help of a cons cell whose @sc{car} is the symbol
1991 @code{dedicated} and whose @sc{cdr} is one of the following values:
1993 @itemize @bullet
1994 @item
1995 @code{nil} which means to not dedicate the window to the buffer,
1997 @item
1998 @code{weak} which means the window shall be weakly dedicated to
1999 its buffer, or
2001 @item
2002 @code{t} to strongly dedicate the window to the buffer.
2003 @end itemize
2005    In general, an application is free to ignore the specifiers of
2006 @code{display-buffer-names} by explicitly passing a non-@code{nil}
2007 second argument to @code{display-buffer}.  For any
2008 @code{display-buffer-names} entry one can, however, add a cons cell
2009 whose @sc{car} is the symbol @code{override} and whose @sc{cdr} is
2010 non-@code{nil} to explicitly override the value supplied by the
2011 application.
2013    Overriding arguments supplied by the calling application is, in
2014 general, not advisable.  It permits, for example, to change the
2015 semantics of a command like @code{switch-to-buffer-other-window} by
2016 setting the method specifier to @code{same-window} or
2017 @code{other-frame}.
2018 @end defopt
2020 @defopt display-buffer-regexps
2021 The value of this option is a list associating regular expressions with
2022 buffer display specifiers.  The @sc{car} of each element of this list is
2023 a list of regular expressions.  Buffers whose names match that
2024 expression are displayed according to the list of specifiers
2025 constituting the @sc{cdr} of the element.  For a description of the
2026 @sc{cdr} see the description of @code{display-buffer-names} above.
2028 This variable has the following default value:
2030 @example
2031 (((".*")
2032   same-frame
2033   (reuse-buffer-window)
2034   (adjust-height . even-window-sizes)
2035   (largest) (lru)
2036   (min-height . 24) (min-width . 60)
2037   other-frame
2038   (reuse-buffer-window . visible)
2039   (graphic-only . t)
2040   (popup-frame-alist
2041    (height . 24) (width . 80) (unsplittable . t))))
2042 @end example
2044 It means that buffers shall be displayed preferably on the selected
2045 frame.  If the buffer is already shown on that frame,
2046 @code{display-buffer} returns the corresponding window.  Otherwise, it
2047 tries to split the largest or the least recently used window with the
2048 new window below or on the right of the window that is split.  The
2049 minimum height of the new window shall be 24 lines, its minimum width 60
2050 columns.  If a window above or below the selected window is used, the
2051 heights of both windows shall be evened out.
2053    If these specifiers fail to produce a window, @code{display-buffer}
2054 tries to show the buffer on a new frame unless a window showing the
2055 buffer can be found on some visible frame.  The default function to pop
2056 up a new frame (@code{make-frame}) is given three parameters: A height
2057 of 24 lines, a width of 80 columns, and a non-@code{nil} unsplittable
2058 property.  On text-only displays, @code{display-buffer} will not try to
2059 show the buffer on another frame.
2060 @end defopt
2062    In order to understand how @code{display-buffer} combines the values
2063 of @code{display-buffer-names} and @code{display-buffer-regexps} with
2064 the @var{specifiers} argument consider the following settings.  Suppose
2065 the value of @code{display-buffer-names} has been specified as
2067 @example
2068 ((("*text*")
2069   same-frame (reuse-buffer-window . none)
2070   (new-window (selected . below) (root . below))
2071   (override . t)))
2072 @end example
2074 the value of @code{display-buffer-regexps} is the default value, and
2075 @code{display-buffer} is called as
2077 @example
2078 (display-buffer "*text*" 'same-window)
2079 @end example
2081 Since the entry from @code{display-buffer-names} matches the buffer name
2082 and has the @code{override} specifier set, @code{display-buffer} will
2083 first try to display the buffer on the selected frame.  Reusing any
2084 window showing the buffer is forbidden, so @code{display-buffer} will
2085 try to split either the selected or the frame's root window (if the
2086 frame has only one window these are one and the same window).  The
2087 minimum height (width) of the new window is 24 lines (60 columns) and
2088 are taken from @code{display-buffer-regexps} since
2089 @code{display-buffer-names} does not supply any values for these
2090 specifiers.
2092    If neither of these windows can be split, @code{display-buffer} will
2093 try to display the buffer in the selected window as requested by the
2094 @var{specifiers} argument.  If this fails as well, for example, because
2095 the selected window is dedicated to another buffer,
2096 @code{display-buffer} will apply the default specifiers from
2097 @code{display-buffer-regexps} as sketched above.  Observe that in this
2098 case @code{display-buffer} will not necessarily try to split the
2099 selected or the frame's root window because the corresponding specifiers
2100 from @code{display-buffer-names} have been already consumed at that
2101 time.
2103    So the order of precedence is to try the overriding specifiers from
2104 @code{display-buffer-names} first, followed by overriding specifiers
2105 from @code{display-buffer-regexps}.  Next come the specifiers from the
2106 @var{specifiers} argument of @code{display-buffer}.  Finally,
2107 non-overriding specifiers from @code{display-buffer-names} and
2108 @code{display-buffer-regexps} are tried.
2110    If neither of these methods is able to produce a suitable window,
2111 @code{display-buffer} applies a number of built-in methods, overriding
2112 specifiers like @code{reuse-buffer-window} or @code{reuse-other-window},
2113 if necessary.
2115    In case you observe any unexpected behavior of @code{display-buffer}
2116 keep in mind the following issues:
2118 @itemize @bullet
2119 @item
2120 Specifiers are consumed in the order sketched above.  When
2121 @code{display-buffer} applies a location specifier, any specifiers
2122 preceding that location specifier have been consumed already, that is
2123 they do not affect the work of @code{display-buffer} any more.
2125    Specifiers following a location specifier are applied in the order
2126 given, which means that the value of the first specifier encountered
2127 prevails.  If you want to make sure that, for example, buffer windows
2128 are not reused as specified by the default value of
2129 @code{display-buffer-regexps}, use a @code{reuse-buffer-window}
2130 specifier with a @code{none} @sc{cdr} as in the display-buffer-names
2131 example above.
2133 @item
2134 Displaying a buffer on a new or other frame will always raise that frame
2135 and give it input focus.  This contrasts with earlier definitions of
2136 @code{display-buffer} up to Emacs 22.  While not raising the frame seems
2137 like a worthwhile scope in this case, it has not been pursued any longer
2138 due to possible bad interaction with window mangers on various
2139 platforms.
2141 @item
2142 The customization interface does not allow to assign every conceivable
2143 value to the options @code{display-buffer-names} and
2144 @code{display-buffer-regexps}.  You have to set these by hand to achieve
2145 more exotic behavior.
2146 @end itemize
2148    Next we describe how to transcribe the buffer display options of
2149 Emacs 23 with @code{display-buffer-names} and
2150 @code{display-buffer-regexps}.
2152 @itemize @bullet
2153 @item
2154 For @code{display-buffer-function} supply the function named there as
2155 location specifier.
2157 @item
2158 @code{same-window-buffer-names} and @code{same-window-regexps} are
2159 handled by adding a @code{same-window} specifier.
2161 @item
2162 For @code{display-buffer-reuse-frames} use the
2163 @code{reuse-buffer-window} specifier with an appropriate @sc{cdr}.
2165 @item
2166 @code{special-display-buffer-names} and @code{special-display-regexps}
2167 are replaced by @code{display-buffer-names} and
2168 @code{display-buffer-names} because, in a sense, all buffers are special
2169 now.
2171 @item
2172 @code{special-display-function} is emulated either by using a function
2173 as location specifier or by setting the @code{pop-up-frame-function}
2174 specifier appropriately.
2176 @item
2177 @code{special-display-frame-alist} is now handled by the
2178 @code{popup-frame-alist} specifier.
2180 @item
2181 To handle @code{pop-up-frames} use the @code{other-frame} location
2182 specifier and the @code{graphic-only} specifier.
2184 @item
2185 @code{pop-up-frame-function} has become the homonymous specifier.  It
2186 must now handle arguments as specified by the @code{pop-up-frame-alist}
2187 specifier, though.
2189 @item
2190 @code{pop-up-frame-alist} has become the homonymous specifier.
2192 @item
2193 @code{pop-up-windows} is handled by the @code{new-window} specifier.
2195 @item
2196 @code{split-window-preferred-function} can be specified as second
2197 argument of window / side pairings.  The semantics of the argument have
2198 not changed.
2200 @item
2201 @code{split-height-threshold} and
2202 @code{split-width-threshold} are handled by the @code{min-height} and
2203 @code{min-width} specifiers respectively.  The sizes you specify there
2204 are, however, no more the original sizes of the window to split but
2205 the desired minimum sizes of the new window.
2207 @item
2208 @code{even-window-heights} is handled by setting the @sc{cdr} of the
2209 @code{even-window-sizes} specifier to a non-@code{nil} value.
2210 @end itemize
2212 The following two functions are simple variations of
2213 @code{display-buffer}.
2215 @defun display-buffer-same-window &optional buffer-or-name
2216 This function is like @code{display-buffer} but preferably displays the
2217 buffer specified by @var{buffer-or-name} in the selected window.
2218 Another window will be used only if the buffer can't be shown in the
2219 selected window, usually because it is dedicated to some other buffer.
2220 @end defun
2222 @defun display-buffer-other-window &optional buffer-or-name
2223 This function is like @code{display-buffer} but tries to avoid using the
2224 selected window.  The selected window will be used if and only if there
2225 is no other choice.
2226 @end defun
2228 The following variable conveys some information about the last
2229 @code{display-buffer} action performed and is used mainly when popping
2230 up a @samp{*Help*} buffer.
2232 @defvar display-buffer-window
2233 After @code{display-buffer} has shown a buffer in some window this
2234 variable should be a cons cell whose @sc{car} denotes the window used to
2235 display the buffer.  The @sc{cdr} is either @code{new-window} (which
2236 means a new window has been made), @code{new-frame} (a new frame has
2237 been created), @code{reuse-buffer-window} (a window showing the buffer
2238 has been reused), @code{reuse-other-window} (some other window has been
2239 reused).
2241    If the location specifier is one of @code{same-window},
2242 @code{same-frame}, or @code{other-frame}, the @code{display-buffer} code
2243 itself sets the value of this variable.  If the location specifier is a
2244 function, that function becomes responsible for assigning a meaningful
2245 value to this variable.
2246 @end defvar
2248 The command described next allows to quit the window chosen by
2249 @code{display-buffer} and restore the previous state without undoing
2250 changes to the window configuration that happend @emph{after}
2251 @code{display-buffer} was called.  A more drastic solution is to save
2252 the window configuration before calling @code{display-buffer} and
2253 eventually restoring the saved configuration, @ref{Window
2254 Configurations}.  That solution sometimes has the undesirable
2255 side-effect that all changes that happened after the configuration was
2256 saved are undone too.
2258 @deffn Command quit-restore-window &optional window kill
2259 This command ``quits'' @var{window} restoring its previous contents if
2260 possible.  The argument @var{window} must be a live window and defaults
2261 to the selected one.  This function always returns @code{nil}.
2263 According to information stored in @var{window}'s @code{quit-restore}
2264 window parameter (@pxref{Window Parameters}) this function performs one
2265 of the following actions.
2267 @itemize @bullet
2269 @item
2270 Delete @var{window} and its frame.  This action is useful when
2271 @var{window} was created on a standalone frame and there are other
2272 frames left.
2274 @item
2275 Delete @var{window}.  This action is usually taken when @var{window} was
2276 obtained by splitting some existing window.
2278 @item
2279 Restore the buffer previously displayed in @var{window}.  This action
2280 is taken when @var{window} was temporarily reused for displaying some
2281 other buffer.
2283 @item
2284 Make @var{window} display some other buffer.  This action is usually
2285 taken when the three preceding ones are not applicable.
2286 @end itemize
2288 If the optional argument @var{kill} is non-@code{nil}, this means in
2289 addition kill @var{window}'s buffer.  If @var{kill} is @code{nil}, this
2290 simply puts @var{window}'s buffer at the end of the buffer list.
2291 Interactively, @var{kill} is the prefix argument.
2292 @end deffn
2294 @node Switching Buffers
2295 @section Switching to a Buffer in Some Window
2296 @cindex switching to a buffer
2297 @cindex popping to a buffer
2299 In this section we describe convenient functions for switching to a
2300 specified buffer in some window.  These functions can also split an
2301 existing window or create a new frame in certain circumstances.  In any
2302 case, the window chosen becomes the selected window and the buffer
2303 current.
2305    Do not use the functions in this section in order to make a buffer
2306 current so that a Lisp program can access or modify it; they are too
2307 drastic for that purpose, since they change the display of buffers in
2308 windows, which would be gratuitous and surprise the user.  Instead, use
2309 @code{set-buffer} and @code{save-current-buffer} (@pxref{Current
2310 Buffer}), which designate buffers as current for programmed access
2311 without affecting the display of buffers in windows.
2313 @deffn Command switch-to-buffer buffer-or-name &optional norecord
2314 This function makes the buffer specified by @var{buffer-or-name} current
2315 and displays it in the selected window.  This means that a human can see
2316 the buffer and subsequent keyboard commands will apply to it.  Contrast
2317 this with @code{set-buffer}, which makes @var{buffer-or-name} the
2318 current buffer but does not display it in the selected window; see
2319 @ref{Current Buffer}.
2321 If @var{buffer-or-name} is @code{nil}, @code{switch-to-buffer} chooses a
2322 buffer using @code{other-buffer}.  If @var{buffer-or-name} is a string
2323 that does not identify an existing buffer, then a new buffer by that
2324 name is created.  The major mode for the new buffer is set according to
2325 the variable @code{major-mode}; see @ref{Auto Major Mode}.
2327 If called interactively, it prompts for the buffer name using the
2328 minibuffer.  The variable @code{confirm-nonexistent-file-or-buffer}
2329 determines whether to request confirmation before creating a new buffer.
2331 When the selected window is the minibuffer window or is strongly
2332 dedicated to its buffer (@pxref{Dedicated Windows}), this function calls
2333 @code{pop-to-buffer} (see below) to display the buffer in some other
2334 window.
2336 Normally, the specified buffer is put at the front of the buffer list
2337 (both the selected frame's buffer list and the frame-independent buffer
2338 list, see @ref{The Buffer List}).  This affects the operation of
2339 @code{other-buffer}.  However, if @var{norecord} is non-@code{nil}, this
2340 is not done.  Also, if @var{norecord} is non-@code{nil}, the window
2341 chosen for displaying the buffer is not automatically made the most
2342 recently selected one.
2344 @code{switch-to-buffer} is often used interactively, as the binding of
2345 @kbd{C-x b}.  It returns the buffer that it switched to.
2346 @end deffn
2348 The next two functions are similar to @code{switch-to-buffer}, except
2349 for the described features.
2351 @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
2352 This command makes the buffer specified by @var{buffer-or-name} current
2353 and displays it in a window not currently selected, by using the
2354 function @code{pop-to-buffer} (see below).  It returns the buffer
2355 switched to.
2357 This function tries hard to avoid using the selected window for doing
2358 the job.  If the selected window already displays @var{buffer-or-name},
2359 then it continues to do so, but another window is nonetheless found to
2360 display it in as well.
2362 The arguments @var{buffer-or-name} and @var{norecord} have the same
2363 meaning as for @code{switch-to-buffer}.
2364 @end deffn
2366 @deffn Command switch-to-buffer-other-frame buffer-or-name &optional norecord
2367 This command switches to buffer @var{buffer-or-name} in another frame.
2368 It returns the buffer switched to.
2370 The arguments @var{buffer-or-name} and @var{norecord} have the same
2371 meaning as for @code{switch-to-buffer}.
2372 @end deffn
2374 @deffn Command pop-to-buffer buffer-or-name &optional specifiers norecord
2375 This command makes @var{buffer-or-name} the current buffer and switches
2376 to it in some window.  The ``popped-to'' window becomes the selected
2377 window.  Its frame is given the X server's focus, if possible; see
2378 @ref{Input Focus}.  The return value is the buffer that was switched to
2379 or @code{nil} if no suitable window could be found.
2381    The optional argument @var{buffer-or-name} may be a buffer, a string
2382 (a buffer name), or @code{nil}.  If @var{buffer-or-name} is a string not
2383 naming an existent buffer, it creates a buffer with that name.  If
2384 @var{buffer-or-name} is @code{nil} or omitted, it displays the current
2385 buffer.
2387    The optional second argument @var{specifiers} must be a list of
2388 buffer display specifiers or a single location specifier, see the
2389 documentations of @code{display-buffer} and @code{display-buffer-names}.
2390 If @var{specifiers} is @code{t}, it means to pop to the buffer in any
2391 but the selected window.  If @var{specifiers} is @code{nil} or omitted,
2392 this means to exclusively use the values provided by
2393 @code{display-buffer-names} and @code{display-buffer-regexps}
2394 (@pxref{Displaying Buffers}).  If their values are nil too, default
2395 specifiers are used.
2397    The optional argument @var{norecord} is handled just as by
2398 @code{switch-to-buffer}.
2399 @end deffn
2401 The following three commands are similar to @code{pop-to-buffer} but
2402 for the mentioned differences.
2404 @deffn Command pop-to-buffer-same-window &optional buffer-or-name norecord
2405 This command tries to display the buffer specified by
2406 @var{buffer-or-name} in the selected window.  Another window will be
2407 used only if the buffer can't be shown in the selected window, usually
2408 because it is dedicated to another buffer.
2410    The optional arguments @var{buffer-or-name} and @var{norecord} are as
2411 for @code{pop-to-buffer}.
2412 @end deffn
2414 @deffn Command pop-to-buffer-other-window &optional buffer-or-name norecord
2415 This command displays the buffer specified by @var{buffer-or-name} in
2416 any but the selected window and selects that window.  The selected
2417 window will be used if and only if there is no other choice.  Windows on
2418 the selected frame are preferred to windows on other frames.  It returns
2419 the buffer specified by @var{buffer-or-name} or @code{nil} if displaying
2420 the buffer failed.
2422    The optional arguments @var{buffer-or-name} and @var{norecord} are as
2423 for @code{pop-to-buffer}.
2424 @end deffn
2426 @deffn Command pop-to-buffer-other-frame &optional buffer-or-name norecord
2427 This command displays the buffer specified by @var{buffer-or-name}
2428 preferably on another frame.  It selects the window used for displaying
2429 the buffer and returns the buffer specified by @var{buffer-or-name} or
2430 @code{nil} if displaying the buffer failed.
2432    The optional arguments @var{buffer-or-name} and @var{norecord} are as
2433 for @code{pop-to-buffer}.
2434 @end deffn
2436 @node Dedicated Windows
2437 @section Dedicated Windows
2438 @cindex dedicated window
2440 Functions for displaying a buffer can be told to not use specific
2441 windows by marking these windows as @dfn{dedicated} to their buffers.
2442 The function @code{display-buffer} (@pxref{Displaying Buffers}) never
2443 uses a dedicated window for displaying another buffer in it.  The
2444 functions @code{get-lru-window} and @code{get-largest-window}
2445 (@pxref{Selecting Windows}) do not consider dedicated windows as
2446 candidates when their @var{dedicated} argument is non-@code{nil}.  The
2447 behavior of @code{set-window-buffer} (@pxref{Buffers and Windows}) with
2448 respect to dedicated windows is slightly different, see below.
2450 When @code{delete-windows-on} (@pxref{Deleting Windows}) wants to delete
2451 a dedicated window and that window is the only window on its frame, it
2452 deletes the window's frame too, provided there are other frames left.
2453 The function @code{replace-buffer-in-windows} (@pxref{Displaying
2454 Buffers}) tries to delete all dedicated windows showing its buffer
2455 argument.  When such a window is the only window on its frame, that
2456 frame is deleted, provided there are other frames left.  If there are no
2457 more frames left, some other buffer is displayed in the window, and the
2458 window is marked as non-dedicated.
2460 When you kill a buffer (@pxref{Killing Buffers}) displayed in a
2461 dedicated window, any such window usually gets deleted too, since
2462 @code{kill-buffer} calls @code{replace-buffer-in-windows} for cleaning
2463 up windows.  Burying a buffer (@pxref{The Buffer List}) deletes the
2464 selected window if it is dedicated to that buffer.  If, however, that
2465 window is the only window on its frame, @code{bury-buffer} displays
2466 another buffer in it and iconifies the frame.
2468 @defun window-dedicated-p &optional window
2469 This function returns non-@code{nil} if @var{window} is dedicated to its
2470 buffer and @code{nil} otherwise.  More precisely, the return value is
2471 the value assigned by the last call of @code{set-window-dedicated-p} for
2472 @var{window} or @code{nil} if that function was never called with
2473 @var{window} as its argument.  The default for @var{window} is the
2474 selected window.
2475 @end defun
2477 @defun set-window-dedicated-p window flag
2478 This function marks @var{window} as dedicated to its buffer if
2479 @var{flag} is non-@code{nil}, and non-dedicated otherwise.
2481 As a special case, if @var{flag} is @code{t}, @var{window} becomes
2482 @dfn{strongly} dedicated to its buffer.  @code{set-window-buffer}
2483 signals an error when the window it acts upon is strongly dedicated to
2484 its buffer and does not already display the buffer it is asked to
2485 display.  Other functions do not treat @code{t} differently from any
2486 non-@code{nil} value.
2487 @end defun
2489 @node Window Point
2490 @section Windows and Point
2491 @cindex window position
2492 @cindex window point
2493 @cindex position in window
2494 @cindex point in window
2496 Each window has its own value of point (@pxref{Point}), independent of
2497 the value of point in other windows displaying the same buffer.  This
2498 makes it useful to have multiple windows showing one buffer.
2500 @itemize @bullet
2501 @item
2502 The window point is established when a window is first created; it is
2503 initialized from the buffer's point, or from the window point of another
2504 window opened on the buffer if such a window exists.
2506 @item
2507 Selecting a window sets the value of point in its buffer from the
2508 window's value of point.  Conversely, deselecting a window sets the
2509 window's value of point from that of the buffer.  Thus, when you switch
2510 between windows that display a given buffer, the point value for the
2511 selected window is in effect in the buffer, while the point values for
2512 the other windows are stored in those windows.
2514 @item
2515 As long as the selected window displays the current buffer, the window's
2516 point and the buffer's point always move together; they remain equal.
2517 @end itemize
2519 @cindex cursor
2520    As far as the user is concerned, point is where the cursor is, and
2521 when the user switches to another buffer, the cursor jumps to the
2522 position of point in that buffer.
2524 @defun window-point &optional window
2525 This function returns the current position of point in @var{window}.
2526 For a nonselected window, this is the value point would have (in that
2527 window's buffer) if that window were selected.  The default for
2528 @var{window} is the selected window.
2530 When @var{window} is the selected window and its buffer is also the
2531 current buffer, the value returned is the same as point in that buffer.
2532 Strictly speaking, it would be more correct to return the ``top-level''
2533 value of point, outside of any @code{save-excursion} forms.  But that
2534 value is hard to find.
2535 @end defun
2537 @defun set-window-point window position
2538 This function positions point in @var{window} at position
2539 @var{position} in @var{window}'s buffer.  It returns @var{position}.
2541 If @var{window} is selected, and its buffer is current,
2542 this simply does @code{goto-char}.
2543 @end defun
2545 @defvar window-point-insertion-type
2546 This variable specifies the marker insertion type (@pxref{Marker
2547 Insertion Types}) of @code{window-point}.  The default is @code{nil},
2548 so @code{window-point} will stay behind text inserted there.
2549 @end defvar
2551 @node Window Start and End
2552 @section The Window Start and End Positions
2553 @cindex window start position
2555   Each window maintains a marker used to keep track of a buffer position
2556 that specifies where in the buffer display should start.  This position
2557 is called the @dfn{display-start} position of the window (or just the
2558 @dfn{start}).  The character after this position is the one that appears
2559 at the upper left corner of the window.  It is usually, but not
2560 inevitably, at the beginning of a text line.
2562   After switching windows or buffers, and in some other cases, if the
2563 window start is in the middle of a line, Emacs adjusts the window
2564 start to the start of a line.  This prevents certain operations from
2565 leaving the window start at a meaningless point within a line.  This
2566 feature may interfere with testing some Lisp code by executing it
2567 using the commands of Lisp mode, because they trigger this
2568 readjustment.  To test such code, put it into a command and bind the
2569 command to a key.
2571 @defun window-start &optional window
2572 @cindex window top line
2573 This function returns the display-start position of window
2574 @var{window}.  If @var{window} is @code{nil}, the selected window is
2575 used.  For example,
2577 @example
2578 @group
2579 (window-start)
2580      @result{} 7058
2581 @end group
2582 @end example
2584 When you create a window, or display a different buffer in it, the
2585 display-start position is set to a display-start position recently used
2586 for the same buffer, or to @code{point-min} if the buffer doesn't have
2587 any.
2589 Redisplay updates the window-start position (if you have not specified
2590 it explicitly since the previous redisplay)---to make sure point appears
2591 on the screen.  Nothing except redisplay automatically changes the
2592 window-start position; if you move point, do not expect the window-start
2593 position to change in response until after the next redisplay.
2595 For a realistic example of using @code{window-start}, see the
2596 description of @code{count-lines}.  @xref{Definition of count-lines}.
2597 @end defun
2599 @cindex window end position
2600 @defun window-end &optional window update
2601 This function returns the position where display of its buffer ends in
2602 @var{window}.  The default for @var{window} is the selected window.
2604 Simply changing the buffer text or moving point does not update the
2605 value that @code{window-end} returns.  The value is updated only when
2606 Emacs redisplays and redisplay completes without being preempted.
2608 If the last redisplay of @var{window} was preempted, and did not finish,
2609 Emacs does not know the position of the end of display in that window.
2610 In that case, this function returns @code{nil}.
2612 If @var{update} is non-@code{nil}, @code{window-end} always returns an
2613 up-to-date value for where display ends, based on the current
2614 @code{window-start} value.  If a previously saved value of that position
2615 is still valid, @code{window-end} returns that value; otherwise it
2616 computes the correct value by scanning the buffer text.
2618 Even if @var{update} is non-@code{nil}, @code{window-end} does not
2619 attempt to scroll the display if point has moved off the screen, the
2620 way real redisplay would do.  It does not alter the
2621 @code{window-start} value.  In effect, it reports where the displayed
2622 text will end if scrolling is not required.
2623 @end defun
2625 @defun set-window-start window position &optional noforce
2626 This function sets the display-start position of @var{window} to
2627 @var{position} in @var{window}'s buffer.  It returns @var{position}.
2629 The display routines insist that the position of point be visible when a
2630 buffer is displayed.  Normally, they change the display-start position
2631 (that is, scroll the window) whenever necessary to make point visible.
2632 However, if you specify the start position with this function using
2633 @code{nil} for @var{noforce}, it means you want display to start at
2634 @var{position} even if that would put the location of point off the
2635 screen.  If this does place point off screen, the display routines move
2636 point to the left margin on the middle line in the window.
2638 For example, if point @w{is 1} and you set the start of the window
2639 @w{to 37}, the start of the next line, point will be ``above'' the top
2640 of the window.  The display routines will automatically move point if
2641 it is still 1 when redisplay occurs.  Here is an example:
2643 @example
2644 @group
2645 ;; @r{Here is what @samp{foo} looks like before executing}
2646 ;;   @r{the @code{set-window-start} expression.}
2647 @end group
2649 @group
2650 ---------- Buffer: foo ----------
2651 @point{}This is the contents of buffer foo.
2657 ---------- Buffer: foo ----------
2658 @end group
2660 @group
2661 (set-window-start
2662  (selected-window)
2663  (save-excursion
2664    (goto-char 1)
2665    (forward-line 1)
2666    (point)))
2667 @result{} 37
2668 @end group
2670 @group
2671 ;; @r{Here is what @samp{foo} looks like after executing}
2672 ;;   @r{the @code{set-window-start} expression.}
2673 ---------- Buffer: foo ----------
2676 @point{}4
2679 ---------- Buffer: foo ----------
2680 @end group
2681 @end example
2683 If @var{noforce} is non-@code{nil}, and @var{position} would place point
2684 off screen at the next redisplay, then redisplay computes a new window-start
2685 position that works well with point, and thus @var{position} is not used.
2686 @end defun
2688 @defun pos-visible-in-window-p &optional position window partially
2689 This function returns non-@code{nil} if @var{position} is within the
2690 range of text currently visible on the screen in @var{window}.  It
2691 returns @code{nil} if @var{position} is scrolled vertically out of view.
2692 Locations that are partially obscured are not considered visible unless
2693 @var{partially} is non-@code{nil}.  The argument @var{position} defaults
2694 to the current position of point in @var{window}; @var{window}, to the
2695 selected window.  If @var{position} is @code{t}, that means to check the
2696 last visible position in @var{window}.
2698 The @code{pos-visible-in-window-p} function considers only vertical
2699 scrolling.  If @var{position} is out of view only because @var{window}
2700 has been scrolled horizontally, @code{pos-visible-in-window-p} returns
2701 non-@code{nil} anyway.  @xref{Horizontal Scrolling}.
2703 If @var{position} is visible, @code{pos-visible-in-window-p} returns
2704 @code{t} if @var{partially} is @code{nil}; if @var{partially} is
2705 non-@code{nil}, and the character following @var{position} is fully
2706 visible, it returns a list of the form @code{(@var{x} @var{y})}, where
2707 @var{x} and @var{y} are the pixel coordinates relative to the top left
2708 corner of the window; otherwise it returns an extended list of the form
2709 @code{(@var{x} @var{y} @var{rtop} @var{rbot} @var{rowh} @var{vpos})},
2710 where @var{rtop} and @var{rbot} specify the number of off-window pixels
2711 at the top and bottom of the row at @var{position}, @var{rowh} specifies
2712 the visible height of that row, and @var{vpos} specifies the vertical
2713 position (zero-based row number) of that row.
2715 Here is an example:
2717 @example
2718 @group
2719 ;; @r{If point is off the screen now, recenter it now.}
2720 (or (pos-visible-in-window-p
2721      (point) (selected-window))
2722     (recenter 0))
2723 @end group
2724 @end example
2725 @end defun
2727 @defun window-line-height &optional line window
2728 This function returns the height of text line @var{line} in
2729 @var{window}.  If @var{line} is one of @code{header-line} or
2730 @code{mode-line}, @code{window-line-height} returns information about
2731 the corresponding line of the window.  Otherwise, @var{line} is a text
2732 line number starting from 0.  A negative number counts from the end of
2733 the window.  The default for @var{line} is the current line in
2734 @var{window}; the default for @var{window} is the selected window.
2736 If the display is not up to date, @code{window-line-height} returns
2737 @code{nil}.  In that case, @code{pos-visible-in-window-p} may be used
2738 to obtain related information.
2740 If there is no line corresponding to the specified @var{line},
2741 @code{window-line-height} returns @code{nil}.  Otherwise, it returns
2742 a list @code{(@var{height} @var{vpos} @var{ypos} @var{offbot})},
2743 where @var{height} is the height in pixels of the visible part of the
2744 line, @var{vpos} and @var{ypos} are the vertical position in lines and
2745 pixels of the line relative to the top of the first text line, and
2746 @var{offbot} is the number of off-window pixels at the bottom of the
2747 text line.  If there are off-window pixels at the top of the (first)
2748 text line, @var{ypos} is negative.
2749 @end defun
2751 @node Textual Scrolling
2752 @section Textual Scrolling
2753 @cindex textual scrolling
2754 @cindex scrolling textually
2756   @dfn{Textual scrolling} means moving the text up or down through a
2757 window.  It works by changing the value of the window's display-start
2758 location.  It may also change the value of @code{window-point} to keep
2759 point on the screen.
2761   Textual scrolling was formerly called ``vertical scrolling,'' but we
2762 changed its name to distinguish it from the new vertical fractional
2763 scrolling feature (@pxref{Vertical Scrolling}).
2765   In the commands @code{scroll-up} and @code{scroll-down}, the directions
2766 ``up'' and ``down'' refer to the motion of the text in the buffer at which
2767 you are looking through the window.  Imagine that the text is
2768 written on a long roll of paper and that the scrolling commands move the
2769 paper up and down.  Thus, if you are looking at text in the middle of a
2770 buffer and repeatedly call @code{scroll-down}, you will eventually see
2771 the beginning of the buffer.
2773   Some people have urged that the opposite convention be used: they
2774 imagine that the window moves over text that remains in place.  Then
2775 ``down'' commands would take you to the end of the buffer.  This view is
2776 more consistent with the actual relationship between windows and the
2777 text in the buffer, but it is less like what the user sees.  The
2778 position of a window on the terminal does not move, and short scrolling
2779 commands clearly move the text up or down on the screen.  We have chosen
2780 names that fit the user's point of view.
2782   The textual scrolling functions (aside from
2783 @code{scroll-other-window}) have unpredictable results if the current
2784 buffer is different from the buffer that is displayed in the selected
2785 window.  @xref{Current Buffer}.
2787   If the window contains a row which is taller than the height of the
2788 window (for example in the presence of a large image), the scroll
2789 functions will adjust the window's vertical scroll position to scroll
2790 the partially visible row.  To disable this feature, Lisp code may bind
2791 the variable @code{auto-window-vscroll} to @code{nil} (@pxref{Vertical
2792 Scrolling}).
2794 @deffn Command scroll-up &optional count
2795 This function scrolls the text in the selected window upward
2796 @var{count} lines.  If @var{count} is negative, scrolling is actually
2797 downward.
2799 If @var{count} is @code{nil} (or omitted), then the length of scroll
2800 is @code{next-screen-context-lines} lines less than the usable height of
2801 the window (not counting its mode line).
2803 @code{scroll-up} returns @code{nil}, unless it gets an error
2804 because it can't scroll any further.
2805 @end deffn
2807 @deffn Command scroll-down &optional count
2808 This function scrolls the text in the selected window downward
2809 @var{count} lines.  If @var{count} is negative, scrolling is actually
2810 upward.
2812 If @var{count} is omitted or @code{nil}, then the length of the scroll
2813 is @code{next-screen-context-lines} lines less than the usable height of
2814 the window (not counting its mode line).
2816 @code{scroll-down} returns @code{nil}, unless it gets an error because
2817 it can't scroll any further.
2818 @end deffn
2820 @deffn Command scroll-other-window &optional count
2821 This function scrolls the text in another window upward @var{count}
2822 lines.  Negative values of @var{count}, or @code{nil}, are handled
2823 as in @code{scroll-up}.
2825 You can specify which buffer to scroll by setting the variable
2826 @code{other-window-scroll-buffer} to a buffer.  If that buffer isn't
2827 already displayed, @code{scroll-other-window} displays it in some
2828 window.
2830 When the selected window is the minibuffer, the next window is normally
2831 the one at the top left corner.  You can specify a different window to
2832 scroll, when the minibuffer is selected, by setting the variable
2833 @code{minibuffer-scroll-window}.  This variable has no effect when any
2834 other window is selected.  When it is non-@code{nil} and the
2835 minibuffer is selected, it takes precedence over
2836 @code{other-window-scroll-buffer}.  @xref{Definition of
2837 minibuffer-scroll-window}.
2839 When the minibuffer is active, it is the next window if the selected
2840 window is the one at the bottom right corner.  In this case,
2841 @code{scroll-other-window} attempts to scroll the minibuffer.  If the
2842 minibuffer contains just one line, it has nowhere to scroll to, so the
2843 line reappears after the echo area momentarily displays the message
2844 @samp{Beginning of buffer}.
2845 @end deffn
2847 @c Emacs 19 feature
2848 @defvar other-window-scroll-buffer
2849 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
2850 which buffer's window to scroll.
2851 @end defvar
2853 @defopt scroll-margin
2854 This option specifies the size of the scroll margin---a minimum number
2855 of lines between point and the top or bottom of a window.  Whenever
2856 point gets within this many lines of the top or bottom of the window,
2857 redisplay scrolls the text automatically (if possible) to move point
2858 out of the margin, closer to the center of the window.
2859 @end defopt
2861 @defopt scroll-conservatively
2862 This variable controls how scrolling is done automatically when point
2863 moves off the screen (or into the scroll margin).  If the value is a
2864 positive integer @var{n}, then redisplay scrolls the text up to
2865 @var{n} lines in either direction, if that will bring point back into
2866 proper view.  This behavior is called @dfn{conservative scrolling}.
2867 Otherwise, scrolling happens in the usual way, under the control of
2868 other variables such as @code{scroll-up-aggressively} and
2869 @code{scroll-down-aggressively}.
2871 The default value is zero, which means that conservative scrolling
2872 never happens.
2873 @end defopt
2875 @defopt scroll-down-aggressively
2876 The value of this variable should be either @code{nil} or a fraction
2877 @var{f} between 0 and 1.  If it is a fraction, that specifies where on
2878 the screen to put point when scrolling down.  More precisely, when a
2879 window scrolls down because point is above the window start, the new
2880 start position is chosen to put point @var{f} part of the window
2881 height from the top.  The larger @var{f}, the more aggressive the
2882 scrolling.
2884 A value of @code{nil} is equivalent to .5, since its effect is to center
2885 point.  This variable automatically becomes buffer-local when set in any
2886 fashion.
2887 @end defopt
2889 @defopt scroll-up-aggressively
2890 Likewise, for scrolling up.  The value, @var{f}, specifies how far
2891 point should be placed from the bottom of the window; thus, as with
2892 @code{scroll-up-aggressively}, a larger value scrolls more aggressively.
2893 @end defopt
2895 @defopt scroll-step
2896 This variable is an older variant of @code{scroll-conservatively}.  The
2897 difference is that it if its value is @var{n}, that permits scrolling
2898 only by precisely @var{n} lines, not a smaller number.  This feature
2899 does not work with @code{scroll-margin}.  The default value is zero.
2900 @end defopt
2902 @defopt scroll-preserve-screen-position
2903 If this option is @code{t}, scrolling which would move the current
2904 point position out of the window chooses the new position of point
2905 so that the vertical position of the cursor is unchanged, if possible.
2907 If it is non-@code{nil} and not @code{t}, then the scrolling functions
2908 always preserve the vertical position of point, if possible.
2909 @end defopt
2911 @defopt next-screen-context-lines
2912 The value of this variable is the number of lines of continuity to
2913 retain when scrolling by full screens.  For example, @code{scroll-up}
2914 with an argument of @code{nil} scrolls so that this many lines at the
2915 bottom of the window appear instead at the top.  The default value is
2916 @code{2}.
2917 @end defopt
2919 @deffn Command recenter &optional count
2920 @cindex centering point
2921 This function scrolls the text in the selected window so that point is
2922 displayed at a specified vertical position within the window.  It does
2923 not ``move point'' with respect to the text.
2925 If @var{count} is a nonnegative number, that puts the line containing
2926 point @var{count} lines down from the top of the window.  If
2927 @var{count} is a negative number, then it counts upward from the
2928 bottom of the window, so that @minus{}1 stands for the last usable
2929 line in the window.  If @var{count} is a non-@code{nil} list, then it
2930 stands for the line in the middle of the window.
2932 If @var{count} is @code{nil}, @code{recenter} puts the line containing
2933 point in the middle of the window, then clears and redisplays the entire
2934 selected frame.
2936 When @code{recenter} is called interactively, @var{count} is the raw
2937 prefix argument.  Thus, typing @kbd{C-u} as the prefix sets the
2938 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
2939 @var{count} to 4, which positions the current line four lines from the
2940 top.
2942 With an argument of zero, @code{recenter} positions the current line at
2943 the top of the window.  This action is so handy that some people make a
2944 separate key binding to do this.  For example,
2946 @example
2947 @group
2948 (defun line-to-top-of-window ()
2949   "Scroll current line to top of window.
2950 Replaces three keystroke sequence C-u 0 C-l."
2951   (interactive)
2952   (recenter 0))
2954 (global-set-key [kp-multiply] 'line-to-top-of-window)
2955 @end group
2956 @end example
2957 @end deffn
2959 @node Vertical Scrolling
2960 @section Vertical Fractional Scrolling
2961 @cindex vertical fractional scrolling
2962 @cindex vertical scroll position
2964    @dfn{Vertical fractional scrolling} means shifting text in a window
2965 up or down by a specified multiple or fraction of a line.  Each window
2966 has a @dfn{vertical scroll position}, which is a number, never less than
2967 zero.  It specifies how far to raise the contents of the window.
2968 Raising the window contents generally makes all or part of some lines
2969 disappear off the top, and all or part of some other lines appear at the
2970 bottom.  The usual value is zero.
2972    The vertical scroll position is measured in units of the normal line
2973 height, which is the height of the default font.  Thus, if the value is
2974 .5, that means the window contents are scrolled up half the normal line
2975 height.  If it is 3.3, that means the window contents are scrolled up
2976 somewhat over three times the normal line height.
2978    What fraction of a line the vertical scrolling covers, or how many
2979 lines, depends on what the lines contain.  A value of .5 could scroll a
2980 line whose height is very short off the screen, while a value of 3.3
2981 could scroll just part of the way through a tall line or an image.
2983 @defun window-vscroll &optional window pixels-p
2984 This function returns the current vertical scroll position of
2985 @var{window}.  The default for @var{window} is the selected window.
2986 If @var{pixels-p} is non-@code{nil}, the return value is measured in
2987 pixels, rather than in units of the normal line height.
2989 @example
2990 @group
2991 (window-vscroll)
2992      @result{} 0
2993 @end group
2994 @end example
2995 @end defun
2997 @defun set-window-vscroll window lines &optional pixels-p
2998 This function sets @var{window}'s vertical scroll position to
2999 @var{lines}.  If @var{window} is @code{nil}, the selected window is
3000 used.  The argument @var{lines} should be zero or positive; if not, it
3001 is taken as zero.
3004 The actual vertical scroll position must always correspond
3005 to an integral number of pixels, so the value you specify
3006 is rounded accordingly.
3008 The return value is the result of this rounding.
3010 @example
3011 @group
3012 (set-window-vscroll (selected-window) 1.2)
3013      @result{} 1.13
3014 @end group
3015 @end example
3017 If @var{pixels-p} is non-@code{nil}, @var{lines} specifies a number of
3018 pixels.  In this case, the return value is @var{lines}.
3019 @end defun
3021 @defvar auto-window-vscroll
3022 If this variable is non-@code{nil}, the line-move, scroll-up, and
3023 scroll-down functions will automatically modify the vertical scroll
3024 position to scroll through display rows that are taller than the height
3025 of the window, for example in the presence of large images.
3026 @end defvar
3028 @node Horizontal Scrolling
3029 @section Horizontal Scrolling
3030 @cindex horizontal scrolling
3032   @dfn{Horizontal scrolling} means shifting the image in the window left
3033 or right by a specified multiple of the normal character width.  Each
3034 window has a @dfn{horizontal scroll position}, which is a number, never
3035 less than zero.  It specifies how far to shift the contents left.
3036 Shifting the window contents left generally makes all or part of some
3037 characters disappear off the left, and all or part of some other
3038 characters appear at the right.  The usual value is zero.
3040   The horizontal scroll position is measured in units of the normal
3041 character width, which is the width of space in the default font.  Thus,
3042 if the value is 5, that means the window contents are scrolled left by 5
3043 times the normal character width.  How many characters actually
3044 disappear off to the left depends on their width, and could vary from
3045 line to line.
3047   Because we read from side to side in the ``inner loop,'' and from top
3048 to bottom in the ``outer loop,'' the effect of horizontal scrolling is
3049 not like that of textual or vertical scrolling.  Textual scrolling
3050 involves selection of a portion of text to display, and vertical
3051 scrolling moves the window contents contiguously; but horizontal
3052 scrolling causes part of @emph{each line} to go off screen.
3054   Usually, no horizontal scrolling is in effect; then the leftmost
3055 column is at the left edge of the window.  In this state, scrolling to
3056 the right is meaningless, since there is no data to the left of the edge
3057 to be revealed by it; so this is not allowed.  Scrolling to the left is
3058 allowed; it scrolls the first columns of text off the edge of the window
3059 and can reveal additional columns on the right that were truncated
3060 before.  Once a window has a nonzero amount of leftward horizontal
3061 scrolling, you can scroll it back to the right, but only so far as to
3062 reduce the net horizontal scroll to zero.  There is no limit to how far
3063 left you can scroll, but eventually all the text will disappear off the
3064 left edge.
3066 @vindex auto-hscroll-mode
3067   If @code{auto-hscroll-mode} is set, redisplay automatically alters
3068 the horizontal scrolling of a window as necessary to ensure that point
3069 is always visible.  However, you can still set the horizontal
3070 scrolling value explicitly.  The value you specify serves as a lower
3071 bound for automatic scrolling, i.e. automatic scrolling will not
3072 scroll a window to a column less than the specified one.
3074 @deffn Command scroll-left &optional count set-minimum
3075 This function scrolls the selected window @var{count} columns to the
3076 left (or to the right if @var{count} is negative).  The default
3077 for @var{count} is the window width, minus 2.
3079 The return value is the total amount of leftward horizontal scrolling in
3080 effect after the change---just like the value returned by
3081 @code{window-hscroll} (below).
3083 Once you scroll a window as far right as it can go, back to its normal
3084 position where the total leftward scrolling is zero, attempts to scroll
3085 any farther right have no effect.
3087 If @var{set-minimum} is non-@code{nil}, the new scroll amount becomes
3088 the lower bound for automatic scrolling; that is, automatic scrolling
3089 will not scroll a window to a column less than the value returned by
3090 this function.  Interactive calls pass non-@code{nil} for
3091 @var{set-minimum}.
3092 @end deffn
3094 @deffn Command scroll-right &optional count set-minimum
3095 This function scrolls the selected window @var{count} columns to the
3096 right (or to the left if @var{count} is negative).  The default
3097 for @var{count} is the window width, minus 2.  Aside from the direction
3098 of scrolling, this works just like @code{scroll-left}.
3099 @end deffn
3101 @defun window-hscroll &optional window
3102 This function returns the total leftward horizontal scrolling of
3103 @var{window}---the number of columns by which the text in @var{window}
3104 is scrolled left past the left margin.  The default for
3105 @var{window} is the selected window.
3107 The return value is never negative.  It is zero when no horizontal
3108 scrolling has been done in @var{window} (which is usually the case).
3111 @example
3112 @group
3113 (window-hscroll)
3114      @result{} 0
3115 @end group
3116 @group
3117 (scroll-left 5)
3118      @result{} 5
3119 @end group
3120 @group
3121 (window-hscroll)
3122      @result{} 5
3123 @end group
3124 @end example
3125 @end defun
3127 @defun set-window-hscroll window columns
3128 This function sets horizontal scrolling of @var{window}.  The value of
3129 @var{columns} specifies the amount of scrolling, in terms of columns
3130 from the left margin.  The argument @var{columns} should be zero or
3131 positive; if not, it is taken as zero.  Fractional values of
3132 @var{columns} are not supported at present.
3134 Note that @code{set-window-hscroll} may appear not to work if you test
3135 it by evaluating a call with @kbd{M-:} in a simple way.  What happens
3136 is that the function sets the horizontal scroll value and returns, but
3137 then redisplay adjusts the horizontal scrolling to make point visible,
3138 and this overrides what the function did.  You can observe the
3139 function's effect if you call it while point is sufficiently far from
3140 the left margin that it will remain visible.
3142 The value returned is @var{columns}.
3144 @example
3145 @group
3146 (set-window-hscroll (selected-window) 10)
3147      @result{} 10
3148 @end group
3149 @end example
3150 @end defun
3152    Here is how you can determine whether a given position @var{position}
3153 is off the screen due to horizontal scrolling:
3155 @example
3156 @group
3157 (defun hscroll-on-screen (window position)
3158   (save-excursion
3159     (goto-char position)
3160     (and
3161      (>= (- (current-column) (window-hscroll window)) 0)
3162      (< (- (current-column) (window-hscroll window))
3163         (window-width window)))))
3164 @end group
3165 @end example
3167 @node Coordinates and Windows
3168 @section Coordinates and Windows
3170 This section describes how to relate edges and screen coordinates to
3171 windows.
3173 @defun window-edges &optional window
3174 This function returns a list of the edge coordinates of @var{window}.
3175 The default for @var{window} is the selected window.
3177 The order of the list is @code{(@var{left} @var{top} @var{right}
3178 @var{bottom})}, all elements relative to 0, 0 at the top left corner of
3179 the frame.  The element @var{right} of the value is one more than the
3180 rightmost column used by @var{window}, and @var{bottom} is one more than
3181 the bottommost row used by @var{window} and its mode-line.
3183 The edges include the space used by the window's scroll bar, display
3184 margins, fringes, header line, and mode line, if it has them.  Also,
3185 if the window has a neighbor on the right, its right edge value
3186 includes the width of the separator line between the window and that
3187 neighbor.  Since the width of the window does not include this
3188 separator, the width does not usually equal the difference between the
3189 right and left edges.
3190 @end defun
3192 @defun window-inside-edges &optional window
3193 This is similar to @code{window-edges}, but the edge values
3194 it returns include only the text area of the window.  They
3195 do not include the header line, mode line, scroll bar or
3196 vertical separator, fringes, or display margins.
3197 @end defun
3199 Here are the results obtained on a typical 24-line terminal with just
3200 one window, with menu bar enabled:
3202 @example
3203 @group
3204 (window-edges (selected-window))
3205      @result{} (0 1 80 23)
3206 @end group
3207 @group
3208 (window-inside-edges (selected-window))
3209      @result{} (0 1 80 22)
3210 @end group
3211 @end example
3213 @noindent
3214 The bottom edge is at line 23 because the last line is the echo area.
3215 The bottom inside edge is at line 22, which is the window's mode line.
3217 If @var{window} is at the upper left corner of its frame, and there is
3218 no menu bar, then @var{bottom} returned by @code{window-edges} is the
3219 same as the value of @code{(window-total-height)}, @var{right} is the
3220 same as the value of @code{(window-total-width)}, and @var{top} and
3221 @var{left} are zero.  For example, the edges of the following window are
3222 @w{@samp{0 0 8 5}}.  Assuming that the frame has more than 8 columns,
3223 the last column of the window (column 7) holds a border rather than
3224 text.  The last row (row 4) holds the mode line, shown here with
3225 @samp{xxxxxxxxx}.
3227 @example
3228 @group
3229            0
3230            _______
3231         0 |       |
3232           |       |
3233           |       |
3234           |       |
3235           xxxxxxxxx  4
3237                   7
3238 @end group
3239 @end example
3241 In the following example, let's suppose that the frame is 7
3242 columns wide.  Then the edges of the left window are @w{@samp{0 0 4 3}}
3243 and the edges of the right window are @w{@samp{4 0 7 3}}.
3244 The inside edges of the left window are @w{@samp{0 0 3 2}},
3245 and the inside edges of the right window are @w{@samp{4 0 7 2}},
3247 @example
3248 @group
3249            ___ ___
3250           |   |   |
3251           |   |   |
3252           xxxxxxxxx
3254            0  34  7
3255 @end group
3256 @end example
3258 @defun window-pixel-edges &optional window
3259 This function is like @code{window-edges} except that, on a graphical
3260 display, the edge values are measured in pixels instead of in
3261 character lines and columns.
3262 @end defun
3264 @defun window-inside-pixel-edges &optional window
3265 This function is like @code{window-inside-edges} except that, on a
3266 graphical display, the edge values are measured in pixels instead of
3267 in character lines and columns.
3268 @end defun
3270 @defun window-at x y &optional frame
3271 This function returns the window containing the specified cursor
3272 position in the frame @var{frame}.  The coordinates @var{x} and @var{y}
3273 are measured in characters and count from the top left corner of the
3274 frame.  If they are out of range, @code{window-at} returns @code{nil}.
3276 If you omit @var{frame}, the selected frame is used.
3277 @end defun
3279 @defun coordinates-in-window-p coordinates window
3280 This function checks whether a particular frame position falls within
3281 the window @var{window}.
3283 The argument @var{coordinates} is a cons cell of the form @code{(@var{x}
3284 . @var{y})}.  The coordinates @var{x} and @var{y} are measured in
3285 characters, and count from the top left corner of the screen or frame.
3287 The value returned by @code{coordinates-in-window-p} is non-@code{nil}
3288 if the coordinates are inside @var{window}.  The value also indicates
3289 what part of the window the position is in, as follows:
3291 @table @code
3292 @item (@var{relx} . @var{rely})
3293 The coordinates are inside @var{window}.  The numbers @var{relx} and
3294 @var{rely} are the equivalent window-relative coordinates for the
3295 specified position, counting from 0 at the top left corner of the
3296 window.
3298 @item mode-line
3299 The coordinates are in the mode line of @var{window}.
3301 @item header-line
3302 The coordinates are in the header line of @var{window}.
3304 @item vertical-line
3305 The coordinates are in the vertical line between @var{window} and its
3306 neighbor to the right.  This value occurs only if the window doesn't
3307 have a scroll bar; positions in a scroll bar are considered outside the
3308 window for these purposes.
3310 @item left-fringe
3311 @itemx right-fringe
3312 The coordinates are in the left or right fringe of the window.
3314 @item left-margin
3315 @itemx right-margin
3316 The coordinates are in the left or right margin of the window.
3318 @item nil
3319 The coordinates are not in any part of @var{window}.
3320 @end table
3322 The function @code{coordinates-in-window-p} does not require a frame as
3323 argument because it always uses the frame that @var{window} is on.
3324 @end defun
3326 @node Window Configurations
3327 @section Window Configurations
3328 @cindex window configurations
3329 @cindex saving window information
3331   A @dfn{window configuration} records the entire layout of one
3332 frame---all windows, their sizes, which buffers they contain, how those
3333 buffers are scrolled, and their values of point and the mark; also their
3334 fringes, margins, and scroll bar settings.  It also includes the value
3335 of @code{minibuffer-scroll-window}.  As a special exception, the window
3336 configuration does not record the value of point in the selected window
3337 for the current buffer.
3339   You can bring back an entire frame layout by restoring a previously
3340 saved window configuration.  If you want to record the layout of all
3341 frames instead of just one, use a frame configuration instead of a
3342 window configuration; see @ref{Frame Configurations}.
3344 @defun current-window-configuration &optional frame
3345 This function returns a new object representing @var{frame}'s current
3346 window configuration.  The default for @var{frame} is the selected
3347 frame.
3348 @end defun
3350 @defun set-window-configuration configuration
3351 This function restores the configuration of windows and buffers as
3352 specified by @var{configuration}, for the frame that @var{configuration}
3353 was created for.
3355 The argument @var{configuration} must be a value that was previously
3356 returned by @code{current-window-configuration}.  The configuration is
3357 restored in the frame from which @var{configuration} was made, whether
3358 that frame is selected or not.  This always counts as a window size
3359 change and triggers execution of the @code{window-size-change-functions}
3360 (@pxref{Window Hooks}), because @code{set-window-configuration} doesn't
3361 know how to tell whether the new configuration actually differs from the
3362 old one.
3364 If the frame which @var{configuration} was saved from is dead, all this
3365 function does is restore the three variables @code{window-min-height},
3366 @code{window-min-width} and @code{minibuffer-scroll-window}. In this
3367 case, the function returns @code{nil}.  Otherwise, it returns @code{t}.
3369 Here is a way of using this function to get the same effect
3370 as @code{save-window-excursion}:
3372 @example
3373 @group
3374 (let ((config (current-window-configuration)))
3375   (unwind-protect
3376       (progn (split-window-vertically nil)
3377              @dots{})
3378     (set-window-configuration config)))
3379 @end group
3380 @end example
3381 @end defun
3383 @defspec save-window-excursion forms@dots{}
3384 This special form records the window configuration, executes @var{forms}
3385 in sequence, then restores the earlier window configuration.  The window
3386 configuration includes, for each window, the value of point and the
3387 portion of the buffer that is visible.  It also includes the choice of
3388 selected window.  However, it does not include the value of point in
3389 the current buffer; use @code{save-excursion} also, if you wish to
3390 preserve that.
3392 Don't use this construct when @code{save-selected-window} is sufficient.
3394 Exit from @code{save-window-excursion} always triggers execution of
3395 @code{window-size-change-functions}.  (It doesn't know how to tell
3396 whether the restored configuration actually differs from the one in
3397 effect at the end of the @var{forms}.)
3399 The return value is the value of the final form in @var{forms}.
3400 For example:
3402 @example
3403 @group
3404 (split-window)
3405      @result{} #<window 25 on control.texi>
3406 @end group
3407 @group
3408 (setq w (selected-window))
3409      @result{} #<window 19 on control.texi>
3410 @end group
3411 @group
3412 (save-window-excursion
3413   (delete-other-windows w)
3414   (switch-to-buffer "foo")
3415   'do-something)
3416      @result{} do-something
3417      ;; @r{The screen is now split again.}
3418 @end group
3419 @end example
3420 @end defspec
3422 @defun window-configuration-p object
3423 This function returns @code{t} if @var{object} is a window configuration.
3424 @end defun
3426 @defun compare-window-configurations config1 config2
3427 This function compares two window configurations as regards the
3428 structure of windows, but ignores the values of point and mark and the
3429 saved scrolling positions---it can return @code{t} even if those
3430 aspects differ.
3432 The function @code{equal} can also compare two window configurations; it
3433 regards configurations as unequal if they differ in any respect, even a
3434 saved point or mark.
3435 @end defun
3437 @defun window-configuration-frame config
3438 This function returns the frame for which the window configuration
3439 @var{config} was made.
3440 @end defun
3442   Other primitives to look inside of window configurations would make
3443 sense, but are not implemented because we did not need them.  See the
3444 file @file{winner.el} for some more operations on windows
3445 configurations.
3447 @node Window Parameters
3448 @section Window Parameters
3449 @cindex window parameters
3451 This section describes how window parameters can be used to associate
3452 additional information with windows.
3454 @defun window-parameter window parameter
3455 This function returns @var{window}'s value for @var{parameter}.  The
3456 default for @var{window} is the selected window.  If @var{window} has no
3457 setting for @var{parameter}, this function returns @code{nil}.
3458 @end defun
3460 @defun window-parameters &optional window
3461 This function returns all parameters of @var{window} and their values.
3462 The default for @var{window} is the selected window.  The return value,
3463 if non-@code{nil} is an association list whose elements have the form
3464 @code{(@var{parameter} . @var{value})}.
3465 @end defun
3467 @defun set-window-parameter window parameter value
3468 This function sets @var{window}'s value of @var{parameter} to
3469 @var{value} and returns @var{value}.  The default for @var{window}
3470 is the selected window.
3471 @end defun
3473 Some functions, notably @code{split-window}, @code{delete-window}, and
3474 @code{delete-other-windows} behave specially when their @var{window}
3475 argument has a parameter set.  The special behavior consists of a
3476 pre-operation step and a post-operation step.
3478 In the @dfn{pre-operation step}, the value of the parameter is analyzed
3479 and, if its value prescribes some special action, that action is
3480 executed.  For example, the pre-operation step of @code{delete-window}
3481 when invoked on the main window of a compound window (@pxref{Compound
3482 Windows}) calls @code{delete-window} with the root window of the
3483 compound window as argument instead.
3485 In the @dfn{post-operation step}, the parameters of all windows forming
3486 the new configuration are adjusted.  For example, @code{split-window}
3487 when invoked on a main window of a window group (@pxref{Window Groups}),
3488 sets in this step the corresponding parameter of the new window.
3490 You can override that special behavior by binding the following variable
3491 to a non-@code{nil} value:
3493 @defvar ignore-window-parameters
3494 If this variable is non-@code{nil}, some standard functions ignore
3495 window parameters.  The functions currently affected by this are
3496 @code{split-window}, @code{delete-window}, @code{delete-other-windows}
3497 and @code{other-window}.
3499 When this variable equals @code{pre}, the pre-operation step is skipped
3500 but the post-operation step is executed.  When this variable equals
3501 @code{post}, the pre-operation step is executed and thee post-operation
3502 step is skipped.
3504 The value @code{t} means pre- and post-operation steps are skipped.
3505 Currently any other non-@code{nil} value is handled like @code{t}.
3507 An application can bind this variable to a non-@code{nil} value around
3508 calls to these functions.  If it does so and the value is not
3509 @code{pre}, the application is fully responsible for correctly setting
3510 the parameters of all remaining windows after the function exited.
3511 @end defvar
3513 Window parameters are mainly used for implementing composite windows,
3514 @xref{Composite Windows}.  In particular, the @code{compound},
3515 @code{group} and @code{composite} parameters are reserved for that
3516 purpose.
3518 The @code{quit-restore} parameter tells how to proceed with a window
3519 when the user ``quits'' it by invoking @code{quit-restore-window}, see
3520 @ref{Displaying Buffers}.  The following non-@code{nil} values of this
3521 parameter have a special meaning.
3523 @table @asis
3524 @item @code{t}
3525 This means to delete the associated window.  By default, @code{t} is
3526 used for a ``temporary'' window that was obtained by splitting an
3527 existing window.
3529 @item @code{frame}
3530 This means to delete the associated window's frame.  This value
3531 indicates that the associated windows was obtained by popping up a new
3532 frame showing just this window.  If the window is no more needed, it
3533 should be deleted together with the containing frame.
3535 @item A list
3536 This option is useful when the associated window was borrowed to
3537 temporarily display some buffer and quitting shall ``restore'' the
3538 previous contents of the window.  The first three elements of the list
3539 must specify a buffer, a window start position, and a window point.
3540 Quitting the window will then try to display the indicated buffer with
3541 the given start position and point in that window.
3543 The fourth element, if non-@code{nil}, must denote a live buffer.  If
3544 specified, quitting will restore the previous window contents if and
3545 only if the buffer shown in the window is the buffer named by this
3546 element.
3548 The fifth element, if non-@code{nil}, should specify the desired height
3549 of the window when its buffer is restored.  This value is applied if the
3550 buffer temporarily shown in the window was in
3551 @code{temp-buffer-resize-mode} to restore the original height of the
3552 window.
3553 @end table
3555 @node Composite Windows
3556 @section Composite Windows
3557 @cindex composite windows
3559 A @dfn{composite window} is a rectangular frame area, typically composed
3560 of one or more so-called support windows grouped around one or more
3561 so-called main windows.  Some applications allow degenerate composite
3562 windows consisting of one live window only.  Currently, two types of
3563 composite windows are supported: Compound windows (@pxref{Compound
3564 Windows}) and window groups (@pxref{Window Groups}).
3566 @cindex composite root window
3567 Each composite window has one and only one composite root window.  That
3568 root window is usually an internal window (@pxref{Frames and Windows})
3569 but may be a live window in the degenerate case where the composite
3570 window is a live window.  All other windows of a composite window are
3571 subwindows of the composite root window.
3573 @defun composite-root-window-p window
3574 This function return non-@code{nil} if @var{window} is the root window
3575 of a composite window.  The return value is the type of that composite
3576 window, currently either @code{compound} or @code{group}.
3577 @end defun
3579 @defun composite-window-p window
3580 This function returns non-@code{nil} if @var{window} is a subwindow of a
3581 composite window.  The return value is the value of the @code{composite}
3582 window parameter (@pxref{Window Parameters}) of @var{window}.
3584 Note that a composite root window that is not part of a composite window
3585 does not have its @code{composite} window parameter set.  That parameter
3586 is reserved for subwindows of a composite window only.  A root window is
3587 not a subwindow of the composite window rooted at it.
3588 @end defun
3590 @cindex main window
3591 Each composite window must contain at least one @dfn{main window}.  A
3592 main window can be either a live window or an internal window.  Live
3593 main windows are the places where ``normal'' editing activities take
3594 place.  An internal main window is either a window whose subwindows are
3595 all main windows of the same composite window, or the root window of
3596 another composite window.
3598 @defun composite-main-window-p window
3599 Ths function returns @code{t} if @var{window} is a main window of a
3600 composite window.
3601 @end defun
3603 @cindex support window
3604 Composite windows may also contain an arbitrary number of @dfn{support
3605 windows}.  A support window can be either a live window or an internal
3606 window.  Live support windows usually supply information like lists of
3607 files, buffers, tags, or bookmarks, a toolbar, tabs, or compiler and
3608 system messages.  An internal support window is either a window whose
3609 subwindows are all support windows of the same composite window, or the
3610 root window of another composite window.
3612 @defun composite-support-window-p window
3613 Ths function returns @code{t} if @var{window} is a support window of a
3614 composite window.
3615 @end defun
3617 For technical reasons, composite windows may contain internal subwindows
3618 that are neither main nor support windows.  These windows are supposed
3619 to have at least one main and one support window among their child
3620 windows.  The functions @code{composite-main-window-p} and
3621 @code{composite-support-window-p} return @code{nil} for such windows.
3623 Composite windows are implemented with the help of three reserved window
3624 parameters, see @ref{Window Parameters}.  Applications should never use
3625 these parameters for any other purposes than the ones described below.
3627 @table @asis
3628 @item @code{compound}
3629 If non-@code{nil}, this parameter designates the associated window as
3630 the root window of a compound window, see @ref{Compound Windows}.
3632 @item @code{group}
3633 If the value of this parameter is non-@code{nil}, the associated window
3634 is the root window of a window group, see @ref{Window Groups}.
3636 @item @code{composite}
3637 If this parameter is non-@code{nil}, the associated window is a
3638 subwindow of a composite window.  The value must be a cons cell whose
3639 @sc{car} denotes the @dfn{type} of the composite window, either
3640 @code{compound} or @code{group}.
3642 The @sc{cdr} denotes the @dfn{role} of the associated window within the
3643 composite window and should be either @code{main}, @code{support} or
3644 @code{t}.  The value @code{t} usually designates the associated window
3645 as an internal window with at least one main and one support window
3646 among its children.
3647 @end table
3649 For any subwindow @sc{w} of a composite window there has to exist a
3650 unique path from @sc{w} to the root window @sc{r} of the composite
3651 window such that the following property holds invariantly:
3653 @enumerate
3654 @item
3655 The parent window @sc{p} of @sc{w} is either @sc{r} or a subwindow of
3656 @sc{r}.
3658 @item
3659 The types of @sc{w} and @sc{p} must match: This means that if @sc{p}
3660 is @sc{r} then either the type of @sc{w} must be @code{compound} and
3661 the @code{compound} parameter of @sc{r} must be @code{t} or the type of
3662 @sc{w} must be @code{group} and the @code{group} parameter of @sc{r}
3663 must be @code{t}.
3665 @item
3666 If @sc{p} is not @sc{r} either the roles of @sc{w} and @sc{p} are
3667 the same or @sc{p} is neither a main nor a support window.
3668 @end enumerate
3670 Violating this property usually breaks subsequent operations on the
3671 composite window.
3673 @defun composite-root-window window
3674 This function returns the root window of the composite window that
3675 contains @var{window} as a subwindow.  It returns @code{nil} if
3676 @var{window} is not a subwindow of a composite window or the path from
3677 @var{window} to the root of the composite window is broken.
3679 When @var{window} is a subwindow of two or more composite windows, this
3680 function returns the ``innermost'' root window, that is the first root
3681 window found following the path from @var{window} to the root window of
3682 its frame.
3683 @end defun
3685 @cindex major window
3686 Usually, each composite window has one @dfn{major window} comprising all
3687 other main windows of the composite window.  Any composite window should
3688 have only one major window to make sure that functions on its component
3689 windows behave ``as intended''.  The major window can be retrieved via
3690 the following function:
3692 @defun composite-major-window window
3693 This function returns the major window of the composite window
3694 @var{window} belongs to.  The major window is the last main or root
3695 window found by following the path from @var{window} to the root of the
3696 composite window @var{window} belongs to.
3698 This function returns a meaningful result if and only if @var{window} is
3699 a main window.
3700 @end defun
3702 Note also the following aspects of composite windows:
3704 @itemize @bullet
3705 @item
3706 In degenerate cases one and the same window can be the root window of a
3707 compound window and a window group.
3709 @item
3710 Composite windows can be nested.  This means that the root window of a
3711 composite window can also be a subwindow of another composite window.
3712 @end itemize
3714 Uusally, the fact that a window is a subwindow of a composite window
3715 changes the semantics of a number of functions called with that window
3716 as argument.  See @ref{Compound Windows} for a list of functions whose
3717 semantics change in compound windows.  See @ref{Window Groups} for a
3718 corresponding list of functions that behave specially in window groups.
3720 You can override the special behavior of any of these functions for a
3721 particular window in one of two ways:
3723 @itemize @bullet
3724 @item
3725 Set a window parameter denoting the function in question to @code{t}.
3726 This makes the function ``behave as usual''.  For example
3728 @smallexample
3729 (set-window-parameter W 'split-window t)
3730 @end smallexample
3732 will cause @code{split-window} split the window @sc{w} as if @sc{w}
3733 did not have any parameters.
3735 @item
3736 Specify the function to be called instead.  For example
3738 @smallexample
3739 (set-window-parameter W 'split-window 'my-split-window)
3740 @end smallexample
3742 will have @code{split-window} call the function @code{my-split-window}
3743 with the original arguments to do the real work.  As a special case
3745 @smallexample
3746 (set-window-parameter W 'split-window 'ignore)
3747 @end smallexample
3749 will do nothing and return @code{nil}.
3751 @item
3752 Bind the value of @var{ignore-window-parameters} (@pxref{Window
3753 Parameters}) to non-@code{nil} around a call to the function.
3754 @end itemize
3756 The command @code{other-window} usually does not select a support
3757 window.  You can override this behavior by specifying
3759 @smallexample
3760 (set-window-parameter W 'maybe-other-window t)
3761 @end smallexample
3763 in which case @code{other-window} can select @sc{w} just like any other
3764 window.  To specify that a main window does not get selected by
3765 @code{other-window}, set its @code{no-other-window} parameter to
3766 @code{t} as
3768 @smallexample
3769 (set-window-parameter W 'no-other-window t)
3770 @end smallexample
3772 Creating a new support window can be tricky.  The following function
3773 should handle this.
3775 @defun make-support-window window support &optional size horizontal
3776 This function adds a support window of type @var{support} to
3777 @var{window}.  The argument @var{window} must specify either a root
3778 window or a subwindow of a composite window.  The argument @var{window}
3779 must be one of @code{compound} or @code{group}.  The optional arguments
3780 @var{SIZE} and @var{HORIZONTAL} are as for @code{split-window}.  The
3781 return value is the new support window.
3783 This function behaves like @code{split-window} but makes sure that the
3784 parameters of all involved windows are set correctly.  In particular,
3785 the new leaf window becomes a support window of the composite window.
3786 @end defun
3789 @node Compound Windows
3790 @section Compound Windows
3791 @cindex compound windows
3793 A @dfn{compound window} is a composite window (@pxref{Composite
3794 Windows}) built from two or more subwindows.  For any subwindow of a
3795 compound window the semantics of a number of operations usually changes
3796 in the sense that the operation is suitably applied to the entire
3797 compound window instead.
3799    One typical use of a compound window is that of providing a sidebar
3800 (like the speedbar) attached to a single ``main'' window.  Splitting the
3801 main window vertically then guarantees that the new window appears below
3802 (or above) the compound window thus not disrupting the relationship
3803 between the sidebar and the main window.  Another use of compound
3804 windows is that of a support window displaying a toolbar or tabs above a
3805 main window.  In this case splitting the main window horizontally will
3806 not break the relationship between the supporting and the main window.
3808    Compound windows must have at least two subwindows.  When
3809 @code{delete-window} deletes a subwindow of a compound window and there
3810 is only one more subwindow left, the compound window is dissolved
3811 automatically and ceases to have any impact on subsequent operations on
3812 the last remaining subwindow.  Apart from this restriction a compound
3813 window may have any number of subwindows.  Deleting the last main window
3814 of a compound window deletes the entire compound window instead (recall
3815 that a composite window must have at least one main subwindow).
3817    Application programs are supposed to preserve the types assigned to
3818 members of compound windows.  If they don't, they risk to break the
3819 semantics of operations on the compound window.  Note also that any
3820 subwindow of a compound window can be the root of another composite
3821 window since the latter can be nested.
3823    In addition to the functions giving meaningful results for any
3824 composite window (@pxref{Composite Windows}) the following functions
3825 have been designed specifically to operate on a subwindow of a compound
3826 window.
3828 @defun compound-window-p window
3829 This function returns non-@code{nil} if @var{window} is a subwindow of a
3830 compound window.
3831 @end defun
3833 @defun compound-main-window-p window
3834 This function returns non-@code{nil} if @var{window} is a main window of
3835 a compound window.
3836 @end defun
3838 A compound window can be created with the following function:
3840 @defun make-compound-window &optional window main size horizontal
3841 This functions behaves like @code{split-window} (@pxref{Splitting
3842 Windows}) with the additional twist that it makes @var{window} the main
3843 window of a new compound window.  For this purpose, it creates a new
3844 internal window with @var{window} and a new leaf window as its only
3845 children.  @var{window} must be a leaf window and defaults to the
3846 selected window.
3848 If the optional argument @var{main} is non-@code{nil}, this means the
3849 new leaf window becomes a main window.  Argument @var{main} @code{nil}
3850 or not provided means the new leaf window becomes a support window.  The
3851 original window @var{window} always becomes a main window.
3853 The optional arguments @var{size} and @var{horizontal} are as for
3854 @code{split-window}.  The return value is the new leaf window.
3855 @end defun
3857 Alternatively, a compound window can be constructed ``manually'' by
3858 splitting some live window and setting the @code{root} and
3859 @code{composite} parameters of the involved windows.  Look at how
3860 @code{make-compound-window} sets these parameters for an example.
3862 Currently, the semantics of the following commands and functions change
3863 when their window argument is a member of a compound window:
3865 @table @asis
3866 @item @code{split-window} (@pxref{Splitting Windows})
3867 When @var{window} is a component of a compound window,
3868 @code{split-window} is invoked with the root window of the compound
3869 window as argument instead.
3871 @item @code{delete-window} (@pxref{Deleting Windows})
3872 When @var{window} is a component of a compound window,
3873 @code{delete-window} deletes the entire compound window instead.  If the
3874 root window of the compound window is the root window of its containing
3875 frame, or a support window or the only main window of a window group
3876 (@pxref{Window Groups}) an error is signalled.
3878 @item @code{delete-other-windows} (@pxref{Deleting Windows})
3879 When @var{window} belongs to a compound window,
3880 @code{delete-other-windows} makes the compound window fill its frame or,
3881 if present, the innermost enclosing major window of a window group, see
3882 @ref{Window Groups}.  If the root window of the compound window is the
3883 root window of its containing frame, or a support window or the only
3884 main window of a window group (@pxref{Window Groups}) nothing is done.
3885 @end table
3887 @node Window Groups
3888 @section Window Groups
3889 @cindex window groups
3891 A @dfn{window group} is a composite window (@pxref{Composite Windows})
3892 built from one or more subwindows.  The main application area of window
3893 groups is in the implementation of Integrated Development Environments
3894 (IDEs) where a rectangular subarea of a frame constitutes the editing
3895 environment proper.  The remaining windows are used for displaying
3896 supporting information and are not intended for editing.
3898 Each window group must contain at least one main window which must be
3899 either live or an internal window which should comprise all other main
3900 windows of the group.  Note that the latter restriction is not checked
3901 by the routines operating on window groups but it's better if
3902 application preserve it since some operations inherently rely on it.
3904 Usually, the root window of a window group is also the root window of
3905 the containing frame (@pxref{Frames and Windows}).  Note, however, that
3906 window groups (and compound windows) can be arbitrarily nested.
3908 @defun group-window-p window
3909 This function returns non-@code{nil} if @var{window} is a subwindow of a
3910 window group.
3911 @end defun
3913 @defun group-window-main-p window
3914 This function returns non-@code{nil} if @var{window} is a main window of
3915 a window group.
3916 @end defun
3918 @defun group-root-window window
3919 This function returns the root window of the window group @var{window}
3920 belongs to.  If @var{window} is part of a compound window, it returns
3921 the root window of the group the root of the compound window belongs
3922 too.
3923 @end defun
3925 You can create a new window group with the following function:
3927 @defun make-window-group &optional window
3928 This functions makes @var{window} the main and root window of a new
3929 window group.  The argument @var{window} must be a live window and
3930 defaults to the selected one.  This function returns @var{window}.
3931 @end defun
3933 Alternatively, you can construct a window group ``manually'' by
3934 appropriately setting the @code{root} parameter of any live window.
3936 Currently, the semantics of the following commands and functions change
3937 when their window argument is a member of a window group:
3939 @table @asis
3940 @item @code{split-window} (@pxref{Splitting Windows})
3941 @code{split-window} is allowed to split main windows of a window group
3942 only.  It will signal an error when invoked with a support window as
3943 argument.
3945 @item @code{delete-window} (@pxref{Deleting Windows})
3946 @code{delete-window} is allowed to delete a main window of a window
3947 group only.  It will signal an error when invoked with a support window
3948 or the last main window of the group as argument
3950 If a window group contains two disjoint main windows that are not
3951 subwindows of another main window of the group, @code{delete-window} may
3952 signal an error even if the window group contains other main windows.
3954 @item @code{delete-other-windows} (@pxref{Deleting Windows})
3955 When @code{delete-other-windows} is invoked with a main window of a
3956 window group as argument, it will delete all main windows of that group
3957 that are neither the argument window itself nor a subwindow of the
3958 argument window.  Support windows are not affected by this operation.
3959 An error is signalled when @code{delete-other-windows} is invoked with a
3960 support window as its argument.
3962 If a window group contains two disjoint main windows that are not
3963 subwindows of another main window of the group,
3964 @code{delete-other-windows} will not be able to remove all main windows
3965 but the argument window and its subwindows.
3966 @end table
3968 @node Window Hooks
3969 @section Hooks for Window Scrolling and Changes
3970 @cindex hooks for window operations
3972 This section describes how a Lisp program can take action whenever a
3973 window displays a different part of its buffer or a different buffer.
3974 There are three actions that can change this: scrolling the window,
3975 switching buffers in the window, and changing the size of the window.
3976 The first two actions run @code{window-scroll-functions}; the last runs
3977 @code{window-size-change-functions}.
3979 @defvar window-scroll-functions
3980 This variable holds a list of functions that Emacs should call before
3981 redisplaying a window with scrolling.  Displaying a different buffer in
3982 the window also runs these functions.
3984 This variable is not a normal hook, because each function is called with
3985 two arguments: the window, and its new display-start position.
3987 These functions must be careful in using @code{window-end}
3988 (@pxref{Window Start and End}); if you need an up-to-date value, you
3989 must use the @var{update} argument to ensure you get it.
3991 @strong{Warning:} don't use this feature to alter the way the window
3992 is scrolled.  It's not designed for that, and such use probably won't
3993 work.
3994 @end defvar
3996 @defvar window-size-change-functions
3997 This variable holds a list of functions to be called if the size of any
3998 window changes for any reason.  The functions are called just once per
3999 redisplay, and just once for each frame on which size changes have
4000 occurred.
4002 Each function receives the frame as its sole argument.  There is no
4003 direct way to find out which windows on that frame have changed size, or
4004 precisely how.  However, if a size-change function records, at each
4005 call, the existing windows and their sizes, it can also compare the
4006 present sizes and the previous sizes.
4008 Creating or deleting windows counts as a size change, and therefore
4009 causes these functions to be called.  Changing the frame size also
4010 counts, because it changes the sizes of the existing windows.
4012 It is not a good idea to use @code{save-window-excursion} (@pxref{Window
4013 Configurations}) in these functions, because that always counts as a
4014 size change, and it would cause these functions to be called over and
4015 over.  In most cases, @code{save-selected-window} (@pxref{Selecting
4016 Windows}) is what you need here.
4017 @end defvar
4019 @defvar window-configuration-change-hook
4020 A normal hook that is run every time you change the window configuration
4021 of an existing frame.  This includes splitting or deleting windows,
4022 changing the sizes of windows, or displaying a different buffer in a
4023 window.
4025 The buffer-local part of this hook is run once per each window on the
4026 affected frame, with the relevant window selected and its buffer
4027 current.  The global part is run once for the modified frame, with that
4028 frame selected.
4029 @end defvar
4031   In addition, you can use @code{jit-lock-register} to register a Font
4032 Lock fontification function, which will be called whenever parts of a
4033 buffer are (re)fontified because a window was scrolled or its size
4034 changed.  @xref{Other Font Lock Variables}.
4036 @ignore
4037    arch-tag: 3f6c36e8-df49-4986-b757-417feed88be3
4038 @end ignore