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