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