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