]> code.delx.au - gnu-emacs/blob - doc/lispref/windows.texi
Quote less in manuals
[gnu-emacs] / doc / lispref / windows.texi
1 @c -*-texinfo-*-
2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 1990-1995, 1998-1999, 2001-2015 Free Software
4 @c Foundation, Inc.
5 @c See the file elisp.texi for copying conditions.
6 @node Windows
7 @chapter Windows
8
9 This chapter describes the functions and variables related to Emacs
10 windows. @xref{Frames}, for how windows are assigned an area of screen
11 available for Emacs to use. @xref{Display}, for information on how text
12 is displayed in windows.
13
14 @menu
15 * Basic Windows:: Basic information on using windows.
16 * Windows and Frames:: Relating windows to the frame they appear on.
17 * Window Sizes:: Accessing a window's size.
18 * Resizing Windows:: Changing the sizes of windows.
19 * Preserving Window Sizes:: Preserving the size of windows.
20 * Splitting Windows:: Creating a new window.
21 * Deleting Windows:: Removing a window from its frame.
22 * Recombining Windows:: Preserving the frame layout when splitting and
23 deleting windows.
24 * Selecting Windows:: The selected window is the one that you edit in.
25 * Cyclic Window Ordering:: Moving around the existing windows.
26 * Buffers and Windows:: Each window displays the contents of a buffer.
27 * Switching Buffers:: Higher-level functions for switching to a buffer.
28 * Choosing Window:: How to choose a window for displaying a buffer.
29 * Display Action Functions:: Subroutines for @code{display-buffer}.
30 * Choosing Window Options:: Extra options affecting how buffers are displayed.
31 * Window History:: Each window remembers the buffers displayed in it.
32 * Dedicated Windows:: How to avoid displaying another buffer in
33 a specific window.
34 * Quitting Windows:: How to restore the state prior to displaying a
35 buffer.
36 * Window Point:: Each window has its own location of point.
37 * Window Start and End:: Buffer positions indicating which text is
38 on-screen in a window.
39 * Textual Scrolling:: Moving text up and down through the window.
40 * Vertical Scrolling:: Moving the contents up and down on the window.
41 * Horizontal Scrolling:: Moving the contents sideways on the window.
42 * Coordinates and Windows:: Converting coordinates to windows.
43 * Window Configurations:: Saving and restoring the state of the screen.
44 * Window Parameters:: Associating additional information with windows.
45 * Window Hooks:: Hooks for scrolling, window size changes,
46 redisplay going past a certain point,
47 or window configuration changes.
48 @end menu
49
50
51 @node Basic Windows
52 @section Basic Concepts of Emacs Windows
53 @cindex window
54
55 A @dfn{window} is an area of the screen that is used to display a buffer
56 (@pxref{Buffers}). In Emacs Lisp, windows are represented by a special
57 Lisp object type.
58
59 @cindex multiple windows
60 Windows are grouped into frames (@pxref{Frames}). Each frame
61 contains at least one window; the user can subdivide it into multiple,
62 non-overlapping windows to view several buffers at once. Lisp
63 programs can use multiple windows for a variety of purposes. In
64 Rmail, for example, you can view a summary of message titles in one
65 window, and the contents of the selected message in another window.
66
67 @cindex terminal screen
68 @cindex screen of terminal
69 Emacs uses the word ``window'' with a different meaning than in
70 graphical desktop environments and window systems, such as the X
71 Window System. When Emacs is run on X, each of its graphical X
72 windows is an Emacs frame (containing one or more Emacs windows).
73 When Emacs is run on a text terminal, the frame fills the entire
74 terminal screen.
75
76 @cindex tiled windows
77 Unlike X windows, Emacs windows are @dfn{tiled}; they never overlap
78 within the area of the frame. When a window is created, resized, or
79 deleted, the change in window space is taken from or given to the
80 adjacent windows, so that the total area of the frame is unchanged.
81
82 @defun windowp object
83 This function returns @code{t} if @var{object} is a window (whether or
84 not it displays a buffer). Otherwise, it returns @code{nil}.
85 @end defun
86
87 @cindex live windows
88 A @dfn{live window} is one that is actually displaying a buffer in a
89 frame.
90
91 @defun window-live-p object
92 This function returns @code{t} if @var{object} is a live window and
93 @code{nil} otherwise. A live window is one that displays a buffer.
94 @end defun
95
96 @cindex internal windows
97 The windows in each frame are organized into a @dfn{window tree}.
98 @xref{Windows and Frames}. The leaf nodes of each window tree are live
99 windows---the ones actually displaying buffers. The internal nodes of
100 the window tree are @dfn{internal windows}, which are not live.
101
102 @cindex valid windows
103 A @dfn{valid window} is one that is either live or internal. A valid
104 window can be @dfn{deleted}, i.e., removed from its frame
105 (@pxref{Deleting Windows}); then it is no longer valid, but the Lisp
106 object representing it might be still referenced from other Lisp
107 objects. A deleted window may be made valid again by restoring a saved
108 window configuration (@pxref{Window Configurations}).
109
110 You can distinguish valid windows from deleted windows with
111 @code{window-valid-p}.
112
113 @defun window-valid-p object
114 This function returns @code{t} if @var{object} is a live window, or an
115 internal window in a window tree. Otherwise, it returns @code{nil},
116 including for the case where @var{object} is a deleted window.
117 @end defun
118
119 @cindex selected window
120 @cindex window selected within a frame
121 In each frame, at any time, exactly one Emacs window is designated
122 as @dfn{selected within the frame}. For the selected frame, that
123 window is called the @dfn{selected window}---the one in which most
124 editing takes place, and in which the cursor for selected windows
125 appears (@pxref{Cursor Parameters}). The selected window's buffer is
126 usually also the current buffer, except when @code{set-buffer} has
127 been used (@pxref{Current Buffer}). As for non-selected frames, the
128 window selected within the frame becomes the selected window if the
129 frame is ever selected. @xref{Selecting Windows}.
130
131 @defun selected-window
132 This function returns the selected window (which is always a live
133 window).
134 @end defun
135
136 @node Windows and Frames
137 @section Windows and Frames
138
139 Each window belongs to exactly one frame (@pxref{Frames}).
140
141 @defun window-frame &optional window
142 This function returns the frame that the window @var{window} belongs
143 to. If @var{window} is @code{nil}, it defaults to the selected
144 window.
145 @end defun
146
147 @defun window-list &optional frame minibuffer window
148 This function returns a list of live windows belonging to the frame
149 @var{frame}. If @var{frame} is omitted or @code{nil}, it defaults to
150 the selected frame.
151
152 The optional argument @var{minibuffer} specifies whether to include
153 the minibuffer window in the returned list. If @var{minibuffer} is
154 @code{t}, the minibuffer window is included. If @var{minibuffer} is
155 @code{nil} or omitted, the minibuffer window is included only if it is
156 active. If @var{minibuffer} is neither @code{nil} nor @code{t}, the
157 minibuffer window is never included.
158
159 The optional argument @var{window}, if non-@code{nil}, should be a live
160 window on the specified frame; then @var{window} will be the first
161 element in the returned list. If @var{window} is omitted or @code{nil},
162 the window selected within the frame is the first element.
163 @end defun
164
165 @cindex window tree
166 @cindex root window
167 Windows in the same frame are organized into a @dfn{window tree},
168 whose leaf nodes are the live windows. The internal nodes of a window
169 tree are not live; they exist for the purpose of organizing the
170 relationships between live windows. The root node of a window tree is
171 called the @dfn{root window}. It can be either a live window (if the
172 frame has just one window), or an internal window.
173
174 A minibuffer window (@pxref{Minibuffer Windows}) is not part of its
175 frame's window tree unless the frame is a minibuffer-only frame.
176 Nonetheless, most of the functions in this section accept the
177 minibuffer window as an argument. Also, the function
178 @code{window-tree} described at the end of this section lists the
179 minibuffer window alongside the actual window tree.
180
181 @defun frame-root-window &optional frame-or-window
182 This function returns the root window for @var{frame-or-window}. The
183 argument @var{frame-or-window} should be either a window or a frame;
184 if omitted or @code{nil}, it defaults to the selected frame. If
185 @var{frame-or-window} is a window, the return value is the root window
186 of that window's frame.
187 @end defun
188
189 @cindex parent window
190 @cindex child window
191 @cindex sibling window
192 When a window is split, there are two live windows where previously
193 there was one. One of these is represented by the same Lisp window
194 object as the original window, and the other is represented by a
195 newly-created Lisp window object. Both of these live windows become
196 leaf nodes of the window tree, as @dfn{child windows} of a single
197 internal window. If necessary, Emacs automatically creates this
198 internal window, which is also called the @dfn{parent window}, and
199 assigns it to the appropriate position in the window tree. A set of
200 windows that share the same parent are called @dfn{siblings}.
201
202 @cindex parent window
203 @defun window-parent &optional window
204 This function returns the parent window of @var{window}. If
205 @var{window} is omitted or @code{nil}, it defaults to the selected
206 window. The return value is @code{nil} if @var{window} has no parent
207 (i.e., it is a minibuffer window or the root window of its frame).
208 @end defun
209
210 Each internal window always has at least two child windows. If this
211 number falls to one as a result of window deletion, Emacs
212 automatically deletes the internal window, and its sole remaining
213 child window takes its place in the window tree.
214
215 Each child window can be either a live window, or an internal window
216 (which in turn would have its own child windows). Therefore, each
217 internal window can be thought of as occupying a certain rectangular
218 @dfn{screen area}---the union of the areas occupied by the live
219 windows that are ultimately descended from it.
220
221 @cindex window combination
222 @cindex vertical combination
223 @cindex horizontal combination
224 For each internal window, the screen areas of the immediate children
225 are arranged either vertically or horizontally (never both). If the
226 child windows are arranged one above the other, they are said to form
227 a @dfn{vertical combination}; if they are arranged side by side, they
228 are said to form a @dfn{horizontal combination}. Consider the
229 following example:
230
231 @smallexample
232 @group
233 ______________________________________
234 | ______ ____________________________ |
235 || || __________________________ ||
236 || ||| |||
237 || ||| |||
238 || ||| |||
239 || |||____________W4____________|||
240 || || __________________________ ||
241 || ||| |||
242 || ||| |||
243 || |||____________W5____________|||
244 ||__W2__||_____________W3_____________ |
245 |__________________W1__________________|
246
247 @end group
248 @end smallexample
249
250 @noindent
251 The root window of this frame is an internal window, @var{W1}. Its
252 child windows form a horizontal combination, consisting of the live
253 window @var{W2} and the internal window @var{W3}. The child windows
254 of @var{W3} form a vertical combination, consisting of the live
255 windows @var{W4} and @var{W5}. Hence, the live windows in this
256 window tree are @var{W2}, @var{W4}, and @var{W5}.
257
258 The following functions can be used to retrieve a child window of an
259 internal window, and the siblings of a child window.
260
261 @defun window-top-child &optional window
262 This function returns the topmost child window of @var{window}, if
263 @var{window} is an internal window whose children form a vertical
264 combination. For any other type of window, the return value is
265 @code{nil}.
266 @end defun
267
268 @defun window-left-child &optional window
269 This function returns the leftmost child window of @var{window}, if
270 @var{window} is an internal window whose children form a horizontal
271 combination. For any other type of window, the return value is
272 @code{nil}.
273 @end defun
274
275 @defun window-child window
276 This function returns the first child window of the internal window
277 @var{window}---the topmost child window for a vertical combination, or
278 the leftmost child window for a horizontal combination. If
279 @var{window} is a live window, the return value is @code{nil}.
280 @end defun
281
282 @defun window-combined-p &optional window horizontal
283 This function returns a non-@code{nil} value if and only if
284 @var{window} is part of a vertical combination. If @var{window} is
285 omitted or @code{nil}, it defaults to the selected one.
286
287 If the optional argument @var{horizontal} is non-@code{nil}, this
288 means to return non-@code{nil} if and only if @var{window} is part of
289 a horizontal combination.
290 @end defun
291
292 @defun window-next-sibling &optional window
293 This function returns the next sibling of the window @var{window}. If
294 omitted or @code{nil}, @var{window} defaults to the selected window.
295 The return value is @code{nil} if @var{window} is the last child of
296 its parent.
297 @end defun
298
299 @defun window-prev-sibling &optional window
300 This function returns the previous sibling of the window @var{window}.
301 If omitted or @code{nil}, @var{window} defaults to the selected
302 window. The return value is @code{nil} if @var{window} is the first
303 child of its parent.
304 @end defun
305
306 The functions @code{window-next-sibling} and
307 @code{window-prev-sibling} should not be confused with the functions
308 @code{next-window} and @code{previous-window}, which return the next
309 and previous window, respectively, in the cyclic ordering of windows
310 (@pxref{Cyclic Window Ordering}).
311
312 You can use the following functions to find the first live window on a
313 frame and the window nearest to a given window.
314
315 @defun frame-first-window &optional frame-or-window
316 This function returns the live window at the upper left corner of the
317 frame specified by @var{frame-or-window}. The argument
318 @var{frame-or-window} must denote a window or a live frame and defaults
319 to the selected frame. If @var{frame-or-window} specifies a window,
320 this function returns the first window on that window's frame. Under
321 the assumption that the frame from our canonical example is selected
322 @code{(frame-first-window)} returns @var{W2}.
323 @end defun
324
325 @cindex window in direction
326 @defun window-in-direction direction &optional window ignore sign wrap mini
327 This function returns the nearest live window in direction
328 @var{direction} as seen from the position of @code{window-point} in
329 window @var{window}. The argument @var{direction} must be one of
330 @code{above}, @code{below}, @code{left} or @code{right}. The optional
331 argument @var{window} must denote a live window and defaults to the
332 selected one.
333
334 This function does not return a window whose @code{no-other-window}
335 parameter is non-@code{nil} (@pxref{Window Parameters}). If the nearest
336 window's @code{no-other-window} parameter is non-@code{nil}, this
337 function tries to find another window in the indicated direction whose
338 @code{no-other-window} parameter is @code{nil}. If the optional
339 argument @var{ignore} is non-@code{nil}, a window may be returned even
340 if its @code{no-other-window} parameter is non-@code{nil}.
341
342 If the optional argument @var{sign} is a negative number, it means to
343 use the right or bottom edge of @var{window} as reference position
344 instead of @code{window-point}. If @var{sign} is a positive number, it
345 means to use the left or top edge of @var{window} as reference position.
346
347 If the optional argument @var{wrap} is non-@code{nil}, this means to
348 wrap @var{direction} around frame borders. For example, if @var{window}
349 is at the top of the frame and @var{direction} is @code{above}, then
350 return the minibuffer window provided the frame has one, and a window at
351 the bottom of the frame otherwise.
352
353 If the optional argument @var{mini} is @code{nil}, this means to return
354 the minibuffer window if and only if it is currently active. If
355 @var{mini} is non-@code{nil}, it returns the minibuffer window even when
356 it's not active. However, if @var{wrap} non-@code{nil}, it always acts
357 as if @var{mini} were @code{nil}.
358
359 If it doesn't find a suitable window, this function returns @code{nil}.
360 @end defun
361
362 The following function allows to retrieve the entire window tree of a
363 frame:
364
365 @defun window-tree &optional frame
366 This function returns a list representing the window tree for frame
367 @var{frame}. If @var{frame} is omitted or @code{nil}, it defaults to
368 the selected frame.
369
370 The return value is a list of the form @code{(@var{root} @var{mini})},
371 where @var{root} represents the window tree of the frame's root
372 window, and @var{mini} is the frame's minibuffer window.
373
374 If the root window is live, @var{root} is that window itself.
375 Otherwise, @var{root} is a list @code{(@var{dir} @var{edges} @var{w1}
376 @var{w2} ...)} where @var{dir} is @code{nil} for a horizontal
377 combination and @code{t} for a vertical combination, @var{edges} gives
378 the size and position of the combination, and the remaining elements
379 are the child windows. Each child window may again be a window object
380 (for a live window) or a list with the same format as above (for an
381 internal window). The @var{edges} element is a list @code{(@var{left}
382 @var{top} @var{right} @var{bottom})}, similar to the value returned by
383 @code{window-edges} (@pxref{Coordinates and Windows}).
384 @end defun
385
386
387 @node Window Sizes
388 @section Window Sizes
389 @cindex window size
390 @cindex size of window
391
392 The following schematic shows the structure of a live window:
393
394 @smallexample
395 @group
396 ____________________________________________
397 |______________ Header Line ______________|RD| ^
398 ^ |LS|LM|LF| |RF|RM|RS| | |
399 | | | | | | | | | | |
400 Window | | | | Text Area | | | | | Window
401 Body | | | | | (Window Body) | | | | | Total
402 Height | | | | | | | | | Height
403 | | | | |<- Window Body Width ->| | | | | |
404 v |__|__|__|_______________________|__|__|__| | |
405 |_________ Horizontal Scroll Bar _________| | |
406 |_______________ Mode Line _______________|__| |
407 |_____________ Bottom Divider _______________| v
408 <---------- Window Total Width ------------>
409
410 @end group
411 @end smallexample
412
413 @cindex window body
414 @cindex text area of a window
415 @cindex body of a window
416 At the center of the window is the @dfn{text area}, or @dfn{body},
417 where the buffer text is displayed. The text area can be surrounded by
418 a series of optional areas. On the left and right, from innermost to
419 outermost, these are the left and right fringes, denoted by LF and RF
420 (@pxref{Fringes}); the left and right margins, denoted by LM and RM in
421 the schematic (@pxref{Display Margins}); the left or right vertical
422 scroll bar, only one of which is present at any time, denoted by LS and
423 RS (@pxref{Scroll Bars}); and the right divider, denoted by RD
424 (@pxref{Window Dividers}). At the top of the window is the header line
425 (@pxref{Header Lines}). At the bottom of the window are the horizontal
426 scroll bar (@pxref{Scroll Bars}); the mode line (@pxref{Mode Line
427 Format}); and the bottom divider (@pxref{Window Dividers}).
428
429 Emacs provides miscellaneous functions for finding the height and
430 width of a window. The return value of many of these functions can be
431 specified either in units of pixels or in units of lines and columns.
432 On a graphical display, the latter actually correspond to the height and
433 width of a default character specified by the frame's default font
434 as returned by @code{frame-char-height} and @code{frame-char-width}
435 (@pxref{Frame Font}). Thus, if a window is displaying text with a
436 different font or size, the reported line height and column width for
437 that window may differ from the actual number of text lines or columns
438 displayed within it.
439
440 @cindex window height
441 @cindex height of a window
442 @cindex total height of a window
443 The @dfn{total height} of a window is the number of lines comprising
444 the window's body, the header line, the horizontal scroll bar, the mode
445 line and the bottom divider (if any).
446
447 @defun window-total-height &optional window round
448 This function returns the total height, in lines, of the window
449 @var{window}. If @var{window} is omitted or @code{nil}, it defaults to
450 the selected window. If @var{window} is an internal window, the return
451 value is the total height occupied by its descendant windows.
452
453 If a window's pixel height is not an integral multiple of its frame's
454 default character height, the number of lines occupied by the window is
455 rounded internally. This is done in a way such that, if the window is a
456 parent window, the sum of the total heights of all its child windows
457 internally equals the total height of their parent. This means that
458 although two windows have the same pixel height, their internal total
459 heights may differ by one line. This means also, that if window is
460 vertically combined and has a next sibling, the topmost row of that
461 sibling can be calculated as the sum of this window's topmost row and
462 total height (@pxref{Coordinates and Windows})
463
464 If the optional argument @var{round} is @code{ceiling}, this
465 function returns the smallest integer larger than @var{window}'s pixel
466 height divided by the character height of its frame; if it is
467 @code{floor}, it returns the largest integer smaller than said value;
468 with any other @var{round} it returns the internal value of
469 @var{windows}'s total height.
470 @end defun
471
472 @cindex window width
473 @cindex width of a window
474 @cindex total width of a window
475 The @dfn{total width} of a window is the number of lines comprising the
476 window's body, its margins, fringes, scroll bars and a right divider (if
477 any).
478
479 @defun window-total-width &optional window round
480 This function returns the total width, in columns, of the window
481 @var{window}. If @var{window} is omitted or @code{nil}, it defaults to
482 the selected window. If @var{window} is internal, the return value is
483 the total width occupied by its descendant windows.
484
485 If a window's pixel width is not an integral multiple of its frame's
486 character width, the number of lines occupied by the window is rounded
487 internally. This is done in a way such that, if the window is a parent
488 window, the sum of the total widths of all its children internally
489 equals the total width of their parent. This means that although two
490 windows have the same pixel width, their internal total widths may
491 differ by one column. This means also, that if this window is
492 horizontally combined and has a next sibling, the leftmost column of
493 that sibling can be calculated as the sum of this window's leftmost
494 column and total width (@pxref{Coordinates and Windows}). The optional
495 argument @var{round} behaves as it does for @code{window-total-height}.
496 @end defun
497
498 @defun window-total-size &optional window horizontal round
499 This function returns either the total height in lines or the total
500 width in columns of the window @var{window}. If @var{horizontal} is
501 omitted or @code{nil}, this is equivalent to calling
502 @code{window-total-height} for @var{window}; otherwise it is equivalent
503 to calling @code{window-total-width} for @var{window}. The optional
504 argument @var{round} behaves as it does for @code{window-total-height}.
505 @end defun
506
507 The following two functions can be used to return the total size of a
508 window in units of pixels.
509
510 @cindex window pixel height
511 @cindex pixel height of a window
512 @cindex total pixel height of a window
513
514 @defun window-pixel-height &optional window
515 This function returns the total height of window @var{window} in pixels.
516 @var{window} must be a valid window and defaults to the selected one.
517
518 The return value includes mode and header line, a horizontal scroll bar
519 and a bottom divider, if any. If @var{window} is an internal window,
520 its pixel height is the pixel height of the screen areas spanned by its
521 children.
522 @end defun
523
524 @cindex window pixel height
525 @cindex pixel height of a window
526 @cindex total pixel height of a window
527
528 @defun window-pixel-width &optional Lisp_Object &optional window
529 This function returns the width of window @var{window} in pixels.
530 @var{window} must be a valid window and defaults to the selected one.
531
532 The return value includes the fringes and margins of @var{window} as
533 well as any vertical dividers or scroll bars belonging to @var{window}.
534 If @var{window} is an internal window, its pixel width is the width of
535 the screen areas spanned by its children.
536 @end defun
537
538 @cindex full-width window
539 @cindex full-height window
540 The following functions can be used to determine whether a given
541 window has any adjacent windows.
542
543 @defun window-full-height-p &optional window
544 This function returns non-@code{nil} if @var{window} has no other window
545 above or below it in its frame. More precisely, this means that the
546 total height of @var{window} equals the total height of the root window
547 on that frame. The minibuffer window does not count in this regard. If
548 @var{window} is omitted or @code{nil}, it defaults to the selected
549 window.
550 @end defun
551
552 @defun window-full-width-p &optional window
553 This function returns non-@code{nil} if @var{window} has no other
554 window to the left or right in its frame, i.e., its total width equals
555 that of the root window on that frame. If @var{window} is omitted or
556 @code{nil}, it defaults to the selected window.
557 @end defun
558
559 @cindex window body height
560 @cindex body height of a window
561 @cindex window body width
562 The @dfn{body height} of a window is the height of its text area, which
563 does not include a mode or header line, a horizontal scroll bar, or a
564 bottom divider.
565
566 @defun window-body-height &optional window pixelwise
567 This function returns the height, in lines, of the body of window
568 @var{window}. If @var{window} is omitted or @code{nil}, it defaults to
569 the selected window; otherwise it must be a live window.
570
571 If the optional argument @var{pixelwise} is non-@code{nil}, this
572 function returns the body height of @var{window} counted in pixels.
573
574 If @var{pixelwise} is @code{nil}, the return value is rounded down to
575 the nearest integer, if necessary. This means that if a line at the
576 bottom of the text area is only partially visible, that line is not
577 counted. It also means that the height of a window's body can never
578 exceed its total height as returned by @code{window-total-height}.
579 @end defun
580
581 @cindex body width of a window
582 @cindex body size of a window
583 @cindex window body size
584 The @dfn{body width} of a window is the width of its text area, which
585 does not include the scroll bar, fringes, margins or a right divider.
586
587 @defun window-body-width &optional window pixelwise
588 This function returns the width, in columns, of the body of window
589 @var{window}. If @var{window} is omitted or @code{nil}, it defaults to
590 the selected window; otherwise it must be a live window.
591
592 If the optional argument @var{pixelwise} is non-@code{nil}, this
593 function returns the body width of @var{window} in units of pixels.
594
595 If @var{pixelwise} is @code{nil}, the return value is rounded down to
596 the nearest integer, if necessary. This means that if a column on the
597 right of the text area is only partially visible, that column is not
598 counted. It also means that the width of a window's body can never
599 exceed its total width as returned by @code{window-total-width}.
600 @end defun
601
602 @defun window-body-size &optional window horizontal pixelwise
603 This function returns the body height or body width of @var{window}. If
604 @var{horizontal} is omitted or @code{nil}, it is equivalent to calling
605 @code{window-body-height} for @var{window}; otherwise it is equivalent
606 to calling @code{window-body-width}. In either case, the optional
607 argument @var{pixelwise} is passed to the function called.
608 @end defun
609
610 For compatibility with previous versions of Emacs,
611 @code{window-height} is an alias for @code{window-total-height}, and
612 @code{window-width} is an alias for @code{window-body-width}. These
613 aliases are considered obsolete and will be removed in the future.
614
615 The pixel heights of a window's mode and header line can be retrieved
616 with the functions given below. Their return value is usually accurate
617 unless the window has not been displayed before: In that case, the
618 return value is based on an estimate of the font used for the window's
619 frame.
620
621 @defun window-mode-line-height &optional window
622 This function returns the height in pixels of @var{window}'s mode line.
623 @var{window} must be a live window and defaults to the selected one. If
624 @var{window} has no mode line, the return value is zero.
625 @end defun
626
627 @defun window-header-line-height &optional window
628 This function returns the height in pixels of @var{window}'s header
629 line. @var{window} must be a live window and defaults to the selected
630 one. If @var{window} has no header line, the return value is zero.
631 @end defun
632
633 Functions for retrieving the height and/or width of window dividers
634 (@pxref{Window Dividers}), fringes (@pxref{Fringes}), scroll bars
635 (@pxref{Scroll Bars}), and display margins (@pxref{Display Margins}) are
636 described in the corresponding sections.
637
638 @cindex fixed-size window
639 @vindex window-min-height
640 @vindex window-min-width
641 Commands that change the size of windows (@pxref{Resizing Windows}),
642 or split them (@pxref{Splitting Windows}), obey the variables
643 @code{window-min-height} and @code{window-min-width}, which specify the
644 smallest allowable window height and width. They also obey the variable
645 @code{window-size-fixed}, with which a window can be @dfn{fixed} in
646 size:
647
648 @defopt window-min-height
649 This option specifies the minimum total height, in lines, of any window.
650 Its value has to accommodate at least one text line as well as a mode
651 and header line, a horizontal scroll bar and a bottom divider, if
652 present.
653 @end defopt
654
655 @defopt window-min-width
656 This option specifies the minimum total width, in columns, of any
657 window. Its value has to accommodate two text columns as well as
658 margins, fringes, a scroll bar and a right divider, if present.
659 @end defopt
660
661 The following function tells how small a specific window can get taking
662 into account the sizes of its areas and the values of
663 @code{window-min-height}, @code{window-min-width} and
664 @code{window-size-fixed}.
665
666 @defun window-min-size &optional window horizontal ignore pixelwise
667 This function returns the minimum size of @var{window}. @var{window}
668 must be a valid window and defaults to the selected one. The optional
669 argument @var{horizontal} non-@code{nil} means to return the minimum
670 number of columns of @var{window}; otherwise return the minimum number
671 of @var{window}'s lines.
672
673 The return value makes sure that all components of @var{window} remain
674 fully visible if @var{window}'s size were actually set to it. With
675 @var{horizontal} @code{nil} it includes the mode and header line, the
676 horizontal scroll bar and the bottom divider. With @var{horizontal}
677 non-@code{nil} it includes the fringes, a scroll bar, and a right
678 divider, if present. It does not, however, include the space reserved
679 for the margins.
680
681 The optional argument @var{ignore}, if non-@code{nil}, means ignore
682 restrictions imposed by fixed size windows, @code{window-min-height} or
683 @code{window-min-width} settings. If @var{ignore} equals @code{safe},
684 live windows may get as small as @code{window-safe-min-height} lines and
685 @code{window-safe-min-width} columns. If @var{ignore} is a window,
686 ignore restrictions for that window only. Any other non-@code{nil}
687 value means ignore all of the above restrictions for all windows.
688
689 The optional argument @var{pixelwise} non-@code{nil} means to return the
690 minimum size of @var{window} counted in pixels.
691 @end defun
692
693 @node Resizing Windows
694 @section Resizing Windows
695 @cindex window resizing
696 @cindex resize window
697 @cindex changing window size
698 @cindex window size, changing
699
700 This section describes functions for resizing a window without
701 changing the size of its frame. Because live windows do not overlap,
702 these functions are meaningful only on frames that contain two or more
703 windows: resizing a window also changes the size of a neighboring
704 window. If there is just one window on a frame, its size cannot be
705 changed except by resizing the frame (@pxref{Size and Position}).
706
707 Except where noted, these functions also accept internal windows as
708 arguments. Resizing an internal window causes its child windows to be
709 resized to fit the same space.
710
711 @defun window-resizable window delta &optional horizontal ignore pixelwise
712 This function returns @var{delta} if the size of @var{window} can be
713 changed vertically by @var{delta} lines. If the optional argument
714 @var{horizontal} is non-@code{nil}, it instead returns @var{delta} if
715 @var{window} can be resized horizontally by @var{delta} columns. It
716 does not actually change the window size.
717
718 If @var{window} is @code{nil}, it defaults to the selected window.
719
720 A positive value of @var{delta} means to check whether the window can be
721 enlarged by that number of lines or columns; a negative value of
722 @var{delta} means to check whether the window can be shrunk by that many
723 lines or columns. If @var{delta} is non-zero, a return value of 0 means
724 that the window cannot be resized.
725
726 Normally, the variables @code{window-min-height} and
727 @code{window-min-width} specify the smallest allowable window size
728 (@pxref{Window Sizes}). However, if the optional argument @var{ignore}
729 is non-@code{nil}, this function ignores @code{window-min-height} and
730 @code{window-min-width}, as well as @code{window-size-fixed}. Instead,
731 it considers the minimum-height window to be one consisting of a header
732 and a mode line, a horizontal scrollbar and a bottom divider (if any),
733 plus a text area one line tall; and a minimum-width window as one
734 consisting of fringes, margins, a scroll bar and a right divider (if
735 any), plus a text area two columns wide.
736
737 If the optional argument @var{pixelwise} is non-@code{nil},
738 @var{delta} is interpreted as pixels.
739 @end defun
740
741 @defun window-resize window delta &optional horizontal ignore pixelwise
742 This function resizes @var{window} by @var{delta} increments. If
743 @var{horizontal} is @code{nil}, it changes the height by @var{delta}
744 lines; otherwise, it changes the width by @var{delta} columns. A
745 positive @var{delta} means to enlarge the window, and a negative
746 @var{delta} means to shrink it.
747
748 If @var{window} is @code{nil}, it defaults to the selected window. If
749 the window cannot be resized as demanded, an error is signaled.
750
751 The optional argument @var{ignore} has the same meaning as for the
752 function @code{window-resizable} above.
753
754 If the optional argument @var{pixelwise} is non-@code{nil},
755 @var{delta} will be interpreted as pixels.
756
757 The choice of which window edges this function alters depends on the
758 values of the option @code{window-combination-resize} and the
759 combination limits of the involved windows; in some cases, it may alter
760 both edges. @xref{Recombining Windows}. To resize by moving only the
761 bottom or right edge of a window, use the function
762 @code{adjust-window-trailing-edge}.
763 @end defun
764
765 @c The commands enlarge-window, enlarge-window-horizontally,
766 @c shrink-window, and shrink-window-horizontally are documented in the
767 @c Emacs manual. They are not preferred for calling from Lisp.
768
769 @defun adjust-window-trailing-edge window delta &optional horizontal pixelwise
770 This function moves @var{window}'s bottom edge by @var{delta} lines.
771 If optional argument @var{horizontal} is non-@code{nil}, it instead
772 moves the right edge by @var{delta} columns. If @var{window} is
773 @code{nil}, it defaults to the selected window.
774
775 If the optional argument @var{pixelwise} is non-@code{nil},
776 @var{delta} is interpreted as pixels.
777
778 A positive @var{delta} moves the edge downwards or to the right; a
779 negative @var{delta} moves it upwards or to the left. If the edge
780 cannot be moved as far as specified by @var{delta}, this function
781 moves it as far as possible but does not signal a error.
782
783 This function tries to resize windows adjacent to the edge that is
784 moved. If this is not possible for some reason (e.g., if that adjacent
785 window is fixed-size), it may resize other windows.
786 @end defun
787
788 @cindex pixelwise, resizing windows
789 @defopt window-resize-pixelwise
790 If the value of this option is non-@code{nil}, Emacs resizes windows in
791 units of pixels. This currently affects functions like
792 @code{split-window} (@pxref{Splitting Windows}), @code{maximize-window},
793 @code{minimize-window}, @code{fit-window-to-buffer},
794 @code{fit-frame-to-buffer} and
795 @code{shrink-window-if-larger-than-buffer} (all listed below).
796
797 Note that when a frame's pixel size is not a multiple of its character
798 size, at least one window may get resized pixelwise even if this
799 option is @code{nil}. The default value is @code{nil}.
800 @end defopt
801
802 The following commands resize windows in more specific ways. When
803 called interactively, they act on the selected window.
804
805 @deffn Command fit-window-to-buffer &optional window max-height min-height max-width min-width preserve-size
806 This command adjusts the height or width of @var{window} to fit the text
807 in it. It returns non-@code{nil} if it was able to resize @var{window},
808 and @code{nil} otherwise. If @var{window} is omitted or @code{nil}, it
809 defaults to the selected window. Otherwise, it should be a live window.
810
811 If @var{window} is part of a vertical combination, this function adjusts
812 @var{window}'s height. The new height is calculated from the actual
813 height of the accessible portion of its buffer. The optional argument
814 @var{max-height}, if non-@code{nil}, specifies the maximum total height
815 that this function can give @var{window}. The optional argument
816 @var{min-height}, if non-@code{nil}, specifies the minimum total height
817 that it can give, which overrides the variable @code{window-min-height}.
818 Both @var{max-height} and @var{min-height} are specified in lines and
819 include mode and header line and a bottom divider, if any.
820
821 If @var{window} is part of a horizontal combination and the value of the
822 option @code{fit-window-to-buffer-horizontally} (see below) is
823 non-@code{nil}, this function adjusts @var{window}'s height. The new
824 width of @var{window} is calculated from the maximum length of its
825 buffer's lines that follow the current start position of @var{window}.
826 The optional argument @var{max-width} specifies a maximum width and
827 defaults to the width of @var{window}'s frame. The optional argument
828 @var{min-width} specifies a minimum width and defaults to
829 @code{window-min-width}. Both @var{max-width} and @var{min-width} are
830 specified in columns and include fringes, margins and scrollbars, if
831 any.
832
833 The optional argument @var{preserve-size}, if non-@code{nil}, will
834 install a parameter to preserve the size of @var{window} during future
835 resize operations (@pxref{Preserving Window Sizes}).
836
837 If the option @code{fit-frame-to-buffer} (see below) is non-@code{nil},
838 this function will try to resize the frame of @var{window} to fit its
839 contents by calling @code{fit-frame-to-buffer} (see below).
840 @end deffn
841
842 @defopt fit-window-to-buffer-horizontally
843 If this is non-@code{nil}, @code{fit-window-to-buffer} can resize
844 windows horizontally. If this is @code{nil} (the default)
845 @code{fit-window-to-buffer} never resizes windows horizontally. If this
846 is @code{only}, it can resize windows horizontally only. Any other
847 value means @code{fit-window-to-buffer} can resize windows in both
848 dimensions.
849 @end defopt
850
851 @defopt fit-frame-to-buffer
852 If this option is non-@code{nil}, @code{fit-window-to-buffer} can fit a
853 frame to its buffer. A frame is fit if and only if its root window is a
854 live window and this option is non-@code{nil}. If this is
855 @code{horizontally}, frames are fit horizontally only. If this is
856 @code{vertically}, frames are fit vertically only. Any other
857 non-@code{nil} value means frames can be resized in both dimensions.
858 @end defopt
859
860 If you have a frame that displays only one window, you can fit that
861 frame to its buffer using the command @code{fit-frame-to-buffer}.
862
863 @deffn Command fit-frame-to-buffer &optional frame max-height min-height max-width min-width only
864 This command adjusts the size of @var{frame} to display the contents of
865 its buffer exactly. @var{frame} can be any live frame and defaults to
866 the selected one. Fitting is done only if @var{frame}'s root window is
867 live. The arguments @var{max-height}, @var{min-height}, @var{max-width}
868 and @var{min-width} specify bounds on the new total size of
869 @var{frame}'s root window. @var{min-height} and @var{min-width} default
870 to the values of @code{window-min-height} and @code{window-min-width}
871 respectively.
872
873 If the optional argument @var{only} is @code{vertically}, this function
874 may resize the frame vertically only. If @var{only} is
875 @code{horizontally}, it may resize the frame horizontally only.
876 @end deffn
877
878 The behavior of @code{fit-frame-to-buffer} can be controlled with the
879 help of the two options listed next.
880
881 @defopt fit-frame-to-buffer-margins
882 This option can be used to specify margins around frames to be fit by
883 @code{fit-frame-to-buffer}. Such margins can be useful to avoid, for
884 example, that such frames overlap the taskbar.
885
886 It specifies the numbers of pixels to be left free on the left, above,
887 the right, and below a frame that shall be fit. The default specifies
888 @code{nil} for each which means to use no margins. The value specified
889 here can be overridden for a specific frame by that frame's
890 @code{fit-frame-to-buffer-margins} parameter, if present.
891 @end defopt
892
893 @defopt fit-frame-to-buffer-sizes
894 This option specifies size boundaries for @code{fit-frame-to-buffer}.
895 It specifies the total maximum and minimum lines and maximum and minimum
896 columns of the root window of any frame that shall be fit to its buffer.
897 If any of these values is non-@code{nil}, it overrides the corresponding
898 argument of @code{fit-frame-to-buffer}.
899 @end defopt
900
901 @deffn Command shrink-window-if-larger-than-buffer &optional window
902 This command attempts to reduce @var{window}'s height as much as
903 possible while still showing its full buffer, but no less than
904 @code{window-min-height} lines. The return value is non-@code{nil} if
905 the window was resized, and @code{nil} otherwise. If @var{window} is
906 omitted or @code{nil}, it defaults to the selected window. Otherwise,
907 it should be a live window.
908
909 This command does nothing if the window is already too short to
910 display all of its buffer, or if any of the buffer is scrolled
911 off-screen, or if the window is the only live window in its frame.
912
913 This command calls @code{fit-window-to-buffer} (see above) to do its
914 work.
915 @end deffn
916
917
918 @cindex balancing window sizes
919 @deffn Command balance-windows &optional window-or-frame
920 This function balances windows in a way that gives more space to
921 full-width and/or full-height windows. If @var{window-or-frame}
922 specifies a frame, it balances all windows on that frame. If
923 @var{window-or-frame} specifies a window, it balances only that window
924 and its siblings (@pxref{Windows and Frames}).
925 @end deffn
926
927 @deffn Command balance-windows-area
928 This function attempts to give all windows on the selected frame
929 approximately the same share of the screen area. Full-width or
930 full-height windows are not given more space than other windows.
931 @end deffn
932
933 @cindex maximizing windows
934 @deffn Command maximize-window &optional window
935 This function attempts to make @var{window} as large as possible, in
936 both dimensions, without resizing its frame or deleting other windows.
937 If @var{window} is omitted or @code{nil}, it defaults to the selected
938 window.
939 @end deffn
940
941 @cindex minimizing windows
942 @deffn Command minimize-window &optional window
943 This function attempts to make @var{window} as small as possible, in
944 both dimensions, without deleting it or resizing its frame. If
945 @var{window} is omitted or @code{nil}, it defaults to the selected
946 window.
947 @end deffn
948
949
950 @node Preserving Window Sizes
951 @section Preserving Window Sizes
952 @cindex preserving window sizes
953
954 A window can get resized explicitly by using one of the functions from
955 the preceding section or implicitly, for example, when resizing an
956 adjacent window, when splitting or deleting a window (@pxref{Splitting
957 Windows}, @pxref{Deleting Windows}) or when resizing the window's frame
958 (@pxref{Size and Position}).
959
960 It is possible to avoid implicit resizing of a specific window when
961 there are one or more other resizable windows on the same frame. For
962 this purpose, Emacs must be advised to @dfn{preserve} the size of that
963 window. There are two basic ways to do that.
964
965 @defvar window-size-fixed
966 If this buffer-local variable is non-@code{nil}, the size of any window
967 displaying the buffer cannot normally be changed. Deleting a window or
968 changing the frame's size may still change the window's size, if there
969 is no choice.
970
971 If the value is @code{height}, then only the window's height is fixed;
972 if the value is @code{width}, then only the window's width is fixed.
973 Any other non-@code{nil} value fixes both the width and the height.
974
975 If this variable is @code{nil}, this does not necessarily mean that any
976 window showing the buffer can be resized in the desired direction. To
977 determine that, use the function @code{window-resizable}.
978 @xref{Resizing Windows}.
979 @end defvar
980
981 Often @code{window-size-fixed} is overly aggressive because it inhibits
982 any attempt to explicitly resize or split an affected window as well.
983 This may even happen after the window has been resized implicitly, for
984 example, when deleting an adjacent window or resizing the window's
985 frame. The following function tries hard to never disallow resizing
986 such a window explicitly:
987
988 @defun window-preserve-size &optional window horizontal preserve
989 This function (un-)marks the height of window @var{window} as preserved
990 for future resize operations. @var{window} must be a live window and
991 defaults to the selected one. If the optional argument @var{horizontal}
992 is non-@code{nil}, it (un-)marks the width of @var{window} as preserved.
993
994 If the optional argument @var{preserve} is @code{t}, this means to
995 preserve the current height/width of @var{window}'s body. The
996 height/width of @var{window} will change only if Emacs has no better
997 choice. Resizing a window whose height/width is preserved by this
998 function never throws an error.
999
1000 If @var{preserve} is @code{nil}, this means to stop preserving the
1001 height/width of @var{window}, lifting any respective restraint induced
1002 by a previous call of this function for @var{window}. Calling
1003 @code{enlarge-window}, @code{shrink-window} or
1004 @code{fit-window-to-buffer} with @var{window} as argument may also
1005 remove the respective restraint.
1006 @end defun
1007
1008 @code{window-preserve-size} is currently invoked by the following
1009 functions:
1010
1011 @table @code
1012 @item fit-window-to-buffer
1013 If the optional argument @var{preserve-size} of that function
1014 (@pxref{Resizing Windows}) is non-@code{nil}, the size established by
1015 that function is preserved.
1016
1017 @item display-buffer
1018 If the @var{alist} argument of that function (@pxref{Choosing Window})
1019 contains a @code{preserve-size} entry, the size of the window produced
1020 by that function is preserved.
1021 @end table
1022
1023 @code{window-preserve-size} installs a window parameter (@pxref{Window
1024 Parameters}) called @code{preserved-size} which is consulted by the
1025 window resizing functions. This parameter will not prevent resizing the
1026 window when the window shows another buffer than the one when
1027 @code{window-preserve-size} was invoked or if its size has changed since
1028 then.
1029
1030 The following function can be used to check whether the height of a
1031 particular window is preserved:
1032
1033 @defun window-preserved-size &optional window horizontal
1034 This function returns the preserved height of window @var{window} in
1035 pixels. @var{window} must be a live window and defaults to the selected
1036 one. If the optional argument @var{horizontal} is non-@code{nil}, it
1037 returns the preserved width of @var{window}. It returns @code{nil} if
1038 the size of @var{window} is not preserved.
1039 @end defun
1040
1041
1042 @node Splitting Windows
1043 @section Splitting Windows
1044 @cindex splitting windows
1045 @cindex window splitting
1046
1047 This section describes functions for creating a new window by
1048 @dfn{splitting} an existing one.
1049
1050 @defun split-window &optional window size side pixelwise
1051 This function creates a new live window next to the window
1052 @var{window}. If @var{window} is omitted or @code{nil}, it defaults
1053 to the selected window. That window is split, and reduced in
1054 size. The space is taken up by the new window, which is returned.
1055
1056 The optional second argument @var{size} determines the sizes of
1057 @var{window} and/or the new window. If it is omitted or @code{nil},
1058 both windows are given equal sizes; if there is an odd line, it is
1059 allocated to the new window. If @var{size} is a positive number,
1060 @var{window} is given @var{size} lines (or columns, depending on the
1061 value of @var{side}). If @var{size} is a negative number, the new
1062 window is given @minus{}@var{size} lines (or columns).
1063
1064 If @var{size} is @code{nil}, this function obeys the variables
1065 @code{window-min-height} and @code{window-min-width} (@pxref{Window
1066 Sizes}). Thus, it signals an error if splitting would result in making
1067 a window smaller than those variables specify. However, a
1068 non-@code{nil} value for @var{size} causes those variables to be
1069 ignored; in that case, the smallest allowable window is considered to be
1070 one that has space for a text area one line tall and/or two columns
1071 wide.
1072
1073 Hence, if @var{size} is specified, it's the caller's responsibility to
1074 check whether the emanating windows are large enough to encompass all
1075 areas like a mode line or a scroll bar. The function
1076 @code{window-min-size} (@pxref{Window Sizes}) can be used to determine
1077 the minimum requirements of @var{window} in this regard. Since the new
1078 window usually inherits areas like the mode line or the scroll bar
1079 from @var{window}, that function is also a good guess for the minimum
1080 size of the new window. The caller should specify a smaller size only
1081 if it correspondingly removes an inherited area before the next
1082 redisplay.
1083
1084 The optional third argument @var{side} determines the position of the
1085 new window relative to @var{window}. If it is @code{nil} or
1086 @code{below}, the new window is placed below @var{window}. If it is
1087 @code{above}, the new window is placed above @var{window}. In both
1088 these cases, @var{size} specifies a total window height, in lines.
1089
1090 If @var{side} is @code{t} or @code{right}, the new window is placed on
1091 the right of @var{window}. If @var{side} is @code{left}, the new
1092 window is placed on the left of @var{window}. In both these cases,
1093 @var{size} specifies a total window width, in columns.
1094
1095 The optional fourth argument @var{pixelwise}, if non-@code{nil}, means
1096 to interpret @var{size} in units of pixels, instead of lines and
1097 columns.
1098
1099 If @var{window} is a live window, the new window inherits various
1100 properties from it, including margins and scroll bars. If
1101 @var{window} is an internal window, the new window inherits the
1102 properties of the window selected within @var{window}'s frame.
1103
1104 The behavior of this function may be altered by the window parameters
1105 of @var{window}, so long as the variable
1106 @code{ignore-window-parameters} is @code{nil}. If the value of
1107 the @code{split-window} window parameter is @code{t}, this function
1108 ignores all other window parameters. Otherwise, if the value of the
1109 @code{split-window} window parameter is a function, that function is
1110 called with the arguments @var{window}, @var{size}, and @var{side}, in
1111 lieu of the usual action of @code{split-window}. Otherwise, this
1112 function obeys the @code{window-atom} or @code{window-side} window
1113 parameter, if any. @xref{Window Parameters}.
1114 @end defun
1115
1116 As an example, here is a sequence of @code{split-window} calls that
1117 yields the window configuration discussed in @ref{Windows and Frames}.
1118 This example demonstrates splitting a live window as well as splitting
1119 an internal window. We begin with a frame containing a single window
1120 (a live root window), which we denote by @var{W4}. Calling
1121 @code{(split-window W4)} yields this window configuration:
1122
1123 @smallexample
1124 @group
1125 ______________________________________
1126 | ____________________________________ |
1127 || ||
1128 || ||
1129 || ||
1130 ||_________________W4_________________||
1131 | ____________________________________ |
1132 || ||
1133 || ||
1134 || ||
1135 ||_________________W5_________________||
1136 |__________________W3__________________|
1137
1138 @end group
1139 @end smallexample
1140
1141 @noindent
1142 The @code{split-window} call has created a new live window, denoted by
1143 @var{W5}. It has also created a new internal window, denoted by
1144 @var{W3}, which becomes the root window and the parent of both
1145 @var{W4} and @var{W5}.
1146
1147 Next, we call @code{(split-window W3 nil 'left)}, passing the
1148 internal window @var{W3} as the argument. The result:
1149
1150 @smallexample
1151 @group
1152 ______________________________________
1153 | ______ ____________________________ |
1154 || || __________________________ ||
1155 || ||| |||
1156 || ||| |||
1157 || ||| |||
1158 || |||____________W4____________|||
1159 || || __________________________ ||
1160 || ||| |||
1161 || ||| |||
1162 || |||____________W5____________|||
1163 ||__W2__||_____________W3_____________ |
1164 |__________________W1__________________|
1165 @end group
1166 @end smallexample
1167
1168 @noindent
1169 A new live window @var{W2} is created, to the left of the internal
1170 window @var{W3}. A new internal window @var{W1} is created, becoming
1171 the new root window.
1172
1173 For interactive use, Emacs provides two commands which always split
1174 the selected window. These call @code{split-window} internally.
1175
1176 @deffn Command split-window-right &optional size
1177 This function splits the selected window into two side-by-side
1178 windows, putting the selected window on the left. If @var{size} is
1179 positive, the left window gets @var{size} columns; if @var{size} is
1180 negative, the right window gets @minus{}@var{size} columns.
1181 @end deffn
1182
1183 @deffn Command split-window-below &optional size
1184 This function splits the selected window into two windows, one above
1185 the other, leaving the upper window selected. If @var{size} is
1186 positive, the upper window gets @var{size} lines; if @var{size} is
1187 negative, the lower window gets @minus{}@var{size} lines.
1188 @end deffn
1189
1190 @defopt split-window-keep-point
1191 If the value of this variable is non-@code{nil} (the default),
1192 @code{split-window-below} behaves as described above.
1193
1194 If it is @code{nil}, @code{split-window-below} adjusts point in each
1195 of the two windows to minimize redisplay. (This is useful on slow
1196 terminals.) It selects whichever window contains the screen line that
1197 point was previously on. Note that this only affects
1198 @code{split-window-below}, not the lower-level @code{split-window}
1199 function.
1200 @end defopt
1201
1202
1203 @node Deleting Windows
1204 @section Deleting Windows
1205 @cindex deleting windows
1206
1207 @dfn{Deleting} a window removes it from the frame's window tree. If
1208 the window is a live window, it disappears from the screen. If the
1209 window is an internal window, its child windows are deleted too.
1210
1211 Even after a window is deleted, it continues to exist as a Lisp
1212 object, until there are no more references to it. Window deletion can
1213 be reversed, by restoring a saved window configuration (@pxref{Window
1214 Configurations}).
1215
1216 @deffn Command delete-window &optional window
1217 This function removes @var{window} from display and returns
1218 @code{nil}. If @var{window} is omitted or @code{nil}, it defaults to
1219 the selected window. If deleting the window would leave no more
1220 windows in the window tree (e.g., if it is the only live window in the
1221 frame), an error is signaled.
1222
1223 By default, the space taken up by @var{window} is given to one of its
1224 adjacent sibling windows, if any. However, if the variable
1225 @code{window-combination-resize} is non-@code{nil}, the space is
1226 proportionally distributed among any remaining windows in the window
1227 combination. @xref{Recombining Windows}.
1228
1229 The behavior of this function may be altered by the window parameters
1230 of @var{window}, so long as the variable
1231 @code{ignore-window-parameters} is @code{nil}. If the value of
1232 the @code{delete-window} window parameter is @code{t}, this function
1233 ignores all other window parameters. Otherwise, if the value of the
1234 @code{delete-window} window parameter is a function, that function is
1235 called with the argument @var{window}, in lieu of the usual action of
1236 @code{delete-window}. Otherwise, this function obeys the
1237 @code{window-atom} or @code{window-side} window parameter, if any.
1238 @xref{Window Parameters}.
1239 @end deffn
1240
1241 @deffn Command delete-other-windows &optional window
1242 This function makes @var{window} fill its frame, by deleting other
1243 windows as necessary. If @var{window} is omitted or @code{nil}, it
1244 defaults to the selected window. The return value is @code{nil}.
1245
1246 The behavior of this function may be altered by the window parameters
1247 of @var{window}, so long as the variable
1248 @code{ignore-window-parameters} is @code{nil}. If the value of
1249 the @code{delete-other-windows} window parameter is @code{t}, this
1250 function ignores all other window parameters. Otherwise, if the value
1251 of the @code{delete-other-windows} window parameter is a function,
1252 that function is called with the argument @var{window}, in lieu of the
1253 usual action of @code{delete-other-windows}. Otherwise, this function
1254 obeys the @code{window-atom} or @code{window-side} window parameter,
1255 if any. @xref{Window Parameters}.
1256 @end deffn
1257
1258 @deffn Command delete-windows-on &optional buffer-or-name frame
1259 This function deletes all windows showing @var{buffer-or-name}, by
1260 calling @code{delete-window} on those windows. @var{buffer-or-name}
1261 should be a buffer, or the name of a buffer; if omitted or @code{nil},
1262 it defaults to the current buffer. If there are no windows showing
1263 the specified buffer, this function does nothing. If the specified
1264 buffer is a minibuffer, an error is signaled.
1265
1266 If there is a dedicated window showing the buffer, and that window is
1267 the only one on its frame, this function also deletes that frame if it
1268 is not the only frame on the terminal.
1269
1270 The optional argument @var{frame} specifies which frames to operate
1271 on:
1272
1273 @itemize @bullet
1274 @item @code{nil}
1275 means operate on all frames.
1276 @item @code{t}
1277 means operate on the selected frame.
1278 @item @code{visible}
1279 means operate on all visible frames.
1280 @item @code{0}
1281 means operate on all visible or iconified frames.
1282 @item A frame
1283 means operate on that frame.
1284 @end itemize
1285
1286 Note that this argument does not have the same meaning as in other
1287 functions which scan all live windows (@pxref{Cyclic Window
1288 Ordering}). Specifically, the meanings of @code{t} and @code{nil} here
1289 are the opposite of what they are in those other functions.
1290 @end deffn
1291
1292
1293 @node Recombining Windows
1294 @section Recombining Windows
1295 @cindex recombining windows
1296 @cindex windows, recombining
1297
1298 When deleting the last sibling of a window @var{W}, its parent window
1299 is deleted too, with @var{W} replacing it in the window tree. This
1300 means that @var{W} must be recombined with its parent's siblings to
1301 form a new window combination (@pxref{Windows and Frames}). In some
1302 occasions, deleting a live window may even entail the deletion of two
1303 internal windows.
1304
1305 @smallexample
1306 @group
1307 ______________________________________
1308 | ______ ____________________________ |
1309 || || __________________________ ||
1310 || ||| ___________ ___________ |||
1311 || |||| || ||||
1312 || ||||____W6_____||_____W7____||||
1313 || |||____________W4____________|||
1314 || || __________________________ ||
1315 || ||| |||
1316 || ||| |||
1317 || |||____________W5____________|||
1318 ||__W2__||_____________W3_____________ |
1319 |__________________W1__________________|
1320
1321 @end group
1322 @end smallexample
1323
1324 @noindent
1325 Deleting @var{W5} in this configuration normally causes the deletion of
1326 @var{W3} and @var{W4}. The remaining live windows @var{W2},
1327 @var{W6} and @var{W7} are recombined to form a new horizontal
1328 combination with parent @var{W1}.
1329
1330 Sometimes, however, it makes sense to not delete a parent window like
1331 @var{W4}. In particular, a parent window should not be removed when it
1332 was used to preserve a combination embedded in a combination of the same
1333 type. Such embeddings make sense to assure that when you split a window
1334 and subsequently delete the new window, Emacs reestablishes the layout
1335 of the associated frame as it existed before the splitting.
1336
1337 Consider a scenario starting with two live windows @var{W2} and
1338 @var{W3} and their parent @var{W1}.
1339
1340 @smallexample
1341 @group
1342 ______________________________________
1343 | ____________________________________ |
1344 || ||
1345 || ||
1346 || ||
1347 || ||
1348 || ||
1349 || ||
1350 ||_________________W2_________________||
1351 | ____________________________________ |
1352 || ||
1353 || ||
1354 ||_________________W3_________________||
1355 |__________________W1__________________|
1356
1357 @end group
1358 @end smallexample
1359
1360 @noindent
1361 Split @var{W2} to make a new window @var{W4} as follows.
1362
1363 @smallexample
1364 @group
1365 ______________________________________
1366 | ____________________________________ |
1367 || ||
1368 || ||
1369 ||_________________W2_________________||
1370 | ____________________________________ |
1371 || ||
1372 || ||
1373 ||_________________W4_________________||
1374 | ____________________________________ |
1375 || ||
1376 || ||
1377 ||_________________W3_________________||
1378 |__________________W1__________________|
1379
1380 @end group
1381 @end smallexample
1382
1383 @noindent
1384 Now, when enlarging a window vertically, Emacs tries to obtain the
1385 corresponding space from its lower sibling, provided such a window
1386 exists. In our scenario, enlarging @var{W4} will steal space from
1387 @var{W3}.
1388
1389 @smallexample
1390 @group
1391 ______________________________________
1392 | ____________________________________ |
1393 || ||
1394 || ||
1395 ||_________________W2_________________||
1396 | ____________________________________ |
1397 || ||
1398 || ||
1399 || ||
1400 || ||
1401 ||_________________W4_________________||
1402 | ____________________________________ |
1403 ||_________________W3_________________||
1404 |__________________W1__________________|
1405
1406 @end group
1407 @end smallexample
1408
1409 @noindent
1410 Deleting @var{W4} will now give its entire space to @var{W2},
1411 including the space earlier stolen from @var{W3}.
1412
1413 @smallexample
1414 @group
1415 ______________________________________
1416 | ____________________________________ |
1417 || ||
1418 || ||
1419 || ||
1420 || ||
1421 || ||
1422 || ||
1423 || ||
1424 || ||
1425 ||_________________W2_________________||
1426 | ____________________________________ |
1427 ||_________________W3_________________||
1428 |__________________W1__________________|
1429
1430 @end group
1431 @end smallexample
1432
1433 @noindent
1434 This can be counterintuitive, in particular if @var{W4} were used for
1435 displaying a buffer only temporarily (@pxref{Temporary Displays}), and
1436 you want to continue working with the initial layout.
1437
1438 The behavior can be fixed by making a new parent window when splitting
1439 @var{W2}. The variable described next allows to do that.
1440
1441 @defopt window-combination-limit
1442 This variable controls whether splitting a window shall make a new
1443 parent window. The following values are recognized:
1444
1445 @table @code
1446 @item nil
1447 This means that the new live window is allowed to share the existing
1448 parent window, if one exists, provided the split occurs in the same
1449 direction as the existing window combination (otherwise, a new internal
1450 window is created anyway).
1451
1452 @item window-size
1453 In this case @code{display-buffer} makes a new parent window if it is
1454 passed a @code{window-height} or @code{window-width} entry in the
1455 @var{alist} argument (@pxref{Display Action Functions}).
1456
1457 @item temp-buffer
1458 This value causes the creation of a new parent window when a window is
1459 split for showing a temporary buffer (@pxref{Temporary Displays}) only.
1460
1461 @item display-buffer
1462 This means that when @code{display-buffer} (@pxref{Choosing Window})
1463 splits a window it always makes a new parent window.
1464
1465 @item t
1466 In this case a new parent window is always created when splitting a
1467 window. Thus, if the value of this variable is at all times @code{t},
1468 then at all times every window tree is a binary tree (a tree where each
1469 window except the root window has exactly one sibling).
1470 @end table
1471
1472 The default is @code{nil}. Other values are reserved for future use.
1473
1474 If, as a consequence of this variable's setting, @code{split-window}
1475 makes a new parent window, it also calls
1476 @code{set-window-combination-limit} (see below) on the newly-created
1477 internal window. This affects how the window tree is rearranged when
1478 the child windows are deleted (see below).
1479 @end defopt
1480
1481 If @code{window-combination-limit} is @code{t}, splitting @var{W2} in
1482 the initial configuration of our scenario would have produced this:
1483
1484 @smallexample
1485 @group
1486 ______________________________________
1487 | ____________________________________ |
1488 || __________________________________ ||
1489 ||| |||
1490 |||________________W2________________|||
1491 || __________________________________ ||
1492 ||| |||
1493 |||________________W4________________|||
1494 ||_________________W5_________________||
1495 | ____________________________________ |
1496 || ||
1497 || ||
1498 ||_________________W3_________________||
1499 |__________________W1__________________|
1500
1501 @end group
1502 @end smallexample
1503
1504 @noindent
1505 A new internal window @var{W5} has been created; its children are
1506 @var{W2} and the new live window @var{W4}. Now, @var{W2} is the only
1507 sibling of @var{W4}, so enlarging @var{W4} will try to shrink
1508 @var{W2}, leaving @var{W3} unaffected. Observe that @var{W5}
1509 represents a vertical combination of two windows embedded in the
1510 vertical combination @var{W1}.
1511
1512 @cindex window combination limit
1513 @defun set-window-combination-limit window limit
1514 This function sets the @dfn{combination limit} of the window
1515 @var{window} to @var{limit}. This value can be retrieved via the
1516 function @code{window-combination-limit}. See below for its effects;
1517 note that it is only meaningful for internal windows. The
1518 @code{split-window} function automatically calls this function, passing
1519 it @code{t} as @var{limit}, provided the value of the variable
1520 @code{window-combination-limit} is @code{t} when it is called.
1521 @end defun
1522
1523 @defun window-combination-limit window
1524 This function returns the combination limit for @var{window}.
1525
1526 The combination limit is meaningful only for an internal window. If it
1527 is @code{nil}, then Emacs is allowed to automatically delete
1528 @var{window}, in response to a window deletion, in order to group the
1529 child windows of @var{window} with its sibling windows to form a new
1530 window combination. If the combination limit is @code{t}, the child
1531 windows of @var{window} are never automatically recombined with its
1532 siblings.
1533
1534 If, in the configuration shown at the beginning of this section, the
1535 combination limit of @var{W4} (the parent window of @var{W6} and
1536 @var{W7}) is @code{t}, deleting @var{W5} will not implicitly delete
1537 @var{W4} too.
1538 @end defun
1539
1540 Alternatively, the problems sketched above can be avoided by always
1541 resizing all windows in the same combination whenever one of its windows
1542 is split or deleted. This also permits to split windows that would be
1543 otherwise too small for such an operation.
1544
1545 @defopt window-combination-resize
1546 If this variable is @code{nil}, @code{split-window} can only split a
1547 window (denoted by @var{window}) if @var{window}'s screen area is large
1548 enough to accommodate both itself and the new window.
1549
1550 If this variable is @code{t}, @code{split-window} tries to resize all
1551 windows that are part of the same combination as @var{window}, in order
1552 to accommodate the new window. In particular, this may allow
1553 @code{split-window} to succeed even if @var{window} is a fixed-size
1554 window or too small to ordinarily split. Furthermore, subsequently
1555 resizing or deleting @var{window} may resize all other windows in its
1556 combination.
1557
1558 The default is @code{nil}. Other values are reserved for future use.
1559 The value of this variable is ignored when
1560 @code{window-combination-limit} is non-@code{nil}.
1561 @end defopt
1562
1563 To illustrate the effect of @code{window-combination-resize}, consider
1564 the following frame layout.
1565
1566 @smallexample
1567 @group
1568 ______________________________________
1569 | ____________________________________ |
1570 || ||
1571 || ||
1572 || ||
1573 || ||
1574 ||_________________W2_________________||
1575 | ____________________________________ |
1576 || ||
1577 || ||
1578 || ||
1579 || ||
1580 ||_________________W3_________________||
1581 |__________________W1__________________|
1582
1583 @end group
1584 @end smallexample
1585
1586 @noindent
1587 If @code{window-combination-resize} is @code{nil}, splitting window
1588 @var{W3} leaves the size of @var{W2} unchanged:
1589
1590 @smallexample
1591 @group
1592 ______________________________________
1593 | ____________________________________ |
1594 || ||
1595 || ||
1596 || ||
1597 || ||
1598 ||_________________W2_________________||
1599 | ____________________________________ |
1600 || ||
1601 ||_________________W3_________________||
1602 | ____________________________________ |
1603 || ||
1604 ||_________________W4_________________||
1605 |__________________W1__________________|
1606
1607 @end group
1608 @end smallexample
1609
1610 @noindent
1611 If @code{window-combination-resize} is @code{t}, splitting @var{W3}
1612 instead leaves all three live windows with approximately the same
1613 height:
1614
1615 @smallexample
1616 @group
1617 ______________________________________
1618 | ____________________________________ |
1619 || ||
1620 || ||
1621 ||_________________W2_________________||
1622 | ____________________________________ |
1623 || ||
1624 || ||
1625 ||_________________W3_________________||
1626 | ____________________________________ |
1627 || ||
1628 || ||
1629 ||_________________W4_________________||
1630 |__________________W1__________________|
1631
1632 @end group
1633 @end smallexample
1634
1635 @noindent
1636 Deleting any of the live windows @var{W2}, @var{W3} or @var{W4} will
1637 distribute its space proportionally among the two remaining live
1638 windows.
1639
1640
1641 @node Selecting Windows
1642 @section Selecting Windows
1643 @cindex selecting a window
1644
1645 @defun select-window window &optional norecord
1646 This function makes @var{window} the selected window and the window
1647 selected within its frame (@pxref{Basic Windows}) and selects that
1648 frame. It also makes @var{window}'s buffer (@pxref{Buffers and
1649 Windows}) current and sets that buffer's value of @code{point} to the
1650 value of @code{window-point} (@pxref{Window Point}) in @var{window}.
1651 @var{window} must be a live window. The return value is @var{window}.
1652
1653 By default, this function also moves @var{window}'s buffer to the front
1654 of the buffer list (@pxref{Buffer List}), and makes @var{window} the
1655 most recently selected window. However, if the optional argument
1656 @var{norecord} is non-@code{nil}, these additional actions are omitted.
1657
1658 This function runs @code{buffer-list-update-hook} (@pxref{Buffer List})
1659 unless @var{norecord} is non-@code{nil}. Note that applications and
1660 internal routines often temporarily select a window in order to simplify
1661 coding. As a rule, such selections (including those made by the macros
1662 @code{save-selected-window} and @code{with-selected-window} below) are
1663 not recorded thus avoiding to pollute @code{buffer-list-update-hook}.
1664 Selections that really count are those causing a visible change in
1665 the next redisplay of @var{window}'s frame and should be always
1666 recorded. This also means that to run a function each time a window
1667 gets selected, putting it on @code{buffer-list-update-hook} should be
1668 the right choice.
1669 @end defun
1670
1671 @cindex most recently selected windows
1672 The sequence of calls to @code{select-window} with a non-@code{nil}
1673 @var{norecord} argument determines an ordering of windows by their
1674 selection time. The function @code{get-lru-window} can be used to
1675 retrieve the least recently selected live window (@pxref{Cyclic Window
1676 Ordering}).
1677
1678 @defmac save-selected-window forms@dots{}
1679 This macro records the selected frame, as well as the selected window
1680 of each frame, executes @var{forms} in sequence, then restores the
1681 earlier selected frame and windows. It also saves and restores the
1682 current buffer. It returns the value of the last form in @var{forms}.
1683
1684 This macro does not save or restore anything about the sizes,
1685 arrangement or contents of windows; therefore, if @var{forms} change
1686 them, the change persists. If the previously selected window of some
1687 frame is no longer live at the time of exit from @var{forms}, that
1688 frame's selected window is left alone. If the previously selected
1689 window is no longer live, then whatever window is selected at the end of
1690 @var{forms} remains selected. The current buffer is restored if and
1691 only if it is still live when exiting @var{forms}.
1692
1693 This macro changes neither the ordering of recently selected windows nor
1694 the buffer list.
1695 @end defmac
1696
1697 @defmac with-selected-window window forms@dots{}
1698 This macro selects @var{window}, executes @var{forms} in sequence, then
1699 restores the previously selected window and current buffer. The ordering
1700 of recently selected windows and the buffer list remain unchanged unless
1701 you deliberately change them within @var{forms}; for example, by calling
1702 @code{select-window} with argument @var{norecord} @code{nil}.
1703
1704 This macro does not change the order of recently selected windows or
1705 the buffer list.
1706 @end defmac
1707
1708 @defun frame-selected-window &optional frame
1709 This function returns the window on @var{frame} that is selected
1710 within that frame. @var{frame} should be a live frame; if omitted or
1711 @code{nil}, it defaults to the selected frame.
1712 @end defun
1713
1714 @defun set-frame-selected-window frame window &optional norecord
1715 This function makes @var{window} the window selected within the frame
1716 @var{frame}. @var{frame} should be a live frame; if @code{nil}, it
1717 defaults to the selected frame. @var{window} should be a live window;
1718 if @code{nil}, it defaults to the selected window.
1719
1720 If @var{frame} is the selected frame, this makes @var{window} the
1721 selected window.
1722
1723 If the optional argument @var{norecord} is non-@code{nil}, this
1724 function does not alter the list of most recently selected windows,
1725 nor the buffer list.
1726 @end defun
1727
1728 @cindex window use time
1729 @cindex use time of window
1730 @cindex window order by time of last use
1731 @defun window-use-time &optional window
1732 This functions returns the use time of window @var{window}.
1733 @var{window} must be a live window and defaults to the selected one.
1734 The @dfn{use time} of a window is not really a time value, but it does
1735 increase monotonically with each window selection, so the window with
1736 the lowest use time is the least recently selected one, and the
1737 window with the highest use time is the most recently selected
1738 one.
1739 @end defun
1740
1741
1742 @node Cyclic Window Ordering
1743 @section Cyclic Ordering of Windows
1744 @cindex cyclic ordering of windows
1745 @cindex ordering of windows, cyclic
1746 @cindex window ordering, cyclic
1747
1748 When you use the command @kbd{C-x o} (@code{other-window}) to select
1749 some other window, it moves through live windows in a specific order.
1750 For any given configuration of windows, this order never varies. It
1751 is called the @dfn{cyclic ordering of windows}.
1752
1753 The ordering is determined by a depth-first traversal of the frame's
1754 window tree, retrieving the live windows which are the leaf nodes of
1755 the tree (@pxref{Windows and Frames}). If the minibuffer is active,
1756 the minibuffer window is included too. The ordering is cyclic, so the
1757 last window in the sequence is followed by the first one.
1758
1759 @defun next-window &optional window minibuf all-frames
1760 @cindex minibuffer window, and @code{next-window}
1761 This function returns a live window, the one following @var{window} in
1762 the cyclic ordering of windows. @var{window} should be a live window;
1763 if omitted or @code{nil}, it defaults to the selected window.
1764
1765 The optional argument @var{minibuf} specifies whether minibuffer windows
1766 should be included in the cyclic ordering. Normally, when @var{minibuf}
1767 is @code{nil}, a minibuffer window is included only if it is currently
1768 active; this matches the behavior of @kbd{C-x o}. (Note that a
1769 minibuffer window is active as long as its minibuffer is in use; see
1770 @ref{Minibuffers}).
1771
1772 If @var{minibuf} is @code{t}, the cyclic ordering includes all
1773 minibuffer windows. If @var{minibuf} is neither @code{t} nor
1774 @code{nil}, minibuffer windows are not included even if they are active.
1775
1776 The optional argument @var{all-frames} specifies which frames to
1777 consider:
1778
1779 @itemize @bullet
1780 @item @code{nil}
1781 means to consider windows on @var{window}'s frame. If the minibuffer
1782 window is considered (as specified by the @var{minibuf} argument),
1783 then frames that share the minibuffer window are considered too.
1784
1785 @item @code{t}
1786 means to consider windows on all existing frames.
1787
1788 @item @code{visible}
1789 means to consider windows on all visible frames.
1790
1791 @item 0
1792 means to consider windows on all visible or iconified frames.
1793
1794 @item A frame
1795 means to consider windows on that specific frame.
1796
1797 @item Anything else
1798 means to consider windows on @var{window}'s frame, and no others.
1799 @end itemize
1800
1801 If more than one frame is considered, the cyclic ordering is obtained
1802 by appending the orderings for those frames, in the same order as the
1803 list of all live frames (@pxref{Finding All Frames}).
1804 @end defun
1805
1806 @defun previous-window &optional window minibuf all-frames
1807 This function returns a live window, the one preceding @var{window} in
1808 the cyclic ordering of windows. The other arguments are handled like
1809 in @code{next-window}.
1810 @end defun
1811
1812 @deffn Command other-window count &optional all-frames
1813 This function selects a live window, one @var{count} places from the
1814 selected window in the cyclic ordering of windows. If @var{count} is
1815 a positive number, it skips @var{count} windows forwards; if
1816 @var{count} is negative, it skips @minus{}@var{count} windows
1817 backwards; if @var{count} is zero, that simply re-selects the selected
1818 window. When called interactively, @var{count} is the numeric prefix
1819 argument.
1820
1821 The optional argument @var{all-frames} has the same meaning as in
1822 @code{next-window}, like a @code{nil} @var{minibuf} argument to
1823 @code{next-window}.
1824
1825 This function does not select a window that has a non-@code{nil}
1826 @code{no-other-window} window parameter (@pxref{Window Parameters}).
1827 @end deffn
1828
1829 @defun walk-windows fun &optional minibuf all-frames
1830 This function calls the function @var{fun} once for each live window,
1831 with the window as the argument.
1832
1833 It follows the cyclic ordering of windows. The optional arguments
1834 @var{minibuf} and @var{all-frames} specify the set of windows
1835 included; these have the same arguments as in @code{next-window}. If
1836 @var{all-frames} specifies a frame, the first window walked is the
1837 first window on that frame (the one returned by
1838 @code{frame-first-window}), not necessarily the selected window.
1839
1840 If @var{fun} changes the window configuration by splitting or deleting
1841 windows, that does not alter the set of windows walked, which is
1842 determined prior to calling @var{fun} for the first time.
1843 @end defun
1844
1845 @defun one-window-p &optional no-mini all-frames
1846 This function returns @code{t} if the selected window is the only live
1847 window, and @code{nil} otherwise.
1848
1849 If the minibuffer window is active, it is normally considered (so that
1850 this function returns @code{nil}). However, if the optional argument
1851 @var{no-mini} is non-@code{nil}, the minibuffer window is ignored even
1852 if active. The optional argument @var{all-frames} has the same
1853 meaning as for @code{next-window}.
1854 @end defun
1855
1856 @cindex finding windows
1857 The following functions return a window which satisfies some
1858 criterion, without selecting it:
1859
1860 @cindex least recently used window
1861 @defun get-lru-window &optional all-frames dedicated not-selected
1862 This function returns a live window which is heuristically the least
1863 recently used. The optional argument @var{all-frames} has
1864 the same meaning as in @code{next-window}.
1865
1866 If any full-width windows are present, only those windows are
1867 considered. A minibuffer window is never a candidate. A dedicated
1868 window (@pxref{Dedicated Windows}) is never a candidate unless the
1869 optional argument @var{dedicated} is non-@code{nil}. The selected
1870 window is never returned, unless it is the only candidate. However, if
1871 the optional argument @var{not-selected} is non-@code{nil}, this
1872 function returns @code{nil} in that case.
1873 @end defun
1874
1875 @cindex most recently used window
1876 @defun get-mru-window &optional all-frames dedicated not-selected
1877 This function is like @code{get-lru-window}, but it returns the most
1878 recently used window instead. The meaning of the arguments is the
1879 same as described for @code{get-lru-window}.
1880 @end defun
1881
1882 @cindex largest window
1883 @defun get-largest-window &optional all-frames dedicated not-selected
1884 This function returns the window with the largest area (height times
1885 width). The optional argument @var{all-frames} specifies the windows to
1886 search, and has the same meaning as in @code{next-window}.
1887
1888 A minibuffer window is never a candidate. A dedicated window
1889 (@pxref{Dedicated Windows}) is never a candidate unless the optional
1890 argument @var{dedicated} is non-@code{nil}. The selected window is not
1891 a candidate if the optional argument @var{not-selected} is
1892 non-@code{nil}. If the optional argument @var{not-selected} is
1893 non-@code{nil} and the selected window is the only candidate, this
1894 function returns @code{nil}.
1895
1896 If there are two candidate windows of the same size, this function
1897 prefers the one that comes first in the cyclic ordering of windows,
1898 starting from the selected window.
1899 @end defun
1900
1901 @cindex window that satisfies a predicate
1902 @cindex conditional selection of windows
1903 @defun get-window-with-predicate predicate &optional minibuf all-frames default
1904 This function calls the function @var{predicate} for each of the
1905 windows in the cyclic order of windows in turn, passing it the window
1906 as an argument. If the predicate returns non-@code{nil} for any
1907 window, this function stops and returns that window. If no such
1908 window is found, the return value is @var{default} (which defaults to
1909 @code{nil}).
1910
1911 The optional arguments @var{minibuf} and @var{all-frames} specify the
1912 windows to search, and have the same meanings as in
1913 @code{next-window}.
1914 @end defun
1915
1916
1917 @node Buffers and Windows
1918 @section Buffers and Windows
1919 @cindex examining windows
1920 @cindex windows, controlling precisely
1921 @cindex buffers, controlled in windows
1922
1923 This section describes low-level functions for examining and setting
1924 the contents of windows. @xref{Switching Buffers}, for higher-level
1925 functions for displaying a specific buffer in a window.
1926
1927 @defun window-buffer &optional window
1928 This function returns the buffer that @var{window} is displaying. If
1929 @var{window} is omitted or @code{nil} it defaults to the selected
1930 window. If @var{window} is an internal window, this function returns
1931 @code{nil}.
1932 @end defun
1933
1934 @defun set-window-buffer window buffer-or-name &optional keep-margins
1935 This function makes @var{window} display @var{buffer-or-name}.
1936 @var{window} should be a live window; if @code{nil}, it defaults to
1937 the selected window. @var{buffer-or-name} should be a buffer, or the
1938 name of an existing buffer. This function does not change which
1939 window is selected, nor does it directly change which buffer is
1940 current (@pxref{Current Buffer}). Its return value is @code{nil}.
1941
1942 If @var{window} is @dfn{strongly dedicated} to a buffer and
1943 @var{buffer-or-name} does not specify that buffer, this function
1944 signals an error. @xref{Dedicated Windows}.
1945
1946 By default, this function resets @var{window}'s position, display
1947 margins, fringe widths, and scroll bar settings, based on the local
1948 variables in the specified buffer. However, if the optional argument
1949 @var{keep-margins} is non-@code{nil}, it leaves the display margins
1950 and fringe widths unchanged.
1951
1952 When writing an application, you should normally use the higher-level
1953 functions described in @ref{Switching Buffers}, instead of calling
1954 @code{set-window-buffer} directly.
1955
1956 This runs @code{window-scroll-functions}, followed by
1957 @code{window-configuration-change-hook}. @xref{Window Hooks}.
1958 @end defun
1959
1960 @defvar buffer-display-count
1961 This buffer-local variable records the number of times a buffer has been
1962 displayed in a window. It is incremented each time
1963 @code{set-window-buffer} is called for the buffer.
1964 @end defvar
1965
1966 @defvar buffer-display-time
1967 This buffer-local variable records the time at which a buffer was last
1968 displayed in a window. The value is @code{nil} if the buffer has
1969 never been displayed. It is updated each time
1970 @code{set-window-buffer} is called for the buffer, with the value
1971 returned by @code{current-time} (@pxref{Time of Day}).
1972 @end defvar
1973
1974 @defun get-buffer-window &optional buffer-or-name all-frames
1975 This function returns the first window displaying @var{buffer-or-name}
1976 in the cyclic ordering of windows, starting from the selected window
1977 (@pxref{Cyclic Window Ordering}). If no such window exists, the
1978 return value is @code{nil}.
1979
1980 @var{buffer-or-name} should be a buffer or the name of a buffer; if
1981 omitted or @code{nil}, it defaults to the current buffer. The
1982 optional argument @var{all-frames} specifies which windows to
1983 consider:
1984
1985 @itemize @bullet
1986 @item
1987 @code{t} means consider windows on all existing frames.
1988 @item
1989 @code{visible} means consider windows on all visible frames.
1990 @item
1991 0 means consider windows on all visible or iconified frames.
1992 @item
1993 A frame means consider windows on that frame only.
1994 @item
1995 Any other value means consider windows on the selected frame.
1996 @end itemize
1997
1998 Note that these meanings differ slightly from those of the
1999 @var{all-frames} argument to @code{next-window} (@pxref{Cyclic Window
2000 Ordering}). This function may be changed in a future version of Emacs
2001 to eliminate this discrepancy.
2002 @end defun
2003
2004 @defun get-buffer-window-list &optional buffer-or-name minibuf all-frames
2005 This function returns a list of all windows currently displaying
2006 @var{buffer-or-name}. @var{buffer-or-name} should be a buffer or the
2007 name of an existing buffer. If omitted or @code{nil}, it defaults to
2008 the current buffer. If the currently selected window displays
2009 @var{buffer-or-name}, it will be the first in the list returned by
2010 this function.
2011
2012 The arguments @var{minibuf} and @var{all-frames} have the same
2013 meanings as in the function @code{next-window} (@pxref{Cyclic Window
2014 Ordering}). Note that the @var{all-frames} argument does @emph{not}
2015 behave exactly like in @code{get-buffer-window}.
2016 @end defun
2017
2018 @deffn Command replace-buffer-in-windows &optional buffer-or-name
2019 This command replaces @var{buffer-or-name} with some other buffer, in
2020 all windows displaying it. @var{buffer-or-name} should be a buffer, or
2021 the name of an existing buffer; if omitted or @code{nil}, it defaults to
2022 the current buffer.
2023
2024 The replacement buffer in each window is chosen via
2025 @code{switch-to-prev-buffer} (@pxref{Window History}). Any dedicated
2026 window displaying @var{buffer-or-name} is deleted if possible
2027 (@pxref{Dedicated Windows}). If such a window is the only window on its
2028 frame and there are other frames on the same terminal, the frame is
2029 deleted as well. If the dedicated window is the only window on the only
2030 frame on its terminal, the buffer is replaced anyway.
2031 @end deffn
2032
2033
2034 @node Switching Buffers
2035 @section Switching to a Buffer in a Window
2036 @cindex switching to a buffer
2037 @cindex displaying a buffer
2038
2039 This section describes high-level functions for switching to a specified
2040 buffer in some window. In general, ``switching to a buffer'' means to
2041 (1) show the buffer in some window, (2) make that window the selected
2042 window (and its frame the selected frame), and (3) make the buffer the
2043 current buffer.
2044
2045 Do @emph{not} use these functions to make a buffer temporarily
2046 current just so a Lisp program can access or modify it. They have
2047 side-effects, such as changing window histories (@pxref{Window
2048 History}), which will surprise the user if used that way. If you want
2049 to make a buffer current to modify it in Lisp, use
2050 @code{with-current-buffer}, @code{save-current-buffer}, or
2051 @code{set-buffer}. @xref{Current Buffer}.
2052
2053 @deffn Command switch-to-buffer buffer-or-name &optional norecord force-same-window
2054 This command attempts to display @var{buffer-or-name} in the selected
2055 window and make it the current buffer. It is often used interactively
2056 (as the binding of @kbd{C-x b}), as well as in Lisp programs. The
2057 return value is the buffer switched to.
2058
2059 If @var{buffer-or-name} is @code{nil}, it defaults to the buffer
2060 returned by @code{other-buffer} (@pxref{Buffer List}). If
2061 @var{buffer-or-name} is a string that is not the name of any existing
2062 buffer, this function creates a new buffer with that name; the new
2063 buffer's major mode is determined by the variable @code{major-mode}
2064 (@pxref{Major Modes}).
2065
2066 Normally, the specified buffer is put at the front of the buffer
2067 list---both the global buffer list and the selected frame's buffer
2068 list (@pxref{Buffer List}). However, this is not done if the
2069 optional argument @var{norecord} is non-@code{nil}.
2070
2071 Sometimes, the selected window may not be suitable for displaying the
2072 buffer. This happens if the selected window is a minibuffer window, or
2073 if the selected window is strongly dedicated to its buffer
2074 (@pxref{Dedicated Windows}). In such cases, the command normally tries
2075 to display the buffer in some other window, by invoking
2076 @code{pop-to-buffer} (see below).
2077
2078 If the optional argument @var{force-same-window} is non-@code{nil} and
2079 the selected window is not suitable for displaying the buffer, this
2080 function always signals an error when called non-interactively. In
2081 interactive use, if the selected window is a minibuffer window, this
2082 function will try to use some other window instead. If the selected
2083 window is strongly dedicated to its buffer, the option
2084 @code{switch-to-buffer-in-dedicated-window} described next can be used
2085 to proceed.
2086 @end deffn
2087
2088 @defopt switch-to-buffer-in-dedicated-window
2089 This option, if non-@code{nil}, allows @code{switch-to-buffer} to
2090 proceed when called interactively and the selected window is strongly
2091 dedicated to its buffer.
2092
2093 The following values are respected:
2094
2095 @table @code
2096 @item nil
2097 Disallows switching and signals an error as in non-interactive use.
2098
2099 @item prompt
2100 Prompts the user whether to allow switching.
2101
2102 @item pop
2103 Invokes @code{pop-to-buffer} to proceed.
2104
2105 @item t
2106 Marks the selected window as non-dedicated and proceeds.
2107 @end table
2108
2109 When called non-interactively, @code{switch-to-buffer} always signals an
2110 error when the selected window is dedicated to its buffer and
2111 @var{force-same-window} is non-@code{nil}.
2112 @end defopt
2113
2114 By default, @code{switch-to-buffer} shows the buffer at its position of
2115 @code{point}. This behavior can be tuned using the following option.
2116
2117 @defopt switch-to-buffer-preserve-window-point
2118 If this variable is @code{nil}, @code{switch-to-buffer} displays the
2119 buffer specified by @var{buffer-or-name} at the position of that
2120 buffer's @code{point}. If this variable is @code{already-displayed}, it
2121 tries to display the buffer at its previous position in the selected
2122 window, provided the buffer is currently displayed in some other window
2123 on any visible or iconified frame. If this variable is @code{t},
2124 @code{switch-to-buffer} unconditionally tries to display the buffer at
2125 its previous position in the selected window.
2126
2127 This variable is ignored if the buffer is already displayed in the
2128 selected window or never appeared in it before, or if
2129 @code{switch-to-buffer} calls @code{pop-to-buffer} to display the
2130 buffer.
2131 @end defopt
2132
2133 The next two commands are similar to @code{switch-to-buffer}, except for
2134 the described features.
2135
2136 @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
2137 This function displays the buffer specified by @var{buffer-or-name} in
2138 some window other than the selected window. It uses the function
2139 @code{pop-to-buffer} internally (see below).
2140
2141 If the selected window already displays the specified buffer, it
2142 continues to do so, but another window is nonetheless found to display
2143 it as well.
2144
2145 The @var{buffer-or-name} and @var{norecord} arguments have the same
2146 meanings as in @code{switch-to-buffer}.
2147 @end deffn
2148
2149 @deffn Command switch-to-buffer-other-frame buffer-or-name &optional norecord
2150 This function displays the buffer specified by @var{buffer-or-name} in a
2151 new frame. It uses the function @code{pop-to-buffer} internally (see
2152 below).
2153
2154 If the specified buffer is already displayed in another window, in any
2155 frame on the current terminal, this switches to that window instead of
2156 creating a new frame. However, the selected window is never used for
2157 this.
2158
2159 The @var{buffer-or-name} and @var{norecord} arguments have the same
2160 meanings as in @code{switch-to-buffer}.
2161 @end deffn
2162
2163 The above commands use the function @code{pop-to-buffer}, which
2164 flexibly displays a buffer in some window and selects that window for
2165 editing. In turn, @code{pop-to-buffer} uses @code{display-buffer} for
2166 displaying the buffer. Hence, all the variables affecting
2167 @code{display-buffer} will affect it as well. @xref{Choosing Window},
2168 for the documentation of @code{display-buffer}.
2169
2170 @deffn Command pop-to-buffer buffer-or-name &optional action norecord
2171 This function makes @var{buffer-or-name} the current buffer and
2172 displays it in some window, preferably not the window previously
2173 selected. It then selects the displaying window. If that window is
2174 on a different graphical frame, that frame is given input focus if
2175 possible (@pxref{Input Focus}). The return value is the buffer that
2176 was switched to.
2177
2178 If @var{buffer-or-name} is @code{nil}, it defaults to the buffer
2179 returned by @code{other-buffer} (@pxref{Buffer List}). If
2180 @var{buffer-or-name} is a string that is not the name of any existing
2181 buffer, this function creates a new buffer with that name; the new
2182 buffer's major mode is determined by the variable @code{major-mode}
2183 (@pxref{Major Modes}).
2184
2185 If @var{action} is non-@code{nil}, it should be a display action to
2186 pass to @code{display-buffer} (@pxref{Choosing Window}).
2187 Alternatively, a non-@code{nil}, non-list value means to pop to a
2188 window other than the selected one---even if the buffer is already
2189 displayed in the selected window.
2190
2191 Like @code{switch-to-buffer}, this function updates the buffer list
2192 unless @var{norecord} is non-@code{nil}.
2193 @end deffn
2194
2195
2196 @node Choosing Window
2197 @section Choosing a Window for Display
2198
2199 The command @code{display-buffer} flexibly chooses a window for
2200 display, and displays a specified buffer in that window. It can be
2201 called interactively, via the key binding @kbd{C-x 4 C-o}. It is also
2202 used as a subroutine by many functions and commands, including
2203 @code{switch-to-buffer} and @code{pop-to-buffer} (@pxref{Switching
2204 Buffers}).
2205
2206 @cindex display action
2207 @cindex action function, for @code{display-buffer}
2208 @cindex action alist, for @code{display-buffer}
2209 This command performs several complex steps to find a window to
2210 display in. These steps are described by means of @dfn{display
2211 actions}, which have the form @code{(@var{function} . @var{alist})}.
2212 Here, @var{function} is either a function or a list of functions,
2213 which we refer to as @dfn{action functions}; @var{alist} is an
2214 association list, which we refer to as @dfn{action alists}.
2215
2216 An action function accepts two arguments: the buffer to display and
2217 an action alist. It attempts to display the buffer in some window,
2218 picking or creating a window according to its own criteria. If
2219 successful, it returns the window; otherwise, it returns @code{nil}.
2220 @xref{Display Action Functions}, for a list of predefined action
2221 functions.
2222
2223 @code{display-buffer} works by combining display actions from
2224 several sources, and calling the action functions in turn, until one
2225 of them manages to display the buffer and returns a non-@code{nil}
2226 value.
2227
2228 @deffn Command display-buffer buffer-or-name &optional action frame
2229 This command makes @var{buffer-or-name} appear in some window, without
2230 selecting the window or making the buffer current. The argument
2231 @var{buffer-or-name} must be a buffer or the name of an existing
2232 buffer. The return value is the window chosen to display the buffer.
2233
2234 The optional argument @var{action}, if non-@code{nil}, should normally
2235 be a display action (described above). @code{display-buffer} builds a
2236 list of action functions and an action alist, by consolidating display
2237 actions from the following sources (in order):
2238
2239 @itemize
2240 @item
2241 The variable @code{display-buffer-overriding-action}.
2242
2243 @item
2244 The user option @code{display-buffer-alist}.
2245
2246 @item
2247 The @var{action} argument.
2248
2249 @item
2250 The user option @code{display-buffer-base-action}.
2251
2252 @item
2253 The constant @code{display-buffer-fallback-action}.
2254 @end itemize
2255
2256 @noindent
2257 Each action function is called in turn, passing the buffer as the
2258 first argument and the combined action alist as the second argument,
2259 until one of the functions returns non-@code{nil}. The caller can
2260 pass @code{(allow-no-window . t)} as an element of the action alist to
2261 indicate its readiness to handle the case of not displaying the
2262 buffer in a window.
2263
2264 The argument @var{action} can also have a non-@code{nil}, non-list
2265 value. This has the special meaning that the buffer should be
2266 displayed in a window other than the selected one, even if the
2267 selected window is already displaying it. If called interactively
2268 with a prefix argument, @var{action} is @code{t}.
2269
2270 The optional argument @var{frame}, if non-@code{nil}, specifies which
2271 frames to check when deciding whether the buffer is already displayed.
2272 It is equivalent to adding an element @code{(reusable-frames
2273 . @var{frame})} to the action alist of @var{action}. @xref{Display
2274 Action Functions}.
2275 @end deffn
2276
2277 @defvar display-buffer-overriding-action
2278 The value of this variable should be a display action, which is
2279 treated with the highest priority by @code{display-buffer}. The
2280 default value is empty, i.e., @code{(nil . nil)}.
2281 @end defvar
2282
2283 @defopt display-buffer-alist
2284 The value of this option is an alist mapping conditions to display
2285 actions. Each condition may be either a regular expression matching a
2286 buffer name or a function that takes two arguments: a buffer name and
2287 the @var{action} argument passed to @code{display-buffer}. If the name
2288 of the buffer passed to @code{display-buffer} either matches a regular
2289 expression in this alist or the function specified by a condition
2290 returns non-@code{nil}, then @code{display-buffer} uses the
2291 corresponding display action to display the buffer.
2292 @end defopt
2293
2294 @defopt display-buffer-base-action
2295 The value of this option should be a display action. This option can
2296 be used to define a standard display action for calls to
2297 @code{display-buffer}.
2298 @end defopt
2299
2300 @defvr Constant display-buffer-fallback-action
2301 This display action specifies the fallback behavior for
2302 @code{display-buffer} if no other display actions are given.
2303 @end defvr
2304
2305
2306 @node Display Action Functions
2307 @section Action Functions for @code{display-buffer}
2308
2309 The following basic action functions are defined in Emacs. Each of
2310 these functions takes two arguments: @var{buffer}, the buffer to
2311 display, and @var{alist}, an action alist. Each action function
2312 returns the window if it succeeds, and @code{nil} if it fails.
2313
2314 @defun display-buffer-same-window buffer alist
2315 This function tries to display @var{buffer} in the selected window.
2316 It fails if the selected window is a minibuffer window or is dedicated
2317 to another buffer (@pxref{Dedicated Windows}). It also fails if
2318 @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry.
2319 @end defun
2320
2321 @defun display-buffer-reuse-window buffer alist
2322 This function tries to display @var{buffer} by finding a window
2323 that is already displaying it.
2324
2325 If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry,
2326 the selected window is not eligible for reuse. If @var{alist}
2327 contains a @code{reusable-frames} entry, its value determines which
2328 frames to search for a reusable window:
2329
2330 @itemize @bullet
2331 @item
2332 @code{nil} means consider windows on the selected frame.
2333 (Actually, the last non-minibuffer frame.)
2334 @item
2335 @code{t} means consider windows on all frames.
2336 @item
2337 @code{visible} means consider windows on all visible frames.
2338 @item
2339 0 means consider windows on all visible or iconified frames.
2340 @item
2341 A frame means consider windows on that frame only.
2342 @end itemize
2343
2344 Note that these meanings differ slightly from those of the
2345 @var{all-frames} argument to @code{next-window} (@pxref{Cyclic Window
2346 Ordering}).
2347
2348 If @var{alist} contains no @code{reusable-frames} entry, this function
2349 normally searches just the selected frame; however, if the variable
2350 @code{pop-up-frames} is non-@code{nil}, it searches all frames on the
2351 current terminal. @xref{Choosing Window Options}.
2352
2353 If this function chooses a window on another frame, it makes that frame
2354 visible and, unless @var{alist} contains an @code{inhibit-switch-frame}
2355 entry (@pxref{Choosing Window Options}), raises that frame if necessary.
2356 @end defun
2357
2358 @defun display-buffer-pop-up-frame buffer alist
2359 This function creates a new frame, and displays the buffer in that
2360 frame's window. It actually performs the frame creation by calling
2361 the function specified in @code{pop-up-frame-function}
2362 (@pxref{Choosing Window Options}). If @var{alist} contains a
2363 @code{pop-up-frame-parameters} entry, the associated value
2364 is added to the newly created frame's parameters.
2365 @end defun
2366
2367 @defun display-buffer-use-some-frame buffer alist
2368 This function tries to display @var{buffer} by trying to find a
2369 frame that meets a predicate (by default any frame other than the
2370 current frame).
2371
2372 If this function chooses a window on another frame, it makes that frame
2373 visible and, unless @var{alist} contains an @code{inhibit-switch-frame}
2374 entry (@pxref{Choosing Window Options}), raises that frame if necessary.
2375
2376 If @var{alist} has a non-nil @code{frame-predicate} entry, its value is a
2377 function taking one argument (a frame), returning non-nil if the
2378 frame is a candidate; this function replaces the default predicate.
2379
2380 If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry,
2381 the selected window is used; thus if the selected frame has a single
2382 window, it is not used.
2383
2384 @end defun
2385
2386 @defun display-buffer-pop-up-window buffer alist
2387 This function tries to display @var{buffer} by splitting the largest
2388 or least recently-used window (typically one on the selected frame).
2389 It actually performs the split by calling the function specified in
2390 @code{split-window-preferred-function} (@pxref{Choosing Window
2391 Options}).
2392
2393 The size of the new window can be adjusted by supplying
2394 @code{window-height} and @code{window-width} entries in @var{alist}. To
2395 adjust the window's height, use an entry whose @sc{car} is
2396 @code{window-height} and whose @sc{cdr} is one of:
2397
2398 @itemize @bullet
2399 @item
2400 @code{nil} means to leave the height of the new window alone.
2401
2402 @item
2403 A number specifies the desired height of the new window. An integer
2404 specifies the number of lines of the window. A floating-point
2405 number gives the fraction of the window's height with respect to the
2406 height of the frame's root window.
2407
2408 @item
2409 If the @sc{cdr} specifies a function, that function is called with one
2410 argument: the new window. The function is supposed to adjust the
2411 height of the window; its return value is ignored. Suitable functions
2412 are @code{shrink-window-if-larger-than-buffer} and
2413 @code{fit-window-to-buffer}, see @ref{Resizing Windows}.
2414 @end itemize
2415
2416 To adjust the window's width, use an entry whose @sc{car} is
2417 @code{window-width} and whose @sc{cdr} is one of:
2418
2419 @itemize @bullet
2420 @item
2421 @code{nil} means to leave the width of the new window alone.
2422
2423 @item
2424 A number specifies the desired width of the new window. An integer
2425 specifies the number of columns of the window. A floating-point
2426 number gives the fraction of the window's width with respect to the
2427 width of the frame's root window.
2428
2429 @item
2430 If the @sc{cdr} specifies a function, that function is called with one
2431 argument: the new window. The function is supposed to adjust the width
2432 of the window; its return value is ignored.
2433 @end itemize
2434
2435 If @var{alist} contains a @code{preserve-size} entry, Emacs will try to
2436 preserve the size of the new window during future resize operations
2437 (@pxref{Preserving Window Sizes}). The @sc{cdr} of that entry must be a
2438 cons cell whose @sc{car}, if non-@code{nil}, means to preserve the width
2439 of the window and whose @sc{cdr}, if non-@code{nil}, means to preserve
2440 the height of the window.
2441
2442 This function can fail if no window splitting can be performed for some
2443 reason (e.g., if the selected frame has an @code{unsplittable} frame
2444 parameter; @pxref{Buffer Parameters}).
2445 @end defun
2446
2447 @defun display-buffer-below-selected buffer alist
2448 This function tries to display @var{buffer} in a window below the
2449 selected window. This means to either split the selected window or use
2450 the window below the selected one. If it does create a new window, it
2451 will also adjust its size provided @var{alist} contains a suitable
2452 @code{window-height} or @code{window-width} entry, see above.
2453 @end defun
2454
2455 @defun display-buffer-in-previous-window buffer alist
2456 This function tries to display @var{buffer} in a window previously
2457 showing it. If @var{alist} has a non-@code{nil}
2458 @code{inhibit-same-window} entry, the selected window is not eligible
2459 for reuse. If @var{alist} contains a @code{reusable-frames} entry, its
2460 value determines which frames to search for a suitable window as with
2461 @code{display-buffer-reuse-window}.
2462
2463 If @var{alist} has a @code{previous-window} entry, the window
2464 specified by that entry will override any other window found by the
2465 methods above, even if that window never showed @var{buffer} before.
2466 @end defun
2467
2468 @defun display-buffer-at-bottom buffer alist
2469 This function tries to display @var{buffer} in a window at the bottom
2470 of the selected frame.
2471
2472 This either splits the window at the bottom of the frame or the
2473 frame's root window, or reuses an existing window at the bottom of the
2474 selected frame.
2475 @end defun
2476
2477 @defun display-buffer-use-some-window buffer alist
2478 This function tries to display @var{buffer} by choosing an existing
2479 window and displaying the buffer in that window. It can fail if all
2480 windows are dedicated to another buffer (@pxref{Dedicated Windows}).
2481 @end defun
2482
2483 @defun display-buffer-no-window buffer alist
2484 If @var{alist} has a non-@code{nil} @code{allow-no-window} entry, then
2485 this function does not display @code{buffer}. This allows to override
2486 the default action and avoid displaying the buffer. It is assumed that
2487 when the caller specifies a non-@code{nil} @code{allow-no-window} value
2488 it can handle a @code{nil} value returned from @code{display-buffer} in
2489 this case.
2490 @end defun
2491
2492 To illustrate the use of action functions, consider the following
2493 example.
2494
2495 @example
2496 @group
2497 (display-buffer
2498 (get-buffer-create "*foo*")
2499 '((display-buffer-reuse-window
2500 display-buffer-pop-up-window
2501 display-buffer-pop-up-frame)
2502 (reusable-frames . 0)
2503 (window-height . 10) (window-width . 40)))
2504 @end group
2505 @end example
2506
2507 @noindent
2508 Evaluating the form above will cause @code{display-buffer} to proceed as
2509 follows: If a buffer called *foo* already appears on a visible or
2510 iconified frame, it will reuse its window. Otherwise, it will try to
2511 pop up a new window or, if that is impossible, a new frame and show the
2512 buffer there. If all these steps fail, it will proceed using whatever
2513 @code{display-buffer-base-action} and
2514 @code{display-buffer-fallback-action} prescribe.
2515
2516 Furthermore, @code{display-buffer} will try to adjust a reused window
2517 (provided *foo* was put by @code{display-buffer} there before) or a
2518 popped-up window as follows: If the window is part of a vertical
2519 combination, it will set its height to ten lines. Note that if, instead
2520 of the number 10, we specified the function
2521 @code{fit-window-to-buffer}, @code{display-buffer} would come up with a
2522 one-line window to fit the empty buffer. If the window is part of a
2523 horizontal combination, it sets its width to 40 columns. Whether a new
2524 window is vertically or horizontally combined depends on the shape of
2525 the window split and the values of
2526 @code{split-window-preferred-function}, @code{split-height-threshold}
2527 and @code{split-width-threshold} (@pxref{Choosing Window Options}).
2528
2529 Now suppose we combine this call with a preexisting setup for
2530 @code{display-buffer-alist} as follows.
2531
2532 @example
2533 @group
2534 (let ((display-buffer-alist
2535 (cons
2536 '("\\*foo\\*"
2537 (display-buffer-reuse-window display-buffer-below-selected)
2538 (reusable-frames)
2539 (window-height . 5))
2540 display-buffer-alist)))
2541 (display-buffer
2542 (get-buffer-create "*foo*")
2543 '((display-buffer-reuse-window
2544 display-buffer-pop-up-window
2545 display-buffer-pop-up-frame)
2546 (reusable-frames . 0)
2547 (window-height . 10) (window-width . 40))))
2548 @end group
2549 @end example
2550
2551 @noindent
2552 This form will have @code{display-buffer} first try reusing a window
2553 that shows *foo* on the selected frame. If there's no such window, it
2554 will try to split the selected window or, if that is impossible, use the
2555 window below the selected window.
2556
2557 If there's no window below the selected one, or the window below the
2558 selected one is dedicated to its buffer, @code{display-buffer} will
2559 proceed as described in the previous example. Note, however, that when
2560 it tries to adjust the height of any reused or popped-up window, it will
2561 in any case try to set its number of lines to 5 since that value
2562 overrides the corresponding specification in the @var{action} argument
2563 of @code{display-buffer}.
2564
2565
2566 @node Choosing Window Options
2567 @section Additional Options for Displaying Buffers
2568
2569 The behavior of the standard display actions of @code{display-buffer}
2570 (@pxref{Choosing Window}) can be modified by a variety of user
2571 options.
2572
2573 @defopt pop-up-windows
2574 If the value of this variable is non-@code{nil}, @code{display-buffer}
2575 is allowed to split an existing window to make a new window for
2576 displaying in. This is the default.
2577
2578 This variable is provided mainly for backward compatibility. It is
2579 obeyed by @code{display-buffer} via a special mechanism in
2580 @code{display-buffer-fallback-action}, which only calls the action
2581 function @code{display-buffer-pop-up-window} (@pxref{Display Action
2582 Functions}) when the value is @code{nil}. It is not consulted by
2583 @code{display-buffer-pop-up-window} itself, which the user may specify
2584 directly in @code{display-buffer-alist} etc.
2585 @end defopt
2586
2587 @defopt split-window-preferred-function
2588 This variable specifies a function for splitting a window, in order to
2589 make a new window for displaying a buffer. It is used by the
2590 @code{display-buffer-pop-up-window} action function to actually split
2591 the window (@pxref{Display Action Functions}).
2592
2593 The default value is @code{split-window-sensibly}, which is documented
2594 below. The value must be a function that takes one argument, a window,
2595 and return either a new window (which will be used to display the
2596 desired buffer) or @code{nil} (which means the splitting failed).
2597 @end defopt
2598
2599 @defun split-window-sensibly window
2600 This function tries to split @var{window}, and return the newly
2601 created window. If @var{window} cannot be split, it returns
2602 @code{nil}.
2603
2604 This function obeys the usual rules that determine when a window may
2605 be split (@pxref{Splitting Windows}). It first tries to split by
2606 placing the new window below, subject to the restriction imposed by
2607 @code{split-height-threshold} (see below), in addition to any other
2608 restrictions. If that fails, it tries to split by placing the new
2609 window to the right, subject to @code{split-width-threshold} (see
2610 below). If that fails, and the window is the only window on its
2611 frame, this function again tries to split and place the new window
2612 below, disregarding @code{split-height-threshold}. If this fails as
2613 well, this function gives up and returns @code{nil}.
2614 @end defun
2615
2616 @defopt split-height-threshold
2617 This variable, used by @code{split-window-sensibly}, specifies whether
2618 to split the window placing the new window below. If it is an
2619 integer, that means to split only if the original window has at least
2620 that many lines. If it is @code{nil}, that means not to split this
2621 way.
2622 @end defopt
2623
2624 @defopt split-width-threshold
2625 This variable, used by @code{split-window-sensibly}, specifies whether
2626 to split the window placing the new window to the right. If the value
2627 is an integer, that means to split only if the original window has at
2628 least that many columns. If the value is @code{nil}, that means not
2629 to split this way.
2630 @end defopt
2631
2632 @defopt even-window-sizes
2633 This variable, if non-nil, causes @code{display-buffer} to even window
2634 sizes whenever it reuses an existing window and that window is adjacent
2635 to the selected one.
2636
2637 If its value is @code{width-only}, sizes are evened only if the reused
2638 window is on the left or right of the selected one and the selected
2639 window is wider than the reused one. If its value is @code{height-only}
2640 sizes are evened only if the reused window is above or beneath the
2641 selected window and the selected window is higher than the reused one.
2642 Any other non-@code{nil} value means to even sizes in any of these cases
2643 provided the selected window is larger than the reused one in the sense
2644 of their combination.
2645 @end defopt
2646
2647 @defopt pop-up-frames
2648 If the value of this variable is non-@code{nil}, that means
2649 @code{display-buffer} may display buffers by making new frames. The
2650 default is @code{nil}.
2651
2652 A non-@code{nil} value also means that when @code{display-buffer} is
2653 looking for a window already displaying @var{buffer-or-name}, it can
2654 search any visible or iconified frame, not just the selected frame.
2655
2656 This variable is provided mainly for backward compatibility. It is
2657 obeyed by @code{display-buffer} via a special mechanism in
2658 @code{display-buffer-fallback-action}, which calls the action function
2659 @code{display-buffer-pop-up-frame} (@pxref{Display Action Functions})
2660 if the value is non-@code{nil}. (This is done before attempting to
2661 split a window.) This variable is not consulted by
2662 @code{display-buffer-pop-up-frame} itself, which the user may specify
2663 directly in @code{display-buffer-alist} etc.
2664 @end defopt
2665
2666 @defopt pop-up-frame-function
2667 This variable specifies a function for creating a new frame, in order
2668 to make a new window for displaying a buffer. It is used by the
2669 @code{display-buffer-pop-up-frame} action function (@pxref{Display
2670 Action Functions}).
2671
2672 The value should be a function that takes no arguments and returns a
2673 frame, or @code{nil} if no frame could be created. The default value
2674 is a function that creates a frame using the parameters specified by
2675 @code{pop-up-frame-alist} (see below).
2676 @end defopt
2677
2678 @defopt pop-up-frame-alist
2679 This variable holds an alist of frame parameters (@pxref{Frame
2680 Parameters}), which is used by the default function in
2681 @code{pop-up-frame-function} to make a new frame. The default is
2682 @code{nil}.
2683 @end defopt
2684
2685 @defopt same-window-buffer-names
2686 A list of buffer names for buffers that should be displayed in the
2687 selected window. If a buffer's name is in this list,
2688 @code{display-buffer} handles the buffer by showing it in the selected
2689 window.
2690 @end defopt
2691
2692 @defopt same-window-regexps
2693 A list of regular expressions that specify buffers that should be
2694 displayed in the selected window. If the buffer's name matches any of
2695 the regular expressions in this list, @code{display-buffer} handles the
2696 buffer by showing it in the selected window.
2697 @end defopt
2698
2699 @defun same-window-p buffer-name
2700 This function returns @code{t} if displaying a buffer
2701 named @var{buffer-name} with @code{display-buffer} would
2702 put it in the selected window.
2703 @end defun
2704
2705 @node Window History
2706 @section Window History
2707 @cindex window history
2708
2709 Each window remembers in a list the buffers it has previously displayed,
2710 and the order in which these buffers were removed from it. This history
2711 is used, for example, by @code{replace-buffer-in-windows}
2712 (@pxref{Buffers and Windows}). The list is automatically maintained by
2713 Emacs, but you can use the following functions to explicitly inspect or
2714 alter it:
2715
2716 @defun window-prev-buffers &optional window
2717 This function returns a list specifying the previous contents of
2718 @var{window}. The optional argument @var{window} should be a live
2719 window and defaults to the selected one.
2720
2721 Each list element has the form @code{(@var{buffer} @var{window-start}
2722 @var{window-pos})}, where @var{buffer} is a buffer previously shown in
2723 the window, @var{window-start} is the window start position
2724 (@pxref{Window Start and End}) when that buffer was last shown, and
2725 @var{window-pos} is the point position (@pxref{Window Point}) when
2726 that buffer was last shown in @var{window}.
2727
2728 The list is ordered so that earlier elements correspond to more
2729 recently-shown buffers, and the first element usually corresponds to the
2730 buffer most recently removed from the window.
2731 @end defun
2732
2733 @defun set-window-prev-buffers window prev-buffers
2734 This function sets @var{window}'s previous buffers to the value of
2735 @var{prev-buffers}. The argument @var{window} must be a live window
2736 and defaults to the selected one. The argument @var{prev-buffers}
2737 should be a list of the same form as that returned by
2738 @code{window-prev-buffers}.
2739 @end defun
2740
2741 In addition, each buffer maintains a list of @dfn{next buffers}, which
2742 is a list of buffers re-shown by @code{switch-to-prev-buffer} (see
2743 below). This list is mainly used by @code{switch-to-prev-buffer} and
2744 @code{switch-to-next-buffer} for choosing buffers to switch to.
2745
2746 @defun window-next-buffers &optional window
2747 This function returns the list of buffers recently re-shown in
2748 @var{window} via @code{switch-to-prev-buffer}. The @var{window}
2749 argument must denote a live window or @code{nil} (meaning the selected
2750 window).
2751 @end defun
2752
2753 @defun set-window-next-buffers window next-buffers
2754 This function sets the next buffer list of @var{window} to
2755 @var{next-buffers}. The @var{window} argument should be a live window
2756 or @code{nil} (meaning the selected window). The argument
2757 @var{next-buffers} should be a list of buffers.
2758 @end defun
2759
2760 The following commands can be used to cycle through the global buffer
2761 list, much like @code{bury-buffer} and @code{unbury-buffer}. However,
2762 they cycle according to the specified window's history list, rather
2763 than the global buffer list. In addition, they restore
2764 window-specific window start and point positions, and may show a
2765 buffer even if it is already shown in another window. The
2766 @code{switch-to-prev-buffer} command, in particular, is used by
2767 @code{replace-buffer-in-windows}, @code{bury-buffer} and
2768 @code{quit-window} to find a replacement buffer for a window.
2769
2770 @deffn Command switch-to-prev-buffer &optional window bury-or-kill
2771 This command displays the previous buffer in @var{window}. The
2772 argument @var{window} should be a live window or @code{nil} (meaning
2773 the selected window). If the optional argument @var{bury-or-kill} is
2774 non-@code{nil}, this means that the buffer currently shown in
2775 @var{window} is about to be buried or killed and consequently should
2776 not be switched to in future invocations of this command.
2777
2778 The previous buffer is usually the buffer shown before the buffer
2779 currently shown in @var{window}. However, a buffer that has been buried
2780 or killed, or has been already shown by a recent invocation of
2781 @code{switch-to-prev-buffer}, does not qualify as previous buffer.
2782
2783 If repeated invocations of this command have already shown all buffers
2784 previously shown in @var{window}, further invocations will show buffers
2785 from the buffer list of the frame @var{window} appears on (@pxref{Buffer
2786 List}), trying to skip buffers that are already shown in another window
2787 on that frame.
2788 @end deffn
2789
2790 @deffn Command switch-to-next-buffer &optional window
2791 This command switches to the next buffer in @var{window}, thus undoing
2792 the effect of the last @code{switch-to-prev-buffer} command in
2793 @var{window}. The argument @var{window} must be a live window and
2794 defaults to the selected one.
2795
2796 If there is no recent invocation of @code{switch-to-prev-buffer} that
2797 can be undone, this function tries to show a buffer from the buffer list
2798 of the frame @var{window} appears on (@pxref{Buffer List}).
2799 @end deffn
2800
2801 By default @code{switch-to-prev-buffer} and @code{switch-to-next-buffer}
2802 can switch to a buffer that is already shown in another window on the
2803 same frame. The following option can be used to override this behavior.
2804
2805 @defopt switch-to-visible-buffer
2806 If this variable is non-@code{nil}, @code{switch-to-prev-buffer} and
2807 @code{switch-to-next-buffer} may switch to a buffer that is already
2808 visible on the same frame, provided the buffer was shown in the
2809 relevant window before. If it is @code{nil},
2810 @code{switch-to-prev-buffer} and @code{switch-to-next-buffer} always
2811 try to avoid switching to a buffer that is already visible in another
2812 window on the same frame. The default is @code{t}.
2813 @end defopt
2814
2815
2816 @node Dedicated Windows
2817 @section Dedicated Windows
2818 @cindex dedicated window
2819
2820 Functions for displaying a buffer can be told to not use specific
2821 windows by marking these windows as @dfn{dedicated} to their buffers.
2822 @code{display-buffer} (@pxref{Choosing Window}) never uses a dedicated
2823 window for displaying another buffer in it. @code{get-lru-window} and
2824 @code{get-largest-window} (@pxref{Cyclic Window Ordering}) do not
2825 consider dedicated windows as candidates when their @var{dedicated}
2826 argument is non-@code{nil}. The behavior of @code{set-window-buffer}
2827 (@pxref{Buffers and Windows}) with respect to dedicated windows is
2828 slightly different, see below.
2829
2830 Functions supposed to remove a buffer from a window or a window from
2831 a frame can behave specially when a window they operate on is dedicated.
2832 We will distinguish three basic cases, namely where (1) the window is
2833 not the only window on its frame, (2) the window is the only window on
2834 its frame but there are other frames on the same terminal left, and (3)
2835 the window is the only window on the only frame on the same terminal.
2836
2837 In particular, @code{delete-windows-on} (@pxref{Deleting Windows})
2838 handles case (2) by deleting the associated frame and case (3) by
2839 showing another buffer in that frame's only window. The function
2840 @code{replace-buffer-in-windows} (@pxref{Buffers and Windows}) which is
2841 called when a buffer gets killed, deletes the window in case (1) and
2842 behaves like @code{delete-windows-on} otherwise.
2843 @c FIXME: Does replace-buffer-in-windows _delete_ a window in case (1)?
2844
2845 When @code{bury-buffer} (@pxref{Buffer List}) operates on the
2846 selected window (which shows the buffer that shall be buried), it
2847 handles case (2) by calling @code{frame-auto-hide-function}
2848 (@pxref{Quitting Windows}) to deal with the selected frame. The other
2849 two cases are handled as with @code{replace-buffer-in-windows}.
2850
2851 @defun window-dedicated-p &optional window
2852 This function returns non-@code{nil} if @var{window} is dedicated to its
2853 buffer and @code{nil} otherwise. More precisely, the return value is
2854 the value assigned by the last call of @code{set-window-dedicated-p} for
2855 @var{window}, or @code{nil} if that function was never called with
2856 @var{window} as its argument. The default for @var{window} is the
2857 selected window.
2858 @end defun
2859
2860 @defun set-window-dedicated-p window flag
2861 This function marks @var{window} as dedicated to its buffer if
2862 @var{flag} is non-@code{nil}, and non-dedicated otherwise.
2863
2864 As a special case, if @var{flag} is @code{t}, @var{window} becomes
2865 @dfn{strongly} dedicated to its buffer. @code{set-window-buffer}
2866 signals an error when the window it acts upon is strongly dedicated to
2867 its buffer and does not already display the buffer it is asked to
2868 display. Other functions do not treat @code{t} differently from any
2869 non-@code{nil} value.
2870 @end defun
2871
2872
2873 @node Quitting Windows
2874 @section Quitting Windows
2875
2876 When you want to get rid of a window used for displaying a buffer, you
2877 can call @code{delete-window} or @code{delete-windows-on}
2878 (@pxref{Deleting Windows}) to remove that window from its frame. If the
2879 buffer is shown on a separate frame, you might want to call
2880 @code{delete-frame} (@pxref{Deleting Frames}) instead. If, on the other
2881 hand, a window has been reused for displaying the buffer, you might
2882 prefer showing the buffer previously shown in that window, by calling the
2883 function @code{switch-to-prev-buffer} (@pxref{Window History}).
2884 Finally, you might want to either bury (@pxref{Buffer List}) or kill
2885 (@pxref{Killing Buffers}) the window's buffer.
2886
2887 The following command uses information on how the window for
2888 displaying the buffer was obtained in the first place, thus attempting
2889 to automate the above decisions for you.
2890
2891 @deffn Command quit-window &optional kill window
2892 This command quits @var{window} and buries its buffer. The argument
2893 @var{window} must be a live window and defaults to the selected one.
2894 With prefix argument @var{kill} non-@code{nil}, it kills the buffer
2895 instead of burying it. It calls the function @code{quit-restore-window}
2896 described next to deal with the window and its buffer.
2897 @end deffn
2898
2899 @defun quit-restore-window &optional window bury-or-kill
2900 This function tries to restore the state of @var{window} that existed
2901 before its buffer was displayed in it. The optional argument
2902 @var{window} must be a live window and defaults to the selected one.
2903
2904 If @var{window} was created specially for displaying its buffer, this
2905 function deletes @var{window} provided its frame contains at least one
2906 other live window. If @var{window} is the only window on its frame and
2907 there are other frames on the frame's terminal, the value of the
2908 optional argument @var{bury-or-kill} determines how to proceed with the
2909 window. If @var{bury-or-kill} equals @code{kill}, the frame is deleted
2910 unconditionally. Otherwise, the fate of the frame is determined by
2911 calling @code{frame-auto-hide-function} (see below) with that frame as
2912 sole argument.
2913
2914 Otherwise, this function tries to redisplay the buffer previously shown
2915 in @var{window}. It also tries to restore the window start
2916 (@pxref{Window Start and End}) and point (@pxref{Window Point})
2917 positions of the previously shown buffer. If, in addition,
2918 @var{window}'s buffer was temporarily resized, this function will also
2919 try to restore the original height of @var{window}.
2920
2921 The cases described so far require that the buffer shown in @var{window}
2922 is still the buffer displayed by the last buffer display function for
2923 this window. If another buffer has been shown in the meantime, or the
2924 buffer previously shown no longer exists, this function calls
2925 @code{switch-to-prev-buffer} (@pxref{Window History}) to show some other
2926 buffer instead.
2927
2928 The optional argument @var{bury-or-kill} specifies how to deal with
2929 @var{window}'s buffer. The following values are handled:
2930
2931 @table @code
2932 @item nil
2933 This means to not deal with the buffer in any particular way. As a
2934 consequence, if @var{window} is not deleted, invoking
2935 @code{switch-to-prev-buffer} will usually show the buffer again.
2936
2937 @item append
2938 This means that if @var{window} is not deleted, its buffer is moved to
2939 the end of @var{window}'s list of previous buffers, so it's less likely
2940 that a future invocation of @code{switch-to-prev-buffer} will switch to
2941 it. Also, it moves the buffer to the end of the frame's buffer list.
2942
2943 @item bury
2944 This means that if @var{window} is not deleted, its buffer is removed
2945 from @var{window}'s list of previous buffers. Also, it moves the buffer
2946 to the end of the frame's buffer list. This value provides the most
2947 reliable remedy to not have @code{switch-to-prev-buffer} switch to this
2948 buffer again without killing the buffer.
2949
2950 @item kill
2951 This means to kill @var{window}'s buffer.
2952 @end table
2953
2954 @code{quit-restore-window} bases its decisions on information stored in
2955 @var{window}'s @code{quit-restore} window parameter (@pxref{Window
2956 Parameters}), and resets that parameter to @code{nil} after it's done.
2957 @end defun
2958
2959 The following option specifies how to deal with a frame containing just
2960 one window that should be either quit, or whose buffer should be buried.
2961
2962 @defopt frame-auto-hide-function
2963 The function specified by this option is called to automatically hide
2964 frames. This function is called with one argument---a frame.
2965
2966 The function specified here is called by @code{bury-buffer}
2967 (@pxref{Buffer List}) when the selected window is dedicated and shows
2968 the buffer to bury. It is also called by @code{quit-restore-window}
2969 (see above) when the frame of the window to quit has been specially
2970 created for displaying that window's buffer and the buffer is not
2971 killed.
2972
2973 The default is to call @code{iconify-frame} (@pxref{Visibility of
2974 Frames}). Alternatively, you may specify either @code{delete-frame}
2975 (@pxref{Deleting Frames}) to remove the frame from its display,
2976 @code{ignore} to leave the frame unchanged, or any other function that
2977 can take a frame as its sole argument.
2978
2979 Note that the function specified by this option is called only if the
2980 specified frame contains just one live window and there is at least one
2981 other frame on the same terminal.
2982 @end defopt
2983
2984
2985 @node Window Point
2986 @section Windows and Point
2987 @cindex window position
2988 @cindex window point
2989 @cindex position in window
2990 @cindex point in window
2991
2992 Each window has its own value of point (@pxref{Point}), independent of
2993 the value of point in other windows displaying the same buffer. This
2994 makes it useful to have multiple windows showing one buffer.
2995
2996 @itemize @bullet
2997 @item
2998 The window point is established when a window is first created; it is
2999 initialized from the buffer's point, or from the window point of another
3000 window opened on the buffer if such a window exists.
3001
3002 @item
3003 Selecting a window sets the value of point in its buffer from the
3004 window's value of point. Conversely, deselecting a window sets the
3005 window's value of point from that of the buffer. Thus, when you switch
3006 between windows that display a given buffer, the point value for the
3007 selected window is in effect in the buffer, while the point values for
3008 the other windows are stored in those windows.
3009
3010 @item
3011 As long as the selected window displays the current buffer, the window's
3012 point and the buffer's point always move together; they remain equal.
3013 @end itemize
3014
3015 @cindex cursor
3016 As far as the user is concerned, point is where the cursor is, and
3017 when the user switches to another buffer, the cursor jumps to the
3018 position of point in that buffer.
3019
3020 @defun window-point &optional window
3021 This function returns the current position of point in @var{window}.
3022 For a nonselected window, this is the value point would have (in that
3023 window's buffer) if that window were selected. The default for
3024 @var{window} is the selected window.
3025
3026 When @var{window} is the selected window, the value returned is the
3027 value of point in that window's buffer. Strictly speaking, it would be
3028 more correct to return the top-level value of point, outside of any
3029 @code{save-excursion} forms. But that value is hard to find.
3030 @end defun
3031
3032 @defun set-window-point window position
3033 This function positions point in @var{window} at position
3034 @var{position} in @var{window}'s buffer. It returns @var{position}.
3035
3036 If @var{window} is selected, this simply does @code{goto-char} in
3037 @var{window}'s buffer.
3038 @end defun
3039
3040 @defvar window-point-insertion-type
3041 This variable specifies the marker insertion type (@pxref{Marker
3042 Insertion Types}) of @code{window-point}. The default is @code{nil},
3043 so @code{window-point} will stay behind text inserted there.
3044 @end defvar
3045
3046 @node Window Start and End
3047 @section The Window Start and End Positions
3048 @cindex window start position
3049 @cindex display-start position
3050
3051 Each window maintains a marker used to keep track of a buffer position
3052 that specifies where in the buffer display should start. This position
3053 is called the @dfn{display-start} position of the window (or just the
3054 @dfn{start}). The character after this position is the one that appears
3055 at the upper left corner of the window. It is usually, but not
3056 inevitably, at the beginning of a text line.
3057
3058 After switching windows or buffers, and in some other cases, if the
3059 window start is in the middle of a line, Emacs adjusts the window
3060 start to the start of a line. This prevents certain operations from
3061 leaving the window start at a meaningless point within a line. This
3062 feature may interfere with testing some Lisp code by executing it
3063 using the commands of Lisp mode, because they trigger this
3064 readjustment. To test such code, put it into a command and bind the
3065 command to a key.
3066
3067 @defun window-start &optional window
3068 @cindex window top line
3069 This function returns the display-start position of window
3070 @var{window}. If @var{window} is @code{nil}, the selected window is
3071 used.
3072
3073 When you create a window, or display a different buffer in it, the
3074 display-start position is set to a display-start position recently used
3075 for the same buffer, or to @code{point-min} if the buffer doesn't have
3076 any.
3077
3078 Redisplay updates the window-start position (if you have not specified
3079 it explicitly since the previous redisplay)---to make sure point appears
3080 on the screen. Nothing except redisplay automatically changes the
3081 window-start position; if you move point, do not expect the window-start
3082 position to change in response until after the next redisplay.
3083 @end defun
3084
3085 @cindex window end position
3086 @defun window-end &optional window update
3087 This function returns the position where display of its buffer ends in
3088 @var{window}. The default for @var{window} is the selected window.
3089
3090 Simply changing the buffer text or moving point does not update the
3091 value that @code{window-end} returns. The value is updated only when
3092 Emacs redisplays and redisplay completes without being preempted.
3093
3094 If the last redisplay of @var{window} was preempted, and did not finish,
3095 Emacs does not know the position of the end of display in that window.
3096 In that case, this function returns @code{nil}.
3097
3098 If @var{update} is non-@code{nil}, @code{window-end} always returns an
3099 up-to-date value for where display ends, based on the current
3100 @code{window-start} value. If a previously saved value of that position
3101 is still valid, @code{window-end} returns that value; otherwise it
3102 computes the correct value by scanning the buffer text.
3103
3104 Even if @var{update} is non-@code{nil}, @code{window-end} does not
3105 attempt to scroll the display if point has moved off the screen, the
3106 way real redisplay would do. It does not alter the
3107 @code{window-start} value. In effect, it reports where the displayed
3108 text will end if scrolling is not required.
3109 @end defun
3110
3111 @defun set-window-start window position &optional noforce
3112 This function sets the display-start position of @var{window} to
3113 @var{position} in @var{window}'s buffer. It returns @var{position}.
3114
3115 The display routines insist that the position of point be visible when a
3116 buffer is displayed. Normally, they change the display-start position
3117 (that is, scroll the window) whenever necessary to make point visible.
3118 However, if you specify the start position with this function using
3119 @code{nil} for @var{noforce}, it means you want display to start at
3120 @var{position} even if that would put the location of point off the
3121 screen. If this does place point off screen, the display routines move
3122 point to the left margin on the middle line in the window.
3123
3124 For example, if point @w{is 1} and you set the start of the window
3125 @w{to 37}, the start of the next line, point will be above the top
3126 of the window. The display routines will automatically move point if
3127 it is still 1 when redisplay occurs. Here is an example:
3128
3129 @example
3130 @group
3131 ;; @r{Here is what @samp{foo} looks like before executing}
3132 ;; @r{the @code{set-window-start} expression.}
3133 @end group
3134
3135 @group
3136 ---------- Buffer: foo ----------
3137 @point{}This is the contents of buffer foo.
3138 2
3139 3
3140 4
3141 5
3142 6
3143 ---------- Buffer: foo ----------
3144 @end group
3145
3146 @group
3147 (set-window-start
3148 (selected-window)
3149 (save-excursion
3150 (goto-char 1)
3151 (forward-line 1)
3152 (point)))
3153 @result{} 37
3154 @end group
3155
3156 @group
3157 ;; @r{Here is what @samp{foo} looks like after executing}
3158 ;; @r{the @code{set-window-start} expression.}
3159 ---------- Buffer: foo ----------
3160 2
3161 3
3162 @point{}4
3163 5
3164 6
3165 ---------- Buffer: foo ----------
3166 @end group
3167 @end example
3168
3169 If @var{noforce} is non-@code{nil}, and @var{position} would place point
3170 off screen at the next redisplay, then redisplay computes a new window-start
3171 position that works well with point, and thus @var{position} is not used.
3172 @end defun
3173
3174 @defun pos-visible-in-window-p &optional position window partially
3175 This function returns non-@code{nil} if @var{position} is within the
3176 range of text currently visible on the screen in @var{window}. It
3177 returns @code{nil} if @var{position} is scrolled vertically out of view.
3178 Locations that are partially obscured are not considered visible unless
3179 @var{partially} is non-@code{nil}. The argument @var{position} defaults
3180 to the current position of point in @var{window}; @var{window}, to the
3181 selected window. If @var{position} is @code{t}, that means to check the
3182 last visible position in @var{window}.
3183
3184 This function considers only vertical scrolling. If @var{position} is
3185 out of view only because @var{window} has been scrolled horizontally,
3186 @code{pos-visible-in-window-p} returns non-@code{nil} anyway.
3187 @xref{Horizontal Scrolling}.
3188
3189 If @var{position} is visible, @code{pos-visible-in-window-p} returns
3190 @code{t} if @var{partially} is @code{nil}; if @var{partially} is
3191 non-@code{nil}, and the character following @var{position} is fully
3192 visible, it returns a list of the form @code{(@var{x} @var{y})}, where
3193 @var{x} and @var{y} are the pixel coordinates relative to the top left
3194 corner of the window; otherwise it returns an extended list of the form
3195 @code{(@var{x} @var{y} @var{rtop} @var{rbot} @var{rowh} @var{vpos})},
3196 where @var{rtop} and @var{rbot} specify the number of off-window pixels
3197 at the top and bottom of the row at @var{position}, @var{rowh} specifies
3198 the visible height of that row, and @var{vpos} specifies the vertical
3199 position (zero-based row number) of that row.
3200
3201 Here is an example:
3202
3203 @example
3204 @group
3205 ;; @r{If point is off the screen now, recenter it now.}
3206 (or (pos-visible-in-window-p
3207 (point) (selected-window))
3208 (recenter 0))
3209 @end group
3210 @end example
3211 @end defun
3212
3213 @defun window-line-height &optional line window
3214 This function returns the height of text line @var{line} in
3215 @var{window}. If @var{line} is one of @code{header-line} or
3216 @code{mode-line}, @code{window-line-height} returns information about
3217 the corresponding line of the window. Otherwise, @var{line} is a text
3218 line number starting from 0. A negative number counts from the end of
3219 the window. The default for @var{line} is the current line in
3220 @var{window}; the default for @var{window} is the selected window.
3221
3222 If the display is not up to date, @code{window-line-height} returns
3223 @code{nil}. In that case, @code{pos-visible-in-window-p} may be used
3224 to obtain related information.
3225
3226 If there is no line corresponding to the specified @var{line},
3227 @code{window-line-height} returns @code{nil}. Otherwise, it returns
3228 a list @code{(@var{height} @var{vpos} @var{ypos} @var{offbot})},
3229 where @var{height} is the height in pixels of the visible part of the
3230 line, @var{vpos} and @var{ypos} are the vertical position in lines and
3231 pixels of the line relative to the top of the first text line, and
3232 @var{offbot} is the number of off-window pixels at the bottom of the
3233 text line. If there are off-window pixels at the top of the (first)
3234 text line, @var{ypos} is negative.
3235 @end defun
3236
3237 @node Textual Scrolling
3238 @section Textual Scrolling
3239 @cindex textual scrolling
3240 @cindex scrolling textually
3241
3242 @dfn{Textual scrolling} means moving the text up or down through a
3243 window. It works by changing the window's display-start location. It
3244 may also change the value of @code{window-point} to keep point on the
3245 screen (@pxref{Window Point}).
3246
3247 The basic textual scrolling functions are @code{scroll-up} (which
3248 scrolls forward) and @code{scroll-down} (which scrolls backward). In
3249 these function names, ``up'' and ``down'' refer to the direction of
3250 motion of the buffer text relative to the window. Imagine that the
3251 text is written on a long roll of paper and that the scrolling
3252 commands move the paper up and down. Thus, if you are looking at the
3253 middle of a buffer and repeatedly call @code{scroll-down}, you will
3254 eventually see the beginning of the buffer.
3255
3256 Unfortunately, this sometimes causes confusion, because some people
3257 tend to think in terms of the opposite convention: they
3258 imagine the window moving over text that remains in place, so that
3259 ``down'' commands take you to the end of the buffer. This convention
3260 is consistent with fact that such a command is bound to a key named
3261 @key{PageDown} on modern keyboards.
3262 @ignore
3263 We have not switched to this convention as that is likely to break
3264 existing Emacs Lisp code.
3265 @end ignore
3266
3267 Textual scrolling functions (aside from @code{scroll-other-window})
3268 have unpredictable results if the current buffer is not the one
3269 displayed in the selected window. @xref{Current Buffer}.
3270
3271 If the window contains a row taller than the height of the window
3272 (for example in the presence of a large image), the scroll functions
3273 will adjust the window's vertical scroll position to scroll the
3274 partially visible row. Lisp callers can disable this feature by
3275 binding the variable @code{auto-window-vscroll} to @code{nil}
3276 (@pxref{Vertical Scrolling}).
3277
3278 @deffn Command scroll-up &optional count
3279 This function scrolls forward by @var{count} lines in the selected
3280 window.
3281
3282 If @var{count} is negative, it scrolls backward instead. If
3283 @var{count} is @code{nil} (or omitted), the distance scrolled is
3284 @code{next-screen-context-lines} lines less than the height of the
3285 window's text area.
3286
3287 If the selected window cannot be scrolled any further, this function
3288 signals an error. Otherwise, it returns @code{nil}.
3289 @end deffn
3290
3291 @deffn Command scroll-down &optional count
3292 This function scrolls backward by @var{count} lines in the selected
3293 window.
3294
3295 If @var{count} is negative, it scrolls forward instead. In other
3296 respects, it behaves the same way as @code{scroll-up} does.
3297 @end deffn
3298
3299 @deffn Command scroll-up-command &optional count
3300 This behaves like @code{scroll-up}, except that if the selected window
3301 cannot be scrolled any further and the value of the variable
3302 @code{scroll-error-top-bottom} is @code{t}, it tries to move to the
3303 end of the buffer instead. If point is already there, it signals an
3304 error.
3305 @end deffn
3306
3307 @deffn Command scroll-down-command &optional count
3308 This behaves like @code{scroll-down}, except that if the selected
3309 window cannot be scrolled any further and the value of the variable
3310 @code{scroll-error-top-bottom} is @code{t}, it tries to move to the
3311 beginning of the buffer instead. If point is already there, it
3312 signals an error.
3313 @end deffn
3314
3315 @deffn Command scroll-other-window &optional count
3316 This function scrolls the text in another window upward @var{count}
3317 lines. Negative values of @var{count}, or @code{nil}, are handled
3318 as in @code{scroll-up}.
3319
3320 You can specify which buffer to scroll by setting the variable
3321 @code{other-window-scroll-buffer} to a buffer. If that buffer isn't
3322 already displayed, @code{scroll-other-window} displays it in some
3323 window.
3324
3325 When the selected window is the minibuffer, the next window is normally
3326 the leftmost one immediately above it. You can specify a different
3327 window to scroll, when the minibuffer is selected, by setting the variable
3328 @code{minibuffer-scroll-window}. This variable has no effect when any
3329 other window is selected. When it is non-@code{nil} and the
3330 minibuffer is selected, it takes precedence over
3331 @code{other-window-scroll-buffer}. @xref{Definition of
3332 minibuffer-scroll-window}.
3333
3334 When the minibuffer is active, it is the next window if the selected
3335 window is the one at the bottom right corner. In this case,
3336 @code{scroll-other-window} attempts to scroll the minibuffer. If the
3337 minibuffer contains just one line, it has nowhere to scroll to, so the
3338 line reappears after the echo area momentarily displays the message
3339 @samp{End of buffer}.
3340 @end deffn
3341
3342 @defvar other-window-scroll-buffer
3343 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
3344 which buffer's window to scroll.
3345 @end defvar
3346
3347 @defopt scroll-margin
3348 This option specifies the size of the scroll margin---a minimum number
3349 of lines between point and the top or bottom of a window. Whenever
3350 point gets within this many lines of the top or bottom of the window,
3351 redisplay scrolls the text automatically (if possible) to move point
3352 out of the margin, closer to the center of the window.
3353 @end defopt
3354
3355 @defopt scroll-conservatively
3356 This variable controls how scrolling is done automatically when point
3357 moves off the screen (or into the scroll margin). If the value is a
3358 positive integer @var{n}, then redisplay scrolls the text up to
3359 @var{n} lines in either direction, if that will bring point back into
3360 proper view. This behavior is called @dfn{conservative scrolling}.
3361 Otherwise, scrolling happens in the usual way, under the control of
3362 other variables such as @code{scroll-up-aggressively} and
3363 @code{scroll-down-aggressively}.
3364
3365 The default value is zero, which means that conservative scrolling
3366 never happens.
3367 @end defopt
3368
3369 @defopt scroll-down-aggressively
3370 The value of this variable should be either @code{nil} or a fraction
3371 @var{f} between 0 and 1. If it is a fraction, that specifies where on
3372 the screen to put point when scrolling down. More precisely, when a
3373 window scrolls down because point is above the window start, the new
3374 start position is chosen to put point @var{f} part of the window
3375 height from the top. The larger @var{f}, the more aggressive the
3376 scrolling.
3377
3378 A value of @code{nil} is equivalent to .5, since its effect is to center
3379 point. This variable automatically becomes buffer-local when set in any
3380 fashion.
3381 @end defopt
3382
3383 @defopt scroll-up-aggressively
3384 Likewise, for scrolling up. The value, @var{f}, specifies how far
3385 point should be placed from the bottom of the window; thus, as with
3386 @code{scroll-up-aggressively}, a larger value scrolls more aggressively.
3387 @end defopt
3388
3389 @defopt scroll-step
3390 This variable is an older variant of @code{scroll-conservatively}.
3391 The difference is that if its value is @var{n}, that permits scrolling
3392 only by precisely @var{n} lines, not a smaller number. This feature
3393 does not work with @code{scroll-margin}. The default value is zero.
3394 @end defopt
3395
3396 @cindex @code{scroll-command} property
3397 @defopt scroll-preserve-screen-position
3398 If this option is @code{t}, whenever a scrolling command moves point
3399 off-window, Emacs tries to adjust point to keep the cursor at its old
3400 vertical position in the window, rather than the window edge.
3401
3402 If the value is non-@code{nil} and not @code{t}, Emacs adjusts point
3403 to keep the cursor at the same vertical position, even if the
3404 scrolling command didn't move point off-window.
3405
3406 This option affects all scroll commands that have a non-@code{nil}
3407 @code{scroll-command} symbol property.
3408 @end defopt
3409
3410 @defopt next-screen-context-lines
3411 The value of this variable is the number of lines of continuity to
3412 retain when scrolling by full screens. For example, @code{scroll-up}
3413 with an argument of @code{nil} scrolls so that this many lines at the
3414 bottom of the window appear instead at the top. The default value is
3415 @code{2}.
3416 @end defopt
3417
3418 @defopt scroll-error-top-bottom
3419 If this option is @code{nil} (the default), @code{scroll-up-command}
3420 and @code{scroll-down-command} simply signal an error when no more
3421 scrolling is possible.
3422
3423 If the value is @code{t}, these commands instead move point to the
3424 beginning or end of the buffer (depending on scrolling direction);
3425 only if point is already on that position do they signal an error.
3426 @end defopt
3427
3428 @deffn Command recenter &optional count
3429 @cindex centering point
3430 This function scrolls the text in the selected window so that point is
3431 displayed at a specified vertical position within the window. It does
3432 not move point with respect to the text.
3433
3434 If @var{count} is a non-negative number, that puts the line containing
3435 point @var{count} lines down from the top of the window. If
3436 @var{count} is a negative number, then it counts upward from the
3437 bottom of the window, so that @minus{}1 stands for the last usable
3438 line in the window.
3439
3440 If @var{count} is @code{nil} (or a non-@code{nil} list),
3441 @code{recenter} puts the line containing point in the middle of the
3442 window. If @var{count} is @code{nil}, this function may redraw the
3443 frame, according to the value of @code{recenter-redisplay}.
3444
3445 When @code{recenter} is called interactively, @var{count} is the raw
3446 prefix argument. Thus, typing @kbd{C-u} as the prefix sets the
3447 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
3448 @var{count} to 4, which positions the current line four lines from the
3449 top.
3450
3451 With an argument of zero, @code{recenter} positions the current line at
3452 the top of the window. The command @code{recenter-top-bottom} offers
3453 a more convenient way to achieve this.
3454 @end deffn
3455
3456 @defopt recenter-redisplay
3457 If this variable is non-@code{nil}, calling @code{recenter} with a
3458 @code{nil} argument redraws the frame. The default value is
3459 @code{tty}, which means only redraw the frame if it is a tty frame.
3460 @end defopt
3461
3462 @deffn Command recenter-top-bottom &optional count
3463 This command, which is the default binding for @kbd{C-l}, acts like
3464 @code{recenter}, except if called with no argument. In that case,
3465 successive calls place point according to the cycling order defined
3466 by the variable @code{recenter-positions}.
3467 @end deffn
3468
3469 @defopt recenter-positions
3470 This variable controls how @code{recenter-top-bottom} behaves when
3471 called with no argument. The default value is @code{(middle top
3472 bottom)}, which means that successive calls of
3473 @code{recenter-top-bottom} with no argument cycle between placing
3474 point at the middle, top, and bottom of the window.
3475 @end defopt
3476
3477
3478 @node Vertical Scrolling
3479 @section Vertical Fractional Scrolling
3480 @cindex vertical fractional scrolling
3481 @cindex vertical scroll position
3482
3483 @dfn{Vertical fractional scrolling} means shifting text in a window
3484 up or down by a specified multiple or fraction of a line. Each window
3485 has a @dfn{vertical scroll position}, which is a number, never less than
3486 zero. It specifies how far to raise the contents of the window.
3487 Raising the window contents generally makes all or part of some lines
3488 disappear off the top, and all or part of some other lines appear at the
3489 bottom. The usual value is zero.
3490
3491 The vertical scroll position is measured in units of the normal line
3492 height, which is the height of the default font. Thus, if the value is
3493 .5, that means the window contents are scrolled up half the normal line
3494 height. If it is 3.3, that means the window contents are scrolled up
3495 somewhat over three times the normal line height.
3496
3497 What fraction of a line the vertical scrolling covers, or how many
3498 lines, depends on what the lines contain. A value of .5 could scroll a
3499 line whose height is very short off the screen, while a value of 3.3
3500 could scroll just part of the way through a tall line or an image.
3501
3502 @defun window-vscroll &optional window pixels-p
3503 This function returns the current vertical scroll position of
3504 @var{window}. The default for @var{window} is the selected window.
3505 If @var{pixels-p} is non-@code{nil}, the return value is measured in
3506 pixels, rather than in units of the normal line height.
3507
3508 @example
3509 @group
3510 (window-vscroll)
3511 @result{} 0
3512 @end group
3513 @end example
3514 @end defun
3515
3516 @defun set-window-vscroll window lines &optional pixels-p
3517 This function sets @var{window}'s vertical scroll position to
3518 @var{lines}. If @var{window} is @code{nil}, the selected window is
3519 used. The argument @var{lines} should be zero or positive; if not, it
3520 is taken as zero.
3521
3522
3523 The actual vertical scroll position must always correspond
3524 to an integral number of pixels, so the value you specify
3525 is rounded accordingly.
3526
3527 The return value is the result of this rounding.
3528
3529 @example
3530 @group
3531 (set-window-vscroll (selected-window) 1.2)
3532 @result{} 1.13
3533 @end group
3534 @end example
3535
3536 If @var{pixels-p} is non-@code{nil}, @var{lines} specifies a number of
3537 pixels. In this case, the return value is @var{lines}.
3538 @end defun
3539
3540 @defvar auto-window-vscroll
3541 If this variable is non-@code{nil}, the @code{line-move},
3542 @code{scroll-up}, and @code{scroll-down} functions will automatically
3543 modify the vertical scroll position to scroll through display rows
3544 that are taller than the height of the window, for example in the
3545 presence of large images.
3546 @end defvar
3547
3548 @node Horizontal Scrolling
3549 @section Horizontal Scrolling
3550 @cindex horizontal scrolling
3551
3552 @dfn{Horizontal scrolling} means shifting the image in the window left
3553 or right by a specified multiple of the normal character width. Each
3554 window has a @dfn{horizontal scroll position}, which is a number, never
3555 less than zero. It specifies how far to shift the contents left.
3556 Shifting the window contents left generally makes all or part of some
3557 characters disappear off the left, and all or part of some other
3558 characters appear at the right. The usual value is zero.
3559
3560 The horizontal scroll position is measured in units of the normal
3561 character width, which is the width of space in the default font. Thus,
3562 if the value is 5, that means the window contents are scrolled left by 5
3563 times the normal character width. How many characters actually
3564 disappear off to the left depends on their width, and could vary from
3565 line to line.
3566
3567 Because we read from side to side in the inner loop, and from top
3568 to bottom in the outer loop, the effect of horizontal scrolling is
3569 not like that of textual or vertical scrolling. Textual scrolling
3570 involves selection of a portion of text to display, and vertical
3571 scrolling moves the window contents contiguously; but horizontal
3572 scrolling causes part of @emph{each line} to go off screen.
3573
3574 Usually, no horizontal scrolling is in effect; then the leftmost
3575 column is at the left edge of the window. In this state, scrolling to
3576 the right is meaningless, since there is no data to the left of the edge
3577 to be revealed by it; so this is not allowed. Scrolling to the left is
3578 allowed; it scrolls the first columns of text off the edge of the window
3579 and can reveal additional columns on the right that were truncated
3580 before. Once a window has a nonzero amount of leftward horizontal
3581 scrolling, you can scroll it back to the right, but only so far as to
3582 reduce the net horizontal scroll to zero. There is no limit to how far
3583 left you can scroll, but eventually all the text will disappear off the
3584 left edge.
3585
3586 @vindex auto-hscroll-mode
3587 If @code{auto-hscroll-mode} is set, redisplay automatically alters
3588 the horizontal scrolling of a window as necessary to ensure that point
3589 is always visible. However, you can still set the horizontal
3590 scrolling value explicitly. The value you specify serves as a lower
3591 bound for automatic scrolling, i.e., automatic scrolling will not
3592 scroll a window to a column less than the specified one.
3593
3594 @deffn Command scroll-left &optional count set-minimum
3595 This function scrolls the selected window @var{count} columns to the
3596 left (or to the right if @var{count} is negative). The default
3597 for @var{count} is the window width, minus 2.
3598
3599 The return value is the total amount of leftward horizontal scrolling in
3600 effect after the change---just like the value returned by
3601 @code{window-hscroll} (below).
3602
3603 Once you scroll a window as far right as it can go, back to its normal
3604 position where the total leftward scrolling is zero, attempts to scroll
3605 any farther right have no effect.
3606
3607 If @var{set-minimum} is non-@code{nil}, the new scroll amount becomes
3608 the lower bound for automatic scrolling; that is, automatic scrolling
3609 will not scroll a window to a column less than the value returned by
3610 this function. Interactive calls pass non-@code{nil} for
3611 @var{set-minimum}.
3612 @end deffn
3613
3614 @deffn Command scroll-right &optional count set-minimum
3615 This function scrolls the selected window @var{count} columns to the
3616 right (or to the left if @var{count} is negative). The default
3617 for @var{count} is the window width, minus 2. Aside from the direction
3618 of scrolling, this works just like @code{scroll-left}.
3619 @end deffn
3620
3621 @defun window-hscroll &optional window
3622 This function returns the total leftward horizontal scrolling of
3623 @var{window}---the number of columns by which the text in @var{window}
3624 is scrolled left past the left margin. The default for
3625 @var{window} is the selected window.
3626
3627 The return value is never negative. It is zero when no horizontal
3628 scrolling has been done in @var{window} (which is usually the case).
3629
3630
3631 @example
3632 @group
3633 (window-hscroll)
3634 @result{} 0
3635 @end group
3636 @group
3637 (scroll-left 5)
3638 @result{} 5
3639 @end group
3640 @group
3641 (window-hscroll)
3642 @result{} 5
3643 @end group
3644 @end example
3645 @end defun
3646
3647 @defun set-window-hscroll window columns
3648 This function sets horizontal scrolling of @var{window}. The value of
3649 @var{columns} specifies the amount of scrolling, in terms of columns
3650 from the left margin. The argument @var{columns} should be zero or
3651 positive; if not, it is taken as zero. Fractional values of
3652 @var{columns} are not supported at present.
3653
3654 Note that @code{set-window-hscroll} may appear not to work if you test
3655 it by evaluating a call with @kbd{M-:} in a simple way. What happens
3656 is that the function sets the horizontal scroll value and returns, but
3657 then redisplay adjusts the horizontal scrolling to make point visible,
3658 and this overrides what the function did. You can observe the
3659 function's effect if you call it while point is sufficiently far from
3660 the left margin that it will remain visible.
3661
3662 The value returned is @var{columns}.
3663
3664 @example
3665 @group
3666 (set-window-hscroll (selected-window) 10)
3667 @result{} 10
3668 @end group
3669 @end example
3670 @end defun
3671
3672 Here is how you can determine whether a given position @var{position}
3673 is off the screen due to horizontal scrolling:
3674
3675 @c FIXME: Maybe hscroll-on-screen-p is a better name?
3676 @example
3677 @group
3678 (defun hscroll-on-screen (window position)
3679 (save-excursion
3680 (goto-char position)
3681 (and
3682 (>= (- (current-column) (window-hscroll window)) 0)
3683 (< (- (current-column) (window-hscroll window))
3684 (window-width window)))))
3685 @end group
3686 @end example
3687
3688
3689 @node Coordinates and Windows
3690 @section Coordinates and Windows
3691 @cindex frame-relative coordinate
3692 @cindex coordinate, relative to frame
3693 @cindex window position
3694
3695 This section describes functions that report the position of a window.
3696 Most of these functions report positions relative to an origin at the
3697 native position of the window's frame (@pxref{Frame Geometry}). Some
3698 functions report positions relative to the origin of the display of the
3699 window's frame. In any case, the origin has the coordinates (0, 0) and
3700 X and Y coordinates increase rightward and downward
3701 respectively.
3702
3703 For the following functions, X and Y coordinates are reported in
3704 integer character units, i.e., numbers of lines and columns
3705 respectively. On a graphical display, each line and column
3706 corresponds to the height and width of a default character specified by
3707 the frame's default font (@pxref{Frame Font}).
3708
3709 @defun window-edges &optional window body absolute pixelwise
3710 This function returns a list of the edge coordinates of @var{window}.
3711 If @var{window} is omitted or @code{nil}, it defaults to the selected
3712 window.
3713
3714 The return value has the form @code{(@var{left} @var{top} @var{right}
3715 @var{bottom})}. These list elements are, respectively, the X
3716 coordinate of the leftmost column occupied by the window, the Y
3717 coordinate of the topmost row, the X coordinate one column to the
3718 right of the rightmost column, and the Y coordinate one row down from
3719 the bottommost row.
3720
3721 Note that these are the actual outer edges of the window, including any
3722 header line, mode line, scroll bar, fringes, window divider and display
3723 margins. On a text terminal, if the window has a neighbor on its right,
3724 its right edge includes the separator line between the window and its
3725 neighbor.
3726
3727 If the optional argument @var{body} is @code{nil}, this means to
3728 return the edges corresponding to the total size of @var{window}.
3729 @var{body} non-@code{nil} means to return the edges of @var{window}'s
3730 body (aka text area). If @var{body} is non-@code{nil}, @var{window}
3731 must specify a live window.
3732
3733 If the optional argument @var{absolute} is @code{nil}, this means to
3734 return edges relative to the native position of @var{window}'s frame.
3735 @var{absolute} non-@code{nil} means to return coordinates relative to
3736 the origin (0, 0) of @var{window}'s display. On non-graphical systems
3737 this argument has no effect.
3738
3739 If the optional argument @var{pixelwise} is @code{nil}, this means to
3740 return the coordinates in terms of the default character width and
3741 height of @var{window}'s frame (@pxref{Frame Font}), rounded if
3742 necessary. @var{pixelwise} non-@code{nil} means to return the
3743 coordinates in pixels. Note that the pixel specified by @var{right} and
3744 @var{bottom} is immediately outside of these edges. If @var{absolute}
3745 is non-@code{nil}, @var{pixelwise} is implicitly non-@code{nil} too.
3746 @end defun
3747
3748 @defun window-body-edges &optional window
3749 This function returns the edges of @var{window}'s body (@pxref{Window
3750 Sizes}). Calling @code{(window-body-edges window)} is equivalent to
3751 calling @code{(window-edges window t)}, see above.
3752 @end defun
3753
3754 @comment The following two functions are confusing and hardly used.
3755 @ignore
3756 @defun window-left-column &optional window
3757 This function returns the leftmost column of @var{window}. This value
3758 equals the @var{left} entry in the list returned by @code{(window-edges
3759 window)} minus the number of columns occupied by the internal border of
3760 @var{window}'s frame.
3761 @end defun
3762
3763 @defun window-top-line &optional window
3764 This function returns the topmost row of @var{window}. This value is
3765 equal to the @var{top} entry in the list returned by @code{(window-edges
3766 window)} minus the number of lines occupied by the internal border of
3767 @var{window}'s frame.
3768 @end defun
3769 @end ignore
3770
3771 The following functions can be used to relate a set of
3772 frame-relative coordinates to a window:
3773
3774 @defun window-at x y &optional frame
3775 This function returns the live window at the coordinates @var{x} and
3776 @var{y} given in default character sizes (@pxref{Frame Font}) relative
3777 to the native position of @var{frame} (@pxref{Frame Geometry}).
3778
3779 If there is no window at that position, the return value is @code{nil}.
3780 If @var{frame} is omitted or @code{nil}, it defaults to the selected
3781 frame.
3782 @end defun
3783
3784 @defun coordinates-in-window-p coordinates window
3785 This function checks whether a window @var{window} occupies the frame
3786 relative coordinates @var{coordinates}, and if so, which part of the
3787 window that is. @var{window} should be a live window.
3788
3789 @var{coordinates} should be a cons cell of the form @code{(@var{x}
3790 . @var{y})}, where @var{x} and @var{y} are given in default character
3791 sizes (@pxref{Frame Font}) relative to the native position of
3792 @var{window}'s frame (@pxref{Frame Geometry}).
3793
3794 If there is no window at the specified position, the return value is
3795 @code{nil} . Otherwise, the return value is one of the following:
3796
3797 @table @code
3798 @item (@var{relx} . @var{rely})
3799 The coordinates are inside @var{window}. The numbers @var{relx} and
3800 @var{rely} are the equivalent window-relative coordinates for the
3801 specified position, counting from 0 at the top left corner of the
3802 window.
3803
3804 @item mode-line
3805 The coordinates are in the mode line of @var{window}.
3806
3807 @item header-line
3808 The coordinates are in the header line of @var{window}.
3809
3810 @item right-divider
3811 The coordinates are in the divider separating @var{window} from a
3812 window on the right.
3813
3814 @item bottom-divider
3815 The coordinates are in the divider separating @var{window} from a
3816 window beneath.
3817
3818 @item vertical-line
3819 The coordinates are in the vertical line between @var{window} and its
3820 neighbor to the right. This value occurs only if the window doesn't
3821 have a scroll bar; positions in a scroll bar are considered outside the
3822 window for these purposes.
3823
3824 @item left-fringe
3825 @itemx right-fringe
3826 The coordinates are in the left or right fringe of the window.
3827
3828 @item left-margin
3829 @itemx right-margin
3830 The coordinates are in the left or right margin of the window.
3831
3832 @item nil
3833 The coordinates are not in any part of @var{window}.
3834 @end table
3835
3836 The function @code{coordinates-in-window-p} does not require a frame as
3837 argument because it always uses the frame that @var{window} is on.
3838 @end defun
3839
3840 The following functions return window positions in pixels, rather
3841 than character units. Though mostly useful on graphical displays,
3842 they can also be called on text terminals, where the screen area of
3843 each text character is taken to be one pixel.
3844
3845 @defun window-pixel-edges &optional window
3846 This function returns a list of pixel coordinates for the edges of
3847 @var{window}. Calling @code{(window-pixel-edges window)} is equivalent
3848 to calling @code{(window-edges window nil nil t)}, see above.
3849 @end defun
3850
3851 @comment The following two functions are confusing and hardly used.
3852 @ignore
3853 @defun window-pixel-left &optional window
3854 This function returns the left pixel edge of window @var{window}. This
3855 value equals the @var{left} entry in the list returned by
3856 @code{(window-pixel-edges window)} minus the number of pixels occupied
3857 by the internal border of @var{window}'s frame. @var{window} must be a
3858 valid window and defaults to the selected one.
3859 @end defun
3860
3861 @defun window-pixel-top &optional window
3862 This function returns the top pixel edge of window @var{window}. This
3863 value is equal to the @var{top} entry in the list returned by
3864 @code{(window-pixel-edges window)} minus the number of pixels occupied
3865 by the internal border of @var{window}'s frame. @var{window} must be a
3866 valid window and defaults to the selected one.
3867 @end defun
3868 @end ignore
3869
3870 @defun window-body-pixel-edges &optional window
3871 This function returns the pixel edges of @var{window}'s body. Calling
3872 @code{(window-body-pixel-edges window)} is equivalent to calling
3873 @code{(window-edges window t nil t)}, see above.
3874 @end defun
3875
3876 The following functions return window positions in pixels, relative to
3877 the origin of the display screen rather than that of the frame:
3878
3879 @defun window-absolute-pixel-edges &optional window
3880 This function returns the pixel coordinates of @var{WINDOW} relative to
3881 an origin at (0, 0) of the display of @var{window}'s frame. Calling
3882 @code{(window-absolute-pixel-edges)} is equivalent to calling
3883 @code{(window-edges window nil t t)}, see above.
3884 @end defun
3885
3886 @defun window-absolute-body-pixel-edges &optional window
3887 This function returns the pixel coordinates of @var{WINDOW}'s body
3888 relative to an origin at (0, 0) of the display of @var{window}'s frame.
3889 Calling @code{(window-absolute-body-pixel-edges window)} is equivalent
3890 to calling @code{(window-edges window t t t)}, see above.
3891
3892 Combined with @code{set-mouse-absolute-pixel-position}, this function
3893 can be used to move the mouse pointer to an arbitrary buffer position
3894 visible in some window:
3895
3896 @example
3897 @group
3898 (let ((edges (window-absolute-body-pixel-edges))
3899 (position (pos-visible-in-window-p nil nil t)))
3900 (x-set-mouse-absolute-pixel-position
3901 (+ (nth 0 edges) (nth 0 position))
3902 (+ (nth 1 edges) (nth 1 position))))
3903 @end group
3904 @end example
3905
3906 On a graphical terminal this form warps the mouse cursor to the
3907 upper left corner of the glyph at the selected window's point. A
3908 position calculated this way can be also used to show a tooltip window
3909 there.
3910 @end defun
3911
3912 The following function returns the screen coordinates of a buffer
3913 position visible in a window:
3914
3915 @defun window-absolute-pixel-position &optional position window
3916 If the buffer position @var{position} is visible in window @var{window},
3917 this function returns the display coordinates of the upper/left corner
3918 of the glyph at @var{position}. The return value is a cons of the X-
3919 and Y-coordinates of that corner, relative to an origin at (0, 0) of
3920 @var{window}'s display. It returns @code{nil} if @var{position} is not
3921 visible in @var{window}.
3922
3923 @var{window} must be a live window and defaults to the selected
3924 window. @var{position} defaults to the value of @code{window-point}
3925 of @var{window}.
3926
3927 This means that in order to move the mouse pointer to the position of
3928 point in the selected window, it's sufficient to write:
3929
3930 @example
3931 @group
3932 (let ((position (window-absolute-pixel-position)))
3933 (set-mouse-absolute-pixel-position
3934 (car position) (cdr position)))
3935 @end group
3936 @end example
3937 @end defun
3938
3939
3940 @node Window Configurations
3941 @section Window Configurations
3942 @cindex window configurations
3943 @cindex saving window information
3944
3945 A @dfn{window configuration} records the entire layout of one
3946 frame---all windows, their sizes, which buffers they contain, how those
3947 buffers are scrolled, and their value of point; also their
3948 fringes, margins, and scroll bar settings. It also includes the value
3949 of @code{minibuffer-scroll-window}. As a special exception, the window
3950 configuration does not record the value of point in the selected window
3951 for the current buffer.
3952
3953 You can bring back an entire frame layout by restoring a previously
3954 saved window configuration. If you want to record the layout of all
3955 frames instead of just one, use a frame configuration instead of a
3956 window configuration. @xref{Frame Configurations}.
3957
3958 @defun current-window-configuration &optional frame
3959 This function returns a new object representing @var{frame}'s current
3960 window configuration. The default for @var{frame} is the selected
3961 frame. The variable @code{window-persistent-parameters} specifies
3962 which window parameters (if any) are saved by this function.
3963 @xref{Window Parameters}.
3964 @end defun
3965
3966 @defun set-window-configuration configuration
3967 This function restores the configuration of windows and buffers as
3968 specified by @var{configuration}, for the frame that @var{configuration}
3969 was created for.
3970
3971 The argument @var{configuration} must be a value that was previously
3972 returned by @code{current-window-configuration}. The configuration is
3973 restored in the frame from which @var{configuration} was made, whether
3974 that frame is selected or not. This always counts as a window size
3975 change and triggers execution of the @code{window-size-change-functions}
3976 (@pxref{Window Hooks}), because @code{set-window-configuration} doesn't
3977 know how to tell whether the new configuration actually differs from the
3978 old one.
3979
3980 If the frame from which @var{configuration} was saved is dead, all this
3981 function does is restore the three variables @code{window-min-height},
3982 @code{window-min-width} and @code{minibuffer-scroll-window}. In this
3983 case, the function returns @code{nil}. Otherwise, it returns @code{t}.
3984
3985 Here is a way of using this function to get the same effect
3986 as @code{save-window-excursion}:
3987
3988 @example
3989 @group
3990 (let ((config (current-window-configuration)))
3991 (unwind-protect
3992 (progn (split-window-below nil)
3993 @dots{})
3994 (set-window-configuration config)))
3995 @end group
3996 @end example
3997 @end defun
3998
3999 @defmac save-window-excursion forms@dots{}
4000 This macro records the window configuration of the selected frame,
4001 executes @var{forms} in sequence, then restores the earlier window
4002 configuration. The return value is the value of the final form in
4003 @var{forms}.
4004
4005 Most Lisp code should not use this macro; @code{save-selected-window}
4006 is typically sufficient. In particular, this macro cannot reliably
4007 prevent the code in @var{forms} from opening new windows, because new
4008 windows might be opened in other frames (@pxref{Choosing Window}), and
4009 @code{save-window-excursion} only saves and restores the window
4010 configuration on the current frame.
4011
4012 Do not use this macro in @code{window-size-change-functions}; exiting
4013 the macro triggers execution of @code{window-size-change-functions},
4014 leading to an endless loop.
4015 @end defmac
4016
4017 @defun window-configuration-p object
4018 This function returns @code{t} if @var{object} is a window configuration.
4019 @end defun
4020
4021 @defun compare-window-configurations config1 config2
4022 This function compares two window configurations as regards the
4023 structure of windows, but ignores the values of point and the
4024 saved scrolling positions---it can return @code{t} even if those
4025 aspects differ.
4026
4027 The function @code{equal} can also compare two window configurations; it
4028 regards configurations as unequal if they differ in any respect, even a
4029 saved point.
4030 @end defun
4031
4032 @defun window-configuration-frame config
4033 This function returns the frame for which the window configuration
4034 @var{config} was made.
4035 @end defun
4036
4037 Other primitives to look inside of window configurations would make
4038 sense, but are not implemented because we did not need them. See the
4039 file @file{winner.el} for some more operations on windows
4040 configurations.
4041
4042 The objects returned by @code{current-window-configuration} die
4043 together with the Emacs process. In order to store a window
4044 configuration on disk and read it back in another Emacs session, you
4045 can use the functions described next. These functions are also useful
4046 to clone the state of a frame into an arbitrary live window
4047 (@code{set-window-configuration} effectively clones the windows of a
4048 frame into the root window of that very frame only).
4049
4050 @cindex window state
4051 @defun window-state-get &optional window writable
4052 This function returns the state of @var{window} as a Lisp object. The
4053 argument @var{window} must be a valid window and defaults to the root
4054 window of the selected frame.
4055
4056 If the optional argument @var{writable} is non-@code{nil}, this means to
4057 not use markers for sampling positions like @code{window-point} or
4058 @code{window-start}. This argument should be non-@code{nil} when the
4059 state will be written to disk and read back in another session.
4060
4061 Together, the argument @var{writable} and the variable
4062 @code{window-persistent-parameters} specify which window parameters are
4063 saved by this function. @xref{Window Parameters}.
4064 @end defun
4065
4066 The value returned by @code{window-state-get} can be used in the same
4067 session to make a clone of a window in another window. It can be also
4068 written to disk and read back in another session. In either case, use
4069 the following function to restore the state of the window.
4070
4071 @defun window-state-put state &optional window ignore
4072 This function puts the window state @var{state} into @var{window}.
4073 The argument @var{state} should be the state of a window returned by
4074 an earlier invocation of @code{window-state-get}, see above. The
4075 optional argument @var{window} can be either a live window or an
4076 internal window (@pxref{Windows and Frames}) and defaults to the
4077 selected one. If @var{window} is not live, it is replaced by a live
4078 window before putting @var{state} into it.
4079
4080 If the optional argument @var{ignore} is non-@code{nil}, it means to ignore
4081 minimum window sizes and fixed-size restrictions. If @var{ignore}
4082 is @code{safe}, this means windows can get as small as one line
4083 and/or two columns.
4084 @end defun
4085
4086
4087 @node Window Parameters
4088 @section Window Parameters
4089 @cindex window parameters
4090
4091 This section describes how window parameters can be used to associate
4092 additional information with windows.
4093
4094 @defun window-parameter window parameter
4095 This function returns @var{window}'s value for @var{parameter}. The
4096 default for @var{window} is the selected window. If @var{window} has no
4097 setting for @var{parameter}, this function returns @code{nil}.
4098 @end defun
4099
4100 @defun window-parameters &optional window
4101 This function returns all parameters of @var{window} and their values.
4102 The default for @var{window} is the selected window. The return value
4103 is either @code{nil}, or an association list whose elements have the form
4104 @code{(@var{parameter} . @var{value})}.
4105 @end defun
4106
4107 @defun set-window-parameter window parameter value
4108 This function sets @var{window}'s value of @var{parameter} to
4109 @var{value} and returns @var{value}. The default for @var{window}
4110 is the selected window.
4111 @end defun
4112
4113 By default, the functions that save and restore window configurations or the
4114 states of windows (@pxref{Window Configurations}) do not care about
4115 window parameters. This means that when you change the value of a
4116 parameter within the body of a @code{save-window-excursion}, the
4117 previous value is not restored when that macro exits. It also means
4118 that when you restore via @code{window-state-put} a window state saved
4119 earlier by @code{window-state-get}, all cloned windows have their
4120 parameters reset to @code{nil}. The following variable allows you to
4121 override the standard behavior:
4122
4123 @defvar window-persistent-parameters
4124 This variable is an alist specifying which parameters get saved by
4125 @code{current-window-configuration} and @code{window-state-get}, and
4126 subsequently restored by @code{set-window-configuration} and
4127 @code{window-state-put}. @xref{Window Configurations}.
4128
4129 The @sc{car} of each entry of this alist is a symbol specifying the
4130 parameter. The @sc{cdr} should be one of the following:
4131
4132 @table @asis
4133 @item @code{nil}
4134 This value means the parameter is saved neither by
4135 @code{window-state-get} nor by @code{current-window-configuration}.
4136
4137 @item @code{t}
4138 This value specifies that the parameter is saved by
4139 @code{current-window-configuration} and (provided its @var{writable}
4140 argument is @code{nil}) by @code{window-state-get}.
4141
4142 @item @code{writable}
4143 This means that the parameter is saved unconditionally by both
4144 @code{current-window-configuration} and @code{window-state-get}. This
4145 value should not be used for parameters whose values do not have a read
4146 syntax. Otherwise, invoking @code{window-state-put} in another session
4147 may fail with an @code{invalid-read-syntax} error.
4148 @end table
4149 @end defvar
4150
4151 Some functions (notably @code{delete-window},
4152 @code{delete-other-windows} and @code{split-window}), may behave specially
4153 when their @var{window} argument has a parameter set. You can override
4154 such special behavior by binding the following variable to a
4155 non-@code{nil} value:
4156
4157 @defvar ignore-window-parameters
4158 If this variable is non-@code{nil}, some standard functions do not
4159 process window parameters. The functions currently affected by this are
4160 @code{split-window}, @code{delete-window}, @code{delete-other-windows},
4161 and @code{other-window}.
4162
4163 An application can bind this variable to a non-@code{nil} value around
4164 calls to these functions. If it does so, the application is fully
4165 responsible for correctly assigning the parameters of all involved
4166 windows when exiting that function.
4167 @end defvar
4168
4169 The following parameters are currently used by the window management
4170 code:
4171
4172 @table @asis
4173 @item @code{delete-window}
4174 This parameter affects the execution of @code{delete-window}
4175 (@pxref{Deleting Windows}).
4176
4177 @item @code{delete-other-windows}
4178 This parameter affects the execution of @code{delete-other-windows}
4179 (@pxref{Deleting Windows}).
4180
4181 @item @code{split-window}
4182 This parameter affects the execution of @code{split-window}
4183 (@pxref{Splitting Windows}).
4184
4185 @item @code{other-window}
4186 This parameter affects the execution of @code{other-window}
4187 (@pxref{Cyclic Window Ordering}).
4188
4189 @item @code{no-other-window}
4190 This parameter marks the window as not selectable by @code{other-window}
4191 (@pxref{Cyclic Window Ordering}).
4192
4193 @item @code{clone-of}
4194 This parameter specifies the window that this one has been cloned
4195 from. It is installed by @code{window-state-get} (@pxref{Window
4196 Configurations}).
4197
4198 @item @code{preserved-size}
4199 This parameter specifies a buffer, a direction where @code{nil} means
4200 vertical and @code{t} horizontal, and a size in pixels. If this window
4201 displays the specified buffer and its size in the indicated direction
4202 equals the size specified by this parameter, then Emacs will try to
4203 preserve the size of this window in the indicated direction. This
4204 parameter is installed and updated by the function
4205 @code{window-preserve-size} (@pxref{Preserving Window Sizes}).
4206
4207 @item @code{quit-restore}
4208 This parameter is installed by the buffer display functions
4209 (@pxref{Choosing Window}) and consulted by @code{quit-restore-window}
4210 (@pxref{Quitting Windows}). It contains four elements:
4211
4212 The first element is one of the symbols @code{window}, meaning that the
4213 window has been specially created by @code{display-buffer}; @code{frame},
4214 a separate frame has been created; @code{same}, the window has
4215 displayed the same buffer before; or @code{other}, the window showed
4216 another buffer before.
4217
4218 The second element is either one of the symbols @code{window} or
4219 @code{frame}, or a list whose elements are the buffer shown in the
4220 window before, that buffer's window start and window point positions,
4221 and the window's height at that time.
4222
4223 The third element is the window selected at the time the parameter was
4224 created. The function @code{quit-restore-window} tries to reselect that
4225 window when it deletes the window passed to it as argument.
4226
4227 The fourth element is the buffer whose display caused the creation of
4228 this parameter. @code{quit-restore-window} deletes the specified window
4229 only if it still shows that buffer.
4230 @end table
4231
4232 There are additional parameters @code{window-atom} and @code{window-side};
4233 these are reserved and should not be used by applications.
4234
4235
4236 @node Window Hooks
4237 @section Hooks for Window Scrolling and Changes
4238 @cindex hooks for window operations
4239
4240 This section describes how a Lisp program can take action whenever a
4241 window displays a different part of its buffer or a different buffer.
4242 There are three actions that can change this: scrolling the window,
4243 switching buffers in the window, and changing the size of the window.
4244 The first two actions run @code{window-scroll-functions}; the last runs
4245 @code{window-size-change-functions}.
4246
4247 @defvar window-scroll-functions
4248 This variable holds a list of functions that Emacs should call before
4249 redisplaying a window with scrolling. Displaying a different buffer in
4250 the window also runs these functions.
4251
4252 This variable is not a normal hook, because each function is called with
4253 two arguments: the window, and its new display-start position.
4254
4255 These functions must take care when using @code{window-end}
4256 (@pxref{Window Start and End}); if you need an up-to-date value, you
4257 must use the @var{update} argument to ensure you get it.
4258
4259 @strong{Warning:} don't use this feature to alter the way the window
4260 is scrolled. It's not designed for that, and such use probably won't
4261 work.
4262 @end defvar
4263
4264 @defvar window-size-change-functions
4265 This variable holds a list of functions to be called if the size of any
4266 window changes for any reason. The functions are called just once per
4267 redisplay, and just once for each frame on which size changes have
4268 occurred.
4269
4270 Each function receives the frame as its sole argument. There is no
4271 direct way to find out which windows on that frame have changed size, or
4272 precisely how. However, if a size-change function records, at each
4273 call, the existing windows and their sizes, it can also compare the
4274 present sizes and the previous sizes.
4275
4276 Creating or deleting windows counts as a size change, and therefore
4277 causes these functions to be called. Changing the frame size also
4278 counts, because it changes the sizes of the existing windows.
4279
4280 You may use @code{save-selected-window} in these functions
4281 (@pxref{Selecting Windows}). However, do not use
4282 @code{save-window-excursion} (@pxref{Window Configurations}); exiting
4283 that macro counts as a size change, which would cause these functions
4284 to be called over and over.
4285 @end defvar
4286
4287 @defvar window-configuration-change-hook
4288 A normal hook that is run every time you change the window configuration
4289 of an existing frame. This includes splitting or deleting windows,
4290 changing the sizes of windows, or displaying a different buffer in a
4291 window.
4292
4293 The buffer-local part of this hook is run once for each window on the
4294 affected frame, with the relevant window selected and its buffer
4295 current. The global part is run once for the modified frame, with that
4296 frame selected.
4297 @end defvar
4298
4299 In addition, you can use @code{jit-lock-register} to register a Font
4300 Lock fontification function, which will be called whenever parts of a
4301 buffer are (re)fontified because a window was scrolled or its size
4302 changed. @xref{Other Font Lock Variables}.