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