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