* doc/lispref/lists.texi (Sets And Lists): Mention cl provides union etc.
[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
10 This chapter describes most of the functions and variables related to
0273ca3a
MR
11Emacs windows. @xref{Frames and Windows}, for how windows relate to
12frames. @xref{Display}, for information on how text is displayed in
13windows.
b8d4c8d0
GM
14
15@menu
16* Basic Windows:: Basic information on using windows.
17* Splitting Windows:: Splitting one window into two windows.
18* Deleting Windows:: Deleting a window gives its space to other windows.
19* Selecting Windows:: The selected window is the one that you edit in.
20* Cyclic Window Ordering:: Moving around the existing windows.
21* Buffers and Windows:: Each window displays the contents of a buffer.
22* Displaying Buffers:: Higher-level functions for displaying a buffer
23 and choosing a window for it.
d24880de
GM
24* Choosing Window:: How to choose a window for displaying a buffer.
25* Dedicated Windows:: How to avoid displaying another buffer in
a1401ab1 26 a specific window.
b8d4c8d0 27* Window Point:: Each window has its own location of point.
0273ca3a
MR
28* Window Start and End:: Buffer positions indicating which text is
29 on-screen in a window.
b8d4c8d0
GM
30* Textual Scrolling:: Moving text up and down through the window.
31* Vertical Scrolling:: Moving the contents up and down on the window.
32* Horizontal Scrolling:: Moving the contents sideways on the window.
33* Size of Window:: Accessing the size of a window.
34* Resizing Windows:: Changing the size of a window.
35* Coordinates and Windows:: Converting coordinates to windows.
36* Window Tree:: The layout and sizes of all windows in a frame.
37* Window Configurations:: Saving and restoring the state of the screen.
0273ca3a 38* Window Parameters:: Associating additional information with windows.
b8d4c8d0
GM
39* Window Hooks:: Hooks for scrolling, window size changes,
40 redisplay going past a certain point,
41 or window configuration changes.
42@end menu
43
44@node Basic Windows
45@section Basic Concepts of Emacs Windows
46@cindex window
47@cindex selected window
48
49 A @dfn{window} in Emacs is the physical area of the screen in which a
50buffer is displayed. The term is also used to refer to a Lisp object that
51represents that screen area in Emacs Lisp. It should be
52clear from the context which is meant.
53
47264a97 54 Emacs groups windows into frames; see @ref{Frames}. A frame
a1401ab1
EZ
55represents an area of screen available for Emacs to use. Each frame
56always contains at least one window, but you can subdivide it
57vertically or horizontally into multiple, nonoverlapping Emacs
58windows.
b8d4c8d0
GM
59
60 In each frame, at any time, one and only one window is designated as
61@dfn{selected within the frame}. The frame's cursor appears in that
62window, but the other windows have ``non-selected'' cursors, normally
a1401ab1 63less visible. (@xref{Cursor Parameters}, for customizing this.) At
0273ca3a 64any time, one frame is the selected frame; and the window selected
7ed54cc5 65within that frame is @dfn{the selected window}. The selected window's
0273ca3a 66buffer is usually the current buffer (except when @code{set-buffer} has
47264a97 67been used); see @ref{Current Buffer}.
b8d4c8d0
GM
68
69 For practical purposes, a window exists only while it is displayed in
70a frame. Once removed from the frame, the window is effectively deleted
71and should not be used, @emph{even though there may still be references
47264a97 72to it} from other Lisp objects; see @ref{Deleting Windows}. Restoring a
0273ca3a 73saved window configuration is the only way for a window no longer on the
47264a97 74screen to come back to life; see @ref{Window Configurations}.
b8d4c8d0
GM
75
76@cindex multiple windows
77 Users create multiple windows so they can look at several buffers at
78once. Lisp libraries use multiple windows for a variety of reasons, but
79most often to display related information. In Rmail, for example, you
80can move through a summary buffer in one window while the other window
81shows messages one at a time as they are reached.
82
83 The meaning of ``window'' in Emacs is similar to what it means in the
84context of general-purpose window systems such as X, but not identical.
85The X Window System places X windows on the screen; Emacs uses one or
86more X windows as frames, and subdivides them into
87Emacs windows. When you use Emacs on a character-only terminal, Emacs
88treats the whole terminal screen as one frame.
89
90@cindex terminal screen
91@cindex screen of terminal
92@cindex tiled windows
93 Most window systems support arbitrarily located overlapping windows.
94In contrast, Emacs windows are @dfn{tiled}; they never overlap, and
95together they fill the whole screen or frame. Because of the way in
0273ca3a
MR
96which Emacs creates new windows (@pxref{Splitting Windows}) and resizes
97them (@pxref{Resizing Windows}), not all conceivable tilings of windows
98on an Emacs frame are actually possible.
b8d4c8d0
GM
99
100@defun windowp object
101This function returns @code{t} if @var{object} is a window.
102@end defun
103
104@node Splitting Windows
105@section Splitting Windows
106@cindex splitting windows
107@cindex window splitting
108
0273ca3a
MR
109The functions described below are the primitives used to split a window
110into two windows. They do not accept a buffer as an argument. Rather,
111the two ``halves'' of the split window initially display the same buffer
b8d4c8d0
GM
112previously visible in the window that was split.
113
114@deffn Command split-window &optional window size horizontal
0273ca3a 115This function splits a new window out of @var{window}'s screen area. It
aeeedf76
MR
116returns the new window. The default for @var{window} is the selected
117window. When you split the selected window, it remains selected.
0273ca3a
MR
118
119If @var{horizontal} is non-@code{nil}, then @var{window} splits into two
120side by side windows. The original window keeps the leftmost @var{size}
121columns, and gives the rest of the columns to the new window.
122Otherwise, @var{window} splits into windows one above the other, the
123original window keeps the upper @var{size} lines and gives the rest of
124the lines to the new window. The original window @var{window} is
125therefore the left-hand or upper of the two, and the new window is the
126right-hand or lower.
b8d4c8d0
GM
127
128If @var{size} is omitted or @code{nil}, then @var{window} is divided
129evenly into two parts. (If there is an odd line, it is allocated to
130the new window.) When @code{split-window} is called interactively,
131all its arguments are @code{nil}.
132
133If splitting would result in making a window that is smaller than
0273ca3a
MR
134@code{window-min-height} or @code{window-min-width} (@pxref{Resizing
135Windows}), @code{split-window} signals an error and does not split the
136window at all.
b8d4c8d0
GM
137
138The following example starts with one window on a screen that is 50
139lines high by 80 columns wide; then it splits the window.
140
141@smallexample
142@group
143(setq w (selected-window))
144 @result{} #<window 8 on windows.texi>
145(window-edges) ; @r{Edges in order:}
146 @result{} (0 0 80 50) ; @r{left--top--right--bottom}
147@end group
148
149@group
150;; @r{Returns window created}
151(setq w2 (split-window w 15))
152 @result{} #<window 28 on windows.texi>
153@end group
154@group
155(window-edges w2)
156 @result{} (0 15 80 50) ; @r{Bottom window;}
157 ; @r{top is line 15}
158@end group
159@group
160(window-edges w)
161 @result{} (0 0 80 15) ; @r{Top window}
162@end group
163@end smallexample
164
165The screen looks like this:
166
167@smallexample
168@group
169 __________
170 | | line 0
171 | w |
172 |__________|
173 | | line 15
174 | w2 |
175 |__________|
176 line 50
177 column 0 column 80
178@end group
179@end smallexample
180
181Next, split the top window horizontally:
182
183@smallexample
184@group
185(setq w3 (split-window w 35 t))
186 @result{} #<window 32 on windows.texi>
187@end group
188@group
189(window-edges w3)
190 @result{} (35 0 80 15) ; @r{Left edge at column 35}
191@end group
192@group
193(window-edges w)
194 @result{} (0 0 35 15) ; @r{Right edge at column 35}
195@end group
196@group
197(window-edges w2)
198 @result{} (0 15 80 50) ; @r{Bottom window unchanged}
199@end group
200@end smallexample
201
202@need 3000
203Now the screen looks like this:
204
205@smallexample
206@group
207 column 35
208 __________
209 | | | line 0
210 | w | w3 |
211 |___|______|
212 | | line 15
213 | w2 |
214 |__________|
215 line 50
216 column 0 column 80
217@end group
218@end smallexample
219
220Normally, Emacs indicates the border between two side-by-side windows
a1401ab1
EZ
221with a scroll bar (@pxref{Scroll Bars}), or with @samp{|} characters. The
222display table can specify alternative border characters; see @ref{Display
0273ca3a 223Tables}.
b8d4c8d0
GM
224@end deffn
225
226@deffn Command split-window-vertically &optional size
227This function splits the selected window into two windows, one above the
228other, leaving the upper of the two windows selected, with @var{size}
229lines. (If @var{size} is negative, then the lower of the two windows
96995b89 230gets @minus{}@var{size} lines and the upper window gets the rest, but
b8d4c8d0
GM
231the upper window is still the one selected.) However, if
232@code{split-window-keep-point} (see below) is @code{nil}, then either
233window can be selected.
234
235In other respects, this function is similar to @code{split-window}.
236In particular, the upper window is the original one and the return
237value is the new, lower window.
238@end deffn
239
240@defopt split-window-keep-point
241If this variable is non-@code{nil} (the default), then
242@code{split-window-vertically} behaves as described above.
243
244If it is @code{nil}, then @code{split-window-vertically} adjusts point
245in each of the two windows to avoid scrolling. (This is useful on
246slow terminals.) It selects whichever window contains the screen line
247that point was previously on.
248
96995b89
MR
249This variable affects the behavior of @code{split-window-vertically}
250only. It has no effect on the other functions described here.
b8d4c8d0
GM
251@end defopt
252
253@deffn Command split-window-horizontally &optional size
254This function splits the selected window into two windows
255side-by-side, leaving the selected window on the left with @var{size}
256columns. If @var{size} is negative, the rightmost window gets
96995b89 257@minus{}@var{size} columns, but the leftmost window still remains
b8d4c8d0
GM
258selected.
259
260This function is basically an interface to @code{split-window}.
261You could define a simplified version of the function like this:
262
263@smallexample
264@group
265(defun split-window-horizontally (&optional arg)
266 "Split selected window into two windows, side by side..."
267 (interactive "P")
268@end group
269@group
270 (let ((size (and arg (prefix-numeric-value arg))))
271 (and size (< size 0)
96995b89 272 (setq size (+ (window-width) size)))
b8d4c8d0
GM
273 (split-window nil size t)))
274@end group
275@end smallexample
276@end deffn
277
278@defun one-window-p &optional no-mini all-frames
279This function returns non-@code{nil} if there is only one window. The
280argument @var{no-mini}, if non-@code{nil}, means don't count the
281minibuffer even if it is active; otherwise, the minibuffer window is
282counted when it is active.
283
284The argument @var{all-frames} specifies which frames to consider. Here
285are the possible values and their meanings:
286
287@table @asis
288@item @code{nil}
289Count the windows in the selected frame, plus the minibuffer used
290by that frame even if it lies in some other frame.
291
292@item @code{t}
293Count all windows in all existing frames.
294
295@item @code{visible}
296Count all windows in all visible frames.
297
298@item 0
299Count all windows in all visible or iconified frames.
300
301@item anything else
302Count precisely the windows in the selected frame, and no others.
303@end table
304@end defun
305
306@node Deleting Windows
307@section Deleting Windows
308@cindex deleting windows
309
310A window remains visible on its frame unless you @dfn{delete} it by
311calling certain functions that delete windows. A deleted window cannot
312appear on the screen, but continues to exist as a Lisp object until
313there are no references to it. There is no way to cancel the deletion
314of a window aside from restoring a saved window configuration
315(@pxref{Window Configurations}). Restoring a window configuration also
316deletes any windows that aren't part of that configuration.
317
a1401ab1
EZ
318 When you delete a window, the space it took up is given to one of
319its sibling windows adjacent to it.
b8d4c8d0
GM
320
321@c Emacs 19 feature
322@defun window-live-p window
323This function returns @code{nil} if @var{window} is deleted, and
324@code{t} otherwise.
325
326@strong{Warning:} Erroneous information or fatal errors may result from
327using a deleted window as if it were live.
328@end defun
329
330@deffn Command delete-window &optional window
0273ca3a 331This function removes @var{window} from display and returns @code{nil}.
aeeedf76
MR
332The default for @var{window} is the selected window. An error is
333signaled if @var{window} is the only window on its frame.
b8d4c8d0
GM
334@end deffn
335
336@deffn Command delete-other-windows &optional window
337This function makes @var{window} the only window on its frame, by
aeeedf76
MR
338deleting the other windows in that frame. The default for @var{window}
339is the selected window. The return value is @code{nil}.
b8d4c8d0
GM
340@end deffn
341
520b29e7 342@deffn Command delete-windows-on &optional buffer-or-name frame
b8d4c8d0 343This function deletes all windows showing @var{buffer-or-name}. If
aeeedf76
MR
344there are no windows showing @var{buffer-or-name}, it does nothing. The
345optional argument @var{buffer-or-name} may be a buffer or the name of an
346existing buffer and defaults to the current buffer.
b8d4c8d0
GM
347
348@code{delete-windows-on} operates frame by frame. If a frame has
349several windows showing different buffers, then those showing
350@var{buffer-or-name} are removed, and the others expand to fill the
351space. If all windows in some frame are showing @var{buffer-or-name}
352(including the case where there is only one window), then the frame
353winds up with a single window showing another buffer chosen with
0273ca3a
MR
354@code{other-buffer} (@pxref{The Buffer List}). If, however, the window
355showing @var{buffer-or-name} is dedicated to its buffer
356(@pxref{Dedicated Windows}), and there are other frames left, that
357window's frame is deleted.
b8d4c8d0 358
aeeedf76
MR
359The optional argument @var{frame} specifies which frames to operate on.
360This function does not use it in quite the same way as the other
361functions which scan all windows; specifically, the values @code{t} and
362@code{nil} have the opposite of their meanings in other functions. Here
363are the full details:
b8d4c8d0
GM
364
365@itemize @bullet
366@item
367If it is @code{nil}, operate on all frames.
368@item
369If it is @code{t}, operate on the selected frame.
370@item
371If it is @code{visible}, operate on all visible frames.
372@item
373If it is 0, operate on all visible or iconified frames.
374@item
375If it is a frame, operate on that frame.
376@end itemize
377
378This function always returns @code{nil}.
379@end deffn
380
381@node Selecting Windows
382@section Selecting Windows
383@cindex selecting a window
384
385 When a window is selected, the buffer in the window becomes the current
386buffer, and the cursor will appear in it.
387
388@defun selected-window
389This function returns the selected window. This is the window in
390which the cursor appears and to which many commands apply.
391@end defun
392
393@defun select-window window &optional norecord
394This function makes @var{window} the selected window. The cursor then
a1401ab1
EZ
395appears in @var{window} (after redisplay). Unless @var{window} was
396already selected, @code{select-window} makes @var{window}'s buffer the
397current buffer. The return value is @var{window}.
b8d4c8d0 398
0273ca3a
MR
399Normally, @var{window}'s selected buffer is moved to the front of the
400buffer list (@pxref{The Buffer List}) and @var{window} becomes the most
401recently selected window. But if @var{norecord} is non-@code{nil}, the
402buffer list remains unchanged and @var{window} does not become the most
403recently selected one.
b8d4c8d0 404
b8d4c8d0
GM
405
406@example
407@group
408(setq w (next-window))
409(select-window w)
410 @result{} #<window 65 on windows.texi>
411@end group
412@end example
413@end defun
414
415@defmac save-selected-window forms@dots{}
416This macro records the selected frame, as well as the selected window
417of each frame, executes @var{forms} in sequence, then restores the
418earlier selected frame and windows. It also saves and restores the
419current buffer. It returns the value of the last form in @var{forms}.
420
421This macro does not save or restore anything about the sizes,
a1401ab1 422arrangement or contents of windows; therefore, if @var{forms} change
0273ca3a
MR
423them, the change persists. If the previously selected window of some
424frame is no longer live at the time of exit from @var{forms}, that
425frame's selected window is left alone. If the previously selected
426window is no longer live, then whatever window is selected at the end of
427@var{forms} remains selected. The current buffer is restored if and
428only if it is still live when exiting @var{forms}.
429
430This macro changes neither the ordering of recently selected windows nor
431the buffer list.
b8d4c8d0
GM
432@end defmac
433
434@defmac with-selected-window window forms@dots{}
0273ca3a
MR
435This macro selects @var{window}, executes @var{forms} in sequence, then
436restores the previously selected window and current buffer. The ordering
437of recently selected windows and the buffer list remain unchanged unless
438you deliberately change them within @var{forms}, for example, by calling
b8766179 439@code{select-window} with argument @var{norecord} @code{nil}.
b8d4c8d0
GM
440@end defmac
441
442@cindex finding windows
443 The following functions choose one of the windows on the screen,
444offering various criteria for the choice.
445
446@defun get-lru-window &optional frame dedicated
447This function returns the window least recently ``used'' (that is,
b8766179
MR
448selected) among a set of candidate windows. If any full-width windows
449are present, it only considers these.
b8d4c8d0 450
b8766179
MR
451The selected window is returned if it is the only candidate. A
452minibuffer window is never a candidate. A dedicated window
453(@pxref{Dedicated Windows}) is never a candidate unless the optional
454argument @var{dedicated} is non-@code{nil}.
b8d4c8d0 455
aeeedf76
MR
456The optional argument @var{frame} specifies which windows are
457considered.
b8d4c8d0
GM
458
459@itemize @bullet
460@item
461If it is @code{nil}, consider windows on the selected frame.
462@item
463If it is @code{t}, consider windows on all frames.
464@item
465If it is @code{visible}, consider windows on all visible frames.
466@item
467If it is 0, consider windows on all visible or iconified frames.
468@item
469If it is a frame, consider windows on that frame.
470@end itemize
471@end defun
472
473@defun get-largest-window &optional frame dedicated
474This function returns the window with the largest area (height times
475width). If there are no side-by-side windows, then this is the window
0273ca3a
MR
476with the most lines. A minibuffer window is never a candidate. A
477dedicated window (@pxref{Dedicated Windows}) is never a candidate unless
aeeedf76 478the optional argument @var{dedicated} is non-@code{nil}.
b8d4c8d0
GM
479
480If there are two candidate windows of the same size, this function
a1401ab1 481prefers the one that comes first in the cyclic ordering of windows,
0273ca3a 482starting from the selected window (@pxref{Cyclic Window Ordering}).
b8d4c8d0 483
aeeedf76
MR
484The optional argument @var{frame} specifies which set of windows to
485consider, see @code{get-lru-window} above.
b8d4c8d0
GM
486@end defun
487
488@cindex window that satisfies a predicate
489@cindex conditional selection of windows
490@defun get-window-with-predicate predicate &optional minibuf all-frames default
491This function returns a window satisfying @var{predicate}. It cycles
492through all visible windows using @code{walk-windows} (@pxref{Cyclic
0273ca3a
MR
493Window Ordering}), calling @var{predicate} on each one of them with that
494window as its argument. The function returns the first window for which
495@var{predicate} returns a non-@code{nil} value; if that never happens,
496it returns @var{default} (which defaults to @code{nil}).
b8d4c8d0
GM
497
498The optional arguments @var{minibuf} and @var{all-frames} specify the
499set of windows to include in the scan. See the description of
500@code{next-window} in @ref{Cyclic Window Ordering}, for details.
501@end defun
502
503@node Cyclic Window Ordering
504@comment node-name, next, previous, up
505@section Cyclic Ordering of Windows
506@cindex cyclic ordering of windows
507@cindex ordering of windows, cyclic
508@cindex window ordering, cyclic
509
510 When you use the command @kbd{C-x o} (@code{other-window}) to select
0273ca3a
MR
511some other window, it moves through the windows on the screen in a
512specific order. For any given configuration of windows, this order
513never varies. It is called the @dfn{cyclic ordering of windows}.
b8d4c8d0 514
b8766179
MR
515 For a particular frame, this ordering generally goes from top to
516bottom, and from left to right. But it may go down first or go right
517first, depending on the order in which windows were split.
b8d4c8d0
GM
518
519 If the first split was vertical (into windows one above each other),
520and then the subwindows were split horizontally, then the ordering is
521left to right in the top of the frame, and then left to right in the
522next lower part of the frame, and so on. If the first split was
523horizontal, the ordering is top to bottom in the left part, and so on.
0273ca3a
MR
524In general, within each set of siblings at any level in the window tree
525(@pxref{Window Tree}), the order is left to right, or top to bottom.
b8d4c8d0 526
5854c267 527@defun next-window &optional window minibuf all-frames
b8d4c8d0
GM
528@cindex minibuffer window, and @code{next-window}
529This function returns the window following @var{window} in the cyclic
0273ca3a 530ordering of windows. This is the window @kbd{C-x o} selects if typed
aeeedf76
MR
531when @var{window} is selected. The default for @var{window} is the
532selected window.
b8d4c8d0 533
aeeedf76
MR
534The value of the optional argument @var{minibuf} specifies whether the
535minibuffer is included in the window order. Normally, when
536@var{minibuf} is @code{nil}, the minibuffer is included only if it is
537currently ``active''; this matches the behavior of @kbd{C-x o}. (The
538minibuffer window is active while the minibuffer is in use; see
539@ref{Minibuffers}.)
b8d4c8d0 540
0273ca3a
MR
541If @var{minibuf} is @code{t}, the cyclic ordering includes the
542minibuffer window even if it is not active. If @var{minibuf} is neither
543@code{t} nor @code{nil}, the minibuffer window is not included even if
544it is active.
b8d4c8d0 545
aeeedf76
MR
546The optional argument @var{all-frames} specifies which frames to
547consider. Here are the possible values and their meanings:
b8d4c8d0
GM
548
549@table @asis
550@item @code{nil}
551Consider all the windows in @var{window}'s frame, plus the minibuffer
552used by that frame even if it lies in some other frame. If the
553minibuffer counts (as determined by @var{minibuf}), then all windows on
554all frames that share that minibuffer count too.
555
556@item @code{t}
557Consider all windows in all existing frames.
558
559@item @code{visible}
560Consider all windows in all visible frames. (To get useful results, you
561must ensure @var{window} is in a visible frame.)
562
563@item 0
564Consider all windows in all visible or iconified frames.
565
566@item a frame
567Consider all windows on that frame.
568
569@item anything else
570Consider precisely the windows in @var{window}'s frame, and no others.
571@end table
572
573This example assumes there are two windows, both displaying the
574buffer @samp{windows.texi}:
575
576@example
577@group
578(selected-window)
579 @result{} #<window 56 on windows.texi>
580@end group
581@group
582(next-window (selected-window))
583 @result{} #<window 52 on windows.texi>
584@end group
585@group
586(next-window (next-window (selected-window)))
587 @result{} #<window 56 on windows.texi>
588@end group
589@end example
5854c267 590@end defun
b8d4c8d0 591
5854c267 592@defun previous-window &optional window minibuf all-frames
b8d4c8d0
GM
593This function returns the window preceding @var{window} in the cyclic
594ordering of windows. The other arguments specify which windows to
595include in the cycle, as in @code{next-window}.
5854c267 596@end defun
b8d4c8d0
GM
597
598@deffn Command other-window count &optional all-frames
0273ca3a
MR
599This function selects another window in the cyclic ordering of windows.
600@var{count} specifies the number of windows to skip in the ordering,
601starting with the selected window, before making the selection. If
602@var{count} is a positive number, it skips @var{count} windows forwards.
603@var{count} negative means skip @minus{}@var{count} windows backwards.
604If @var{count} is zero, it does not skip any window, thus re-selecting
605the selected window. In an interactive call, @var{count} is the numeric
606prefix argument.
b8d4c8d0 607
aeeedf76 608The optional argument @var{all-frames} has the same meaning as in
b8d4c8d0 609@code{next-window}, but the @var{minibuf} argument of @code{next-window}
0273ca3a 610is always effectively @code{nil}. This function returns @code{nil}.
b8d4c8d0
GM
611@end deffn
612
613@c Emacs 19 feature
614@defun walk-windows proc &optional minibuf all-frames
615This function cycles through all windows. It calls the function
616@code{proc} once for each window, with the window as its sole
617argument.
618
619The optional arguments @var{minibuf} and @var{all-frames} specify the
0273ca3a 620set of windows to include in the walk. See @code{next-window}, above,
b8d4c8d0
GM
621for details.
622@end defun
623
624@defun window-list &optional frame minibuf window
0273ca3a 625This function returns a list of all windows on @var{frame}, starting
aeeedf76
MR
626with @var{window}. The default for @var{frame} is the selected frame;
627the default for @var{window} is the selected window.
b8d4c8d0 628
0273ca3a 629The value of @var{minibuf} specifies if the minibuffer window shall be
b8d4c8d0
GM
630included in the result list. If @var{minibuf} is @code{t}, the result
631always includes the minibuffer window. If @var{minibuf} is @code{nil}
632or omitted, that includes the minibuffer window if it is active. If
633@var{minibuf} is neither @code{nil} nor @code{t}, the result never
634includes the minibuffer window.
635@end defun
636
637@node Buffers and Windows
638@section Buffers and Windows
639@cindex examining windows
640@cindex windows, controlling precisely
641@cindex buffers, controlled in windows
642
643 This section describes low-level functions to examine windows or to
644display buffers in windows in a precisely controlled fashion.
645@iftex
646See the following section for
647@end iftex
648@ifnottex
649@xref{Displaying Buffers}, for
650@end ifnottex
651related functions that find a window to use and specify a buffer for it.
0273ca3a
MR
652The functions described there are easier to use, but they employ
653heuristics in choosing or creating a window; use the functions described
654here when you need complete control.
b8d4c8d0
GM
655
656@defun set-window-buffer window buffer-or-name &optional keep-margins
657This function makes @var{window} display @var{buffer-or-name} as its
aeeedf76
MR
658contents. It returns @code{nil}. The default for @var{window} is the
659selected window. The argument @var{buffer-or-name} must specify a
660buffer or the name of an existing buffer.
661
662@code{set-window-buffer} is the fundamental primitive for changing which
663buffer is displayed in a window, and all ways of doing that call this
664function.
b8d4c8d0
GM
665
666@example
667@group
668(set-window-buffer (selected-window) "foo")
669 @result{} nil
670@end group
671@end example
672
0273ca3a
MR
673Normally, displaying @var{buffer-or-name} in @var{window} resets the
674window's position, display margins, fringe widths, and scroll bar
a1401ab1 675settings based on the local variables of that buffer.
0273ca3a
MR
676However, if @var{keep-margins} is non-@code{nil}, display margins and
677fringe widths of @var{window} remain unchanged. @xref{Fringes}.
678
aeeedf76
MR
679@code{set-window-buffer} signals an error when @var{window} is
680@dfn{strongly} dedicated to its buffer (@pxref{Dedicated Windows}) and
681does not already display @var{buffer-or-name}.
0273ca3a 682
aeeedf76
MR
683Note that this function runs @code{window-scroll-functions} before
684running @code{window-configuration-change-hook}.
b8d4c8d0
GM
685@end defun
686
687@defvar buffer-display-count
0273ca3a 688This buffer-local variable records the number of times a buffer has been
b8d4c8d0
GM
689displayed in a window. It is incremented each time
690@code{set-window-buffer} is called for the buffer.
691@end defvar
692
693@defun window-buffer &optional window
aeeedf76
MR
694This function returns the buffer that @var{window} is displaying. The
695default for @var{window} is the selected window.
b8d4c8d0
GM
696
697@example
698@group
699(window-buffer)
700 @result{} #<buffer windows.texi>
701@end group
702@end example
703@end defun
704
520b29e7 705@defun get-buffer-window &optional buffer-or-name all-frames
b8d4c8d0
GM
706This function returns a window currently displaying
707@var{buffer-or-name}, or @code{nil} if there is none. If there are
708several such windows, then the function returns the first one in the
709cyclic ordering of windows, starting from the selected window.
710@xref{Cyclic Window Ordering}.
711
aeeedf76
MR
712The argument @var{BUFFER-OR-NAME} may be a buffer or a buffer name and
713defaults to the current buffer. The optional argument @var{all-frames}
714specifies which windows to consider:
b8d4c8d0
GM
715
716@itemize @bullet
717@item
0273ca3a 718@code{nil} means consider windows on the selected frame.
b8d4c8d0 719@item
0273ca3a 720@code{t} means consider windows on all existing frames.
b8d4c8d0 721@item
0273ca3a 722@code{visible} means consider windows on all visible frames.
b8d4c8d0 723@item
0273ca3a 7240 means consider windows on all visible or iconified frames.
b8d4c8d0 725@item
0273ca3a 726A frame means consider windows on that frame only.
b8d4c8d0 727@end itemize
0273ca3a
MR
728
729Observe that the behavior of @code{get-buffer-window} may differ from
730that of @code{next-window} (@pxref{Cyclic Window Ordering}) when
731@var{all-frames} equals @code{nil} or any value not listed here.
732Perhaps we will change @code{get-buffer-window} in the future to make it
733compatible with the other functions.
b8d4c8d0
GM
734@end defun
735
520b29e7
MR
736@defun get-buffer-window-list &optional buffer-or-name minibuf all-frames
737This function returns a list of all windows currently displaying
aeeedf76
MR
738@var{buffer-or-name}. The argument @var{buffer-or-name} may be a buffer
739or the name of an existing buffer and defaults to the current buffer.
b8d4c8d0 740
0273ca3a
MR
741The two remaining arguments work like the same-named arguments of
742@code{next-window}; they are @emph{not} like the optional arguments of
743@code{get-buffer-window}.
b8d4c8d0
GM
744@end defun
745
746@defvar buffer-display-time
747This variable records the time at which a buffer was last made visible
748in a window. It is always local in each buffer; each time
749@code{set-window-buffer} is called, it sets this variable to
750@code{(current-time)} in the specified buffer (@pxref{Time of Day}).
751When a buffer is first created, @code{buffer-display-time} starts out
752with the value @code{nil}.
753@end defvar
754
755@node Displaying Buffers
756@section Displaying Buffers in Windows
757@cindex switching to a buffer
758@cindex displaying a buffer
759
760 In this section we describe convenient functions that choose a window
761automatically and use it to display a specified buffer. These functions
762can also split an existing window in certain circumstances. We also
763describe variables that parameterize the heuristics used for choosing a
764window.
765@iftex
766See the preceding section for
767@end iftex
768@ifnottex
769@xref{Buffers and Windows}, for
770@end ifnottex
43c59a3d 771low-level primitives that give you more precise control. All of these
b8d4c8d0
GM
772functions work by calling @code{set-window-buffer}.
773
774 Do not use the functions in this section in order to make a buffer
775current so that a Lisp program can access or modify it; they are too
776drastic for that purpose, since they change the display of buffers in
777windows, which would be gratuitous and surprise the user. Instead, use
778@code{set-buffer} and @code{save-current-buffer} (@pxref{Current
779Buffer}), which designate buffers as current for programmed access
780without affecting the display of buffers in windows.
781
782@deffn Command switch-to-buffer buffer-or-name &optional norecord
783This function makes @var{buffer-or-name} the current buffer, and also
784displays the buffer in the selected window. This means that a human can
785see the buffer and subsequent keyboard commands will apply to it.
786Contrast this with @code{set-buffer}, which makes @var{buffer-or-name}
aeeedf76 787the current buffer but does not display it in the selected window;
a1401ab1 788see @ref{Current Buffer}.
b8d4c8d0 789
0273ca3a
MR
790If @var{buffer-or-name} is @code{nil}, @code{switch-to-buffer} chooses a
791buffer using @code{other-buffer}. If @var{buffer-or-name} is a string
792that does not identify an existing buffer, then a new buffer by that
793name is created. The major mode for the new buffer is set according to
4e3b4528 794the variable @code{major-mode}; see @ref{Auto Major Mode}.
b8d4c8d0 795
b8766179
MR
796When the selected window is the minibuffer window or is strongly
797dedicated to its buffer (@pxref{Dedicated Windows}), this function calls
86ab855a
MR
798@code{pop-to-buffer} (see below) to display the buffer in some other
799window.
800
b8d4c8d0
GM
801Normally the specified buffer is put at the front of the buffer list
802(both the selected frame's buffer list and the frame-independent buffer
803list). This affects the operation of @code{other-buffer}. However, if
804@var{norecord} is non-@code{nil}, this is not done. @xref{The Buffer
805List}.
806
807The @code{switch-to-buffer} function is often used interactively, as
808the binding of @kbd{C-x b}. It is also used frequently in programs. It
809returns the buffer that it switched to.
810@end deffn
811
812The next two functions are similar to @code{switch-to-buffer}, except
813for the described features.
814
815@deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
af1a5cd5 816This function makes the buffer specified by @var{buffer-or-name} current
b8766179
MR
817and displays it in a window not currently selected, using the function
818@code{pop-to-buffer} (see below).
b8d4c8d0
GM
819
820The currently selected window is absolutely never used to do the job.
b8766179
MR
821If the selected window already displays @var{buffer-or-name}, then it
822continues to do so, but another window is nonetheless found to display
823it in as well.
b8d4c8d0
GM
824
825This function updates the buffer list just like @code{switch-to-buffer}
826unless @var{norecord} is non-@code{nil}.
827@end deffn
828
35a30759
N
829@defun pop-to-buffer buffer-or-name &optional other-window norecord
830This function makes @var{buffer-or-name} the current buffer and switches
52a94b85
MR
831to it in some window, preferably not the window previously selected.
832The ``popped-to'' window becomes the selected window. Its frame is
b8766179
MR
833given the X server's focus, if possible; see @ref{Input Focus}. The
834return value is the buffer that was switched to.
0273ca3a
MR
835
836If @var{buffer-or-name} is @code{nil}, that means to choose some other
837buffer, but you don't specify which. If @var{buffer-or-name} is a
838string that does not name an existing buffer, a buffer by that name is
839created. The major mode for the new buffer is set according to the
4e3b4528 840variable @code{major-mode}. @xref{Auto Major Mode}.
b8d4c8d0 841
b8766179
MR
842If either of the variables @code{display-buffer-reuse-frames} or
843@code{pop-up-frames} is non-@code{nil}, @code{pop-to-buffer} looks for a
844window in any visible frame already displaying the buffer; if there is
845one, it selects and returns that window. If no such window exists and
846@code{pop-up-frames} is non-@code{nil}, it creates a new frame and
847displays the buffer in it. Otherwise, @code{pop-to-buffer} operates
848entirely within the selected frame. (If the selected frame has just a
849minibuffer, @code{pop-to-buffer} operates within the most recently
850selected frame that was not just a minibuffer.)
b8d4c8d0 851
0273ca3a
MR
852If the variable @code{pop-up-windows} is non-@code{nil}, windows may be
853split to create a new window that is different from the original window.
a1401ab1 854For details, see @ref{Choosing Window}.
b8d4c8d0
GM
855
856If @var{other-window} is non-@code{nil}, @code{pop-to-buffer} finds or
857creates another window even if @var{buffer-or-name} is already visible
858in the selected window. Thus @var{buffer-or-name} could end up
859displayed in two windows. On the other hand, if @var{buffer-or-name} is
860already displayed in the selected window and @var{other-window} is
0273ca3a
MR
861@code{nil}, then the selected window is considered sufficient for
862displaying @var{buffer-or-name}, so that nothing needs to be done.
b8d4c8d0
GM
863
864All the variables that affect @code{display-buffer} affect
865@code{pop-to-buffer} as well. @xref{Choosing Window}.
866
b8d4c8d0
GM
867This function updates the buffer list just like @code{switch-to-buffer}
868unless @var{norecord} is non-@code{nil}.
35a30759 869@end defun
b8d4c8d0 870
520b29e7 871@deffn Command replace-buffer-in-windows &optional buffer-or-name
da86d54b
EZ
872This function replaces @var{buffer-or-name} in all windows displaying
873it with some other buffer. It uses @code{other-buffer} to choose the
874other buffer. In the usual applications of this function, you
b8d4c8d0
GM
875don't care which other buffer is used; you just want to make sure that
876@var{buffer-or-name} is no longer displayed.
877
aeeedf76
MR
878The argument @var{buffer-or-name} may be a buffer or the name of an
879existing buffer and defaults to the current buffer.
520b29e7 880
0273ca3a
MR
881If a window displaying @var{buffer-or-name} is dedicated
882(@pxref{Dedicated Windows}), and is not the only window on its frame,
883that window is deleted. If that window is the only window on its frame
884and there are other frames left, the window's frame is deleted too. If
885there are no other frames left, some other buffer is displayed in that
886window.
250959e0 887
b8d4c8d0
GM
888This function returns @code{nil}.
889@end deffn
890
891@node Choosing Window
892@section Choosing a Window for Display
893
894 This section describes the basic facility that chooses a window to
0273ca3a 895display a buffer in---@code{display-buffer}. Higher-level functions and
a1401ab1 896commands, like @code{switch-to-buffer} and @code{pop-to-buffer}, use this
0273ca3a
MR
897subroutine. Here we describe how to use @code{display-buffer} and how
898to customize it.
b8d4c8d0
GM
899
900@deffn Command display-buffer buffer-or-name &optional not-this-window frame
52a94b85
MR
901This command makes @var{buffer-or-name} appear in some window, but it
902does not select that window and does not make the buffer specified by
903@var{buffer-or-name} current. The identity of the selected window is
aeeedf76
MR
904unaltered by this function. The argument @var{buffer-or-name} must be a
905buffer or the name of an existing buffer.
b8d4c8d0 906
0273ca3a
MR
907@var{not-this-window} non-@code{nil} means to display the specified
908buffer in a window other than the selected one, even if it is already
909displayed in the selected window. This can cause the buffer to appear
910in two windows at once. Otherwise, if @var{buffer-or-name} is already
911being displayed in any window, that is good enough, so this function
912does nothing.
b8d4c8d0
GM
913
914@code{display-buffer} returns the window chosen to display
915@var{buffer-or-name}.
916
aeeedf76
MR
917If the optional argument @var{frame} is non-@code{nil}, it specifies
918which frames to check when deciding whether the buffer is already
919displayed. If the buffer is already displayed in some window on one of
920these frames, @code{display-buffer} simply returns that window. Here
921are the possible values of @var{frame}:
b8d4c8d0
GM
922
923@itemize @bullet
924@item
0273ca3a 925@code{nil} means consider windows on the selected frame.
b8d4c8d0
GM
926(Actually, the last non-minibuffer frame.)
927@item
0273ca3a 928@code{t} means consider windows on all frames.
b8d4c8d0 929@item
0273ca3a 930@code{visible} means consider windows on all visible frames.
b8d4c8d0 931@item
0273ca3a 9320 means consider windows on all visible or iconified frames.
b8d4c8d0 933@item
0273ca3a 934A frame means consider windows on that frame only.
b8d4c8d0
GM
935@end itemize
936
937Precisely how @code{display-buffer} finds or creates a window depends on
938the variables described below.
939@end deffn
940
52a94b85
MR
941@defopt display-buffer-reuse-frames
942If this variable is non-@code{nil}, @code{display-buffer} searches
b8766179
MR
943visible and iconified frames for a window displaying
944@var{buffer-or-name}. If there is such a window, @code{display-buffer}
945makes that window's frame visible and raises it if necessary, and
946returns the window. If there is no such window or
52a94b85
MR
947@code{display-buffer-reuse-frames} is @code{nil}, the behavior of
948@code{display-buffer} is determined by the variables described next.
949@end defopt
950
951@defopt pop-up-windows
952This variable specifies whether @code{display-buffer} is allowed to
d3c0c321
MR
953split (@pxref{Splitting Windows}) an existing window. If this variable
954is non-@code{nil}, @code{display-buffer} tries to split the largest or
955least recently used window on the selected frame. (If the selected
956frame is a minibuffer-only frame, @code{display-buffer} tries to split a
957window on another frame instead.) If this variable is @code{nil} or the
b6474f84 958variable @code{pop-up-frames} (see below) is non-@code{nil},
52a94b85
MR
959@code{display-buffer} does not split any window.
960@end defopt
961
01f17ae2 962@defopt split-window-preferred-function
d3c0c321
MR
963This variable must specify a function with one argument, which is a
964window. The @code{display-buffer} routines will call this function with
965one or more candidate windows when they look for a window to split. The
966function is expected to split that window and return the new window. If
967the function returns @code{nil}, this means that the argument window
968cannot (or shall not) be split.
969
970The default value of @code{split-window-preferred-function} is the
714c3541 971function @code{split-window-sensibly} described below. If you
d3c0c321
MR
972customize this option, bear in mind that the @code{display-buffer}
973routines may call your function up to two times when trying to split a
974window. The argument of the first call is the largest window on the
975chosen frame (as returned by @code{get-largest-window}). If that call
976fails to return a live window, your function is called a second time
977with the least recently used window on that frame (as returned by
978@code{get-lru-window}).
979
714c3541
MR
980The function specified by this option may try to split any other window
981instead of the argument window. Note that the window selected at the
982time @code{display-buffer} was invoked is still selected when your
d3c0c321
MR
983function is called. Hence, you can split the selected window (instead
984of the largest or least recently used one) by simply ignoring the window
985argument in the body of your function. You can even choose to not split
986any window as long as the return value of your function specifies a live
714c3541
MR
987window or @code{nil}, but you are not encouraged to do so
988unconditionally. If you want @code{display-buffer} to never split any
989windows, set @code{pop-up-windows} to @code{nil}.
01f17ae2 990@end defopt
43c59a3d 991
714c3541 992@defun split-window-sensibly window
d3c0c321
MR
993This function takes a window as argument and tries to split that window
994in a suitable way. The two variables described next are useful for
995tuning the behavior of this function.
996@end defun
997
b8d4c8d0 998@defopt split-height-threshold
372a93ac
MR
999This variable specifies whether @code{split-window-sensibly} may split
1000windows vertically. If it is an integer, @code{split-window-sensibly}
1001tries to vertically split a window only if it has at least this many
1002lines. If the window has less lines, splitting fails, or the value of
1003this variable is @code{nil}, @code{split-window-sensibly} will try to
1004split the window horizontally, subject to restrictions of
714c3541
MR
1005@code{split-width-threshold} (see below). If splitting horizontally
1006fails too and the window is the only window on its frame,
1007@code{split-window-sensibly} will try to split the window vertically
1008disregarding the value of @code{split-height-threshold}. If this fails
1009as well, @code{split-window-sensibly} returns @code{nil}.
1010
1011@code{split-window-sensibly} does not split vertically a window whose
1012height is fixed (@pxref{Resizing Windows}). Also, it vertically splits
1013a window only if the space taken up by that window can accommodate two
1014windows one above the other that are both at least
1015@code{window-min-height} lines tall. Moreover, if the window that shall
1016be split has a mode line, @code{split-window-sensibly} does not split
7ee6a1d3 1017the window unless the new window can accommodate a mode line too.
43c59a3d
EZ
1018@end defopt
1019
1020@defopt split-width-threshold
372a93ac
MR
1021This variable specifies whether @code{split-window-sensibly} may split
1022windows horizontally. If it is an integer, @code{split-window-sensibly}
1023tries to horizontally split a window only if it has at least this many
1024columns. If it is @code{nil}, @code{split-window-sensibly} will not
1025split the window horizontally. (It still might split the window
714c3541
MR
1026vertically, though, see above.)
1027
1028@code{split-window-sensibly} does not split horizontally a window if
d3c0c321 1029that window's width is fixed (@pxref{Resizing Windows}). Also, it
714c3541 1030horizontally splits a window only if the space that window takes up can
d3c0c321
MR
1031accommodate two windows side by side that are both at least
1032@code{window-min-width} columns wide.
b8d4c8d0
GM
1033@end defopt
1034
1035@defopt even-window-heights
403b14d1 1036This variable specifies whether @code{display-buffer} should even out
52a94b85
MR
1037window heights if the buffer gets displayed in an existing window, above
1038or beneath another window. If @code{even-window-heights} is
1039non-@code{nil}, the default, window heights will be evened out. If
1040either of the involved window has fixed height (@pxref{Resizing
1041Windows}) or @code{even-window-heights} is @code{nil}, the original
1042window heights will be left alone.
b8d4c8d0
GM
1043@end defopt
1044
1045@c Emacs 19 feature
1046@defopt pop-up-frames
b8766179
MR
1047This variable specifies whether @code{display-buffer} should make new
1048frames. If it is non-@code{nil}, @code{display-buffer} looks for a
1049window already displaying @var{buffer-or-name} on any visible or
1050iconified frame. If it finds such a window, it makes that window's
1051frame visible and raises it if necessary, and returns the window.
1052Otherwise it makes a new frame, unless the variable's value is
1053@code{graphic-only} and the selected frame is not on a graphic display.
1054@xref{Frames}, for more information.
b8d4c8d0 1055
0273ca3a
MR
1056Note that the value of @code{pop-up-windows} does not matter if
1057@code{pop-up-frames} is non-@code{nil}. If @code{pop-up-frames} is
1058@code{nil}, then @code{display-buffer} either splits a window or reuses
1059one.
b8d4c8d0
GM
1060@end defopt
1061
1062@c Emacs 19 feature
1063@defopt pop-up-frame-function
1064This variable specifies how to make a new frame if @code{pop-up-frames}
1065is non-@code{nil}.
1066
b8766179 1067The value of this variable must be a function of no arguments. When
b8d4c8d0 1068@code{display-buffer} makes a new frame, it does so by calling that
b8766179
MR
1069function, which should return a frame. The default value of this
1070variable is a function that creates a frame using the parameters
1071specified by @code{pop-up-frame-alist} described next.
b8d4c8d0
GM
1072@end defopt
1073
1074@defopt pop-up-frame-alist
9f822178
MR
1075This variable holds an alist specifying frame parameters used by the
1076default value of @code{pop-up-frame-function} for making new frames.
1077@xref{Frame Parameters}, for more information about frame parameters.
b8d4c8d0
GM
1078@end defopt
1079
1080@defopt special-display-buffer-names
0273ca3a
MR
1081A list of buffer names identifying buffers that should be displayed
1082specially. If the name of @var{buffer-or-name} is in this list,
1083@code{display-buffer} handles the buffer specially. By default, special
1084display means to give the buffer a dedicated frame.
b8d4c8d0 1085
52a94b85
MR
1086If an element is a list, instead of a string, then the @sc{car} of that
1087list is the buffer name, and the rest of that list says how to create
1088the frame. There are two possibilities for the rest of that list (its
1089@sc{cdr}): It can be an alist, specifying frame parameters, or it can
b8d4c8d0
GM
1090contain a function and arguments to give to it. (The function's first
1091argument is always the buffer to be displayed; the arguments from the
1092list come after that.)
1093
1094For example:
1095
1096@example
1097(("myfile" (minibuffer) (menu-bar-lines . 0)))
1098@end example
1099
1100@noindent
1101specifies to display a buffer named @samp{myfile} in a dedicated frame
1102with specified @code{minibuffer} and @code{menu-bar-lines} parameters.
1103
1104The list of frame parameters can also use the phony frame parameters
1105@code{same-frame} and @code{same-window}. If the specified frame
1106parameters include @code{(same-window . @var{value})} and @var{value}
1107is non-@code{nil}, that means to display the buffer in the current
1108selected window. Otherwise, if they include @code{(same-frame .
1109@var{value})} and @var{value} is non-@code{nil}, that means to display
1110the buffer in a new window in the currently selected frame.
1111@end defopt
1112
1113@defopt special-display-regexps
0273ca3a 1114A list of regular expressions specifying buffers that should be
b8d4c8d0
GM
1115displayed specially. If the buffer's name matches any of the regular
1116expressions in this list, @code{display-buffer} handles the buffer
0273ca3a
MR
1117specially. By default, special display means to give the buffer a
1118dedicated frame.
b8d4c8d0
GM
1119
1120If an element is a list, instead of a string, then the @sc{car} of the
1121list is the regular expression, and the rest of the list says how to
0273ca3a 1122create the frame. See @code{special-display-buffer-names} above.
b8d4c8d0
GM
1123@end defopt
1124
1125@defun special-display-p buffer-name
1126This function returns non-@code{nil} if displaying a buffer
1127named @var{buffer-name} with @code{display-buffer} would
1128create a special frame. The value is @code{t} if it would
1129use the default frame parameters, or else the specified list
1130of frame parameters.
1131@end defun
1132
01f17ae2 1133@defopt special-display-function
b8d4c8d0
GM
1134This variable holds the function to call to display a buffer specially.
1135It receives the buffer as an argument, and should return the window in
0273ca3a
MR
1136which it is displayed. The default value of this variable is
1137@code{special-display-popup-frame}, see below.
01f17ae2 1138@end defopt
b8d4c8d0
GM
1139
1140@defun special-display-popup-frame buffer &optional args
0273ca3a
MR
1141This function tries to make @var{buffer} visible in a frame of its own.
1142If @var{buffer} is already displayed in some window, it makes that
1143window's frame visible and raises it. Otherwise, it creates a frame
1144that is dedicated to @var{buffer}. The return value is the window used
1145to display @var{buffer}.
b8d4c8d0
GM
1146
1147If @var{args} is an alist, it specifies frame parameters for the new
0273ca3a
MR
1148frame. If @var{args} is a list whose @sc{car} is a symbol, then
1149@code{(car @var{args})} is called as a function to actually create and
1150set up the frame; it is called with @var{buffer} as first argument, and
1151@code{(cdr @var{args})} as additional arguments.
b8d4c8d0
GM
1152
1153This function always uses an existing window displaying @var{buffer},
1154whether or not it is in a frame of its own; but if you set up the above
1155variables in your init file, before @var{buffer} was created, then
1156presumably the window was previously made by this function.
1157@end defun
1158
1159@defopt special-display-frame-alist
1160@anchor{Definition of special-display-frame-alist}
1161This variable holds frame parameters for
1162@code{special-display-popup-frame} to use when it creates a frame.
1163@end defopt
1164
1165@defopt same-window-buffer-names
1166A list of buffer names for buffers that should be displayed in the
1167selected window. If the buffer's name is in this list,
1168@code{display-buffer} handles the buffer by switching to it in the
1169selected window.
1170@end defopt
1171
1172@defopt same-window-regexps
1173A list of regular expressions that specify buffers that should be
1174displayed in the selected window. If the buffer's name matches any of
1175the regular expressions in this list, @code{display-buffer} handles the
1176buffer by switching to it in the selected window.
1177@end defopt
1178
1179@defun same-window-p buffer-name
1180This function returns @code{t} if displaying a buffer
1181named @var{buffer-name} with @code{display-buffer} would
1182put it in the selected window.
1183@end defun
1184
1185@c Emacs 19 feature
01f17ae2 1186@defopt display-buffer-function
b8d4c8d0
GM
1187This variable is the most flexible way to customize the behavior of
1188@code{display-buffer}. If it is non-@code{nil}, it should be a function
1189that @code{display-buffer} calls to do the work. The function should
1190accept two arguments, the first two arguments that @code{display-buffer}
1191received. It should choose or create a window, display the specified
1192buffer in it, and then return the window.
1193
52a94b85
MR
1194This variable takes precedence over all the other options described
1195above.
01f17ae2 1196@end defopt
b8d4c8d0 1197
52a94b85 1198If all options described above fail to produce a suitable window,
0273ca3a
MR
1199@code{display-buffer} tries to reuse an existing window. As a last
1200resort, it will try to display @var{buffer-or-name} on a separate frame.
1201In that case, the value of @code{pop-up-frames} is disregarded.
1202
1203@node Dedicated Windows
1204@section Dedicated Windows
1205@cindex dedicated window
1206
1207Functions for displaying a buffer can be told to not use specific
df006536 1208windows by marking these windows as @dfn{dedicated} to their buffers.
0273ca3a
MR
1209@code{display-buffer} (@pxref{Choosing Window}) never uses a dedicated
1210window for displaying another buffer in it. @code{get-lru-window} and
1211@code{get-largest-window} (@pxref{Selecting Windows}) do not consider
1212dedicated windows as candidates when their @var{dedicated} argument is
1213non-@code{nil}. The behavior of @code{set-window-buffer}
1214(@pxref{Buffers and Windows}) with respect to dedicated windows is
1215slightly different, see below.
1216
1217When @code{delete-windows-on} (@pxref{Deleting Windows}) wants to delete
1218a dedicated window and that window is the only window on its frame, it
1219deletes the window's frame too, provided there are other frames left.
1220@code{replace-buffer-in-windows} (@pxref{Displaying Buffers}) tries to
1221delete all dedicated windows showing its buffer argument. When such a
1222window is the only window on its frame, that frame is deleted, provided
1223there are other frames left. If there are no more frames left, some
1224other buffer is displayed in the window, and the window is marked as
1225non-dedicated.
1226
1227When you kill a buffer (@pxref{Killing Buffers}) displayed in a
1228dedicated window, any such window usually gets deleted too, since
1229@code{kill-buffer} calls @code{replace-buffer-in-windows} for cleaning
1230up windows. Burying a buffer (@pxref{The Buffer List}) deletes the
b8766179
MR
1231selected window if it is dedicated to that buffer. If, however, that
1232window is the only window on its frame, @code{bury-buffer} displays
1233another buffer in it and iconifies the frame.
250959e0
MR
1234
1235@defun window-dedicated-p &optional window
52a94b85
MR
1236This function returns non-@code{nil} if @var{window} is dedicated to its
1237buffer and @code{nil} otherwise. More precisely, the return value is
1238the value assigned by the last call of @code{set-window-dedicated-p} for
1239@var{window} or @code{nil} if that function was never called with
aeeedf76
MR
1240@var{window} as its argument. The default for @var{window} is the
1241selected window.
b8d4c8d0
GM
1242@end defun
1243
1244@defun set-window-dedicated-p window flag
52a94b85
MR
1245This function marks @var{window} as dedicated to its buffer if
1246@var{flag} is non-@code{nil}, and non-dedicated otherwise.
52a94b85 1247
0273ca3a
MR
1248As a special case, if @var{flag} is @code{t}, @var{window} becomes
1249@dfn{strongly} dedicated to its buffer. @code{set-window-buffer}
1250signals an error when the window it acts upon is strongly dedicated to
1251its buffer and does not already display the buffer it is asked to
b8766179
MR
1252display. Other functions do not treat @code{t} differently from any
1253non-@code{nil} value.
0273ca3a 1254@end defun
52a94b85 1255
b8d4c8d0
GM
1256@node Window Point
1257@section Windows and Point
1258@cindex window position
1259@cindex window point
1260@cindex position in window
1261@cindex point in window
1262
0273ca3a
MR
1263 Each window has its own value of point (@pxref{Point}), independent of
1264the value of point in other windows displaying the same buffer. This
1265makes it useful to have multiple windows showing one buffer.
b8d4c8d0
GM
1266
1267@itemize @bullet
1268@item
1269The window point is established when a window is first created; it is
1270initialized from the buffer's point, or from the window point of another
1271window opened on the buffer if such a window exists.
1272
1273@item
1274Selecting a window sets the value of point in its buffer from the
1275window's value of point. Conversely, deselecting a window sets the
1276window's value of point from that of the buffer. Thus, when you switch
1277between windows that display a given buffer, the point value for the
1278selected window is in effect in the buffer, while the point values for
1279the other windows are stored in those windows.
1280
1281@item
1282As long as the selected window displays the current buffer, the window's
1283point and the buffer's point always move together; they remain equal.
1284@end itemize
1285
b8d4c8d0 1286@cindex cursor
af1a5cd5 1287 As far as the user is concerned, point is where the cursor is, and
b8d4c8d0
GM
1288when the user switches to another buffer, the cursor jumps to the
1289position of point in that buffer.
1290
1291@defun window-point &optional window
1292This function returns the current position of point in @var{window}.
1293For a nonselected window, this is the value point would have (in that
aeeedf76
MR
1294window's buffer) if that window were selected. The default for
1295@var{window} is the selected window.
b8d4c8d0
GM
1296
1297When @var{window} is the selected window and its buffer is also the
1298current buffer, the value returned is the same as point in that buffer.
0273ca3a
MR
1299Strictly speaking, it would be more correct to return the ``top-level''
1300value of point, outside of any @code{save-excursion} forms. But that
1301value is hard to find.
b8d4c8d0
GM
1302@end defun
1303
1304@defun set-window-point window position
1305This function positions point in @var{window} at position
1306@var{position} in @var{window}'s buffer. It returns @var{position}.
1307
1308If @var{window} is selected, and its buffer is current,
1309this simply does @code{goto-char}.
1310@end defun
1311
86ab855a
MR
1312@defvar window-point-insertion-type
1313This variable specifies the marker insertion type (@pxref{Marker
1314Insertion Types}) of @code{window-point}. The default is @code{nil},
1315so @code{window-point} will stay behind text inserted there.
1316@end defvar
1317
0273ca3a
MR
1318@node Window Start and End
1319@section The Window Start and End Positions
b8d4c8d0
GM
1320@cindex window start position
1321
0273ca3a 1322 Each window maintains a marker used to keep track of a buffer position
b8d4c8d0
GM
1323that specifies where in the buffer display should start. This position
1324is called the @dfn{display-start} position of the window (or just the
1325@dfn{start}). The character after this position is the one that appears
1326at the upper left corner of the window. It is usually, but not
1327inevitably, at the beginning of a text line.
1328
431b78c9
RS
1329 After switching windows or buffers, and in some other cases, if the
1330window start is in the middle of a line, Emacs adjusts the window
1331start to the start of a line. This prevents certain operations from
1332leaving the window start at a meaningless point within a line. This
1333feature may interfere with testing some Lisp code by executing it
1334using the commands of Lisp mode, because they trigger this
1335readjustment. To test such code, put it into a command and bind the
1336command to a key.
1337
b8d4c8d0
GM
1338@defun window-start &optional window
1339@cindex window top line
1340This function returns the display-start position of window
1341@var{window}. If @var{window} is @code{nil}, the selected window is
1342used. For example,
1343
1344@example
1345@group
1346(window-start)
1347 @result{} 7058
1348@end group
1349@end example
1350
1351When you create a window, or display a different buffer in it, the
1352display-start position is set to a display-start position recently used
0273ca3a
MR
1353for the same buffer, or to @code{point-min} if the buffer doesn't have
1354any.
b8d4c8d0
GM
1355
1356Redisplay updates the window-start position (if you have not specified
0273ca3a
MR
1357it explicitly since the previous redisplay)---to make sure point appears
1358on the screen. Nothing except redisplay automatically changes the
1359window-start position; if you move point, do not expect the window-start
1360position to change in response until after the next redisplay.
b8d4c8d0
GM
1361
1362For a realistic example of using @code{window-start}, see the
1363description of @code{count-lines}. @xref{Definition of count-lines}.
1364@end defun
1365
0273ca3a 1366@cindex window end position
b8d4c8d0 1367@defun window-end &optional window update
0273ca3a 1368This function returns the position where display of its buffer ends in
aeeedf76 1369@var{window}. The default for @var{window} is the selected window.
b8d4c8d0
GM
1370
1371Simply changing the buffer text or moving point does not update the
1372value that @code{window-end} returns. The value is updated only when
1373Emacs redisplays and redisplay completes without being preempted.
1374
1375If the last redisplay of @var{window} was preempted, and did not finish,
1376Emacs does not know the position of the end of display in that window.
1377In that case, this function returns @code{nil}.
1378
1379If @var{update} is non-@code{nil}, @code{window-end} always returns an
0273ca3a
MR
1380up-to-date value for where display ends, based on the current
1381@code{window-start} value. If a previously saved value of that position
1382is still valid, @code{window-end} returns that value; otherwise it
1383computes the correct value by scanning the buffer text.
b8d4c8d0
GM
1384
1385Even if @var{update} is non-@code{nil}, @code{window-end} does not
1386attempt to scroll the display if point has moved off the screen, the
1387way real redisplay would do. It does not alter the
1388@code{window-start} value. In effect, it reports where the displayed
1389text will end if scrolling is not required.
1390@end defun
1391
1392@defun set-window-start window position &optional noforce
1393This function sets the display-start position of @var{window} to
1394@var{position} in @var{window}'s buffer. It returns @var{position}.
1395
1396The display routines insist that the position of point be visible when a
1397buffer is displayed. Normally, they change the display-start position
1398(that is, scroll the window) whenever necessary to make point visible.
1399However, if you specify the start position with this function using
1400@code{nil} for @var{noforce}, it means you want display to start at
1401@var{position} even if that would put the location of point off the
1402screen. If this does place point off screen, the display routines move
1403point to the left margin on the middle line in the window.
1404
431b78c9
RS
1405For example, if point @w{is 1} and you set the start of the window
1406@w{to 37}, the start of the next line, point will be ``above'' the top
1407of the window. The display routines will automatically move point if
1408it is still 1 when redisplay occurs. Here is an example:
b8d4c8d0
GM
1409
1410@example
1411@group
1412;; @r{Here is what @samp{foo} looks like before executing}
1413;; @r{the @code{set-window-start} expression.}
1414@end group
1415
1416@group
1417---------- Buffer: foo ----------
1418@point{}This is the contents of buffer foo.
14192
14203
14214
14225
14236
1424---------- Buffer: foo ----------
1425@end group
1426
1427@group
1428(set-window-start
1429 (selected-window)
431b78c9
RS
1430 (save-excursion
1431 (goto-char 1)
1432 (forward-line 1)
1433 (point)))
1434@result{} 37
b8d4c8d0
GM
1435@end group
1436
1437@group
1438;; @r{Here is what @samp{foo} looks like after executing}
1439;; @r{the @code{set-window-start} expression.}
1440---------- Buffer: foo ----------
b8d4c8d0
GM
14412
14423
1443@point{}4
14445
14456
1446---------- Buffer: foo ----------
1447@end group
1448@end example
1449
1450If @var{noforce} is non-@code{nil}, and @var{position} would place point
1451off screen at the next redisplay, then redisplay computes a new window-start
1452position that works well with point, and thus @var{position} is not used.
1453@end defun
1454
1455@defun pos-visible-in-window-p &optional position window partially
1456This function returns non-@code{nil} if @var{position} is within the
1457range of text currently visible on the screen in @var{window}. It
0273ca3a
MR
1458returns @code{nil} if @var{position} is scrolled vertically out of view.
1459Locations that are partially obscured are not considered visible unless
1460@var{partially} is non-@code{nil}. The argument @var{position} defaults
1461to the current position of point in @var{window}; @var{window}, to the
1462selected window. If @var{position} is @code{t}, that means to check the
1463last visible position in @var{window}.
b8d4c8d0
GM
1464
1465The @code{pos-visible-in-window-p} function considers only vertical
1466scrolling. If @var{position} is out of view only because @var{window}
1467has been scrolled horizontally, @code{pos-visible-in-window-p} returns
1468non-@code{nil} anyway. @xref{Horizontal Scrolling}.
1469
1470If @var{position} is visible, @code{pos-visible-in-window-p} returns
1471@code{t} if @var{partially} is @code{nil}; if @var{partially} is
0273ca3a 1472non-@code{nil}, and the character following @var{position} is fully
b8d4c8d0
GM
1473visible, it returns a list of the form @code{(@var{x} @var{y})}, where
1474@var{x} and @var{y} are the pixel coordinates relative to the top left
0273ca3a
MR
1475corner of the window; otherwise it returns an extended list of the form
1476@code{(@var{x} @var{y} @var{rtop} @var{rbot} @var{rowh} @var{vpos})},
1477where @var{rtop} and @var{rbot} specify the number of off-window pixels
1478at the top and bottom of the row at @var{position}, @var{rowh} specifies
1479the visible height of that row, and @var{vpos} specifies the vertical
1480position (zero-based row number) of that row.
b8d4c8d0
GM
1481
1482Here is an example:
1483
1484@example
1485@group
1486;; @r{If point is off the screen now, recenter it now.}
1487(or (pos-visible-in-window-p
1488 (point) (selected-window))
1489 (recenter 0))
1490@end group
1491@end example
1492@end defun
1493
1494@defun window-line-height &optional line window
aeeedf76
MR
1495This function returns the height of text line @var{line} in
1496@var{window}. If @var{line} is one of @code{header-line} or
1497@code{mode-line}, @code{window-line-height} returns information about
1498the corresponding line of the window. Otherwise, @var{line} is a text
1499line number starting from 0. A negative number counts from the end of
1500the window. The default for @var{line} is the current line in
1501@var{window}; the default for @var{window} is the selected window.
b8d4c8d0
GM
1502
1503If the display is not up to date, @code{window-line-height} returns
1504@code{nil}. In that case, @code{pos-visible-in-window-p} may be used
1505to obtain related information.
1506
1507If there is no line corresponding to the specified @var{line},
1508@code{window-line-height} returns @code{nil}. Otherwise, it returns
1509a list @code{(@var{height} @var{vpos} @var{ypos} @var{offbot})},
1510where @var{height} is the height in pixels of the visible part of the
1511line, @var{vpos} and @var{ypos} are the vertical position in lines and
1512pixels of the line relative to the top of the first text line, and
1513@var{offbot} is the number of off-window pixels at the bottom of the
1514text line. If there are off-window pixels at the top of the (first)
1515text line, @var{ypos} is negative.
1516@end defun
1517
1518@node Textual Scrolling
1519@section Textual Scrolling
1520@cindex textual scrolling
1521@cindex scrolling textually
1522
1523 @dfn{Textual scrolling} means moving the text up or down through a
1524window. It works by changing the value of the window's display-start
1525location. It may also change the value of @code{window-point} to keep
1526point on the screen.
1527
1528 Textual scrolling was formerly called ``vertical scrolling,'' but we
1529changed its name to distinguish it from the new vertical fractional
1530scrolling feature (@pxref{Vertical Scrolling}).
1531
1532 In the commands @code{scroll-up} and @code{scroll-down}, the directions
1533``up'' and ``down'' refer to the motion of the text in the buffer at which
1534you are looking through the window. Imagine that the text is
1535written on a long roll of paper and that the scrolling commands move the
1536paper up and down. Thus, if you are looking at text in the middle of a
1537buffer and repeatedly call @code{scroll-down}, you will eventually see
1538the beginning of the buffer.
1539
1540 Some people have urged that the opposite convention be used: they
1541imagine that the window moves over text that remains in place. Then
1542``down'' commands would take you to the end of the buffer. This view is
1543more consistent with the actual relationship between windows and the
1544text in the buffer, but it is less like what the user sees. The
1545position of a window on the terminal does not move, and short scrolling
1546commands clearly move the text up or down on the screen. We have chosen
1547names that fit the user's point of view.
1548
1549 The textual scrolling functions (aside from
1550@code{scroll-other-window}) have unpredictable results if the current
1551buffer is different from the buffer that is displayed in the selected
1552window. @xref{Current Buffer}.
1553
1554 If the window contains a row which is taller than the height of the
1555window (for example in the presence of a large image), the scroll
b8766179
MR
1556functions will adjust the window's vertical scroll position to scroll
1557the partially visible row. To disable this feature, Lisp code may bind
1558the variable @code{auto-window-vscroll} to @code{nil} (@pxref{Vertical
1559Scrolling}).
b8d4c8d0
GM
1560
1561@deffn Command scroll-up &optional count
1562This function scrolls the text in the selected window upward
1563@var{count} lines. If @var{count} is negative, scrolling is actually
1564downward.
1565
1566If @var{count} is @code{nil} (or omitted), then the length of scroll
1567is @code{next-screen-context-lines} lines less than the usable height of
1568the window (not counting its mode line).
1569
1570@code{scroll-up} returns @code{nil}, unless it gets an error
1571because it can't scroll any further.
1572@end deffn
1573
1574@deffn Command scroll-down &optional count
1575This function scrolls the text in the selected window downward
1576@var{count} lines. If @var{count} is negative, scrolling is actually
1577upward.
1578
1579If @var{count} is omitted or @code{nil}, then the length of the scroll
1580is @code{next-screen-context-lines} lines less than the usable height of
1581the window (not counting its mode line).
1582
1583@code{scroll-down} returns @code{nil}, unless it gets an error because
1584it can't scroll any further.
1585@end deffn
1586
1587@deffn Command scroll-other-window &optional count
1588This function scrolls the text in another window upward @var{count}
1589lines. Negative values of @var{count}, or @code{nil}, are handled
1590as in @code{scroll-up}.
1591
1592You can specify which buffer to scroll by setting the variable
1593@code{other-window-scroll-buffer} to a buffer. If that buffer isn't
1594already displayed, @code{scroll-other-window} displays it in some
1595window.
1596
1597When the selected window is the minibuffer, the next window is normally
1598the one at the top left corner. You can specify a different window to
1599scroll, when the minibuffer is selected, by setting the variable
1600@code{minibuffer-scroll-window}. This variable has no effect when any
1601other window is selected. When it is non-@code{nil} and the
1602minibuffer is selected, it takes precedence over
1603@code{other-window-scroll-buffer}. @xref{Definition of
1604minibuffer-scroll-window}.
1605
1606When the minibuffer is active, it is the next window if the selected
1607window is the one at the bottom right corner. In this case,
1608@code{scroll-other-window} attempts to scroll the minibuffer. If the
1609minibuffer contains just one line, it has nowhere to scroll to, so the
1610line reappears after the echo area momentarily displays the message
1611@samp{Beginning of buffer}.
1612@end deffn
1613
1614@c Emacs 19 feature
1615@defvar other-window-scroll-buffer
1616If this variable is non-@code{nil}, it tells @code{scroll-other-window}
0273ca3a 1617which buffer's window to scroll.
b8d4c8d0
GM
1618@end defvar
1619
1620@defopt scroll-margin
1621This option specifies the size of the scroll margin---a minimum number
1622of lines between point and the top or bottom of a window. Whenever
1623point gets within this many lines of the top or bottom of the window,
1624redisplay scrolls the text automatically (if possible) to move point
1625out of the margin, closer to the center of the window.
1626@end defopt
1627
1628@defopt scroll-conservatively
1629This variable controls how scrolling is done automatically when point
1630moves off the screen (or into the scroll margin). If the value is a
1631positive integer @var{n}, then redisplay scrolls the text up to
1632@var{n} lines in either direction, if that will bring point back into
0273ca3a 1633proper view. This behavior is called @dfn{conservative scrolling}.
b8d4c8d0
GM
1634Otherwise, scrolling happens in the usual way, under the control of
1635other variables such as @code{scroll-up-aggressively} and
1636@code{scroll-down-aggressively}.
1637
1638The default value is zero, which means that conservative scrolling
1639never happens.
1640@end defopt
1641
1642@defopt scroll-down-aggressively
1643The value of this variable should be either @code{nil} or a fraction
1644@var{f} between 0 and 1. If it is a fraction, that specifies where on
1645the screen to put point when scrolling down. More precisely, when a
1646window scrolls down because point is above the window start, the new
1647start position is chosen to put point @var{f} part of the window
1648height from the top. The larger @var{f}, the more aggressive the
1649scrolling.
1650
1651A value of @code{nil} is equivalent to .5, since its effect is to center
1652point. This variable automatically becomes buffer-local when set in any
1653fashion.
1654@end defopt
1655
1656@defopt scroll-up-aggressively
1657Likewise, for scrolling up. The value, @var{f}, specifies how far
1658point should be placed from the bottom of the window; thus, as with
1659@code{scroll-up-aggressively}, a larger value scrolls more aggressively.
1660@end defopt
1661
1662@defopt scroll-step
da0bbbc4
CY
1663This variable is an older variant of @code{scroll-conservatively}.
1664The difference is that if its value is @var{n}, that permits scrolling
b8d4c8d0
GM
1665only by precisely @var{n} lines, not a smaller number. This feature
1666does not work with @code{scroll-margin}. The default value is zero.
1667@end defopt
1668
1669@defopt scroll-preserve-screen-position
1670If this option is @code{t}, scrolling which would move the current
1671point position out of the window chooses the new position of point
1672so that the vertical position of the cursor is unchanged, if possible.
1673
1674If it is non-@code{nil} and not @code{t}, then the scrolling functions
1675always preserve the vertical position of point, if possible.
1676@end defopt
1677
1678@defopt next-screen-context-lines
1679The value of this variable is the number of lines of continuity to
1680retain when scrolling by full screens. For example, @code{scroll-up}
1681with an argument of @code{nil} scrolls so that this many lines at the
1682bottom of the window appear instead at the top. The default value is
1683@code{2}.
1684@end defopt
1685
1686@deffn Command recenter &optional count
1687@cindex centering point
1688This function scrolls the text in the selected window so that point is
1689displayed at a specified vertical position within the window. It does
1690not ``move point'' with respect to the text.
1691
1692If @var{count} is a nonnegative number, that puts the line containing
1693point @var{count} lines down from the top of the window. If
1694@var{count} is a negative number, then it counts upward from the
1695bottom of the window, so that @minus{}1 stands for the last usable
1696line in the window. If @var{count} is a non-@code{nil} list, then it
1697stands for the line in the middle of the window.
1698
1699If @var{count} is @code{nil}, @code{recenter} puts the line containing
1700point in the middle of the window, then clears and redisplays the entire
1701selected frame.
1702
1703When @code{recenter} is called interactively, @var{count} is the raw
1704prefix argument. Thus, typing @kbd{C-u} as the prefix sets the
1705@var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
1706@var{count} to 4, which positions the current line four lines from the
1707top.
1708
1709With an argument of zero, @code{recenter} positions the current line at
1710the top of the window. This action is so handy that some people make a
1711separate key binding to do this. For example,
1712
1713@example
1714@group
1715(defun line-to-top-of-window ()
1716 "Scroll current line to top of window.
1717Replaces three keystroke sequence C-u 0 C-l."
1718 (interactive)
1719 (recenter 0))
1720
1721(global-set-key [kp-multiply] 'line-to-top-of-window)
1722@end group
1723@end example
1724@end deffn
1725
1726@node Vertical Scrolling
1727@section Vertical Fractional Scrolling
1728@cindex vertical fractional scrolling
0273ca3a 1729@cindex vertical scroll position
b8d4c8d0 1730
af1a5cd5
MR
1731 @dfn{Vertical fractional scrolling} means shifting text in a window
1732up or down by a specified multiple or fraction of a line. Each window
1733has a @dfn{vertical scroll position}, which is a number, never less than
0273ca3a
MR
1734zero. It specifies how far to raise the contents of the window.
1735Raising the window contents generally makes all or part of some lines
1736disappear off the top, and all or part of some other lines appear at the
1737bottom. The usual value is zero.
b8d4c8d0 1738
af1a5cd5 1739 The vertical scroll position is measured in units of the normal line
b8d4c8d0
GM
1740height, which is the height of the default font. Thus, if the value is
1741.5, that means the window contents are scrolled up half the normal line
1742height. If it is 3.3, that means the window contents are scrolled up
1743somewhat over three times the normal line height.
1744
af1a5cd5 1745 What fraction of a line the vertical scrolling covers, or how many
b8d4c8d0
GM
1746lines, depends on what the lines contain. A value of .5 could scroll a
1747line whose height is very short off the screen, while a value of 3.3
1748could scroll just part of the way through a tall line or an image.
1749
1750@defun window-vscroll &optional window pixels-p
1751This function returns the current vertical scroll position of
aeeedf76
MR
1752@var{window}. The default for @var{window} is the selected window.
1753If @var{pixels-p} is non-@code{nil}, the return value is measured in
0273ca3a 1754pixels, rather than in units of the normal line height.
b8d4c8d0
GM
1755
1756@example
1757@group
1758(window-vscroll)
1759 @result{} 0
1760@end group
1761@end example
1762@end defun
1763
1764@defun set-window-vscroll window lines &optional pixels-p
1765This function sets @var{window}'s vertical scroll position to
0273ca3a
MR
1766@var{lines}. If @var{window} is @code{nil}, the selected window is
1767used. The argument @var{lines} should be zero or positive; if not, it
1768is taken as zero.
b8d4c8d0 1769
b8d4c8d0
GM
1770
1771The actual vertical scroll position must always correspond
1772to an integral number of pixels, so the value you specify
1773is rounded accordingly.
1774
1775The return value is the result of this rounding.
1776
1777@example
1778@group
1779(set-window-vscroll (selected-window) 1.2)
1780 @result{} 1.13
1781@end group
1782@end example
1783
1784If @var{pixels-p} is non-@code{nil}, @var{lines} specifies a number of
1785pixels. In this case, the return value is @var{lines}.
1786@end defun
1787
1788@defvar auto-window-vscroll
1789If this variable is non-@code{nil}, the line-move, scroll-up, and
0273ca3a 1790scroll-down functions will automatically modify the vertical scroll
b8766179 1791position to scroll through display rows that are taller than the height
0273ca3a 1792of the window, for example in the presence of large images.
b8d4c8d0
GM
1793@end defvar
1794
1795@node Horizontal Scrolling
1796@section Horizontal Scrolling
1797@cindex horizontal scrolling
1798
1799 @dfn{Horizontal scrolling} means shifting the image in the window left
1800or right by a specified multiple of the normal character width. Each
1801window has a @dfn{horizontal scroll position}, which is a number, never
1802less than zero. It specifies how far to shift the contents left.
1803Shifting the window contents left generally makes all or part of some
1804characters disappear off the left, and all or part of some other
1805characters appear at the right. The usual value is zero.
1806
1807 The horizontal scroll position is measured in units of the normal
1808character width, which is the width of space in the default font. Thus,
1809if the value is 5, that means the window contents are scrolled left by 5
1810times the normal character width. How many characters actually
1811disappear off to the left depends on their width, and could vary from
1812line to line.
1813
1814 Because we read from side to side in the ``inner loop,'' and from top
1815to bottom in the ``outer loop,'' the effect of horizontal scrolling is
1816not like that of textual or vertical scrolling. Textual scrolling
1817involves selection of a portion of text to display, and vertical
1818scrolling moves the window contents contiguously; but horizontal
1819scrolling causes part of @emph{each line} to go off screen.
1820
1821 Usually, no horizontal scrolling is in effect; then the leftmost
1822column is at the left edge of the window. In this state, scrolling to
1823the right is meaningless, since there is no data to the left of the edge
1824to be revealed by it; so this is not allowed. Scrolling to the left is
1825allowed; it scrolls the first columns of text off the edge of the window
1826and can reveal additional columns on the right that were truncated
1827before. Once a window has a nonzero amount of leftward horizontal
1828scrolling, you can scroll it back to the right, but only so far as to
1829reduce the net horizontal scroll to zero. There is no limit to how far
1830left you can scroll, but eventually all the text will disappear off the
1831left edge.
1832
1833@vindex auto-hscroll-mode
1834 If @code{auto-hscroll-mode} is set, redisplay automatically alters
1835the horizontal scrolling of a window as necessary to ensure that point
1836is always visible. However, you can still set the horizontal
1837scrolling value explicitly. The value you specify serves as a lower
1838bound for automatic scrolling, i.e. automatic scrolling will not
1839scroll a window to a column less than the specified one.
1840
1841@deffn Command scroll-left &optional count set-minimum
1842This function scrolls the selected window @var{count} columns to the
1843left (or to the right if @var{count} is negative). The default
1844for @var{count} is the window width, minus 2.
1845
1846The return value is the total amount of leftward horizontal scrolling in
1847effect after the change---just like the value returned by
1848@code{window-hscroll} (below).
1849
1850Once you scroll a window as far right as it can go, back to its normal
1851position where the total leftward scrolling is zero, attempts to scroll
1852any farther right have no effect.
1853
1854If @var{set-minimum} is non-@code{nil}, the new scroll amount becomes
1855the lower bound for automatic scrolling; that is, automatic scrolling
1856will not scroll a window to a column less than the value returned by
1857this function. Interactive calls pass non-@code{nil} for
1858@var{set-minimum}.
1859@end deffn
1860
1861@deffn Command scroll-right &optional count set-minimum
1862This function scrolls the selected window @var{count} columns to the
1863right (or to the left if @var{count} is negative). The default
1864for @var{count} is the window width, minus 2. Aside from the direction
1865of scrolling, this works just like @code{scroll-left}.
1866@end deffn
1867
1868@defun window-hscroll &optional window
1869This function returns the total leftward horizontal scrolling of
1870@var{window}---the number of columns by which the text in @var{window}
aeeedf76
MR
1871is scrolled left past the left margin. The default for
1872@var{window} is the selected window.
b8d4c8d0 1873
0273ca3a
MR
1874The return value is never negative. It is zero when no horizontal
1875scrolling has been done in @var{window} (which is usually the case).
b8d4c8d0 1876
b8d4c8d0
GM
1877
1878@example
1879@group
1880(window-hscroll)
1881 @result{} 0
1882@end group
1883@group
1884(scroll-left 5)
1885 @result{} 5
1886@end group
1887@group
1888(window-hscroll)
1889 @result{} 5
1890@end group
1891@end example
1892@end defun
1893
1894@defun set-window-hscroll window columns
1895This function sets horizontal scrolling of @var{window}. The value of
1896@var{columns} specifies the amount of scrolling, in terms of columns
1897from the left margin. The argument @var{columns} should be zero or
1898positive; if not, it is taken as zero. Fractional values of
1899@var{columns} are not supported at present.
1900
1901Note that @code{set-window-hscroll} may appear not to work if you test
1902it by evaluating a call with @kbd{M-:} in a simple way. What happens
1903is that the function sets the horizontal scroll value and returns, but
1904then redisplay adjusts the horizontal scrolling to make point visible,
1905and this overrides what the function did. You can observe the
1906function's effect if you call it while point is sufficiently far from
1907the left margin that it will remain visible.
1908
1909The value returned is @var{columns}.
1910
1911@example
1912@group
1913(set-window-hscroll (selected-window) 10)
1914 @result{} 10
1915@end group
1916@end example
1917@end defun
1918
af1a5cd5
MR
1919 Here is how you can determine whether a given position @var{position}
1920is off the screen due to horizontal scrolling:
b8d4c8d0
GM
1921
1922@example
1923@group
1924(defun hscroll-on-screen (window position)
1925 (save-excursion
1926 (goto-char position)
1927 (and
1928 (>= (- (current-column) (window-hscroll window)) 0)
1929 (< (- (current-column) (window-hscroll window))
1930 (window-width window)))))
1931@end group
1932@end example
1933
1934@node Size of Window
1935@section The Size of a Window
1936@cindex window size
1937@cindex size of window
1938
1939 An Emacs window is rectangular, and its size information consists of
1940the height (the number of lines) and the width (the number of character
1941positions in each line). The mode line is included in the height. But
1942the width does not count the scroll bar or the column of @samp{|}
1943characters that separates side-by-side windows.
1944
1945 The following three functions return size information about a window:
1946
1947@defun window-height &optional window
0c5413c8
GM
1948This function returns the number of lines in @var{window} (by default
1949the selected window), including any mode line and header line.
1950The result is almost always less than the value of @code{frame-height}
1951for the associated frame, because the latter also includes any echo
1952area. Depending on the toolkit in use, the frame height can also
1953include the menu bar and tool bar (@pxref{Size and Position}).
1954Therefore in general it is not straightforward to compare window and
1955frame heights (see @code{window-full-height-p} below).
b8d4c8d0
GM
1956
1957@example
1958@group
1959(window-height)
1960 @result{} 23
1961@end group
1962@group
1963(split-window-vertically)
1964 @result{} #<window 4 on windows.texi>
1965@end group
1966@group
1967(window-height)
1968 @result{} 11
1969@end group
1970@end example
1971@end defun
1972
1973@defun window-body-height &optional window
1974Like @code{window-height} but the value does not include the
1975mode line (if any) or the header line (if any).
1976@end defun
1977
0c5413c8
GM
1978@defun window-full-height-p &optional window
1979This function returns non-@code{nil} if @var{window} is as tall as the
1980frame that contains it. The default for @var{window} is the selected
1981window.
1982@end defun
1983
b8d4c8d0 1984@defun window-width &optional window
aeeedf76
MR
1985This function returns the number of columns in @var{window}. The
1986default for @var{window} is the selected window.
b8d4c8d0 1987
0273ca3a
MR
1988The return value does not include the window's scroll bar or the column
1989of @samp{|} characters that separates side-by-side windows. Moreover,
1990the return value does not include the space used for displaying fringes
1991and margins. Hence you cannot, in general, compare the return values of
1992@code{window-width} and @code{frame-width} for equality to determine
1993whether a window is a wide as the containing frame. Use the function
1994@code{window-full-width-p}, see below, instead.
b8d4c8d0
GM
1995
1996@example
1997@group
1998(window-width)
1999 @result{} 80
2000@end group
2001@end example
2002@end defun
2003
2004@defun window-full-width-p &optional window
0273ca3a 2005This function returns non-@code{nil} if @var{window} is as wide as the
aeeedf76
MR
2006frame that contains it; otherwise @code{nil}. The default for
2007@var{window} is the selected window.
b8d4c8d0
GM
2008@end defun
2009
2010@defun window-edges &optional window
2011This function returns a list of the edge coordinates of @var{window}.
aeeedf76 2012The default for @var{window} is the selected window.
b8d4c8d0
GM
2013
2014The order of the list is @code{(@var{left} @var{top} @var{right}
2015@var{bottom})}, all elements relative to 0, 0 at the top left corner of
2016the frame. The element @var{right} of the value is one more than the
2017rightmost column used by @var{window}, and @var{bottom} is one more than
2018the bottommost row used by @var{window} and its mode-line.
2019
2020The edges include the space used by the window's scroll bar, display
2021margins, fringes, header line, and mode line, if it has them. Also,
2022if the window has a neighbor on the right, its right edge value
2023includes the width of the separator line between the window and that
2024neighbor. Since the width of the window does not include this
2025separator, the width does not usually equal the difference between the
2026right and left edges.
2027@end defun
2028
2029@defun window-inside-edges &optional window
2030This is similar to @code{window-edges}, but the edge values
2031it returns include only the text area of the window. They
2032do not include the header line, mode line, scroll bar or
2033vertical separator, fringes, or display margins.
2034@end defun
2035
2036Here are the results obtained on a typical 24-line terminal with just
2037one window, with menu bar enabled:
2038
2039@example
2040@group
2041(window-edges (selected-window))
2042 @result{} (0 1 80 23)
2043@end group
2044@group
2045(window-inside-edges (selected-window))
2046 @result{} (0 1 80 22)
2047@end group
2048@end example
2049
2050@noindent
2051The bottom edge is at line 23 because the last line is the echo area.
2052The bottom inside edge is at line 22, which is the window's mode line.
2053
2054If @var{window} is at the upper left corner of its frame, and there is
2055no menu bar, then @var{bottom} returned by @code{window-edges} is the
2056same as the value of @code{(window-height)}, @var{right} is almost the
2057same as the value of @code{(window-width)}, and @var{top} and
2058@var{left} are zero. For example, the edges of the following window
2059are @w{@samp{0 0 8 5}}. Assuming that the frame has more than 8
2060columns, the last column of the window (column 7) holds a border
2061rather than text. The last row (row 4) holds the mode line, shown
2062here with @samp{xxxxxxxxx}.
2063
2064@example
2065@group
2066 0
2067 _______
2068 0 | |
2069 | |
2070 | |
2071 | |
2072 xxxxxxxxx 4
2073
2074 7
2075@end group
2076@end example
2077
2078In the following example, let's suppose that the frame is 7
2079columns wide. Then the edges of the left window are @w{@samp{0 0 4 3}}
2080and the edges of the right window are @w{@samp{4 0 7 3}}.
2081The inside edges of the left window are @w{@samp{0 0 3 2}},
2082and the inside edges of the right window are @w{@samp{4 0 7 2}},
2083
2084@example
2085@group
2086 ___ ___
2087 | | |
2088 | | |
2089 xxxxxxxxx
2090
2091 0 34 7
2092@end group
2093@end example
2094
2095@defun window-pixel-edges &optional window
2096This function is like @code{window-edges} except that, on a graphical
2097display, the edge values are measured in pixels instead of in
2098character lines and columns.
2099@end defun
2100
2101@defun window-inside-pixel-edges &optional window
2102This function is like @code{window-inside-edges} except that, on a
2103graphical display, the edge values are measured in pixels instead of
2104in character lines and columns.
2105@end defun
2106
2107@node Resizing Windows
2108@section Changing the Size of a Window
2109@cindex window resizing
2110@cindex resize window
2111@cindex changing window size
2112@cindex window size, changing
2113
af1a5cd5 2114 The window size functions fall into two classes: high-level commands
b8d4c8d0
GM
2115that change the size of windows and low-level functions that access
2116window size. Emacs does not permit overlapping windows or gaps between
0273ca3a 2117windows, so resizing a window always affects at least one other window.
b8d4c8d0
GM
2118
2119@deffn Command enlarge-window size &optional horizontal
0273ca3a
MR
2120This function makes the selected window @var{size} lines taller by
2121stealing lines from windows above or below. In a first round, it takes
2122lines from one window at a time until that window is
2123@code{window-min-height} lines tall, then takes from another. If, at
2124the end of the first round, the selected window is still not tall
2125enough, @code{enlarge-window} starts a second round, where it deletes
2126windows above or below the selected one.
b8d4c8d0 2127
5d8dda33
MR
2128If @var{horizontal} is non-@code{nil}, this function makes the window
2129@var{size} columns wider, stealing columns instead of lines. If a
2130window from which columns are stolen shrinks below
b8d4c8d0
GM
2131@code{window-min-width} columns, that window disappears.
2132
2133If the requested size would exceed that of the window's frame, then the
2134function makes the window occupy the entire height (or width) of the
2135frame.
2136
2137If there are various other windows from which lines or columns can be
2138stolen, and some of them specify fixed size (using
2139@code{window-size-fixed}, see below), they are left untouched while
a1401ab1 2140other windows are ``robbed.'' If it would be necessary to alter the
b8d4c8d0
GM
2141size of a fixed-size window, @code{enlarge-window} gets an error
2142instead.
2143
10e187e8 2144If @var{size} is negative, this function shrinks the selected window by
b8d4c8d0
GM
2145@minus{}@var{size} lines or columns. If that makes the window smaller
2146than the minimum size (@code{window-min-height} and
0273ca3a 2147@code{window-min-width}), then @code{enlarge-window} deletes the window.
b8d4c8d0
GM
2148
2149@code{enlarge-window} returns @code{nil}.
2150@end deffn
2151
2152@deffn Command enlarge-window-horizontally columns
2153This function makes the selected window @var{columns} wider.
2154It could be defined as follows:
2155
2156@example
2157@group
2158(defun enlarge-window-horizontally (columns)
2159 (interactive "p")
2160 (enlarge-window columns t))
2161@end group
2162@end example
2163@end deffn
2164
2165@deffn Command shrink-window size &optional horizontal
2166This function is like @code{enlarge-window} but negates the argument
2167@var{size}, making the selected window smaller by giving lines (or
2168columns) to the other windows. If the window shrinks below
2169@code{window-min-height} or @code{window-min-width}, then it disappears.
2170
2171If @var{size} is negative, the window is enlarged by @minus{}@var{size}
2172lines or columns.
2173@end deffn
2174
2175@deffn Command shrink-window-horizontally columns
2176This function makes the selected window @var{columns} narrower.
2177It could be defined as follows:
2178
2179@example
2180@group
2181(defun shrink-window-horizontally (columns)
2182 (interactive "p")
2183 (shrink-window columns t))
2184@end group
2185@end example
2186@end deffn
2187
2188@defun adjust-window-trailing-edge window delta horizontal
2189This function makes the selected window @var{delta} lines taller or
2190@var{delta} columns wider, by moving the bottom or right edge. This
2191function does not delete other windows; if it cannot make the
2192requested size adjustment, it signals an error. On success, this
2193function returns @code{nil}.
2194@end defun
2195
df006536
MR
2196@deffn Command fit-window-to-buffer &optional window max-height min-height
2197This command makes @var{window} the right height to display its
dda87836
MR
2198contents exactly. The default for @var{window} is the selected window.
2199
2200The optional argument @var{max-height} specifies the maximum height the
2201window is allowed to be; @code{nil} means use the maximum permissible
2202height of a window on @var{window}'s frame. The optional argument
2203@var{min-height} specifies the minimum height for the window; @code{nil}
2204means use @code{window-min-height}. All these height values include the
2205mode line and/or header line.
2206
2207This function can delete windows when their height shrinks below
2208@var{min-height}. It returns non-@code{nil} if it orderly resized
2209@var{window}, and @code{nil} otherwise.
df006536 2210@end deffn
b8d4c8d0
GM
2211
2212@deffn Command shrink-window-if-larger-than-buffer &optional window
0273ca3a
MR
2213This command shrinks @var{window} vertically to be as small as possible
2214while still showing the full contents of its buffer---but not less than
aeeedf76
MR
2215@code{window-min-height} lines. The default for @var{window} is
2216the selected window.
b8d4c8d0 2217
0273ca3a 2218However, this command does nothing if the window is already too small to
b8d4c8d0
GM
2219display the whole text of the buffer, or if part of the contents are
2220currently scrolled off screen, or if the window is not the full width of
2221its frame, or if the window is the only window in its frame.
2222
2223This command returns non-@code{nil} if it actually shrank the window
2224and @code{nil} otherwise.
2225@end deffn
2226
52a94b85 2227@cindex fixed-size window
b8d4c8d0 2228@defvar window-size-fixed
0273ca3a
MR
2229If this variable is non-@code{nil}, in a given buffer, then the size of
2230any window displaying that buffer remains fixed unless you either
2231explicitly change it or Emacs has no other choice.
b8d4c8d0
GM
2232
2233If the value is @code{height}, then only the window's height is fixed;
2234if the value is @code{width}, then only the window's width is fixed.
2235Any other non-@code{nil} value fixes both the width and the height.
2236
2237This variable automatically becomes buffer-local when set.
2238
2239Explicit size-change functions such as @code{enlarge-window}
2240get an error if they would have to change a window size which is fixed.
2241Therefore, when you want to change the size of such a window,
2242you should bind @code{window-size-fixed} to @code{nil}, like this:
2243
2244@example
2245(let ((window-size-fixed nil))
2246 (enlarge-window 10))
2247@end example
2248
0273ca3a
MR
2249Deleting an adjacent window or changing the frame size may change the
2250size of a fixed-size window, if there is no other alternative.
b8d4c8d0
GM
2251@end defvar
2252
2253@cindex minimum window size
2254 The following two variables constrain the window-structure-changing
2255functions to a minimum height and width.
2256
2257@defopt window-min-height
403b14d1 2258The value of this variable specifies how short a window may become
b8d4c8d0 2259before it is automatically deleted. Making a window smaller than
5d8dda33
MR
2260@code{window-min-height} automatically deletes it, and no window may be
2261created shorter than this. The value is measured in line units. When
0273ca3a 2262the window wants a mode line and/or a header line, they are counted as
aeeedf76
MR
2263one line each. The default value is @code{4}. A value less than
2264@code{1} is ignored.
b8d4c8d0
GM
2265@end defopt
2266
2267@defopt window-min-width
403b14d1 2268The value of this variable specifies how narrow a window may become
b8d4c8d0
GM
2269before it is automatically deleted. Making a window smaller than
2270@code{window-min-width} automatically deletes it, and no window may be
5d8dda33 2271created narrower than this. The value is measured in characters and
0273ca3a
MR
2272includes any fringes or the scroll bar. The default value is @code{10}.
2273A value less than @code{2} is ignored.
b8d4c8d0
GM
2274@end defopt
2275
0273ca3a 2276@cindex balancing window sizes
a1401ab1 2277Emacs provides two functions to balance windows, that is, to even out
0273ca3a
MR
2278the sizes of windows on the same frame. The minibuffer window and
2279fixed-size windows are not resized by these functions.
2280
2281@deffn Command balance-windows &optional window-or-frame
2282This function balances windows in a way that gives more space to
2283full-width and/or full-height windows. If @var{window-or-frame}
2284specifies a frame, it balances all windows on that frame. If
2285@var{window-or-frame} specifies a window, it balances this window and
2286its ``siblings'' only. Think of a sibling as the other (original or
2287new) window with respect to the present one, involved in the process of
47264a97 2288splitting; see @ref{Splitting Windows}. Since a sibling may have been
0273ca3a
MR
2289split again, a window can have more than one sibling.
2290@end deffn
2291
2292@deffn Command balance-windows-area
2293This function attempts to give all windows on the selected frame
a1401ab1 2294approximately the same share of the screen area. This means that
0273ca3a
MR
2295full-width or full-height windows are not given more space than other
2296windows.
2297@end deffn
2298
b8d4c8d0
GM
2299@node Coordinates and Windows
2300@section Coordinates and Windows
2301
2302This section describes how to relate screen coordinates to windows.
2303
2304@defun window-at x y &optional frame
2305This function returns the window containing the specified cursor
2306position in the frame @var{frame}. The coordinates @var{x} and @var{y}
2307are measured in characters and count from the top left corner of the
2308frame. If they are out of range, @code{window-at} returns @code{nil}.
2309
2310If you omit @var{frame}, the selected frame is used.
2311@end defun
2312
2313@defun coordinates-in-window-p coordinates window
2314This function checks whether a particular frame position falls within
2315the window @var{window}.
2316
2317The argument @var{coordinates} is a cons cell of the form @code{(@var{x}
2318. @var{y})}. The coordinates @var{x} and @var{y} are measured in
2319characters, and count from the top left corner of the screen or frame.
2320
2321The value returned by @code{coordinates-in-window-p} is non-@code{nil}
2322if the coordinates are inside @var{window}. The value also indicates
2323what part of the window the position is in, as follows:
2324
2325@table @code
2326@item (@var{relx} . @var{rely})
2327The coordinates are inside @var{window}. The numbers @var{relx} and
2328@var{rely} are the equivalent window-relative coordinates for the
2329specified position, counting from 0 at the top left corner of the
2330window.
2331
2332@item mode-line
2333The coordinates are in the mode line of @var{window}.
2334
2335@item header-line
2336The coordinates are in the header line of @var{window}.
2337
2338@item vertical-line
2339The coordinates are in the vertical line between @var{window} and its
2340neighbor to the right. This value occurs only if the window doesn't
2341have a scroll bar; positions in a scroll bar are considered outside the
2342window for these purposes.
2343
2344@item left-fringe
2345@itemx right-fringe
2346The coordinates are in the left or right fringe of the window.
2347
2348@item left-margin
2349@itemx right-margin
2350The coordinates are in the left or right margin of the window.
2351
2352@item nil
2353The coordinates are not in any part of @var{window}.
2354@end table
2355
2356The function @code{coordinates-in-window-p} does not require a frame as
2357argument because it always uses the frame that @var{window} is on.
2358@end defun
2359
2360@node Window Tree
2361@section The Window Tree
2362@cindex window tree
2363
2364 A @dfn{window tree} specifies the layout, size, and relationship
2365between all windows in one frame.
2366
2367@defun window-tree &optional frame
2368This function returns the window tree for frame @var{frame}.
2369If @var{frame} is omitted, the selected frame is used.
2370
2371The return value is a list of the form @code{(@var{root} @var{mini})},
2372where @var{root} represents the window tree of the frame's
2373root window, and @var{mini} is the frame's minibuffer window.
2374
2375If the root window is not split, @var{root} is the root window itself.
2376Otherwise, @var{root} is a list @code{(@var{dir} @var{edges} @var{w1}
2377@var{w2} ...)} where @var{dir} is @code{nil} for a horizontal split,
2378and @code{t} for a vertical split, @var{edges} gives the combined size and
2379position of the subwindows in the split, and the rest of the elements
2380are the subwindows in the split. Each of the subwindows may again be
2381a window or a list representing a window split, and so on. The
2382@var{edges} element is a list @code{(@var{left}@var{ top}@var{ right}@var{ bottom})}
2383similar to the value returned by @code{window-edges}.
2384@end defun
2385
2386@node Window Configurations
2387@section Window Configurations
2388@cindex window configurations
2389@cindex saving window information
2390
2391 A @dfn{window configuration} records the entire layout of one
0273ca3a
MR
2392frame---all windows, their sizes, which buffers they contain, how those
2393buffers are scrolled, and their values of point and the mark; also their
2394fringes, margins, and scroll bar settings. It also includes the value
2395of @code{minibuffer-scroll-window}. As a special exception, the window
2396configuration does not record the value of point in the selected window
2397for the current buffer. Also, the window configuration does not record
47264a97 2398the values of window parameters; see @ref{Window Parameters}.
0273ca3a 2399
a1401ab1
EZ
2400 You can bring back an entire frame layout by restoring a previously
2401saved window configuration. If you want to record the layout of all
0273ca3a 2402frames instead of just one, use a frame configuration instead of a
47264a97 2403window configuration; see @ref{Frame Configurations}.
b8d4c8d0
GM
2404
2405@defun current-window-configuration &optional frame
2406This function returns a new object representing @var{frame}'s current
aeeedf76
MR
2407window configuration. The default for @var{frame} is the selected
2408frame.
b8d4c8d0
GM
2409@end defun
2410
2411@defun set-window-configuration configuration
2412This function restores the configuration of windows and buffers as
2413specified by @var{configuration}, for the frame that @var{configuration}
2414was created for.
2415
2416The argument @var{configuration} must be a value that was previously
0273ca3a 2417returned by @code{current-window-configuration}. The configuration is
b8d4c8d0
GM
2418restored in the frame from which @var{configuration} was made, whether
2419that frame is selected or not. This always counts as a window size
2420change and triggers execution of the @code{window-size-change-functions}
2421(@pxref{Window Hooks}), because @code{set-window-configuration} doesn't
2422know how to tell whether the new configuration actually differs from the
2423old one.
2424
2425If the frame which @var{configuration} was saved from is dead, all this
2426function does is restore the three variables @code{window-min-height},
2427@code{window-min-width} and @code{minibuffer-scroll-window}. In this
2428case, the function returns @code{nil}. Otherwise, it returns @code{t}.
2429
2430Here is a way of using this function to get the same effect
2431as @code{save-window-excursion}:
2432
2433@example
2434@group
2435(let ((config (current-window-configuration)))
2436 (unwind-protect
2437 (progn (split-window-vertically nil)
2438 @dots{})
2439 (set-window-configuration config)))
2440@end group
2441@end example
2442@end defun
2443
2444@defspec save-window-excursion forms@dots{}
2445This special form records the window configuration, executes @var{forms}
2446in sequence, then restores the earlier window configuration. The window
2447configuration includes, for each window, the value of point and the
2448portion of the buffer that is visible. It also includes the choice of
2449selected window. However, it does not include the value of point in
2450the current buffer; use @code{save-excursion} also, if you wish to
2451preserve that.
2452
2453Don't use this construct when @code{save-selected-window} is sufficient.
2454
0273ca3a 2455Exit from @code{save-window-excursion} always triggers execution of
b8d4c8d0
GM
2456@code{window-size-change-functions}. (It doesn't know how to tell
2457whether the restored configuration actually differs from the one in
2458effect at the end of the @var{forms}.)
2459
2460The return value is the value of the final form in @var{forms}.
2461For example:
2462
2463@example
2464@group
2465(split-window)
2466 @result{} #<window 25 on control.texi>
2467@end group
2468@group
2469(setq w (selected-window))
2470 @result{} #<window 19 on control.texi>
2471@end group
2472@group
2473(save-window-excursion
2474 (delete-other-windows w)
2475 (switch-to-buffer "foo")
2476 'do-something)
2477 @result{} do-something
2478 ;; @r{The screen is now split again.}
2479@end group
2480@end example
2481@end defspec
2482
2483@defun window-configuration-p object
2484This function returns @code{t} if @var{object} is a window configuration.
2485@end defun
2486
2487@defun compare-window-configurations config1 config2
2488This function compares two window configurations as regards the
2489structure of windows, but ignores the values of point and mark and the
2490saved scrolling positions---it can return @code{t} even if those
2491aspects differ.
2492
2493The function @code{equal} can also compare two window configurations; it
2494regards configurations as unequal if they differ in any respect, even a
2495saved point or mark.
2496@end defun
2497
2498@defun window-configuration-frame config
2499This function returns the frame for which the window configuration
2500@var{config} was made.
2501@end defun
2502
2503 Other primitives to look inside of window configurations would make
2504sense, but are not implemented because we did not need them. See the
2505file @file{winner.el} for some more operations on windows
2506configurations.
2507
0273ca3a
MR
2508@node Window Parameters
2509@section Window Parameters
2510@cindex window parameters
2511
2512This sections describes how window parameters can be used to associate
2513additional information with windows.
2514
2515@defun window-parameter window parameter
aeeedf76
MR
2516This function returns @var{window}'s value for @var{parameter}. The
2517default for @var{window} is the selected window. If @var{window}
2518has no setting for @var{parameter}, this function returns @code{nil}.
0273ca3a
MR
2519@end defun
2520
a1401ab1 2521@defun window-parameters &optional window
0273ca3a 2522This function returns all parameters of @var{window} and their values.
aeeedf76
MR
2523The default for @var{window} is the selected window. The return value
2524is an association list of elements of the form @code{(@var{parameter}
a1401ab1 2525. @var{value})}.
0273ca3a
MR
2526@end defun
2527
2528@defun set-window-parameter window parameter value
2529This function sets @var{window}'s value of @var{parameter} to
aeeedf76
MR
2530@var{value} and returns @var{value}. The default for @var{window}
2531is the selected window.
0273ca3a
MR
2532@end defun
2533
2534Currently, window parameters are not saved in window configurations and
2535consequently not restored by @code{set-window-configuration}. Hence,
2536any change of a parameter introduced via @code{set-window-parameter} can
2537be undone only by invoking @code{set-window-parameter} for the same
2538parameter again. Since @code{save-window-excursion} relies on window
a1401ab1
EZ
2539configurations (@pxref{Window Configurations}), window parameters are
2540not saved and restored by that special form, either.
0273ca3a 2541
b8d4c8d0
GM
2542@node Window Hooks
2543@section Hooks for Window Scrolling and Changes
2544@cindex hooks for window operations
2545
2546This section describes how a Lisp program can take action whenever a
2547window displays a different part of its buffer or a different buffer.
2548There are three actions that can change this: scrolling the window,
2549switching buffers in the window, and changing the size of the window.
2550The first two actions run @code{window-scroll-functions}; the last runs
2551@code{window-size-change-functions}.
2552
2553@defvar window-scroll-functions
2554This variable holds a list of functions that Emacs should call before
0273ca3a
MR
2555redisplaying a window with scrolling. Displaying a different buffer in
2556the window also runs these functions.
b8d4c8d0 2557
0273ca3a
MR
2558This variable is not a normal hook, because each function is called with
2559two arguments: the window, and its new display-start position.
b8d4c8d0
GM
2560
2561These functions must be careful in using @code{window-end}
0273ca3a
MR
2562(@pxref{Window Start and End}); if you need an up-to-date value, you
2563must use the @var{update} argument to ensure you get it.
b8d4c8d0
GM
2564
2565@strong{Warning:} don't use this feature to alter the way the window
2566is scrolled. It's not designed for that, and such use probably won't
2567work.
2568@end defvar
2569
2570@defvar window-size-change-functions
2571This variable holds a list of functions to be called if the size of any
2572window changes for any reason. The functions are called just once per
2573redisplay, and just once for each frame on which size changes have
2574occurred.
2575
2576Each function receives the frame as its sole argument. There is no
2577direct way to find out which windows on that frame have changed size, or
2578precisely how. However, if a size-change function records, at each
2579call, the existing windows and their sizes, it can also compare the
2580present sizes and the previous sizes.
2581
2582Creating or deleting windows counts as a size change, and therefore
2583causes these functions to be called. Changing the frame size also
2584counts, because it changes the sizes of the existing windows.
2585
2586It is not a good idea to use @code{save-window-excursion} (@pxref{Window
2587Configurations}) in these functions, because that always counts as a
2588size change, and it would cause these functions to be called over and
2589over. In most cases, @code{save-selected-window} (@pxref{Selecting
2590Windows}) is what you need here.
2591@end defvar
2592
b8d4c8d0
GM
2593@defvar window-configuration-change-hook
2594A normal hook that is run every time you change the window configuration
2595of an existing frame. This includes splitting or deleting windows,
2596changing the sizes of windows, or displaying a different buffer in a
0273ca3a
MR
2597window.
2598
2599The buffer-local part of this hook is run once per each window on the
2600affected frame, with the relevant window selected and its buffer
2601current. The global part is run once for the modified frame, with that
2602frame selected.
b8d4c8d0
GM
2603@end defvar
2604
38b1d346 2605 In addition, you can use @code{jit-lock-register} to register a Font
b8766179
MR
2606Lock fontification function, which will be called whenever parts of a
2607buffer are (re)fontified because a window was scrolled or its size
2608changed. @xref{Other Font Lock Variables}.