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