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