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