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