Describe frame-auto-hide-function and related issues.
[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 initial 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 accommodate 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 accommodate 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 The argument @var{buffer-or-name} may be a buffer, or the name of an
2080 existing buffer; it defaults to the current buffer.
2081
2082 If a window displaying @var{buffer-or-name} is dedicated
2083 (@pxref{Dedicated Windows}) and is not the only window on its frame,
2084 that window is deleted. If that window is the only window on its frame
2085 and there are other frames on the frame's terminal, that frame is dealt
2086 with by the function spcecified by @code{frame-auto-hide-function}
2087 (@pxref{Quitting Windows}). Otherwise, the buffer provided by the
2088 function @code{switch-to-prev-buffer} (@pxref{Window History}) is
2089 displayed in the window instead.
2090 @end deffn
2091
2092
2093 @node Switching Buffers
2094 @section Switching to a Buffer in a Window
2095 @cindex switching to a buffer
2096 @cindex displaying a buffer
2097
2098 This section describes high-level functions for switching to a
2099 specified buffer in some window.
2100
2101 Do @emph{not} use these functions to make a buffer temporarily
2102 current just so a Lisp program can access or modify it. They have
2103 side-effects, such as changing window histories (@pxref{Window
2104 History}), which will surprise the user if used that way. If you want
2105 to make a buffer current to modify it in Lisp, use
2106 @code{with-current-buffer}, @code{save-current-buffer}, or
2107 @code{set-buffer}. @xref{Current Buffer}.
2108
2109 @deffn Command switch-to-buffer buffer-or-name &optional norecord force-same-window
2110 This function displays @var{buffer-or-name} in the selected window,
2111 and makes it the current buffer. (In contrast, @code{set-buffer}
2112 makes the buffer current but does not display it; @pxref{Current
2113 Buffer}). It is often used interactively (as the binding of @kbd{C-x
2114 b}), as well as in Lisp programs. The return value is the buffer
2115 switched to.
2116
2117 If @var{buffer-or-name} is @code{nil}, it defaults to the buffer
2118 returned by @code{other-buffer} (@pxref{The Buffer List}). If
2119 @var{buffer-or-name} is a string that is not the name of any existing
2120 buffer, this function creates a new buffer with that name; the new
2121 buffer's major mode is determined by the variable @code{major-mode}
2122 (@pxref{Major Modes}).
2123
2124 Normally the specified buffer is put at the front of the buffer
2125 list---both the global buffer list and the selected frame's buffer
2126 list (@pxref{The Buffer List}). However, this is not done if the
2127 optional argument @var{norecord} is non-@code{nil}.
2128
2129 If this function is unable to display the buffer in the selected
2130 window---usually because the selected window is a minibuffer window or
2131 is strongly dedicated to its buffer (@pxref{Dedicated Windows})---then
2132 it normally tries to display the buffer in some other window, in the
2133 manner of @code{pop-to-buffer} (see below). However, if the optional
2134 argument @var{force-same-window} is non-@code{nil}, it signals an error
2135 instead.
2136 @end deffn
2137
2138 The next two functions are similar to @code{switch-to-buffer}, except
2139 for the described features.
2140
2141 @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
2142 This function makes the buffer specified by @var{buffer-or-name}
2143 current and displays it in some window other than the selected window.
2144 It uses the function @code{pop-to-buffer} internally (see below).
2145
2146 If the selected window already displays the specified buffer, it
2147 continues to do so, but another window is nonetheless found to display
2148 it as well.
2149
2150 The @var{buffer-or-name} and @var{norecord} arguments have the same
2151 meanings as in @code{switch-to-buffer}.
2152 @end deffn
2153
2154 @deffn Command switch-to-buffer-other-frame buffer-or-name &optional norecord
2155 This function makes the buffer specified by @var{buffer-or-name}
2156 current and displays it, usually in a new frame. It uses the function
2157 @code{pop-to-buffer} (see below).
2158
2159 If the specified buffer is already displayed in another window, in any
2160 frame on the current terminal, this switches to that window instead of
2161 creating a new frame. However, the selected window is never used for
2162 this.
2163
2164 The @var{buffer-or-name} and @var{norecord} arguments have the same
2165 meanings as in @code{switch-to-buffer}.
2166 @end deffn
2167
2168 The above commands use @code{pop-to-buffer}, which is the function
2169 used by Lisp programs to flexibly display a buffer in some window and
2170 select that window for editing:
2171
2172 @defun pop-to-buffer buffer-or-name &optional action norecord
2173 This function makes @var{buffer-or-name} the current buffer and
2174 displays it in some window, preferably not the window previously
2175 selected. It then selects the displaying window. If that window is
2176 on a different graphical frame, that frame is given input focus if
2177 possible (@pxref{Input Focus}). The return value is the buffer that
2178 was switched to.
2179
2180 This function uses @code{display-buffer} to display the buffer, so all
2181 the variables affecting @code{display-buffer} will affect it as well.
2182 @xref{Choosing Window}.
2183
2184 If @var{buffer-or-name} is @code{nil}, it defaults to the buffer
2185 returned by @code{other-buffer} (@pxref{The Buffer List}). If
2186 @var{buffer-or-name} is a string that is not the name of any existing
2187 buffer, this function creates a new buffer with that name; the new
2188 buffer's major mode is determined by the variable @code{major-mode}
2189 (@pxref{Major Modes}).
2190
2191 If @var{action} is non-@code{nil}, it should be a display action to
2192 pass to @code{display-buffer} (@pxref{Choosing Window}).
2193 Alternatively, a non-@code{nil}, non-list value means to pop to a
2194 window other than the selected one---even if the buffer is already
2195 displayed in the selected window.
2196
2197 Like @code{switch-to-buffer}, this function updates the buffer list
2198 unless @var{norecord} is non-@code{nil}.
2199 @end defun
2200
2201 @node Choosing Window
2202 @section Choosing a Window for Display
2203
2204 The command @code{display-buffer} flexibly chooses a window for
2205 display, and displays a specified buffer in that window. It can be
2206 called interactively, via the key binding @kbd{C-x 4 o}. It is also
2207 used as a subroutine by many functions and commands, including
2208 @code{switch-to-buffer} and @code{pop-to-buffer} (@pxref{Switching
2209 Buffers}).
2210
2211 @cindex display action
2212 @cindex action function, for display-buffer
2213 @cindex action alist, for display-buffer
2214 This command performs several complex steps to find a window to
2215 display in. These steps are described by means of @dfn{display
2216 actions}, which have the form @code{(@var{function} . @var{alist})}.
2217 Here, @var{function} is either a function or a list of functions,
2218 which we refer to as @dfn{action functions}; @var{alist} is an
2219 association list, which we refer to as @dfn{action alists}.
2220
2221 An action function accepts two arguments: the buffer to display and
2222 an action alist. It attempts to display the buffer in some window,
2223 picking or creating a window according to its own criteria. If
2224 successful, it returns the window; otherwise, it returns @code{nil}.
2225 @xref{Display Action Functions}, for a list of predefined action
2226 functions.
2227
2228 @code{display-buffer} works by combining display actions from
2229 several sources, and calling the action functions in turn, until one
2230 of them manages to display the buffer and returns a non-@code{nil}
2231 value.
2232
2233 @deffn Command display-buffer buffer-or-name &optional action frame
2234 This command makes @var{buffer-or-name} appear in some window, without
2235 selecting the window or making the buffer current. The argument
2236 @var{buffer-or-name} must be a buffer or the name of an existing
2237 buffer. The return value is the window chosen to display the buffer.
2238
2239 The optional argument @var{action}, if non-@code{nil}, should normally
2240 be a display action (described above). @code{display-buffer} builds a
2241 list of action functions and an action alist, by consolidating display
2242 actions from the following sources (in order):
2243
2244 @itemize
2245 @item
2246 The variable @code{display-buffer-overriding-action}.
2247
2248 @item
2249 The user option @code{display-buffer-alist}.
2250
2251 @item
2252 The @var{action} argument.
2253
2254 @item
2255 The user option @code{display-buffer-base-action}.
2256
2257 @item
2258 The constant @code{display-buffer-fallback-action}.
2259 @end itemize
2260
2261 @noindent
2262 Each action function is called in turn, passing the buffer as the
2263 first argument and the combined action alist as the second argument,
2264 until one of the functions returns non-nil.
2265
2266 The argument @var{action} can also have a non-@code{nil}, non-list
2267 value. This has the special meaning that the buffer should be
2268 displayed in a window other than the selected one, even if the
2269 selected window is already displaying it. If called interactively
2270 with a prefix argument, @var{action} is @code{t}.
2271
2272 The optional argument @var{frame}, if non-@code{nil}, specifies which
2273 frames to check when deciding whether the buffer is already displayed.
2274 It is equivalent to adding an element @code{(reusable-frames
2275 . @var{frame})} to the action alist of @var{action}. @xref{Display
2276 Action Functions}.
2277 @end deffn
2278
2279 @defvar display-buffer-overriding-action
2280 The value of this variable should be a display action, which is
2281 treated with the highest priority by @code{display-buffer}. The
2282 default value is empty, i.e. @code{(nil . nil)}.
2283 @end defvar
2284
2285 @defopt display-buffer-alist
2286 The value of this option is an alist mapping regular expressions to
2287 display actions. If the name of the buffer passed to
2288 @code{display-buffer} matches a regular expression in this alist, then
2289 @code{display-buffer} uses the corresponding display action.
2290 @end defopt
2291
2292 @defopt display-buffer-base-action
2293 The value of this option should be a display action. This option can
2294 be used to define a ``standard'' display action for calls to
2295 @code{display-buffer}.
2296 @end defopt
2297
2298 @defvr Constant display-buffer-fallback-action
2299 This display action specifies the fallback behavior for
2300 @code{display-buffer} if no other display actions are given.
2301 @end defvr
2302
2303 @node Display Action Functions
2304 @section Action Functions for @code{display-buffer}
2305
2306 The following basic action functions are defined in Emacs. Each of
2307 these functions takes two arguments: @var{buffer}, the buffer to
2308 display, and @var{alist}, an action alist. Each action function
2309 returns the window if it succeeds, and @code{nil} if it fails.
2310
2311 @defun display-buffer-same-window buffer alist
2312 This function tries to display @var{buffer} in the selected window.
2313 It fails if the selected window is a minibuffer window or is dedicated
2314 to another buffer (@pxref{Dedicated Windows}). It also fails if
2315 @var{alist} has a non-nil @code{inhibit-same-window} entry.
2316 @end defun
2317
2318 @defun display-buffer-reuse-window buffer alist
2319 This function tries to ``display'' @var{buffer} by finding a window
2320 that is already displaying it.
2321
2322 If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry,
2323 the selected window is not eligible for reuse.
2324
2325 If @var{alist} contains a @code{reusable-frames} entry, its value
2326 determines which frames to search for a reusable window:
2327
2328 @itemize @bullet
2329 @item
2330 @code{nil} means consider windows on the selected frame.
2331 (Actually, the last non-minibuffer frame.)
2332 @item
2333 @code{t} means consider windows on all frames.
2334 @item
2335 @code{visible} means consider windows on all visible frames.
2336 @item
2337 0 means consider windows on all visible or iconified frames.
2338 @item
2339 A frame means consider windows on that frame only.
2340 @end itemize
2341
2342 If @var{alist} contains no @code{reusable-frames} entry, this function
2343 normally searches just the selected frame; however, if either the
2344 variable @code{display-buffer-reuse-frames} or the variable
2345 @code{pop-up-frames} is non-@code{nil}, it searches all frames on the
2346 current terminal. @xref{Choosing Window Options}.
2347 @end defun
2348
2349 @defun display-buffer-pop-up-frame buffer alist
2350 This function creates a new frame, and displays the buffer in that
2351 frame's window.
2352 @end defun
2353
2354 @defun display-buffer-pop-up-window buffer alist
2355 This function tries to display @var{buffer} by splitting the largest
2356 or least recently-used window. It uses @code{split-window-sensibly}
2357 as a subroutine (@pxref{Choosing Window Options}).
2358 @end defun
2359
2360 @defun display-buffer-use-some-window buffer alist
2361 This function tries to display @var{buffer} by choosing an existing
2362 window and displaying the buffer in that window. It can fail if all
2363 windows are dedicated to another buffer (@pxref{Dedicated Windows}).
2364 @end defun
2365
2366 @node Choosing Window Options
2367 @section Additional Options for Displaying Buffers
2368
2369 The behavior of the standard display actions of @code{display-buffer}
2370 (@pxref{Choosing Window}) can be modified by a variety of user
2371 options.
2372
2373 @defopt display-buffer-reuse-frames
2374 If this variable is non-@code{nil}, @code{display-buffer} searches
2375 visible and iconified frames for a window displaying
2376 @var{buffer-or-name}. If there is such a window, @code{display-buffer}
2377 makes that window's frame visible and raises it if necessary, and
2378 returns the window. If there is no such window or
2379 @code{display-buffer-reuse-frames} is @code{nil}, the behavior of
2380 @code{display-buffer} is determined by the variables described next.
2381 @end defopt
2382
2383 @defopt pop-up-windows
2384 This variable specifies whether @code{display-buffer} is allowed to
2385 split (@pxref{Splitting Windows}) an existing window. If this variable
2386 is non-@code{nil}, @code{display-buffer} tries to split the largest or
2387 least recently used window on the selected frame. (If the selected
2388 frame is a minibuffer-only frame, @code{display-buffer} tries to split a
2389 window on another frame instead.) If this variable is @code{nil} or the
2390 variable @code{pop-up-frames} (see below) is non-@code{nil},
2391 @code{display-buffer} does not split any window.
2392 @end defopt
2393
2394 @defopt split-window-preferred-function
2395 This variable must specify a function with one argument, which is a
2396 window. The @code{display-buffer} routines will call this function with
2397 one or more candidate windows when they look for a window to split. The
2398 function is expected to split that window and return the new window. If
2399 the function returns @code{nil}, this means that the argument window
2400 cannot (or shall not) be split.
2401
2402 The default value of @code{split-window-preferred-function} is the
2403 function @code{split-window-sensibly} described below. If you
2404 customize this option, bear in mind that the @code{display-buffer}
2405 routines may call your function up to two times when trying to split a
2406 window. The argument of the first call is the largest window on the
2407 chosen frame (as returned by @code{get-largest-window}). If that call
2408 fails to return a live window, your function is called a second time
2409 with the least recently used window on that frame (as returned by
2410 @code{get-lru-window}).
2411
2412 The function specified by this option may try to split any other window
2413 instead of the argument window. Note that the window selected at the
2414 time @code{display-buffer} was invoked is still selected when your
2415 function is called. Hence, you can split the selected window (instead
2416 of the largest or least recently used one) by simply ignoring the window
2417 argument in the body of your function. You can even choose to not split
2418 any window as long as the return value of your function specifies a live
2419 window or @code{nil}, but you are not encouraged to do so
2420 unconditionally. If you want @code{display-buffer} to never split any
2421 windows, set @code{pop-up-windows} to @code{nil}.
2422 @end defopt
2423
2424 @defun split-window-sensibly window
2425 This function takes a window as argument and tries to split that window
2426 in a suitable way. The two variables described next are useful for
2427 tuning the behavior of this function.
2428 @end defun
2429
2430 @defopt split-height-threshold
2431 This variable specifies whether @code{split-window-sensibly} may split
2432 windows vertically. If it is an integer, @code{split-window-sensibly}
2433 tries to vertically split a window only if it has at least this many
2434 lines. If the window has less lines, splitting fails, or the value of
2435 this variable is @code{nil}, @code{split-window-sensibly} will try to
2436 split the window horizontally, subject to restrictions of
2437 @code{split-width-threshold} (see below). If splitting horizontally
2438 fails too and the window is the only window on its frame,
2439 @code{split-window-sensibly} will try to split the window vertically
2440 disregarding the value of @code{split-height-threshold}. If this fails
2441 as well, @code{split-window-sensibly} returns @code{nil}.
2442
2443 @code{split-window-sensibly} does not split vertically a window whose
2444 height is fixed (@pxref{Resizing Windows}). Also, it vertically splits
2445 a window only if the space taken up by that window can accommodate two
2446 windows one above the other that are both at least
2447 @code{window-min-height} lines tall. Moreover, if the window that shall
2448 be split has a mode line, @code{split-window-sensibly} does not split
2449 the window unless the new window can accommodate a mode line too.
2450 @end defopt
2451
2452 @defopt split-width-threshold
2453 This variable specifies whether @code{split-window-sensibly} may split
2454 windows horizontally. If it is an integer, @code{split-window-sensibly}
2455 tries to horizontally split a window only if it has at least this many
2456 columns. If it is @code{nil}, @code{split-window-sensibly} will not
2457 split the window horizontally. (It still might split the window
2458 vertically, though, see above.)
2459
2460 @code{split-window-sensibly} does not split horizontally a window if
2461 that window's width is fixed (@pxref{Resizing Windows}). Also, it
2462 horizontally splits a window only if the space that window takes up can
2463 accommodate two windows side by side that are both at least
2464 @code{window-min-width} columns wide.
2465 @end defopt
2466
2467 @defopt even-window-heights
2468 This variable specifies whether @code{display-buffer} should even out
2469 window heights if the buffer gets displayed in an existing window, above
2470 or beneath another window. If @code{even-window-heights} is
2471 non-@code{nil}, the default, window heights will be evened out. If
2472 either of the involved window has fixed height (@pxref{Resizing
2473 Windows}) or @code{even-window-heights} is @code{nil}, the original
2474 window heights will be left alone.
2475 @end defopt
2476
2477 @c Emacs 19 feature
2478 @defopt pop-up-frames
2479 This variable specifies whether @code{display-buffer} should make new
2480 frames. If it is non-@code{nil}, @code{display-buffer} looks for a
2481 window already displaying @var{buffer-or-name} on any visible or
2482 iconified frame. If it finds such a window, it makes that window's
2483 frame visible and raises it if necessary, and returns the window.
2484 Otherwise it makes a new frame, unless the variable's value is
2485 @code{graphic-only} and the selected frame is not on a graphic display.
2486 @xref{Frames}, for more information.
2487
2488 Note that the value of @code{pop-up-windows} does not matter if
2489 @code{pop-up-frames} is non-@code{nil}. If @code{pop-up-frames} is
2490 @code{nil}, then @code{display-buffer} either splits a window or reuses
2491 one.
2492 @end defopt
2493
2494 @c Emacs 19 feature
2495 @defopt pop-up-frame-function
2496 This variable specifies how to make a new frame if @code{pop-up-frames}
2497 is non-@code{nil}.
2498
2499 The value of this variable must be a function of no arguments. When
2500 @code{display-buffer} makes a new frame, it does so by calling that
2501 function, which should return a frame. The default value of this
2502 variable is a function that creates a frame using the parameters
2503 specified by @code{pop-up-frame-alist} described next.
2504 @end defopt
2505
2506 @defopt pop-up-frame-alist
2507 This variable holds an alist specifying frame parameters used by the
2508 default value of @code{pop-up-frame-function} for making new frames.
2509 @xref{Frame Parameters}, for more information about frame parameters.
2510 @end defopt
2511
2512 @defopt special-display-buffer-names
2513 A list of buffer names identifying buffers that should be displayed
2514 specially. If the name of @var{buffer-or-name} is in this list,
2515 @code{display-buffer} handles the buffer specially. By default, special
2516 display means to give the buffer a dedicated frame.
2517
2518 If an element is a list, instead of a string, then the @sc{car} of that
2519 list is the buffer name, and the rest of that list says how to create
2520 the frame. There are two possibilities for the rest of that list (its
2521 @sc{cdr}): It can be an alist, specifying frame parameters, or it can
2522 contain a function and arguments to give to it. (The function's first
2523 argument is always the buffer to be displayed; the arguments from the
2524 list come after that.)
2525
2526 For example:
2527
2528 @example
2529 (("myfile" (minibuffer) (menu-bar-lines . 0)))
2530 @end example
2531
2532 @noindent
2533 specifies to display a buffer named @samp{myfile} in a dedicated frame
2534 with specified @code{minibuffer} and @code{menu-bar-lines} parameters.
2535
2536 The list of frame parameters can also use the phony frame parameters
2537 @code{same-frame} and @code{same-window}. If the specified frame
2538 parameters include @code{(same-window . @var{value})} and @var{value}
2539 is non-@code{nil}, that means to display the buffer in the current
2540 selected window. Otherwise, if they include @code{(same-frame .
2541 @var{value})} and @var{value} is non-@code{nil}, that means to display
2542 the buffer in a new window in the currently selected frame.
2543 @end defopt
2544
2545 @defopt special-display-regexps
2546 A list of regular expressions specifying buffers that should be
2547 displayed specially. If the buffer's name matches any of the regular
2548 expressions in this list, @code{display-buffer} handles the buffer
2549 specially. By default, special display means to give the buffer a
2550 dedicated frame.
2551
2552 If an element is a list, instead of a string, then the @sc{car} of the
2553 list is the regular expression, and the rest of the list says how to
2554 create the frame. See @code{special-display-buffer-names} above.
2555 @end defopt
2556
2557 @defun special-display-p buffer-name
2558 This function returns non-@code{nil} if displaying a buffer
2559 named @var{buffer-name} with @code{display-buffer} would
2560 create a special frame. The value is @code{t} if it would
2561 use the default frame parameters, or else the specified list
2562 of frame parameters.
2563 @end defun
2564
2565 @defopt special-display-function
2566 This variable holds the function to call to display a buffer specially.
2567 It receives the buffer as an argument, and should return the window in
2568 which it is displayed. The default value of this variable is
2569 @code{special-display-popup-frame}, see below.
2570 @end defopt
2571
2572 @defun special-display-popup-frame buffer &optional args
2573 This function tries to make @var{buffer} visible in a frame of its own.
2574 If @var{buffer} is already displayed in some window, it makes that
2575 window's frame visible and raises it. Otherwise, it creates a frame
2576 that is dedicated to @var{buffer}. The return value is the window used
2577 to display @var{buffer}.
2578
2579 If @var{args} is an alist, it specifies frame parameters for the new
2580 frame. If @var{args} is a list whose @sc{car} is a symbol, then
2581 @code{(car @var{args})} is called as a function to actually create and
2582 set up the frame; it is called with @var{buffer} as first argument, and
2583 @code{(cdr @var{args})} as additional arguments.
2584
2585 This function always uses an existing window displaying @var{buffer},
2586 whether or not it is in a frame of its own; but if you set up the above
2587 variables in your init file, before @var{buffer} was created, then
2588 presumably the window was previously made by this function.
2589 @end defun
2590
2591 @defopt special-display-frame-alist
2592 @anchor{Definition of special-display-frame-alist}
2593 This variable holds frame parameters for
2594 @code{special-display-popup-frame} to use when it creates a frame.
2595 @end defopt
2596
2597 @defopt same-window-buffer-names
2598 A list of buffer names for buffers that should be displayed in the
2599 selected window. If the buffer's name is in this list,
2600 @code{display-buffer} handles the buffer by switching to it in the
2601 selected window.
2602 @end defopt
2603
2604 @defopt same-window-regexps
2605 A list of regular expressions that specify buffers that should be
2606 displayed in the selected window. If the buffer's name matches any of
2607 the regular expressions in this list, @code{display-buffer} handles the
2608 buffer by switching to it in the selected window.
2609 @end defopt
2610
2611 @defun same-window-p buffer-name
2612 This function returns @code{t} if displaying a buffer
2613 named @var{buffer-name} with @code{display-buffer} would
2614 put it in the selected window.
2615 @end defun
2616
2617 @c Emacs 19 feature
2618 @defopt display-buffer-function
2619 This variable is the most flexible way to customize the behavior of
2620 @code{display-buffer}. If it is non-@code{nil}, it should be a function
2621 that @code{display-buffer} calls to do the work. The function should
2622 accept two arguments, the first two arguments that @code{display-buffer}
2623 received. It should choose or create a window, display the specified
2624 buffer in it, and then return the window.
2625
2626 This variable takes precedence over all the other options described
2627 above.
2628 @end defopt
2629
2630 If all options described above fail to produce a suitable window,
2631 @code{display-buffer} tries to reuse an existing window. As a last
2632 resort, it will try to display @var{buffer-or-name} on a separate frame.
2633 In that case, the value of @code{pop-up-frames} is disregarded.
2634
2635
2636 @node Window History
2637 @section Window History
2638 @cindex window history
2639
2640 Each window remembers the buffers it has displayed earlier and the order
2641 in which these buffers have been removed from it. This history is used,
2642 for example, by @code{replace-buffer-in-windows} (@pxref{Buffers and
2643 Windows}). This list is automatically maintained by Emacs, but you can
2644 use the following functions to explicitly inspect or alter it:
2645
2646 @defun window-prev-buffers &optional window
2647 This function returns a list specifying the previous contents of
2648 @var{window}, which should be a live window and defaults to the
2649 selected window.
2650
2651 Each list element has the form @code{(@var{buffer} @var{window-start}
2652 @var{window-pos})}, where @var{buffer} is a buffer previously shown in
2653 the window, @var{window-start} is the window start position when that
2654 buffer was last shown, and @var{window-pos} is the point position when
2655 that buffer was last shown.
2656
2657 The list is ordered so that earlier elements correspond to more
2658 recently-shown buffers, and the first element usually corresponds to the
2659 buffer most recently removed from the window.
2660 @end defun
2661
2662 @defun set-window-prev-buffers window prev-buffers
2663 This function sets @var{window}'s previous buffers to the value of
2664 @var{prev-buffers}. The argument @var{window} must be a live window
2665 and defaults to the selected one. The argument @var{prev-buffers}
2666 should be a list of the same form as that returned by
2667 @code{window-prev-buffers}.
2668 @end defun
2669
2670 In addition, each buffer maintains a list of @dfn{next buffers}, which
2671 is a list of buffers re-shown by @code{switch-to-prev-buffer} (see
2672 below). This list is mainly used by @code{switch-to-prev-buffer} and
2673 @code{switch-to-next-buffer} for choosing buffers to switch to.
2674
2675 @defun window-next-buffers &optional window
2676 This function returns the list of buffers recently re-shown in
2677 @var{window} via @code{switch-to-prev-buffer}. The @var{window}
2678 argument must denote a live window or @code{nil} (meaning the selected
2679 window).
2680 @end defun
2681
2682 @defun set-window-next-buffers window next-buffers
2683 This function sets the next buffer list of @var{window} to
2684 @var{next-buffers}. The @var{window} argument should be a live window
2685 or @code{nil} (meaning the selected window). The argument
2686 @var{next-buffers} should be a list of buffers.
2687 @end defun
2688
2689 The following commands can be used to cycle through the global buffer
2690 list, much like @code{bury-buffer} and @code{unbury-buffer}. However,
2691 they cycle according to the specified window's history list, rather
2692 than the global buffer list. In addition, they restore
2693 window-specific window start and point positions, and may show a
2694 buffer even if it is already shown in another window. The
2695 @code{switch-to-prev-buffer} command, in particular, is used by
2696 @code{replace-buffer-in-windows}, @code{bury-buffer} and
2697 @code{quit-window} to find a replacement buffer for a window.
2698
2699 @deffn Command switch-to-prev-buffer &optional window bury-or-kill
2700 This command displays the previous buffer in @var{window}. The
2701 argument @var{window} should be a live window or @code{nil} (meaning
2702 the selected window). If the optional argument @var{bury-or-kill} is
2703 non-@code{nil}, this means that the buffer currently shown in
2704 @var{window} is about to be buried or killed and consequently shall
2705 not be switched to in future invocations of this command.
2706
2707 The previous buffer is usually the buffer shown before the buffer
2708 currently shown in @var{window}. However, a buffer that has been buried
2709 or killed or has been already shown by a recent invocation of
2710 @code{switch-to-prev-buffer} does not qualify as previous buffer.
2711
2712 If repeated invocations of this command have already shown all buffers
2713 previously shown in @var{window}, further invocations will show buffers
2714 from the buffer list of the frame @var{window} appears on (@pxref{The
2715 Buffer List}).
2716 @end deffn
2717
2718 @deffn Command switch-to-next-buffer &optional window
2719 This command switches to the next buffer in @var{window} thus undoing
2720 the effect of the last @code{switch-to-prev-buffer} command in
2721 @var{window}. The argument @var{window} must be a live window and
2722 defaults to the selected one.
2723
2724 If there is no recent invocation of a @code{switch-to-prev-buffer} that
2725 can be undone, this function tries to show a buffer from the buffer list
2726 of the frame @var{window} appears on (@pxref{The Buffer List}).
2727 @end deffn
2728
2729
2730 @node Dedicated Windows
2731 @section Dedicated Windows
2732 @cindex dedicated window
2733
2734 Functions for displaying a buffer can be told to not use specific
2735 windows by marking these windows as @dfn{dedicated} to their buffers.
2736 @code{display-buffer} (@pxref{Choosing Window}) never uses a dedicated
2737 window for displaying another buffer in it. @code{get-lru-window} and
2738 @code{get-largest-window} (@pxref{Selecting Windows}) do not consider
2739 dedicated windows as candidates when their @var{dedicated} argument is
2740 non-@code{nil}. The behavior of @code{set-window-buffer}
2741 (@pxref{Buffers and Windows}) with respect to dedicated windows is
2742 slightly different, see below.
2743
2744 When @code{delete-windows-on} (@pxref{Deleting Windows}) wants to
2745 delete a dedicated window and that window is the only window on its
2746 frame, it deletes the window's frame too, provided there are other
2747 frames left. @code{replace-buffer-in-windows} (@pxref{Switching
2748 Buffers}) tries to delete all dedicated windows showing its buffer
2749 argument. When such a window is the only window on its frame, that
2750 frame is deleted, provided there are other frames left. If there are
2751 no more frames left, some other buffer is displayed in the window, and
2752 the window is marked as non-dedicated.
2753
2754 When you kill a buffer (@pxref{Killing Buffers}) displayed in a
2755 dedicated window, any such window usually gets deleted too, since
2756 @code{kill-buffer} calls @code{replace-buffer-in-windows} for cleaning
2757 up windows. Burying a buffer (@pxref{The Buffer List}) deletes the
2758 selected window if it is dedicated to that buffer. If, however, that
2759 window is the only window on its frame, @code{bury-buffer} displays
2760 another buffer in it and iconifies the frame.
2761
2762 @defun window-dedicated-p &optional window
2763 This function returns non-@code{nil} if @var{window} is dedicated to its
2764 buffer and @code{nil} otherwise. More precisely, the return value is
2765 the value assigned by the last call of @code{set-window-dedicated-p} for
2766 @var{window} or @code{nil} if that function was never called with
2767 @var{window} as its argument. The default for @var{window} is the
2768 selected window.
2769 @end defun
2770
2771 @defun set-window-dedicated-p window flag
2772 This function marks @var{window} as dedicated to its buffer if
2773 @var{flag} is non-@code{nil}, and non-dedicated otherwise.
2774
2775 As a special case, if @var{flag} is @code{t}, @var{window} becomes
2776 @dfn{strongly} dedicated to its buffer. @code{set-window-buffer}
2777 signals an error when the window it acts upon is strongly dedicated to
2778 its buffer and does not already display the buffer it is asked to
2779 display. Other functions do not treat @code{t} differently from any
2780 non-@code{nil} value.
2781 @end defun
2782
2783
2784 @node Quitting Windows
2785 @section Quitting Windows
2786
2787 When you want to get rid of a window used for displaying a buffer you
2788 can call @code{delete-window} or @code{delete-windows-on}
2789 (@pxref{Deleting Windows}) to remove that window from its frame. If the
2790 buffer is shown on a separate frame, you might want to call
2791 @code{delete-frame} (@pxref{Deleting Frames}) instead. If, on the other
2792 hand, a window has been reused for displaying the buffer, you might
2793 prefer showing the buffer previously shown in that window by calling the
2794 function @code{switch-to-prev-buffer} (@pxref{Window History}).
2795 Finally, you might want to either bury (@pxref{The Buffer List}) or kill
2796 (@pxref{Killing Buffers}) the window's buffer.
2797
2798 The following function uses information on how the window for
2799 displaying the buffer was obtained in the first place thus attempting to
2800 automatize the above decisions for you.
2801
2802 @deffn Command quit-window &optional kill window
2803 This command quits @var{window} and buries its buffer. The argument
2804 @var{window} must be a live window and defaults to the selected one.
2805 With prefix argument @var{kill} non-@code{nil}, it kills the buffer
2806 instead of burying it.
2807
2808 Quitting @var{window} means to proceed as follows: If @var{window} was
2809 created specially for displaying its current buffer, delete @var{window}
2810 provided its frame contains at least one other live window. If
2811 @var{window} is the only window on its frame and there are other frames
2812 on the frame's terminal, the value of @var{kill} determines how to
2813 proceed with the window. If @var{kill} is @code{nil}, the fate of the
2814 frame is determined by calling @code{frame-auto-hide-function} (see
2815 below) with that frame as sole argument. If @var{kill} is
2816 non-@code{nil}, the frame is deleted unconditionally.
2817
2818 If @var{window} was reused for displaying its buffer, this command tries
2819 to display the buffer previously shown in it. It also tries to restore
2820 the window start (@pxref{Window Start and End}) and point (@pxref{Window
2821 Point}) positions of the previously shown buffer. If, in addition, the
2822 current buffer was temporarily resized, this command will also try to
2823 restore the original height of @var{window}.
2824
2825 The three cases described so far require that the buffer shown in
2826 @var{window} is still the buffer displayed by the last buffer display
2827 function for this window. If another buffer has been shown in the
2828 meantime or the buffer previously shown no longer exists, this command
2829 calls @code{switch-to-prev-buffer} (@pxref{Window History}) to show some
2830 other buffer instead.
2831 @end deffn
2832
2833 The function @code{quit-window} bases its decisions on information
2834 stored in @var{window}'s @code{quit-restore} window parameter
2835 (@pxref{Window Parameters}) and resets that parameter to @code{nil}
2836 after it's done.
2837
2838 The following option specifies how to deal with a frame containing just
2839 one window that shall be either quit or whose buffer shall be buried.
2840
2841 @defopt frame-auto-hide-function
2842 The function specified by this option is called to automatically hide
2843 frames. This function is called with one argument - a frame.
2844
2845 The function specified here is called by @code{bury-buffer} (@pxref{The
2846 Buffer List}) when the selected window is dedicated and shows the buffer
2847 that shall be buried. It is also called by @code{quit-window} (see
2848 above) when the frame of the window that shall be quit has been
2849 specially created for displaying that window's buffer and the buffer
2850 shall be buried.
2851
2852 The default is to call @code{iconify-frame} (@pxref{Visibility of
2853 Frames}). Alternatively, you may either specify @code{delete-frame}
2854 (@pxref{Deleting Frames}) to remove the frame from its display,
2855 @code{ignore} to leave the frame unchanged, or any other function that
2856 can take a frame as its sole argument.
2857
2858 Note that the function specified by this option is called if and only if
2859 there's at least one other frame on the terminal of the frame it's
2860 supposed to handle and that frame contains only one live window.
2861 @end defopt
2862
2863
2864 @node Window Point
2865 @section Windows and Point
2866 @cindex window position
2867 @cindex window point
2868 @cindex position in window
2869 @cindex point in window
2870
2871 Each window has its own value of point (@pxref{Point}), independent of
2872 the value of point in other windows displaying the same buffer. This
2873 makes it useful to have multiple windows showing one buffer.
2874
2875 @itemize @bullet
2876 @item
2877 The window point is established when a window is first created; it is
2878 initialized from the buffer's point, or from the window point of another
2879 window opened on the buffer if such a window exists.
2880
2881 @item
2882 Selecting a window sets the value of point in its buffer from the
2883 window's value of point. Conversely, deselecting a window sets the
2884 window's value of point from that of the buffer. Thus, when you switch
2885 between windows that display a given buffer, the point value for the
2886 selected window is in effect in the buffer, while the point values for
2887 the other windows are stored in those windows.
2888
2889 @item
2890 As long as the selected window displays the current buffer, the window's
2891 point and the buffer's point always move together; they remain equal.
2892 @end itemize
2893
2894 @cindex cursor
2895 As far as the user is concerned, point is where the cursor is, and
2896 when the user switches to another buffer, the cursor jumps to the
2897 position of point in that buffer.
2898
2899 @defun window-point &optional window
2900 This function returns the current position of point in @var{window}.
2901 For a nonselected window, this is the value point would have (in that
2902 window's buffer) if that window were selected. The default for
2903 @var{window} is the selected window.
2904
2905 When @var{window} is the selected window and its buffer is also the
2906 current buffer, the value returned is the same as point in that buffer.
2907 Strictly speaking, it would be more correct to return the ``top-level''
2908 value of point, outside of any @code{save-excursion} forms. But that
2909 value is hard to find.
2910 @end defun
2911
2912 @defun set-window-point window position
2913 This function positions point in @var{window} at position
2914 @var{position} in @var{window}'s buffer. It returns @var{position}.
2915
2916 If @var{window} is selected, and its buffer is current,
2917 this simply does @code{goto-char}.
2918 @end defun
2919
2920 @defvar window-point-insertion-type
2921 This variable specifies the marker insertion type (@pxref{Marker
2922 Insertion Types}) of @code{window-point}. The default is @code{nil},
2923 so @code{window-point} will stay behind text inserted there.
2924 @end defvar
2925
2926 @node Window Start and End
2927 @section The Window Start and End Positions
2928 @cindex window start position
2929
2930 Each window maintains a marker used to keep track of a buffer position
2931 that specifies where in the buffer display should start. This position
2932 is called the @dfn{display-start} position of the window (or just the
2933 @dfn{start}). The character after this position is the one that appears
2934 at the upper left corner of the window. It is usually, but not
2935 inevitably, at the beginning of a text line.
2936
2937 After switching windows or buffers, and in some other cases, if the
2938 window start is in the middle of a line, Emacs adjusts the window
2939 start to the start of a line. This prevents certain operations from
2940 leaving the window start at a meaningless point within a line. This
2941 feature may interfere with testing some Lisp code by executing it
2942 using the commands of Lisp mode, because they trigger this
2943 readjustment. To test such code, put it into a command and bind the
2944 command to a key.
2945
2946 @defun window-start &optional window
2947 @cindex window top line
2948 This function returns the display-start position of window
2949 @var{window}. If @var{window} is @code{nil}, the selected window is
2950 used. For example,
2951
2952 @example
2953 @group
2954 (window-start)
2955 @result{} 7058
2956 @end group
2957 @end example
2958
2959 When you create a window, or display a different buffer in it, the
2960 display-start position is set to a display-start position recently used
2961 for the same buffer, or to @code{point-min} if the buffer doesn't have
2962 any.
2963
2964 Redisplay updates the window-start position (if you have not specified
2965 it explicitly since the previous redisplay)---to make sure point appears
2966 on the screen. Nothing except redisplay automatically changes the
2967 window-start position; if you move point, do not expect the window-start
2968 position to change in response until after the next redisplay.
2969
2970 For a realistic example of using @code{window-start}, see the
2971 description of @code{count-lines}. @xref{Definition of count-lines}.
2972 @end defun
2973
2974 @cindex window end position
2975 @defun window-end &optional window update
2976 This function returns the position where display of its buffer ends in
2977 @var{window}. The default for @var{window} is the selected window.
2978
2979 Simply changing the buffer text or moving point does not update the
2980 value that @code{window-end} returns. The value is updated only when
2981 Emacs redisplays and redisplay completes without being preempted.
2982
2983 If the last redisplay of @var{window} was preempted, and did not finish,
2984 Emacs does not know the position of the end of display in that window.
2985 In that case, this function returns @code{nil}.
2986
2987 If @var{update} is non-@code{nil}, @code{window-end} always returns an
2988 up-to-date value for where display ends, based on the current
2989 @code{window-start} value. If a previously saved value of that position
2990 is still valid, @code{window-end} returns that value; otherwise it
2991 computes the correct value by scanning the buffer text.
2992
2993 Even if @var{update} is non-@code{nil}, @code{window-end} does not
2994 attempt to scroll the display if point has moved off the screen, the
2995 way real redisplay would do. It does not alter the
2996 @code{window-start} value. In effect, it reports where the displayed
2997 text will end if scrolling is not required.
2998 @end defun
2999
3000 @defun set-window-start window position &optional noforce
3001 This function sets the display-start position of @var{window} to
3002 @var{position} in @var{window}'s buffer. It returns @var{position}.
3003
3004 The display routines insist that the position of point be visible when a
3005 buffer is displayed. Normally, they change the display-start position
3006 (that is, scroll the window) whenever necessary to make point visible.
3007 However, if you specify the start position with this function using
3008 @code{nil} for @var{noforce}, it means you want display to start at
3009 @var{position} even if that would put the location of point off the
3010 screen. If this does place point off screen, the display routines move
3011 point to the left margin on the middle line in the window.
3012
3013 For example, if point @w{is 1} and you set the start of the window
3014 @w{to 37}, the start of the next line, point will be ``above'' the top
3015 of the window. The display routines will automatically move point if
3016 it is still 1 when redisplay occurs. Here is an example:
3017
3018 @example
3019 @group
3020 ;; @r{Here is what @samp{foo} looks like before executing}
3021 ;; @r{the @code{set-window-start} expression.}
3022 @end group
3023
3024 @group
3025 ---------- Buffer: foo ----------
3026 @point{}This is the contents of buffer foo.
3027 2
3028 3
3029 4
3030 5
3031 6
3032 ---------- Buffer: foo ----------
3033 @end group
3034
3035 @group
3036 (set-window-start
3037 (selected-window)
3038 (save-excursion
3039 (goto-char 1)
3040 (forward-line 1)
3041 (point)))
3042 @result{} 37
3043 @end group
3044
3045 @group
3046 ;; @r{Here is what @samp{foo} looks like after executing}
3047 ;; @r{the @code{set-window-start} expression.}
3048 ---------- Buffer: foo ----------
3049 2
3050 3
3051 @point{}4
3052 5
3053 6
3054 ---------- Buffer: foo ----------
3055 @end group
3056 @end example
3057
3058 If @var{noforce} is non-@code{nil}, and @var{position} would place point
3059 off screen at the next redisplay, then redisplay computes a new window-start
3060 position that works well with point, and thus @var{position} is not used.
3061 @end defun
3062
3063 @defun pos-visible-in-window-p &optional position window partially
3064 This function returns non-@code{nil} if @var{position} is within the
3065 range of text currently visible on the screen in @var{window}. It
3066 returns @code{nil} if @var{position} is scrolled vertically out of view.
3067 Locations that are partially obscured are not considered visible unless
3068 @var{partially} is non-@code{nil}. The argument @var{position} defaults
3069 to the current position of point in @var{window}; @var{window}, to the
3070 selected window. If @var{position} is @code{t}, that means to check the
3071 last visible position in @var{window}.
3072
3073 This function considers only vertical scrolling. If @var{position} is
3074 out of view only because @var{window} has been scrolled horizontally,
3075 @code{pos-visible-in-window-p} returns non-@code{nil} anyway.
3076 @xref{Horizontal Scrolling}.
3077
3078 If @var{position} is visible, @code{pos-visible-in-window-p} returns
3079 @code{t} if @var{partially} is @code{nil}; if @var{partially} is
3080 non-@code{nil}, and the character following @var{position} is fully
3081 visible, it returns a list of the form @code{(@var{x} @var{y})}, where
3082 @var{x} and @var{y} are the pixel coordinates relative to the top left
3083 corner of the window; otherwise it returns an extended list of the form
3084 @code{(@var{x} @var{y} @var{rtop} @var{rbot} @var{rowh} @var{vpos})},
3085 where @var{rtop} and @var{rbot} specify the number of off-window pixels
3086 at the top and bottom of the row at @var{position}, @var{rowh} specifies
3087 the visible height of that row, and @var{vpos} specifies the vertical
3088 position (zero-based row number) of that row.
3089
3090 Here is an example:
3091
3092 @example
3093 @group
3094 ;; @r{If point is off the screen now, recenter it now.}
3095 (or (pos-visible-in-window-p
3096 (point) (selected-window))
3097 (recenter 0))
3098 @end group
3099 @end example
3100 @end defun
3101
3102 @defun window-line-height &optional line window
3103 This function returns the height of text line @var{line} in
3104 @var{window}. If @var{line} is one of @code{header-line} or
3105 @code{mode-line}, @code{window-line-height} returns information about
3106 the corresponding line of the window. Otherwise, @var{line} is a text
3107 line number starting from 0. A negative number counts from the end of
3108 the window. The default for @var{line} is the current line in
3109 @var{window}; the default for @var{window} is the selected window.
3110
3111 If the display is not up to date, @code{window-line-height} returns
3112 @code{nil}. In that case, @code{pos-visible-in-window-p} may be used
3113 to obtain related information.
3114
3115 If there is no line corresponding to the specified @var{line},
3116 @code{window-line-height} returns @code{nil}. Otherwise, it returns
3117 a list @code{(@var{height} @var{vpos} @var{ypos} @var{offbot})},
3118 where @var{height} is the height in pixels of the visible part of the
3119 line, @var{vpos} and @var{ypos} are the vertical position in lines and
3120 pixels of the line relative to the top of the first text line, and
3121 @var{offbot} is the number of off-window pixels at the bottom of the
3122 text line. If there are off-window pixels at the top of the (first)
3123 text line, @var{ypos} is negative.
3124 @end defun
3125
3126 @node Textual Scrolling
3127 @section Textual Scrolling
3128 @cindex textual scrolling
3129 @cindex scrolling textually
3130
3131 @dfn{Textual scrolling} means moving the text up or down through a
3132 window. It works by changing the window's display-start location. It
3133 may also change the value of @code{window-point} to keep point on the
3134 screen (@pxref{Window Point}).
3135
3136 The basic textual scrolling functions are @code{scroll-up} (which
3137 scrolls forward) and @code{scroll-down} (which scrolls backward). In
3138 these function names, ``up'' and ``down'' refer to the direction of
3139 motion of the buffer text relative to the window. Imagine that the
3140 text is written on a long roll of paper and that the scrolling
3141 commands move the paper up and down. Thus, if you are looking at the
3142 middle of a buffer and repeatedly call @code{scroll-down}, you will
3143 eventually see the beginning of the buffer.
3144
3145 Some people have urged that the opposite convention be used: they
3146 imagine the window moving over text that remains in place, so that
3147 ``down'' commands take you to the end of the buffer. This convention
3148 is consistent with fact that such a command is bound to a key named
3149 @key{PageDown} on modern keyboards. We have not switched to this
3150 convention as that is likely to break existing Emacs Lisp code.
3151
3152 Textual scrolling functions (aside from @code{scroll-other-window})
3153 have unpredictable results if the current buffer is not the one
3154 displayed in the selected window. @xref{Current Buffer}.
3155
3156 If the window contains a row taller than the height of the window
3157 (for example in the presence of a large image), the scroll functions
3158 will adjust the window's vertical scroll position to scroll the
3159 partially visible row. Lisp callers can disable this feature by
3160 binding the variable @code{auto-window-vscroll} to @code{nil}
3161 (@pxref{Vertical Scrolling}).
3162
3163 @deffn Command scroll-up &optional count
3164 This function scrolls forward by @var{count} lines in the selected
3165 window.
3166
3167 If @var{count} is negative, it scrolls backward instead. If
3168 @var{count} is @code{nil} (or omitted), the distance scrolled is
3169 @code{next-screen-context-lines} lines less than the height of the
3170 window's text area.
3171
3172 If the selected window cannot be scrolled any further, this function
3173 signals an error. Otherwise, it returns @code{nil}.
3174 @end deffn
3175
3176 @deffn Command scroll-down &optional count
3177 This function scrolls backward by @var{count} lines in the selected
3178 window.
3179
3180 If @var{count} is negative, it scrolls forward instead. If
3181 @var{count} is omitted or @code{nil}, the distance scrolled is
3182 @code{next-screen-context-lines} lines less than the height of the
3183 window's text area.
3184
3185 If the selected window cannot be scrolled any further, this function
3186 signals an error. Otherwise, it returns @code{nil}.
3187 @end deffn
3188
3189 @deffn Command scroll-up-command &optional count
3190 This behaves like @code{scroll-up}, except that if the selected window
3191 cannot be scrolled any further and the value of the variable
3192 @code{scroll-error-top-bottom} is @code{t}, it tries to move to the
3193 end of the buffer instead. If point is already there, it signals an
3194 error.
3195 @end deffn
3196
3197 @deffn Command scroll-down-command &optional count
3198 This behaves like @code{scroll-down}, except that if the selected
3199 window cannot be scrolled any further and the value of the variable
3200 @code{scroll-error-top-bottom} is @code{t}, it tries to move to the
3201 beginning of the buffer instead. If point is already there, it
3202 signals an error.
3203 @end deffn
3204
3205 @deffn Command scroll-other-window &optional count
3206 This function scrolls the text in another window upward @var{count}
3207 lines. Negative values of @var{count}, or @code{nil}, are handled
3208 as in @code{scroll-up}.
3209
3210 You can specify which buffer to scroll by setting the variable
3211 @code{other-window-scroll-buffer} to a buffer. If that buffer isn't
3212 already displayed, @code{scroll-other-window} displays it in some
3213 window.
3214
3215 When the selected window is the minibuffer, the next window is normally
3216 the one at the top left corner. You can specify a different window to
3217 scroll, when the minibuffer is selected, by setting the variable
3218 @code{minibuffer-scroll-window}. This variable has no effect when any
3219 other window is selected. When it is non-@code{nil} and the
3220 minibuffer is selected, it takes precedence over
3221 @code{other-window-scroll-buffer}. @xref{Definition of
3222 minibuffer-scroll-window}.
3223
3224 When the minibuffer is active, it is the next window if the selected
3225 window is the one at the bottom right corner. In this case,
3226 @code{scroll-other-window} attempts to scroll the minibuffer. If the
3227 minibuffer contains just one line, it has nowhere to scroll to, so the
3228 line reappears after the echo area momentarily displays the message
3229 @samp{Beginning of buffer}.
3230 @end deffn
3231
3232 @defvar other-window-scroll-buffer
3233 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
3234 which buffer's window to scroll.
3235 @end defvar
3236
3237 @defopt scroll-margin
3238 This option specifies the size of the scroll margin---a minimum number
3239 of lines between point and the top or bottom of a window. Whenever
3240 point gets within this many lines of the top or bottom of the window,
3241 redisplay scrolls the text automatically (if possible) to move point
3242 out of the margin, closer to the center of the window.
3243 @end defopt
3244
3245 @defopt scroll-conservatively
3246 This variable controls how scrolling is done automatically when point
3247 moves off the screen (or into the scroll margin). If the value is a
3248 positive integer @var{n}, then redisplay scrolls the text up to
3249 @var{n} lines in either direction, if that will bring point back into
3250 proper view. This behavior is called @dfn{conservative scrolling}.
3251 Otherwise, scrolling happens in the usual way, under the control of
3252 other variables such as @code{scroll-up-aggressively} and
3253 @code{scroll-down-aggressively}.
3254
3255 The default value is zero, which means that conservative scrolling
3256 never happens.
3257 @end defopt
3258
3259 @defopt scroll-down-aggressively
3260 The value of this variable should be either @code{nil} or a fraction
3261 @var{f} between 0 and 1. If it is a fraction, that specifies where on
3262 the screen to put point when scrolling down. More precisely, when a
3263 window scrolls down because point is above the window start, the new
3264 start position is chosen to put point @var{f} part of the window
3265 height from the top. The larger @var{f}, the more aggressive the
3266 scrolling.
3267
3268 A value of @code{nil} is equivalent to .5, since its effect is to center
3269 point. This variable automatically becomes buffer-local when set in any
3270 fashion.
3271 @end defopt
3272
3273 @defopt scroll-up-aggressively
3274 Likewise, for scrolling up. The value, @var{f}, specifies how far
3275 point should be placed from the bottom of the window; thus, as with
3276 @code{scroll-up-aggressively}, a larger value scrolls more aggressively.
3277 @end defopt
3278
3279 @defopt scroll-step
3280 This variable is an older variant of @code{scroll-conservatively}.
3281 The difference is that if its value is @var{n}, that permits scrolling
3282 only by precisely @var{n} lines, not a smaller number. This feature
3283 does not work with @code{scroll-margin}. The default value is zero.
3284 @end defopt
3285
3286 @cindex @code{scroll-command} property
3287 @defopt scroll-preserve-screen-position
3288 If this option is @code{t}, whenever a scrolling command moves point
3289 off-window, Emacs tries to adjust point to keep the cursor at its old
3290 vertical position in the window, rather than the window edge.
3291
3292 If the value is non-@code{nil} and not @code{t}, Emacs adjusts point
3293 to keep the cursor at the same vertical position, even if the
3294 scrolling command didn't move point off-window.
3295
3296 This option affects all scroll commands that have a non-@code{nil}
3297 @code{scroll-command} symbol property.
3298 @end defopt
3299
3300 @defopt next-screen-context-lines
3301 The value of this variable is the number of lines of continuity to
3302 retain when scrolling by full screens. For example, @code{scroll-up}
3303 with an argument of @code{nil} scrolls so that this many lines at the
3304 bottom of the window appear instead at the top. The default value is
3305 @code{2}.
3306 @end defopt
3307
3308 @defopt scroll-error-top-bottom
3309 If this option is @code{nil} (the default), @code{scroll-up-command}
3310 and @code{scroll-down-command} simply signal an error when no more
3311 scrolling is possible.
3312
3313 If the value is @code{t}, these commands instead move point to the
3314 beginning or end of the buffer (depending on scrolling direction);
3315 only if point is already on that position do they signal an error.
3316 @end defopt
3317
3318 @deffn Command recenter &optional count
3319 @cindex centering point
3320 This function scrolls the text in the selected window so that point is
3321 displayed at a specified vertical position within the window. It does
3322 not ``move point'' with respect to the text.
3323
3324 If @var{count} is a nonnegative number, that puts the line containing
3325 point @var{count} lines down from the top of the window. If
3326 @var{count} is a negative number, then it counts upward from the
3327 bottom of the window, so that @minus{}1 stands for the last usable
3328 line in the window. If @var{count} is a non-@code{nil} list, then it
3329 stands for the line in the middle of the window.
3330
3331 If @var{count} is @code{nil}, @code{recenter} puts the line containing
3332 point in the middle of the window, then clears and redisplays the entire
3333 selected frame.
3334
3335 When @code{recenter} is called interactively, @var{count} is the raw
3336 prefix argument. Thus, typing @kbd{C-u} as the prefix sets the
3337 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
3338 @var{count} to 4, which positions the current line four lines from the
3339 top.
3340
3341 With an argument of zero, @code{recenter} positions the current line at
3342 the top of the window. This action is so handy that some people make a
3343 separate key binding to do this. For example,
3344
3345 @example
3346 @group
3347 (defun line-to-top-of-window ()
3348 "Scroll current line to top of window.
3349 Replaces three keystroke sequence C-u 0 C-l."
3350 (interactive)
3351 (recenter 0))
3352
3353 (global-set-key [kp-multiply] 'line-to-top-of-window)
3354 @end group
3355 @end example
3356 @end deffn
3357
3358 @node Vertical Scrolling
3359 @section Vertical Fractional Scrolling
3360 @cindex vertical fractional scrolling
3361 @cindex vertical scroll position
3362
3363 @dfn{Vertical fractional scrolling} means shifting text in a window
3364 up or down by a specified multiple or fraction of a line. Each window
3365 has a @dfn{vertical scroll position}, which is a number, never less than
3366 zero. It specifies how far to raise the contents of the window.
3367 Raising the window contents generally makes all or part of some lines
3368 disappear off the top, and all or part of some other lines appear at the
3369 bottom. The usual value is zero.
3370
3371 The vertical scroll position is measured in units of the normal line
3372 height, which is the height of the default font. Thus, if the value is
3373 .5, that means the window contents are scrolled up half the normal line
3374 height. If it is 3.3, that means the window contents are scrolled up
3375 somewhat over three times the normal line height.
3376
3377 What fraction of a line the vertical scrolling covers, or how many
3378 lines, depends on what the lines contain. A value of .5 could scroll a
3379 line whose height is very short off the screen, while a value of 3.3
3380 could scroll just part of the way through a tall line or an image.
3381
3382 @defun window-vscroll &optional window pixels-p
3383 This function returns the current vertical scroll position of
3384 @var{window}. The default for @var{window} is the selected window.
3385 If @var{pixels-p} is non-@code{nil}, the return value is measured in
3386 pixels, rather than in units of the normal line height.
3387
3388 @example
3389 @group
3390 (window-vscroll)
3391 @result{} 0
3392 @end group
3393 @end example
3394 @end defun
3395
3396 @defun set-window-vscroll window lines &optional pixels-p
3397 This function sets @var{window}'s vertical scroll position to
3398 @var{lines}. If @var{window} is @code{nil}, the selected window is
3399 used. The argument @var{lines} should be zero or positive; if not, it
3400 is taken as zero.
3401
3402
3403 The actual vertical scroll position must always correspond
3404 to an integral number of pixels, so the value you specify
3405 is rounded accordingly.
3406
3407 The return value is the result of this rounding.
3408
3409 @example
3410 @group
3411 (set-window-vscroll (selected-window) 1.2)
3412 @result{} 1.13
3413 @end group
3414 @end example
3415
3416 If @var{pixels-p} is non-@code{nil}, @var{lines} specifies a number of
3417 pixels. In this case, the return value is @var{lines}.
3418 @end defun
3419
3420 @defvar auto-window-vscroll
3421 If this variable is non-@code{nil}, the line-move, scroll-up, and
3422 scroll-down functions will automatically modify the vertical scroll
3423 position to scroll through display rows that are taller than the height
3424 of the window, for example in the presence of large images.
3425 @end defvar
3426
3427 @node Horizontal Scrolling
3428 @section Horizontal Scrolling
3429 @cindex horizontal scrolling
3430
3431 @dfn{Horizontal scrolling} means shifting the image in the window left
3432 or right by a specified multiple of the normal character width. Each
3433 window has a @dfn{horizontal scroll position}, which is a number, never
3434 less than zero. It specifies how far to shift the contents left.
3435 Shifting the window contents left generally makes all or part of some
3436 characters disappear off the left, and all or part of some other
3437 characters appear at the right. The usual value is zero.
3438
3439 The horizontal scroll position is measured in units of the normal
3440 character width, which is the width of space in the default font. Thus,
3441 if the value is 5, that means the window contents are scrolled left by 5
3442 times the normal character width. How many characters actually
3443 disappear off to the left depends on their width, and could vary from
3444 line to line.
3445
3446 Because we read from side to side in the ``inner loop,'' and from top
3447 to bottom in the ``outer loop,'' the effect of horizontal scrolling is
3448 not like that of textual or vertical scrolling. Textual scrolling
3449 involves selection of a portion of text to display, and vertical
3450 scrolling moves the window contents contiguously; but horizontal
3451 scrolling causes part of @emph{each line} to go off screen.
3452
3453 Usually, no horizontal scrolling is in effect; then the leftmost
3454 column is at the left edge of the window. In this state, scrolling to
3455 the right is meaningless, since there is no data to the left of the edge
3456 to be revealed by it; so this is not allowed. Scrolling to the left is
3457 allowed; it scrolls the first columns of text off the edge of the window
3458 and can reveal additional columns on the right that were truncated
3459 before. Once a window has a nonzero amount of leftward horizontal
3460 scrolling, you can scroll it back to the right, but only so far as to
3461 reduce the net horizontal scroll to zero. There is no limit to how far
3462 left you can scroll, but eventually all the text will disappear off the
3463 left edge.
3464
3465 @vindex auto-hscroll-mode
3466 If @code{auto-hscroll-mode} is set, redisplay automatically alters
3467 the horizontal scrolling of a window as necessary to ensure that point
3468 is always visible. However, you can still set the horizontal
3469 scrolling value explicitly. The value you specify serves as a lower
3470 bound for automatic scrolling, i.e. automatic scrolling will not
3471 scroll a window to a column less than the specified one.
3472
3473 @deffn Command scroll-left &optional count set-minimum
3474 This function scrolls the selected window @var{count} columns to the
3475 left (or to the right if @var{count} is negative). The default
3476 for @var{count} is the window width, minus 2.
3477
3478 The return value is the total amount of leftward horizontal scrolling in
3479 effect after the change---just like the value returned by
3480 @code{window-hscroll} (below).
3481
3482 Once you scroll a window as far right as it can go, back to its normal
3483 position where the total leftward scrolling is zero, attempts to scroll
3484 any farther right have no effect.
3485
3486 If @var{set-minimum} is non-@code{nil}, the new scroll amount becomes
3487 the lower bound for automatic scrolling; that is, automatic scrolling
3488 will not scroll a window to a column less than the value returned by
3489 this function. Interactive calls pass non-@code{nil} for
3490 @var{set-minimum}.
3491 @end deffn
3492
3493 @deffn Command scroll-right &optional count set-minimum
3494 This function scrolls the selected window @var{count} columns to the
3495 right (or to the left if @var{count} is negative). The default
3496 for @var{count} is the window width, minus 2. Aside from the direction
3497 of scrolling, this works just like @code{scroll-left}.
3498 @end deffn
3499
3500 @defun window-hscroll &optional window
3501 This function returns the total leftward horizontal scrolling of
3502 @var{window}---the number of columns by which the text in @var{window}
3503 is scrolled left past the left margin. The default for
3504 @var{window} is the selected window.
3505
3506 The return value is never negative. It is zero when no horizontal
3507 scrolling has been done in @var{window} (which is usually the case).
3508
3509
3510 @example
3511 @group
3512 (window-hscroll)
3513 @result{} 0
3514 @end group
3515 @group
3516 (scroll-left 5)
3517 @result{} 5
3518 @end group
3519 @group
3520 (window-hscroll)
3521 @result{} 5
3522 @end group
3523 @end example
3524 @end defun
3525
3526 @defun set-window-hscroll window columns
3527 This function sets horizontal scrolling of @var{window}. The value of
3528 @var{columns} specifies the amount of scrolling, in terms of columns
3529 from the left margin. The argument @var{columns} should be zero or
3530 positive; if not, it is taken as zero. Fractional values of
3531 @var{columns} are not supported at present.
3532
3533 Note that @code{set-window-hscroll} may appear not to work if you test
3534 it by evaluating a call with @kbd{M-:} in a simple way. What happens
3535 is that the function sets the horizontal scroll value and returns, but
3536 then redisplay adjusts the horizontal scrolling to make point visible,
3537 and this overrides what the function did. You can observe the
3538 function's effect if you call it while point is sufficiently far from
3539 the left margin that it will remain visible.
3540
3541 The value returned is @var{columns}.
3542
3543 @example
3544 @group
3545 (set-window-hscroll (selected-window) 10)
3546 @result{} 10
3547 @end group
3548 @end example
3549 @end defun
3550
3551 Here is how you can determine whether a given position @var{position}
3552 is off the screen due to horizontal scrolling:
3553
3554 @example
3555 @group
3556 (defun hscroll-on-screen (window position)
3557 (save-excursion
3558 (goto-char position)
3559 (and
3560 (>= (- (current-column) (window-hscroll window)) 0)
3561 (< (- (current-column) (window-hscroll window))
3562 (window-width window)))))
3563 @end group
3564 @end example
3565
3566
3567 @node Coordinates and Windows
3568 @section Coordinates and Windows
3569
3570 This section describes how to relate screen coordinates to windows.
3571
3572 @defun window-at x y &optional frame
3573 This function returns the window containing the specified cursor
3574 position in the frame @var{frame}. The coordinates @var{x} and @var{y}
3575 are measured in characters and count from the top left corner of the
3576 frame. If they are out of range, @code{window-at} returns @code{nil}.
3577
3578 If you omit @var{frame}, the selected frame is used.
3579 @end defun
3580
3581 @defun coordinates-in-window-p coordinates window
3582 This function checks whether a particular frame position falls within
3583 the window @var{window}.
3584
3585 The argument @var{coordinates} is a cons cell of the form @code{(@var{x}
3586 . @var{y})}. The coordinates @var{x} and @var{y} are measured in
3587 characters, and count from the top left corner of the screen or frame.
3588
3589 The value returned by @code{coordinates-in-window-p} is non-@code{nil}
3590 if the coordinates are inside @var{window}. The value also indicates
3591 what part of the window the position is in, as follows:
3592
3593 @table @code
3594 @item (@var{relx} . @var{rely})
3595 The coordinates are inside @var{window}. The numbers @var{relx} and
3596 @var{rely} are the equivalent window-relative coordinates for the
3597 specified position, counting from 0 at the top left corner of the
3598 window.
3599
3600 @item mode-line
3601 The coordinates are in the mode line of @var{window}.
3602
3603 @item header-line
3604 The coordinates are in the header line of @var{window}.
3605
3606 @item vertical-line
3607 The coordinates are in the vertical line between @var{window} and its
3608 neighbor to the right. This value occurs only if the window doesn't
3609 have a scroll bar; positions in a scroll bar are considered outside the
3610 window for these purposes.
3611
3612 @item left-fringe
3613 @itemx right-fringe
3614 The coordinates are in the left or right fringe of the window.
3615
3616 @item left-margin
3617 @itemx right-margin
3618 The coordinates are in the left or right margin of the window.
3619
3620 @item nil
3621 The coordinates are not in any part of @var{window}.
3622 @end table
3623
3624 The function @code{coordinates-in-window-p} does not require a frame as
3625 argument because it always uses the frame that @var{window} is on.
3626 @end defun
3627
3628
3629 @node Window Configurations
3630 @section Window Configurations
3631 @cindex window configurations
3632 @cindex saving window information
3633
3634 A @dfn{window configuration} records the entire layout of one
3635 frame---all windows, their sizes, which buffers they contain, how those
3636 buffers are scrolled, and their values of point and the mark; also their
3637 fringes, margins, and scroll bar settings. It also includes the value
3638 of @code{minibuffer-scroll-window}. As a special exception, the window
3639 configuration does not record the value of point in the selected window
3640 for the current buffer.
3641
3642 You can bring back an entire frame layout by restoring a previously
3643 saved window configuration. If you want to record the layout of all
3644 frames instead of just one, use a frame configuration instead of a
3645 window configuration; see @ref{Frame Configurations}.
3646
3647 @defun current-window-configuration &optional frame
3648 This function returns a new object representing @var{frame}'s current
3649 window configuration. The default for @var{frame} is the selected
3650 frame.
3651 @end defun
3652
3653 @defun set-window-configuration configuration
3654 This function restores the configuration of windows and buffers as
3655 specified by @var{configuration}, for the frame that @var{configuration}
3656 was created for.
3657
3658 The argument @var{configuration} must be a value that was previously
3659 returned by @code{current-window-configuration}. The configuration is
3660 restored in the frame from which @var{configuration} was made, whether
3661 that frame is selected or not. This always counts as a window size
3662 change and triggers execution of the @code{window-size-change-functions}
3663 (@pxref{Window Hooks}), because @code{set-window-configuration} doesn't
3664 know how to tell whether the new configuration actually differs from the
3665 old one.
3666
3667 If the frame which @var{configuration} was saved from is dead, all this
3668 function does is restore the three variables @code{window-min-height},
3669 @code{window-min-width} and @code{minibuffer-scroll-window}. In this
3670 case, the function returns @code{nil}. Otherwise, it returns @code{t}.
3671
3672 Here is a way of using this function to get the same effect
3673 as @code{save-window-excursion}:
3674
3675 @example
3676 @group
3677 (let ((config (current-window-configuration)))
3678 (unwind-protect
3679 (progn (split-window-vertically nil)
3680 @dots{})
3681 (set-window-configuration config)))
3682 @end group
3683 @end example
3684 @end defun
3685
3686 @defspec save-window-excursion forms@dots{}
3687 This special form records the window configuration, executes @var{forms}
3688 in sequence, then restores the earlier window configuration. The window
3689 configuration includes, for each window, the value of point and the
3690 portion of the buffer that is visible. It also includes the choice of
3691 selected window. However, it does not include the value of point in
3692 the current buffer; use @code{save-excursion} also, if you wish to
3693 preserve that.
3694
3695 Don't use this construct when @code{save-selected-window} is sufficient.
3696
3697 Exit from @code{save-window-excursion} always triggers execution of
3698 @code{window-size-change-functions}. (It doesn't know how to tell
3699 whether the restored configuration actually differs from the one in
3700 effect at the end of the @var{forms}.)
3701
3702 The return value is the value of the final form in @var{forms}.
3703 For example:
3704
3705 @example
3706 @group
3707 (split-window)
3708 @result{} #<window 25 on control.texi>
3709 @end group
3710 @group
3711 (setq w (selected-window))
3712 @result{} #<window 19 on control.texi>
3713 @end group
3714 @group
3715 (save-window-excursion
3716 (delete-other-windows w)
3717 (switch-to-buffer "foo")
3718 'do-something)
3719 @result{} do-something
3720 ;; @r{The screen is now split again.}
3721 @end group
3722 @end example
3723 @end defspec
3724
3725 @defun window-configuration-p object
3726 This function returns @code{t} if @var{object} is a window configuration.
3727 @end defun
3728
3729 @defun compare-window-configurations config1 config2
3730 This function compares two window configurations as regards the
3731 structure of windows, but ignores the values of point and mark and the
3732 saved scrolling positions---it can return @code{t} even if those
3733 aspects differ.
3734
3735 The function @code{equal} can also compare two window configurations; it
3736 regards configurations as unequal if they differ in any respect, even a
3737 saved point or mark.
3738 @end defun
3739
3740 @defun window-configuration-frame config
3741 This function returns the frame for which the window configuration
3742 @var{config} was made.
3743 @end defun
3744
3745 Other primitives to look inside of window configurations would make
3746 sense, but are not implemented because we did not need them. See the
3747 file @file{winner.el} for some more operations on windows
3748 configurations.
3749
3750 The objects returned by @code{current-window-configuration} die
3751 together with the Emacs process. In order to store a window
3752 configuration on disk and read it back in another Emacs session the
3753 following two functions can be used.
3754
3755 @defun window-state-get &optional window markers
3756 This function returns the state of @var{window} as a Lisp object. The
3757 argument @var{window} can be any window and defaults to the root window
3758 of the selected frame.
3759
3760 The optional argument @var{markers} non-@code{nil} means to use markers
3761 for sampling positions like @code{window-point} or @code{window-start}.
3762 This argument should be non-@code{nil} only if the value is used for
3763 putting the state back in the same session since markers slow down
3764 processing.
3765 @end defun
3766
3767 The value returned by @code{window-state-get} can be converted by using
3768 one of the functions defined by Desktop Save Mode (@pxref{Desktop Save
3769 Mode}) to an object that can be written to a file. Such objects can be
3770 read back and converted to a Lisp object representing the state of the
3771 window. That Lisp object can be used as argument for the following
3772 function in order to restore the state window in another window.
3773
3774 @defun window-state-put state &optional window ignore
3775 This function puts the window state @var{state} into @var{window}. The
3776 argument @var{state} should be the state of a window returned by an
3777 earlier invocation of @code{window-state-get}, see above. The optional
3778 argument @var{window} must specify a live window and defaults to the
3779 selected one.
3780
3781 The optional argument @var{ignore} non-@code{nil} means to ignore
3782 minimum window sizes and fixed size restrictions. If @var{ignore}
3783 equals @code{safe}, this means subwindows can get as small as one line
3784 and/or two columns.
3785 @end defun
3786
3787
3788 @node Window Parameters
3789 @section Window Parameters
3790 @cindex window parameters
3791
3792 This section describes how window parameters can be used to associate
3793 additional information with windows.
3794
3795 @defun window-parameter window parameter
3796 This function returns @var{window}'s value for @var{parameter}. The
3797 default for @var{window} is the selected window. If @var{window} has no
3798 setting for @var{parameter}, this function returns @code{nil}.
3799 @end defun
3800
3801 @defun window-parameters &optional window
3802 This function returns all parameters of @var{window} and their values.
3803 The default for @var{window} is the selected window. The return value,
3804 if non-@code{nil} is an association list whose elements have the form
3805 @code{(@var{parameter} . @var{value})}.
3806 @end defun
3807
3808 @defun set-window-parameter window parameter value
3809 This function sets @var{window}'s value of @var{parameter} to
3810 @var{value} and returns @var{value}. The default for @var{window}
3811 is the selected window.
3812 @end defun
3813
3814 Some functions, notably @code{delete-window},
3815 @code{delete-other-windows} and @code{split-window} may behave specially
3816 when their @var{window} argument has a parameter set. You can override
3817 such special behavior by binding the following variable to a
3818 non-@code{nil} value:
3819
3820 @defvar ignore-window-parameters
3821 If this variable is non-@code{nil}, some standard functions do not
3822 process window parameters. The functions currently affected by this are
3823 @code{split-window}, @code{delete-window}, @code{delete-other-windows}
3824 and @code{other-window}.
3825
3826 An application can bind this variable to a non-@code{nil} value around
3827 calls to these functions. If it does so, the application is fully
3828 responsible for correctly assigning the parameters of all involved
3829 windows when exiting that function.
3830 @end defvar
3831
3832 The following parameters are currently used by the window management
3833 code.
3834
3835 @table @asis
3836 @item @code{delete-window}
3837 This parameter affects the execution of @code{delete-window}
3838 (@pxref{Deleting Windows}).
3839
3840 @item @code{delete-other-windows}
3841 This parameter affects the execution of @code{delete-other-windows}
3842 (@pxref{Deleting Windows}).
3843
3844 @item @code{split-window}
3845 This parameter affects the execution of @code{split-window}
3846 (@pxref{Splitting Windows}).
3847
3848 @item @code{other-window}
3849 This parameter affects the execution of @code{other-window}
3850 (@pxref{Cyclic Window Ordering}).
3851
3852 @item @code{no-other-window}
3853 This parameter marks the window as not selectable by @code{other-window}
3854 (@pxref{Cyclic Window Ordering}).
3855 @end table
3856
3857 In addition, the parameters @code{window-atom} and @code{window-side}
3858 are reserved and should not be used by applications. The
3859 @code{quit-restore} parameter tells how to proceed with a window when
3860 the buffer it shows is no more needed. This parameter is installed by
3861 the buffer display functions (@pxref{Choosing Window}) and consulted by
3862 the function @code{quit-window} (@pxref{Quitting Windows}).
3863
3864
3865 @node Window Hooks
3866 @section Hooks for Window Scrolling and Changes
3867 @cindex hooks for window operations
3868
3869 This section describes how a Lisp program can take action whenever a
3870 window displays a different part of its buffer or a different buffer.
3871 There are three actions that can change this: scrolling the window,
3872 switching buffers in the window, and changing the size of the window.
3873 The first two actions run @code{window-scroll-functions}; the last runs
3874 @code{window-size-change-functions}.
3875
3876 @defvar window-scroll-functions
3877 This variable holds a list of functions that Emacs should call before
3878 redisplaying a window with scrolling. Displaying a different buffer in
3879 the window also runs these functions.
3880
3881 This variable is not a normal hook, because each function is called with
3882 two arguments: the window, and its new display-start position.
3883
3884 These functions must be careful in using @code{window-end}
3885 (@pxref{Window Start and End}); if you need an up-to-date value, you
3886 must use the @var{update} argument to ensure you get it.
3887
3888 @strong{Warning:} don't use this feature to alter the way the window
3889 is scrolled. It's not designed for that, and such use probably won't
3890 work.
3891 @end defvar
3892
3893 @defvar window-size-change-functions
3894 This variable holds a list of functions to be called if the size of any
3895 window changes for any reason. The functions are called just once per
3896 redisplay, and just once for each frame on which size changes have
3897 occurred.
3898
3899 Each function receives the frame as its sole argument. There is no
3900 direct way to find out which windows on that frame have changed size, or
3901 precisely how. However, if a size-change function records, at each
3902 call, the existing windows and their sizes, it can also compare the
3903 present sizes and the previous sizes.
3904
3905 Creating or deleting windows counts as a size change, and therefore
3906 causes these functions to be called. Changing the frame size also
3907 counts, because it changes the sizes of the existing windows.
3908
3909 It is not a good idea to use @code{save-window-excursion} (@pxref{Window
3910 Configurations}) in these functions, because that always counts as a
3911 size change, and it would cause these functions to be called over and
3912 over. In most cases, @code{save-selected-window} (@pxref{Selecting
3913 Windows}) is what you need here.
3914 @end defvar
3915
3916 @defvar window-configuration-change-hook
3917 A normal hook that is run every time you change the window configuration
3918 of an existing frame. This includes splitting or deleting windows,
3919 changing the sizes of windows, or displaying a different buffer in a
3920 window.
3921
3922 The buffer-local part of this hook is run once per each window on the
3923 affected frame, with the relevant window selected and its buffer
3924 current. The global part is run once for the modified frame, with that
3925 frame selected.
3926 @end defvar
3927
3928 In addition, you can use @code{jit-lock-register} to register a Font
3929 Lock fontification function, which will be called whenever parts of a
3930 buffer are (re)fontified because a window was scrolled or its size
3931 changed. @xref{Other Font Lock Variables}.