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