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