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