* doc/lispref/windows.texi (Resizing Windows): Simplify introduction.
[emacs.git] / doc / lispref / windows.texi
blob46ed4476036577633ab1212380c685d2eb26999b
1 @c -*-texinfo-*-
2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 1990-1995, 1998-1999, 2001-2011
4 @c   Free Software Foundation, Inc.
5 @c See the file elisp.texi for copying conditions.
6 @setfilename ../../info/windows
7 @node Windows, Frames, Buffers, Top
8 @chapter Windows
10 This chapter describes the functions and variables related to Emacs
11 windows.  @xref{Frames}, for how windows are assigned an area of screen
12 available for Emacs to use.  @xref{Display}, for information on how text
13 is displayed in windows.
15 @menu
16 * Basic Windows::           Basic information on using windows.
17 * Windows and Frames::      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 window displays the contents of a buffer.
25 * Switching Buffers::       Higher-level functions for switching to a buffer.
26 * Choosing Window::         How to choose a window for displaying a buffer.
27 * Display Action Functions:: Subroutines for @code{display-buffer}.
28 * Choosing Window Options:: Extra options affecting how buffers are displayed.
29 * Window History::          Each window remembers the buffers displayed in it.
30 * Dedicated Windows::       How to avoid displaying another buffer in
31                               a specific window.
32 * Quitting Windows::        How to restore the state prior to displaying a
33                               buffer.
34 * Window Point::            Each window has its own location of point.
35 * Window Start and End::    Buffer positions indicating which text is
36                               on-screen in a window.
37 * Textual Scrolling::       Moving text up and down through the window.
38 * Vertical Scrolling::      Moving the contents up and down on the window.
39 * Horizontal Scrolling::    Moving the contents sideways on the window.
40 * Coordinates and Windows:: Converting coordinates to windows.
41 * Window Configurations::   Saving and restoring the state of the screen.
42 * Window Parameters::       Associating additional information with windows.
43 * Window Hooks::            Hooks for scrolling, window size changes,
44                               redisplay going past a certain point,
45                               or window configuration changes.
46 @end menu
49 @node Basic Windows
50 @section Basic Concepts of Emacs Windows
51 @cindex window
53 A @dfn{window} is a area of the screen which is used to display a
54 buffer (@pxref{Buffers}).  In Emacs Lisp, windows are represented by a
55 special Lisp object type.
57 @cindex multiple windows
58   Windows are grouped into frames (@pxref{Frames}).  Each frame
59 contains at least one window; the user can subdivide it into multiple,
60 non-overlapping windows to view several buffers at once.  Lisp
61 programs can use multiple windows for a variety of purposes.  In
62 Rmail, for example, you can view a summary of message titles in one
63 window, and the contents of the selected message in another window.
65 @cindex terminal screen
66 @cindex screen of terminal
67   Emacs uses the word ``window'' with a different meaning than in
68 graphical desktop environments and window systems, such as the X
69 Window System.  When Emacs is run on X, each of its graphical X
70 windows is an Emacs frame (containing one or more Emacs windows).
71 When Emacs is run on a text-only terminal, the frame fills the entire
72 terminal screen.
74 @cindex tiled windows
75   Unlike X windows, Emacs windows are @dfn{tiled}; they never overlap
76 within the area of the frame.  When a window is created, resized, or
77 deleted, the change in window space is taken from or given to the
78 adjacent windows, so that the total area of the frame is unchanged.
80 @cindex live windows
81 @cindex internal windows
82   A @dfn{live window} is one that is actually displaying a buffer in a
83 frame.  Such a window can be @dfn{deleted}, i.e. removed from the
84 frame (@pxref{Deleting Windows}); then it is no longer live, but the
85 Lisp object representing it might be still referenced from other Lisp
86 objects.  A deleted window may be brought back to life by restoring a
87 saved window configuration (@pxref{Window Configurations}).
89 @defun windowp object
90 This function returns @code{t} if @var{object} is a window (whether or
91 not it is live).  Otherwise, it returns @code{nil}.
92 @end defun
94 @defun window-live-p object
95 This function returns @code{t} if @var{object} is a live window and
96 @code{nil} otherwise.  A live window is one that displays a buffer.
97 @end defun
99   The windows in each frame are organized into a @dfn{window tree}.
100 @xref{Windows and Frames}.  The leaf nodes of each window tree are
101 live windows---the ones actually displaying buffers.  The internal
102 nodes of the window tree are internal windows, which are not live.
103 You can distinguish internal windows from deleted windows with
104 @code{window-valid-p}.
106 @defun window-valid-p object
107 This function returns @code{t} if @var{object} is a live window, or an
108 internal window in a window tree.  Otherwise, it returns @code{nil},
109 including for the case where @var{object} is a deleted window.
110 @end defun
112 @cindex selected window
113   In each frame, at any time, exactly one Emacs window is designated
114 as @dfn{selected within the frame}.  For the selected frame, that
115 window is called the @dfn{selected window}---the one in which most
116 editing takes place, and in which the cursor for selected windows
117 appears (@pxref{Cursor Parameters}).  The selected window's buffer is
118 usually also the current buffer, except when @code{set-buffer} has
119 been used (@pxref{Current Buffer}).  As for non-selected frames, the
120 window selected within the frame becomes the selected window if the
121 frame is ever selected.  @xref{Selecting Windows}.
123 @defun selected-window
124 This function returns the selected window (which is always a live
125 window).
126 @end defun
128 @node Windows and Frames
129 @section Windows and Frames
131 Each window belongs to exactly one frame (@pxref{Frames}).
133 @defun window-frame window
134 This function returns the frame that the window @var{window} belongs
135 to.  If @var{window} is @code{nil}, it defaults to the selected
136 window.
137 @end defun
139 @defun window-list &optional frame minibuffer window
140 This function returns a list of live windows belonging to the frame
141 @var{frame}.  If @var{frame} is omitted or @code{nil}, it defaults to
142 the selected frame.
144 The optional argument @var{minibuffer} specifies whether to include
145 the minibuffer window in the returned list.  If @var{minibuffer} is
146 @code{t}, the minibuffer window is included.  If @var{minibuffer} is
147 @code{nil} or omitted, the minibuffer window is included only if it is
148 active.  If @var{minibuffer} is neither @code{nil} nor @code{t}, the
149 minibuffer window is never included.
151 The optional argument @var{window}, if non-@code{nil}, should be a
152 live window on the specified frame; then @var{window} will be the
153 first element in the returned list.  If @var{window} is omitted or
154 @code{nil}, the window selected within the frame is first element.
155 @end defun
157 @cindex window tree
158 @cindex root window
159   Windows in the same frame are organized into a @dfn{window tree},
160 whose leaf nodes are the live windows.  The internal nodes of a window
161 tree are not live; they exist for the purpose of organizing the
162 relationships between live windows.  The root node of a window tree is
163 called the @dfn{root window}.  It can be either a live window (if the
164 frame has just one window), or an internal window.
166   A minibuffer window (@pxref{Minibuffer Windows}) is not part of its
167 frame's window tree unless the frame is a minibuffer-only frame.
168 Nonetheless, most of the functions in this section accept the
169 minibuffer window as an argument.  Also, the function
170 @code{window-tree} described at the end of this section lists the
171 minibuffer window alongside the actual window tree.
173 @defun frame-root-window &optional frame-or-window
174 This function returns the root window for @var{frame-or-window}.  The
175 argument @var{frame-or-window} should be either a window or a frame;
176 if omitted or @code{nil}, it defaults to the selected frame.  If
177 @var{frame-or-window} is a window, the return value is the root window
178 of that window's frame.
179 @end defun
181 @cindex parent window
182 @cindex child window
183 @cindex sibling window
184   When a window is split, there are two live windows where previously
185 there was one.  One of these is represented by the same Lisp window
186 object as the original window, and the other is represented by a
187 newly-created Lisp window object.  Both of these live windows become
188 leaf nodes of the window tree, as @dfn{child windows} of a single
189 internal window.  If necessary, Emacs automatically creates this
190 internal window, which is also called the @dfn{parent window}, and
191 assigns it to the appropriate position in the window tree.  A set of
192 windows that share the same parent are called @dfn{siblings}.
194 @cindex parent window
195 @defun window-parent &optional window
196 This function returns the parent window of @var{window}.  If
197 @var{window} is omitted or @code{nil}, it defaults to the selected
198 window.  The return value is @code{nil} if @var{window} has no parent
199 (i.e. it is a minibuffer window or the root window of its frame).
200 @end defun
202   Each internal window always has at least two child windows.  If this
203 number falls to one as a result of window deletion, Emacs
204 automatically deletes the internal window, and its sole remaining
205 child window takes its place in the window tree.
207   Each child window can be either a live window, or an internal window
208 (which in turn would have its own child windows).  Therefore, each
209 internal window can be thought of as occupying a certain rectangular
210 @dfn{screen area}---the union of the areas occupied by the live
211 windows that are ultimately descended from it.
213 @cindex window combination
214 @cindex vertical combination
215 @cindex horizontal combination
216   For each internal window, the screen areas of the immediate children
217 are arranged either vertically or horizontally (never both).  If the
218 child windows are arranged one above the other, they are said to form
219 a @dfn{vertical combination}; if they are arranged side by side, they
220 are said to form a @dfn{horizontal combination}.  Consider the
221 following example:
223 @smallexample
224 @group
225      ______________________________________
226     | ______  ____________________________ |
227     ||      || __________________________ ||
228     ||      |||                          |||
229     ||      |||                          |||
230     ||      |||                          |||
231     ||      |||____________W4____________|||
232     ||      || __________________________ ||
233     ||      |||                          |||
234     ||      |||                          |||
235     ||      |||____________W5____________|||
236     ||__W2__||_____________W3_____________ |
237     |__________________W1__________________|
239 @end group
240 @end smallexample
242 @noindent
243 The root window of this frame is an internal window, @code{W1}.  Its
244 child windows form a horizontal combination, consisting of the live
245 window @code{W2} and the internal window @code{W3}.  The child windows
246 of @code{W3} form a vertical combination, consisting of the live
247 windows @code{W4} and @code{W5}.  Hence, the live windows in this
248 window tree are @code{W2} @code{W4}, and @code{W5}.
250   The following functions can be used to retrieve a child window of an
251 internal window, and the siblings of a child window.
253 @defun window-top-child window
254 This function returns the topmost child window of @var{window}, if
255 @var{window} is an internal window whose children form a vertical
256 combination.  For any other type of window, the return value is
257 @code{nil}.
258 @end defun
260 @defun window-left-child window
261 This function returns the leftmost child window of @var{window}, if
262 @var{window} is an internal window whose children form a horizontal
263 combination.  For any other type of window, the return value is
264 @code{nil}.
265 @end defun
267 @defun window-child window
268 This function returns the first child window of the internal window
269 @var{window}---the topmost child window for a vertical combination, or
270 the leftmost child window for a horizontal combination.  If
271 @var{window} is a live window, the return value is @code{nil}.
272 @end defun
274 @defun window-combined-p &optional window horizontal
275 This function returns a non-@code{nil} value if and only if
276 @var{window} is part of a vertical combination.  If @var{window} is
277 omitted or @code{nil}, it defaults to the selected one.
279 If the optional argument @var{horizontal} is non-@code{nil}, this
280 means to return non-@code{nil} if and only if @var{window} is part of
281 a horizontal combination.
282 @end defun
284 @defun window-next-sibling &optional window
285 This function returns the next sibling of the window @var{window}.  If
286 omitted or @code{nil}, @var{window} defaults to the selected window.
287 The return value is @code{nil} if @var{window} is the last child of
288 its parent.
289 @end defun
291 @defun window-prev-sibling &optional window
292 This function returns the previous sibling of the window @var{window}.
293 If omitted or @code{nil}, @var{window} defaults to the selected
294 window.  The return value is @code{nil} if @var{window} is the first
295 child of its parent.
296 @end defun
298 The functions @code{window-next-sibling} and
299 @code{window-prev-sibling} should not be confused with the functions
300 @code{next-window} and @code{previous-window} which respectively
301 return the next and previous window in the cyclic ordering of windows
302 (@pxref{Cyclic Window Ordering}).
304   You can use the following functions to find the first live window on
305 a frame, and to retrieve the entire window tree of a frame:
307 @defun frame-first-window &optional frame-or-window
308 This function returns the live window at the upper left corner of the
309 frame specified by @var{frame-or-window}.  The argument
310 @var{frame-or-window} must denote a window or a live frame and defaults
311 to the selected frame.  If @var{frame-or-window} specifies a window,
312 this function returns the first window on that window's frame.  Under
313 the assumption that the frame from our canonical example is selected
314 @code{(frame-first-window)} returns @code{W2}.
315 @end defun
317 @defun window-tree &optional frame
318 This function returns a list representing the window tree for frame
319 @var{frame}.  If @var{frame} is omitted or @code{nil}, it defaults to
320 the selected frame.
322 The return value is a list of the form @code{(@var{root} @var{mini})},
323 where @var{root} represents the window tree of the frame's root
324 window, and @var{mini} is the frame's minibuffer window.
326 If the root window is live, @var{root} is that window itself.
327 Otherwise, @var{root} is a list @code{(@var{dir} @var{edges} @var{w1}
328 @var{w2} ...)} where @var{dir} is @code{nil} for a horizontal
329 combination and @code{t} for a vertical combination, @var{edges} gives
330 the size and position of the combination, and the remaining elements
331 are the child windows.  Each child window may again be a window object
332 (for a live window) or a list with the same format as above (for an
333 internal window).  The @var{edges} element is a list @code{(@var{left}
334 @var{top} @var{right} @var{bottom})}, similar to the value returned by
335 @code{window-edges} (@pxref{Coordinates and Windows}).
336 @end defun
338 @node Window Sizes
339 @section Window Sizes
340 @cindex window size
341 @cindex size of window
343   The following schematic shows the structure of a live window:
345 @smallexample
346 @group
347          _________________________________________
348       ^ |______________ Header Line_______________|
349       | |LS|LF|LM|                       |RM|RF|RS| ^
350       | |  |  |  |                       |  |  |  | |
351  Window |  |  |  |       Text Area       |  |  |  | Window
352  Total  |  |  |  |     (Window Body)     |  |  |  | Body
353  Height |  |  |  |                       |  |  |  | Height
354       | |  |  |  |<- Window Body Width ->|  |  |  | |
355       | |__|__|__|_______________________|__|__|__| v
356       v |_______________ Mode Line _______________|
358          <----------- Window Total Width -------->
360 @end group
361 @end smallexample
363 @cindex window body
364 @cindex text area of a window
365 @cindex body of a window
366   At the center of the window is the @dfn{text area}, or @dfn{body},
367 where the buffer text is displayed.  On each side of the text area is
368 a series of vertical areas; from innermost to outermost, these are the
369 left and right margins, denoted by LM and RM in the schematic
370 (@pxref{Display Margins}); the left and right fringes, denoted by LF
371 and RF (@pxref{Fringes}); and the left or right scroll bar, only one of
372 which is present at any time, denoted by LS and RS (@pxref{Scroll
373 Bars}).  At the top of the window is an optional header line
374 (@pxref{Header Lines}), and at the bottom of the window is the mode
375 line (@pxref{Mode Line Format}).
377   Emacs provides several functions for finding the height and width of
378 a window.  Most of these functions report the values as integer
379 multiples of the default character height and width.  On a graphical
380 display, the actual screen size of this default height and width are
381 those specified by the frame's default font.  Hence, if the buffer
382 contains text that is displayed in a different size, the reported
383 height and width of the window may differ from the actual number of
384 text lines or columns displayed in it.
386 @cindex window height
387 @cindex height of a window
388 @cindex total height of a window
389 @cindex window width
390 @cindex width of a window
391 @cindex total width of a window
392   The @dfn{total height} of a window is the distance between the top
393 and bottom of the window, including the header line (if one exists)
394 and the mode line.  The @dfn{total width} of a window is the distance
395 between the left and right edges of the mode line.  Note that the
396 height of a frame is not the same as the height of its windows, since
397 a frame may also contain an echo area, menu bar, and tool bar
398 (@pxref{Size and Position}).
400 @defun window-total-height &optional window
401 This function returns the total height, in lines, of the window
402 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults
403 to the selected window.  If @var{window} is an internal window, the
404 return value is the total height occupied by its descendant windows.
405 @end defun
407 @defun window-total-width &optional window
408 This function returns the total width, in columns, of the window
409 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults
410 to the selected window.  If @var{window} is internal, the return value
411 is the total width occupied by its descendant windows.
412 @end defun
414 @defun window-total-size &optional window horizontal
415 This function returns either the total height or width of the window
416 @var{window}.  If @var{horizontal} is omitted or @code{nil}, this is
417 equivalent to calling @code{window-total-height} for @var{window};
418 otherwise it is equivalent to calling @code{window-total-width} for
419 @var{window}.
420 @end defun
422 @cindex full-width window
423 @cindex full-height window
424   The following functions can be used to determine whether a given
425 window has any adjacent windows.
427 @defun window-full-height-p &optional window
428 This function returns non-@code{nil} if @var{window} has no other
429 window above or below it in its frame, i.e. its total height equals
430 the total height of the root window on that frame.  If @var{window} is
431 omitted or @code{nil}, it defaults to the selected window.
432 @end defun
434 @defun window-full-width-p &optional window
435 This function returns non-@code{nil} if @var{window} has no other
436 window to the left or right in its frame, i.e. its total width equals
437 that of the root window on that frame.  If @var{window} is omitted or
438 @code{nil}, it defaults to the selected window.
439 @end defun
441 @cindex window position
442   The following functions can be used to determine the position of a
443 window relative to the window area of its frame:
445 @defun window-top-line &optional window
446 This function returns the distance, in lines, between the top of
447 @var{window} and the top of the frame's window area.  For instance,
448 the return value is 0 if there is no window above @var{window}.  If
449 @var{window} is omitted or @code{nil}, it defaults to the selected
450 window.
451 @end defun
453 @defun window-left-column &optional window
454 This function returns the distance, in columns, between the left edge
455 of @var{window} and the left edge of the frame's window area.  For
456 instance, the return value is 0 if there is no window to the left of
457 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults
458 to the selected window.
459 @end defun
461 @cindex window body height
462 @cindex body height of a window
463 @cindex window body width
464 @cindex body width of a window
465 @cindex body size of a window
466 @cindex window body size
467   The @dfn{body height} of a window is the height of its text area,
468 which does not include the mode or header line.  Similarly, the
469 @dfn{body width} is the width of the text area, which does not include
470 the scroll bar, fringes, or margins.
472 @defun window-body-height &optional window
473 This function returns the body height, in lines, of the window
474 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults
475 to the selected window; otherwise it must be a live window.
477 If there is a partially-visible line at the bottom of the text area,
478 that counts as a whole line; to exclude such a partially-visible line,
479 use @code{window-text-height}, below.
480 @end defun
482 @defun window-body-width &optional window
483 This function returns the body width, in columns, of the window
484 @var{window}.  If @var{window} is omitted or @code{nil}, it defaults
485 to the selected window; otherwise it must be a live window.
486 @end defun
488 @defun window-body-size &optional window horizontal
489 This function returns the body height or body width of @var{window}.
490 If @var{horizontal} is omitted or @code{nil}, it is equivalent to
491 calling @code{window-body-height} for @var{window}; otherwise it is
492 equivalent to calling @code{window-body-width}.
493 @end defun
495 @defun window-text-height &optional window
496 This function is like @code{window-body-height}, except that any
497 partially-visible line at the bottom of the text area is not counted.
498 @end defun
500   For compatibility with previous versions of Emacs,
501 @code{window-height} is an alias for @code{window-body-height}, and
502 @code{window-width} is an alias for @code{window-body-width}.  These
503 aliases are considered obsolete and will be removed in the future.
505 @cindex fixed-size window
506   Commands that change the size of windows (@pxref{Resizing Windows}),
507 or split them (@pxref{Splitting Windows}), obey the variables
508 @code{window-min-height} and @code{window-min-width}, which specify
509 the smallest allowable window height and width.  @xref{Change
510 Window,,Deleting and Rearranging Windows, emacs, The GNU Emacs
511 Manual}.  They also obey the variable @code{window-size-fixed}, with
512 which a window can be @dfn{fixed} in size:
514 @defvar window-size-fixed
515 If this buffer-local variable is non-@code{nil}, the size of any
516 window displaying the buffer cannot normally be changed.  Deleting a
517 window or changing the frame's size may still change its size, if
518 there is no choice.
520 If the value is @code{height}, then only the window's height is fixed;
521 if the value is @code{width}, then only the window's width is fixed.
522 Any other non-@code{nil} value fixes both the width and the height.
523 @end defvar
525 @defun window-size-fixed-p &optional window horizontal
526 This function returns a non-@code{nil} value if @var{window}'s height
527 is fixed.  If @var{window} is omitted or @code{nil}, it defaults to
528 the selected window.  If the optional argument @var{horizontal} is
529 non-@code{nil}, the return value is non-@code{nil} if @var{window}'s
530 width is fixed.
532 A @code{nil} return value does not necessarily mean that @var{window}
533 can be resized in the desired direction.  To determine that, use the
534 function @code{window-resizable}.  @xref{Resizing Windows}.
535 @end defun
538 @node Resizing Windows
539 @section Resizing Windows
540 @cindex window resizing
541 @cindex resize window
542 @cindex changing window size
543 @cindex window size, changing
545   This section describes functions for resizing a window without
546 changing the size of its frame.  Because live windows do not overlap,
547 these functions are meaningful only on frames that contain two or more
548 windows: resizing a window also changes the size of a neighboring
549 window.  If there is just one window on a frame, its size cannot be
550 changed except by resizing the frame (@pxref{Size and Position}).
552   Except where noted, these functions also accept internal windows as
553 arguments.  Resizing an internal window causes its child windows to be
554 resized to fit the same space.
556 @defun window-resizable window delta &optional horizontal ignore side noup nodown
557 This function returns @var{delta} if the size of @var{window} can be
558 changed vertically by @var{delta} lines.  If the optional argument
559 @var{horizontal} is non-@code{nil}, it instead returns @var{delta} if
560 @var{window} can be resized horizontally by @var{delta} columns.  It
561 does not actually change the window size.
563 If @var{window} is @code{nil}, it defaults to the selected window.
565 A positive value of @var{delta} enlarges the window by that number of
566 lines or columns; a negative value of @var{delta} shrinks it.  If
567 @var{delta} is non-zero, a return value of 0 means that the window
568 cannot be resized.
570 Normally, the variables @code{window-min-height} and
571 @code{window-min-width} specify the smallest allowable window size.
572 @xref{Change Window,, Deleting and Rearranging Windows, emacs, The GNU
573 Emacs Manual}.  However, if the optional argument @var{ignore} is
574 non-@code{nil}, this function ignores @code{window-min-height} and
575 @code{window-min-width}, as well as @code{window-size-fixed}.
576 Instead, it considers the minimum-height window to be one consisting
577 of a header (if any), a mode line, plus a text area one line tall; and
578 a minimum-width window as one consisting of fringes, margins, and
579 scroll bar (if any), plus a text area two columns wide.
581 If the optional argument @var{noup} is non-@code{nil}, this function
582 considers a resize operation that does not alter the window parent of
583 @var{window}, only its siblings.  If the optional argument
584 @var{nodown} is non-@code{nil}, it does not attempt to check whether
585 @var{window} itself and its child windows can be resized.
586 @end defun
588 @defun window-resize window delta &optional horizontal ignore
589 This function resizes @var{window} by @var{delta} increments.  If
590 @var{horizontal} is @code{nil}, it changes the height by @var{delta}
591 lines; otherwise, it changes the width by @var{delta} columns.  A
592 positive @var{delta} means to enlarge the window, and a negative
593 @var{delta} means to shrink it.
595 If @var{window} is @code{nil}, it defaults to the selected window.  If
596 the window cannot be resized as demanded, an error is signaled.
598 The optional argument @var{ignore} has the same meaning as for the
599 function @code{window-resizable} above.
601 The choice of which window edge this function alters depends on the
602 splitting and nesting status of the involved windows; in some cases,
603 it may alter both edges.  @xref{Splitting Windows}.  To resize by
604 moving only the bottom or right edge of a window, use the function
605 @code{adjust-window-trailing-edge}, below.
606 @end defun
608 @c The commands enlarge-window, enlarge-window-horizontally,
609 @c shrink-window, and shrink-window-horizontally are documented in the
610 @c Emacs manual.  They are not preferred for calling from Lisp.
612   The following function is useful for moving the line dividing two
613 windows.
615 @defun adjust-window-trailing-edge window delta &optional horizontal
616 This function moves @var{window}'s bottom edge by @var{delta} lines.
617 Optional argument @var{horizontal} non-@code{nil} means to move
618 @var{window}'s right edge by @var{delta} columns.  The argument
619 @var{window} defaults to the selected window.
621 If @var{delta} is greater zero, this moves the edge downwards or to the
622 right.  If @var{delta} is less than zero, this moves the edge upwards or
623 to the left. If the edge can't be moved by @var{delta} lines or columns,
624 it is moved as far as possible in the desired direction but no error is
625 signaled.
627 This function tries to resize windows adjacent to the edge that is
628 moved.  Only if this is insufficient, it will also resize windows not
629 adjacent to that edge.  As a consequence, if you move an edge in one
630 direction and back in the other direction by the same amount, the
631 resulting window configuration will not be necessarily identical to the
632 one before the first move.  So if your intend to just resize
633 @var{window}, you should not use this function but call
634 @code{window-resize} (see above) instead.
635 @end defun
637 @deffn Command fit-window-to-buffer &optional window max-height min-height override
638 This command makes @var{window} the right height to display its
639 contents exactly.  The default for @var{window} is the selected window.
641 The optional argument @var{max-height} specifies the maximum total
642 height the window is allowed to be; @code{nil} means use the maximum
643 permissible height of a window on @var{window}'s frame.  The optional
644 argument @var{min-height} specifies the minimum total height for the
645 window; @code{nil} means use @code{window-min-height}.  All these height
646 values include the mode line and/or header line.
648 If the optional argument @var{override} is non-@code{nil}, this means to
649 ignore any restrictions imposed by @code{window-min-height} and
650 @code{window-min-width} on the size of @var{window}.
652 This function returns non-@code{nil} if it orderly resized @var{window},
653 and @code{nil} otherwise.
654 @end deffn
656 @deffn Command shrink-window-if-larger-than-buffer &optional window
657 This command shrinks @var{window} vertically to be as small as possible
658 while still showing the full contents of its buffer---but not less than
659 @code{window-min-height} lines.  The argument @var{window} must denote
660 a live window and defaults to the selected one.
662 However, this command does nothing if the window is already too small to
663 display the whole text of the buffer, or if part of the contents are
664 currently scrolled off screen, or if the window is not the full width of
665 its frame, or if the window is the only window in its frame.
667 This command returns non-@code{nil} if it actually shrank the window
668 and @code{nil} otherwise.
669 @end deffn
671 @cindex balancing window sizes
672 Emacs provides two functions to balance windows, that is, to even out
673 the sizes of all windows on the same frame.  The minibuffer window and
674 fixed-size windows are not resized by these functions.
676 @deffn Command balance-windows &optional window-or-frame
677 This function balances windows in a way that gives more space to
678 full-width and/or full-height windows.  If @var{window-or-frame}
679 specifies a frame, it balances all windows on that frame.  If
680 @var{window-or-frame} specifies a window, it balances that window and
681 its siblings (@pxref{Windows and Frames}) only.
682 @end deffn
684 @deffn Command balance-windows-area
685 This function attempts to give all windows on the selected frame
686 approximately the same share of the screen area.  This means that
687 full-width or full-height windows are not given more space than other
688 windows.
689 @end deffn
691 @cindex maximizing windows
692 The following function can be used to give a window the maximum possible
693 size without deleting other ones.
695 @deffn Command maximize-window &optional window
696 This function maximizes @var{window}.  More precisely, this makes
697 @var{window} as large as possible without resizing its frame or deleting
698 other windows.  @var{window} can be any window and defaults to the
699 selected one.
700 @end deffn
702 @cindex minimizing windows
703 To make a window as small as possible without deleting it the
704 following function can be used.
706 @deffn Command minimize-window &optional window
707 This function minimizes @var{window}.  More precisely, this makes
708 @var{window} as small as possible without deleting it or resizing its
709 frame.  @var{window} can be any window and defaults to the selected one.
710 @end deffn
713 @node Splitting Windows
714 @section Splitting Windows
715 @cindex splitting windows
716 @cindex window splitting
718 The functions described below are the primitives needed for creating a
719 new window.  They do not accept a buffer as an argument.  Rather, they
720 ``split'' an existing window into two halves, both displaying the buffer
721 previously visible in the window that was split.
723 @deffn Command split-window &optional window size side
724 This function creates a new window adjacent to @var{window}.  It returns
725 the new window which is always a live window.  The argument @var{window}
726 can denote any window and defaults to the selected one.  This function
727 does not change the selected window.
729 Optional second argument @var{size} a positive number means make
730 @var{window} @var{size} lines (or columns) tall.  If @var{size} is
731 negative, make the new window @minus{}@var{size} lines (or columns)
732 tall.  If @var{size} is omitted or @code{nil}, then @var{window} is
733 divided evenly into two parts.  (If there is an odd line, it is
734 allocated to the new window.)
736 Normally, the customizable variables @code{window-min-height} and
737 @code{window-min-width} specify the smallest allowable size of a
738 window.  @xref{Change Window,,Deleting and Rearranging Windows, emacs,
739 The GNU Emacs Manual}.  If splitting would result in making a window
740 smaller than this, this function usually signals an error.  However,
741 if @var{size} is non-@code{nil} and valid, a new window of the
742 requested size is created, provided it has enough space for a text
743 area one line tall and/or two columns wide.
745 Optional third argument @var{side} @code{nil} (or @code{below})
746 specifies that the new window shall be located below @var{window}.  The
747 value @code{above} means the new window will be located above
748 @var{window}.  In both cases @var{size} specifies the new number of
749 lines for @var{window} (or the new window if @var{size} is negative)
750 including space reserved for the mode and/or header line.
752 If @var{side} is @code{t} or @code{right} the new window will be
753 positioned on the right side of @var{window}.  The value @code{left}
754 means the new window will be located on the left side of @var{window}.
755 In both cases @var{size} specifies the new number of columns for
756 @var{window} (or the new window provided @var{size} is negative)
757 including space reserved for margins, fringes and the scroll bar or a
758 divider column.
760 Any other non-@code{nil} value for @var{side} is currently handled like
761 @code{t} (or @code{right}).  Since this might change in the future,
762 application programs should refrain from using other values.
764 If @var{window} is live, properties of the new window like margins and
765 scroll bars are inherited from @var{window}.  If @var{window} is an
766 internal window, these properties, as well as the buffer shown in the
767 new window, are inherited from the window selected on @var{window}'s
768 frame.
770 If @code{ignore-window-parameters} is non-@code{nil}, this function
771 ignores window parameters (@pxref{Window Parameters}).  Otherwise, if
772 the @code{split-window} parameter of @var{window} is @code{t}, it splits
773 the window disregarding any other window parameters.  If the
774 @code{split-window} parameter specifies a function, that function is
775 called with the arguments @var{window}, @var{size}, and @var{side} to
776 split @var{window}.  If that function is @code{ignore}, nothing is done.
777 @end deffn
779 The following example starts with one window on a screen that is 50
780 lines high by 80 columns wide; then it splits the window.
782 @smallexample
783 @group
784 (setq W1 (selected-window))
785      @result{} #<window 8 on windows.texi>
786 (setq W2 (split-window W1 15))
787      @result{} #<window 28 on windows.texi>
788 @end group
789 @group
790 (window-top-line W1)
791      @result{} 0
792 (window-total-size W1)
793      @result{} 15
794 (window-top-line W2)
795      @result{} 15
796 @end group
797 @end smallexample
799 The screen looks like this:
801 @smallexample
802 @group
803          __________
804         |          |  line 0
805         |    W1    |
806         |__________|
807         |          |  line 15
808         |    W2    |
809         |__________|
810                       line 50
811  column 0   column 80
812 @end group
813 @end smallexample
815 Next, split the top window into two side-by-side windows:
817 @smallexample
818 @group
819 (setq W3 (split-window W1 35 t))
820      @result{} #<window 32 on windows.texi>
821 @end group
822 @group
823 (window-left-column W1)
824      @result{} 0
825 (window-total-size W1 t)
826      @result{} 35
827 (window-left-column W3)
828      @result{} 35
829 @end group
830 @end smallexample
832 @need 3000
833 Now the screen looks like this:
835 @smallexample
836 @group
837      column 35
838          __________
839         |    |     |  line 0
840         | W1 |  W3 |
841         |____|_____|
842         |          |  line 15
843         |    W2    |
844         |__________|
845                       line 50
846  column 0   column 80
847 @end group
848 @end smallexample
850 Normally, Emacs indicates the border between two side-by-side windows
851 with a scroll bar (@pxref{Scroll Bars}), or with @samp{|} characters.  The
852 display table can specify alternative border characters; see @ref{Display
853 Tables}.
855 Below we describe how @code{split-window} can be used to create the
856 window configuration from our earlier example (@pxref{Windows and
857 Frames}) and how internal windows are created for this purpose.  We
858 start with a frame containing one live window @code{W2} (in the
859 following scenarios window names are assigned in an arbitrary manner in
860 order to match the names of the example).  Evaluating the form
861 @code{(split-window W2 8 t)} creates a new internal window @code{W1}
862 with two children---@code{W2} (the window we've split) and a new leaf
863 window @code{W6}:
864 @smallexample
865 @group
866      ______________________________________
867     | ______  ____________________________ |
868     ||      ||                            ||
869     ||      ||                            ||
870     ||      ||                            ||
871     ||      ||                            ||
872     ||      ||                            ||
873     ||      ||                            ||
874     ||      ||                            ||
875     ||      ||                            ||
876     ||      ||                            ||
877     ||      ||                            ||
878     ||__W2__||_____________W6_____________ |
879     |__________________W1__________________|
881 @end group
882 @end smallexample
884 Evaluating now @code{(split-window W6 -3)} creates another internal
885 window @code{W3} with two children---@code{W6} and a new live window
886 @code{W5}.  This leaves us with a vertically combined window @code{W3}
887 embedded in the horizontally combined window @code{W1}:
888 @smallexample
889 @group
890      ______________________________________
891     | ______  ____________________________ |
892     ||      || __________________________ ||
893     ||      |||                          |||
894     ||      |||                          |||
895     ||      |||                          |||
896     ||      |||                          |||
897     ||      |||                          |||
898     ||      |||____________W6____________|||
899     ||      || __________________________ ||
900     ||      |||                          |||
901     ||      |||____________W5____________|||
902     ||__W2__||_____________W3_____________ |
903     |__________________W1__________________|
905 @end group
906 @end smallexample
908 Finally, evaluating @code{(split-window W6 nil t)} should get us the
909 desired configuration as depicted below.
910 @smallexample
911 @group
912      ______________________________________
913     | ______  ____________________________ |
914     ||      || __________________________ ||
915     ||      ||| ___________  ___________ |||
916     ||      ||||           ||           ||||
917     ||      ||||           ||           ||||
918     ||      ||||_____W6____||_____W7____||||
919     ||      |||____________W4____________|||
920     ||      || __________________________ ||
921     ||      |||                          |||
922     ||      |||____________W5____________|||
923     ||__W2__||_____________W3_____________ |
924     |__________________W1__________________|
926 @end group
927 @end smallexample
929 The scenario sketched above is the standard way to obtain the desired
930 configuration.  In Emacs 23 it was also the only way to do that since
931 Emacs 23 didn't allow splitting internal windows.
933 With Emacs 24 you can also proceed as follows: Split an initial window
934 @code{W6} by evaluating @code{(split-window W6 -3)} to produce the
935 following vertical combination:
936 @smallexample
937 @group
938      ______________________________________
939     | ____________________________________ |
940     ||                                    ||
941     ||                                    ||
942     ||                                    ||
943     ||                                    ||
944     ||                                    ||
945     ||                                    ||
946     ||                                    ||
947     ||_________________W6_________________||
948     | ____________________________________ |
949     ||                                    ||
950     ||_________________W5_________________||
951     |__________________W3__________________|
953 @end group
954 @end smallexample
956 Evaluating now @code{(split-window (window-parent W6) -8 'left)} or,
957 equivalently, @code{(split-window W3 -8 'left)} should now produce the
958 penultimate configuration from the previous scenario from where we can
959 continue as described before.
961    Another strategy starts with splitting an initial window @code{W6} by
962 evaluating @code{(split-window W6 nil nil t)} with the following result:
963 @smallexample
964 @group
965      ______________________________________
966     | _________________  _________________ |
967     ||                 ||                 ||
968     ||                 ||                 ||
969     ||                 ||                 ||
970     ||                 ||                 ||
971     ||                 ||                 ||
972     ||                 ||                 ||
973     ||                 ||                 ||
974     ||                 ||                 ||
975     ||                 ||                 ||
976     ||                 ||                 ||
977     ||________W6_______||________W7_______||
978     |__________________W4__________________|
980 @end group
981 @end smallexample
983 Evaluating now @code{(split-window W4 -3)} or @code{(split-window
984 (window-parent W6) -3)} should get us a configuration as shown next.
985 @smallexample
986 @group
987      ______________________________________
988     | ____________________________________ |
989     || ________________  ________________ ||
990     |||                ||                |||
991     |||                ||                |||
992     |||                ||                |||
993     |||                ||                |||
994     |||                ||                |||
995     |||_______W6_______||________W7______|||
996     ||_________________W4_________________||
997     | ____________________________________ |
998     ||                                    ||
999     ||_________________W5_________________||
1000     |__________________W3__________________|
1002 @end group
1003 @end smallexample
1005 The desired configuration can be now obtained by evaluating
1006 @code{(split-window W3 -8 'left)} or, equivalently, @code{(split-window
1007 (window-parent W5) -8 'left)}.
1009    For a final approach let's start with the configuration of two live
1010 windows @code{W6} and @code{W7} shown above.  If we now evaluate
1011 @code{(split-window W4 -8 'left)} or @code{(split-window (window-parent
1012 W6) -8 'left)} we get the following configuration.
1013 @smallexample
1014 @group
1015      ______________________________________
1016     | ______  ____________________________ |
1017     ||      || ____________  ____________ ||
1018     ||      |||            ||            |||
1019     ||      |||            ||            |||
1020     ||      |||            ||            |||
1021     ||      |||            ||            |||
1022     ||      |||            ||            |||
1023     ||      |||            ||            |||
1024     ||      |||            ||            |||
1025     ||      |||______W6____||______W7____|||
1026     ||__W2__||_____________W4_____________||
1027     |__________________W1__________________|
1029 @end group
1030 @end smallexample
1032 Evaluating now @code{(split-window W4 -3)} or, for example,
1033 @code{(split-window (window-parent W6) -3)} should produce the desired
1034 configuration.
1036   The two options described next can be used to tune the operation of
1037 @code{split-window}.
1039 @defopt window-splits
1040 If this variable is @code{nil}, the function @code{split-window} can
1041 split a window if and only if that window's screen estate is
1042 sufficiently large to accommodate both--itself and the new window.
1044 If this variable is non-@code{nil}, @code{split-window} tries to resize
1045 all windows that are part of the same combination as the old window to
1046 accommodate the new window.  Hence, the new window can be also created if
1047 the old window is of fixed size or too small to split (@pxref{Window
1048 Sizes}).
1050 In any case, the value of this variable is assigned to the splits status
1051 of the new window and, provided old and new window form a new
1052 combination, of the old window as well.  The splits status of a window
1053 can be retrieved by invoking the function @code{window-splits} and
1054 altered by the function @code{set-window-splits} described next.
1056 If @code{window-nest} (see below) is non-@code{nil}, the space for the
1057 new window is exclusively taken from the old window, but the splits
1058 status of the involved windows is nevertheless set as described here.
1059 @end defopt
1061 @defun window-splits &optional window
1062 This function returns the splits status of @var{window}.  The argument
1063 @var{window} can be any window and defaults to the selected one.
1065 @cindex splits status
1066 The @dfn{splits status} of a window specifies how resizing and deleting
1067 that window may affect the size of other windows in the same window
1068 combination.  More precisely, if @var{window}'s splits status is
1069 @code{nil} and @var{window} is resized, the corresponding space is
1070 preferably taken from (or given to) @var{window}'s right sibling.  When
1071 @var{window} is deleted, its space is given to its left sibling.  If
1072 @var{window}'s splits status is non-@code{nil}, resizing and deleting
1073 @var{window} may resize @emph{all} windows in @var{window}'s
1074 combination.
1076 The splits status is initially set by @code{split-window}
1077 from the current value of the variable @code{window-splits} (see above)
1078 and can be reset by the function @code{set-window-splits} (see below).
1079 @end defun
1081 @defun set-window-splits window &optional status
1082 This function sets the splits status (see above) of @var{window} to
1083 @var{status}.  The argument @var{window} can be any window and defaults
1084 to the selected one.  The return value is @var{status}.
1085 @end defun
1087 To illustrate the use of @code{window-splits} consider the following
1088 window configuration:
1089 @smallexample
1090 @group
1091      ______________________________________
1092     | ____________________________________ |
1093     ||                                    ||
1094     ||                                    ||
1095     ||                                    ||
1096     ||                                    ||
1097     ||_________________W2_________________||
1098     | ____________________________________ |
1099     ||                                    ||
1100     ||                                    ||
1101     ||                                    ||
1102     ||                                    ||
1103     ||_________________W3_________________||
1104     |__________________W1__________________|
1106 @end group
1107 @end smallexample
1109 Splitting window @code{W3} with @code{window-splits} @code{nil}
1110 produces a configuration where the size of @code{W2} remains unchanged:
1111 @smallexample
1112 @group
1113      ______________________________________
1114     | ____________________________________ |
1115     ||                                    ||
1116     ||                                    ||
1117     ||                                    ||
1118     ||                                    ||
1119     ||_________________W2_________________||
1120     | ____________________________________ |
1121     ||                                    ||
1122     ||_________________W3_________________||
1123     | ____________________________________ |
1124     ||                                    ||
1125     ||_________________W4_________________||
1126     |__________________W1__________________|
1128 @end group
1129 @end smallexample
1131 Splitting @code{W3} with @code{window-splits} non-@code{nil} instead
1132 produces a configuration where all windows have approximately the same
1133 height:
1135 @smallexample
1136 @group
1137      ______________________________________
1138     | ____________________________________ |
1139     ||                                    ||
1140     ||                                    ||
1141     ||_________________W2_________________||
1142     | ____________________________________ |
1143     ||                                    ||
1144     ||                                    ||
1145     ||_________________W3_________________||
1146     | ____________________________________ |
1147     ||                                    ||
1148     ||                                    ||
1149     ||_________________W4_________________||
1150     |__________________W1__________________|
1152 @end group
1153 @end smallexample
1155 @defopt window-nest
1156 If this variable is @code{nil}, @code{split-window} creates a new parent
1157 window if and only if the old window has no parent window or shall be
1158 split orthogonally to the combination it is part of.  If this variable
1159 is non-@code{nil}, @code{split-window} always creates a new parent
1160 window.  If this variable is always non-@code{nil}, a frame's window
1161 tree is a binary tree so every window but the frame's root window has
1162 exactly one sibling.
1164 The value of this variable is also assigned to the nest status of the
1165 new parent window.  The nest status of any window can be retrieved via
1166 the function @code{window-nest} and altered by the function
1167 @code{set-window-nest}, see below.
1168 @end defopt
1170 @defun window-nest &optional window
1171 This function returns the nest status of @var{window}.  The argument
1172 @var{window} can be any window and defaults to the selected one.  Note,
1173 however, that the nest status is currently meaningful for internal
1174 windows only.
1176 @cindex nest status
1177 The @dfn{nest status} of a window specifies whether that window may be
1178 removed and its child windows recombined with that window's siblings
1179 when such a sibling's child window is deleted.  The nest status is
1180 initially assigned by @code{split-window} from the current value of the
1181 variable @code{window-nest} (see above) and can be reset by the function
1182 @code{set-window-nest} (see below).
1184 If the return value is @code{nil}, child windows of @var{window} may be
1185 recombined with @var{window}'s siblings when a window gets deleted.  A
1186 return value of @code{nil} means that child windows of @var{window} are
1187 never (re-)combined with @var{window}'s siblings in such a case.
1188 @end defun
1190 @defun set-window-nest window &optional status
1191 This functions sets the nest status (see above) of @var{window} to
1192 @var{status}.  The argument @var{window} can be any window and defaults
1193 to the selected one.  Note that setting the nest status is meaningful
1194 for internal windows only.  The return value is @var{status}.
1195 @end defun
1197 To illustrate the use of @code{window-nest} consider the following
1198 configuration (throughout the following examples we shall assume that
1199 @code{window-splits} invariantly is @code{nil}).
1200 @smallexample
1201 @group
1202      ______________________________________
1203     | ____________________________________ |
1204     ||                                    ||
1205     ||                                    ||
1206     ||                                    ||
1207     ||                                    ||
1208     ||                                    ||
1209     ||                                    ||
1210     ||_________________W2_________________||
1211     | ____________________________________ |
1212     ||                                    ||
1213     ||                                    ||
1214     ||_________________W3_________________||
1215     |__________________W1__________________|
1217 @end group
1218 @end smallexample
1220 Splitting @code{W2} into two windows above each other with
1221 @code{window-nest} equal @code{nil} will get you a configuration like:
1222 @smallexample
1223 @group
1224      ______________________________________
1225     | ____________________________________ |
1226     ||                                    ||
1227     ||                                    ||
1228     ||_________________W2_________________||
1229     | ____________________________________ |
1230     ||                                    ||
1231     ||                                    ||
1232     ||_________________W4_________________||
1233     | ____________________________________ |
1234     ||                                    ||
1235     ||                                    ||
1236     ||_________________W3_________________||
1237     |__________________W1__________________|
1239 @end group
1240 @end smallexample
1242 If you now enlarge window @code{W4}, Emacs steals the necessary space
1243 from window @code{W3} resulting in a configuration like:
1244 @smallexample
1245 @group
1246      ______________________________________
1247     | ____________________________________ |
1248     ||                                    ||
1249     ||                                    ||
1250     ||_________________W2_________________||
1251     | ____________________________________ |
1252     ||                                    ||
1253     ||                                    ||
1254     ||                                    ||
1255     ||_________________W4_________________||
1256     | ____________________________________ |
1257     ||                                    ||
1258     ||_________________W3_________________||
1259     |__________________W1__________________|
1261 @end group
1262 @end smallexample
1264 Deleting window @code{W4}, will return its space to @code{W2} as
1265 follows:
1266 @smallexample
1267 @group
1268      ______________________________________
1269     | ____________________________________ |
1270     ||                                    ||
1271     ||                                    ||
1272     ||                                    ||
1273     ||                                    ||
1274     ||                                    ||
1275     ||                                    ||
1276     ||                                    ||
1277     ||_________________W2_________________||
1278     | ____________________________________ |
1279     ||                                    ||
1280     ||_________________W3_________________||
1281     |__________________W1__________________|
1283 @end group
1284 @end smallexample
1286 Hence, with respect to the initial configuration, window @code{W2} has
1287 grown at the expense of window @code{W3}.  If, however, in the initial
1288 configuration you had split @code{W2} with @code{window-nest} bound to
1289 @code{t}, a new internal window @code{W5} would have been created as
1290 depicted below.
1291 @smallexample
1292 @group
1293      ______________________________________
1294     | ____________________________________ |
1295     || __________________________________ ||
1296     |||                                  |||
1297     |||________________W2________________|||
1298     || __________________________________ ||
1299     |||                                  |||
1300     |||________________W4________________|||
1301     ||_________________W5_________________||
1302     | ____________________________________ |
1303     ||                                    ||
1304     ||                                    ||
1305     ||_________________W3_________________||
1306     |__________________W1__________________|
1308 @end group
1309 @end smallexample
1311 Enlarging @code{W4} would now have stolen the necessary space from
1312 @code{W2} instead of @code{W3} as
1313 @smallexample
1314 @group
1315      ______________________________________
1316     | ____________________________________ |
1317     || __________________________________ ||
1318     |||________________W2________________|||
1319     || __________________________________ ||
1320     |||                                  |||
1321     |||                                  |||
1322     |||________________W4________________|||
1323     ||_________________W5_________________||
1324     | ____________________________________ |
1325     ||                                    ||
1326     ||                                    ||
1327     ||_________________W3_________________||
1328     |__________________W1__________________|
1330 @end group
1331 @end smallexample
1333 and the subsequent deletion of @code{W4} would have restored the initial
1334 configuration.
1336 For interactive use, Emacs provides two commands which always split the
1337 selected window.
1339 @deffn Command split-window-below &optional size
1340 This function splits the selected window into two windows, one above the
1341 other, leaving the upper of the two windows selected, with @var{size}
1342 lines.  (If @var{size} is negative, then the lower of the two windows
1343 gets @minus{}@var{size} lines and the upper window gets the rest, but
1344 the upper window is still the one selected.)  However, if
1345 @code{split-window-keep-point} (see below) is @code{nil}, then either
1346 window can be selected.
1348    In other respects, this function is similar to @code{split-window}.
1349 In particular, the upper window is the original one and the return value
1350 is the new, lower window.
1351 @end deffn
1353 @defopt split-window-keep-point
1354 If this variable is non-@code{nil} (the default), then
1355 @code{split-window-below} behaves as described above.
1357    If it is @code{nil}, then @code{split-window-below} adjusts point
1358 in each of the two windows to avoid scrolling.  (This is useful on
1359 slow terminals.)  It selects whichever window contains the screen line
1360 that point was previously on.  Other functions are not affected by
1361 this variable.
1362 @end defopt
1364 @deffn Command split-window-right &optional size
1365 This function splits the selected window into two windows
1366 side-by-side, leaving the selected window on the left with @var{size}
1367 columns.  If @var{size} is negative, the rightmost window gets
1368 @minus{}@var{size} columns, but the leftmost window still remains
1369 selected.
1370 @end deffn
1373 @node Deleting Windows
1374 @section Deleting Windows
1375 @cindex deleting windows
1377 A window remains visible on its frame unless you @dfn{delete} it by
1378 calling certain functions that delete windows.  A deleted window cannot
1379 appear on the screen, but continues to exist as a Lisp object until
1380 there are no references to it.  There is no way to cancel the deletion
1381 of a window aside from restoring a saved window configuration
1382 (@pxref{Window Configurations}).  Restoring a window configuration also
1383 deletes any windows that aren't part of that configuration.  Erroneous
1384 information may result from using a deleted window as if it were live.
1386 @deffn Command delete-window &optional window
1387 This function removes @var{window} from display and returns @code{nil}.
1388 The argument @var{window} can denote any window and defaults to the
1389 selected one.  An error is signaled if @var{window} is the only window
1390 on its frame.  Hence @var{window} must have at least one sibling window
1391 (@pxref{Windows and Frames}) in order to get deleted.  If @var{window}
1392 is the selected window on its frame, this function selects the most
1393 recently selected live window on that frame instead.
1395 If the variable @code{ignore-window-parameters} (@pxref{Window
1396 Parameters}) is non-@code{nil}, this function ignores all parameters of
1397 @var{window}.  Otherwise, if the @code{delete-window} parameter of
1398 @var{window} is @code{t}, it deletes the window disregarding other
1399 window parameters.  If the @code{delete-window} parameter specifies a
1400 function, that function is called with @var{window} as its sole
1401 argument.
1403 If the splits status of @var{window} (@pxref{Splitting Windows}) is
1404 @code{nil}, the space @var{window} took up is given to its left sibling
1405 if such a window exists and to its right sibling otherwise.  If the
1406 splits status of @var{window} is non-@code{nil}, its space is
1407 proportionally distributed among the remaining windows in the same
1408 combination.
1409 @end deffn
1411 @deffn Command delete-other-windows &optional window
1412 This function makes @var{window} fill its frame and returns @code{nil}.
1413 The argument @var{window} can denote an arbitrary window and defaults to
1414 the selected one.  Upon exit, @var{window} will be the selected window
1415 on its frame.
1417 If the variable @code{ignore-window-parameters} (@pxref{Window
1418 Parameters}) is non-@code{nil}, this function ignores all parameters of
1419 @var{window}.  Otherwise, if the @code{delete-other-windows} parameter
1420 of @var{window} equals @code{t}, it deletes all other windows
1421 disregarding any remaining window parameters.  If the
1422 @code{delete-other-windows} parameter of @var{window} specifies a
1423 function, it calls that function with @var{window} as its sole argument.
1424 @end deffn
1426 @deffn Command delete-windows-on &optional buffer-or-name frame
1427 This function deletes all windows showing @var{buffer-or-name}.  If
1428 there are no windows showing @var{buffer-or-name}, it does nothing.
1429 The optional argument @var{buffer-or-name} may be a buffer or the name
1430 of an existing buffer and defaults to the current buffer.  Invoking
1431 this command on a minibuffer signals an error.
1433 The function @code{delete-windows-on} operates by calling
1434 @code{delete-window} for each window showing @var{buffer-or-name}.  If a
1435 frame has several windows showing different buffers, then those showing
1436 @var{buffer-or-name} are removed, and the other windows expand to fill
1437 the space.
1439 If all windows in some frame are showing @var{buffer-or-name} (including
1440 the case where there is only one window), then that frame is deleted
1441 provided there are other frames left.
1443 The optional argument @var{frame} specifies which frames to operate on.
1444 This function does not use it in quite the same way as the other
1445 functions which scan all live windows (@pxref{Cyclic Window Ordering});
1446 specifically, the values @code{t} and @code{nil} have the opposite of
1447 their meanings in the other functions.  Here are the full details:
1449 @itemize @bullet
1450 @item @code{nil}
1451 means operate on all frames.
1452 @item @code{t}
1453 means operate on the selected frame.
1454 @item @code{visible}
1455 means operate on all visible frames.
1456 @item @code{0}
1457 means operate on all visible or iconified frames.
1458 @item A frame
1459 means operate on that frame.
1460 @end itemize
1461 @end deffn
1464 @node Selecting Windows
1465 @section Selecting Windows
1466 @cindex selecting a window
1468 @defun select-window window &optional norecord
1469 This function makes @var{window} the selected window, see @ref{Basic
1470 Windows}.  Unless @var{window} already is the selected window, this also
1471 makes @var{window}'s buffer (@pxref{Buffers and Windows}) the current
1472 buffer.  Moreover, the cursor for selected windows will be displayed in
1473 @var{window} after the next redisplay.  This function returns
1474 @var{window}.
1476 Normally, @var{window}'s selected buffer is moved to the front of the
1477 buffer list (@pxref{The Buffer List}) and @var{window} becomes the most
1478 recently selected window.  But if the optional argument @var{norecord}
1479 is non-@code{nil}, the buffer list remains unchanged and @var{window}
1480 does not become the most recently selected one.
1481 @end defun
1483 @cindex most recently selected windows
1484 The sequence of calls to @code{select-window} with a non-@code{nil}
1485 @var{norecord} argument determines an ordering of windows by their
1486 selection time.  The function @code{get-lru-window} can be used to
1487 retrieve the least recently selected live window in this ordering, see
1488 @ref{Cyclic Window Ordering}.
1490 @defmac save-selected-window forms@dots{}
1491 This macro records the selected frame, as well as the selected window
1492 of each frame, executes @var{forms} in sequence, then restores the
1493 earlier selected frame and windows.  It also saves and restores the
1494 current buffer.  It returns the value of the last form in @var{forms}.
1496 This macro does not save or restore anything about the sizes,
1497 arrangement or contents of windows; therefore, if @var{forms} change
1498 them, the change persists.  If the previously selected window of some
1499 frame is no longer live at the time of exit from @var{forms}, that
1500 frame's selected window is left alone.  If the previously selected
1501 window is no longer live, then whatever window is selected at the end of
1502 @var{forms} remains selected.  The current buffer is restored if and
1503 only if it is still live when exiting @var{forms}.
1505 This macro changes neither the ordering of recently selected windows nor
1506 the buffer list.
1507 @end defmac
1509 @defmac with-selected-window window forms@dots{}
1510 This macro selects @var{window}, executes @var{forms} in sequence, then
1511 restores the previously selected window and current buffer.  The ordering
1512 of recently selected windows and the buffer list remain unchanged unless
1513 you deliberately change them within @var{forms}, for example, by calling
1514 @code{select-window} with argument @var{norecord} @code{nil}.
1516 The order of recently selected windows and the buffer list are not
1517 changed by this macro.
1518 @end defmac
1520 @cindex frame selected window
1521 @cindex window selected within frame
1522 Earlier (@pxref{Basic Windows}) we mentioned that at any time, exactly
1523 one window on any frame is selected within the frame.  The significance
1524 of this designation is that selecting the frame also selects this
1525 window.  Conversely, selecting a window for Emacs with
1526 @code{select-window} also makes that window selected within its frame.
1528 @defun frame-selected-window  &optional frame
1529 This function returns the window on @var{frame} that is selected within
1530 @var{frame}.  The optional argument @var{frame} must denote a live frame
1531 and defaults to the selected one.
1532 @end defun
1534 @defun set-frame-selected-window frame window &optional norecord
1535 This function sets the selected window of frame @var{frame} to
1536 @var{window}.  The argument @var{frame} must denote a live frame and
1537 defaults to the selected one.  If @var{frame} is the selected frame,
1538 this also makes @var{window} the selected window.  The argument
1539 @var{window} must denote a live window.  This function returns
1540 @var{window}.
1542 Optional argument @var{norecord} non-@code{nil} means to neither change
1543 the list of most recently selected windows (@pxref{Selecting Windows})
1544 nor the buffer list (@pxref{The Buffer List}).
1545 @end defun
1548 @node Cyclic Window Ordering
1549 @section Cyclic Ordering of Windows
1550 @cindex cyclic ordering of windows
1551 @cindex ordering of windows, cyclic
1552 @cindex window ordering, cyclic
1554 When you use the command @kbd{C-x o} (@code{other-window}) to select
1555 some other window, it moves through live windows in a specific order.
1556 For any given configuration of windows, this order never varies.  It is
1557 called the @dfn{cyclic ordering of windows}.
1559    For a particular frame, this ordering is determined by the window
1560 tree of that frame, see @ref{Windows and Frames}.  More precisely, the
1561 ordering is obtained by a depth-first traversal of the frame's window
1562 tree supplemented, if requested, by the frame's minibuffer window.
1564    If there's just one live frame, the cyclic ordering is the ordering
1565 for that frame.  Otherwise, the cyclic ordering is obtained by appending
1566 the orderings for individual frames in order of the list of all live
1567 frames, @ref{Finding All Frames}.  In any case, the ordering is made
1568 ``cyclic'' by having the last window precede the first window in the
1569 ordering.
1571 @defun next-window &optional window minibuf all-frames
1572 @cindex minibuffer window, and @code{next-window}
1573 This function returns the window following @var{window} in the cyclic
1574 ordering of windows.  The argument @var{window} must specify a live
1575 window and defaults to the selected one.
1577 The optional argument @var{minibuf} specifies whether minibuffer windows
1578 shall be included in the cyclic ordering.  Normally, when @var{minibuf}
1579 is @code{nil}, a minibuffer window is included only if it is currently
1580 ``active''; this matches the behavior of @kbd{C-x o}.  (Note that a
1581 minibuffer window is active as long as its minibuffer is in use; see
1582 @ref{Minibuffers}).
1584 If @var{minibuf} is @code{t}, the cyclic ordering includes all
1585 minibuffer windows.  If @var{minibuf} is neither @code{t} nor
1586 @code{nil}, minibuffer windows are not included even if they are active.
1588 The optional argument @var{all-frames} specifies which frames to
1589 consider.  Here are the possible values and their meanings:
1591 @itemize @bullet
1592 @item @code{nil}
1593 means consider all windows on @var{window}'s frame, plus the minibuffer
1594 window used by that frame even if it lies in some other frame.  If the
1595 minibuffer counts (as determined by @var{minibuf}), then all windows on
1596 all frames that share that minibuffer count too.
1598 @item @code{t}
1599 means consider all windows on all existing frames.
1601 @item @code{visible}
1602 means consider all windows on all visible frames.  (To get useful
1603 results, ensure that @var{window} is on a visible frame.)
1605 @item 0
1606 means consider all windows on all visible or iconified frames.
1608 @item A frame
1609 means consider all windows on that frame.
1611 @item Anything else
1612 means consider the windows on @var{window}'s frame, and no others.
1613 @end itemize
1615 This example assumes there are two windows, both displaying the
1616 buffer @samp{windows.texi}:
1618 @example
1619 @group
1620 (selected-window)
1621      @result{} #<window 56 on windows.texi>
1622 @end group
1623 @group
1624 (next-window (selected-window))
1625      @result{} #<window 52 on windows.texi>
1626 @end group
1627 @group
1628 (next-window (next-window (selected-window)))
1629      @result{} #<window 56 on windows.texi>
1630 @end group
1631 @end example
1632 @end defun
1634 @defun previous-window &optional window minibuf all-frames
1635 This function returns the window preceding @var{window} in the cyclic
1636 ordering of windows.  The other arguments specify which windows to
1637 consider as in @code{next-window}.
1638 @end defun
1640 @deffn Command other-window count &optional all-frames
1641 This function selects another window in the cyclic ordering of windows.
1642 @var{count} specifies the number of windows to skip in the ordering,
1643 starting with the selected window, before making the selection.  If
1644 @var{count} is a positive number, it skips @var{count} windows forwards.
1645 @var{count} negative means skip @minus{}@var{count} windows backwards.
1646 If @var{count} is zero, it does not skip any window, thus re-selecting
1647 the selected window.  In an interactive call, @var{count} is the numeric
1648 prefix argument.
1650 The optional argument @var{all-frames} has the same meaning as in
1651 @code{next-window}, but the @var{minibuf} argument of @code{next-window}
1652 is always effectively @code{nil}.  This function returns @code{nil}.
1654 This function does not select a window that has a non-@code{nil}
1655 @code{no-other-window} window parameter (@pxref{Window Parameters}).
1656 @end deffn
1658 The following function returns a copy of the list of windows in the
1659 cyclic ordering.
1661 @defun window-list-1 &optional window &optional minibuf &optional all_frames
1662 This function returns a list of live windows.  The optional arguments
1663 @var{minibuf} and @var{all-frames} specify the set of windows to include
1664 in the list.  See the description of @code{next-window} for details.
1666 The optional argument @var{window} specifies the first window to list
1667 and defaults to the selected window.  If @var{window} is not on the list
1668 of windows returned, some other window will be listed first but no error
1669 is signaled.
1670 @end defun
1672 The functions described below use @code{window-list-1} for generating a
1673 copy of the list of all relevant windows.  Hence, any change of the
1674 window configuration that occurs while one of these functions is
1675 executed is @emph{not} reflected in the list of windows investigated.
1677 @defun walk-windows proc &optional minibuf all-frames
1678 This function cycles through live windows.  It calls the function
1679 @var{proc} once for each window, with the window as its sole argument.
1681 The optional arguments @var{minibuf} and @var{all-frames} specify the
1682 set of windows to include in the walk, see @code{next-window} above.  If
1683 @var{all-frames} specifies a frame, the first window walked is the first
1684 window on that frame as returned by @code{frame-first-window} and not
1685 necessarily the selected window.
1687 If @var{proc} changes the window configuration by splitting or deleting
1688 windows, that change is not reflected in the set of windows walked.
1689 That set is determined entirely by the set of live windows at the time
1690 this function was invoked.
1691 @end defun
1693 The following function allows to determine whether a specific window is
1694 the only live window.
1696 @defun one-window-p &optional no-mini all-frames
1697 This function returns non-@code{nil} if the selected window is the only
1698 window.
1700 The optional argument @var{no-mini}, if non-@code{nil}, means don't
1701 count the minibuffer even if it is active; otherwise, the minibuffer
1702 window is counted when it is active.  The optional argument
1703 @var{all-frames} has the same meaning as for @code{next-window}, see
1704 above.
1705 @end defun
1707 @cindex finding windows
1708   The following functions choose (but do not select) one of the windows
1709 on the screen, offering various criteria for the choice.
1711 @cindex least recently used window
1712 @defun get-lru-window &optional all-frames dedicated
1713 This function returns the window least recently ``used'' (that is,
1714 selected).  If any full-width windows are present, it only considers
1715 these.  The optional argument @var{all-frames} has the same meaning as
1716 in @code{next-window}.
1718 The selected window is returned if it is the only candidate.  A
1719 minibuffer window is never a candidate.  A dedicated window
1720 (@pxref{Dedicated Windows}) is never a candidate unless the optional
1721 argument @var{dedicated} is non-@code{nil}.
1722 @end defun
1724 @cindex largest window
1725 @defun get-largest-window &optional all-frames dedicated
1726 This function returns the window with the largest area (height times
1727 width).  A minibuffer window is never a candidate.  A dedicated window
1728 (@pxref{Dedicated Windows}) is never a candidate unless the optional
1729 argument @var{dedicated} is non-@code{nil}.
1731 If there are two candidate windows of the same size, this function
1732 prefers the one that comes first in the cyclic ordering of windows,
1733 starting from the selected window.
1735 The optional argument @var{all-frames} specifies which set of windows to
1736 consider as with @code{next-window}, see above.
1737 @end defun
1739 @cindex window that satisfies a predicate
1740 @cindex conditional selection of windows
1741 @defun get-window-with-predicate predicate &optional minibuf all-frames default
1742 This function returns a window satisfying @var{predicate}.  It cycles
1743 through all visible windows calling @var{predicate} on each one of them
1744 with that window as its argument.  The function returns the first window
1745 for which @var{predicate} returns a non-@code{nil} value; if that never
1746 happens, it returns @var{default} (which defaults to @code{nil}).
1748 The optional arguments @var{minibuf} and @var{all-frames} specify the
1749 set of windows to investigate.  See the description of
1750 @code{next-window} for details.
1751 @end defun
1753 @node Buffers and Windows
1754 @section Buffers and Windows
1755 @cindex examining windows
1756 @cindex windows, controlling precisely
1757 @cindex buffers, controlled in windows
1759 To find out which buffer is displayed in a given window the following
1760 function is used.
1762 @defun window-buffer &optional window
1763 This function returns the buffer that @var{window} is displaying.  The
1764 argument @var{window} can be any window and defaults to the selected
1765 one.  If @var{window} is an internal window, this function returns
1766 @code{nil}.
1767 @end defun
1769 The basic, low-level function to associate a window with a buffer is
1770 @code{set-window-buffer}.  Higher-level functions like
1771 @code{switch-to-buffer} and @code{display-buffer} try to obey a number
1772 of user customizations regulating which windows are supposed to
1773 display which buffers.  @xref{Switching Buffers}.  When writing an
1774 application, you should avoid using @code{set-window-buffer} unless
1775 you are sure you need it.
1777 @defun set-window-buffer window buffer-or-name &optional keep-margins
1778 This function makes @var{window} display @var{buffer-or-name} and
1779 returns @code{nil}.  The argument @var{window} has to denote a live
1780 window and defaults to the selected one.  The argument
1781 @var{buffer-or-name} must specify a buffer or the name of an existing
1782 buffer.  An error is signaled when @var{window} is @dfn{strongly}
1783 dedicated to its buffer (@pxref{Dedicated Windows}) and does not already
1784 display @var{buffer-or-name}.
1786 Normally, displaying @var{buffer-or-name} in @var{window} resets the
1787 window's position, display margins, fringe widths, and scroll bar
1788 settings based on the local variables of the specified buffer.  However,
1789 if the optional argument @var{keep-margins} is non-@code{nil}, display
1790 margins and fringe widths of @var{window} remain unchanged.
1791 @xref{Fringes}.
1793 This function is the fundamental primitive for changing which buffer is
1794 displayed in a window, and all ways of doing that call this function.
1795 Neither the selected window nor the current buffer are changed by this
1796 function.
1798 This function runs @code{window-scroll-functions} before running
1799 @code{window-configuration-change-hook}, see @ref{Window Hooks}.
1800 @end defun
1802 @defvar buffer-display-count
1803 This buffer-local variable records the number of times a buffer has been
1804 displayed in a window.  It is incremented each time
1805 @code{set-window-buffer} is called for the buffer.
1806 @end defvar
1808 @defvar buffer-display-time
1809 This variable records the time at which a buffer was last made visible
1810 in a window.  It is always local in each buffer; each time
1811 @code{set-window-buffer} is called, it sets this variable to
1812 @code{(current-time)} in the specified buffer (@pxref{Time of Day}).
1813 When a buffer is first created, @code{buffer-display-time} starts out
1814 with the value @code{nil}.
1815 @end defvar
1817 @defun get-buffer-window &optional buffer-or-name all-frames
1818 This function returns a window displaying @var{buffer-or-name}, or
1819 @code{nil} if there is none.  If there are several such windows, then
1820 the function returns the first one in the cyclic ordering of windows,
1821 starting from the selected window, @xref{Cyclic Window Ordering}.
1823 The argument @var{buffer-or-name} may be a buffer or a buffer name and
1824 defaults to the current buffer.  The optional argument @var{all-frames}
1825 specifies which windows to consider:
1827 @itemize @bullet
1828 @item
1829 @code{nil} means consider windows on the selected frame.
1830 @item
1831 @code{t} means consider windows on all existing frames.
1832 @item
1833 @code{visible} means consider windows on all visible frames.
1834 @item
1835 0 means consider windows on all visible or iconified frames.
1836 @item
1837 A frame means consider windows on that frame only.
1838 @end itemize
1840 Observe that the behavior of @code{get-buffer-window} may differ from
1841 that of @code{next-window} (@pxref{Cyclic Window Ordering}) when
1842 @var{all-frames} equals @code{nil} or any value not listed here.
1843 Perhaps we will change @code{get-buffer-window} in the future to make it
1844 compatible with the other functions.
1845 @end defun
1847 @defun get-buffer-window-list &optional buffer-or-name minibuf all-frames
1848 This function returns a list of all windows currently displaying
1849 @var{buffer-or-name}.  The argument @var{buffer-or-name} may be a buffer
1850 or the name of an existing buffer and defaults to the current buffer.
1852 The two remaining arguments work like the same-named arguments of
1853 @code{next-window} (@pxref{Cyclic Window Ordering}); they are @emph{not}
1854 like the optional arguments of @code{get-buffer-window}.
1855 @end defun
1857 @deffn Command replace-buffer-in-windows &optional buffer-or-name
1858 This command replaces @var{buffer-or-name} with some other buffer, in
1859 all windows displaying it.  For each such window, it choose another
1860 buffer using @code{switch-to-prev-buffer} (@pxref{Window History}).
1862 The argument @var{buffer-or-name} may be a buffer, or the name of an
1863 existing buffer; it defaults to the current buffer.
1865 If a window displaying @var{buffer-or-name} is dedicated
1866 (@pxref{Dedicated Windows}) and is not the only window on its frame,
1867 that window is deleted.  If that window is the only window on its frame
1868 and there are other frames on the frame's terminal, that frame is dealt
1869 with by the function specified by @code{frame-auto-hide-function}
1870 (@pxref{Quitting Windows}).  Otherwise, the buffer provided by the
1871 function @code{switch-to-prev-buffer} (@pxref{Window History}) is
1872 displayed in the window instead.
1873 @end deffn
1876 @node Switching Buffers
1877 @section Switching to a Buffer in a Window
1878 @cindex switching to a buffer
1879 @cindex displaying a buffer
1881   This section describes high-level functions for switching to a
1882 specified buffer in some window.
1884   Do @emph{not} use these functions to make a buffer temporarily
1885 current just so a Lisp program can access or modify it.  They have
1886 side-effects, such as changing window histories (@pxref{Window
1887 History}), which will surprise the user if used that way.  If you want
1888 to make a buffer current to modify it in Lisp, use
1889 @code{with-current-buffer}, @code{save-current-buffer}, or
1890 @code{set-buffer}.  @xref{Current Buffer}.
1892 @deffn Command switch-to-buffer buffer-or-name &optional norecord force-same-window
1893 This function displays @var{buffer-or-name} in the selected window,
1894 and makes it the current buffer.  (In contrast, @code{set-buffer}
1895 makes the buffer current but does not display it; @pxref{Current
1896 Buffer}).  It is often used interactively (as the binding of @kbd{C-x
1897 b}), as well as in Lisp programs.  The return value is the buffer
1898 switched to.
1900 If @var{buffer-or-name} is @code{nil}, it defaults to the buffer
1901 returned by @code{other-buffer} (@pxref{The Buffer List}).  If
1902 @var{buffer-or-name} is a string that is not the name of any existing
1903 buffer, this function creates a new buffer with that name; the new
1904 buffer's major mode is determined by the variable @code{major-mode}
1905 (@pxref{Major Modes}).
1907 Normally the specified buffer is put at the front of the buffer
1908 list---both the global buffer list and the selected frame's buffer
1909 list (@pxref{The Buffer List}).  However, this is not done if the
1910 optional argument @var{norecord} is non-@code{nil}.
1912 If this function is unable to display the buffer in the selected
1913 window---usually because the selected window is a minibuffer window or
1914 is strongly dedicated to its buffer (@pxref{Dedicated Windows})---then
1915 it normally tries to display the buffer in some other window, in the
1916 manner of @code{pop-to-buffer} (see below).  However, if the optional
1917 argument @var{force-same-window} is non-@code{nil}, it signals an error
1918 instead.
1919 @end deffn
1921 The next two functions are similar to @code{switch-to-buffer}, except
1922 for the described features.
1924 @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
1925 This function makes the buffer specified by @var{buffer-or-name}
1926 current and displays it in some window other than the selected window.
1927 It uses the function @code{pop-to-buffer} internally (see below).
1929 If the selected window already displays the specified buffer, it
1930 continues to do so, but another window is nonetheless found to display
1931 it as well.
1933 The @var{buffer-or-name} and @var{norecord} arguments have the same
1934 meanings as in @code{switch-to-buffer}.
1935 @end deffn
1937 @deffn Command switch-to-buffer-other-frame buffer-or-name &optional norecord
1938 This function makes the buffer specified by @var{buffer-or-name}
1939 current and displays it, usually in a new frame.  It uses the function
1940 @code{pop-to-buffer} (see below).
1942 If the specified buffer is already displayed in another window, in any
1943 frame on the current terminal, this switches to that window instead of
1944 creating a new frame.  However, the selected window is never used for
1945 this.
1947 The @var{buffer-or-name} and @var{norecord} arguments have the same
1948 meanings as in @code{switch-to-buffer}.
1949 @end deffn
1951 The above commands use @code{pop-to-buffer}, which is the function
1952 used by Lisp programs to flexibly display a buffer in some window and
1953 select that window for editing:
1955 @defun pop-to-buffer buffer-or-name &optional action norecord
1956 This function makes @var{buffer-or-name} the current buffer and
1957 displays it in some window, preferably not the window previously
1958 selected.  It then selects the displaying window.  If that window is
1959 on a different graphical frame, that frame is given input focus if
1960 possible (@pxref{Input Focus}).  The return value is the buffer that
1961 was switched to.
1963 This function uses @code{display-buffer} to display the buffer, so all
1964 the variables affecting @code{display-buffer} will affect it as well.
1965 @xref{Choosing Window}.
1967 If @var{buffer-or-name} is @code{nil}, it defaults to the buffer
1968 returned by @code{other-buffer} (@pxref{The Buffer List}).  If
1969 @var{buffer-or-name} is a string that is not the name of any existing
1970 buffer, this function creates a new buffer with that name; the new
1971 buffer's major mode is determined by the variable @code{major-mode}
1972 (@pxref{Major Modes}).
1974 If @var{action} is non-@code{nil}, it should be a display action to
1975 pass to @code{display-buffer} (@pxref{Choosing Window}).
1976 Alternatively, a non-@code{nil}, non-list value means to pop to a
1977 window other than the selected one---even if the buffer is already
1978 displayed in the selected window.
1980 Like @code{switch-to-buffer}, this function updates the buffer list
1981 unless @var{norecord} is non-@code{nil}.
1982 @end defun
1984 @node Choosing Window
1985 @section Choosing a Window for Display
1987   The command @code{display-buffer} flexibly chooses a window for
1988 display, and displays a specified buffer in that window.  It can be
1989 called interactively, via the key binding @kbd{C-x 4 C-o}.  It is also
1990 used as a subroutine by many functions and commands, including
1991 @code{switch-to-buffer} and @code{pop-to-buffer} (@pxref{Switching
1992 Buffers}).
1994 @cindex display action
1995 @cindex action function, for display-buffer
1996 @cindex action alist, for display-buffer
1997   This command performs several complex steps to find a window to
1998 display in.  These steps are described by means of @dfn{display
1999 actions}, which have the form @code{(@var{function} . @var{alist})}.
2000 Here, @var{function} is either a function or a list of functions,
2001 which we refer to as @dfn{action functions}; @var{alist} is an
2002 association list, which we refer to as @dfn{action alists}.
2004   An action function accepts two arguments: the buffer to display and
2005 an action alist.  It attempts to display the buffer in some window,
2006 picking or creating a window according to its own criteria.  If
2007 successful, it returns the window; otherwise, it returns @code{nil}.
2008 @xref{Display Action Functions}, for a list of predefined action
2009 functions.
2011   @code{display-buffer} works by combining display actions from
2012 several sources, and calling the action functions in turn, until one
2013 of them manages to display the buffer and returns a non-@code{nil}
2014 value.
2016 @deffn Command display-buffer buffer-or-name &optional action frame
2017 This command makes @var{buffer-or-name} appear in some window, without
2018 selecting the window or making the buffer current.  The argument
2019 @var{buffer-or-name} must be a buffer or the name of an existing
2020 buffer.  The return value is the window chosen to display the buffer.
2022 The optional argument @var{action}, if non-@code{nil}, should normally
2023 be a display action (described above).  @code{display-buffer} builds a
2024 list of action functions and an action alist, by consolidating display
2025 actions from the following sources (in order):
2027 @itemize
2028 @item
2029 The variable @code{display-buffer-overriding-action}.
2031 @item
2032 The user option @code{display-buffer-alist}.
2034 @item
2035 The @var{action} argument.
2037 @item
2038 The user option @code{display-buffer-base-action}.
2040 @item
2041 The constant @code{display-buffer-fallback-action}.
2042 @end itemize
2044 @noindent
2045 Each action function is called in turn, passing the buffer as the
2046 first argument and the combined action alist as the second argument,
2047 until one of the functions returns non-@code{nil}.
2049 The argument @var{action} can also have a non-@code{nil}, non-list
2050 value.  This has the special meaning that the buffer should be
2051 displayed in a window other than the selected one, even if the
2052 selected window is already displaying it.  If called interactively
2053 with a prefix argument, @var{action} is @code{t}.
2055 The optional argument @var{frame}, if non-@code{nil}, specifies which
2056 frames to check when deciding whether the buffer is already displayed.
2057 It is equivalent to adding an element @code{(reusable-frames
2058 . @var{frame})} to the action alist of @var{action}.  @xref{Display
2059 Action Functions}.
2060 @end deffn
2062 @defvar display-buffer-overriding-action
2063 The value of this variable should be a display action, which is
2064 treated with the highest priority by @code{display-buffer}.  The
2065 default value is empty, i.e. @code{(nil . nil)}.
2066 @end defvar
2068 @defopt display-buffer-alist
2069 The value of this option is an alist mapping regular expressions to
2070 display actions.  If the name of the buffer passed to
2071 @code{display-buffer} matches a regular expression in this alist, then
2072 @code{display-buffer} uses the corresponding display action.
2073 @end defopt
2075 @defopt display-buffer-base-action
2076 The value of this option should be a display action.  This option can
2077 be used to define a ``standard'' display action for calls to
2078 @code{display-buffer}.
2079 @end defopt
2081 @defvr Constant display-buffer-fallback-action
2082 This display action specifies the fallback behavior for
2083 @code{display-buffer} if no other display actions are given.
2084 @end defvr
2086 @node Display Action Functions
2087 @section Action Functions for @code{display-buffer}
2089 The following basic action functions are defined in Emacs.  Each of
2090 these functions takes two arguments: @var{buffer}, the buffer to
2091 display, and @var{alist}, an action alist.  Each action function
2092 returns the window if it succeeds, and @code{nil} if it fails.
2094 @defun display-buffer-same-window buffer alist
2095 This function tries to display @var{buffer} in the selected window.
2096 It fails if the selected window is a minibuffer window or is dedicated
2097 to another buffer (@pxref{Dedicated Windows}).  It also fails if
2098 @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry.
2099 @end defun
2101 @defun display-buffer-reuse-window buffer alist
2102 This function tries to ``display'' @var{buffer} by finding a window
2103 that is already displaying it.
2105 If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry,
2106 the selected window is not eligible for reuse.
2108 If @var{alist} contains a @code{reusable-frames} entry, its value
2109 determines which frames to search for a reusable window:
2111 @itemize @bullet
2112 @item
2113 @code{nil} means consider windows on the selected frame.
2114 (Actually, the last non-minibuffer frame.)
2115 @item
2116 @code{t} means consider windows on all frames.
2117 @item
2118 @code{visible} means consider windows on all visible frames.
2119 @item
2120 0 means consider windows on all visible or iconified frames.
2121 @item
2122 A frame means consider windows on that frame only.
2123 @end itemize
2125 If @var{alist} contains no @code{reusable-frames} entry, this function
2126 normally searches just the selected frame; however, if either the
2127 variable @code{display-buffer-reuse-frames} or the variable
2128 @code{pop-up-frames} is non-@code{nil}, it searches all frames on the
2129 current terminal.  @xref{Choosing Window Options}.
2130 @end defun
2132 @defun display-buffer-pop-up-frame buffer alist
2133 This function creates a new frame, and displays the buffer in that
2134 frame's window.
2135 @end defun
2137 @defun display-buffer-pop-up-window buffer alist
2138 This function tries to display @var{buffer} by splitting the largest
2139 or least recently-used window.  It uses @code{split-window-sensibly}
2140 as a subroutine (@pxref{Choosing Window Options}).
2141 @end defun
2143 @defun display-buffer-use-some-window buffer alist
2144 This function tries to display @var{buffer} by choosing an existing
2145 window and displaying the buffer in that window.  It can fail if all
2146 windows are dedicated to another buffer (@pxref{Dedicated Windows}).
2147 @end defun
2149 @node Choosing Window Options
2150 @section Additional Options for Displaying Buffers
2152 The behavior of the standard display actions of @code{display-buffer}
2153 (@pxref{Choosing Window}) can be modified by a variety of user
2154 options.
2156 @defopt display-buffer-reuse-frames
2157 If this variable is non-@code{nil}, @code{display-buffer} searches
2158 visible and iconified frames for a window displaying
2159 @var{buffer-or-name}.  If there is such a window, @code{display-buffer}
2160 makes that window's frame visible and raises it if necessary, and
2161 returns the window.  If there is no such window or
2162 @code{display-buffer-reuse-frames} is @code{nil}, the behavior of
2163 @code{display-buffer} is determined by the variables described next.
2164 @end defopt
2166 @defopt pop-up-windows
2167 This variable specifies whether @code{display-buffer} is allowed to
2168 split (@pxref{Splitting Windows}) an existing window.  If this variable
2169 is non-@code{nil}, @code{display-buffer} tries to split the largest or
2170 least recently used window on the selected frame.  (If the selected
2171 frame is a minibuffer-only frame, @code{display-buffer} tries to split a
2172 window on another frame instead.)  If this variable is @code{nil} or the
2173 variable @code{pop-up-frames} (see below) is non-@code{nil},
2174 @code{display-buffer} does not split any window.
2175 @end defopt
2177 @defopt split-window-preferred-function
2178 This variable must specify a function with one argument, which is a
2179 window.  The @code{display-buffer} routines will call this function with
2180 one or more candidate windows when they look for a window to split.  The
2181 function is expected to split that window and return the new window.  If
2182 the function returns @code{nil}, this means that the argument window
2183 cannot (or shall not) be split.
2185 The default value of @code{split-window-preferred-function} is the
2186 function @code{split-window-sensibly} described below.  If you
2187 customize this option, bear in mind that the @code{display-buffer}
2188 routines may call your function up to two times when trying to split a
2189 window.  The argument of the first call is the largest window on the
2190 chosen frame (as returned by @code{get-largest-window}).  If that call
2191 fails to return a live window, your function is called a second time
2192 with the least recently used window on that frame (as returned by
2193 @code{get-lru-window}).
2195 The function specified by this option may try to split any other window
2196 instead of the argument window.  Note that the window selected at the
2197 time @code{display-buffer} was invoked is still selected when your
2198 function is called.  Hence, you can split the selected window (instead
2199 of the largest or least recently used one) by simply ignoring the window
2200 argument in the body of your function.  You can even choose to not split
2201 any window as long as the return value of your function specifies a live
2202 window or @code{nil}, but you are not encouraged to do so
2203 unconditionally.  If you want @code{display-buffer} to never split any
2204 windows, set @code{pop-up-windows} to @code{nil}.
2205 @end defopt
2207 @defun split-window-sensibly window
2208 This function takes a window as argument and tries to split that window
2209 in a suitable way.  The two variables described next are useful for
2210 tuning the behavior of this function.
2211 @end defun
2213 @defopt split-height-threshold
2214 This variable specifies whether @code{split-window-sensibly} may split
2215 windows vertically.  If it is an integer, @code{split-window-sensibly}
2216 tries to vertically split a window only if it has at least this many
2217 lines.  If the window has less lines, splitting fails, or the value of
2218 this variable is @code{nil}, @code{split-window-sensibly} will try to
2219 split the window horizontally, subject to restrictions of
2220 @code{split-width-threshold} (see below).  If splitting horizontally
2221 fails too and the window is the only window on its frame,
2222 @code{split-window-sensibly} will try to split the window vertically
2223 disregarding the value of @code{split-height-threshold}.  If this fails
2224 as well, @code{split-window-sensibly} returns @code{nil}.
2226 @code{split-window-sensibly} does not split vertically a window whose
2227 height is fixed (@pxref{Resizing Windows}).  Also, it vertically splits
2228 a window only if the space taken up by that window can accommodate two
2229 windows one above the other that are both at least
2230 @code{window-min-height} lines tall.  Moreover, if the window that shall
2231 be split has a mode line, @code{split-window-sensibly} does not split
2232 the window unless the new window can accommodate a mode line too.
2233 @end defopt
2235 @defopt split-width-threshold
2236 This variable specifies whether @code{split-window-sensibly} may split
2237 windows horizontally.  If it is an integer, @code{split-window-sensibly}
2238 tries to horizontally split a window only if it has at least this many
2239 columns.  If it is @code{nil}, @code{split-window-sensibly} will not
2240 split the window horizontally.  (It still might split the window
2241 vertically, though, see above.)
2243 @code{split-window-sensibly} does not split horizontally a window if
2244 that window's width is fixed (@pxref{Resizing Windows}).  Also, it
2245 horizontally splits a window only if the space that window takes up can
2246 accommodate two windows side by side that are both at least
2247 @code{window-min-width} columns wide.
2248 @end defopt
2250 @defopt even-window-heights
2251 This variable specifies whether @code{display-buffer} should even out
2252 window heights if the buffer gets displayed in an existing window, above
2253 or beneath another window.  If @code{even-window-heights} is
2254 non-@code{nil}, the default, window heights will be evened out.  If
2255 either of the involved window has fixed height (@pxref{Resizing
2256 Windows}) or @code{even-window-heights} is @code{nil}, the original
2257 window heights will be left alone.
2258 @end defopt
2260 @c Emacs 19 feature
2261 @defopt pop-up-frames
2262 This variable specifies whether @code{display-buffer} should make new
2263 frames.  If it is non-@code{nil}, @code{display-buffer} looks for a
2264 window already displaying @var{buffer-or-name} on any visible or
2265 iconified frame.  If it finds such a window, it makes that window's
2266 frame visible and raises it if necessary, and returns the window.
2267 Otherwise it makes a new frame, unless the variable's value is
2268 @code{graphic-only} and the selected frame is not on a graphic display.
2269 @xref{Frames}, for more information.
2271 Note that the value of @code{pop-up-windows} does not matter if
2272 @code{pop-up-frames} is non-@code{nil}.  If @code{pop-up-frames} is
2273 @code{nil}, then @code{display-buffer} either splits a window or reuses
2274 one.
2275 @end defopt
2277 @c Emacs 19 feature
2278 @defopt pop-up-frame-function
2279 This variable specifies how to make a new frame if @code{pop-up-frames}
2280 is non-@code{nil}.
2282 The value of this variable must be a function of no arguments.  When
2283 @code{display-buffer} makes a new frame, it does so by calling that
2284 function, which should return a frame.  The default value of this
2285 variable is a function that creates a frame using the parameters
2286 specified by @code{pop-up-frame-alist} described next.
2287 @end defopt
2289 @defopt pop-up-frame-alist
2290 This variable holds an alist specifying frame parameters used by the
2291 default value of @code{pop-up-frame-function} for making new frames.
2292 @xref{Frame Parameters}, for more information about frame parameters.
2293 @end defopt
2295 @defopt special-display-buffer-names
2296 A list of buffer names identifying buffers that should be displayed
2297 specially.  If the name of @var{buffer-or-name} is in this list,
2298 @code{display-buffer} handles the buffer specially.  By default, special
2299 display means to give the buffer a dedicated frame.
2301 If an element is a list, instead of a string, then the @sc{car} of that
2302 list is the buffer name, and the rest of that list says how to create
2303 the frame.  There are two possibilities for the rest of that list (its
2304 @sc{cdr}): It can be an alist, specifying frame parameters, or it can
2305 contain a function and arguments to give to it.  (The function's first
2306 argument is always the buffer to be displayed; the arguments from the
2307 list come after that.)
2309 For example:
2311 @example
2312 (("myfile" (minibuffer) (menu-bar-lines . 0)))
2313 @end example
2315 @noindent
2316 specifies to display a buffer named @samp{myfile} in a dedicated frame
2317 with specified @code{minibuffer} and @code{menu-bar-lines} parameters.
2319 The list of frame parameters can also use the phony frame parameters
2320 @code{same-frame} and @code{same-window}.  If the specified frame
2321 parameters include @code{(same-window . @var{value})} and @var{value}
2322 is non-@code{nil}, that means to display the buffer in the current
2323 selected window.  Otherwise, if they include @code{(same-frame .
2324 @var{value})} and @var{value} is non-@code{nil}, that means to display
2325 the buffer in a new window in the currently selected frame.
2326 @end defopt
2328 @defopt special-display-regexps
2329 A list of regular expressions specifying buffers that should be
2330 displayed specially.  If the buffer's name matches any of the regular
2331 expressions in this list, @code{display-buffer} handles the buffer
2332 specially.  By default, special display means to give the buffer a
2333 dedicated frame.
2335 If an element is a list, instead of a string, then the @sc{car} of the
2336 list is the regular expression, and the rest of the list says how to
2337 create the frame.  See @code{special-display-buffer-names} above.
2338 @end defopt
2340 @defun special-display-p buffer-name
2341 This function returns non-@code{nil} if displaying a buffer
2342 named @var{buffer-name} with @code{display-buffer} would
2343 create a special frame.  The value is @code{t} if it would
2344 use the default frame parameters, or else the specified list
2345 of frame parameters.
2346 @end defun
2348 @defopt special-display-function
2349 This variable holds the function to call to display a buffer specially.
2350 It receives the buffer as an argument, and should return the window in
2351 which it is displayed.  The default value of this variable is
2352 @code{special-display-popup-frame}, see below.
2353 @end defopt
2355 @defun special-display-popup-frame buffer &optional args
2356 This function tries to make @var{buffer} visible in a frame of its own.
2357 If @var{buffer} is already displayed in some window, it makes that
2358 window's frame visible and raises it.  Otherwise, it creates a frame
2359 that is dedicated to @var{buffer}.  The return value is the window used
2360 to display @var{buffer}.
2362 If @var{args} is an alist, it specifies frame parameters for the new
2363 frame.  If @var{args} is a list whose @sc{car} is a symbol, then
2364 @code{(car @var{args})} is called as a function to actually create and
2365 set up the frame; it is called with @var{buffer} as first argument, and
2366 @code{(cdr @var{args})} as additional arguments.
2368 This function always uses an existing window displaying @var{buffer},
2369 whether or not it is in a frame of its own; but if you set up the above
2370 variables in your init file, before @var{buffer} was created, then
2371 presumably the window was previously made by this function.
2372 @end defun
2374 @defopt special-display-frame-alist
2375 @anchor{Definition of special-display-frame-alist}
2376 This variable holds frame parameters for
2377 @code{special-display-popup-frame} to use when it creates a frame.
2378 @end defopt
2380 @defopt same-window-buffer-names
2381 A list of buffer names for buffers that should be displayed in the
2382 selected window.  If the buffer's name is in this list,
2383 @code{display-buffer} handles the buffer by switching to it in the
2384 selected window.
2385 @end defopt
2387 @defopt same-window-regexps
2388 A list of regular expressions that specify buffers that should be
2389 displayed in the selected window.  If the buffer's name matches any of
2390 the regular expressions in this list, @code{display-buffer} handles the
2391 buffer by switching to it in the selected window.
2392 @end defopt
2394 @defun same-window-p buffer-name
2395 This function returns @code{t} if displaying a buffer
2396 named @var{buffer-name} with @code{display-buffer} would
2397 put it in the selected window.
2398 @end defun
2400 @c Emacs 19 feature
2401 @defopt display-buffer-function
2402 This variable is the most flexible way to customize the behavior of
2403 @code{display-buffer}.  If it is non-@code{nil}, it should be a function
2404 that @code{display-buffer} calls to do the work.  The function should
2405 accept two arguments, the first two arguments that @code{display-buffer}
2406 received.  It should choose or create a window, display the specified
2407 buffer in it, and then return the window.
2409 This variable takes precedence over all the other options described
2410 above.
2411 @end defopt
2413 If all options described above fail to produce a suitable window,
2414 @code{display-buffer} tries to reuse an existing window.  As a last
2415 resort, it will try to display @var{buffer-or-name} on a separate frame.
2416 In that case, the value of @code{pop-up-frames} is disregarded.
2419 @node Window History
2420 @section Window History
2421 @cindex window history
2423 Each window remembers the buffers it has displayed earlier and the order
2424 in which these buffers have been removed from it.  This history is used,
2425 for example, by @code{replace-buffer-in-windows} (@pxref{Buffers and
2426 Windows}).  This list is automatically maintained by Emacs, but you can
2427 use the following functions to explicitly inspect or alter it:
2429 @defun window-prev-buffers &optional window
2430 This function returns a list specifying the previous contents of
2431 @var{window}, which should be a live window and defaults to the
2432 selected window.
2434 Each list element has the form @code{(@var{buffer} @var{window-start}
2435 @var{window-pos})}, where @var{buffer} is a buffer previously shown in
2436 the window, @var{window-start} is the window start position when that
2437 buffer was last shown, and @var{window-pos} is the point position when
2438 that buffer was last shown.
2440 The list is ordered so that earlier elements correspond to more
2441 recently-shown buffers, and the first element usually corresponds to the
2442 buffer most recently removed from the window.
2443 @end defun
2445 @defun set-window-prev-buffers window prev-buffers
2446 This function sets @var{window}'s previous buffers to the value of
2447 @var{prev-buffers}.  The argument @var{window} must be a live window
2448 and defaults to the selected one.  The argument @var{prev-buffers}
2449 should be a list of the same form as that returned by
2450 @code{window-prev-buffers}.
2451 @end defun
2453 In addition, each buffer maintains a list of @dfn{next buffers}, which
2454 is a list of buffers re-shown by @code{switch-to-prev-buffer} (see
2455 below).  This list is mainly used by @code{switch-to-prev-buffer} and
2456 @code{switch-to-next-buffer} for choosing buffers to switch to.
2458 @defun window-next-buffers &optional window
2459 This function returns the list of buffers recently re-shown in
2460 @var{window} via @code{switch-to-prev-buffer}.  The @var{window}
2461 argument must denote a live window or @code{nil} (meaning the selected
2462 window).
2463 @end defun
2465 @defun set-window-next-buffers window next-buffers
2466 This function sets the next buffer list of @var{window} to
2467 @var{next-buffers}.  The @var{window} argument should be a live window
2468 or @code{nil} (meaning the selected window).  The argument
2469 @var{next-buffers} should be a list of buffers.
2470 @end defun
2472 The following commands can be used to cycle through the global buffer
2473 list, much like @code{bury-buffer} and @code{unbury-buffer}.  However,
2474 they cycle according to the specified window's history list, rather
2475 than the global buffer list.  In addition, they restore
2476 window-specific window start and point positions, and may show a
2477 buffer even if it is already shown in another window.  The
2478 @code{switch-to-prev-buffer} command, in particular, is used by
2479 @code{replace-buffer-in-windows}, @code{bury-buffer} and
2480 @code{quit-window} to find a replacement buffer for a window.
2482 @deffn Command switch-to-prev-buffer &optional window bury-or-kill
2483 This command displays the previous buffer in @var{window}.  The
2484 argument @var{window} should be a live window or @code{nil} (meaning
2485 the selected window).  If the optional argument @var{bury-or-kill} is
2486 non-@code{nil}, this means that the buffer currently shown in
2487 @var{window} is about to be buried or killed and consequently shall
2488 not be switched to in future invocations of this command.
2490 The previous buffer is usually the buffer shown before the buffer
2491 currently shown in @var{window}.  However, a buffer that has been buried
2492 or killed or has been already shown by a recent invocation of
2493 @code{switch-to-prev-buffer} does not qualify as previous buffer.
2495 If repeated invocations of this command have already shown all buffers
2496 previously shown in @var{window}, further invocations will show buffers
2497 from the buffer list of the frame @var{window} appears on (@pxref{The
2498 Buffer List}).
2499 @end deffn
2501 @deffn Command switch-to-next-buffer &optional window
2502 This command switches to the next buffer in @var{window} thus undoing
2503 the effect of the last @code{switch-to-prev-buffer} command in
2504 @var{window}.  The argument @var{window} must be a live window and
2505 defaults to the selected one.
2507 If there is no recent invocation of a @code{switch-to-prev-buffer} that
2508 can be undone, this function tries to show a buffer from the buffer list
2509 of the frame @var{window} appears on (@pxref{The Buffer List}).
2510 @end deffn
2513 @node Dedicated Windows
2514 @section Dedicated Windows
2515 @cindex dedicated window
2517 Functions for displaying a buffer can be told to not use specific
2518 windows by marking these windows as @dfn{dedicated} to their buffers.
2519 @code{display-buffer} (@pxref{Choosing Window}) never uses a dedicated
2520 window for displaying another buffer in it.  @code{get-lru-window} and
2521 @code{get-largest-window} (@pxref{Selecting Windows}) do not consider
2522 dedicated windows as candidates when their @var{dedicated} argument is
2523 non-@code{nil}.  The behavior of @code{set-window-buffer}
2524 (@pxref{Buffers and Windows}) with respect to dedicated windows is
2525 slightly different, see below.
2527 When @code{delete-windows-on} (@pxref{Deleting Windows}) wants to
2528 delete a dedicated window and that window is the only window on its
2529 frame, it deletes the window's frame too, provided there are other
2530 frames left.  @code{replace-buffer-in-windows} (@pxref{Switching
2531 Buffers}) tries to delete all dedicated windows showing its buffer
2532 argument.  When such a window is the only window on its frame, that
2533 frame is deleted, provided there are other frames left.  If there are
2534 no more frames left, some other buffer is displayed in the window, and
2535 the window is marked as non-dedicated.
2537 When you kill a buffer (@pxref{Killing Buffers}) displayed in a
2538 dedicated window, any such window usually gets deleted too, since
2539 @code{kill-buffer} calls @code{replace-buffer-in-windows} for cleaning
2540 up windows.  Burying a buffer (@pxref{The Buffer List}) deletes the
2541 selected window if it is dedicated to that buffer.  If, however, that
2542 window is the only window on its frame, @code{bury-buffer} displays
2543 another buffer in it and iconifies the frame.
2545 @defun window-dedicated-p &optional window
2546 This function returns non-@code{nil} if @var{window} is dedicated to its
2547 buffer and @code{nil} otherwise.  More precisely, the return value is
2548 the value assigned by the last call of @code{set-window-dedicated-p} for
2549 @var{window} or @code{nil} if that function was never called with
2550 @var{window} as its argument.  The default for @var{window} is the
2551 selected window.
2552 @end defun
2554 @defun set-window-dedicated-p window flag
2555 This function marks @var{window} as dedicated to its buffer if
2556 @var{flag} is non-@code{nil}, and non-dedicated otherwise.
2558 As a special case, if @var{flag} is @code{t}, @var{window} becomes
2559 @dfn{strongly} dedicated to its buffer.  @code{set-window-buffer}
2560 signals an error when the window it acts upon is strongly dedicated to
2561 its buffer and does not already display the buffer it is asked to
2562 display.  Other functions do not treat @code{t} differently from any
2563 non-@code{nil} value.
2564 @end defun
2567 @node Quitting Windows
2568 @section Quitting Windows
2570 When you want to get rid of a window used for displaying a buffer you
2571 can call @code{delete-window} or @code{delete-windows-on}
2572 (@pxref{Deleting Windows}) to remove that window from its frame.  If the
2573 buffer is shown on a separate frame, you might want to call
2574 @code{delete-frame} (@pxref{Deleting Frames}) instead.  If, on the other
2575 hand, a window has been reused for displaying the buffer, you might
2576 prefer showing the buffer previously shown in that window by calling the
2577 function @code{switch-to-prev-buffer} (@pxref{Window History}).
2578 Finally, you might want to either bury (@pxref{The Buffer List}) or kill
2579 (@pxref{Killing Buffers}) the window's buffer.
2581    The following function uses information on how the window for
2582 displaying the buffer was obtained in the first place thus attempting to
2583 automatize the above decisions for you.
2585 @deffn Command quit-window &optional kill window
2586 This command quits @var{window} and buries its buffer.  The argument
2587 @var{window} must be a live window and defaults to the selected one.
2588 With prefix argument @var{kill} non-@code{nil}, it kills the buffer
2589 instead of burying it.
2591 Quitting @var{window} means to proceed as follows: If @var{window} was
2592 created specially for displaying its current buffer, delete @var{window}
2593 provided its frame contains at least one other live window.  If
2594 @var{window} is the only window on its frame and there are other frames
2595 on the frame's terminal, the value of @var{kill} determines how to
2596 proceed with the window.  If @var{kill} is @code{nil}, the fate of the
2597 frame is determined by calling @code{frame-auto-hide-function} (see
2598 below) with that frame as sole argument.  If @var{kill} is
2599 non-@code{nil}, the frame is deleted unconditionally.
2601 If @var{window} was reused for displaying its buffer, this command tries
2602 to display the buffer previously shown in it.  It also tries to restore
2603 the window start (@pxref{Window Start and End}) and point (@pxref{Window
2604 Point}) positions of the previously shown buffer.  If, in addition, the
2605 current buffer was temporarily resized, this command will also try to
2606 restore the original height of @var{window}.
2608 The three cases described so far require that the buffer shown in
2609 @var{window} is still the buffer displayed by the last buffer display
2610 function for this window.  If another buffer has been shown in the
2611 meantime or the buffer previously shown no longer exists, this command
2612 calls @code{switch-to-prev-buffer} (@pxref{Window History}) to show some
2613 other buffer instead.
2614 @end deffn
2616 The function @code{quit-window} bases its decisions on information
2617 stored in @var{window}'s @code{quit-restore} window parameter
2618 (@pxref{Window Parameters}) and resets that parameter to @code{nil}
2619 after it's done.
2621 The following option specifies how to deal with a frame containing just
2622 one window that shall be either quit or whose buffer shall be buried.
2624 @defopt frame-auto-hide-function
2625 The function specified by this option is called to automatically hide
2626 frames.  This function is called with one argument - a frame.
2628 The function specified here is called by @code{bury-buffer} (@pxref{The
2629 Buffer List}) when the selected window is dedicated and shows the buffer
2630 that shall be buried.  It is also called by @code{quit-window} (see
2631 above) when the frame of the window that shall be quit has been
2632 specially created for displaying that window's buffer and the buffer
2633 shall be buried.
2635 The default is to call @code{iconify-frame} (@pxref{Visibility of
2636 Frames}).  Alternatively, you may either specify @code{delete-frame}
2637 (@pxref{Deleting Frames}) to remove the frame from its display,
2638 @code{ignore} to leave the frame unchanged, or any other function that
2639 can take a frame as its sole argument.
2641 Note that the function specified by this option is called if and only if
2642 there's at least one other frame on the terminal of the frame it's
2643 supposed to handle and that frame contains only one live window.
2644 @end defopt
2647 @node Window Point
2648 @section Windows and Point
2649 @cindex window position
2650 @cindex window point
2651 @cindex position in window
2652 @cindex point in window
2654   Each window has its own value of point (@pxref{Point}), independent of
2655 the value of point in other windows displaying the same buffer.  This
2656 makes it useful to have multiple windows showing one buffer.
2658 @itemize @bullet
2659 @item
2660 The window point is established when a window is first created; it is
2661 initialized from the buffer's point, or from the window point of another
2662 window opened on the buffer if such a window exists.
2664 @item
2665 Selecting a window sets the value of point in its buffer from the
2666 window's value of point.  Conversely, deselecting a window sets the
2667 window's value of point from that of the buffer.  Thus, when you switch
2668 between windows that display a given buffer, the point value for the
2669 selected window is in effect in the buffer, while the point values for
2670 the other windows are stored in those windows.
2672 @item
2673 As long as the selected window displays the current buffer, the window's
2674 point and the buffer's point always move together; they remain equal.
2675 @end itemize
2677 @cindex cursor
2678    As far as the user is concerned, point is where the cursor is, and
2679 when the user switches to another buffer, the cursor jumps to the
2680 position of point in that buffer.
2682 @defun window-point &optional window
2683 This function returns the current position of point in @var{window}.
2684 For a nonselected window, this is the value point would have (in that
2685 window's buffer) if that window were selected.  The default for
2686 @var{window} is the selected window.
2688 When @var{window} is the selected window and its buffer is also the
2689 current buffer, the value returned is the same as point in that buffer.
2690 Strictly speaking, it would be more correct to return the ``top-level''
2691 value of point, outside of any @code{save-excursion} forms.  But that
2692 value is hard to find.
2693 @end defun
2695 @defun set-window-point window position
2696 This function positions point in @var{window} at position
2697 @var{position} in @var{window}'s buffer.  It returns @var{position}.
2699 If @var{window} is selected, and its buffer is current,
2700 this simply does @code{goto-char}.
2701 @end defun
2703 @defvar window-point-insertion-type
2704 This variable specifies the marker insertion type (@pxref{Marker
2705 Insertion Types}) of @code{window-point}.  The default is @code{nil},
2706 so @code{window-point} will stay behind text inserted there.
2707 @end defvar
2709 @node Window Start and End
2710 @section The Window Start and End Positions
2711 @cindex window start position
2713   Each window maintains a marker used to keep track of a buffer position
2714 that specifies where in the buffer display should start.  This position
2715 is called the @dfn{display-start} position of the window (or just the
2716 @dfn{start}).  The character after this position is the one that appears
2717 at the upper left corner of the window.  It is usually, but not
2718 inevitably, at the beginning of a text line.
2720   After switching windows or buffers, and in some other cases, if the
2721 window start is in the middle of a line, Emacs adjusts the window
2722 start to the start of a line.  This prevents certain operations from
2723 leaving the window start at a meaningless point within a line.  This
2724 feature may interfere with testing some Lisp code by executing it
2725 using the commands of Lisp mode, because they trigger this
2726 readjustment.  To test such code, put it into a command and bind the
2727 command to a key.
2729 @defun window-start &optional window
2730 @cindex window top line
2731 This function returns the display-start position of window
2732 @var{window}.  If @var{window} is @code{nil}, the selected window is
2733 used.  For example,
2735 @example
2736 @group
2737 (window-start)
2738      @result{} 7058
2739 @end group
2740 @end example
2742 When you create a window, or display a different buffer in it, the
2743 display-start position is set to a display-start position recently used
2744 for the same buffer, or to @code{point-min} if the buffer doesn't have
2745 any.
2747 Redisplay updates the window-start position (if you have not specified
2748 it explicitly since the previous redisplay)---to make sure point appears
2749 on the screen.  Nothing except redisplay automatically changes the
2750 window-start position; if you move point, do not expect the window-start
2751 position to change in response until after the next redisplay.
2753 For a realistic example of using @code{window-start}, see the
2754 description of @code{count-lines}.  @xref{Definition of count-lines}.
2755 @end defun
2757 @cindex window end position
2758 @defun window-end &optional window update
2759 This function returns the position where display of its buffer ends in
2760 @var{window}.  The default for @var{window} is the selected window.
2762 Simply changing the buffer text or moving point does not update the
2763 value that @code{window-end} returns.  The value is updated only when
2764 Emacs redisplays and redisplay completes without being preempted.
2766 If the last redisplay of @var{window} was preempted, and did not finish,
2767 Emacs does not know the position of the end of display in that window.
2768 In that case, this function returns @code{nil}.
2770 If @var{update} is non-@code{nil}, @code{window-end} always returns an
2771 up-to-date value for where display ends, based on the current
2772 @code{window-start} value.  If a previously saved value of that position
2773 is still valid, @code{window-end} returns that value; otherwise it
2774 computes the correct value by scanning the buffer text.
2776 Even if @var{update} is non-@code{nil}, @code{window-end} does not
2777 attempt to scroll the display if point has moved off the screen, the
2778 way real redisplay would do.  It does not alter the
2779 @code{window-start} value.  In effect, it reports where the displayed
2780 text will end if scrolling is not required.
2781 @end defun
2783 @defun set-window-start window position &optional noforce
2784 This function sets the display-start position of @var{window} to
2785 @var{position} in @var{window}'s buffer.  It returns @var{position}.
2787 The display routines insist that the position of point be visible when a
2788 buffer is displayed.  Normally, they change the display-start position
2789 (that is, scroll the window) whenever necessary to make point visible.
2790 However, if you specify the start position with this function using
2791 @code{nil} for @var{noforce}, it means you want display to start at
2792 @var{position} even if that would put the location of point off the
2793 screen.  If this does place point off screen, the display routines move
2794 point to the left margin on the middle line in the window.
2796 For example, if point @w{is 1} and you set the start of the window
2797 @w{to 37}, the start of the next line, point will be ``above'' the top
2798 of the window.  The display routines will automatically move point if
2799 it is still 1 when redisplay occurs.  Here is an example:
2801 @example
2802 @group
2803 ;; @r{Here is what @samp{foo} looks like before executing}
2804 ;;   @r{the @code{set-window-start} expression.}
2805 @end group
2807 @group
2808 ---------- Buffer: foo ----------
2809 @point{}This is the contents of buffer foo.
2815 ---------- Buffer: foo ----------
2816 @end group
2818 @group
2819 (set-window-start
2820  (selected-window)
2821  (save-excursion
2822    (goto-char 1)
2823    (forward-line 1)
2824    (point)))
2825 @result{} 37
2826 @end group
2828 @group
2829 ;; @r{Here is what @samp{foo} looks like after executing}
2830 ;;   @r{the @code{set-window-start} expression.}
2831 ---------- Buffer: foo ----------
2834 @point{}4
2837 ---------- Buffer: foo ----------
2838 @end group
2839 @end example
2841 If @var{noforce} is non-@code{nil}, and @var{position} would place point
2842 off screen at the next redisplay, then redisplay computes a new window-start
2843 position that works well with point, and thus @var{position} is not used.
2844 @end defun
2846 @defun pos-visible-in-window-p &optional position window partially
2847 This function returns non-@code{nil} if @var{position} is within the
2848 range of text currently visible on the screen in @var{window}.  It
2849 returns @code{nil} if @var{position} is scrolled vertically out of view.
2850 Locations that are partially obscured are not considered visible unless
2851 @var{partially} is non-@code{nil}.  The argument @var{position} defaults
2852 to the current position of point in @var{window}; @var{window}, to the
2853 selected window.  If @var{position} is @code{t}, that means to check the
2854 last visible position in @var{window}.
2856 This function considers only vertical scrolling.  If @var{position} is
2857 out of view only because @var{window} has been scrolled horizontally,
2858 @code{pos-visible-in-window-p} returns non-@code{nil} anyway.
2859 @xref{Horizontal Scrolling}.
2861 If @var{position} is visible, @code{pos-visible-in-window-p} returns
2862 @code{t} if @var{partially} is @code{nil}; if @var{partially} is
2863 non-@code{nil}, and the character following @var{position} is fully
2864 visible, it returns a list of the form @code{(@var{x} @var{y})}, where
2865 @var{x} and @var{y} are the pixel coordinates relative to the top left
2866 corner of the window; otherwise it returns an extended list of the form
2867 @code{(@var{x} @var{y} @var{rtop} @var{rbot} @var{rowh} @var{vpos})},
2868 where @var{rtop} and @var{rbot} specify the number of off-window pixels
2869 at the top and bottom of the row at @var{position}, @var{rowh} specifies
2870 the visible height of that row, and @var{vpos} specifies the vertical
2871 position (zero-based row number) of that row.
2873 Here is an example:
2875 @example
2876 @group
2877 ;; @r{If point is off the screen now, recenter it now.}
2878 (or (pos-visible-in-window-p
2879      (point) (selected-window))
2880     (recenter 0))
2881 @end group
2882 @end example
2883 @end defun
2885 @defun window-line-height &optional line window
2886 This function returns the height of text line @var{line} in
2887 @var{window}.  If @var{line} is one of @code{header-line} or
2888 @code{mode-line}, @code{window-line-height} returns information about
2889 the corresponding line of the window.  Otherwise, @var{line} is a text
2890 line number starting from 0.  A negative number counts from the end of
2891 the window.  The default for @var{line} is the current line in
2892 @var{window}; the default for @var{window} is the selected window.
2894 If the display is not up to date, @code{window-line-height} returns
2895 @code{nil}.  In that case, @code{pos-visible-in-window-p} may be used
2896 to obtain related information.
2898 If there is no line corresponding to the specified @var{line},
2899 @code{window-line-height} returns @code{nil}.  Otherwise, it returns
2900 a list @code{(@var{height} @var{vpos} @var{ypos} @var{offbot})},
2901 where @var{height} is the height in pixels of the visible part of the
2902 line, @var{vpos} and @var{ypos} are the vertical position in lines and
2903 pixels of the line relative to the top of the first text line, and
2904 @var{offbot} is the number of off-window pixels at the bottom of the
2905 text line.  If there are off-window pixels at the top of the (first)
2906 text line, @var{ypos} is negative.
2907 @end defun
2909 @node Textual Scrolling
2910 @section Textual Scrolling
2911 @cindex textual scrolling
2912 @cindex scrolling textually
2914   @dfn{Textual scrolling} means moving the text up or down through a
2915 window.  It works by changing the window's display-start location.  It
2916 may also change the value of @code{window-point} to keep point on the
2917 screen (@pxref{Window Point}).
2919   The basic textual scrolling functions are @code{scroll-up} (which
2920 scrolls forward) and @code{scroll-down} (which scrolls backward).  In
2921 these function names, ``up'' and ``down'' refer to the direction of
2922 motion of the buffer text relative to the window.  Imagine that the
2923 text is written on a long roll of paper and that the scrolling
2924 commands move the paper up and down.  Thus, if you are looking at the
2925 middle of a buffer and repeatedly call @code{scroll-down}, you will
2926 eventually see the beginning of the buffer.
2928   Some people have urged that the opposite convention be used: they
2929 imagine the window moving over text that remains in place, so that
2930 ``down'' commands take you to the end of the buffer.  This convention
2931 is consistent with fact that such a command is bound to a key named
2932 @key{PageDown} on modern keyboards.  We have not switched to this
2933 convention as that is likely to break existing Emacs Lisp code.
2935   Textual scrolling functions (aside from @code{scroll-other-window})
2936 have unpredictable results if the current buffer is not the one
2937 displayed in the selected window.  @xref{Current Buffer}.
2939   If the window contains a row taller than the height of the window
2940 (for example in the presence of a large image), the scroll functions
2941 will adjust the window's vertical scroll position to scroll the
2942 partially visible row.  Lisp callers can disable this feature by
2943 binding the variable @code{auto-window-vscroll} to @code{nil}
2944 (@pxref{Vertical Scrolling}).
2946 @deffn Command scroll-up &optional count
2947 This function scrolls forward by @var{count} lines in the selected
2948 window.
2950 If @var{count} is negative, it scrolls backward instead.  If
2951 @var{count} is @code{nil} (or omitted), the distance scrolled is
2952 @code{next-screen-context-lines} lines less than the height of the
2953 window's text area.
2955 If the selected window cannot be scrolled any further, this function
2956 signals an error.  Otherwise, it returns @code{nil}.
2957 @end deffn
2959 @deffn Command scroll-down &optional count
2960 This function scrolls backward by @var{count} lines in the selected
2961 window.
2963 If @var{count} is negative, it scrolls forward instead.  If
2964 @var{count} is omitted or @code{nil}, the distance scrolled is
2965 @code{next-screen-context-lines} lines less than the height of the
2966 window's text area.
2968 If the selected window cannot be scrolled any further, this function
2969 signals an error.  Otherwise, it returns @code{nil}.
2970 @end deffn
2972 @deffn Command scroll-up-command &optional count
2973 This behaves like @code{scroll-up}, except that if the selected window
2974 cannot be scrolled any further and the value of the variable
2975 @code{scroll-error-top-bottom} is @code{t}, it tries to move to the
2976 end of the buffer instead.  If point is already there, it signals an
2977 error.
2978 @end deffn
2980 @deffn Command scroll-down-command &optional count
2981 This behaves like @code{scroll-down}, except that if the selected
2982 window cannot be scrolled any further and the value of the variable
2983 @code{scroll-error-top-bottom} is @code{t}, it tries to move to the
2984 beginning of the buffer instead.  If point is already there, it
2985 signals an error.
2986 @end deffn
2988 @deffn Command scroll-other-window &optional count
2989 This function scrolls the text in another window upward @var{count}
2990 lines.  Negative values of @var{count}, or @code{nil}, are handled
2991 as in @code{scroll-up}.
2993 You can specify which buffer to scroll by setting the variable
2994 @code{other-window-scroll-buffer} to a buffer.  If that buffer isn't
2995 already displayed, @code{scroll-other-window} displays it in some
2996 window.
2998 When the selected window is the minibuffer, the next window is normally
2999 the one at the top left corner.  You can specify a different window to
3000 scroll, when the minibuffer is selected, by setting the variable
3001 @code{minibuffer-scroll-window}.  This variable has no effect when any
3002 other window is selected.  When it is non-@code{nil} and the
3003 minibuffer is selected, it takes precedence over
3004 @code{other-window-scroll-buffer}.  @xref{Definition of
3005 minibuffer-scroll-window}.
3007 When the minibuffer is active, it is the next window if the selected
3008 window is the one at the bottom right corner.  In this case,
3009 @code{scroll-other-window} attempts to scroll the minibuffer.  If the
3010 minibuffer contains just one line, it has nowhere to scroll to, so the
3011 line reappears after the echo area momentarily displays the message
3012 @samp{Beginning of buffer}.
3013 @end deffn
3015 @defvar other-window-scroll-buffer
3016 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
3017 which buffer's window to scroll.
3018 @end defvar
3020 @defopt scroll-margin
3021 This option specifies the size of the scroll margin---a minimum number
3022 of lines between point and the top or bottom of a window.  Whenever
3023 point gets within this many lines of the top or bottom of the window,
3024 redisplay scrolls the text automatically (if possible) to move point
3025 out of the margin, closer to the center of the window.
3026 @end defopt
3028 @defopt scroll-conservatively
3029 This variable controls how scrolling is done automatically when point
3030 moves off the screen (or into the scroll margin).  If the value is a
3031 positive integer @var{n}, then redisplay scrolls the text up to
3032 @var{n} lines in either direction, if that will bring point back into
3033 proper view.  This behavior is called @dfn{conservative scrolling}.
3034 Otherwise, scrolling happens in the usual way, under the control of
3035 other variables such as @code{scroll-up-aggressively} and
3036 @code{scroll-down-aggressively}.
3038 The default value is zero, which means that conservative scrolling
3039 never happens.
3040 @end defopt
3042 @defopt scroll-down-aggressively
3043 The value of this variable should be either @code{nil} or a fraction
3044 @var{f} between 0 and 1.  If it is a fraction, that specifies where on
3045 the screen to put point when scrolling down.  More precisely, when a
3046 window scrolls down because point is above the window start, the new
3047 start position is chosen to put point @var{f} part of the window
3048 height from the top.  The larger @var{f}, the more aggressive the
3049 scrolling.
3051 A value of @code{nil} is equivalent to .5, since its effect is to center
3052 point.  This variable automatically becomes buffer-local when set in any
3053 fashion.
3054 @end defopt
3056 @defopt scroll-up-aggressively
3057 Likewise, for scrolling up.  The value, @var{f}, specifies how far
3058 point should be placed from the bottom of the window; thus, as with
3059 @code{scroll-up-aggressively}, a larger value scrolls more aggressively.
3060 @end defopt
3062 @defopt scroll-step
3063 This variable is an older variant of @code{scroll-conservatively}.
3064 The difference is that if its value is @var{n}, that permits scrolling
3065 only by precisely @var{n} lines, not a smaller number.  This feature
3066 does not work with @code{scroll-margin}.  The default value is zero.
3067 @end defopt
3069 @cindex @code{scroll-command} property
3070 @defopt scroll-preserve-screen-position
3071 If this option is @code{t}, whenever a scrolling command moves point
3072 off-window, Emacs tries to adjust point to keep the cursor at its old
3073 vertical position in the window, rather than the window edge.
3075 If the value is non-@code{nil} and not @code{t}, Emacs adjusts point
3076 to keep the cursor at the same vertical position, even if the
3077 scrolling command didn't move point off-window.
3079 This option affects all scroll commands that have a non-@code{nil}
3080 @code{scroll-command} symbol property.
3081 @end defopt
3083 @defopt next-screen-context-lines
3084 The value of this variable is the number of lines of continuity to
3085 retain when scrolling by full screens.  For example, @code{scroll-up}
3086 with an argument of @code{nil} scrolls so that this many lines at the
3087 bottom of the window appear instead at the top.  The default value is
3088 @code{2}.
3089 @end defopt
3091 @defopt scroll-error-top-bottom
3092 If this option is @code{nil} (the default), @code{scroll-up-command}
3093 and @code{scroll-down-command} simply signal an error when no more
3094 scrolling is possible.
3096 If the value is @code{t}, these commands instead move point to the
3097 beginning or end of the buffer (depending on scrolling direction);
3098 only if point is already on that position do they signal an error.
3099 @end defopt
3101 @deffn Command recenter &optional count
3102 @cindex centering point
3103 This function scrolls the text in the selected window so that point is
3104 displayed at a specified vertical position within the window.  It does
3105 not ``move point'' with respect to the text.
3107 If @var{count} is a non-negative number, that puts the line containing
3108 point @var{count} lines down from the top of the window.  If
3109 @var{count} is a negative number, then it counts upward from the
3110 bottom of the window, so that @minus{}1 stands for the last usable
3111 line in the window.  If @var{count} is a non-@code{nil} list, then it
3112 stands for the line in the middle of the window.
3114 If @var{count} is @code{nil}, @code{recenter} puts the line containing
3115 point in the middle of the window, then clears and redisplays the entire
3116 selected frame.
3118 When @code{recenter} is called interactively, @var{count} is the raw
3119 prefix argument.  Thus, typing @kbd{C-u} as the prefix sets the
3120 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
3121 @var{count} to 4, which positions the current line four lines from the
3122 top.
3124 With an argument of zero, @code{recenter} positions the current line at
3125 the top of the window.  This action is so handy that some people make a
3126 separate key binding to do this.  For example,
3128 @example
3129 @group
3130 (defun line-to-top-of-window ()
3131   "Scroll current line to top of window.
3132 Replaces three keystroke sequence C-u 0 C-l."
3133   (interactive)
3134   (recenter 0))
3136 (global-set-key [kp-multiply] 'line-to-top-of-window)
3137 @end group
3138 @end example
3139 @end deffn
3141 @node Vertical Scrolling
3142 @section Vertical Fractional Scrolling
3143 @cindex vertical fractional scrolling
3144 @cindex vertical scroll position
3146    @dfn{Vertical fractional scrolling} means shifting text in a window
3147 up or down by a specified multiple or fraction of a line.  Each window
3148 has a @dfn{vertical scroll position}, which is a number, never less than
3149 zero.  It specifies how far to raise the contents of the window.
3150 Raising the window contents generally makes all or part of some lines
3151 disappear off the top, and all or part of some other lines appear at the
3152 bottom.  The usual value is zero.
3154    The vertical scroll position is measured in units of the normal line
3155 height, which is the height of the default font.  Thus, if the value is
3156 .5, that means the window contents are scrolled up half the normal line
3157 height.  If it is 3.3, that means the window contents are scrolled up
3158 somewhat over three times the normal line height.
3160    What fraction of a line the vertical scrolling covers, or how many
3161 lines, depends on what the lines contain.  A value of .5 could scroll a
3162 line whose height is very short off the screen, while a value of 3.3
3163 could scroll just part of the way through a tall line or an image.
3165 @defun window-vscroll &optional window pixels-p
3166 This function returns the current vertical scroll position of
3167 @var{window}.  The default for @var{window} is the selected window.
3168 If @var{pixels-p} is non-@code{nil}, the return value is measured in
3169 pixels, rather than in units of the normal line height.
3171 @example
3172 @group
3173 (window-vscroll)
3174      @result{} 0
3175 @end group
3176 @end example
3177 @end defun
3179 @defun set-window-vscroll window lines &optional pixels-p
3180 This function sets @var{window}'s vertical scroll position to
3181 @var{lines}.  If @var{window} is @code{nil}, the selected window is
3182 used.  The argument @var{lines} should be zero or positive; if not, it
3183 is taken as zero.
3186 The actual vertical scroll position must always correspond
3187 to an integral number of pixels, so the value you specify
3188 is rounded accordingly.
3190 The return value is the result of this rounding.
3192 @example
3193 @group
3194 (set-window-vscroll (selected-window) 1.2)
3195      @result{} 1.13
3196 @end group
3197 @end example
3199 If @var{pixels-p} is non-@code{nil}, @var{lines} specifies a number of
3200 pixels.  In this case, the return value is @var{lines}.
3201 @end defun
3203 @defvar auto-window-vscroll
3204 If this variable is non-@code{nil}, the line-move, scroll-up, and
3205 scroll-down functions will automatically modify the vertical scroll
3206 position to scroll through display rows that are taller than the height
3207 of the window, for example in the presence of large images.
3208 @end defvar
3210 @node Horizontal Scrolling
3211 @section Horizontal Scrolling
3212 @cindex horizontal scrolling
3214   @dfn{Horizontal scrolling} means shifting the image in the window left
3215 or right by a specified multiple of the normal character width.  Each
3216 window has a @dfn{horizontal scroll position}, which is a number, never
3217 less than zero.  It specifies how far to shift the contents left.
3218 Shifting the window contents left generally makes all or part of some
3219 characters disappear off the left, and all or part of some other
3220 characters appear at the right.  The usual value is zero.
3222   The horizontal scroll position is measured in units of the normal
3223 character width, which is the width of space in the default font.  Thus,
3224 if the value is 5, that means the window contents are scrolled left by 5
3225 times the normal character width.  How many characters actually
3226 disappear off to the left depends on their width, and could vary from
3227 line to line.
3229   Because we read from side to side in the ``inner loop,'' and from top
3230 to bottom in the ``outer loop,'' the effect of horizontal scrolling is
3231 not like that of textual or vertical scrolling.  Textual scrolling
3232 involves selection of a portion of text to display, and vertical
3233 scrolling moves the window contents contiguously; but horizontal
3234 scrolling causes part of @emph{each line} to go off screen.
3236   Usually, no horizontal scrolling is in effect; then the leftmost
3237 column is at the left edge of the window.  In this state, scrolling to
3238 the right is meaningless, since there is no data to the left of the edge
3239 to be revealed by it; so this is not allowed.  Scrolling to the left is
3240 allowed; it scrolls the first columns of text off the edge of the window
3241 and can reveal additional columns on the right that were truncated
3242 before.  Once a window has a nonzero amount of leftward horizontal
3243 scrolling, you can scroll it back to the right, but only so far as to
3244 reduce the net horizontal scroll to zero.  There is no limit to how far
3245 left you can scroll, but eventually all the text will disappear off the
3246 left edge.
3248 @vindex auto-hscroll-mode
3249   If @code{auto-hscroll-mode} is set, redisplay automatically alters
3250 the horizontal scrolling of a window as necessary to ensure that point
3251 is always visible.  However, you can still set the horizontal
3252 scrolling value explicitly.  The value you specify serves as a lower
3253 bound for automatic scrolling, i.e. automatic scrolling will not
3254 scroll a window to a column less than the specified one.
3256 @deffn Command scroll-left &optional count set-minimum
3257 This function scrolls the selected window @var{count} columns to the
3258 left (or to the right if @var{count} is negative).  The default
3259 for @var{count} is the window width, minus 2.
3261 The return value is the total amount of leftward horizontal scrolling in
3262 effect after the change---just like the value returned by
3263 @code{window-hscroll} (below).
3265 Once you scroll a window as far right as it can go, back to its normal
3266 position where the total leftward scrolling is zero, attempts to scroll
3267 any farther right have no effect.
3269 If @var{set-minimum} is non-@code{nil}, the new scroll amount becomes
3270 the lower bound for automatic scrolling; that is, automatic scrolling
3271 will not scroll a window to a column less than the value returned by
3272 this function.  Interactive calls pass non-@code{nil} for
3273 @var{set-minimum}.
3274 @end deffn
3276 @deffn Command scroll-right &optional count set-minimum
3277 This function scrolls the selected window @var{count} columns to the
3278 right (or to the left if @var{count} is negative).  The default
3279 for @var{count} is the window width, minus 2.  Aside from the direction
3280 of scrolling, this works just like @code{scroll-left}.
3281 @end deffn
3283 @defun window-hscroll &optional window
3284 This function returns the total leftward horizontal scrolling of
3285 @var{window}---the number of columns by which the text in @var{window}
3286 is scrolled left past the left margin.  The default for
3287 @var{window} is the selected window.
3289 The return value is never negative.  It is zero when no horizontal
3290 scrolling has been done in @var{window} (which is usually the case).
3293 @example
3294 @group
3295 (window-hscroll)
3296      @result{} 0
3297 @end group
3298 @group
3299 (scroll-left 5)
3300      @result{} 5
3301 @end group
3302 @group
3303 (window-hscroll)
3304      @result{} 5
3305 @end group
3306 @end example
3307 @end defun
3309 @defun set-window-hscroll window columns
3310 This function sets horizontal scrolling of @var{window}.  The value of
3311 @var{columns} specifies the amount of scrolling, in terms of columns
3312 from the left margin.  The argument @var{columns} should be zero or
3313 positive; if not, it is taken as zero.  Fractional values of
3314 @var{columns} are not supported at present.
3316 Note that @code{set-window-hscroll} may appear not to work if you test
3317 it by evaluating a call with @kbd{M-:} in a simple way.  What happens
3318 is that the function sets the horizontal scroll value and returns, but
3319 then redisplay adjusts the horizontal scrolling to make point visible,
3320 and this overrides what the function did.  You can observe the
3321 function's effect if you call it while point is sufficiently far from
3322 the left margin that it will remain visible.
3324 The value returned is @var{columns}.
3326 @example
3327 @group
3328 (set-window-hscroll (selected-window) 10)
3329      @result{} 10
3330 @end group
3331 @end example
3332 @end defun
3334    Here is how you can determine whether a given position @var{position}
3335 is off the screen due to horizontal scrolling:
3337 @example
3338 @group
3339 (defun hscroll-on-screen (window position)
3340   (save-excursion
3341     (goto-char position)
3342     (and
3343      (>= (- (current-column) (window-hscroll window)) 0)
3344      (< (- (current-column) (window-hscroll window))
3345         (window-width window)))))
3346 @end group
3347 @end example
3350 @node Coordinates and Windows
3351 @section Coordinates and Windows
3353 This section describes how to relate screen coordinates to windows.
3355 @defun window-at x y &optional frame
3356 This function returns the window containing the specified cursor
3357 position in the frame @var{frame}.  The coordinates @var{x} and @var{y}
3358 are measured in characters and count from the top left corner of the
3359 frame.  If they are out of range, @code{window-at} returns @code{nil}.
3361 If you omit @var{frame}, the selected frame is used.
3362 @end defun
3364 @defun coordinates-in-window-p coordinates window
3365 This function checks whether a particular frame position falls within
3366 the window @var{window}.
3368 The argument @var{coordinates} is a cons cell of the form @code{(@var{x}
3369 . @var{y})}.  The coordinates @var{x} and @var{y} are measured in
3370 characters, and count from the top left corner of the screen or frame.
3372 The value returned by @code{coordinates-in-window-p} is non-@code{nil}
3373 if the coordinates are inside @var{window}.  The value also indicates
3374 what part of the window the position is in, as follows:
3376 @table @code
3377 @item (@var{relx} . @var{rely})
3378 The coordinates are inside @var{window}.  The numbers @var{relx} and
3379 @var{rely} are the equivalent window-relative coordinates for the
3380 specified position, counting from 0 at the top left corner of the
3381 window.
3383 @item mode-line
3384 The coordinates are in the mode line of @var{window}.
3386 @item header-line
3387 The coordinates are in the header line of @var{window}.
3389 @item vertical-line
3390 The coordinates are in the vertical line between @var{window} and its
3391 neighbor to the right.  This value occurs only if the window doesn't
3392 have a scroll bar; positions in a scroll bar are considered outside the
3393 window for these purposes.
3395 @item left-fringe
3396 @itemx right-fringe
3397 The coordinates are in the left or right fringe of the window.
3399 @item left-margin
3400 @itemx right-margin
3401 The coordinates are in the left or right margin of the window.
3403 @item nil
3404 The coordinates are not in any part of @var{window}.
3405 @end table
3407 The function @code{coordinates-in-window-p} does not require a frame as
3408 argument because it always uses the frame that @var{window} is on.
3409 @end defun
3412 @node Window Configurations
3413 @section Window Configurations
3414 @cindex window configurations
3415 @cindex saving window information
3417 A @dfn{window configuration} records the entire layout of one
3418 frame---all windows, their sizes, which buffers they contain, how those
3419 buffers are scrolled, and their values of point and the mark; also their
3420 fringes, margins, and scroll bar settings.  It also includes the value
3421 of @code{minibuffer-scroll-window}.  As a special exception, the window
3422 configuration does not record the value of point in the selected window
3423 for the current buffer.
3425   You can bring back an entire frame layout by restoring a previously
3426 saved window configuration.  If you want to record the layout of all
3427 frames instead of just one, use a frame configuration instead of a
3428 window configuration; see @ref{Frame Configurations}.
3430 @defun current-window-configuration &optional frame
3431 This function returns a new object representing @var{frame}'s current
3432 window configuration.  The default for @var{frame} is the selected
3433 frame.
3434 @end defun
3436 @defun set-window-configuration configuration
3437 This function restores the configuration of windows and buffers as
3438 specified by @var{configuration}, for the frame that @var{configuration}
3439 was created for.
3441 The argument @var{configuration} must be a value that was previously
3442 returned by @code{current-window-configuration}.  The configuration is
3443 restored in the frame from which @var{configuration} was made, whether
3444 that frame is selected or not.  This always counts as a window size
3445 change and triggers execution of the @code{window-size-change-functions}
3446 (@pxref{Window Hooks}), because @code{set-window-configuration} doesn't
3447 know how to tell whether the new configuration actually differs from the
3448 old one.
3450 If the frame which @var{configuration} was saved from is dead, all this
3451 function does is restore the three variables @code{window-min-height},
3452 @code{window-min-width} and @code{minibuffer-scroll-window}. In this
3453 case, the function returns @code{nil}.  Otherwise, it returns @code{t}.
3455 Here is a way of using this function to get the same effect
3456 as @code{save-window-excursion}:
3458 @example
3459 @group
3460 (let ((config (current-window-configuration)))
3461   (unwind-protect
3462       (progn (split-window-below nil)
3463              @dots{})
3464     (set-window-configuration config)))
3465 @end group
3466 @end example
3467 @end defun
3469 @defspec save-window-excursion forms@dots{}
3470 This special form records the window configuration, executes @var{forms}
3471 in sequence, then restores the earlier window configuration.  The window
3472 configuration includes, for each window, the value of point and the
3473 portion of the buffer that is visible.  It also includes the choice of
3474 selected window.  However, it does not include the value of point in
3475 the current buffer; use @code{save-excursion} also, if you wish to
3476 preserve that.
3478 Don't use this construct when @code{save-selected-window} is sufficient.
3480 Exit from @code{save-window-excursion} always triggers execution of
3481 @code{window-size-change-functions}.  (It doesn't know how to tell
3482 whether the restored configuration actually differs from the one in
3483 effect at the end of the @var{forms}.)
3485 The return value is the value of the final form in @var{forms}.
3486 For example:
3488 @example
3489 @group
3490 (split-window)
3491      @result{} #<window 25 on control.texi>
3492 @end group
3493 @group
3494 (setq w (selected-window))
3495      @result{} #<window 19 on control.texi>
3496 @end group
3497 @group
3498 (save-window-excursion
3499   (delete-other-windows w)
3500   (switch-to-buffer "foo")
3501   'do-something)
3502      @result{} do-something
3503      ;; @r{The screen is now split again.}
3504 @end group
3505 @end example
3506 @end defspec
3508 @defun window-configuration-p object
3509 This function returns @code{t} if @var{object} is a window configuration.
3510 @end defun
3512 @defun compare-window-configurations config1 config2
3513 This function compares two window configurations as regards the
3514 structure of windows, but ignores the values of point and mark and the
3515 saved scrolling positions---it can return @code{t} even if those
3516 aspects differ.
3518 The function @code{equal} can also compare two window configurations; it
3519 regards configurations as unequal if they differ in any respect, even a
3520 saved point or mark.
3521 @end defun
3523 @defun window-configuration-frame config
3524 This function returns the frame for which the window configuration
3525 @var{config} was made.
3526 @end defun
3528   Other primitives to look inside of window configurations would make
3529 sense, but are not implemented because we did not need them.  See the
3530 file @file{winner.el} for some more operations on windows
3531 configurations.
3533   The objects returned by @code{current-window-configuration} die
3534 together with the Emacs process.  In order to store a window
3535 configuration on disk and read it back in another Emacs session the
3536 following two functions can be used.
3538 @defun window-state-get &optional window markers
3539 This function returns the state of @var{window} as a Lisp object.  The
3540 argument @var{window} can be any window and defaults to the root window
3541 of the selected frame.
3543 The optional argument @var{markers} non-@code{nil} means to use markers
3544 for sampling positions like @code{window-point} or @code{window-start}.
3545 This argument should be non-@code{nil} only if the value is used for
3546 putting the state back in the same session since markers slow down
3547 processing.
3548 @end defun
3550 The value returned by @code{window-state-get} can be converted by using
3551 one of the functions defined by Desktop Save Mode (@pxref{Desktop Save
3552 Mode}) to an object that can be written to a file.  Such objects can be
3553 read back and converted to a Lisp object representing the state of the
3554 window.  That Lisp object can be used as argument for the following
3555 function in order to restore the state window in another window.
3557 @defun window-state-put state &optional window ignore
3558 This function puts the window state @var{state} into @var{window}.  The
3559 argument @var{state} should be the state of a window returned by an
3560 earlier invocation of @code{window-state-get}, see above.  The optional
3561 argument @var{window} must specify a live window and defaults to the
3562 selected one.
3564 The optional argument @var{ignore} non-@code{nil} means to ignore
3565 minimum window sizes and fixed size restrictions.  If @var{ignore}
3566 equals @code{safe}, this means windows can get as small as one line
3567 and/or two columns.
3568 @end defun
3571 @node Window Parameters
3572 @section Window Parameters
3573 @cindex window parameters
3575 This section describes how window parameters can be used to associate
3576 additional information with windows.
3578 @defun window-parameter window parameter
3579 This function returns @var{window}'s value for @var{parameter}.  The
3580 default for @var{window} is the selected window.  If @var{window} has no
3581 setting for @var{parameter}, this function returns @code{nil}.
3582 @end defun
3584 @defun window-parameters &optional window
3585 This function returns all parameters of @var{window} and their values.
3586 The default for @var{window} is the selected window.  The return value,
3587 if non-@code{nil} is an association list whose elements have the form
3588 @code{(@var{parameter} . @var{value})}.
3589 @end defun
3591 @defun set-window-parameter window parameter value
3592 This function sets @var{window}'s value of @var{parameter} to
3593 @var{value} and returns @var{value}.  The default for @var{window}
3594 is the selected window.
3595 @end defun
3597 Some functions, notably @code{delete-window},
3598 @code{delete-other-windows} and @code{split-window} may behave specially
3599 when their @var{window} argument has a parameter set.  You can override
3600 such special behavior by binding the following variable to a
3601 non-@code{nil} value:
3603 @defvar ignore-window-parameters
3604 If this variable is non-@code{nil}, some standard functions do not
3605 process window parameters.  The functions currently affected by this are
3606 @code{split-window}, @code{delete-window}, @code{delete-other-windows}
3607 and @code{other-window}.
3609 An application can bind this variable to a non-@code{nil} value around
3610 calls to these functions.  If it does so, the application is fully
3611 responsible for correctly assigning the parameters of all involved
3612 windows when exiting that function.
3613 @end defvar
3615 The following parameters are currently used by the window management
3616 code.
3618 @table @asis
3619 @item @code{delete-window}
3620 This parameter affects the execution of @code{delete-window}
3621 (@pxref{Deleting Windows}).
3623 @item @code{delete-other-windows}
3624 This parameter affects the execution of @code{delete-other-windows}
3625 (@pxref{Deleting Windows}).
3627 @item @code{split-window}
3628 This parameter affects the execution of @code{split-window}
3629 (@pxref{Splitting Windows}).
3631 @item @code{other-window}
3632 This parameter affects the execution of @code{other-window}
3633 (@pxref{Cyclic Window Ordering}).
3635 @item @code{no-other-window}
3636 This parameter marks the window as not selectable by @code{other-window}
3637 (@pxref{Cyclic Window Ordering}).
3638 @end table
3640 In addition, the parameters @code{window-atom} and @code{window-side}
3641 are reserved and should not be used by applications.  The
3642 @code{quit-restore} parameter tells how to proceed with a window when
3643 the buffer it shows is no more needed.  This parameter is installed by
3644 the buffer display functions (@pxref{Choosing Window}) and consulted by
3645 the function @code{quit-window} (@pxref{Quitting Windows}).
3648 @node Window Hooks
3649 @section Hooks for Window Scrolling and Changes
3650 @cindex hooks for window operations
3652 This section describes how a Lisp program can take action whenever a
3653 window displays a different part of its buffer or a different buffer.
3654 There are three actions that can change this: scrolling the window,
3655 switching buffers in the window, and changing the size of the window.
3656 The first two actions run @code{window-scroll-functions}; the last runs
3657 @code{window-size-change-functions}.
3659 @defvar window-scroll-functions
3660 This variable holds a list of functions that Emacs should call before
3661 redisplaying a window with scrolling.  Displaying a different buffer in
3662 the window also runs these functions.
3664 This variable is not a normal hook, because each function is called with
3665 two arguments: the window, and its new display-start position.
3667 These functions must be careful in using @code{window-end}
3668 (@pxref{Window Start and End}); if you need an up-to-date value, you
3669 must use the @var{update} argument to ensure you get it.
3671 @strong{Warning:} don't use this feature to alter the way the window
3672 is scrolled.  It's not designed for that, and such use probably won't
3673 work.
3674 @end defvar
3676 @defvar window-size-change-functions
3677 This variable holds a list of functions to be called if the size of any
3678 window changes for any reason.  The functions are called just once per
3679 redisplay, and just once for each frame on which size changes have
3680 occurred.
3682 Each function receives the frame as its sole argument.  There is no
3683 direct way to find out which windows on that frame have changed size, or
3684 precisely how.  However, if a size-change function records, at each
3685 call, the existing windows and their sizes, it can also compare the
3686 present sizes and the previous sizes.
3688 Creating or deleting windows counts as a size change, and therefore
3689 causes these functions to be called.  Changing the frame size also
3690 counts, because it changes the sizes of the existing windows.
3692 It is not a good idea to use @code{save-window-excursion} (@pxref{Window
3693 Configurations}) in these functions, because that always counts as a
3694 size change, and it would cause these functions to be called over and
3695 over.  In most cases, @code{save-selected-window} (@pxref{Selecting
3696 Windows}) is what you need here.
3697 @end defvar
3699 @defvar window-configuration-change-hook
3700 A normal hook that is run every time you change the window configuration
3701 of an existing frame.  This includes splitting or deleting windows,
3702 changing the sizes of windows, or displaying a different buffer in a
3703 window.
3705 The buffer-local part of this hook is run once per each window on the
3706 affected frame, with the relevant window selected and its buffer
3707 current.  The global part is run once for the modified frame, with that
3708 frame selected.
3709 @end defvar
3711   In addition, you can use @code{jit-lock-register} to register a Font
3712 Lock fontification function, which will be called whenever parts of a
3713 buffer are (re)fontified because a window was scrolled or its size
3714 changed.  @xref{Other Font Lock Variables}.