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