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