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