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