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