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