New code for replacing buffers in windows, mostly in Elisp now.
[emacs.git] / doc / lispref / windows.texi
blob16662c05c8f002ad21dfb1ace27234532e78d643
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 * Switching Buffers::       Higher-level functions for switching to a buffer
26                               in some window.
27 * Displaying Buffers::      How to choose a window for displaying a buffer.
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
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 This function returns non-@code{nil} if it orderly resized @var{window},
797 and @code{nil} otherwise.
798 @end deffn
800 @deffn Command shrink-window-if-larger-than-buffer &optional window
801 This command shrinks @var{window} vertically to be as small as possible
802 while still showing the full contents of its buffer---but not less than
803 @code{window-min-height} lines.  The argument @var{window} must denote
804 a live window and defaults to the selected one.
806 However, this command does nothing if the window is already too small to
807 display the whole text of the buffer, or if part of the contents are
808 currently scrolled off screen, or if the window is not the full width of
809 its frame, or if the window is the only window in its frame.
811 This command returns non-@code{nil} if it actually shrank the window
812 and @code{nil} otherwise.
813 @end deffn
815 @cindex balancing window sizes
816 Emacs provides two functions to balance windows, that is, to even out
817 the sizes of windows on the same frame.  The minibuffer window and
818 fixed-size windows are not resized by these functions.
820 @deffn Command balance-windows &optional window-or-frame
821 This function balances windows in a way that gives more space to
822 full-width and/or full-height windows.  If @var{window-or-frame}
823 specifies a frame, it balances all windows on that frame.  If
824 @var{window-or-frame} specifies a window, it balances that window and
825 its siblings (@pxref{Frames and Windows}) only.
826 @end deffn
828 @deffn Command balance-windows-area
829 This function attempts to give all windows on the selected frame
830 approximately the same share of the screen area.  This means that
831 full-width or full-height windows are not given more space than other
832 windows.
833 @end deffn
835 @cindex maximizing windows
836 The following function can be used to give a window the maximum possible
837 size on its frame.
839 @deffn Command maximize-window &optional window
840 This function maximizes @var{window}.  More precisely, this makes
841 @var{window} as large as possible without resizing its frame or deleting
842 other windows.  @var{window} can be any window and defaults to the
843 selected one.
844 @end deffn
846 @cindex minimizing windows
847 To make a window as small as possible without deleting it the
848 following function can be used.
850 @deffn Command minimize-window &optional window
851 This function minimizes @var{window}.  More precisely, this makes
852 @var{window} as small as possible without deleting it or resizing its
853 frame.  @var{window} can be any window and defaults to the selected one.
854 @end deffn
856 @node Splitting Windows
857 @section Splitting Windows
858 @cindex splitting windows
859 @cindex window splitting
861 The functions described below are the primitives needed for creating a
862 new window.  They do not accept a buffer as an argument.  Rather, they
863 apparently ``split'' an existing window into two halves, both displaying
864 the buffer previously visible in the window that was split.
866 @deffn Command split-window &optional window size horizontal
867 This function creates a new window adjacent to @var{window}.  It returns
868 the new window which is always a live window.  The argument @var{window}
869 can denote any window and defaults to the selected one.  This function
870 does not change the selected window.
872 Optional second argument @var{size} a positive number means make
873 @var{window} @var{size} lines (or columns) tall.  If @var{size} is
874 negative, make the new window @minus{}@var{size} lines (or columns)
875 tall.  If @var{size} is omitted or @code{nil}, then @var{window} is
876 divided evenly into two parts.  (If there is an odd line, it is
877 allocated to the new window.)
879 If splitting would result in making a window smaller than
880 @code{window-min-height} or @code{window-min-width} (@pxref{Window
881 Sizes}), this function usually signals an error.  However, if @var{size}
882 is negative and its absolute value is valid, a new window of the
883 requested size is created.  (A size value would be invalid if it
884 assigned less than one line or less than two columns to the new window.)
886 Optional third argument @var{horizontal} @code{nil} (or @code{below})
887 specifies that the new window shall be located below @var{window}.  The
888 value @code{above} means the new window will be located above
889 @var{window}.  In both cases @var{size} specifies the new number of
890 lines for @var{window} (or the new window if @var{size} is negative)
891 including space reserved for the mode and/or header line.
893 If @var{horizontal} is @code{t} or @code{right} the new window will be
894 positioned on the right side of @var{window}.  The value @code{left}
895 means the new window will be located on the left side of @var{window}.
896 In both cases @var{size} specifies the new number of columns for
897 @var{window} (or the new window provided @var{size} is negative)
898 including space reserved for margins, fringes and the scroll bar or a
899 divider column.
901 Any other non-@code{nil} value for @var{horizontal} is currently handled
902 like @code{t} (or @code{right}).  Since this might change in the future,
903 application programs should refrain from using other values.
905 If @var{window} is live, properties of the new window like margins and
906 scroll bars are inherited from @var{window}.  If @var{window} is an
907 internal window, these properties, as well as the buffer shown in the
908 new window, are inherited from the window selected on @var{window}'s
909 frame.
911 This function respects the variable @code{ignore-window-parameters}
912 (@pxref{Window Parameters}) when processing window parameters so any
913 processing of @var{window}'s parameters may be suppressed.
915 If the @code{split-window} parameter of @var{window} equals @code{t},
916 any other parameters for @var{window} are ignored and @var{window} is
917 split as described above.  If the @code{split-window} parameter of
918 @var{window} specifies a function, that function is called with the
919 @var{window}, @var{size}, and @var{horizontal} arguments to do the
920 split.  If that function is @code{ignore}, nothing is done.  It's the
921 responsibility of that function to adjust all window parameters.
923 If neither @code{ignore-window-parameters} nor the @code{split-window}
924 parameter come in the way, this function may behave specially when
925 @var{window} is a composite window or part of a composite window, see
926 @ref{Composite Windows}.  If @var{window} is a component of a compound
927 window (@pxref{Compound Windows}) this function operates on the root of
928 the compound window instead.  The new window does not become a member of
929 the compound window.  If @var{window} is a main window of a window group
930 (@pxref{Window Groups}), the new window becomes a main window in that
931 window group.  If @var{window} is a non-main component of a window group
932 this function signals an error.
933 @end deffn
935 The following example starts with one window on a screen that is 50
936 lines high by 80 columns wide; then it splits the window.
938 @smallexample
939 @group
940 (setq w1 (selected-window))
941      @result{} #<window 8 on windows.texi>
942 (setq w2 (split-window w1 15))
943      @result{} #<window 28 on windows.texi>
944 @end group
945 @group
946 (window-top-line w1)
947      @result{} 0
948 (window-total-size w1)
949      @result{} 15
950 (window-top-line w2)
951      @result{} 15
952 @end group
953 @end smallexample
955 The screen looks like this:
957 @smallexample
958 @group
959          __________
960         |          |  line 0
961         |    w1    |
962         |__________|
963         |          |  line 15
964         |    w2    |
965         |__________|
966                       line 50
967  column 0   column 80
968 @end group
969 @end smallexample
971 Next, split the top window horizontally:
973 @smallexample
974 @group
975 (setq w3 (split-window w1 35 t))
976      @result{} #<window 32 on windows.texi>
977 @end group
978 @group
979 (window-left-column w1)
980      @result{} 0
981 (window-total-size w1 t)
982      @result{} 35
983 (window-left-column w3)
984      @result{} 35
985 @end group
986 @end smallexample
988 @need 3000
989 Now the screen looks like this:
991 @smallexample
992 @group
993      column 35
994          __________
995         |    |     |  line 0
996         | w1 |  w3 |
997         |____|_____|
998         |          |  line 15
999         |    w2    |
1000         |__________|
1001                       line 50
1002  column 0   column 80
1003 @end group
1004 @end smallexample
1006 Normally, Emacs indicates the border between two side-by-side windows
1007 with a scroll bar (@pxref{Scroll Bars}), or with @samp{|} characters.  The
1008 display table can specify alternative border characters; see @ref{Display
1009 Tables}.
1011 The following option affects the behavior of a number of functions
1012 operating on a window that is part of a window combination, see
1013 @ref{Frames and Windows}.
1015 @defopt window-splits
1016 If this variable is @code{nil}, @code{split-window} creates a new parent
1017 window if and only if either @var{window} has no parent window or
1018 @var{window} shall be split in another direction than the combination
1019 @var{window} is part of.  @code{resize-window} preferably resizes
1020 @var{window}'s right sibling.  @code{delete-window} preferably returns
1021 space to @var{window}'s left sibling.
1023 If this variable equals @code{nest}, @code{split-window} always creates
1024 a new parent window.  As a consequence, any frame's window tree is a
1025 binary tree and every window has at most one (left or right) sibling.
1026 @code{resize-window} preferably resizes @var{window}'s sibling.
1027 @code{delete-window} preferably returns space to @var{window}'s sibling.
1029 If this variable equals @code{resize}, @code{split-window} tries to
1030 resize all windows belnging to the same combination as @var{window} to
1031 accomodate the new window.  Hence, the new window can be also created if
1032 @var{window} is otherwise too small to be split.  Resizing or deleting
1033 any window of a combination tries to distribute space proportionally
1034 among all other windows of the combination.
1036 Application programs should never rebind this variable to any value but
1037 @code{nest}.
1038 @end defopt
1040 @deffn Command split-window-vertically &optional size
1041 This function splits the selected window into two windows, one above the
1042 other, leaving the upper of the two windows selected, with @var{size}
1043 lines.  (If @var{size} is negative, then the lower of the two windows
1044 gets @minus{}@var{size} lines and the upper window gets the rest, but
1045 the upper window is still the one selected.)  However, if
1046 @code{split-window-keep-point} (see below) is @code{nil}, then either
1047 window can be selected.
1049 In other respects, this function is similar to @code{split-window}.
1050 In particular, the upper window is the original one and the return
1051 value is the new, lower window.
1052 @end deffn
1054 @defopt split-window-keep-point
1055 If this variable is non-@code{nil} (the default), then
1056 @code{split-window-vertically} behaves as described above.
1058 If it is @code{nil}, then @code{split-window-vertically} adjusts point
1059 in each of the two windows to avoid scrolling.  (This is useful on
1060 slow terminals.)  It selects whichever window contains the screen line
1061 that point was previously on.
1063 This variable affects the behavior of @code{split-window-vertically}
1064 only.  It has no effect on the other functions described here.
1065 @end defopt
1067 @deffn Command split-window-horizontally &optional size
1068 This function splits the selected window into two windows
1069 side-by-side, leaving the selected window on the left with @var{size}
1070 columns.  If @var{size} is negative, the rightmost window gets
1071 @minus{}@var{size} columns, but the leftmost window still remains
1072 selected.
1073 @end deffn
1075 @node Deleting Windows
1076 @section Deleting Windows
1077 @cindex deleting windows
1079 A window remains visible on its frame unless you @dfn{delete} it by
1080 calling certain functions that delete windows.  A deleted window cannot
1081 appear on the screen, but continues to exist as a Lisp object until
1082 there are no references to it.  There is no way to cancel the deletion
1083 of a window aside from restoring a saved window configuration
1084 (@pxref{Window Configurations}).  Restoring a window configuration also
1085 deletes any windows that aren't part of that configuration.
1087 @strong{Warning:} Erroneous information or fatal errors may result from
1088 using a deleted window as if it were live.
1090 @deffn Command delete-window &optional window
1091 This function removes @var{window} from display and returns @code{nil}.
1092 The argument @var{window} can denote any window and defaults to the
1093 selected one.  An error is signaled if @var{window} is the only window
1094 on its frame.  Hence @var{window} must have at least one sibling window
1095 (@pxref{Frames and Windows}) in order to get deleted.
1097 If @code{window-splits} is @code{nil}, the space @var{window} took up is
1098 given to its left sibling if such a window exists and to its right
1099 sibling otherwise.  If @code{window-splits} equals @code{nest} that
1100 space is given to the sole remaining sibling of @var{window}.  If
1101 @code{window-splits} equals @code{resize}, the space occupied by
1102 @var{window} is distributed proportionally among the other windows in
1103 the same combination as @var{window}.
1105 This function respects the variable @code{ignore-window-parameters}
1106 (@pxref{Window Parameters}) when processing window parameters.  If
1107 parameters are not ignored and the @code{delete-window} parameter of
1108 @var{window} equals @code{t}, this function deletes @var{window}
1109 ignoring any other window parameters.  If the @code{delete-window}
1110 parameter specifies a function, that function is called with
1111 @var{window} as its sole argument.  It's the responsibility of that
1112 function to adjust the parameters of all remaining windows.
1114 Otherwise, if @var{window} is part of a compound window (@pxref{Compound
1115 Windows}), this function is called with the root of the compound window
1116 as its argument.  If @var{window} is a support window or the last main
1117 window of a window group (@pxref{Window Groups}), this function signals
1118 an error.
1119 @end deffn
1121 @deffn Command delete-other-windows &optional window
1122 This function makes @var{window} fill its frame and returns @code{nil}.
1123 The argument @var{window} can denote an arbitrary window and defaults to
1124 the selected one.
1126 This function respects the variable @code{ignore-window-parameters}
1127 when processing window parameters so any processing of @var{window}'s
1128 parameters may be suppressed.
1130 If the @code{delete-other-windows} parameter of @var{window} equals
1131 @code{t}, this function deletes the remaining windows ignoring all other
1132 parameters.  If the @code{delete-other-windows} parameter specifies a
1133 function, it calls that function with @var{window} as its sole argument.
1135 Otherwise, if @var{window} is part of a compound window, it calls this
1136 function with the root of the compound window as its argument.  If
1137 @var{window} is a main window in a window group, it makes @var{window}
1138 the only main window in that group.  Any support windows of the group
1139 are left alone.  If @var{window} is a support window of a window group,
1140 this function signals an error and doesn't delete any windows.
1141 @end deffn
1143 @deffn Command delete-windows-on &optional buffer-or-name frame
1144 This function deletes all windows showing @var{buffer-or-name} and
1145 returns nil.  If there are no windows showing @var{buffer-or-name}, it
1146 does nothing.  The optional argument @var{buffer-or-name} may be a
1147 buffer or the name of an existing buffer and defaults to the current
1148 buffer.  Invoking this command on a minibuffer signals an error.
1150 @code{delete-windows-on} operates by calling @code{delete-window} for
1151 each window showing @var{buffer-or-name}.  If a frame has several
1152 windows showing different buffers, then those showing
1153 @var{buffer-or-name} are removed, and the other windows expand to fill
1154 the space.  If all windows in some frame are showing
1155 @var{buffer-or-name} (including the case where there is only one
1156 window), then the frame winds up with a single window showing another
1157 buffer chosen with @code{other-buffer}, see @ref{The Buffer List}.  If,
1158 however, that last remaining window is dedicated to the buffer specified
1159 by @var{buffer-or-name} (@pxref{Dedicated Windows}), and there are other
1160 frames left, that window's frame is deleted.
1162 The optional argument @var{frame} specifies which frames to operate on.
1163 This function does not use it in quite the same way as the other
1164 functions which scan all live windows (@pxref{Cyclic Window Ordering});
1165 specifically, the values @code{t} and @code{nil} have the opposite of
1166 their meanings in the other functions.  Here are the full details:
1168 @itemize @bullet
1169 @item @code{nil}
1170 means operate on all frames.
1171 @item @code{t}
1172 means operate on the selected frame.
1173 @item @code{visible}
1174 means operate on all visible frames.
1175 @item @code{0}
1176 means operate on all visible or iconified frames.
1177 @item A frame
1178 means operate on that frame.
1179 @end itemize
1180 @end deffn
1182 @node Selecting Windows
1183 @section Selecting Windows
1184 @cindex selecting a window
1186 @cindex selected window
1187 In each frame, at any time, one and only one window is designated as
1188 @dfn{selected within the frame}.  Also, at any time, one frame is the
1189 selected frame (@pxref{Input Focus}).  The window selected within the
1190 selected frame is the @dfn{selected window}.  The selected window's
1191 buffer is usually the current buffer (except when @code{set-buffer} has
1192 been used); see @ref{Current Buffer}.
1194 @defun selected-window
1195 This function returns the selected window.  This is the window in which
1196 the cursor for selected windows (@pxref{Cursor Parameters}) appears and
1197 to which many commands apply.
1198 @end defun
1200 @defun select-window window &optional norecord
1201 This function makes @var{window} the selected window.  Unless
1202 @var{window} already is the selected window, this also makes
1203 @var{window}'s buffer (@pxref{Buffers and Windows}) the current buffer.
1204 Moreover, the cursor for selected windows will be displayed in
1205 @var{window} after the next redisplay.  This function returns
1206 @var{window}.
1208 Normally, @var{window}'s selected buffer is moved to the front of the
1209 buffer list (@pxref{The Buffer List}) and @var{window} becomes the most
1210 recently selected window.  But if the optional argument @var{norecord}
1211 is non-@code{nil}, the buffer list remains unchanged and @var{window}
1212 does not become the most recently selected one.
1213 @end defun
1215 @cindex most recently selected windows
1216 The sequence of calls to @code{select-window} with a non-@code{nil}
1217 @var{norecord} argument determines an ordering of windows by their
1218 selection time.  The function @code{get-lru-window} can be used to
1219 retrieve the least recently selected live window in this ordering, see
1220 @ref{Cyclic Window Ordering}.
1222 @defmac save-selected-window forms@dots{}
1223 This macro records the selected frame, as well as the selected window
1224 of each frame, executes @var{forms} in sequence, then restores the
1225 earlier selected frame and windows.  It also saves and restores the
1226 current buffer.  It returns the value of the last form in @var{forms}.
1228 This macro does not save or restore anything about the sizes,
1229 arrangement or contents of windows; therefore, if @var{forms} change
1230 them, the change persists.  If the previously selected window of some
1231 frame is no longer live at the time of exit from @var{forms}, that
1232 frame's selected window is left alone.  If the previously selected
1233 window is no longer live, then whatever window is selected at the end of
1234 @var{forms} remains selected.  The current buffer is restored if and
1235 only if it is still live when exiting @var{forms}.
1237 This macro changes neither the ordering of recently selected windows nor
1238 the buffer list.
1239 @end defmac
1241 @defmac with-selected-window window forms@dots{}
1242 This macro selects @var{window}, executes @var{forms} in sequence, then
1243 restores the previously selected window and current buffer.  The ordering
1244 of recently selected windows and the buffer list remain unchanged unless
1245 you deliberately change them within @var{forms}, for example, by calling
1246 @code{select-window} with argument @var{norecord} @code{nil}.
1248 The order of recently selected windows and the buffer list are not
1249 changed by this macro.
1250 @end defmac
1252 @cindex frame selected window
1253 @cindex window selected within frame
1254 Above we explained that at any time, exactly one window on any frame is
1255 selected within the frame.  The significance of this designation is that
1256 selecting the frame also selects this window.  Conversely, selecting a
1257 window for Emacs with @code{select-window} also makes that window
1258 selected within its frame.
1260 @defun frame-selected-window  &optional frame
1261 This function returns the window on @var{frame} that is selected within
1262 @var{frame}.  The optional argument @var{frame} must denote a live frame
1263 and defaults to the selected one.
1264 @end defun
1266 @defun set-frame-selected-window frame window &optional norecord
1267 This function sets the selected window of frame @var{frame} to
1268 @var{window}.  The argument @var{frame} must denote a live frame and
1269 defaults to the selected one.  If @var{frame} is the selected frame,
1270 this also makes @var{window} the selected window.  The argument
1271 @var{window} must denote a live window.  This function returns
1272 @var{window}.
1274 Optional argument @var{norecord} non-@code{nil} means to neither change
1275 the list of most recently selected windows (@pxref{Selecting Windows})
1276 nor the buffer list (@pxref{The Buffer List}).
1277 @end defun
1279 @node Cyclic Window Ordering
1280 @section Cyclic Ordering of Windows
1281 @cindex cyclic ordering of windows
1282 @cindex ordering of windows, cyclic
1283 @cindex window ordering, cyclic
1285 When you use the command @kbd{C-x o} (@code{other-window}) to select
1286 some other window, it moves through live windows in a specific order.
1287 For any given configuration of windows, this order never varies.  It is
1288 called the @dfn{cyclic ordering of windows}.
1290    For a particular frame, this ordering is determined by the window
1291 tree of that frame, see @ref{Frames and Windows}.  More precisely, the
1292 ordering is obtained by a depth-first traversal of the frame's window
1293 tree supplemented, if requested, by the frame's minibuffer window.
1295    If there's just one live frame, the cyclic ordering is the ordering
1296 for that frame.  Otherwise, the cyclic ordering is obtained by appending
1297 the orderings for individual frames in order of the list of all live
1298 frames, @ref{Finding All Frames}.  In any case, the ordering is made
1299 ``cyclic'' by having the last window precede the first window in the
1300 ordering.
1302 @defun next-window &optional window minibuf all-frames
1303 @cindex minibuffer window, and @code{next-window}
1304 This function returns the window following @var{window} in the cyclic
1305 ordering of windows.  This is the window @kbd{C-x o} selects if typed
1306 when @var{window} is selected.  The argument @var{window} must specify a
1307 live window and defaults to the selected one.
1309 The optional argument @var{minibuf} specifies whether minibuffer windows
1310 shall be included in the cyclic ordering.  Normally, when @var{minibuf}
1311 is @code{nil}, a minibuffer window is included only if it is currently
1312 ``active''; this matches the behavior of @kbd{C-x o}.  (Note that a
1313 minibuffer window is active as long as its minibuffer is in use; see
1314 @ref{Minibuffers}).
1316 If @var{minibuf} is @code{t}, the cyclic ordering includes all
1317 minibuffer windows.  If @var{minibuf} is neither @code{t} nor
1318 @code{nil}, minibuffer windows are not included even if they are active.
1320 The optional argument @var{all-frames} specifies which frames to
1321 consider.  Here are the possible values and their meanings:
1323 @itemize @bullet
1324 @item @code{nil}
1325 means consider all windows on @var{window}'s frame, plus the minibuffer
1326 window used by that frame even if it lies in some other frame.  If the
1327 minibuffer counts (as determined by @var{minibuf}), then all windows on
1328 all frames that share that minibuffer count too.
1330 @item @code{t}
1331 means consider all windows on all existing frames.
1333 @item @code{visible}
1334 means consider all windows on all visible frames.  (To get useful
1335 results, ensure that @var{window} is on a visible frame.)
1337 @item 0
1338 means consider all windows on all visible or iconified frames.
1340 @item A frame
1341 means consider all windows on that frame.
1343 @item Anything else
1344 means consider the windows on @var{window}'s frame, and no others.
1345 @end itemize
1347 This example assumes there are two windows, both displaying the
1348 buffer @samp{windows.texi}:
1350 @example
1351 @group
1352 (selected-window)
1353      @result{} #<window 56 on windows.texi>
1354 @end group
1355 @group
1356 (next-window (selected-window))
1357      @result{} #<window 52 on windows.texi>
1358 @end group
1359 @group
1360 (next-window (next-window (selected-window)))
1361      @result{} #<window 56 on windows.texi>
1362 @end group
1363 @end example
1364 @end defun
1366 @defun previous-window &optional window minibuf all-frames
1367 This function returns the window preceding @var{window} in the cyclic
1368 ordering of windows.  The other arguments specify which windows to
1369 consider as in @code{next-window}.
1370 @end defun
1372 @deffn Command other-window count &optional all-frames
1373 This function selects another window in the cyclic ordering of windows.
1374 @var{count} specifies the number of windows to skip in the ordering,
1375 starting with the selected window, before making the selection.  If
1376 @var{count} is a positive number, it skips @var{count} windows forwards.
1377 @var{count} negative means skip @minus{}@var{count} windows backwards.
1378 If @var{count} is zero, it does not skip any window, thus re-selecting
1379 the selected window.  In an interactive call, @var{count} is the numeric
1380 prefix argument.
1382 The optional argument @var{all-frames} has the same meaning as in
1383 @code{next-window}, but the @var{minibuf} argument of @code{next-window}
1384 is always effectively @code{nil}.  This function returns @code{nil}.
1385 @end deffn
1387 The following function returns a copy of the list of windows in the
1388 cyclic odering.
1390 @defun window-list-1 &optional window &optional minibuf &optional all_frames
1391 This function returns a list of live windows.  The optional arguments
1392 @var{minibuf} and @var{all-frames} specify the set of windows to include
1393 in the list.  See the description of @code{next-window} for details.
1395 The optional argument @var{window} specifies the first window to list
1396 and defaults to the selected window.  If @var{window} is not on the list
1397 of windows returned, some other window will be listed first but no error
1398 is signalled.
1399 @end defun
1401 The functions described below use @code{window-list-1} for generating a
1402 copy of the list of all relevant windows.  Hence, any change of the
1403 window configuration that occurs while one of these functions is
1404 executed is @emph{not} reflected in the list of windows investigated.
1406 @defun walk-windows proc &optional minibuf all-frames
1407 This function cycles through live windows.  It calls the function
1408 @var{proc} once for each window, with the window as its sole argument.
1410 The optional arguments @var{minibuf} and @var{all-frames} specify the
1411 set of windows to include in the walk, see @code{next-window} above.  If
1412 @var{all-frames} specifies a frame, the first window walked is the first
1413 window on that frame as returned by @code{frame-first-window} and not
1414 necessarily the selected window.
1416 If @var{proc} changes the window configuration by splitting or deleting
1417 windows, that change is not reflected in the set of windows walked.
1418 That set is determined entirely by the set of live windows at the time
1419 this function was invoked.
1420 @end defun
1422 The following function allows to determine whether a specific window is
1423 the only live window.
1425 @defun one-window-p &optional no-mini all-frames
1426 This function returns non-@code{nil} if the selected window is the only
1427 window.
1429 The optional argument @var{no-mini}, if non-@code{nil}, means don't
1430 count the minibuffer even if it is active; otherwise, the minibuffer
1431 window is counted when it is active.  The optional argument
1432 @var{all-frames} has the same meaning as for @code{next-window}, see
1433 above.
1434 @end defun
1436 @cindex finding windows
1437   The following functions choose (but do not select) one of the windows
1438 on the screen, offering various criteria for the choice.
1440 @cindex least recently used window
1441 @defun get-lru-window &optional all-frames dedicated
1442 This function returns the window least recently ``used'' (that is,
1443 selected).  If any full-width windows are present, it only considers
1444 these.  The optional argument @var{all-frames} has the same meaning as
1445 in @code{next-window}.
1447 The selected window is returned if it is the only candidate.  A
1448 minibuffer window is never a candidate.  A dedicated window
1449 (@pxref{Dedicated Windows}) is never a candidate unless the optional
1450 argument @var{dedicated} is non-@code{nil}.
1451 @end defun
1453 @cindex largest window
1454 @defun get-largest-window &optional all-frames dedicated
1455 This function returns the window with the largest area (height times
1456 width).  If there are no side-by-side windows, then this is the window
1457 with the most lines.  A minibuffer window is never a candidate.  A
1458 dedicated window (@pxref{Dedicated Windows}) is never a candidate unless
1459 the optional argument @var{dedicated} is non-@code{nil}.
1461 If there are two candidate windows of the same size, this function
1462 prefers the one that comes first in the cyclic ordering of windows,
1463 starting from the selected window.
1465 The optional argument @var{all-frames} specifies which set of windows to
1466 consider as with @code{next-window}, see above.
1467 @end defun
1469 @cindex window that satisfies a predicate
1470 @cindex conditional selection of windows
1471 @defun get-window-with-predicate predicate &optional minibuf all-frames default
1472 This function returns a window satisfying @var{predicate}.  It cycles
1473 through all visible windows calling @var{predicate} on each one of them
1474 with that window as its argument.  The function returns the first window
1475 for which @var{predicate} returns a non-@code{nil} value; if that never
1476 happens, it returns @var{default} (which defaults to @code{nil}).
1478 The optional arguments @var{minibuf} and @var{all-frames} specify the
1479 set of windows to investigate.  See the description of
1480 @code{next-window} for details.
1481 @end defun
1483 @node Buffers and Windows
1484 @section Buffers and Windows
1485 @cindex examining windows
1486 @cindex windows, controlling precisely
1487 @cindex buffers, controlled in windows
1489 To find out which buffer is displayed in a given window the following
1490 function is used.
1492 @defun window-buffer &optional window
1493 This function returns the buffer that @var{window} is displaying.  The
1494 argument @var{window} can be any window and defaults to the selected
1495 one.  If @var{window} is an internal window, this function returns
1496 @code{nil}.
1497 @end defun
1499 Next we describe the basic, low-level function to associate a window
1500 with a buffer.  Higher-level functions like @code{display-buffer} try to
1501 obey a number of user customizations regulating which windows are
1502 supposed to display which buffers.  When writing an application,
1503 programmers should therefore carefully evaluate whether they really need
1504 the power of this function.
1506 @defun set-window-buffer window buffer-or-name &optional keep-margins
1507 This function makes @var{window} display @var{buffer-or-name} and
1508 returns @code{nil}.  The argument @var{window} has to denote a live
1509 window and defaults to the selected one.  The argument
1510 @var{buffer-or-name} must specify a buffer or the name of an existing
1511 buffer.
1513 Normally, displaying @var{buffer-or-name} in @var{window} resets the
1514 window's position, display margins, fringe widths, and scroll bar
1515 settings based on the local variables of the specified buffer.  However,
1516 if the optional argument @var{keep-margins} is non-@code{nil}, display
1517 margins and fringe widths of @var{window} remain unchanged.
1518 @xref{Fringes}.
1520 @code{set-window-buffer} is the fundamental primitive for changing which
1521 buffer is displayed in a window, and all ways of doing that call this
1522 function.  Neither the selected window nor the current buffer are
1523 changed by this function.
1525 @code{set-window-buffer} signals an error when @var{window} is
1526 @dfn{strongly} dedicated to its buffer (@pxref{Dedicated Windows}) and
1527 does not already display @var{buffer-or-name}.
1529 This function runs @code{window-scroll-functions} before running
1530 @code{window-configuration-change-hook}, see @ref{Window Hooks}.
1531 @end defun
1533 @defvar buffer-display-count
1534 This buffer-local variable records the number of times a buffer has been
1535 displayed in a window.  It is incremented each time
1536 @code{set-window-buffer} is called for the buffer.
1537 @end defvar
1539 @defvar buffer-display-time
1540 This variable records the time at which a buffer was last made visible
1541 in a window.  It is always local in each buffer; each time
1542 @code{set-window-buffer} is called, it sets this variable to
1543 @code{(current-time)} in the specified buffer (@pxref{Time of Day}).
1544 When a buffer is first created, @code{buffer-display-time} starts out
1545 with the value @code{nil}.
1546 @end defvar
1548 @defun get-buffer-window &optional buffer-or-name all-frames
1549 This function returns a window displaying @var{buffer-or-name}, or
1550 @code{nil} if there is none.  If there are several such windows, then
1551 the function returns the first one in the cyclic ordering of windows,
1552 starting from the selected window, @xref{Cyclic Window Ordering}.
1554 The argument @var{BUFFER-OR-NAME} may be a buffer or a buffer name and
1555 defaults to the current buffer.  The optional argument @var{all-frames}
1556 specifies which windows to consider:
1558 @itemize @bullet
1559 @item
1560 @code{nil} means consider windows on the selected frame.
1561 @item
1562 @code{t} means consider windows on all existing frames.
1563 @item
1564 @code{visible} means consider windows on all visible frames.
1565 @item
1566 0 means consider windows on all visible or iconified frames.
1567 @item
1568 A frame means consider windows on that frame only.
1569 @end itemize
1571 Observe that the behavior of @code{get-buffer-window} may differ from
1572 that of @code{next-window} (@pxref{Cyclic Window Ordering}) when
1573 @var{all-frames} equals @code{nil} or any value not listed here.
1574 Perhaps we will change @code{get-buffer-window} in the future to make it
1575 compatible with the other functions.
1576 @end defun
1578 @defun get-buffer-window-list &optional buffer-or-name minibuf all-frames
1579 This function returns a list of all windows currently displaying
1580 @var{buffer-or-name}.  The argument @var{buffer-or-name} may be a buffer
1581 or the name of an existing buffer and defaults to the current buffer.
1583 The two remaining arguments work like the same-named arguments of
1584 @code{next-window} (@pxref{Cyclic Window Ordering}); they are @emph{not}
1585 like the optional arguments of @code{get-buffer-window}.
1586 @end defun
1588 The following command removes a buffer from all windows showing it.
1590 @deffn Command replace-buffer-in-windows &optional buffer-or-name
1591 This function replaces @var{buffer-or-name} in all windows displaying it
1592 with some other buffer.  It uses @code{switch-to-prev-buffer}, see
1593 below, to choose that other buffer which is usually the last buffer
1594 displayed before @var{buffer-or-name} in the respective window.
1596 The argument @var{buffer-or-name} may be a buffer or the name of an
1597 existing buffer and defaults to the current buffer.
1599 If a window displaying @var{buffer-or-name} is dedicated
1600 (@pxref{Dedicated Windows}), and is not the only window on its frame,
1601 that window is deleted.  If that window is the only window on its frame
1602 and there are other frames left, the window's frame is deleted too.  If
1603 there are no other frames left, some other buffer is displayed in that
1604 window as explained above.
1606 This function returns @code{nil}.
1607 @end deffn
1609    When @code{replace-buffer-in-windows} has to show another buffer in a
1610 window, it tries to pick the buffer shown there before.  For this
1611 purpose each window remembers the buffers it has displayed earlier and
1612 the order in which these buffers have been removed from it.
1614 The list of @dfn{previous buffers} of a window is an association list
1615 where each entry specifies a buffer, the last start position of that
1616 buffer in the window (@pxref{Window Start and End}) and the last
1617 position of that buffer's point in the window (@pxref{Window Point}).
1618 This list is ordered by the times of the removal of the respective
1619 buffers from the window.  In particular, the first element of the list
1620 references the buffer removed most recently.  The function
1621 @code{set-window-buffer} pushes an entry for the old buffer of its
1622 window argument on that list before it shows its buffer argument in the
1623 window.
1625 The list of @dfn{next buffers} of a window is a list of buffers that
1626 have been recently re-shown by the function @code{switch-to-prev-buffer}
1627 and is used to avoid that that function switches to such a buffer again
1628 before showing other interesting buffers.
1630 The lists of previous and next buffers and the global buffer list
1631 (@pxref{The Buffer List}) allow to effectively display all buffers in a
1632 window while giving preference to the buffers previously shown in that
1633 window.  The commands used for this purpose are
1634 @code{switch-to-prev-buffer} and @code{switch-to-next-buffer} described
1635 below.
1637 The following functions directly operate on the lists of previous and
1638 next buffers.
1640 @defun window-prev-buffers &optional window
1641 This function returns an alist specifying the buffers previously shown
1642 in @var{window} together with their window start and point positions.
1643 The argument @var{window} must be a live window and defaults to the
1644 selected one.
1645 @end defun
1647 @defun set-window-prev-buffers window prev-buffers
1648 This function sets @var{window}'s previous buffers to the value of
1649 @var{prev-buffers}.  The argument @var{window} must be a live window and
1650 defaults to the selected one.  This function returns
1651 @var{prev-buffers}.
1653 If non-@code{nil}, @var{prev-buffers} must specify an alist of triples
1654 specifying a buffer and two markers for that buffer's start and point
1655 position in @var{window}.
1656 @end defun
1658 @defun window-next-buffers &optional window
1659 This function returns the list of buffers recently re-shown in
1660 @var{window}.  The argument @var{window} must be a live window and
1661 defaults to the selected one.
1662 @end defun
1664 @defun set-window-next-buffers window next-buffers
1665 This function sets @var{window}'s next buffers to @var{next-buffers}.
1666 @var{window} must be a live window and defaults to the selected one.
1667 This fucntion returns @var{next-buffers}.
1669 If non-@code{nil}, the argument @var{next-buffers} should specify a list
1670 of buffers that shall be preferably not shown by the command
1671 @code{switch-to-prev-buffer}, see below.
1672 @end defun
1674 The following command is used by @code{replace-buffer-in-windows},
1675 @code{bury-buffer} and @code{quit-restore-window} to show another buffer
1676 in a window.  It can be also used interactively to cycle through the
1677 list of all buffers in a window, preferably showing the buffers recently
1678 shown (but not buried or killed) in that window.
1680 @deffn Command switch-to-prev-buffer &optional window bury-or-kill
1681 This function displays the previous buffer in @var{window}.  The
1682 argument @var{window} must be a live window and defaults to the selected
1683 one.  If the optional argument @var{bury-or-kill} is non-@code{nil},
1684 this means that the buffer currently shown in @var{window} is about to
1685 be buried or killed and consequently shall not be switched to in future
1686 invocations of this command.
1688 The previous buffer is usually the buffer shown before the buffer
1689 currently shown in @var{window}.  However, a buffer that has been buried
1690 or killed or has been already shown by a recent invocation of
1691 @code{switch-to-prev-buffer} does not qualify as previous buffer.
1693 If repeated invocations of this command have already shown all buffers
1694 previously shown in @var{window}, further invocations will show buffers
1695 from the global buffer list starting with the buffer returned by
1696 @code{last-buffer} (@pxref{The Buffer List}).
1697 @end deffn
1699 The following command can be used to undo the effect of the last undone
1700 @code{switch-to-prev-buffer} command.
1702 @deffn Command switch-to-next-buffer &optional window
1703 This functions switches to the next buffer in @var{window} thus undoing
1704 the effect of the last @code{switch-to-prev-buffer} command in
1705 @var{window}.  The argument @var{window} must be a live window and
1706 defaults to the selected one.
1708 If there is no recent invocation of a @code{switch-to-prev-buffer} that
1709 can be undone, @code{switch-to-next-buffer} will try to show the first
1710 buffer from the global buffer list as returned by @code{other-buffer}
1711 (@pxref{The Buffer List}).
1712 @end deffn
1714    Together, @code{switch-to-prev-buffer} and
1715 @code{switch-to-next-buffer} permit to navigate the global buffer list
1716 much like @code{bury-buffer} and @code{unbury-buffer}.  In contrast with
1717 the latter, however, they may show a buffer even if it is already shown
1718 in another window.  Moreover, they try to restore the window specific
1719 start and point positions of buffers which should handle viewing one and
1720 the same buffer in multiple windows more easily.
1723 @node Switching Buffers
1724 @section Switching to a Buffer in Some Window
1725 @cindex switching to a buffer
1726 @cindex popping to a buffer
1728 In this section we describe convenient functions for switching to a
1729 specified buffer in some window.  These functions can also split an
1730 existing window in certain circumstances.  In any case, the window
1731 chosen becomes the selected window and the buffer current.
1733    Do not use the functions in this section in order to make a buffer
1734 current so that a Lisp program can access or modify it; they are too
1735 drastic for that purpose, since they change the display of buffers in
1736 windows, which would be gratuitous and surprise the user.  Instead, use
1737 @code{set-buffer} and @code{save-current-buffer} (@pxref{Current
1738 Buffer}), which designate buffers as current for programmed access
1739 without affecting the display of buffers in windows.
1741 @deffn Command switch-to-buffer buffer-or-name &optional norecord
1742 This function makes the buffer specified by @var{buffer-or-name} current
1743 and displays it in the selected window.  This means that a human can see
1744 the buffer and subsequent keyboard commands will apply to it.  Contrast
1745 this with @code{set-buffer}, which makes @var{buffer-or-name} the
1746 current buffer but does not display it in the selected window; see
1747 @ref{Current Buffer}.
1749 If called interactively, it prompts for the buffer name using the
1750 minibuffer.  The variable @code{confirm-nonexistent-file-or-buffer}
1751 determines whether to request confirmation before creating a new buffer.
1753 If @var{buffer-or-name} is @code{nil}, @code{switch-to-buffer} chooses a
1754 buffer using @code{other-buffer}.  If @var{buffer-or-name} is a string
1755 that does not identify an existing buffer, then a new buffer by that
1756 name is created.  The major mode for the new buffer is set according to
1757 the variable @code{major-mode}; see @ref{Auto Major Mode}.
1759 When the selected window is the minibuffer window or is strongly
1760 dedicated to its buffer (@pxref{Dedicated Windows}), this function calls
1761 @code{pop-to-buffer} (see below) to display the buffer in some other
1762 window.
1764 Normally, the specified buffer is put at the front of the buffer list
1765 (both the selected frame's buffer list and the frame-independent buffer
1766 list, see @ref{The Buffer List}).  This affects the operation of
1767 @code{other-buffer}.  However, if @var{norecord} is non-@code{nil}, this
1768 is not done.  Also, if @var{norecord} is non-@code{nil}, the window
1769 chosen for displaying the buffer is not automatically made the most
1770 recently selected one.
1772 @code{switch-to-buffer} is often used interactively, as the binding of
1773 @kbd{C-x b}.  It is also used frequently in programs.  It returns the
1774 buffer that it switched to.
1775 @end deffn
1777 The remaining functions described in this section are similar to
1778 @code{switch-to-buffer}, except for the described features.
1780 @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
1781 This command makes the buffer specified by @var{buffer-or-name} current
1782 and displays it in a window not currently selected, by using the
1783 function @code{pop-to-buffer} (see below).  It returns the buffer
1784 switched to.
1786 The currently selected window is absolutely never used to do the job.
1787 If the selected window already displays @var{buffer-or-name}, then it
1788 continues to do so, but another window is nonetheless found to display
1789 it in as well.
1791 The arguments @var{buffer-or-name} and @var{norecord} have the same
1792 meaning as for @code{switch-to-buffer}.
1793 @end deffn
1795 @deffn Command switch-to-buffer-other-frame buffer-or-name &optional norecord
1796 This command switches to buffer @var{buffer-or-name} in another frame.
1797 It returns the buffer switched to.
1799 The arguments @var{buffer-or-name} and @var{norecord} have the same
1800 meaning as for @code{switch-to-buffer}.
1801 @end deffn
1803 @deffn Command pop-to-buffer buffer-or-name &optional other-window norecord
1804 This command makes @var{buffer-or-name} the current buffer and switches
1805 to it in some window, preferably not the window previously selected.
1806 The ``popped-to'' window becomes the selected window.  Its frame is
1807 given the X server's focus, if possible; see @ref{Input Focus}.  The
1808 return value is the buffer that was switched to.
1810 If either of the variables @code{display-buffer-reuse-frames} or
1811 @code{pop-up-frames} is non-@code{nil}, @code{pop-to-buffer} looks for a
1812 window in any visible frame already displaying the buffer; if there is
1813 one, it selects and returns that window.  If no such window exists and
1814 @code{pop-up-frames} is non-@code{nil}, it creates a new frame and
1815 displays the buffer in it.  Otherwise, @code{pop-to-buffer} operates
1816 entirely within the selected frame.  (If the selected frame has just a
1817 minibuffer, @code{pop-to-buffer} operates within the most recently
1818 selected frame that was not just a minibuffer.)
1820 If the variable @code{pop-up-windows} is non-@code{nil}, windows may be
1821 split to create a new window that is different from the original window.
1822 For details, see @ref{Displaying Buffers}.
1824 If @var{other-window} is non-@code{nil}, @code{pop-to-buffer} finds or
1825 creates another window even if @var{buffer-or-name} is already visible
1826 in the selected window.  Thus @var{buffer-or-name} could end up
1827 displayed in two windows.  On the other hand, if @var{buffer-or-name} is
1828 already displayed in the selected window and @var{other-window} is
1829 @code{nil}, then the selected window is considered sufficient for
1830 displaying @var{buffer-or-name}, so that nothing needs to be done.
1832 All the variables that affect @code{display-buffer} affect
1833 @code{pop-to-buffer} as well.  @xref{Displaying Buffers}.
1835 The arguments @var{buffer-or-name} and @var{norecord} are handled as
1836 with @code{switch-to-buffer}.
1837 @end deffn
1839 @node Displaying Buffers
1840 @section Choosing a Window for Displaying a Buffer
1842 This section describes the basic facility that chooses a window to
1843 display a buffer in---@code{display-buffer}.  Higher-level commands and
1844 functions like @code{pop-to-buffer} (@pxref{Switching Buffers}) and
1845 @code{with-output-to-temp-buffer} (@pxref{Temporary Displays}), use this
1846 as a subroutine.  Here we describe how @code{display-buffer} works and
1847 and how to customize it.  We also describe a function which allows to
1848 ``quit'' the chosen window in a way that tries to restore the window to
1849 its state before the buffer was displayed.
1851 @deffn Command display-buffer buffer-or-name &optional not-this-window frame
1852 This command makes the buffer specified by @var{buffer-or-name} appear
1853 in some window, but it does not select that window and does not make the
1854 buffer current.  The argument @var{buffer-or-name} must be a buffer or
1855 the name of an existing buffer and defaults to the current buffer.
1857 When called interactively, it prompts for a buffer name in the
1858 minibuffer.  The variable `confirm-nonexistent-file-or-buffer'
1859 determines whether to request confirmation before creating a new buffer.
1860 The return value is the window chosen to display that buffer.
1862 If the optional argument @var{not-this-window} is non-@code{nil}, this
1863 means to display the specified buffer in a window other than the
1864 selected one, even if it is already displayed in the selected window.
1865 This can cause the buffer to appear in two windows at once.
1867 If the optional argument @var{frame} is non-@code{nil}, it specifies
1868 which frames to check when deciding whether the buffer is already
1869 displayed.  If the buffer is already displayed in some window on one of
1870 these frames, @code{display-buffer} will simply return that window.
1871 Here are the possible values of @var{frame}:
1873 @itemize @bullet
1874 @item @code{nil}
1875 means consider windows on the selected frame.
1876 (Actually, the last non-minibuffer frame.)
1877 @item @code{t}
1878 means consider windows on all frames.
1879 @item @code{visible}
1880 means consider windows on all visible frames.
1881 @item 0
1882 means consider windows on all visible or iconified frames.
1883 @item A frame
1884 means consider windows on that frame only.
1885 @end itemize
1886 @end deffn
1888 Precisely how @code{display-buffer} finds or creates a window depends on
1889 the variables described below.
1891 @defopt display-buffer-function
1892 This variable is the most flexible way to customize the behavior of
1893 @code{display-buffer}.  If it is non-@code{nil}, it should be a function
1894 that @code{display-buffer} calls to do the work.  The function is called
1895 with two arguments, the buffer to display and the @var{not-this-window}
1896 argument of @code{display-buffer}.  It should choose or create a window,
1897 display the specified buffer in it, and then return the window.
1898 @end defopt
1900 If @code{display-buffer-function} is @code{nil}, the selected window
1901 already displays @var{buffer-or-name}, and @var{not-this-window} is
1902 @code{nil}, @code{display-buffer} simply returns the selected window.
1903 Otherwise, it consults the two options described next in order to decide
1904 whether the buffer specified by @var{buffer-or-name} should appear in
1905 the selected window.
1907 @defopt same-window-buffer-names
1908 A list of buffer names for buffers that should be displayed in the
1909 selected window.  If the buffer's name is in this list, then
1910 @code{display-buffer} displays the buffer in the selected window.
1911 @end defopt
1913 @defopt same-window-regexps
1914 A list of regular expressions that specify buffers that should be
1915 displayed in the selected window.  If the buffer's name matches any of
1916 the regular expressions in this list, @code{display-buffer} displays the
1917 buffer in the selected window.
1918 @end defopt
1920 If the selected window is not considered suitable for displaying
1921 @var{buffer-or-name}, @code{display-buffer} will try to find another
1922 window already displaying @var{buffer-or-name}.  It will do so, however,
1923 if and only if either the variable @code{pop-up-frames} (see below) is
1924 non-@code{nil} or the following option has been activated.
1926 @defopt display-buffer-reuse-frames
1927 If this variable is non-@code{nil}, @code{display-buffer} searches
1928 visible and iconified frames for a window displaying
1929 @var{buffer-or-name}.  If there is such a window, @code{display-buffer}
1930 makes that window's frame visible, raises it if necessary, and returns
1931 the window.
1932 @end defopt
1934 If there is no such window or both @var{display-buffer-reuse-frames} and
1935 @var{pop-up-frames} are @code{nil}, @code{display-buffer} checks whether
1936 @var{buffer-or-name} should be displayed specially according to the
1937 options described next.
1939 @defopt special-display-buffer-names
1940 A list of buffer names identifying buffers that should be displayed
1941 specially.  If the name of @var{buffer-or-name} is in this list,
1942 @code{display-buffer} handles the buffer specially.  By default, special
1943 display means to give the buffer a dedicated frame.
1945 If an element is a list, instead of a string, then the @sc{car} of that
1946 list is the buffer name, and the rest of that list says how to create
1947 the frame.  There are two possibilities for the rest of that list (its
1948 @sc{cdr}): It can be an alist, specifying frame parameters, or it can
1949 contain a function and arguments to give to it.  (The function's first
1950 argument is always the buffer to be displayed; the arguments from the
1951 list come after that.)
1953 For example:
1955 @example
1956 (("myfile" (minibuffer) (menu-bar-lines . 0)))
1957 @end example
1959 @noindent
1960 specifies to display a buffer named @samp{myfile} in a dedicated frame
1961 with specified @code{minibuffer} and @code{menu-bar-lines} parameters.
1963 The list of frame parameters can also use the phony frame parameters
1964 @code{same-frame} and @code{same-window}.  If the specified frame
1965 parameters include @code{(same-window . @var{value})} and @var{value}
1966 is non-@code{nil}, that means to display the buffer in the current
1967 selected window.  Otherwise, if they include @code{(same-frame .
1968 @var{value})} and @var{value} is non-@code{nil}, that means to display
1969 the buffer in a new window in the currently selected frame.
1970 @end defopt
1972 @defopt special-display-regexps
1973 A list of regular expressions specifying buffers that should be
1974 displayed specially.  If the buffer's name matches any of the regular
1975 expressions in this list, @code{display-buffer} handles the buffer
1976 specially.  By default, special display means to give the buffer a
1977 dedicated frame.
1979 If an element is a list, instead of a string, then the @sc{car} of the
1980 list is the regular expression, and the rest of the list says how to
1981 create the frame.  See @code{special-display-buffer-names} above.
1982 @end defopt
1984 @defopt special-display-function
1985 This variable holds the function to call to display a buffer specially.
1986 It receives the buffer as an argument, and should return the window in
1987 which it is displayed.  The default value of this variable is
1988 @code{special-display-popup-frame}, see below.
1989 @end defopt
1991 @defun special-display-popup-frame buffer &optional args
1992 This function tries to make @var{buffer} visible in a frame of its own.
1993 If @var{buffer} is already displayed in some window, it makes that
1994 window's frame visible and raises it.  Otherwise, it creates a frame
1995 that is dedicated to @var{buffer}.  The return value is the window used
1996 to display @var{buffer}.
1998 If @var{args} is an alist, it specifies frame parameters for the new
1999 frame.  If @var{args} is a list whose @sc{car} is a symbol, then
2000 @code{(car @var{args})} is called as a function to actually create and
2001 set up the frame; it is called with @var{buffer} as first argument, and
2002 @code{(cdr @var{args})} as additional arguments.
2004 This function always uses an existing window displaying @var{buffer},
2005 whether or not it is in a frame of its own; but if you set up the above
2006 variables in your init file, before @var{buffer} was created, then
2007 presumably the window was previously made by this function.
2008 @end defun
2010 @defopt special-display-frame-alist
2011 @anchor{Definition of special-display-frame-alist}
2012 This variable holds frame parameters for
2013 @code{special-display-popup-frame} to use when it creates a frame.
2014 @end defopt
2016 If @var{buffer-or-name} shall not be displayed specially,
2017 @code{display-buffer} will try to pop up a new frame provided the option
2018 described next permits that.
2020 @defopt pop-up-frames
2021 This variable specifies whether @code{display-buffer} should make new
2022 frames.  If it is non-@code{nil}, @code{display-buffer} tries to locate
2023 a window displaying @var{buffer-or-name} on any visible or iconified
2024 frame, see above.  If no such window can be found, it makes a new frame,
2025 unless the variable's value is @code{graphic-only} and the selected
2026 frame is not on a graphic display.  @xref{Frames}, for more information.
2027 @end defopt
2029 @defopt pop-up-frame-function
2030 This variable specifies how to make a new frame if @code{pop-up-frames}
2031 is non-@code{nil}.
2033 The value of this variable must be a function of no arguments.  When
2034 @code{display-buffer} makes a new frame, it does so by calling that
2035 function, which should return a frame.  The default value of this
2036 variable is a function that creates a frame using the parameters
2037 specified by @code{pop-up-frame-alist} described next.
2038 @end defopt
2040 @defopt pop-up-frame-alist
2041 This variable holds an alist specifying frame parameters used by the
2042 default value of @code{pop-up-frame-function} for making new frames.
2043 @xref{Frame Parameters}, for more information about frame parameters.
2044 @end defopt
2046 If popping up a new frame is not possible, @code{display-buffer} will
2047 try to split an existing window.
2049 @defopt pop-up-windows
2050 If this variable is non-@code{nil}, @code{display-buffer} is allowed to
2051 make a new window on the selected frame.  (If the selected frame is a
2052 minibuffer-only frame, @code{display-buffer} tries to make a new window
2053 on another frame instead.)  If this variable is a non-empty list, that
2054 list has to specify the windows @code{display-buffer} will consider for
2055 splitting.  The following entries are supported.
2057 @table @code
2058 @item largest
2059 The largest window, that is the window returned by
2060 @code{get-largest-window}, see @ref{Cyclic Window Ordering}.
2062 @item lru
2063 The least recently used window as returned by @code{get-lru-window}, see
2064 @ref{Cyclic Window Ordering}.
2066 @item selected
2067 The selected window on that frame as returned by
2068 @code{frame-selected-window}, see @ref{Selecting Windows}.
2070 @item root
2071 The frame's root window as returned by @code{frame-root-window}, see
2072 @ref{Frames and Windows}.
2073 @end table
2075  The default value @code{t} stands for the list `(largest lru)'.  This
2076 means that @code{display-buffer} will first try to split the largest
2077 window and, if that fails, the least recently used window.  If this
2078 variable is @code{nil}, @code{display-buffer} does not split any window.
2079 @end defopt
2081 @defopt split-window-preferred-function
2082 This variable must specify a function with one argument, which is a
2083 window.  The @code{display-buffer} routines will call this function with
2084 one or more candidate windows when they look for a window to split.  The
2085 function is expected to split that window and return the new window.  If
2086 the function returns @code{nil}, this means that the argument window
2087 cannot be split.
2089 The default value of @code{split-window-preferred-function} is the
2090 function @code{split-window-sensibly} described below.  If you customize
2091 this option, bear in mind that @code{display-buffer} may call the
2092 specified function once for each element of @code{pop-up-windows}, see
2093 above.
2095 This option affects the behavior of @code{display-buffer} only.  Other
2096 functions like @code{split-window} and its relatives are @emph{not}
2097 affected by it.
2098 @end defopt
2100 @defun split-window-sensibly window
2101 This function takes a window as argument and tries to split that window
2102 in a suitable way.  The two variables described next are useful for
2103 tuning the behavior of this function.
2104 @end defun
2106 @defopt split-height-threshold
2107 This variable specifies whether @code{split-window-sensibly} may split
2108 windows vertically.  If it is an integer, @code{split-window-sensibly}
2109 tries to split a window vertically only if it has at least this many
2110 lines.  If the window has less lines, splitting fails, or the value of
2111 this variable is @code{nil}, @code{split-window-sensibly} will try to
2112 split the window horizontally, subject to restrictions of
2113 @code{split-width-threshold} (see below).
2115 If splitting horizontally fails too, and the window is the only window
2116 on its frame, @code{split-window-sensibly} will try to split that window
2117 vertically disregarding the value of this variable.  If this fails as
2118 well, @code{split-window-sensibly} returns @code{nil}.
2120 @code{split-window-sensibly} does not split a window vertically when
2121 that window's height is fixed (@pxref{Window Sizes}).  Also, it splits a
2122 window vertically only if the space taken up by that window can
2123 accommodate two windows one above the other that are both at least
2124 @code{window-min-height} lines tall.
2126 Moreover, if the window that shall be split has a mode line,
2127 @code{split-window-sensibly} does not split the window unless the new
2128 window can accomodate a mode line too.  However, if the option
2129 @code{window-splits} (@pxref{Splitting Windows}) equals @code{resize},
2130 @code{split-window-sensibly} may split a window provided the resulting
2131 windows can be embedded in a combination of windows.
2132 @end defopt
2134 @defopt split-width-threshold
2135 This variable specifies whether @code{split-window-sensibly} may split
2136 windows horizontally.  If it is an integer, @code{split-window-sensibly}
2137 tries to split a window horizontally only if it has at least this many
2138 columns.  If it is @code{nil}, @code{split-window-sensibly} will not
2139 split the window horizontally.  (It still might split the window
2140 vertically, though, see above.)
2142 @code{split-window-sensibly} does not split a window horizontally if
2143 that window's width is fixed (@pxref{Window Sizes}).  Also, it splits a
2144 window horizontally only if the space that window takes up can
2145 accommodate two windows side by side that are both at least
2146 @code{window-min-width} columns wide.  Note, however, that if the option
2147 @code{window-splits} (@pxref{Splitting Windows}) equals @code{resize},
2148 @code{split-window-sensibly} will split the window provided it can embed
2149 the emanating windows in a window combination.
2150 @end defopt
2152 If all options described so far fail to produce a suitable window,
2153 @code{display-buffer} tries to reuse an existing window.  As a last
2154 resort, it will try to display @var{buffer-or-name} on a separate frame.
2155 In that case, the value of @code{pop-up-frames} is disregarded.
2157 @defopt even-window-heights
2158 This variable specifies whether @code{display-buffer} should even out
2159 window heights if the buffer gets displayed in an existing window, above
2160 or beneath another window.  If @code{even-window-heights} is
2161 non-@code{nil}, the default, window heights will be evened out.  If
2162 either of the involved window has fixed height (@pxref{Window Sizes}) or
2163 @code{even-window-heights} is @code{nil}, window heights are left alone.
2164 @end defopt
2166 The command described next allows to quit the window chosen by
2167 @code{display-buffer} and restore the previous state without undoing
2168 changes to the window configuration that happend @emph{after}
2169 @code{display-buffer} was called.  A more drastic solution is to save
2170 the window configuration before calling @code{display-buffer} and
2171 eventually restoring the saved configuration, @ref{Window
2172 Configurations}.  That solution sometimes has the undesirable
2173 side-effect that all changes that happened after the configuration was
2174 saved are undone too.
2176 @deffn Command quit-restore-window &optional window kill
2177 This command ``quits'' @var{window} restoring its previous contents if
2178 possible.  The argument @var{window} must be a live window and defaults
2179 to the selected one.  This function always returns @code{nil}.
2181 According to information stored in @var{window}'s @code{quit-restore}
2182 window parameter (@pxref{Window Parameters}) this function performs one
2183 of the following actions.
2185 @itemize @bullet 
2186 @item
2187 Delete @var{window} and its frame.  This action is useful when
2188 @var{window} was created on a standalone frame and there are other
2189 frames left.
2191 @item
2192 Delete @var{window}.  This action is usually taken when @var{window} was
2193 obtained by splitting some existing window.
2195 @item
2196 Restore the buffer previously displayed in @var{window}.  This action
2197 is taken when @var{window} was temporarily reused for displaying some
2198 other buffer.
2200 @item
2201 Make @var{window} display some other buffer.  This action is usually
2202 taken when the three preceding ones are not applicable.
2203 @end itemize
2205 If its value was non-@code{nil}, this function resets @var{window}'s
2206 @code{quit-restore} parameter to @code{nil}.
2208 If the optional argument @var{kill} is non-@code{nil}, this means in
2209 addition kill @var{window}'s buffer.  If @var{kill} is @code{nil}, this
2210 simply puts @var{window}'s buffer at the end of the buffer list.
2211 Interactively, @var{kill} is the prefix argument.
2212 @end deffn
2214 @node Dedicated Windows
2215 @section Dedicated Windows
2216 @cindex dedicated window
2218 Functions for displaying a buffer can be told to not use specific
2219 windows by marking these windows as @dfn{dedicated} to their buffers.
2220 The function @code{display-buffer} (@pxref{Displaying Buffers}) never
2221 uses a dedicated window for displaying another buffer in it.  The
2222 functions @code{get-lru-window} and @code{get-largest-window}
2223 (@pxref{Selecting Windows}) do not consider dedicated windows as
2224 candidates when their @var{dedicated} argument is non-@code{nil}.  The
2225 behavior of @code{set-window-buffer} (@pxref{Buffers and Windows}) with
2226 respect to dedicated windows is slightly different, see below.
2228 When @code{delete-windows-on} (@pxref{Deleting Windows}) wants to delete
2229 a dedicated window and that window is the only window on its frame, it
2230 deletes the window's frame too, provided there are other frames left.
2231 The function @code{replace-buffer-in-windows} (@pxref{Displaying
2232 Buffers}) tries to delete all dedicated windows showing its buffer
2233 argument.  When such a window is the only window on its frame, that
2234 frame is deleted, provided there are other frames left.  If there are no
2235 more frames left, some other buffer is displayed in the window, and the
2236 window is marked as non-dedicated.
2238 When you kill a buffer (@pxref{Killing Buffers}) displayed in a
2239 dedicated window, any such window usually gets deleted too, since
2240 @code{kill-buffer} calls @code{replace-buffer-in-windows} for cleaning
2241 up windows.  Burying a buffer (@pxref{The Buffer List}) deletes the
2242 selected window if it is dedicated to that buffer.  If, however, that
2243 window is the only window on its frame, @code{bury-buffer} displays
2244 another buffer in it and iconifies the frame.
2246 @defun window-dedicated-p &optional window
2247 This function returns non-@code{nil} if @var{window} is dedicated to its
2248 buffer and @code{nil} otherwise.  More precisely, the return value is
2249 the value assigned by the last call of @code{set-window-dedicated-p} for
2250 @var{window} or @code{nil} if that function was never called with
2251 @var{window} as its argument.  The default for @var{window} is the
2252 selected window.
2253 @end defun
2255 @defun set-window-dedicated-p window flag
2256 This function marks @var{window} as dedicated to its buffer if
2257 @var{flag} is non-@code{nil}, and non-dedicated otherwise.
2259 As a special case, if @var{flag} is @code{t}, @var{window} becomes
2260 @dfn{strongly} dedicated to its buffer.  @code{set-window-buffer}
2261 signals an error when the window it acts upon is strongly dedicated to
2262 its buffer and does not already display the buffer it is asked to
2263 display.  Other functions do not treat @code{t} differently from any
2264 non-@code{nil} value.
2265 @end defun
2267 @node Window Point
2268 @section Windows and Point
2269 @cindex window position
2270 @cindex window point
2271 @cindex position in window
2272 @cindex point in window
2274 Each window has its own value of point (@pxref{Point}), independent of
2275 the value of point in other windows displaying the same buffer.  This
2276 makes it useful to have multiple windows showing one buffer.
2278 @itemize @bullet
2279 @item
2280 The window point is established when a window is first created; it is
2281 initialized from the buffer's point, or from the window point of another
2282 window opened on the buffer if such a window exists.
2284 @item
2285 Selecting a window sets the value of point in its buffer from the
2286 window's value of point.  Conversely, deselecting a window sets the
2287 window's value of point from that of the buffer.  Thus, when you switch
2288 between windows that display a given buffer, the point value for the
2289 selected window is in effect in the buffer, while the point values for
2290 the other windows are stored in those windows.
2292 @item
2293 As long as the selected window displays the current buffer, the window's
2294 point and the buffer's point always move together; they remain equal.
2295 @end itemize
2297 @cindex cursor
2298    As far as the user is concerned, point is where the cursor is, and
2299 when the user switches to another buffer, the cursor jumps to the
2300 position of point in that buffer.
2302 @defun window-point &optional window
2303 This function returns the current position of point in @var{window}.
2304 For a nonselected window, this is the value point would have (in that
2305 window's buffer) if that window were selected.  The default for
2306 @var{window} is the selected window.
2308 When @var{window} is the selected window and its buffer is also the
2309 current buffer, the value returned is the same as point in that buffer.
2310 Strictly speaking, it would be more correct to return the ``top-level''
2311 value of point, outside of any @code{save-excursion} forms.  But that
2312 value is hard to find.
2313 @end defun
2315 @defun set-window-point window position
2316 This function positions point in @var{window} at position
2317 @var{position} in @var{window}'s buffer.  It returns @var{position}.
2319 If @var{window} is selected, and its buffer is current,
2320 this simply does @code{goto-char}.
2321 @end defun
2323 @defvar window-point-insertion-type
2324 This variable specifies the marker insertion type (@pxref{Marker
2325 Insertion Types}) of @code{window-point}.  The default is @code{nil},
2326 so @code{window-point} will stay behind text inserted there.
2327 @end defvar
2329 @node Window Start and End
2330 @section The Window Start and End Positions
2331 @cindex window start position
2333   Each window maintains a marker used to keep track of a buffer position
2334 that specifies where in the buffer display should start.  This position
2335 is called the @dfn{display-start} position of the window (or just the
2336 @dfn{start}).  The character after this position is the one that appears
2337 at the upper left corner of the window.  It is usually, but not
2338 inevitably, at the beginning of a text line.
2340   After switching windows or buffers, and in some other cases, if the
2341 window start is in the middle of a line, Emacs adjusts the window
2342 start to the start of a line.  This prevents certain operations from
2343 leaving the window start at a meaningless point within a line.  This
2344 feature may interfere with testing some Lisp code by executing it
2345 using the commands of Lisp mode, because they trigger this
2346 readjustment.  To test such code, put it into a command and bind the
2347 command to a key.
2349 @defun window-start &optional window
2350 @cindex window top line
2351 This function returns the display-start position of window
2352 @var{window}.  If @var{window} is @code{nil}, the selected window is
2353 used.  For example,
2355 @example
2356 @group
2357 (window-start)
2358      @result{} 7058
2359 @end group
2360 @end example
2362 When you create a window, or display a different buffer in it, the
2363 display-start position is set to a display-start position recently used
2364 for the same buffer, or to @code{point-min} if the buffer doesn't have
2365 any.
2367 Redisplay updates the window-start position (if you have not specified
2368 it explicitly since the previous redisplay)---to make sure point appears
2369 on the screen.  Nothing except redisplay automatically changes the
2370 window-start position; if you move point, do not expect the window-start
2371 position to change in response until after the next redisplay.
2373 For a realistic example of using @code{window-start}, see the
2374 description of @code{count-lines}.  @xref{Definition of count-lines}.
2375 @end defun
2377 @cindex window end position
2378 @defun window-end &optional window update
2379 This function returns the position where display of its buffer ends in
2380 @var{window}.  The default for @var{window} is the selected window.
2382 Simply changing the buffer text or moving point does not update the
2383 value that @code{window-end} returns.  The value is updated only when
2384 Emacs redisplays and redisplay completes without being preempted.
2386 If the last redisplay of @var{window} was preempted, and did not finish,
2387 Emacs does not know the position of the end of display in that window.
2388 In that case, this function returns @code{nil}.
2390 If @var{update} is non-@code{nil}, @code{window-end} always returns an
2391 up-to-date value for where display ends, based on the current
2392 @code{window-start} value.  If a previously saved value of that position
2393 is still valid, @code{window-end} returns that value; otherwise it
2394 computes the correct value by scanning the buffer text.
2396 Even if @var{update} is non-@code{nil}, @code{window-end} does not
2397 attempt to scroll the display if point has moved off the screen, the
2398 way real redisplay would do.  It does not alter the
2399 @code{window-start} value.  In effect, it reports where the displayed
2400 text will end if scrolling is not required.
2401 @end defun
2403 @defun set-window-start window position &optional noforce
2404 This function sets the display-start position of @var{window} to
2405 @var{position} in @var{window}'s buffer.  It returns @var{position}.
2407 The display routines insist that the position of point be visible when a
2408 buffer is displayed.  Normally, they change the display-start position
2409 (that is, scroll the window) whenever necessary to make point visible.
2410 However, if you specify the start position with this function using
2411 @code{nil} for @var{noforce}, it means you want display to start at
2412 @var{position} even if that would put the location of point off the
2413 screen.  If this does place point off screen, the display routines move
2414 point to the left margin on the middle line in the window.
2416 For example, if point @w{is 1} and you set the start of the window
2417 @w{to 37}, the start of the next line, point will be ``above'' the top
2418 of the window.  The display routines will automatically move point if
2419 it is still 1 when redisplay occurs.  Here is an example:
2421 @example
2422 @group
2423 ;; @r{Here is what @samp{foo} looks like before executing}
2424 ;;   @r{the @code{set-window-start} expression.}
2425 @end group
2427 @group
2428 ---------- Buffer: foo ----------
2429 @point{}This is the contents of buffer foo.
2435 ---------- Buffer: foo ----------
2436 @end group
2438 @group
2439 (set-window-start
2440  (selected-window)
2441  (save-excursion
2442    (goto-char 1)
2443    (forward-line 1)
2444    (point)))
2445 @result{} 37
2446 @end group
2448 @group
2449 ;; @r{Here is what @samp{foo} looks like after executing}
2450 ;;   @r{the @code{set-window-start} expression.}
2451 ---------- Buffer: foo ----------
2454 @point{}4
2457 ---------- Buffer: foo ----------
2458 @end group
2459 @end example
2461 If @var{noforce} is non-@code{nil}, and @var{position} would place point
2462 off screen at the next redisplay, then redisplay computes a new window-start
2463 position that works well with point, and thus @var{position} is not used.
2464 @end defun
2466 @defun pos-visible-in-window-p &optional position window partially
2467 This function returns non-@code{nil} if @var{position} is within the
2468 range of text currently visible on the screen in @var{window}.  It
2469 returns @code{nil} if @var{position} is scrolled vertically out of view.
2470 Locations that are partially obscured are not considered visible unless
2471 @var{partially} is non-@code{nil}.  The argument @var{position} defaults
2472 to the current position of point in @var{window}; @var{window}, to the
2473 selected window.  If @var{position} is @code{t}, that means to check the
2474 last visible position in @var{window}.
2476 The @code{pos-visible-in-window-p} function considers only vertical
2477 scrolling.  If @var{position} is out of view only because @var{window}
2478 has been scrolled horizontally, @code{pos-visible-in-window-p} returns
2479 non-@code{nil} anyway.  @xref{Horizontal Scrolling}.
2481 If @var{position} is visible, @code{pos-visible-in-window-p} returns
2482 @code{t} if @var{partially} is @code{nil}; if @var{partially} is
2483 non-@code{nil}, and the character following @var{position} is fully
2484 visible, it returns a list of the form @code{(@var{x} @var{y})}, where
2485 @var{x} and @var{y} are the pixel coordinates relative to the top left
2486 corner of the window; otherwise it returns an extended list of the form
2487 @code{(@var{x} @var{y} @var{rtop} @var{rbot} @var{rowh} @var{vpos})},
2488 where @var{rtop} and @var{rbot} specify the number of off-window pixels
2489 at the top and bottom of the row at @var{position}, @var{rowh} specifies
2490 the visible height of that row, and @var{vpos} specifies the vertical
2491 position (zero-based row number) of that row.
2493 Here is an example:
2495 @example
2496 @group
2497 ;; @r{If point is off the screen now, recenter it now.}
2498 (or (pos-visible-in-window-p
2499      (point) (selected-window))
2500     (recenter 0))
2501 @end group
2502 @end example
2503 @end defun
2505 @defun window-line-height &optional line window
2506 This function returns the height of text line @var{line} in
2507 @var{window}.  If @var{line} is one of @code{header-line} or
2508 @code{mode-line}, @code{window-line-height} returns information about
2509 the corresponding line of the window.  Otherwise, @var{line} is a text
2510 line number starting from 0.  A negative number counts from the end of
2511 the window.  The default for @var{line} is the current line in
2512 @var{window}; the default for @var{window} is the selected window.
2514 If the display is not up to date, @code{window-line-height} returns
2515 @code{nil}.  In that case, @code{pos-visible-in-window-p} may be used
2516 to obtain related information.
2518 If there is no line corresponding to the specified @var{line},
2519 @code{window-line-height} returns @code{nil}.  Otherwise, it returns
2520 a list @code{(@var{height} @var{vpos} @var{ypos} @var{offbot})},
2521 where @var{height} is the height in pixels of the visible part of the
2522 line, @var{vpos} and @var{ypos} are the vertical position in lines and
2523 pixels of the line relative to the top of the first text line, and
2524 @var{offbot} is the number of off-window pixels at the bottom of the
2525 text line.  If there are off-window pixels at the top of the (first)
2526 text line, @var{ypos} is negative.
2527 @end defun
2529 @node Textual Scrolling
2530 @section Textual Scrolling
2531 @cindex textual scrolling
2532 @cindex scrolling textually
2534   @dfn{Textual scrolling} means moving the text up or down through a
2535 window.  It works by changing the value of the window's display-start
2536 location.  It may also change the value of @code{window-point} to keep
2537 point on the screen.
2539   Textual scrolling was formerly called ``vertical scrolling,'' but we
2540 changed its name to distinguish it from the new vertical fractional
2541 scrolling feature (@pxref{Vertical Scrolling}).
2543   In the commands @code{scroll-up} and @code{scroll-down}, the directions
2544 ``up'' and ``down'' refer to the motion of the text in the buffer at which
2545 you are looking through the window.  Imagine that the text is
2546 written on a long roll of paper and that the scrolling commands move the
2547 paper up and down.  Thus, if you are looking at text in the middle of a
2548 buffer and repeatedly call @code{scroll-down}, you will eventually see
2549 the beginning of the buffer.
2551   Some people have urged that the opposite convention be used: they
2552 imagine that the window moves over text that remains in place.  Then
2553 ``down'' commands would take you to the end of the buffer.  This view is
2554 more consistent with the actual relationship between windows and the
2555 text in the buffer, but it is less like what the user sees.  The
2556 position of a window on the terminal does not move, and short scrolling
2557 commands clearly move the text up or down on the screen.  We have chosen
2558 names that fit the user's point of view.
2560   The textual scrolling functions (aside from
2561 @code{scroll-other-window}) have unpredictable results if the current
2562 buffer is different from the buffer that is displayed in the selected
2563 window.  @xref{Current Buffer}.
2565   If the window contains a row which is taller than the height of the
2566 window (for example in the presence of a large image), the scroll
2567 functions will adjust the window's vertical scroll position to scroll
2568 the partially visible row.  To disable this feature, Lisp code may bind
2569 the variable @code{auto-window-vscroll} to @code{nil} (@pxref{Vertical
2570 Scrolling}).
2572 @deffn Command scroll-up &optional count
2573 This function scrolls the text in the selected window upward
2574 @var{count} lines.  If @var{count} is negative, scrolling is actually
2575 downward.
2577 If @var{count} is @code{nil} (or omitted), then the length of scroll
2578 is @code{next-screen-context-lines} lines less than the usable height of
2579 the window (not counting its mode line).
2581 @code{scroll-up} returns @code{nil}, unless it gets an error
2582 because it can't scroll any further.
2583 @end deffn
2585 @deffn Command scroll-down &optional count
2586 This function scrolls the text in the selected window downward
2587 @var{count} lines.  If @var{count} is negative, scrolling is actually
2588 upward.
2590 If @var{count} is omitted or @code{nil}, then the length of the scroll
2591 is @code{next-screen-context-lines} lines less than the usable height of
2592 the window (not counting its mode line).
2594 @code{scroll-down} returns @code{nil}, unless it gets an error because
2595 it can't scroll any further.
2596 @end deffn
2598 @deffn Command scroll-other-window &optional count
2599 This function scrolls the text in another window upward @var{count}
2600 lines.  Negative values of @var{count}, or @code{nil}, are handled
2601 as in @code{scroll-up}.
2603 You can specify which buffer to scroll by setting the variable
2604 @code{other-window-scroll-buffer} to a buffer.  If that buffer isn't
2605 already displayed, @code{scroll-other-window} displays it in some
2606 window.
2608 When the selected window is the minibuffer, the next window is normally
2609 the one at the top left corner.  You can specify a different window to
2610 scroll, when the minibuffer is selected, by setting the variable
2611 @code{minibuffer-scroll-window}.  This variable has no effect when any
2612 other window is selected.  When it is non-@code{nil} and the
2613 minibuffer is selected, it takes precedence over
2614 @code{other-window-scroll-buffer}.  @xref{Definition of
2615 minibuffer-scroll-window}.
2617 When the minibuffer is active, it is the next window if the selected
2618 window is the one at the bottom right corner.  In this case,
2619 @code{scroll-other-window} attempts to scroll the minibuffer.  If the
2620 minibuffer contains just one line, it has nowhere to scroll to, so the
2621 line reappears after the echo area momentarily displays the message
2622 @samp{Beginning of buffer}.
2623 @end deffn
2625 @c Emacs 19 feature
2626 @defvar other-window-scroll-buffer
2627 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
2628 which buffer's window to scroll.
2629 @end defvar
2631 @defopt scroll-margin
2632 This option specifies the size of the scroll margin---a minimum number
2633 of lines between point and the top or bottom of a window.  Whenever
2634 point gets within this many lines of the top or bottom of the window,
2635 redisplay scrolls the text automatically (if possible) to move point
2636 out of the margin, closer to the center of the window.
2637 @end defopt
2639 @defopt scroll-conservatively
2640 This variable controls how scrolling is done automatically when point
2641 moves off the screen (or into the scroll margin).  If the value is a
2642 positive integer @var{n}, then redisplay scrolls the text up to
2643 @var{n} lines in either direction, if that will bring point back into
2644 proper view.  This behavior is called @dfn{conservative scrolling}.
2645 Otherwise, scrolling happens in the usual way, under the control of
2646 other variables such as @code{scroll-up-aggressively} and
2647 @code{scroll-down-aggressively}.
2649 The default value is zero, which means that conservative scrolling
2650 never happens.
2651 @end defopt
2653 @defopt scroll-down-aggressively
2654 The value of this variable should be either @code{nil} or a fraction
2655 @var{f} between 0 and 1.  If it is a fraction, that specifies where on
2656 the screen to put point when scrolling down.  More precisely, when a
2657 window scrolls down because point is above the window start, the new
2658 start position is chosen to put point @var{f} part of the window
2659 height from the top.  The larger @var{f}, the more aggressive the
2660 scrolling.
2662 A value of @code{nil} is equivalent to .5, since its effect is to center
2663 point.  This variable automatically becomes buffer-local when set in any
2664 fashion.
2665 @end defopt
2667 @defopt scroll-up-aggressively
2668 Likewise, for scrolling up.  The value, @var{f}, specifies how far
2669 point should be placed from the bottom of the window; thus, as with
2670 @code{scroll-up-aggressively}, a larger value scrolls more aggressively.
2671 @end defopt
2673 @defopt scroll-step
2674 This variable is an older variant of @code{scroll-conservatively}.  The
2675 difference is that it if its value is @var{n}, that permits scrolling
2676 only by precisely @var{n} lines, not a smaller number.  This feature
2677 does not work with @code{scroll-margin}.  The default value is zero.
2678 @end defopt
2680 @defopt scroll-preserve-screen-position
2681 If this option is @code{t}, scrolling which would move the current
2682 point position out of the window chooses the new position of point
2683 so that the vertical position of the cursor is unchanged, if possible.
2685 If it is non-@code{nil} and not @code{t}, then the scrolling functions
2686 always preserve the vertical position of point, if possible.
2687 @end defopt
2689 @defopt next-screen-context-lines
2690 The value of this variable is the number of lines of continuity to
2691 retain when scrolling by full screens.  For example, @code{scroll-up}
2692 with an argument of @code{nil} scrolls so that this many lines at the
2693 bottom of the window appear instead at the top.  The default value is
2694 @code{2}.
2695 @end defopt
2697 @deffn Command recenter &optional count
2698 @cindex centering point
2699 This function scrolls the text in the selected window so that point is
2700 displayed at a specified vertical position within the window.  It does
2701 not ``move point'' with respect to the text.
2703 If @var{count} is a nonnegative number, that puts the line containing
2704 point @var{count} lines down from the top of the window.  If
2705 @var{count} is a negative number, then it counts upward from the
2706 bottom of the window, so that @minus{}1 stands for the last usable
2707 line in the window.  If @var{count} is a non-@code{nil} list, then it
2708 stands for the line in the middle of the window.
2710 If @var{count} is @code{nil}, @code{recenter} puts the line containing
2711 point in the middle of the window, then clears and redisplays the entire
2712 selected frame.
2714 When @code{recenter} is called interactively, @var{count} is the raw
2715 prefix argument.  Thus, typing @kbd{C-u} as the prefix sets the
2716 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
2717 @var{count} to 4, which positions the current line four lines from the
2718 top.
2720 With an argument of zero, @code{recenter} positions the current line at
2721 the top of the window.  This action is so handy that some people make a
2722 separate key binding to do this.  For example,
2724 @example
2725 @group
2726 (defun line-to-top-of-window ()
2727   "Scroll current line to top of window.
2728 Replaces three keystroke sequence C-u 0 C-l."
2729   (interactive)
2730   (recenter 0))
2732 (global-set-key [kp-multiply] 'line-to-top-of-window)
2733 @end group
2734 @end example
2735 @end deffn
2737 @node Vertical Scrolling
2738 @section Vertical Fractional Scrolling
2739 @cindex vertical fractional scrolling
2740 @cindex vertical scroll position
2742    @dfn{Vertical fractional scrolling} means shifting text in a window
2743 up or down by a specified multiple or fraction of a line.  Each window
2744 has a @dfn{vertical scroll position}, which is a number, never less than
2745 zero.  It specifies how far to raise the contents of the window.
2746 Raising the window contents generally makes all or part of some lines
2747 disappear off the top, and all or part of some other lines appear at the
2748 bottom.  The usual value is zero.
2750    The vertical scroll position is measured in units of the normal line
2751 height, which is the height of the default font.  Thus, if the value is
2752 .5, that means the window contents are scrolled up half the normal line
2753 height.  If it is 3.3, that means the window contents are scrolled up
2754 somewhat over three times the normal line height.
2756    What fraction of a line the vertical scrolling covers, or how many
2757 lines, depends on what the lines contain.  A value of .5 could scroll a
2758 line whose height is very short off the screen, while a value of 3.3
2759 could scroll just part of the way through a tall line or an image.
2761 @defun window-vscroll &optional window pixels-p
2762 This function returns the current vertical scroll position of
2763 @var{window}.  The default for @var{window} is the selected window.
2764 If @var{pixels-p} is non-@code{nil}, the return value is measured in
2765 pixels, rather than in units of the normal line height.
2767 @example
2768 @group
2769 (window-vscroll)
2770      @result{} 0
2771 @end group
2772 @end example
2773 @end defun
2775 @defun set-window-vscroll window lines &optional pixels-p
2776 This function sets @var{window}'s vertical scroll position to
2777 @var{lines}.  If @var{window} is @code{nil}, the selected window is
2778 used.  The argument @var{lines} should be zero or positive; if not, it
2779 is taken as zero.
2782 The actual vertical scroll position must always correspond
2783 to an integral number of pixels, so the value you specify
2784 is rounded accordingly.
2786 The return value is the result of this rounding.
2788 @example
2789 @group
2790 (set-window-vscroll (selected-window) 1.2)
2791      @result{} 1.13
2792 @end group
2793 @end example
2795 If @var{pixels-p} is non-@code{nil}, @var{lines} specifies a number of
2796 pixels.  In this case, the return value is @var{lines}.
2797 @end defun
2799 @defvar auto-window-vscroll
2800 If this variable is non-@code{nil}, the line-move, scroll-up, and
2801 scroll-down functions will automatically modify the vertical scroll
2802 position to scroll through display rows that are taller than the height
2803 of the window, for example in the presence of large images.
2804 @end defvar
2806 @node Horizontal Scrolling
2807 @section Horizontal Scrolling
2808 @cindex horizontal scrolling
2810   @dfn{Horizontal scrolling} means shifting the image in the window left
2811 or right by a specified multiple of the normal character width.  Each
2812 window has a @dfn{horizontal scroll position}, which is a number, never
2813 less than zero.  It specifies how far to shift the contents left.
2814 Shifting the window contents left generally makes all or part of some
2815 characters disappear off the left, and all or part of some other
2816 characters appear at the right.  The usual value is zero.
2818   The horizontal scroll position is measured in units of the normal
2819 character width, which is the width of space in the default font.  Thus,
2820 if the value is 5, that means the window contents are scrolled left by 5
2821 times the normal character width.  How many characters actually
2822 disappear off to the left depends on their width, and could vary from
2823 line to line.
2825   Because we read from side to side in the ``inner loop,'' and from top
2826 to bottom in the ``outer loop,'' the effect of horizontal scrolling is
2827 not like that of textual or vertical scrolling.  Textual scrolling
2828 involves selection of a portion of text to display, and vertical
2829 scrolling moves the window contents contiguously; but horizontal
2830 scrolling causes part of @emph{each line} to go off screen.
2832   Usually, no horizontal scrolling is in effect; then the leftmost
2833 column is at the left edge of the window.  In this state, scrolling to
2834 the right is meaningless, since there is no data to the left of the edge
2835 to be revealed by it; so this is not allowed.  Scrolling to the left is
2836 allowed; it scrolls the first columns of text off the edge of the window
2837 and can reveal additional columns on the right that were truncated
2838 before.  Once a window has a nonzero amount of leftward horizontal
2839 scrolling, you can scroll it back to the right, but only so far as to
2840 reduce the net horizontal scroll to zero.  There is no limit to how far
2841 left you can scroll, but eventually all the text will disappear off the
2842 left edge.
2844 @vindex auto-hscroll-mode
2845   If @code{auto-hscroll-mode} is set, redisplay automatically alters
2846 the horizontal scrolling of a window as necessary to ensure that point
2847 is always visible.  However, you can still set the horizontal
2848 scrolling value explicitly.  The value you specify serves as a lower
2849 bound for automatic scrolling, i.e. automatic scrolling will not
2850 scroll a window to a column less than the specified one.
2852 @deffn Command scroll-left &optional count set-minimum
2853 This function scrolls the selected window @var{count} columns to the
2854 left (or to the right if @var{count} is negative).  The default
2855 for @var{count} is the window width, minus 2.
2857 The return value is the total amount of leftward horizontal scrolling in
2858 effect after the change---just like the value returned by
2859 @code{window-hscroll} (below).
2861 Once you scroll a window as far right as it can go, back to its normal
2862 position where the total leftward scrolling is zero, attempts to scroll
2863 any farther right have no effect.
2865 If @var{set-minimum} is non-@code{nil}, the new scroll amount becomes
2866 the lower bound for automatic scrolling; that is, automatic scrolling
2867 will not scroll a window to a column less than the value returned by
2868 this function.  Interactive calls pass non-@code{nil} for
2869 @var{set-minimum}.
2870 @end deffn
2872 @deffn Command scroll-right &optional count set-minimum
2873 This function scrolls the selected window @var{count} columns to the
2874 right (or to the left if @var{count} is negative).  The default
2875 for @var{count} is the window width, minus 2.  Aside from the direction
2876 of scrolling, this works just like @code{scroll-left}.
2877 @end deffn
2879 @defun window-hscroll &optional window
2880 This function returns the total leftward horizontal scrolling of
2881 @var{window}---the number of columns by which the text in @var{window}
2882 is scrolled left past the left margin.  The default for
2883 @var{window} is the selected window.
2885 The return value is never negative.  It is zero when no horizontal
2886 scrolling has been done in @var{window} (which is usually the case).
2889 @example
2890 @group
2891 (window-hscroll)
2892      @result{} 0
2893 @end group
2894 @group
2895 (scroll-left 5)
2896      @result{} 5
2897 @end group
2898 @group
2899 (window-hscroll)
2900      @result{} 5
2901 @end group
2902 @end example
2903 @end defun
2905 @defun set-window-hscroll window columns
2906 This function sets horizontal scrolling of @var{window}.  The value of
2907 @var{columns} specifies the amount of scrolling, in terms of columns
2908 from the left margin.  The argument @var{columns} should be zero or
2909 positive; if not, it is taken as zero.  Fractional values of
2910 @var{columns} are not supported at present.
2912 Note that @code{set-window-hscroll} may appear not to work if you test
2913 it by evaluating a call with @kbd{M-:} in a simple way.  What happens
2914 is that the function sets the horizontal scroll value and returns, but
2915 then redisplay adjusts the horizontal scrolling to make point visible,
2916 and this overrides what the function did.  You can observe the
2917 function's effect if you call it while point is sufficiently far from
2918 the left margin that it will remain visible.
2920 The value returned is @var{columns}.
2922 @example
2923 @group
2924 (set-window-hscroll (selected-window) 10)
2925      @result{} 10
2926 @end group
2927 @end example
2928 @end defun
2930    Here is how you can determine whether a given position @var{position}
2931 is off the screen due to horizontal scrolling:
2933 @example
2934 @group
2935 (defun hscroll-on-screen (window position)
2936   (save-excursion
2937     (goto-char position)
2938     (and
2939      (>= (- (current-column) (window-hscroll window)) 0)
2940      (< (- (current-column) (window-hscroll window))
2941         (window-width window)))))
2942 @end group
2943 @end example
2945 @node Coordinates and Windows
2946 @section Coordinates and Windows
2948 This section describes how to relate edges and screen coordinates to
2949 windows.
2951 @defun window-edges &optional window
2952 This function returns a list of the edge coordinates of @var{window}.
2953 The default for @var{window} is the selected window.
2955 The order of the list is @code{(@var{left} @var{top} @var{right}
2956 @var{bottom})}, all elements relative to 0, 0 at the top left corner of
2957 the frame.  The element @var{right} of the value is one more than the
2958 rightmost column used by @var{window}, and @var{bottom} is one more than
2959 the bottommost row used by @var{window} and its mode-line.
2961 The edges include the space used by the window's scroll bar, display
2962 margins, fringes, header line, and mode line, if it has them.  Also,
2963 if the window has a neighbor on the right, its right edge value
2964 includes the width of the separator line between the window and that
2965 neighbor.  Since the width of the window does not include this
2966 separator, the width does not usually equal the difference between the
2967 right and left edges.
2968 @end defun
2970 @defun window-inside-edges &optional window
2971 This is similar to @code{window-edges}, but the edge values
2972 it returns include only the text area of the window.  They
2973 do not include the header line, mode line, scroll bar or
2974 vertical separator, fringes, or display margins.
2975 @end defun
2977 Here are the results obtained on a typical 24-line terminal with just
2978 one window, with menu bar enabled:
2980 @example
2981 @group
2982 (window-edges (selected-window))
2983      @result{} (0 1 80 23)
2984 @end group
2985 @group
2986 (window-inside-edges (selected-window))
2987      @result{} (0 1 80 22)
2988 @end group
2989 @end example
2991 @noindent
2992 The bottom edge is at line 23 because the last line is the echo area.
2993 The bottom inside edge is at line 22, which is the window's mode line.
2995 If @var{window} is at the upper left corner of its frame, and there is
2996 no menu bar, then @var{bottom} returned by @code{window-edges} is the
2997 same as the value of @code{(window-total-height)}, @var{right} is the
2998 same as the value of @code{(window-total-width)}, and @var{top} and
2999 @var{left} are zero.  For example, the edges of the following window are
3000 @w{@samp{0 0 8 5}}.  Assuming that the frame has more than 8 columns,
3001 the last column of the window (column 7) holds a border rather than
3002 text.  The last row (row 4) holds the mode line, shown here with
3003 @samp{xxxxxxxxx}.
3005 @example
3006 @group
3007            0
3008            _______
3009         0 |       |
3010           |       |
3011           |       |
3012           |       |
3013           xxxxxxxxx  4
3015                   7
3016 @end group
3017 @end example
3019 In the following example, let's suppose that the frame is 7
3020 columns wide.  Then the edges of the left window are @w{@samp{0 0 4 3}}
3021 and the edges of the right window are @w{@samp{4 0 7 3}}.
3022 The inside edges of the left window are @w{@samp{0 0 3 2}},
3023 and the inside edges of the right window are @w{@samp{4 0 7 2}},
3025 @example
3026 @group
3027            ___ ___
3028           |   |   |
3029           |   |   |
3030           xxxxxxxxx
3032            0  34  7
3033 @end group
3034 @end example
3036 @defun window-pixel-edges &optional window
3037 This function is like @code{window-edges} except that, on a graphical
3038 display, the edge values are measured in pixels instead of in
3039 character lines and columns.
3040 @end defun
3042 @defun window-inside-pixel-edges &optional window
3043 This function is like @code{window-inside-edges} except that, on a
3044 graphical display, the edge values are measured in pixels instead of
3045 in character lines and columns.
3046 @end defun
3048 @defun window-at x y &optional frame
3049 This function returns the window containing the specified cursor
3050 position in the frame @var{frame}.  The coordinates @var{x} and @var{y}
3051 are measured in characters and count from the top left corner of the
3052 frame.  If they are out of range, @code{window-at} returns @code{nil}.
3054 If you omit @var{frame}, the selected frame is used.
3055 @end defun
3057 @defun coordinates-in-window-p coordinates window
3058 This function checks whether a particular frame position falls within
3059 the window @var{window}.
3061 The argument @var{coordinates} is a cons cell of the form @code{(@var{x}
3062 . @var{y})}.  The coordinates @var{x} and @var{y} are measured in
3063 characters, and count from the top left corner of the screen or frame.
3065 The value returned by @code{coordinates-in-window-p} is non-@code{nil}
3066 if the coordinates are inside @var{window}.  The value also indicates
3067 what part of the window the position is in, as follows:
3069 @table @code
3070 @item (@var{relx} . @var{rely})
3071 The coordinates are inside @var{window}.  The numbers @var{relx} and
3072 @var{rely} are the equivalent window-relative coordinates for the
3073 specified position, counting from 0 at the top left corner of the
3074 window.
3076 @item mode-line
3077 The coordinates are in the mode line of @var{window}.
3079 @item header-line
3080 The coordinates are in the header line of @var{window}.
3082 @item vertical-line
3083 The coordinates are in the vertical line between @var{window} and its
3084 neighbor to the right.  This value occurs only if the window doesn't
3085 have a scroll bar; positions in a scroll bar are considered outside the
3086 window for these purposes.
3088 @item left-fringe
3089 @itemx right-fringe
3090 The coordinates are in the left or right fringe of the window.
3092 @item left-margin
3093 @itemx right-margin
3094 The coordinates are in the left or right margin of the window.
3096 @item nil
3097 The coordinates are not in any part of @var{window}.
3098 @end table
3100 The function @code{coordinates-in-window-p} does not require a frame as
3101 argument because it always uses the frame that @var{window} is on.
3102 @end defun
3104 @node Window Configurations
3105 @section Window Configurations
3106 @cindex window configurations
3107 @cindex saving window information
3109   A @dfn{window configuration} records the entire layout of one
3110 frame---all windows, their sizes, which buffers they contain, how those
3111 buffers are scrolled, and their values of point and the mark; also their
3112 fringes, margins, and scroll bar settings.  It also includes the value
3113 of @code{minibuffer-scroll-window}.  As a special exception, the window
3114 configuration does not record the value of point in the selected window
3115 for the current buffer.
3117   You can bring back an entire frame layout by restoring a previously
3118 saved window configuration.  If you want to record the layout of all
3119 frames instead of just one, use a frame configuration instead of a
3120 window configuration; see @ref{Frame Configurations}.
3122 @defun current-window-configuration &optional frame
3123 This function returns a new object representing @var{frame}'s current
3124 window configuration.  The default for @var{frame} is the selected
3125 frame.
3126 @end defun
3128 @defun set-window-configuration configuration
3129 This function restores the configuration of windows and buffers as
3130 specified by @var{configuration}, for the frame that @var{configuration}
3131 was created for.
3133 The argument @var{configuration} must be a value that was previously
3134 returned by @code{current-window-configuration}.  The configuration is
3135 restored in the frame from which @var{configuration} was made, whether
3136 that frame is selected or not.  This always counts as a window size
3137 change and triggers execution of the @code{window-size-change-functions}
3138 (@pxref{Window Hooks}), because @code{set-window-configuration} doesn't
3139 know how to tell whether the new configuration actually differs from the
3140 old one.
3142 If the frame which @var{configuration} was saved from is dead, all this
3143 function does is restore the three variables @code{window-min-height},
3144 @code{window-min-width} and @code{minibuffer-scroll-window}. In this
3145 case, the function returns @code{nil}.  Otherwise, it returns @code{t}.
3147 Here is a way of using this function to get the same effect
3148 as @code{save-window-excursion}:
3150 @example
3151 @group
3152 (let ((config (current-window-configuration)))
3153   (unwind-protect
3154       (progn (split-window-vertically nil)
3155              @dots{})
3156     (set-window-configuration config)))
3157 @end group
3158 @end example
3159 @end defun
3161 @defspec save-window-excursion forms@dots{}
3162 This special form records the window configuration, executes @var{forms}
3163 in sequence, then restores the earlier window configuration.  The window
3164 configuration includes, for each window, the value of point and the
3165 portion of the buffer that is visible.  It also includes the choice of
3166 selected window.  However, it does not include the value of point in
3167 the current buffer; use @code{save-excursion} also, if you wish to
3168 preserve that.
3170 Don't use this construct when @code{save-selected-window} is sufficient.
3172 Exit from @code{save-window-excursion} always triggers execution of
3173 @code{window-size-change-functions}.  (It doesn't know how to tell
3174 whether the restored configuration actually differs from the one in
3175 effect at the end of the @var{forms}.)
3177 The return value is the value of the final form in @var{forms}.
3178 For example:
3180 @example
3181 @group
3182 (split-window)
3183      @result{} #<window 25 on control.texi>
3184 @end group
3185 @group
3186 (setq w (selected-window))
3187      @result{} #<window 19 on control.texi>
3188 @end group
3189 @group
3190 (save-window-excursion
3191   (delete-other-windows w)
3192   (switch-to-buffer "foo")
3193   'do-something)
3194      @result{} do-something
3195      ;; @r{The screen is now split again.}
3196 @end group
3197 @end example
3198 @end defspec
3200 @defun window-configuration-p object
3201 This function returns @code{t} if @var{object} is a window configuration.
3202 @end defun
3204 @defun compare-window-configurations config1 config2
3205 This function compares two window configurations as regards the
3206 structure of windows, but ignores the values of point and mark and the
3207 saved scrolling positions---it can return @code{t} even if those
3208 aspects differ.
3210 The function @code{equal} can also compare two window configurations; it
3211 regards configurations as unequal if they differ in any respect, even a
3212 saved point or mark.
3213 @end defun
3215 @defun window-configuration-frame config
3216 This function returns the frame for which the window configuration
3217 @var{config} was made.
3218 @end defun
3220   Other primitives to look inside of window configurations would make
3221 sense, but are not implemented because we did not need them.  See the
3222 file @file{winner.el} for some more operations on windows
3223 configurations.
3225 @node Window Parameters
3226 @section Window Parameters
3227 @cindex window parameters
3229 This section describes how window parameters can be used to associate
3230 additional information with windows.
3232 @defun window-parameter window parameter
3233 This function returns @var{window}'s value for @var{parameter}.  The
3234 default for @var{window} is the selected window.  If @var{window} has no
3235 setting for @var{parameter}, this function returns @code{nil}.
3236 @end defun
3238 @defun window-parameters &optional window
3239 This function returns all parameters of @var{window} and their values.
3240 The default for @var{window} is the selected window.  The return value,
3241 if non-@code{nil} is an association list whose elements have the form
3242 @code{(@var{parameter} . @var{value})}.
3243 @end defun
3245 @defun set-window-parameter window parameter value
3246 This function sets @var{window}'s value of @var{parameter} to
3247 @var{value} and returns @var{value}.  The default for @var{window}
3248 is the selected window.
3249 @end defun
3251 Some functions, notably @code{split-window}, @code{delete-window}, and
3252 @code{delete-other-windows} behave specially when their @var{window}
3253 argument has a parameter set.  The special behavior consists of a
3254 pre-operation step and a post-operation step.
3256 In the @dfn{pre-operation step}, the value of the parameter is analyzed
3257 and, if its value prescribes some special action, that action is
3258 executed.  For example, the pre-operation step of @code{delete-window}
3259 when invoked on the main window of a compound window (@pxref{Compound
3260 Windows}) calls @code{delete-window} with the root window of the
3261 compound window as argument instead.
3263 In the @dfn{post-operation step}, the parameters of all windows forming
3264 the new configuration are adjusted.  For example, @code{split-window}
3265 when invoked on a main window of a window group (@pxref{Window Groups}),
3266 sets in this step the corresponding parameter of the new window.
3268 You can override that special behavior by binding the following variable
3269 to a non-@code{nil} value:
3271 @defvar ignore-window-parameters
3272 If this variable is non-@code{nil}, some standard functions ignore
3273 window parameters.  The functions currently affected by this are
3274 @code{split-window}, @code{delete-window}, @code{delete-other-windows}
3275 and @code{other-window}.
3277 When this variable equals @code{pre}, the pre-operation step is skipped
3278 but the post-operation step is executed.  When this variable equals
3279 @code{post}, the pre-operation step is executed and thee post-operation
3280 step is skipped.
3282 The value @code{t} means pre- and post-operation steps are skipped.
3283 Currently any other non-@code{nil} value is handled like @code{t}.
3285 An application can bind this variable to a non-@code{nil} value around
3286 calls to these functions.  If it does so and the value is not
3287 @code{pre}, the application is fully responsible for correctly setting
3288 the parameters of all remaining windows after the function exited.
3289 @end defvar
3291 Window parameters are mainly used for implementing composite windows,
3292 @xref{Composite Windows}.  In particular, the @code{compound},
3293 @code{group} and @code{composite} parameters are reserved for that
3294 purpose.
3296 The @code{quit-restore} parameter tells how to proceed with a window
3297 when the user ``quits'' it by invoking @code{quit-restore-window}, see
3298 @ref{Displaying Buffers}.  The following non-@code{nil} values of this
3299 parameter have a special meaning.
3301 @table @asis
3302 @item @code{t}
3303 This means to delete the associated window.  By default, @code{t} is
3304 used for a ``temporary'' window that was obtained by splitting an
3305 existing window.
3307 @item @code{frame}
3308 This means to delete the associated window's frame.  This value
3309 indicates that the associated windows was obtained by popping up a new
3310 frame showing just this window.  If the window is no more needed, it
3311 should be deleted together with the containing frame.
3313 @item A list
3314 This option is useful when the associated window was borrowed to
3315 temporarily display some buffer and quitting shall ``restore'' the
3316 previous contents of the window.  The first three elements of the list
3317 must specify a buffer, a window start position, and a window point.
3318 Quitting the window will then try to display the indicated buffer with
3319 the given start position and point in that window.
3321 The fourth element, if non-@code{nil}, must denote a live buffer.  If
3322 specified, quitting will restore the previous window contents if and
3323 only if the buffer shown in the window is the buffer named by this
3324 element.
3326 The fifth element, if non-@code{nil}, should specify the desired height
3327 of the window when its buffer is restored.  This value is applied if the
3328 buffer temporarily shown in the window was in
3329 @code{temp-buffer-resize-mode} to restore the original height of the
3330 window.
3331 @end table
3333 @node Composite Windows
3334 @section Composite Windows
3335 @cindex composite windows
3337 A @dfn{composite window} is a rectangular frame area, typically composed
3338 of one or more so-called support windows grouped around one or more
3339 so-called main windows.  Some applications allow degenerate composite
3340 windows consisting of one live window only.  Currently, two types of
3341 composite windows are supported: Compound windows (@pxref{Compound
3342 Windows}) and window groups (@pxref{Window Groups}).
3344 @cindex composite root window
3345 Each composite window has one and only one composite root window.  That
3346 root window is usually an internal window (@pxref{Frames and Windows})
3347 but may be a live window in the degenerate case where the composite
3348 window is a live window.  All other windows of a composite window are
3349 subwindows of the composite root window.
3351 @defun composite-root-window-p window
3352 This function return non-@code{nil} if @var{window} is the root window
3353 of a composite window.  The return value is the type of that composite
3354 window, currently either @code{compound} or @code{group}.
3355 @end defun
3357 @defun composite-window-p window
3358 This function returns non-@code{nil} if @var{window} is a subwindow of a
3359 composite window.  The return value is the value of the @code{composite}
3360 window parameter (@pxref{Window Parameters}) of @var{window}.
3362 Note that a composite root window that is not part of a composite window
3363 does not have its @code{composite} window parameter set.  That parameter
3364 is reserved for subwindows of a composite window only.  A root window is
3365 not a subwindow of the composite window rooted at it.
3366 @end defun
3368 @cindex main window
3369 Each composite window must contain at least one @dfn{main window}.  A
3370 main window can be either a live window or an internal window.  Live
3371 main windows are the places where ``normal'' editing activities take
3372 place.  An internal main window is either a window whose subwindows are
3373 all main windows of the same composite window, or the root window of
3374 another composite window.
3376 @defun composite-main-window-p window
3377 Ths function returns @code{t} if @var{window} is a main window of a
3378 composite window.
3379 @end defun
3381 @cindex support window
3382 Composite windows may also contain an arbitrary number of @dfn{support
3383 windows}.  A support window can be either a live window or an internal
3384 window.  Live support windows usually supply information like lists of
3385 files, buffers, tags, or bookmarks, a toolbar, tabs, or compiler and
3386 system messages.  An internal support window is either a window whose
3387 subwindows are all support windows of the same composite window, or the
3388 root window of another composite window.
3390 @defun composite-support-window-p window
3391 Ths function returns @code{t} if @var{window} is a support window of a
3392 composite window.
3393 @end defun
3395 For technical reasons, composite windows may contain internal subwindows
3396 that are neither main nor support windows.  These windows are supposed
3397 to have at least one main and one support window among their child
3398 windows.  The functions @code{composite-main-window-p} and
3399 @code{composite-support-window-p} return @code{nil} for such windows.
3401 Composite windows are implemented with the help of three reserved window
3402 parameters, see @ref{Window Parameters}.  Applications should never use
3403 these parameters for any other purposes than the ones described below.
3405 @table @asis
3406 @item @code{compound}
3407 If non-@code{nil}, this parameter designates the associated window as
3408 the root window of a compound window, see @ref{Compound Windows}.
3410 @item @code{group}
3411 If the value of this parameter is non-@code{nil}, the associated window
3412 is the root window of a window group, see @ref{Window Groups}.
3414 @item @code{composite}
3415 If this parameter is non-@code{nil}, the associated window is a
3416 subwindow of a composite window.  The value must be a cons cell whose
3417 @sc{car} denotes the @dfn{type} of the composite window, either
3418 @code{compound} or @code{group}.
3420 The @sc{cdr} denotes the @dfn{role} of the associated window within the
3421 composite window and should be either @code{main}, @code{support} or
3422 @code{t}.  The value @code{t} usually designates the associated window
3423 as an internal window with at least one main and one support window
3424 among its children.
3425 @end table
3427 For any subwindow @sc{w} of a composite window there has to exist a
3428 unique path from @sc{w} to the root window @sc{r} of the composite
3429 window such that the following property holds invariantly:
3431 @enumerate
3432 @item
3433 The parent window @sc{p} of @sc{w} is either @sc{r} or a subwindow of
3434 @sc{r}.
3436 @item
3437 The types of @sc{w} and @sc{p} must match: This means that if @sc{p}
3438 is @sc{r} then either the type of @sc{w} must be @code{compound} and
3439 the @code{compound} parameter of @sc{r} must be @code{t} or the type of
3440 @sc{w} must be @code{group} and the @code{group} parameter of @sc{r}
3441 must be @code{t}.
3443 @item
3444 If @sc{p} is not @sc{r} either the roles of @sc{w} and @sc{p} are
3445 the same or @sc{p} is neither a main nor a support window.
3446 @end enumerate
3448 Violating this property usually breaks subsequent operations on the
3449 composite window.
3451 @defun composite-root-window window
3452 This function returns the root window of the composite window that
3453 contains @var{window} as a subwindow.  It returns @code{nil} if
3454 @var{window} is not a subwindow of a composite window or the path from
3455 @var{window} to the root of the composite window is broken.
3457 When @var{window} is a subwindow of two or more composite windows, this
3458 function returns the ``innermost'' root window, that is the first root
3459 window found following the path from @var{window} to the root window of
3460 its frame.
3461 @end defun
3463 @cindex major window
3464 Usually, each composite window has one @dfn{major window} comprising all
3465 other main windows of the composite window.  Any composite window should
3466 have only one major window to make sure that functions on its component
3467 windows behave ``as intended''.  The major window can be retrieved via
3468 the following function:
3470 @defun composite-major-window window
3471 This function returns the major window of the composite window
3472 @var{window} belongs to.  The major window is the last main or root
3473 window found by following the path from @var{window} to the root of the
3474 composite window @var{window} belongs to.
3476 This function returns a meaningful result if and only if @var{window} is
3477 a main window.
3478 @end defun
3480 Note also the following aspects of composite windows:
3482 @itemize @bullet
3483 @item
3484 In degenerate cases one and the same window can be the root window of a
3485 compound window and a window group.
3487 @item
3488 Composite windows can be nested.  This means that the root window of a
3489 composite window can also be a subwindow of another composite window.
3490 @end itemize
3492 Uusally, the fact that a window is a subwindow of a composite window
3493 changes the semantics of a number of functions called with that window
3494 as argument.  See @ref{Compound Windows} for a list of functions whose
3495 semantics change in compound windows.  See @ref{Window Groups} for a
3496 corresponding list of functions that behave specially in window groups.
3498 You can override the special behavior of any of these functions for a
3499 particular window in one of two ways:
3501 @itemize @bullet
3502 @item
3503 Set a window parameter denoting the function in question to @code{t}.
3504 This makes the function ``behave as usual''.  For example
3506 @smallexample
3507 (set-window-parameter W 'split-window t)
3508 @end smallexample
3510 will cause @code{split-window} split the window @sc{w} as if @sc{w}
3511 did not have any parameters.
3513 @item
3514 Specify the function to be called instead.  For example
3516 @smallexample
3517 (set-window-parameter W 'split-window 'my-split-window)
3518 @end smallexample
3520 will have @code{split-window} call the function @code{my-split-window}
3521 with the original arguments to do the real work.  As a special case
3523 @smallexample
3524 (set-window-parameter W 'split-window 'ignore)
3525 @end smallexample
3527 will do nothing and return @code{nil}.
3529 @item
3530 Bind the value of @var{ignore-window-parameters} (@pxref{Window
3531 Parameters}) to non-@code{nil} around a call to the function.
3532 @end itemize
3534 The command @code{other-window} usually does not select a support
3535 window.  You can override this behavior by specifying
3537 @smallexample
3538 (set-window-parameter W 'maybe-other-window t)
3539 @end smallexample
3541 in which case @code{other-window} can select @sc{w} just like any other
3542 window.  To specify that a main window does not get selected by
3543 @code{other-window}, set its @code{no-other-window} parameter to
3544 @code{t} as
3546 @smallexample
3547 (set-window-parameter W 'no-other-window t)
3548 @end smallexample
3550 Creating a new support window can be tricky.  The following function
3551 should handle this.
3553 @defun make-support-window window support &optional size horizontal
3554 This function adds a support window of type @var{support} to
3555 @var{window}.  The argument @var{window} must specify either a root
3556 window or a subwindow of a composite window.  The argument @var{window}
3557 must be one of @code{compound} or @code{group}.  The optional arguments
3558 @var{SIZE} and @var{HORIZONTAL} are as for @code{split-window}.  The
3559 return value is the new support window.
3561 This function behaves like @code{split-window} but makes sure that the
3562 parameters of all involved windows are set correctly.  In particular,
3563 the new leaf window becomes a support window of the composite window.
3564 @end defun
3567 @node Compound Windows
3568 @section Compound Windows
3569 @cindex compound windows
3571 A @dfn{compound window} is a composite window (@pxref{Composite
3572 Windows}) built from two or more subwindows.  For any subwindow of a
3573 compound window the semantics of a number of operations usually changes
3574 in the sense that the operation is suitably applied to the entire
3575 compound window instead.
3577    One typical use of a compound window is that of providing a sidebar
3578 (like the speedbar) attached to a single ``main'' window.  Splitting the
3579 main window vertically then guarantees that the new window appears below
3580 (or above) the compound window thus not disrupting the relationship
3581 between the sidebar and the main window.  Another use of compound
3582 windows is that of a support window displaying a toolbar or tabs above a
3583 main window.  In this case splitting the main window horizontally will
3584 not break the relationship between the supporting and the main window.
3586    Compound windows must have at least two subwindows.  When
3587 @code{delete-window} deletes a subwindow of a compound window and there
3588 is only one more subwindow left, the compound window is dissolved
3589 automatically and ceases to have any impact on subsequent operations on
3590 the last remaining subwindow.  Apart from this restriction a compound
3591 window may have any number of subwindows.  Deleting the last main window
3592 of a compound window deletes the entire compound window instead (recall
3593 that a composite window must have at least one main subwindow).
3595    Application programs are supposed to preserve the types assigned to
3596 members of compound windows.  If they don't, they risk to break the
3597 semantics of operations on the compound window.  Note also that any
3598 subwindow of a compound window can be the root of another composite
3599 window since the latter can be nested.
3601    In addition to the functions giving meaningful results for any
3602 composite window (@pxref{Composite Windows}) the following functions
3603 have been designed specifically to operate on a subwindow of a compound
3604 window.
3606 @defun compound-window-p window
3607 This function returns non-@code{nil} if @var{window} is a subwindow of a
3608 compound window.
3609 @end defun
3611 @defun compound-main-window-p window
3612 This function returns non-@code{nil} if @var{window} is a main window of
3613 a compound window.
3614 @end defun
3616 A compound window can be created with the following function:
3618 @defun make-compound-window &optional window main size horizontal
3619 This functions behaves like @code{split-window} (@pxref{Splitting
3620 Windows}) with the additional twist that it makes @var{window} the main
3621 window of a new compound window.  For this purpose, it creates a new
3622 internal window with @var{window} and a new leaf window as its only
3623 children.  @var{window} must be a leaf window and defaults to the
3624 selected window.
3626 If the optional argument @var{main} is non-@code{nil}, this means the
3627 new leaf window becomes a main window.  Argument @var{main} @code{nil}
3628 or not provided means the new leaf window becomes a support window.  The
3629 original window @var{window} always becomes a main window.
3631 The optional arguments @var{size} and @var{horizontal} are as for
3632 @code{split-window}.  The return value is the new leaf window.
3633 @end defun
3635 Alternatively, a compound window can be constructed ``manually'' by
3636 splitting some live window and setting the @code{root} and
3637 @code{composite} parameters of the involved windows.  Look at how
3638 @code{make-compound-window} sets these parameters for an example.
3640 Currently, the semantics of the following commands and functions change
3641 when their window argument is a member of a compound window:
3643 @table @asis
3644 @item @code{split-window} (@pxref{Splitting Windows})
3645 When @var{window} is a component of a compound window,
3646 @code{split-window} is invoked with the root window of the compound
3647 window as argument instead.
3649 @item @code{delete-window} (@pxref{Deleting Windows})
3650 When @var{window} is a component of a compound window,
3651 @code{delete-window} deletes the entire compound window instead.  If the
3652 root window of the compound window is the root window of its containing
3653 frame, or a support window or the only main window of a window group
3654 (@pxref{Window Groups}) an error is signalled.
3656 @item @code{delete-other-windows} (@pxref{Deleting Windows})
3657 When @var{window} belongs to a compound window,
3658 @code{delete-other-windows} makes the compound window fill its frame or,
3659 if present, the innermost enclosing major window of a window group, see
3660 @ref{Window Groups}.  If the root window of the compound window is the
3661 root window of its containing frame, or a support window or the only
3662 main window of a window group (@pxref{Window Groups}) nothing is done.
3663 @end table
3665 @node Window Groups
3666 @section Window Groups
3667 @cindex window groups
3669 A @dfn{window group} is a composite window (@pxref{Composite Windows})
3670 built from one or more subwindows.  The main application area of window
3671 groups is in the implementation of Integrated Development Environments
3672 (IDEs) where a rectangular subarea of a frame constitutes the editing
3673 environment proper.  The remaining windows are used for displaying
3674 supporting information and are not intended for editing.
3676 Each window group must contain at least one main window which must be
3677 either live or an internal window which should comprise all other main
3678 windows of the group.  Note that the latter restriction is not checked
3679 by the routines operating on window groups but it's better if
3680 application preserve it since some operations inherently rely on it.
3682 Usually, the root window of a window group is also the root window of
3683 the containing frame (@pxref{Frames and Windows}).  Note, however, that
3684 window groups (and compound windows) can be arbitrarily nested.
3686 @defun group-window-p window
3687 This function returns non-@code{nil} if @var{window} is a subwindow of a
3688 window group.
3689 @end defun
3691 @defun group-window-main-p window
3692 This function returns non-@code{nil} if @var{window} is a main window of
3693 a window group.
3694 @end defun
3696 @defun group-root-window window
3697 This function returns the root window of the window group @var{window}
3698 belongs to.  If @var{window} is part of a compound window, it returns
3699 the root window of the group the root of the compound window belongs
3700 too.
3701 @end defun
3703 You can create a new window group with the following function:
3705 @defun make-window-group &optional window
3706 This functions makes @var{window} the main and root window of a new
3707 window group.  The argument @var{window} must be a live window and
3708 defaults to the selected one.  This function returns @var{window}.
3709 @end defun
3711 Alternatively, you can construct a window group ``manually'' by
3712 appropriately setting the @code{root} parameter of any live window.
3714 Currently, the semantics of the following commands and functions change
3715 when their window argument is a member of a window group:
3717 @table @asis
3718 @item @code{split-window} (@pxref{Splitting Windows})
3719 @code{split-window} is allowed to split main windows of a window group
3720 only.  It will signal an error when invoked with a support window as
3721 argument.
3723 @item @code{delete-window} (@pxref{Deleting Windows})
3724 @code{delete-window} is allowed to delete a main window of a window
3725 group only.  It will signal an error when invoked with a support window
3726 or the last main window of the group as argument
3728 If a window group contains two disjoint main windows that are not
3729 subwindows of another main window of the group, @code{delete-window} may
3730 signal an error even if the window group contains other main windows.
3732 @item @code{delete-other-windows} (@pxref{Deleting Windows})
3733 When @code{delete-other-windows} is invoked with a main window of a
3734 window group as argument, it will delete all main windows of that group
3735 that are neither the argument window itself nor a subwindow of the
3736 argument window.  Support windows are not affected by this operation.
3737 An error is signalled when @code{delete-other-windows} is invoked with a
3738 support window as its argument.
3740 If a window group contains two disjoint main windows that are not
3741 subwindows of another main window of the group,
3742 @code{delete-other-windows} will not be able to remove all main windows
3743 but the argument window and its subwindows.
3744 @end table
3746 @node Window Hooks
3747 @section Hooks for Window Scrolling and Changes
3748 @cindex hooks for window operations
3750 This section describes how a Lisp program can take action whenever a
3751 window displays a different part of its buffer or a different buffer.
3752 There are three actions that can change this: scrolling the window,
3753 switching buffers in the window, and changing the size of the window.
3754 The first two actions run @code{window-scroll-functions}; the last runs
3755 @code{window-size-change-functions}.
3757 @defvar window-scroll-functions
3758 This variable holds a list of functions that Emacs should call before
3759 redisplaying a window with scrolling.  Displaying a different buffer in
3760 the window also runs these functions.
3762 This variable is not a normal hook, because each function is called with
3763 two arguments: the window, and its new display-start position.
3765 These functions must be careful in using @code{window-end}
3766 (@pxref{Window Start and End}); if you need an up-to-date value, you
3767 must use the @var{update} argument to ensure you get it.
3769 @strong{Warning:} don't use this feature to alter the way the window
3770 is scrolled.  It's not designed for that, and such use probably won't
3771 work.
3772 @end defvar
3774 @defvar window-size-change-functions
3775 This variable holds a list of functions to be called if the size of any
3776 window changes for any reason.  The functions are called just once per
3777 redisplay, and just once for each frame on which size changes have
3778 occurred.
3780 Each function receives the frame as its sole argument.  There is no
3781 direct way to find out which windows on that frame have changed size, or
3782 precisely how.  However, if a size-change function records, at each
3783 call, the existing windows and their sizes, it can also compare the
3784 present sizes and the previous sizes.
3786 Creating or deleting windows counts as a size change, and therefore
3787 causes these functions to be called.  Changing the frame size also
3788 counts, because it changes the sizes of the existing windows.
3790 It is not a good idea to use @code{save-window-excursion} (@pxref{Window
3791 Configurations}) in these functions, because that always counts as a
3792 size change, and it would cause these functions to be called over and
3793 over.  In most cases, @code{save-selected-window} (@pxref{Selecting
3794 Windows}) is what you need here.
3795 @end defvar
3797 @defvar window-configuration-change-hook
3798 A normal hook that is run every time you change the window configuration
3799 of an existing frame.  This includes splitting or deleting windows,
3800 changing the sizes of windows, or displaying a different buffer in a
3801 window.
3803 The buffer-local part of this hook is run once per each window on the
3804 affected frame, with the relevant window selected and its buffer
3805 current.  The global part is run once for the modified frame, with that
3806 frame selected.
3807 @end defvar
3809   In addition, you can use @code{jit-lock-register} to register a Font
3810 Lock fontification function, which will be called whenever parts of a
3811 buffer are (re)fontified because a window was scrolled or its size
3812 changed.  @xref{Other Font Lock Variables}.
3814 @ignore
3815    arch-tag: 3f6c36e8-df49-4986-b757-417feed88be3
3816 @end ignore