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