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