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