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