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