Commit | Line | Data |
---|---|---|
b8d4c8d0 GM |
1 | @c -*-texinfo-*- |
2 | @c This is part of the GNU Emacs Lisp Reference Manual. | |
3 | @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001, | |
6ed161e1 | 4 | @c 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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 | ||
10 | This chapter describes most of the functions and variables related to | |
0273ca3a MR |
11 | Emacs windows. @xref{Frames and Windows}, for how windows relate to |
12 | frames. @xref{Display}, for information on how text is displayed in | |
13 | windows. | |
b8d4c8d0 GM |
14 | |
15 | @menu | |
16 | * Basic Windows:: Basic information on using windows. | |
17 | * Splitting Windows:: Splitting one window into two windows. | |
18 | * Deleting Windows:: Deleting a window gives its space to other windows. | |
19 | * Selecting Windows:: The selected window is the one that you edit in. | |
20 | * Cyclic Window Ordering:: Moving around the existing windows. | |
21 | * Buffers and Windows:: Each window displays the contents of a buffer. | |
22 | * Displaying Buffers:: Higher-level functions for displaying a buffer | |
23 | and choosing a window for it. | |
24 | * Choosing Window:: How to choose a window for displaying a buffer. | |
0273ca3a | 25 | * Dedicated Windows:: How to avoid displaying another buffer in |
a1401ab1 | 26 | a specific window. |
b8d4c8d0 | 27 | * Window Point:: Each window has its own location of point. |
0273ca3a MR |
28 | * Window Start and End:: Buffer positions indicating which text is |
29 | on-screen in a window. | |
b8d4c8d0 GM |
30 | * Textual Scrolling:: Moving text up and down through the window. |
31 | * Vertical Scrolling:: Moving the contents up and down on the window. | |
32 | * Horizontal Scrolling:: Moving the contents sideways on the window. | |
33 | * Size of Window:: Accessing the size of a window. | |
34 | * Resizing Windows:: Changing the size of a window. | |
35 | * Coordinates and Windows:: Converting coordinates to windows. | |
36 | * Window Tree:: The layout and sizes of all windows in a frame. | |
37 | * Window Configurations:: Saving and restoring the state of the screen. | |
0273ca3a | 38 | * Window Parameters:: Associating additional information with windows. |
b8d4c8d0 GM |
39 | * Window Hooks:: Hooks for scrolling, window size changes, |
40 | redisplay going past a certain point, | |
41 | or window configuration changes. | |
42 | @end menu | |
43 | ||
44 | @node Basic Windows | |
45 | @section Basic Concepts of Emacs Windows | |
46 | @cindex window | |
47 | @cindex selected window | |
48 | ||
49 | A @dfn{window} in Emacs is the physical area of the screen in which a | |
50 | buffer is displayed. The term is also used to refer to a Lisp object that | |
51 | represents that screen area in Emacs Lisp. It should be | |
52 | clear from the context which is meant. | |
53 | ||
47264a97 | 54 | Emacs groups windows into frames; see @ref{Frames}. A frame |
a1401ab1 EZ |
55 | represents an area of screen available for Emacs to use. Each frame |
56 | always contains at least one window, but you can subdivide it | |
57 | vertically or horizontally into multiple, nonoverlapping Emacs | |
58 | windows. | |
b8d4c8d0 GM |
59 | |
60 | In each frame, at any time, one and only one window is designated as | |
61 | @dfn{selected within the frame}. The frame's cursor appears in that | |
62 | window, but the other windows have ``non-selected'' cursors, normally | |
a1401ab1 | 63 | less visible. (@xref{Cursor Parameters}, for customizing this.) At |
0273ca3a | 64 | any time, one frame is the selected frame; and the window selected |
7ed54cc5 | 65 | within that frame is @dfn{the selected window}. The selected window's |
0273ca3a | 66 | buffer is usually the current buffer (except when @code{set-buffer} has |
47264a97 | 67 | been used); see @ref{Current Buffer}. |
b8d4c8d0 GM |
68 | |
69 | For practical purposes, a window exists only while it is displayed in | |
70 | a frame. Once removed from the frame, the window is effectively deleted | |
71 | and should not be used, @emph{even though there may still be references | |
47264a97 | 72 | to it} from other Lisp objects; see @ref{Deleting Windows}. Restoring a |
0273ca3a | 73 | saved window configuration is the only way for a window no longer on the |
47264a97 | 74 | screen to come back to life; see @ref{Window Configurations}. |
b8d4c8d0 GM |
75 | |
76 | @cindex multiple windows | |
77 | Users create multiple windows so they can look at several buffers at | |
78 | once. Lisp libraries use multiple windows for a variety of reasons, but | |
79 | most often to display related information. In Rmail, for example, you | |
80 | can move through a summary buffer in one window while the other window | |
81 | shows messages one at a time as they are reached. | |
82 | ||
83 | The meaning of ``window'' in Emacs is similar to what it means in the | |
84 | context of general-purpose window systems such as X, but not identical. | |
85 | The X Window System places X windows on the screen; Emacs uses one or | |
86 | more X windows as frames, and subdivides them into | |
87 | Emacs windows. When you use Emacs on a character-only terminal, Emacs | |
88 | treats the whole terminal screen as one frame. | |
89 | ||
90 | @cindex terminal screen | |
91 | @cindex screen of terminal | |
92 | @cindex tiled windows | |
93 | Most window systems support arbitrarily located overlapping windows. | |
94 | In contrast, Emacs windows are @dfn{tiled}; they never overlap, and | |
95 | together they fill the whole screen or frame. Because of the way in | |
0273ca3a MR |
96 | which Emacs creates new windows (@pxref{Splitting Windows}) and resizes |
97 | them (@pxref{Resizing Windows}), not all conceivable tilings of windows | |
98 | on an Emacs frame are actually possible. | |
b8d4c8d0 GM |
99 | |
100 | @defun windowp object | |
101 | This function returns @code{t} if @var{object} is a window. | |
102 | @end defun | |
103 | ||
104 | @node Splitting Windows | |
105 | @section Splitting Windows | |
106 | @cindex splitting windows | |
107 | @cindex window splitting | |
108 | ||
0273ca3a MR |
109 | The functions described below are the primitives used to split a window |
110 | into two windows. They do not accept a buffer as an argument. Rather, | |
111 | the two ``halves'' of the split window initially display the same buffer | |
b8d4c8d0 GM |
112 | previously visible in the window that was split. |
113 | ||
114 | @deffn Command split-window &optional window size horizontal | |
0273ca3a | 115 | This function splits a new window out of @var{window}'s screen area. It |
aeeedf76 MR |
116 | returns the new window. The default for @var{window} is the selected |
117 | window. When you split the selected window, it remains selected. | |
0273ca3a MR |
118 | |
119 | If @var{horizontal} is non-@code{nil}, then @var{window} splits into two | |
120 | side by side windows. The original window keeps the leftmost @var{size} | |
121 | columns, and gives the rest of the columns to the new window. | |
122 | Otherwise, @var{window} splits into windows one above the other, the | |
123 | original window keeps the upper @var{size} lines and gives the rest of | |
124 | the lines to the new window. The original window @var{window} is | |
125 | therefore the left-hand or upper of the two, and the new window is the | |
126 | right-hand or lower. | |
b8d4c8d0 GM |
127 | |
128 | If @var{size} is omitted or @code{nil}, then @var{window} is divided | |
129 | evenly into two parts. (If there is an odd line, it is allocated to | |
130 | the new window.) When @code{split-window} is called interactively, | |
131 | all its arguments are @code{nil}. | |
132 | ||
133 | If splitting would result in making a window that is smaller than | |
0273ca3a MR |
134 | @code{window-min-height} or @code{window-min-width} (@pxref{Resizing |
135 | Windows}), @code{split-window} signals an error and does not split the | |
136 | window at all. | |
b8d4c8d0 GM |
137 | |
138 | The following example starts with one window on a screen that is 50 | |
139 | lines high by 80 columns wide; then it splits the window. | |
140 | ||
141 | @smallexample | |
142 | @group | |
143 | (setq w (selected-window)) | |
144 | @result{} #<window 8 on windows.texi> | |
145 | (window-edges) ; @r{Edges in order:} | |
146 | @result{} (0 0 80 50) ; @r{left--top--right--bottom} | |
147 | @end group | |
148 | ||
149 | @group | |
150 | ;; @r{Returns window created} | |
151 | (setq w2 (split-window w 15)) | |
152 | @result{} #<window 28 on windows.texi> | |
153 | @end group | |
154 | @group | |
155 | (window-edges w2) | |
156 | @result{} (0 15 80 50) ; @r{Bottom window;} | |
157 | ; @r{top is line 15} | |
158 | @end group | |
159 | @group | |
160 | (window-edges w) | |
161 | @result{} (0 0 80 15) ; @r{Top window} | |
162 | @end group | |
163 | @end smallexample | |
164 | ||
165 | The screen looks like this: | |
166 | ||
167 | @smallexample | |
168 | @group | |
169 | __________ | |
170 | | | line 0 | |
171 | | w | | |
172 | |__________| | |
173 | | | line 15 | |
174 | | w2 | | |
175 | |__________| | |
176 | line 50 | |
177 | column 0 column 80 | |
178 | @end group | |
179 | @end smallexample | |
180 | ||
181 | Next, split the top window horizontally: | |
182 | ||
183 | @smallexample | |
184 | @group | |
185 | (setq w3 (split-window w 35 t)) | |
186 | @result{} #<window 32 on windows.texi> | |
187 | @end group | |
188 | @group | |
189 | (window-edges w3) | |
190 | @result{} (35 0 80 15) ; @r{Left edge at column 35} | |
191 | @end group | |
192 | @group | |
193 | (window-edges w) | |
194 | @result{} (0 0 35 15) ; @r{Right edge at column 35} | |
195 | @end group | |
196 | @group | |
197 | (window-edges w2) | |
198 | @result{} (0 15 80 50) ; @r{Bottom window unchanged} | |
199 | @end group | |
200 | @end smallexample | |
201 | ||
202 | @need 3000 | |
203 | Now the screen looks like this: | |
204 | ||
205 | @smallexample | |
206 | @group | |
207 | column 35 | |
208 | __________ | |
209 | | | | line 0 | |
210 | | w | w3 | | |
211 | |___|______| | |
212 | | | line 15 | |
213 | | w2 | | |
214 | |__________| | |
215 | line 50 | |
216 | column 0 column 80 | |
217 | @end group | |
218 | @end smallexample | |
219 | ||
220 | Normally, Emacs indicates the border between two side-by-side windows | |
a1401ab1 EZ |
221 | with a scroll bar (@pxref{Scroll Bars}), or with @samp{|} characters. The |
222 | display table can specify alternative border characters; see @ref{Display | |
0273ca3a | 223 | Tables}. |
b8d4c8d0 GM |
224 | @end deffn |
225 | ||
226 | @deffn Command split-window-vertically &optional size | |
227 | This function splits the selected window into two windows, one above the | |
228 | other, leaving the upper of the two windows selected, with @var{size} | |
229 | lines. (If @var{size} is negative, then the lower of the two windows | |
96995b89 | 230 | gets @minus{}@var{size} lines and the upper window gets the rest, but |
b8d4c8d0 GM |
231 | the upper window is still the one selected.) However, if |
232 | @code{split-window-keep-point} (see below) is @code{nil}, then either | |
233 | window can be selected. | |
234 | ||
235 | In other respects, this function is similar to @code{split-window}. | |
236 | In particular, the upper window is the original one and the return | |
237 | value is the new, lower window. | |
238 | @end deffn | |
239 | ||
240 | @defopt split-window-keep-point | |
241 | If this variable is non-@code{nil} (the default), then | |
242 | @code{split-window-vertically} behaves as described above. | |
243 | ||
244 | If it is @code{nil}, then @code{split-window-vertically} adjusts point | |
245 | in each of the two windows to avoid scrolling. (This is useful on | |
246 | slow terminals.) It selects whichever window contains the screen line | |
247 | that point was previously on. | |
248 | ||
96995b89 MR |
249 | This variable affects the behavior of @code{split-window-vertically} |
250 | only. It has no effect on the other functions described here. | |
b8d4c8d0 GM |
251 | @end defopt |
252 | ||
253 | @deffn Command split-window-horizontally &optional size | |
254 | This function splits the selected window into two windows | |
255 | side-by-side, leaving the selected window on the left with @var{size} | |
256 | columns. If @var{size} is negative, the rightmost window gets | |
96995b89 | 257 | @minus{}@var{size} columns, but the leftmost window still remains |
b8d4c8d0 GM |
258 | selected. |
259 | ||
260 | This function is basically an interface to @code{split-window}. | |
261 | You could define a simplified version of the function like this: | |
262 | ||
263 | @smallexample | |
264 | @group | |
265 | (defun split-window-horizontally (&optional arg) | |
266 | "Split selected window into two windows, side by side..." | |
267 | (interactive "P") | |
268 | @end group | |
269 | @group | |
270 | (let ((size (and arg (prefix-numeric-value arg)))) | |
271 | (and size (< size 0) | |
96995b89 | 272 | (setq size (+ (window-width) size))) |
b8d4c8d0 GM |
273 | (split-window nil size t))) |
274 | @end group | |
275 | @end smallexample | |
276 | @end deffn | |
277 | ||
278 | @defun one-window-p &optional no-mini all-frames | |
279 | This function returns non-@code{nil} if there is only one window. The | |
280 | argument @var{no-mini}, if non-@code{nil}, means don't count the | |
281 | minibuffer even if it is active; otherwise, the minibuffer window is | |
282 | counted when it is active. | |
283 | ||
284 | The argument @var{all-frames} specifies which frames to consider. Here | |
285 | are the possible values and their meanings: | |
286 | ||
287 | @table @asis | |
288 | @item @code{nil} | |
289 | Count the windows in the selected frame, plus the minibuffer used | |
290 | by that frame even if it lies in some other frame. | |
291 | ||
292 | @item @code{t} | |
293 | Count all windows in all existing frames. | |
294 | ||
295 | @item @code{visible} | |
296 | Count all windows in all visible frames. | |
297 | ||
298 | @item 0 | |
299 | Count all windows in all visible or iconified frames. | |
300 | ||
301 | @item anything else | |
302 | Count precisely the windows in the selected frame, and no others. | |
303 | @end table | |
304 | @end defun | |
305 | ||
306 | @node Deleting Windows | |
307 | @section Deleting Windows | |
308 | @cindex deleting windows | |
309 | ||
310 | A window remains visible on its frame unless you @dfn{delete} it by | |
311 | calling certain functions that delete windows. A deleted window cannot | |
312 | appear on the screen, but continues to exist as a Lisp object until | |
313 | there are no references to it. There is no way to cancel the deletion | |
314 | of a window aside from restoring a saved window configuration | |
315 | (@pxref{Window Configurations}). Restoring a window configuration also | |
316 | deletes any windows that aren't part of that configuration. | |
317 | ||
a1401ab1 EZ |
318 | When you delete a window, the space it took up is given to one of |
319 | its sibling windows adjacent to it. | |
b8d4c8d0 GM |
320 | |
321 | @c Emacs 19 feature | |
322 | @defun window-live-p window | |
323 | This function returns @code{nil} if @var{window} is deleted, and | |
324 | @code{t} otherwise. | |
325 | ||
326 | @strong{Warning:} Erroneous information or fatal errors may result from | |
327 | using a deleted window as if it were live. | |
328 | @end defun | |
329 | ||
330 | @deffn Command delete-window &optional window | |
0273ca3a | 331 | This function removes @var{window} from display and returns @code{nil}. |
aeeedf76 MR |
332 | The default for @var{window} is the selected window. An error is |
333 | signaled if @var{window} is the only window on its frame. | |
b8d4c8d0 GM |
334 | @end deffn |
335 | ||
336 | @deffn Command delete-other-windows &optional window | |
337 | This function makes @var{window} the only window on its frame, by | |
aeeedf76 MR |
338 | deleting the other windows in that frame. The default for @var{window} |
339 | is the selected window. The return value is @code{nil}. | |
b8d4c8d0 GM |
340 | @end deffn |
341 | ||
520b29e7 | 342 | @deffn Command delete-windows-on &optional buffer-or-name frame |
b8d4c8d0 | 343 | This function deletes all windows showing @var{buffer-or-name}. If |
aeeedf76 MR |
344 | there are no windows showing @var{buffer-or-name}, it does nothing. The |
345 | optional argument @var{buffer-or-name} may be a buffer or the name of an | |
346 | existing buffer and defaults to the current buffer. | |
b8d4c8d0 GM |
347 | |
348 | @code{delete-windows-on} operates frame by frame. If a frame has | |
349 | several windows showing different buffers, then those showing | |
350 | @var{buffer-or-name} are removed, and the others expand to fill the | |
351 | space. If all windows in some frame are showing @var{buffer-or-name} | |
352 | (including the case where there is only one window), then the frame | |
353 | winds up with a single window showing another buffer chosen with | |
0273ca3a MR |
354 | @code{other-buffer} (@pxref{The Buffer List}). If, however, the window |
355 | showing @var{buffer-or-name} is dedicated to its buffer | |
356 | (@pxref{Dedicated Windows}), and there are other frames left, that | |
357 | window's frame is deleted. | |
b8d4c8d0 | 358 | |
aeeedf76 MR |
359 | The optional argument @var{frame} specifies which frames to operate on. |
360 | This function does not use it in quite the same way as the other | |
361 | functions which scan all windows; specifically, the values @code{t} and | |
362 | @code{nil} have the opposite of their meanings in other functions. Here | |
363 | are the full details: | |
b8d4c8d0 GM |
364 | |
365 | @itemize @bullet | |
366 | @item | |
367 | If it is @code{nil}, operate on all frames. | |
368 | @item | |
369 | If it is @code{t}, operate on the selected frame. | |
370 | @item | |
371 | If it is @code{visible}, operate on all visible frames. | |
372 | @item | |
373 | If it is 0, operate on all visible or iconified frames. | |
374 | @item | |
375 | If it is a frame, operate on that frame. | |
376 | @end itemize | |
377 | ||
378 | This function always returns @code{nil}. | |
379 | @end deffn | |
380 | ||
381 | @node Selecting Windows | |
382 | @section Selecting Windows | |
383 | @cindex selecting a window | |
384 | ||
385 | When a window is selected, the buffer in the window becomes the current | |
386 | buffer, and the cursor will appear in it. | |
387 | ||
388 | @defun selected-window | |
389 | This function returns the selected window. This is the window in | |
390 | which the cursor appears and to which many commands apply. | |
391 | @end defun | |
392 | ||
393 | @defun select-window window &optional norecord | |
394 | This function makes @var{window} the selected window. The cursor then | |
a1401ab1 EZ |
395 | appears in @var{window} (after redisplay). Unless @var{window} was |
396 | already selected, @code{select-window} makes @var{window}'s buffer the | |
397 | current buffer. The return value is @var{window}. | |
b8d4c8d0 | 398 | |
0273ca3a MR |
399 | Normally, @var{window}'s selected buffer is moved to the front of the |
400 | buffer list (@pxref{The Buffer List}) and @var{window} becomes the most | |
401 | recently selected window. But if @var{norecord} is non-@code{nil}, the | |
402 | buffer list remains unchanged and @var{window} does not become the most | |
403 | recently selected one. | |
b8d4c8d0 | 404 | |
b8d4c8d0 GM |
405 | |
406 | @example | |
407 | @group | |
408 | (setq w (next-window)) | |
409 | (select-window w) | |
410 | @result{} #<window 65 on windows.texi> | |
411 | @end group | |
412 | @end example | |
413 | @end defun | |
414 | ||
415 | @defmac save-selected-window forms@dots{} | |
416 | This macro records the selected frame, as well as the selected window | |
417 | of each frame, executes @var{forms} in sequence, then restores the | |
418 | earlier selected frame and windows. It also saves and restores the | |
419 | current buffer. It returns the value of the last form in @var{forms}. | |
420 | ||
421 | This macro does not save or restore anything about the sizes, | |
a1401ab1 | 422 | arrangement or contents of windows; therefore, if @var{forms} change |
0273ca3a MR |
423 | them, the change persists. If the previously selected window of some |
424 | frame is no longer live at the time of exit from @var{forms}, that | |
425 | frame's selected window is left alone. If the previously selected | |
426 | window is no longer live, then whatever window is selected at the end of | |
427 | @var{forms} remains selected. The current buffer is restored if and | |
428 | only if it is still live when exiting @var{forms}. | |
429 | ||
430 | This macro changes neither the ordering of recently selected windows nor | |
431 | the buffer list. | |
b8d4c8d0 GM |
432 | @end defmac |
433 | ||
434 | @defmac with-selected-window window forms@dots{} | |
0273ca3a MR |
435 | This macro selects @var{window}, executes @var{forms} in sequence, then |
436 | restores the previously selected window and current buffer. The ordering | |
437 | of recently selected windows and the buffer list remain unchanged unless | |
438 | you deliberately change them within @var{forms}, for example, by calling | |
a1401ab1 EZ |
439 | @code{select-window} with argument @var{norecord} @code{nil} or omitted |
440 | there. | |
b8d4c8d0 GM |
441 | @end defmac |
442 | ||
443 | @cindex finding windows | |
444 | The following functions choose one of the windows on the screen, | |
445 | offering various criteria for the choice. | |
446 | ||
447 | @defun get-lru-window &optional frame dedicated | |
448 | This function returns the window least recently ``used'' (that is, | |
449 | selected). If any full-width windows are present, it only considers | |
0273ca3a | 450 | these. |
b8d4c8d0 GM |
451 | |
452 | The selected window can be the least recently used window if it is the | |
453 | only window. A newly created window becomes the least recently used | |
0273ca3a MR |
454 | window until it is selected. A minibuffer window is never a candidate. |
455 | A dedicated window (@pxref{Dedicated Windows}) is never a candidate | |
aeeedf76 | 456 | unless the optional argument @var{dedicated} is non-@code{nil}. |
b8d4c8d0 | 457 | |
aeeedf76 MR |
458 | The optional argument @var{frame} specifies which windows are |
459 | considered. | |
b8d4c8d0 GM |
460 | |
461 | @itemize @bullet | |
462 | @item | |
463 | If it is @code{nil}, consider windows on the selected frame. | |
464 | @item | |
465 | If it is @code{t}, consider windows on all frames. | |
466 | @item | |
467 | If it is @code{visible}, consider windows on all visible frames. | |
468 | @item | |
469 | If it is 0, consider windows on all visible or iconified frames. | |
470 | @item | |
471 | If it is a frame, consider windows on that frame. | |
472 | @end itemize | |
473 | @end defun | |
474 | ||
475 | @defun get-largest-window &optional frame dedicated | |
476 | This function returns the window with the largest area (height times | |
477 | width). If there are no side-by-side windows, then this is the window | |
0273ca3a MR |
478 | with the most lines. A minibuffer window is never a candidate. A |
479 | dedicated window (@pxref{Dedicated Windows}) is never a candidate unless | |
aeeedf76 | 480 | the optional argument @var{dedicated} is non-@code{nil}. |
b8d4c8d0 GM |
481 | |
482 | If there are two candidate windows of the same size, this function | |
a1401ab1 | 483 | prefers the one that comes first in the cyclic ordering of windows, |
0273ca3a | 484 | starting from the selected window (@pxref{Cyclic Window Ordering}). |
b8d4c8d0 | 485 | |
aeeedf76 MR |
486 | The optional argument @var{frame} specifies which set of windows to |
487 | consider, see @code{get-lru-window} above. | |
b8d4c8d0 GM |
488 | @end defun |
489 | ||
490 | @cindex window that satisfies a predicate | |
491 | @cindex conditional selection of windows | |
492 | @defun get-window-with-predicate predicate &optional minibuf all-frames default | |
493 | This function returns a window satisfying @var{predicate}. It cycles | |
494 | through all visible windows using @code{walk-windows} (@pxref{Cyclic | |
0273ca3a MR |
495 | Window Ordering}), calling @var{predicate} on each one of them with that |
496 | window as its argument. The function returns the first window for which | |
497 | @var{predicate} returns a non-@code{nil} value; if that never happens, | |
498 | it returns @var{default} (which defaults to @code{nil}). | |
b8d4c8d0 GM |
499 | |
500 | The optional arguments @var{minibuf} and @var{all-frames} specify the | |
501 | set of windows to include in the scan. See the description of | |
502 | @code{next-window} in @ref{Cyclic Window Ordering}, for details. | |
503 | @end defun | |
504 | ||
505 | @node Cyclic Window Ordering | |
506 | @comment node-name, next, previous, up | |
507 | @section Cyclic Ordering of Windows | |
508 | @cindex cyclic ordering of windows | |
509 | @cindex ordering of windows, cyclic | |
510 | @cindex window ordering, cyclic | |
511 | ||
512 | When you use the command @kbd{C-x o} (@code{other-window}) to select | |
0273ca3a MR |
513 | some other window, it moves through the windows on the screen in a |
514 | specific order. For any given configuration of windows, this order | |
515 | never varies. It is called the @dfn{cyclic ordering of windows}. | |
b8d4c8d0 GM |
516 | |
517 | This ordering generally goes from top to bottom, and from left to | |
518 | right. But it may go down first or go right first, depending on the | |
0273ca3a | 519 | order in which windows were split. |
b8d4c8d0 GM |
520 | |
521 | If the first split was vertical (into windows one above each other), | |
522 | and then the subwindows were split horizontally, then the ordering is | |
523 | left to right in the top of the frame, and then left to right in the | |
524 | next lower part of the frame, and so on. If the first split was | |
525 | horizontal, the ordering is top to bottom in the left part, and so on. | |
0273ca3a MR |
526 | In general, within each set of siblings at any level in the window tree |
527 | (@pxref{Window Tree}), the order is left to right, or top to bottom. | |
b8d4c8d0 | 528 | |
0273ca3a | 529 | @deffn Command next-window &optional window minibuf all-frames |
b8d4c8d0 GM |
530 | @cindex minibuffer window, and @code{next-window} |
531 | This function returns the window following @var{window} in the cyclic | |
0273ca3a | 532 | ordering of windows. This is the window @kbd{C-x o} selects if typed |
aeeedf76 MR |
533 | when @var{window} is selected. The default for @var{window} is the |
534 | selected window. | |
b8d4c8d0 | 535 | |
aeeedf76 MR |
536 | The value of the optional argument @var{minibuf} specifies whether the |
537 | minibuffer is included in the window order. Normally, when | |
538 | @var{minibuf} is @code{nil}, the minibuffer is included only if it is | |
539 | currently ``active''; this matches the behavior of @kbd{C-x o}. (The | |
540 | minibuffer window is active while the minibuffer is in use; see | |
541 | @ref{Minibuffers}.) | |
b8d4c8d0 | 542 | |
0273ca3a MR |
543 | If @var{minibuf} is @code{t}, the cyclic ordering includes the |
544 | minibuffer window even if it is not active. If @var{minibuf} is neither | |
545 | @code{t} nor @code{nil}, the minibuffer window is not included even if | |
546 | it is active. | |
b8d4c8d0 | 547 | |
aeeedf76 MR |
548 | The optional argument @var{all-frames} specifies which frames to |
549 | consider. Here are the possible values and their meanings: | |
b8d4c8d0 GM |
550 | |
551 | @table @asis | |
552 | @item @code{nil} | |
553 | Consider all the windows in @var{window}'s frame, plus the minibuffer | |
554 | used by that frame even if it lies in some other frame. If the | |
555 | minibuffer counts (as determined by @var{minibuf}), then all windows on | |
556 | all frames that share that minibuffer count too. | |
557 | ||
558 | @item @code{t} | |
559 | Consider all windows in all existing frames. | |
560 | ||
561 | @item @code{visible} | |
562 | Consider all windows in all visible frames. (To get useful results, you | |
563 | must ensure @var{window} is in a visible frame.) | |
564 | ||
565 | @item 0 | |
566 | Consider all windows in all visible or iconified frames. | |
567 | ||
568 | @item a frame | |
569 | Consider all windows on that frame. | |
570 | ||
571 | @item anything else | |
572 | Consider precisely the windows in @var{window}'s frame, and no others. | |
573 | @end table | |
574 | ||
575 | This example assumes there are two windows, both displaying the | |
576 | buffer @samp{windows.texi}: | |
577 | ||
578 | @example | |
579 | @group | |
580 | (selected-window) | |
581 | @result{} #<window 56 on windows.texi> | |
582 | @end group | |
583 | @group | |
584 | (next-window (selected-window)) | |
585 | @result{} #<window 52 on windows.texi> | |
586 | @end group | |
587 | @group | |
588 | (next-window (next-window (selected-window))) | |
589 | @result{} #<window 56 on windows.texi> | |
590 | @end group | |
591 | @end example | |
0273ca3a | 592 | @end deffn |
b8d4c8d0 | 593 | |
0273ca3a | 594 | @deffn Command previous-window &optional window minibuf all-frames |
b8d4c8d0 GM |
595 | This function returns the window preceding @var{window} in the cyclic |
596 | ordering of windows. The other arguments specify which windows to | |
597 | include in the cycle, as in @code{next-window}. | |
0273ca3a | 598 | @end deffn |
b8d4c8d0 GM |
599 | |
600 | @deffn Command other-window count &optional all-frames | |
0273ca3a MR |
601 | This function selects another window in the cyclic ordering of windows. |
602 | @var{count} specifies the number of windows to skip in the ordering, | |
603 | starting with the selected window, before making the selection. If | |
604 | @var{count} is a positive number, it skips @var{count} windows forwards. | |
605 | @var{count} negative means skip @minus{}@var{count} windows backwards. | |
606 | If @var{count} is zero, it does not skip any window, thus re-selecting | |
607 | the selected window. In an interactive call, @var{count} is the numeric | |
608 | prefix argument. | |
b8d4c8d0 | 609 | |
aeeedf76 | 610 | The optional argument @var{all-frames} has the same meaning as in |
b8d4c8d0 | 611 | @code{next-window}, but the @var{minibuf} argument of @code{next-window} |
0273ca3a | 612 | is always effectively @code{nil}. This function returns @code{nil}. |
b8d4c8d0 GM |
613 | @end deffn |
614 | ||
615 | @c Emacs 19 feature | |
616 | @defun walk-windows proc &optional minibuf all-frames | |
617 | This function cycles through all windows. It calls the function | |
618 | @code{proc} once for each window, with the window as its sole | |
619 | argument. | |
620 | ||
621 | The optional arguments @var{minibuf} and @var{all-frames} specify the | |
0273ca3a | 622 | set of windows to include in the walk. See @code{next-window}, above, |
b8d4c8d0 GM |
623 | for details. |
624 | @end defun | |
625 | ||
626 | @defun window-list &optional frame minibuf window | |
0273ca3a | 627 | This function returns a list of all windows on @var{frame}, starting |
aeeedf76 MR |
628 | with @var{window}. The default for @var{frame} is the selected frame; |
629 | the default for @var{window} is the selected window. | |
b8d4c8d0 | 630 | |
0273ca3a | 631 | The value of @var{minibuf} specifies if the minibuffer window shall be |
b8d4c8d0 GM |
632 | included in the result list. If @var{minibuf} is @code{t}, the result |
633 | always includes the minibuffer window. If @var{minibuf} is @code{nil} | |
634 | or omitted, that includes the minibuffer window if it is active. If | |
635 | @var{minibuf} is neither @code{nil} nor @code{t}, the result never | |
636 | includes the minibuffer window. | |
637 | @end defun | |
638 | ||
639 | @node Buffers and Windows | |
640 | @section Buffers and Windows | |
641 | @cindex examining windows | |
642 | @cindex windows, controlling precisely | |
643 | @cindex buffers, controlled in windows | |
644 | ||
645 | This section describes low-level functions to examine windows or to | |
646 | display buffers in windows in a precisely controlled fashion. | |
647 | @iftex | |
648 | See the following section for | |
649 | @end iftex | |
650 | @ifnottex | |
651 | @xref{Displaying Buffers}, for | |
652 | @end ifnottex | |
653 | related functions that find a window to use and specify a buffer for it. | |
0273ca3a MR |
654 | The functions described there are easier to use, but they employ |
655 | heuristics in choosing or creating a window; use the functions described | |
656 | here when you need complete control. | |
b8d4c8d0 GM |
657 | |
658 | @defun set-window-buffer window buffer-or-name &optional keep-margins | |
659 | This function makes @var{window} display @var{buffer-or-name} as its | |
aeeedf76 MR |
660 | contents. It returns @code{nil}. The default for @var{window} is the |
661 | selected window. The argument @var{buffer-or-name} must specify a | |
662 | buffer or the name of an existing buffer. | |
663 | ||
664 | @code{set-window-buffer} is the fundamental primitive for changing which | |
665 | buffer is displayed in a window, and all ways of doing that call this | |
666 | function. | |
b8d4c8d0 GM |
667 | |
668 | @example | |
669 | @group | |
670 | (set-window-buffer (selected-window) "foo") | |
671 | @result{} nil | |
672 | @end group | |
673 | @end example | |
674 | ||
0273ca3a MR |
675 | Normally, displaying @var{buffer-or-name} in @var{window} resets the |
676 | window's position, display margins, fringe widths, and scroll bar | |
a1401ab1 | 677 | settings based on the local variables of that buffer. |
0273ca3a MR |
678 | However, if @var{keep-margins} is non-@code{nil}, display margins and |
679 | fringe widths of @var{window} remain unchanged. @xref{Fringes}. | |
680 | ||
aeeedf76 MR |
681 | @code{set-window-buffer} signals an error when @var{window} is |
682 | @dfn{strongly} dedicated to its buffer (@pxref{Dedicated Windows}) and | |
683 | does not already display @var{buffer-or-name}. | |
0273ca3a | 684 | |
aeeedf76 MR |
685 | Note that this function runs @code{window-scroll-functions} before |
686 | running @code{window-configuration-change-hook}. | |
b8d4c8d0 GM |
687 | @end defun |
688 | ||
689 | @defvar buffer-display-count | |
0273ca3a | 690 | This buffer-local variable records the number of times a buffer has been |
b8d4c8d0 GM |
691 | displayed in a window. It is incremented each time |
692 | @code{set-window-buffer} is called for the buffer. | |
693 | @end defvar | |
694 | ||
695 | @defun window-buffer &optional window | |
aeeedf76 MR |
696 | This function returns the buffer that @var{window} is displaying. The |
697 | default for @var{window} is the selected window. | |
b8d4c8d0 GM |
698 | |
699 | @example | |
700 | @group | |
701 | (window-buffer) | |
702 | @result{} #<buffer windows.texi> | |
703 | @end group | |
704 | @end example | |
705 | @end defun | |
706 | ||
520b29e7 | 707 | @defun get-buffer-window &optional buffer-or-name all-frames |
b8d4c8d0 GM |
708 | This function returns a window currently displaying |
709 | @var{buffer-or-name}, or @code{nil} if there is none. If there are | |
710 | several such windows, then the function returns the first one in the | |
711 | cyclic ordering of windows, starting from the selected window. | |
712 | @xref{Cyclic Window Ordering}. | |
713 | ||
aeeedf76 MR |
714 | The argument @var{BUFFER-OR-NAME} may be a buffer or a buffer name and |
715 | defaults to the current buffer. The optional argument @var{all-frames} | |
716 | specifies which windows to consider: | |
b8d4c8d0 GM |
717 | |
718 | @itemize @bullet | |
719 | @item | |
0273ca3a | 720 | @code{nil} means consider windows on the selected frame. |
b8d4c8d0 | 721 | @item |
0273ca3a | 722 | @code{t} means consider windows on all existing frames. |
b8d4c8d0 | 723 | @item |
0273ca3a | 724 | @code{visible} means consider windows on all visible frames. |
b8d4c8d0 | 725 | @item |
0273ca3a | 726 | 0 means consider windows on all visible or iconified frames. |
b8d4c8d0 | 727 | @item |
0273ca3a | 728 | A frame means consider windows on that frame only. |
b8d4c8d0 | 729 | @end itemize |
0273ca3a MR |
730 | |
731 | Observe that the behavior of @code{get-buffer-window} may differ from | |
732 | that of @code{next-window} (@pxref{Cyclic Window Ordering}) when | |
733 | @var{all-frames} equals @code{nil} or any value not listed here. | |
734 | Perhaps we will change @code{get-buffer-window} in the future to make it | |
735 | compatible with the other functions. | |
b8d4c8d0 GM |
736 | @end defun |
737 | ||
520b29e7 MR |
738 | @defun get-buffer-window-list &optional buffer-or-name minibuf all-frames |
739 | This function returns a list of all windows currently displaying | |
aeeedf76 MR |
740 | @var{buffer-or-name}. The argument @var{buffer-or-name} may be a buffer |
741 | or the name of an existing buffer and defaults to the current buffer. | |
b8d4c8d0 | 742 | |
0273ca3a MR |
743 | The two remaining arguments work like the same-named arguments of |
744 | @code{next-window}; they are @emph{not} like the optional arguments of | |
745 | @code{get-buffer-window}. | |
b8d4c8d0 GM |
746 | @end defun |
747 | ||
748 | @defvar buffer-display-time | |
749 | This variable records the time at which a buffer was last made visible | |
750 | in a window. It is always local in each buffer; each time | |
751 | @code{set-window-buffer} is called, it sets this variable to | |
752 | @code{(current-time)} in the specified buffer (@pxref{Time of Day}). | |
753 | When a buffer is first created, @code{buffer-display-time} starts out | |
754 | with the value @code{nil}. | |
755 | @end defvar | |
756 | ||
757 | @node Displaying Buffers | |
758 | @section Displaying Buffers in Windows | |
759 | @cindex switching to a buffer | |
760 | @cindex displaying a buffer | |
761 | ||
762 | In this section we describe convenient functions that choose a window | |
763 | automatically and use it to display a specified buffer. These functions | |
764 | can also split an existing window in certain circumstances. We also | |
765 | describe variables that parameterize the heuristics used for choosing a | |
766 | window. | |
767 | @iftex | |
768 | See the preceding section for | |
769 | @end iftex | |
770 | @ifnottex | |
771 | @xref{Buffers and Windows}, for | |
772 | @end ifnottex | |
43c59a3d | 773 | low-level primitives that give you more precise control. All of these |
b8d4c8d0 GM |
774 | functions work by calling @code{set-window-buffer}. |
775 | ||
776 | Do not use the functions in this section in order to make a buffer | |
777 | current so that a Lisp program can access or modify it; they are too | |
778 | drastic for that purpose, since they change the display of buffers in | |
779 | windows, which would be gratuitous and surprise the user. Instead, use | |
780 | @code{set-buffer} and @code{save-current-buffer} (@pxref{Current | |
781 | Buffer}), which designate buffers as current for programmed access | |
782 | without affecting the display of buffers in windows. | |
783 | ||
784 | @deffn Command switch-to-buffer buffer-or-name &optional norecord | |
785 | This function makes @var{buffer-or-name} the current buffer, and also | |
786 | displays the buffer in the selected window. This means that a human can | |
787 | see the buffer and subsequent keyboard commands will apply to it. | |
788 | Contrast this with @code{set-buffer}, which makes @var{buffer-or-name} | |
aeeedf76 | 789 | the current buffer but does not display it in the selected window; |
a1401ab1 | 790 | see @ref{Current Buffer}. |
b8d4c8d0 | 791 | |
0273ca3a MR |
792 | If @var{buffer-or-name} is @code{nil}, @code{switch-to-buffer} chooses a |
793 | buffer using @code{other-buffer}. If @var{buffer-or-name} is a string | |
794 | that does not identify an existing buffer, then a new buffer by that | |
795 | name is created. The major mode for the new buffer is set according to | |
47264a97 | 796 | the variable @code{default-major-mode}; see @ref{Auto Major Mode}. |
b8d4c8d0 | 797 | |
86ab855a MR |
798 | When @code{enable-recursive-minibuffers} is non-@code{nil} and the |
799 | selected window is either the minibuffer window or is dedicated to its | |
800 | buffer (@pxref{Dedicated Windows}), @code{switch-to-buffer} calls | |
801 | @code{pop-to-buffer} (see below) to display the buffer in some other | |
802 | window. | |
803 | ||
b8d4c8d0 GM |
804 | Normally the specified buffer is put at the front of the buffer list |
805 | (both the selected frame's buffer list and the frame-independent buffer | |
806 | list). This affects the operation of @code{other-buffer}. However, if | |
807 | @var{norecord} is non-@code{nil}, this is not done. @xref{The Buffer | |
808 | List}. | |
809 | ||
810 | The @code{switch-to-buffer} function is often used interactively, as | |
811 | the binding of @kbd{C-x b}. It is also used frequently in programs. It | |
812 | returns the buffer that it switched to. | |
813 | @end deffn | |
814 | ||
815 | The next two functions are similar to @code{switch-to-buffer}, except | |
816 | for the described features. | |
817 | ||
818 | @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord | |
af1a5cd5 MR |
819 | This function makes the buffer specified by @var{buffer-or-name} current |
820 | and displays it in a window not currently selected. It then selects | |
821 | that window. The handling of the buffer is the same as in | |
822 | @code{switch-to-buffer}. | |
b8d4c8d0 GM |
823 | |
824 | The currently selected window is absolutely never used to do the job. | |
825 | If it is the only window, then it is split to make a distinct window for | |
826 | this purpose. If the selected window is already displaying the buffer, | |
827 | then it continues to do so, but another window is nonetheless found to | |
828 | display it in as well. | |
829 | ||
830 | This function updates the buffer list just like @code{switch-to-buffer} | |
831 | unless @var{norecord} is non-@code{nil}. | |
832 | @end deffn | |
833 | ||
0273ca3a MR |
834 | @deffn Command pop-to-buffer buffer-or-name &optional other-window norecord |
835 | This command makes @var{buffer-or-name} the current buffer and switches | |
52a94b85 MR |
836 | to it in some window, preferably not the window previously selected. |
837 | The ``popped-to'' window becomes the selected window. Its frame is | |
47264a97 | 838 | given the X server's focus, if possible; see @ref{Input Focus}. The return |
0273ca3a MR |
839 | value is the buffer that was switched to. |
840 | ||
841 | If @var{buffer-or-name} is @code{nil}, that means to choose some other | |
842 | buffer, but you don't specify which. If @var{buffer-or-name} is a | |
843 | string that does not name an existing buffer, a buffer by that name is | |
844 | created. The major mode for the new buffer is set according to the | |
845 | variable @code{default-major-mode}. @xref{Auto Major Mode}. | |
b8d4c8d0 GM |
846 | |
847 | If the variable @code{pop-up-frames} is non-@code{nil}, | |
848 | @code{pop-to-buffer} looks for a window in any visible frame already | |
0273ca3a MR |
849 | displaying the buffer; if there is one, it selects and returns that |
850 | window. If no such window exists, it creates a new frame and displays | |
851 | the buffer in it. | |
b8d4c8d0 GM |
852 | |
853 | If @code{pop-up-frames} is @code{nil}, then @code{pop-to-buffer} | |
854 | operates entirely within the selected frame. (If the selected frame has | |
855 | just a minibuffer, @code{pop-to-buffer} operates within the most | |
856 | recently selected frame that was not just a minibuffer.) | |
857 | ||
0273ca3a MR |
858 | If the variable @code{pop-up-windows} is non-@code{nil}, windows may be |
859 | split to create a new window that is different from the original window. | |
a1401ab1 | 860 | For details, see @ref{Choosing Window}. |
b8d4c8d0 GM |
861 | |
862 | If @var{other-window} is non-@code{nil}, @code{pop-to-buffer} finds or | |
863 | creates another window even if @var{buffer-or-name} is already visible | |
864 | in the selected window. Thus @var{buffer-or-name} could end up | |
865 | displayed in two windows. On the other hand, if @var{buffer-or-name} is | |
866 | already displayed in the selected window and @var{other-window} is | |
0273ca3a MR |
867 | @code{nil}, then the selected window is considered sufficient for |
868 | displaying @var{buffer-or-name}, so that nothing needs to be done. | |
b8d4c8d0 GM |
869 | |
870 | All the variables that affect @code{display-buffer} affect | |
871 | @code{pop-to-buffer} as well. @xref{Choosing Window}. | |
872 | ||
b8d4c8d0 GM |
873 | This function updates the buffer list just like @code{switch-to-buffer} |
874 | unless @var{norecord} is non-@code{nil}. | |
0273ca3a | 875 | @end deffn |
b8d4c8d0 | 876 | |
520b29e7 | 877 | @deffn Command replace-buffer-in-windows &optional buffer-or-name |
da86d54b EZ |
878 | This function replaces @var{buffer-or-name} in all windows displaying |
879 | it with some other buffer. It uses @code{other-buffer} to choose the | |
880 | other buffer. In the usual applications of this function, you | |
b8d4c8d0 GM |
881 | don't care which other buffer is used; you just want to make sure that |
882 | @var{buffer-or-name} is no longer displayed. | |
883 | ||
aeeedf76 MR |
884 | The argument @var{buffer-or-name} may be a buffer or the name of an |
885 | existing buffer and defaults to the current buffer. | |
520b29e7 | 886 | |
0273ca3a MR |
887 | If a window displaying @var{buffer-or-name} is dedicated |
888 | (@pxref{Dedicated Windows}), and is not the only window on its frame, | |
889 | that window is deleted. If that window is the only window on its frame | |
890 | and there are other frames left, the window's frame is deleted too. If | |
891 | there are no other frames left, some other buffer is displayed in that | |
892 | window. | |
250959e0 | 893 | |
b8d4c8d0 GM |
894 | This function returns @code{nil}. |
895 | @end deffn | |
896 | ||
897 | @node Choosing Window | |
898 | @section Choosing a Window for Display | |
899 | ||
900 | This section describes the basic facility that chooses a window to | |
0273ca3a | 901 | display a buffer in---@code{display-buffer}. Higher-level functions and |
a1401ab1 | 902 | commands, like @code{switch-to-buffer} and @code{pop-to-buffer}, use this |
0273ca3a MR |
903 | subroutine. Here we describe how to use @code{display-buffer} and how |
904 | to customize it. | |
b8d4c8d0 GM |
905 | |
906 | @deffn Command display-buffer buffer-or-name &optional not-this-window frame | |
52a94b85 MR |
907 | This command makes @var{buffer-or-name} appear in some window, but it |
908 | does not select that window and does not make the buffer specified by | |
909 | @var{buffer-or-name} current. The identity of the selected window is | |
aeeedf76 MR |
910 | unaltered by this function. The argument @var{buffer-or-name} must be a |
911 | buffer or the name of an existing buffer. | |
b8d4c8d0 | 912 | |
0273ca3a MR |
913 | @var{not-this-window} non-@code{nil} means to display the specified |
914 | buffer in a window other than the selected one, even if it is already | |
915 | displayed in the selected window. This can cause the buffer to appear | |
916 | in two windows at once. Otherwise, if @var{buffer-or-name} is already | |
917 | being displayed in any window, that is good enough, so this function | |
918 | does nothing. | |
b8d4c8d0 GM |
919 | |
920 | @code{display-buffer} returns the window chosen to display | |
921 | @var{buffer-or-name}. | |
922 | ||
aeeedf76 MR |
923 | If the optional argument @var{frame} is non-@code{nil}, it specifies |
924 | which frames to check when deciding whether the buffer is already | |
925 | displayed. If the buffer is already displayed in some window on one of | |
926 | these frames, @code{display-buffer} simply returns that window. Here | |
927 | are the possible values of @var{frame}: | |
b8d4c8d0 GM |
928 | |
929 | @itemize @bullet | |
930 | @item | |
0273ca3a | 931 | @code{nil} means consider windows on the selected frame. |
b8d4c8d0 GM |
932 | (Actually, the last non-minibuffer frame.) |
933 | @item | |
0273ca3a | 934 | @code{t} means consider windows on all frames. |
b8d4c8d0 | 935 | @item |
0273ca3a | 936 | @code{visible} means consider windows on all visible frames. |
b8d4c8d0 | 937 | @item |
0273ca3a | 938 | 0 means consider windows on all visible or iconified frames. |
b8d4c8d0 | 939 | @item |
0273ca3a | 940 | A frame means consider windows on that frame only. |
b8d4c8d0 GM |
941 | @end itemize |
942 | ||
943 | Precisely how @code{display-buffer} finds or creates a window depends on | |
944 | the variables described below. | |
945 | @end deffn | |
946 | ||
52a94b85 MR |
947 | @defopt display-buffer-reuse-frames |
948 | If this variable is non-@code{nil}, @code{display-buffer} searches | |
949 | existing frames for a window displaying @var{buffer-or-name}. If the | |
950 | buffer is already displayed in a window in some frame, | |
951 | @code{display-buffer} makes the frame visible and raises it, to use that | |
952 | window. If the buffer is not already displayed, or | |
953 | @code{display-buffer-reuse-frames} is @code{nil}, the behavior of | |
954 | @code{display-buffer} is determined by the variables described next. | |
955 | @end defopt | |
956 | ||
957 | @defopt pop-up-windows | |
958 | This variable specifies whether @code{display-buffer} is allowed to | |
d3c0c321 MR |
959 | split (@pxref{Splitting Windows}) an existing window. If this variable |
960 | is non-@code{nil}, @code{display-buffer} tries to split the largest or | |
961 | least recently used window on the selected frame. (If the selected | |
962 | frame is a minibuffer-only frame, @code{display-buffer} tries to split a | |
963 | window on another frame instead.) If this variable is @code{nil} or the | |
b6474f84 | 964 | variable @code{pop-up-frames} (see below) is non-@code{nil}, |
52a94b85 MR |
965 | @code{display-buffer} does not split any window. |
966 | @end defopt | |
967 | ||
ef5fbab7 | 968 | @defvar split-window-preferred-function |
d3c0c321 MR |
969 | This variable must specify a function with one argument, which is a |
970 | window. The @code{display-buffer} routines will call this function with | |
971 | one or more candidate windows when they look for a window to split. The | |
972 | function is expected to split that window and return the new window. If | |
973 | the function returns @code{nil}, this means that the argument window | |
974 | cannot (or shall not) be split. | |
975 | ||
976 | The default value of @code{split-window-preferred-function} is the | |
977 | function @code{split-window-sensibly} described below. When you | |
978 | customize this option, bear in mind that the @code{display-buffer} | |
979 | routines may call your function up to two times when trying to split a | |
980 | window. The argument of the first call is the largest window on the | |
981 | chosen frame (as returned by @code{get-largest-window}). If that call | |
982 | fails to return a live window, your function is called a second time | |
983 | with the least recently used window on that frame (as returned by | |
984 | @code{get-lru-window}). | |
985 | ||
986 | The function assigned to this option may also try to split any other | |
987 | window instead of the argument window. Note that the window selected at | |
988 | the time @code{display-buffer} was invoked is still selected when your | |
989 | function is called. Hence, you can split the selected window (instead | |
990 | of the largest or least recently used one) by simply ignoring the window | |
991 | argument in the body of your function. You can even choose to not split | |
992 | any window as long as the return value of your function specifies a live | |
993 | window or nil, but you are not encouraged to do so unconditionally. If | |
994 | you want @code{display-buffer} to never split any windows, set | |
995 | @code{pop-up-windows} to @code{nil}. | |
ef5fbab7 | 996 | @end defvar |
43c59a3d | 997 | |
d3c0c321 MR |
998 | @defun split-window-sensibly |
999 | This function takes a window as argument and tries to split that window | |
1000 | in a suitable way. The two variables described next are useful for | |
1001 | tuning the behavior of this function. | |
1002 | @end defun | |
1003 | ||
b8d4c8d0 | 1004 | @defopt split-height-threshold |
d3c0c321 MR |
1005 | This variable specifies whether @code{split-window-sensibly} may split |
1006 | its argument window vertically. If this variable is set to an integer, | |
1007 | @code{split-window-sensibly} splits the window only if it has at least | |
1008 | this many lines. If the value of this variable is @code{nil}, | |
1009 | @code{split-window-sensibly} tries to split the window horizontally, | |
1010 | subject to restrictions of @code{split-width-threshold} (see below). If | |
1011 | splitting horizontally fails too, @code{split-window-sensibly} will try | |
1012 | to split the window vertically disregarding the value of this variable. | |
1013 | ||
1014 | @code{split-window-sensibly} does not split a window vertically whose | |
1015 | height is fixed (@pxref{Resizing Windows}). Moreover, it splits a | |
1016 | window vertically only if the space taken up by that window can | |
1017 | accommodate two windows one above the other that are both at least | |
1018 | @code{window-min-height} lines tall. Finally, if the window that shall | |
1019 | be split has a mode line, @code{split-window-sensibly} makes sure that | |
1020 | the new window can accomodate a mode line as well. | |
43c59a3d EZ |
1021 | @end defopt |
1022 | ||
1023 | @defopt split-width-threshold | |
d3c0c321 MR |
1024 | This variable specifies whether @code{split-window-sensibly} may split |
1025 | its argument window horizontally. If this variable is set to an | |
1026 | integer, @code{split-window-sensibly} splits the window only if it has | |
1027 | at least this many columns. If the value of this variable is | |
1028 | @code{nil}, @code{split-window-sensibly} will not split the window | |
1029 | horizontally. (It still might split the window vertically, though, see | |
52a94b85 MR |
1030 | above.) |
1031 | ||
d3c0c321 MR |
1032 | @code{split-window-sensibly} does not split a window horizontally if |
1033 | that window's width is fixed (@pxref{Resizing Windows}). Also, it | |
1034 | splits a window horizontally only if the space that window takes up can | |
1035 | accommodate two windows side by side that are both at least | |
1036 | @code{window-min-width} columns wide. | |
b8d4c8d0 GM |
1037 | @end defopt |
1038 | ||
1039 | @defopt even-window-heights | |
403b14d1 | 1040 | This variable specifies whether @code{display-buffer} should even out |
52a94b85 MR |
1041 | window heights if the buffer gets displayed in an existing window, above |
1042 | or beneath another window. If @code{even-window-heights} is | |
1043 | non-@code{nil}, the default, window heights will be evened out. If | |
1044 | either of the involved window has fixed height (@pxref{Resizing | |
1045 | Windows}) or @code{even-window-heights} is @code{nil}, the original | |
1046 | window heights will be left alone. | |
b8d4c8d0 GM |
1047 | @end defopt |
1048 | ||
1049 | @c Emacs 19 feature | |
1050 | @defopt pop-up-frames | |
403b14d1 | 1051 | This variable specifies whether @code{display-buffer} makes new frames. |
b8d4c8d0 | 1052 | If it is non-@code{nil}, @code{display-buffer} looks for an existing |
52a94b85 MR |
1053 | window already displaying the desired buffer, on any visible frame. If |
1054 | it finds one, it returns that window. Otherwise it makes a new frame, | |
1055 | unless the variable's value is @code{graphic-only} and the selected | |
0273ca3a | 1056 | frame is not on a graphic display. @xref{Frames}, for more information. |
b8d4c8d0 | 1057 | |
0273ca3a MR |
1058 | Note that the value of @code{pop-up-windows} does not matter if |
1059 | @code{pop-up-frames} is non-@code{nil}. If @code{pop-up-frames} is | |
1060 | @code{nil}, then @code{display-buffer} either splits a window or reuses | |
1061 | one. | |
b8d4c8d0 GM |
1062 | @end defopt |
1063 | ||
1064 | @c Emacs 19 feature | |
1065 | @defopt pop-up-frame-function | |
1066 | This variable specifies how to make a new frame if @code{pop-up-frames} | |
1067 | is non-@code{nil}. | |
1068 | ||
1069 | Its value should be a function of no arguments. When | |
1070 | @code{display-buffer} makes a new frame, it does so by calling that | |
1071 | function, which should return a frame. The default value of the | |
1072 | variable is a function that creates a frame using parameters from | |
1073 | @code{pop-up-frame-alist}. | |
1074 | @end defopt | |
1075 | ||
1076 | @defopt pop-up-frame-alist | |
9f822178 MR |
1077 | This variable holds an alist specifying frame parameters used by the |
1078 | default value of @code{pop-up-frame-function} for making new frames. | |
1079 | @xref{Frame Parameters}, for more information about frame parameters. | |
b8d4c8d0 GM |
1080 | @end defopt |
1081 | ||
1082 | @defopt special-display-buffer-names | |
0273ca3a MR |
1083 | A list of buffer names identifying buffers that should be displayed |
1084 | specially. If the name of @var{buffer-or-name} is in this list, | |
1085 | @code{display-buffer} handles the buffer specially. By default, special | |
1086 | display means to give the buffer a dedicated frame. | |
b8d4c8d0 | 1087 | |
52a94b85 MR |
1088 | If an element is a list, instead of a string, then the @sc{car} of that |
1089 | list is the buffer name, and the rest of that list says how to create | |
1090 | the frame. There are two possibilities for the rest of that list (its | |
1091 | @sc{cdr}): It can be an alist, specifying frame parameters, or it can | |
b8d4c8d0 GM |
1092 | contain a function and arguments to give to it. (The function's first |
1093 | argument is always the buffer to be displayed; the arguments from the | |
1094 | list come after that.) | |
1095 | ||
1096 | For example: | |
1097 | ||
1098 | @example | |
1099 | (("myfile" (minibuffer) (menu-bar-lines . 0))) | |
1100 | @end example | |
1101 | ||
1102 | @noindent | |
1103 | specifies to display a buffer named @samp{myfile} in a dedicated frame | |
1104 | with specified @code{minibuffer} and @code{menu-bar-lines} parameters. | |
1105 | ||
1106 | The list of frame parameters can also use the phony frame parameters | |
1107 | @code{same-frame} and @code{same-window}. If the specified frame | |
1108 | parameters include @code{(same-window . @var{value})} and @var{value} | |
1109 | is non-@code{nil}, that means to display the buffer in the current | |
1110 | selected window. Otherwise, if they include @code{(same-frame . | |
1111 | @var{value})} and @var{value} is non-@code{nil}, that means to display | |
1112 | the buffer in a new window in the currently selected frame. | |
1113 | @end defopt | |
1114 | ||
1115 | @defopt special-display-regexps | |
0273ca3a | 1116 | A list of regular expressions specifying buffers that should be |
b8d4c8d0 GM |
1117 | displayed specially. If the buffer's name matches any of the regular |
1118 | expressions in this list, @code{display-buffer} handles the buffer | |
0273ca3a MR |
1119 | specially. By default, special display means to give the buffer a |
1120 | dedicated frame. | |
b8d4c8d0 GM |
1121 | |
1122 | If an element is a list, instead of a string, then the @sc{car} of the | |
1123 | list is the regular expression, and the rest of the list says how to | |
0273ca3a | 1124 | create the frame. See @code{special-display-buffer-names} above. |
b8d4c8d0 GM |
1125 | @end defopt |
1126 | ||
1127 | @defun special-display-p buffer-name | |
1128 | This function returns non-@code{nil} if displaying a buffer | |
1129 | named @var{buffer-name} with @code{display-buffer} would | |
1130 | create a special frame. The value is @code{t} if it would | |
1131 | use the default frame parameters, or else the specified list | |
1132 | of frame parameters. | |
1133 | @end defun | |
1134 | ||
1135 | @defvar special-display-function | |
1136 | This variable holds the function to call to display a buffer specially. | |
1137 | It receives the buffer as an argument, and should return the window in | |
0273ca3a MR |
1138 | which it is displayed. The default value of this variable is |
1139 | @code{special-display-popup-frame}, see below. | |
b8d4c8d0 GM |
1140 | @end defvar |
1141 | ||
1142 | @defun special-display-popup-frame buffer &optional args | |
0273ca3a MR |
1143 | This function tries to make @var{buffer} visible in a frame of its own. |
1144 | If @var{buffer} is already displayed in some window, it makes that | |
1145 | window's frame visible and raises it. Otherwise, it creates a frame | |
1146 | that is dedicated to @var{buffer}. The return value is the window used | |
1147 | to display @var{buffer}. | |
b8d4c8d0 GM |
1148 | |
1149 | If @var{args} is an alist, it specifies frame parameters for the new | |
0273ca3a MR |
1150 | frame. If @var{args} is a list whose @sc{car} is a symbol, then |
1151 | @code{(car @var{args})} is called as a function to actually create and | |
1152 | set up the frame; it is called with @var{buffer} as first argument, and | |
1153 | @code{(cdr @var{args})} as additional arguments. | |
b8d4c8d0 GM |
1154 | |
1155 | This function always uses an existing window displaying @var{buffer}, | |
1156 | whether or not it is in a frame of its own; but if you set up the above | |
1157 | variables in your init file, before @var{buffer} was created, then | |
1158 | presumably the window was previously made by this function. | |
1159 | @end defun | |
1160 | ||
1161 | @defopt special-display-frame-alist | |
1162 | @anchor{Definition of special-display-frame-alist} | |
1163 | This variable holds frame parameters for | |
1164 | @code{special-display-popup-frame} to use when it creates a frame. | |
1165 | @end defopt | |
1166 | ||
1167 | @defopt same-window-buffer-names | |
1168 | A list of buffer names for buffers that should be displayed in the | |
1169 | selected window. If the buffer's name is in this list, | |
1170 | @code{display-buffer} handles the buffer by switching to it in the | |
1171 | selected window. | |
1172 | @end defopt | |
1173 | ||
1174 | @defopt same-window-regexps | |
1175 | A list of regular expressions that specify buffers that should be | |
1176 | displayed in the selected window. If the buffer's name matches any of | |
1177 | the regular expressions in this list, @code{display-buffer} handles the | |
1178 | buffer by switching to it in the selected window. | |
1179 | @end defopt | |
1180 | ||
1181 | @defun same-window-p buffer-name | |
1182 | This function returns @code{t} if displaying a buffer | |
1183 | named @var{buffer-name} with @code{display-buffer} would | |
1184 | put it in the selected window. | |
1185 | @end defun | |
1186 | ||
1187 | @c Emacs 19 feature | |
1188 | @defvar display-buffer-function | |
1189 | This variable is the most flexible way to customize the behavior of | |
1190 | @code{display-buffer}. If it is non-@code{nil}, it should be a function | |
1191 | that @code{display-buffer} calls to do the work. The function should | |
1192 | accept two arguments, the first two arguments that @code{display-buffer} | |
1193 | received. It should choose or create a window, display the specified | |
1194 | buffer in it, and then return the window. | |
1195 | ||
52a94b85 MR |
1196 | This variable takes precedence over all the other options described |
1197 | above. | |
b8d4c8d0 GM |
1198 | @end defvar |
1199 | ||
52a94b85 | 1200 | If all options described above fail to produce a suitable window, |
0273ca3a MR |
1201 | @code{display-buffer} tries to reuse an existing window. As a last |
1202 | resort, it will try to display @var{buffer-or-name} on a separate frame. | |
1203 | In that case, the value of @code{pop-up-frames} is disregarded. | |
1204 | ||
1205 | @node Dedicated Windows | |
1206 | @section Dedicated Windows | |
1207 | @cindex dedicated window | |
1208 | ||
1209 | Functions for displaying a buffer can be told to not use specific | |
1210 | windows by marking these window as @dfn{dedicated} to their buffers. | |
1211 | @code{display-buffer} (@pxref{Choosing Window}) never uses a dedicated | |
1212 | window for displaying another buffer in it. @code{get-lru-window} and | |
1213 | @code{get-largest-window} (@pxref{Selecting Windows}) do not consider | |
1214 | dedicated windows as candidates when their @var{dedicated} argument is | |
1215 | non-@code{nil}. The behavior of @code{set-window-buffer} | |
1216 | (@pxref{Buffers and Windows}) with respect to dedicated windows is | |
1217 | slightly different, see below. | |
1218 | ||
1219 | When @code{delete-windows-on} (@pxref{Deleting Windows}) wants to delete | |
1220 | a dedicated window and that window is the only window on its frame, it | |
1221 | deletes the window's frame too, provided there are other frames left. | |
1222 | @code{replace-buffer-in-windows} (@pxref{Displaying Buffers}) tries to | |
1223 | delete all dedicated windows showing its buffer argument. When such a | |
1224 | window is the only window on its frame, that frame is deleted, provided | |
1225 | there are other frames left. If there are no more frames left, some | |
1226 | other buffer is displayed in the window, and the window is marked as | |
1227 | non-dedicated. | |
1228 | ||
1229 | When you kill a buffer (@pxref{Killing Buffers}) displayed in a | |
1230 | dedicated window, any such window usually gets deleted too, since | |
1231 | @code{kill-buffer} calls @code{replace-buffer-in-windows} for cleaning | |
1232 | up windows. Burying a buffer (@pxref{The Buffer List}) deletes the | |
1233 | selected window if it is dedicated and shows that buffer. However, if | |
1234 | that window is the only window on its frame, another buffer is displayed | |
1235 | in it and the frame is iconified. | |
250959e0 MR |
1236 | |
1237 | @defun window-dedicated-p &optional window | |
52a94b85 MR |
1238 | This function returns non-@code{nil} if @var{window} is dedicated to its |
1239 | buffer and @code{nil} otherwise. More precisely, the return value is | |
1240 | the value assigned by the last call of @code{set-window-dedicated-p} for | |
1241 | @var{window} or @code{nil} if that function was never called with | |
aeeedf76 MR |
1242 | @var{window} as its argument. The default for @var{window} is the |
1243 | selected window. | |
b8d4c8d0 GM |
1244 | @end defun |
1245 | ||
1246 | @defun set-window-dedicated-p window flag | |
52a94b85 MR |
1247 | This function marks @var{window} as dedicated to its buffer if |
1248 | @var{flag} is non-@code{nil}, and non-dedicated otherwise. | |
52a94b85 | 1249 | |
0273ca3a MR |
1250 | As a special case, if @var{flag} is @code{t}, @var{window} becomes |
1251 | @dfn{strongly} dedicated to its buffer. @code{set-window-buffer} | |
1252 | signals an error when the window it acts upon is strongly dedicated to | |
1253 | its buffer and does not already display the buffer it is asked to | |
1254 | display. In any other case, @code{set-window-buffer} will display | |
1255 | another buffer in that window. Other functions do not treat @code{t} | |
1256 | differently from any non-@code{nil} value. | |
1257 | @end defun | |
52a94b85 | 1258 | |
b8d4c8d0 GM |
1259 | @node Window Point |
1260 | @section Windows and Point | |
1261 | @cindex window position | |
1262 | @cindex window point | |
1263 | @cindex position in window | |
1264 | @cindex point in window | |
1265 | ||
0273ca3a MR |
1266 | Each window has its own value of point (@pxref{Point}), independent of |
1267 | the value of point in other windows displaying the same buffer. This | |
1268 | makes it useful to have multiple windows showing one buffer. | |
b8d4c8d0 GM |
1269 | |
1270 | @itemize @bullet | |
1271 | @item | |
1272 | The window point is established when a window is first created; it is | |
1273 | initialized from the buffer's point, or from the window point of another | |
1274 | window opened on the buffer if such a window exists. | |
1275 | ||
1276 | @item | |
1277 | Selecting a window sets the value of point in its buffer from the | |
1278 | window's value of point. Conversely, deselecting a window sets the | |
1279 | window's value of point from that of the buffer. Thus, when you switch | |
1280 | between windows that display a given buffer, the point value for the | |
1281 | selected window is in effect in the buffer, while the point values for | |
1282 | the other windows are stored in those windows. | |
1283 | ||
1284 | @item | |
1285 | As long as the selected window displays the current buffer, the window's | |
1286 | point and the buffer's point always move together; they remain equal. | |
1287 | @end itemize | |
1288 | ||
b8d4c8d0 | 1289 | @cindex cursor |
af1a5cd5 | 1290 | As far as the user is concerned, point is where the cursor is, and |
b8d4c8d0 GM |
1291 | when the user switches to another buffer, the cursor jumps to the |
1292 | position of point in that buffer. | |
1293 | ||
1294 | @defun window-point &optional window | |
1295 | This function returns the current position of point in @var{window}. | |
1296 | For a nonselected window, this is the value point would have (in that | |
aeeedf76 MR |
1297 | window's buffer) if that window were selected. The default for |
1298 | @var{window} is the selected window. | |
b8d4c8d0 GM |
1299 | |
1300 | When @var{window} is the selected window and its buffer is also the | |
1301 | current buffer, the value returned is the same as point in that buffer. | |
0273ca3a MR |
1302 | Strictly speaking, it would be more correct to return the ``top-level'' |
1303 | value of point, outside of any @code{save-excursion} forms. But that | |
1304 | value is hard to find. | |
b8d4c8d0 GM |
1305 | @end defun |
1306 | ||
1307 | @defun set-window-point window position | |
1308 | This function positions point in @var{window} at position | |
1309 | @var{position} in @var{window}'s buffer. It returns @var{position}. | |
1310 | ||
1311 | If @var{window} is selected, and its buffer is current, | |
1312 | this simply does @code{goto-char}. | |
1313 | @end defun | |
1314 | ||
86ab855a MR |
1315 | @defvar window-point-insertion-type |
1316 | This variable specifies the marker insertion type (@pxref{Marker | |
1317 | Insertion Types}) of @code{window-point}. The default is @code{nil}, | |
1318 | so @code{window-point} will stay behind text inserted there. | |
1319 | @end defvar | |
1320 | ||
0273ca3a MR |
1321 | @node Window Start and End |
1322 | @section The Window Start and End Positions | |
b8d4c8d0 GM |
1323 | @cindex window start position |
1324 | ||
0273ca3a | 1325 | Each window maintains a marker used to keep track of a buffer position |
b8d4c8d0 GM |
1326 | that specifies where in the buffer display should start. This position |
1327 | is called the @dfn{display-start} position of the window (or just the | |
1328 | @dfn{start}). The character after this position is the one that appears | |
1329 | at the upper left corner of the window. It is usually, but not | |
1330 | inevitably, at the beginning of a text line. | |
1331 | ||
431b78c9 RS |
1332 | After switching windows or buffers, and in some other cases, if the |
1333 | window start is in the middle of a line, Emacs adjusts the window | |
1334 | start to the start of a line. This prevents certain operations from | |
1335 | leaving the window start at a meaningless point within a line. This | |
1336 | feature may interfere with testing some Lisp code by executing it | |
1337 | using the commands of Lisp mode, because they trigger this | |
1338 | readjustment. To test such code, put it into a command and bind the | |
1339 | command to a key. | |
1340 | ||
b8d4c8d0 GM |
1341 | @defun window-start &optional window |
1342 | @cindex window top line | |
1343 | This function returns the display-start position of window | |
1344 | @var{window}. If @var{window} is @code{nil}, the selected window is | |
1345 | used. For example, | |
1346 | ||
1347 | @example | |
1348 | @group | |
1349 | (window-start) | |
1350 | @result{} 7058 | |
1351 | @end group | |
1352 | @end example | |
1353 | ||
1354 | When you create a window, or display a different buffer in it, the | |
1355 | display-start position is set to a display-start position recently used | |
0273ca3a MR |
1356 | for the same buffer, or to @code{point-min} if the buffer doesn't have |
1357 | any. | |
b8d4c8d0 GM |
1358 | |
1359 | Redisplay updates the window-start position (if you have not specified | |
0273ca3a MR |
1360 | it explicitly since the previous redisplay)---to make sure point appears |
1361 | on the screen. Nothing except redisplay automatically changes the | |
1362 | window-start position; if you move point, do not expect the window-start | |
1363 | position to change in response until after the next redisplay. | |
b8d4c8d0 GM |
1364 | |
1365 | For a realistic example of using @code{window-start}, see the | |
1366 | description of @code{count-lines}. @xref{Definition of count-lines}. | |
1367 | @end defun | |
1368 | ||
0273ca3a | 1369 | @cindex window end position |
b8d4c8d0 | 1370 | @defun window-end &optional window update |
0273ca3a | 1371 | This function returns the position where display of its buffer ends in |
aeeedf76 | 1372 | @var{window}. The default for @var{window} is the selected window. |
b8d4c8d0 GM |
1373 | |
1374 | Simply changing the buffer text or moving point does not update the | |
1375 | value that @code{window-end} returns. The value is updated only when | |
1376 | Emacs redisplays and redisplay completes without being preempted. | |
1377 | ||
1378 | If the last redisplay of @var{window} was preempted, and did not finish, | |
1379 | Emacs does not know the position of the end of display in that window. | |
1380 | In that case, this function returns @code{nil}. | |
1381 | ||
1382 | If @var{update} is non-@code{nil}, @code{window-end} always returns an | |
0273ca3a MR |
1383 | up-to-date value for where display ends, based on the current |
1384 | @code{window-start} value. If a previously saved value of that position | |
1385 | is still valid, @code{window-end} returns that value; otherwise it | |
1386 | computes the correct value by scanning the buffer text. | |
b8d4c8d0 GM |
1387 | |
1388 | Even if @var{update} is non-@code{nil}, @code{window-end} does not | |
1389 | attempt to scroll the display if point has moved off the screen, the | |
1390 | way real redisplay would do. It does not alter the | |
1391 | @code{window-start} value. In effect, it reports where the displayed | |
1392 | text will end if scrolling is not required. | |
1393 | @end defun | |
1394 | ||
1395 | @defun set-window-start window position &optional noforce | |
1396 | This function sets the display-start position of @var{window} to | |
1397 | @var{position} in @var{window}'s buffer. It returns @var{position}. | |
1398 | ||
1399 | The display routines insist that the position of point be visible when a | |
1400 | buffer is displayed. Normally, they change the display-start position | |
1401 | (that is, scroll the window) whenever necessary to make point visible. | |
1402 | However, if you specify the start position with this function using | |
1403 | @code{nil} for @var{noforce}, it means you want display to start at | |
1404 | @var{position} even if that would put the location of point off the | |
1405 | screen. If this does place point off screen, the display routines move | |
1406 | point to the left margin on the middle line in the window. | |
1407 | ||
431b78c9 RS |
1408 | For example, if point @w{is 1} and you set the start of the window |
1409 | @w{to 37}, the start of the next line, point will be ``above'' the top | |
1410 | of the window. The display routines will automatically move point if | |
1411 | it is still 1 when redisplay occurs. Here is an example: | |
b8d4c8d0 GM |
1412 | |
1413 | @example | |
1414 | @group | |
1415 | ;; @r{Here is what @samp{foo} looks like before executing} | |
1416 | ;; @r{the @code{set-window-start} expression.} | |
1417 | @end group | |
1418 | ||
1419 | @group | |
1420 | ---------- Buffer: foo ---------- | |
1421 | @point{}This is the contents of buffer foo. | |
1422 | 2 | |
1423 | 3 | |
1424 | 4 | |
1425 | 5 | |
1426 | 6 | |
1427 | ---------- Buffer: foo ---------- | |
1428 | @end group | |
1429 | ||
1430 | @group | |
1431 | (set-window-start | |
1432 | (selected-window) | |
431b78c9 RS |
1433 | (save-excursion |
1434 | (goto-char 1) | |
1435 | (forward-line 1) | |
1436 | (point))) | |
1437 | @result{} 37 | |
b8d4c8d0 GM |
1438 | @end group |
1439 | ||
1440 | @group | |
1441 | ;; @r{Here is what @samp{foo} looks like after executing} | |
1442 | ;; @r{the @code{set-window-start} expression.} | |
1443 | ---------- Buffer: foo ---------- | |
b8d4c8d0 GM |
1444 | 2 |
1445 | 3 | |
1446 | @point{}4 | |
1447 | 5 | |
1448 | 6 | |
1449 | ---------- Buffer: foo ---------- | |
1450 | @end group | |
1451 | @end example | |
1452 | ||
1453 | If @var{noforce} is non-@code{nil}, and @var{position} would place point | |
1454 | off screen at the next redisplay, then redisplay computes a new window-start | |
1455 | position that works well with point, and thus @var{position} is not used. | |
1456 | @end defun | |
1457 | ||
1458 | @defun pos-visible-in-window-p &optional position window partially | |
1459 | This function returns non-@code{nil} if @var{position} is within the | |
1460 | range of text currently visible on the screen in @var{window}. It | |
0273ca3a MR |
1461 | returns @code{nil} if @var{position} is scrolled vertically out of view. |
1462 | Locations that are partially obscured are not considered visible unless | |
1463 | @var{partially} is non-@code{nil}. The argument @var{position} defaults | |
1464 | to the current position of point in @var{window}; @var{window}, to the | |
1465 | selected window. If @var{position} is @code{t}, that means to check the | |
1466 | last visible position in @var{window}. | |
b8d4c8d0 GM |
1467 | |
1468 | The @code{pos-visible-in-window-p} function considers only vertical | |
1469 | scrolling. If @var{position} is out of view only because @var{window} | |
1470 | has been scrolled horizontally, @code{pos-visible-in-window-p} returns | |
1471 | non-@code{nil} anyway. @xref{Horizontal Scrolling}. | |
1472 | ||
1473 | If @var{position} is visible, @code{pos-visible-in-window-p} returns | |
1474 | @code{t} if @var{partially} is @code{nil}; if @var{partially} is | |
0273ca3a | 1475 | non-@code{nil}, and the character following @var{position} is fully |
b8d4c8d0 GM |
1476 | visible, it returns a list of the form @code{(@var{x} @var{y})}, where |
1477 | @var{x} and @var{y} are the pixel coordinates relative to the top left | |
0273ca3a MR |
1478 | corner of the window; otherwise it returns an extended list of the form |
1479 | @code{(@var{x} @var{y} @var{rtop} @var{rbot} @var{rowh} @var{vpos})}, | |
1480 | where @var{rtop} and @var{rbot} specify the number of off-window pixels | |
1481 | at the top and bottom of the row at @var{position}, @var{rowh} specifies | |
1482 | the visible height of that row, and @var{vpos} specifies the vertical | |
1483 | position (zero-based row number) of that row. | |
b8d4c8d0 GM |
1484 | |
1485 | Here is an example: | |
1486 | ||
1487 | @example | |
1488 | @group | |
1489 | ;; @r{If point is off the screen now, recenter it now.} | |
1490 | (or (pos-visible-in-window-p | |
1491 | (point) (selected-window)) | |
1492 | (recenter 0)) | |
1493 | @end group | |
1494 | @end example | |
1495 | @end defun | |
1496 | ||
1497 | @defun window-line-height &optional line window | |
aeeedf76 MR |
1498 | This function returns the height of text line @var{line} in |
1499 | @var{window}. If @var{line} is one of @code{header-line} or | |
1500 | @code{mode-line}, @code{window-line-height} returns information about | |
1501 | the corresponding line of the window. Otherwise, @var{line} is a text | |
1502 | line number starting from 0. A negative number counts from the end of | |
1503 | the window. The default for @var{line} is the current line in | |
1504 | @var{window}; the default for @var{window} is the selected window. | |
b8d4c8d0 GM |
1505 | |
1506 | If the display is not up to date, @code{window-line-height} returns | |
1507 | @code{nil}. In that case, @code{pos-visible-in-window-p} may be used | |
1508 | to obtain related information. | |
1509 | ||
1510 | If there is no line corresponding to the specified @var{line}, | |
1511 | @code{window-line-height} returns @code{nil}. Otherwise, it returns | |
1512 | a list @code{(@var{height} @var{vpos} @var{ypos} @var{offbot})}, | |
1513 | where @var{height} is the height in pixels of the visible part of the | |
1514 | line, @var{vpos} and @var{ypos} are the vertical position in lines and | |
1515 | pixels of the line relative to the top of the first text line, and | |
1516 | @var{offbot} is the number of off-window pixels at the bottom of the | |
1517 | text line. If there are off-window pixels at the top of the (first) | |
1518 | text line, @var{ypos} is negative. | |
1519 | @end defun | |
1520 | ||
1521 | @node Textual Scrolling | |
1522 | @section Textual Scrolling | |
1523 | @cindex textual scrolling | |
1524 | @cindex scrolling textually | |
1525 | ||
1526 | @dfn{Textual scrolling} means moving the text up or down through a | |
1527 | window. It works by changing the value of the window's display-start | |
1528 | location. It may also change the value of @code{window-point} to keep | |
1529 | point on the screen. | |
1530 | ||
1531 | Textual scrolling was formerly called ``vertical scrolling,'' but we | |
1532 | changed its name to distinguish it from the new vertical fractional | |
1533 | scrolling feature (@pxref{Vertical Scrolling}). | |
1534 | ||
1535 | In the commands @code{scroll-up} and @code{scroll-down}, the directions | |
1536 | ``up'' and ``down'' refer to the motion of the text in the buffer at which | |
1537 | you are looking through the window. Imagine that the text is | |
1538 | written on a long roll of paper and that the scrolling commands move the | |
1539 | paper up and down. Thus, if you are looking at text in the middle of a | |
1540 | buffer and repeatedly call @code{scroll-down}, you will eventually see | |
1541 | the beginning of the buffer. | |
1542 | ||
1543 | Some people have urged that the opposite convention be used: they | |
1544 | imagine that the window moves over text that remains in place. Then | |
1545 | ``down'' commands would take you to the end of the buffer. This view is | |
1546 | more consistent with the actual relationship between windows and the | |
1547 | text in the buffer, but it is less like what the user sees. The | |
1548 | position of a window on the terminal does not move, and short scrolling | |
1549 | commands clearly move the text up or down on the screen. We have chosen | |
1550 | names that fit the user's point of view. | |
1551 | ||
1552 | The textual scrolling functions (aside from | |
1553 | @code{scroll-other-window}) have unpredictable results if the current | |
1554 | buffer is different from the buffer that is displayed in the selected | |
1555 | window. @xref{Current Buffer}. | |
1556 | ||
1557 | If the window contains a row which is taller than the height of the | |
1558 | window (for example in the presence of a large image), the scroll | |
d3c0c321 MR |
1559 | functions will adjust the window vscroll to scroll the partially visible |
1560 | row. To disable this feature, Lisp code may bind the variable | |
1561 | @code{auto-window-vscroll} to @code{nil} (@pxref{Vertical Scrolling}). | |
b8d4c8d0 GM |
1562 | |
1563 | @deffn Command scroll-up &optional count | |
1564 | This function scrolls the text in the selected window upward | |
1565 | @var{count} lines. If @var{count} is negative, scrolling is actually | |
1566 | downward. | |
1567 | ||
1568 | If @var{count} is @code{nil} (or omitted), then the length of scroll | |
1569 | is @code{next-screen-context-lines} lines less than the usable height of | |
1570 | the window (not counting its mode line). | |
1571 | ||
1572 | @code{scroll-up} returns @code{nil}, unless it gets an error | |
1573 | because it can't scroll any further. | |
1574 | @end deffn | |
1575 | ||
1576 | @deffn Command scroll-down &optional count | |
1577 | This function scrolls the text in the selected window downward | |
1578 | @var{count} lines. If @var{count} is negative, scrolling is actually | |
1579 | upward. | |
1580 | ||
1581 | If @var{count} is omitted or @code{nil}, then the length of the scroll | |
1582 | is @code{next-screen-context-lines} lines less than the usable height of | |
1583 | the window (not counting its mode line). | |
1584 | ||
1585 | @code{scroll-down} returns @code{nil}, unless it gets an error because | |
1586 | it can't scroll any further. | |
1587 | @end deffn | |
1588 | ||
1589 | @deffn Command scroll-other-window &optional count | |
1590 | This function scrolls the text in another window upward @var{count} | |
1591 | lines. Negative values of @var{count}, or @code{nil}, are handled | |
1592 | as in @code{scroll-up}. | |
1593 | ||
1594 | You can specify which buffer to scroll by setting the variable | |
1595 | @code{other-window-scroll-buffer} to a buffer. If that buffer isn't | |
1596 | already displayed, @code{scroll-other-window} displays it in some | |
1597 | window. | |
1598 | ||
1599 | When the selected window is the minibuffer, the next window is normally | |
1600 | the one at the top left corner. You can specify a different window to | |
1601 | scroll, when the minibuffer is selected, by setting the variable | |
1602 | @code{minibuffer-scroll-window}. This variable has no effect when any | |
1603 | other window is selected. When it is non-@code{nil} and the | |
1604 | minibuffer is selected, it takes precedence over | |
1605 | @code{other-window-scroll-buffer}. @xref{Definition of | |
1606 | minibuffer-scroll-window}. | |
1607 | ||
1608 | When the minibuffer is active, it is the next window if the selected | |
1609 | window is the one at the bottom right corner. In this case, | |
1610 | @code{scroll-other-window} attempts to scroll the minibuffer. If the | |
1611 | minibuffer contains just one line, it has nowhere to scroll to, so the | |
1612 | line reappears after the echo area momentarily displays the message | |
1613 | @samp{Beginning of buffer}. | |
1614 | @end deffn | |
1615 | ||
1616 | @c Emacs 19 feature | |
1617 | @defvar other-window-scroll-buffer | |
1618 | If this variable is non-@code{nil}, it tells @code{scroll-other-window} | |
0273ca3a | 1619 | which buffer's window to scroll. |
b8d4c8d0 GM |
1620 | @end defvar |
1621 | ||
1622 | @defopt scroll-margin | |
1623 | This option specifies the size of the scroll margin---a minimum number | |
1624 | of lines between point and the top or bottom of a window. Whenever | |
1625 | point gets within this many lines of the top or bottom of the window, | |
1626 | redisplay scrolls the text automatically (if possible) to move point | |
1627 | out of the margin, closer to the center of the window. | |
1628 | @end defopt | |
1629 | ||
1630 | @defopt scroll-conservatively | |
1631 | This variable controls how scrolling is done automatically when point | |
1632 | moves off the screen (or into the scroll margin). If the value is a | |
1633 | positive integer @var{n}, then redisplay scrolls the text up to | |
1634 | @var{n} lines in either direction, if that will bring point back into | |
0273ca3a | 1635 | proper view. This behavior is called @dfn{conservative scrolling}. |
b8d4c8d0 GM |
1636 | Otherwise, scrolling happens in the usual way, under the control of |
1637 | other variables such as @code{scroll-up-aggressively} and | |
1638 | @code{scroll-down-aggressively}. | |
1639 | ||
1640 | The default value is zero, which means that conservative scrolling | |
1641 | never happens. | |
1642 | @end defopt | |
1643 | ||
1644 | @defopt scroll-down-aggressively | |
1645 | The value of this variable should be either @code{nil} or a fraction | |
1646 | @var{f} between 0 and 1. If it is a fraction, that specifies where on | |
1647 | the screen to put point when scrolling down. More precisely, when a | |
1648 | window scrolls down because point is above the window start, the new | |
1649 | start position is chosen to put point @var{f} part of the window | |
1650 | height from the top. The larger @var{f}, the more aggressive the | |
1651 | scrolling. | |
1652 | ||
1653 | A value of @code{nil} is equivalent to .5, since its effect is to center | |
1654 | point. This variable automatically becomes buffer-local when set in any | |
1655 | fashion. | |
1656 | @end defopt | |
1657 | ||
1658 | @defopt scroll-up-aggressively | |
1659 | Likewise, for scrolling up. The value, @var{f}, specifies how far | |
1660 | point should be placed from the bottom of the window; thus, as with | |
1661 | @code{scroll-up-aggressively}, a larger value scrolls more aggressively. | |
1662 | @end defopt | |
1663 | ||
1664 | @defopt scroll-step | |
1665 | This variable is an older variant of @code{scroll-conservatively}. The | |
1666 | difference is that it if its value is @var{n}, that permits scrolling | |
1667 | only by precisely @var{n} lines, not a smaller number. This feature | |
1668 | does not work with @code{scroll-margin}. The default value is zero. | |
1669 | @end defopt | |
1670 | ||
1671 | @defopt scroll-preserve-screen-position | |
1672 | If this option is @code{t}, scrolling which would move the current | |
1673 | point position out of the window chooses the new position of point | |
1674 | so that the vertical position of the cursor is unchanged, if possible. | |
1675 | ||
1676 | If it is non-@code{nil} and not @code{t}, then the scrolling functions | |
1677 | always preserve the vertical position of point, if possible. | |
1678 | @end defopt | |
1679 | ||
1680 | @defopt next-screen-context-lines | |
1681 | The value of this variable is the number of lines of continuity to | |
1682 | retain when scrolling by full screens. For example, @code{scroll-up} | |
1683 | with an argument of @code{nil} scrolls so that this many lines at the | |
1684 | bottom of the window appear instead at the top. The default value is | |
1685 | @code{2}. | |
1686 | @end defopt | |
1687 | ||
1688 | @deffn Command recenter &optional count | |
1689 | @cindex centering point | |
1690 | This function scrolls the text in the selected window so that point is | |
1691 | displayed at a specified vertical position within the window. It does | |
1692 | not ``move point'' with respect to the text. | |
1693 | ||
1694 | If @var{count} is a nonnegative number, that puts the line containing | |
1695 | point @var{count} lines down from the top of the window. If | |
1696 | @var{count} is a negative number, then it counts upward from the | |
1697 | bottom of the window, so that @minus{}1 stands for the last usable | |
1698 | line in the window. If @var{count} is a non-@code{nil} list, then it | |
1699 | stands for the line in the middle of the window. | |
1700 | ||
1701 | If @var{count} is @code{nil}, @code{recenter} puts the line containing | |
1702 | point in the middle of the window, then clears and redisplays the entire | |
1703 | selected frame. | |
1704 | ||
1705 | When @code{recenter} is called interactively, @var{count} is the raw | |
1706 | prefix argument. Thus, typing @kbd{C-u} as the prefix sets the | |
1707 | @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets | |
1708 | @var{count} to 4, which positions the current line four lines from the | |
1709 | top. | |
1710 | ||
1711 | With an argument of zero, @code{recenter} positions the current line at | |
1712 | the top of the window. This action is so handy that some people make a | |
1713 | separate key binding to do this. For example, | |
1714 | ||
1715 | @example | |
1716 | @group | |
1717 | (defun line-to-top-of-window () | |
1718 | "Scroll current line to top of window. | |
1719 | Replaces three keystroke sequence C-u 0 C-l." | |
1720 | (interactive) | |
1721 | (recenter 0)) | |
1722 | ||
1723 | (global-set-key [kp-multiply] 'line-to-top-of-window) | |
1724 | @end group | |
1725 | @end example | |
1726 | @end deffn | |
1727 | ||
1728 | @node Vertical Scrolling | |
1729 | @section Vertical Fractional Scrolling | |
1730 | @cindex vertical fractional scrolling | |
0273ca3a | 1731 | @cindex vertical scroll position |
b8d4c8d0 | 1732 | |
af1a5cd5 MR |
1733 | @dfn{Vertical fractional scrolling} means shifting text in a window |
1734 | up or down by a specified multiple or fraction of a line. Each window | |
1735 | has a @dfn{vertical scroll position}, which is a number, never less than | |
0273ca3a MR |
1736 | zero. It specifies how far to raise the contents of the window. |
1737 | Raising the window contents generally makes all or part of some lines | |
1738 | disappear off the top, and all or part of some other lines appear at the | |
1739 | bottom. The usual value is zero. | |
b8d4c8d0 | 1740 | |
af1a5cd5 | 1741 | The vertical scroll position is measured in units of the normal line |
b8d4c8d0 GM |
1742 | height, which is the height of the default font. Thus, if the value is |
1743 | .5, that means the window contents are scrolled up half the normal line | |
1744 | height. If it is 3.3, that means the window contents are scrolled up | |
1745 | somewhat over three times the normal line height. | |
1746 | ||
af1a5cd5 | 1747 | What fraction of a line the vertical scrolling covers, or how many |
b8d4c8d0 GM |
1748 | lines, depends on what the lines contain. A value of .5 could scroll a |
1749 | line whose height is very short off the screen, while a value of 3.3 | |
1750 | could scroll just part of the way through a tall line or an image. | |
1751 | ||
1752 | @defun window-vscroll &optional window pixels-p | |
1753 | This function returns the current vertical scroll position of | |
aeeedf76 MR |
1754 | @var{window}. The default for @var{window} is the selected window. |
1755 | If @var{pixels-p} is non-@code{nil}, the return value is measured in | |
0273ca3a | 1756 | pixels, rather than in units of the normal line height. |
b8d4c8d0 GM |
1757 | |
1758 | @example | |
1759 | @group | |
1760 | (window-vscroll) | |
1761 | @result{} 0 | |
1762 | @end group | |
1763 | @end example | |
1764 | @end defun | |
1765 | ||
1766 | @defun set-window-vscroll window lines &optional pixels-p | |
1767 | This function sets @var{window}'s vertical scroll position to | |
0273ca3a MR |
1768 | @var{lines}. If @var{window} is @code{nil}, the selected window is |
1769 | used. The argument @var{lines} should be zero or positive; if not, it | |
1770 | is taken as zero. | |
b8d4c8d0 | 1771 | |
b8d4c8d0 GM |
1772 | |
1773 | The actual vertical scroll position must always correspond | |
1774 | to an integral number of pixels, so the value you specify | |
1775 | is rounded accordingly. | |
1776 | ||
1777 | The return value is the result of this rounding. | |
1778 | ||
1779 | @example | |
1780 | @group | |
1781 | (set-window-vscroll (selected-window) 1.2) | |
1782 | @result{} 1.13 | |
1783 | @end group | |
1784 | @end example | |
1785 | ||
1786 | If @var{pixels-p} is non-@code{nil}, @var{lines} specifies a number of | |
1787 | pixels. In this case, the return value is @var{lines}. | |
1788 | @end defun | |
1789 | ||
1790 | @defvar auto-window-vscroll | |
1791 | If this variable is non-@code{nil}, the line-move, scroll-up, and | |
0273ca3a MR |
1792 | scroll-down functions will automatically modify the vertical scroll |
1793 | position to scroll through display rows that are taller that the height | |
1794 | of the window, for example in the presence of large images. | |
b8d4c8d0 GM |
1795 | @end defvar |
1796 | ||
1797 | @node Horizontal Scrolling | |
1798 | @section Horizontal Scrolling | |
1799 | @cindex horizontal scrolling | |
1800 | ||
1801 | @dfn{Horizontal scrolling} means shifting the image in the window left | |
1802 | or right by a specified multiple of the normal character width. Each | |
1803 | window has a @dfn{horizontal scroll position}, which is a number, never | |
1804 | less than zero. It specifies how far to shift the contents left. | |
1805 | Shifting the window contents left generally makes all or part of some | |
1806 | characters disappear off the left, and all or part of some other | |
1807 | characters appear at the right. The usual value is zero. | |
1808 | ||
1809 | The horizontal scroll position is measured in units of the normal | |
1810 | character width, which is the width of space in the default font. Thus, | |
1811 | if the value is 5, that means the window contents are scrolled left by 5 | |
1812 | times the normal character width. How many characters actually | |
1813 | disappear off to the left depends on their width, and could vary from | |
1814 | line to line. | |
1815 | ||
1816 | Because we read from side to side in the ``inner loop,'' and from top | |
1817 | to bottom in the ``outer loop,'' the effect of horizontal scrolling is | |
1818 | not like that of textual or vertical scrolling. Textual scrolling | |
1819 | involves selection of a portion of text to display, and vertical | |
1820 | scrolling moves the window contents contiguously; but horizontal | |
1821 | scrolling causes part of @emph{each line} to go off screen. | |
1822 | ||
1823 | Usually, no horizontal scrolling is in effect; then the leftmost | |
1824 | column is at the left edge of the window. In this state, scrolling to | |
1825 | the right is meaningless, since there is no data to the left of the edge | |
1826 | to be revealed by it; so this is not allowed. Scrolling to the left is | |
1827 | allowed; it scrolls the first columns of text off the edge of the window | |
1828 | and can reveal additional columns on the right that were truncated | |
1829 | before. Once a window has a nonzero amount of leftward horizontal | |
1830 | scrolling, you can scroll it back to the right, but only so far as to | |
1831 | reduce the net horizontal scroll to zero. There is no limit to how far | |
1832 | left you can scroll, but eventually all the text will disappear off the | |
1833 | left edge. | |
1834 | ||
1835 | @vindex auto-hscroll-mode | |
1836 | If @code{auto-hscroll-mode} is set, redisplay automatically alters | |
1837 | the horizontal scrolling of a window as necessary to ensure that point | |
1838 | is always visible. However, you can still set the horizontal | |
1839 | scrolling value explicitly. The value you specify serves as a lower | |
1840 | bound for automatic scrolling, i.e. automatic scrolling will not | |
1841 | scroll a window to a column less than the specified one. | |
1842 | ||
1843 | @deffn Command scroll-left &optional count set-minimum | |
1844 | This function scrolls the selected window @var{count} columns to the | |
1845 | left (or to the right if @var{count} is negative). The default | |
1846 | for @var{count} is the window width, minus 2. | |
1847 | ||
1848 | The return value is the total amount of leftward horizontal scrolling in | |
1849 | effect after the change---just like the value returned by | |
1850 | @code{window-hscroll} (below). | |
1851 | ||
1852 | Once you scroll a window as far right as it can go, back to its normal | |
1853 | position where the total leftward scrolling is zero, attempts to scroll | |
1854 | any farther right have no effect. | |
1855 | ||
1856 | If @var{set-minimum} is non-@code{nil}, the new scroll amount becomes | |
1857 | the lower bound for automatic scrolling; that is, automatic scrolling | |
1858 | will not scroll a window to a column less than the value returned by | |
1859 | this function. Interactive calls pass non-@code{nil} for | |
1860 | @var{set-minimum}. | |
1861 | @end deffn | |
1862 | ||
1863 | @deffn Command scroll-right &optional count set-minimum | |
1864 | This function scrolls the selected window @var{count} columns to the | |
1865 | right (or to the left if @var{count} is negative). The default | |
1866 | for @var{count} is the window width, minus 2. Aside from the direction | |
1867 | of scrolling, this works just like @code{scroll-left}. | |
1868 | @end deffn | |
1869 | ||
1870 | @defun window-hscroll &optional window | |
1871 | This function returns the total leftward horizontal scrolling of | |
1872 | @var{window}---the number of columns by which the text in @var{window} | |
aeeedf76 MR |
1873 | is scrolled left past the left margin. The default for |
1874 | @var{window} is the selected window. | |
b8d4c8d0 | 1875 | |
0273ca3a MR |
1876 | The return value is never negative. It is zero when no horizontal |
1877 | scrolling has been done in @var{window} (which is usually the case). | |
b8d4c8d0 | 1878 | |
b8d4c8d0 GM |
1879 | |
1880 | @example | |
1881 | @group | |
1882 | (window-hscroll) | |
1883 | @result{} 0 | |
1884 | @end group | |
1885 | @group | |
1886 | (scroll-left 5) | |
1887 | @result{} 5 | |
1888 | @end group | |
1889 | @group | |
1890 | (window-hscroll) | |
1891 | @result{} 5 | |
1892 | @end group | |
1893 | @end example | |
1894 | @end defun | |
1895 | ||
1896 | @defun set-window-hscroll window columns | |
1897 | This function sets horizontal scrolling of @var{window}. The value of | |
1898 | @var{columns} specifies the amount of scrolling, in terms of columns | |
1899 | from the left margin. The argument @var{columns} should be zero or | |
1900 | positive; if not, it is taken as zero. Fractional values of | |
1901 | @var{columns} are not supported at present. | |
1902 | ||
1903 | Note that @code{set-window-hscroll} may appear not to work if you test | |
1904 | it by evaluating a call with @kbd{M-:} in a simple way. What happens | |
1905 | is that the function sets the horizontal scroll value and returns, but | |
1906 | then redisplay adjusts the horizontal scrolling to make point visible, | |
1907 | and this overrides what the function did. You can observe the | |
1908 | function's effect if you call it while point is sufficiently far from | |
1909 | the left margin that it will remain visible. | |
1910 | ||
1911 | The value returned is @var{columns}. | |
1912 | ||
1913 | @example | |
1914 | @group | |
1915 | (set-window-hscroll (selected-window) 10) | |
1916 | @result{} 10 | |
1917 | @end group | |
1918 | @end example | |
1919 | @end defun | |
1920 | ||
af1a5cd5 MR |
1921 | Here is how you can determine whether a given position @var{position} |
1922 | is off the screen due to horizontal scrolling: | |
b8d4c8d0 GM |
1923 | |
1924 | @example | |
1925 | @group | |
1926 | (defun hscroll-on-screen (window position) | |
1927 | (save-excursion | |
1928 | (goto-char position) | |
1929 | (and | |
1930 | (>= (- (current-column) (window-hscroll window)) 0) | |
1931 | (< (- (current-column) (window-hscroll window)) | |
1932 | (window-width window))))) | |
1933 | @end group | |
1934 | @end example | |
1935 | ||
1936 | @node Size of Window | |
1937 | @section The Size of a Window | |
1938 | @cindex window size | |
1939 | @cindex size of window | |
1940 | ||
1941 | An Emacs window is rectangular, and its size information consists of | |
1942 | the height (the number of lines) and the width (the number of character | |
1943 | positions in each line). The mode line is included in the height. But | |
1944 | the width does not count the scroll bar or the column of @samp{|} | |
1945 | characters that separates side-by-side windows. | |
1946 | ||
1947 | The following three functions return size information about a window: | |
1948 | ||
1949 | @defun window-height &optional window | |
0273ca3a MR |
1950 | This function returns the number of lines in @var{window}, including its |
1951 | mode line and header line, if any. If @var{window} fills its entire | |
1952 | frame except for the echo area, this is typically one less than the | |
aeeedf76 MR |
1953 | value of @code{frame-height} on that frame. The default for |
1954 | @var{window} is the selected window. | |
b8d4c8d0 GM |
1955 | |
1956 | @example | |
1957 | @group | |
1958 | (window-height) | |
1959 | @result{} 23 | |
1960 | @end group | |
1961 | @group | |
1962 | (split-window-vertically) | |
1963 | @result{} #<window 4 on windows.texi> | |
1964 | @end group | |
1965 | @group | |
1966 | (window-height) | |
1967 | @result{} 11 | |
1968 | @end group | |
1969 | @end example | |
1970 | @end defun | |
1971 | ||
1972 | @defun window-body-height &optional window | |
1973 | Like @code{window-height} but the value does not include the | |
1974 | mode line (if any) or the header line (if any). | |
1975 | @end defun | |
1976 | ||
1977 | @defun window-width &optional window | |
aeeedf76 MR |
1978 | This function returns the number of columns in @var{window}. The |
1979 | default for @var{window} is the selected window. | |
b8d4c8d0 | 1980 | |
0273ca3a MR |
1981 | The return value does not include the window's scroll bar or the column |
1982 | of @samp{|} characters that separates side-by-side windows. Moreover, | |
1983 | the return value does not include the space used for displaying fringes | |
1984 | and margins. Hence you cannot, in general, compare the return values of | |
1985 | @code{window-width} and @code{frame-width} for equality to determine | |
1986 | whether a window is a wide as the containing frame. Use the function | |
1987 | @code{window-full-width-p}, see below, instead. | |
b8d4c8d0 GM |
1988 | |
1989 | @example | |
1990 | @group | |
1991 | (window-width) | |
1992 | @result{} 80 | |
1993 | @end group | |
1994 | @end example | |
1995 | @end defun | |
1996 | ||
1997 | @defun window-full-width-p &optional window | |
0273ca3a | 1998 | This function returns non-@code{nil} if @var{window} is as wide as the |
aeeedf76 MR |
1999 | frame that contains it; otherwise @code{nil}. The default for |
2000 | @var{window} is the selected window. | |
b8d4c8d0 GM |
2001 | @end defun |
2002 | ||
2003 | @defun window-edges &optional window | |
2004 | This function returns a list of the edge coordinates of @var{window}. | |
aeeedf76 | 2005 | The default for @var{window} is the selected window. |
b8d4c8d0 GM |
2006 | |
2007 | The order of the list is @code{(@var{left} @var{top} @var{right} | |
2008 | @var{bottom})}, all elements relative to 0, 0 at the top left corner of | |
2009 | the frame. The element @var{right} of the value is one more than the | |
2010 | rightmost column used by @var{window}, and @var{bottom} is one more than | |
2011 | the bottommost row used by @var{window} and its mode-line. | |
2012 | ||
2013 | The edges include the space used by the window's scroll bar, display | |
2014 | margins, fringes, header line, and mode line, if it has them. Also, | |
2015 | if the window has a neighbor on the right, its right edge value | |
2016 | includes the width of the separator line between the window and that | |
2017 | neighbor. Since the width of the window does not include this | |
2018 | separator, the width does not usually equal the difference between the | |
2019 | right and left edges. | |
2020 | @end defun | |
2021 | ||
2022 | @defun window-inside-edges &optional window | |
2023 | This is similar to @code{window-edges}, but the edge values | |
2024 | it returns include only the text area of the window. They | |
2025 | do not include the header line, mode line, scroll bar or | |
2026 | vertical separator, fringes, or display margins. | |
2027 | @end defun | |
2028 | ||
2029 | Here are the results obtained on a typical 24-line terminal with just | |
2030 | one window, with menu bar enabled: | |
2031 | ||
2032 | @example | |
2033 | @group | |
2034 | (window-edges (selected-window)) | |
2035 | @result{} (0 1 80 23) | |
2036 | @end group | |
2037 | @group | |
2038 | (window-inside-edges (selected-window)) | |
2039 | @result{} (0 1 80 22) | |
2040 | @end group | |
2041 | @end example | |
2042 | ||
2043 | @noindent | |
2044 | The bottom edge is at line 23 because the last line is the echo area. | |
2045 | The bottom inside edge is at line 22, which is the window's mode line. | |
2046 | ||
2047 | If @var{window} is at the upper left corner of its frame, and there is | |
2048 | no menu bar, then @var{bottom} returned by @code{window-edges} is the | |
2049 | same as the value of @code{(window-height)}, @var{right} is almost the | |
2050 | same as the value of @code{(window-width)}, and @var{top} and | |
2051 | @var{left} are zero. For example, the edges of the following window | |
2052 | are @w{@samp{0 0 8 5}}. Assuming that the frame has more than 8 | |
2053 | columns, the last column of the window (column 7) holds a border | |
2054 | rather than text. The last row (row 4) holds the mode line, shown | |
2055 | here with @samp{xxxxxxxxx}. | |
2056 | ||
2057 | @example | |
2058 | @group | |
2059 | 0 | |
2060 | _______ | |
2061 | 0 | | | |
2062 | | | | |
2063 | | | | |
2064 | | | | |
2065 | xxxxxxxxx 4 | |
2066 | ||
2067 | 7 | |
2068 | @end group | |
2069 | @end example | |
2070 | ||
2071 | In the following example, let's suppose that the frame is 7 | |
2072 | columns wide. Then the edges of the left window are @w{@samp{0 0 4 3}} | |
2073 | and the edges of the right window are @w{@samp{4 0 7 3}}. | |
2074 | The inside edges of the left window are @w{@samp{0 0 3 2}}, | |
2075 | and the inside edges of the right window are @w{@samp{4 0 7 2}}, | |
2076 | ||
2077 | @example | |
2078 | @group | |
2079 | ___ ___ | |
2080 | | | | | |
2081 | | | | | |
2082 | xxxxxxxxx | |
2083 | ||
2084 | 0 34 7 | |
2085 | @end group | |
2086 | @end example | |
2087 | ||
2088 | @defun window-pixel-edges &optional window | |
2089 | This function is like @code{window-edges} except that, on a graphical | |
2090 | display, the edge values are measured in pixels instead of in | |
2091 | character lines and columns. | |
2092 | @end defun | |
2093 | ||
2094 | @defun window-inside-pixel-edges &optional window | |
2095 | This function is like @code{window-inside-edges} except that, on a | |
2096 | graphical display, the edge values are measured in pixels instead of | |
2097 | in character lines and columns. | |
2098 | @end defun | |
2099 | ||
2100 | @node Resizing Windows | |
2101 | @section Changing the Size of a Window | |
2102 | @cindex window resizing | |
2103 | @cindex resize window | |
2104 | @cindex changing window size | |
2105 | @cindex window size, changing | |
2106 | ||
af1a5cd5 | 2107 | The window size functions fall into two classes: high-level commands |
b8d4c8d0 GM |
2108 | that change the size of windows and low-level functions that access |
2109 | window size. Emacs does not permit overlapping windows or gaps between | |
0273ca3a | 2110 | windows, so resizing a window always affects at least one other window. |
b8d4c8d0 GM |
2111 | |
2112 | @deffn Command enlarge-window size &optional horizontal | |
0273ca3a MR |
2113 | This function makes the selected window @var{size} lines taller by |
2114 | stealing lines from windows above or below. In a first round, it takes | |
2115 | lines from one window at a time until that window is | |
2116 | @code{window-min-height} lines tall, then takes from another. If, at | |
2117 | the end of the first round, the selected window is still not tall | |
2118 | enough, @code{enlarge-window} starts a second round, where it deletes | |
2119 | windows above or below the selected one. | |
b8d4c8d0 | 2120 | |
5d8dda33 MR |
2121 | If @var{horizontal} is non-@code{nil}, this function makes the window |
2122 | @var{size} columns wider, stealing columns instead of lines. If a | |
2123 | window from which columns are stolen shrinks below | |
b8d4c8d0 GM |
2124 | @code{window-min-width} columns, that window disappears. |
2125 | ||
2126 | If the requested size would exceed that of the window's frame, then the | |
2127 | function makes the window occupy the entire height (or width) of the | |
2128 | frame. | |
2129 | ||
2130 | If there are various other windows from which lines or columns can be | |
2131 | stolen, and some of them specify fixed size (using | |
2132 | @code{window-size-fixed}, see below), they are left untouched while | |
a1401ab1 | 2133 | other windows are ``robbed.'' If it would be necessary to alter the |
b8d4c8d0 GM |
2134 | size of a fixed-size window, @code{enlarge-window} gets an error |
2135 | instead. | |
2136 | ||
10e187e8 | 2137 | If @var{size} is negative, this function shrinks the selected window by |
b8d4c8d0 GM |
2138 | @minus{}@var{size} lines or columns. If that makes the window smaller |
2139 | than the minimum size (@code{window-min-height} and | |
0273ca3a | 2140 | @code{window-min-width}), then @code{enlarge-window} deletes the window. |
b8d4c8d0 GM |
2141 | |
2142 | @code{enlarge-window} returns @code{nil}. | |
2143 | @end deffn | |
2144 | ||
2145 | @deffn Command enlarge-window-horizontally columns | |
2146 | This function makes the selected window @var{columns} wider. | |
2147 | It could be defined as follows: | |
2148 | ||
2149 | @example | |
2150 | @group | |
2151 | (defun enlarge-window-horizontally (columns) | |
2152 | (interactive "p") | |
2153 | (enlarge-window columns t)) | |
2154 | @end group | |
2155 | @end example | |
2156 | @end deffn | |
2157 | ||
2158 | @deffn Command shrink-window size &optional horizontal | |
2159 | This function is like @code{enlarge-window} but negates the argument | |
2160 | @var{size}, making the selected window smaller by giving lines (or | |
2161 | columns) to the other windows. If the window shrinks below | |
2162 | @code{window-min-height} or @code{window-min-width}, then it disappears. | |
2163 | ||
2164 | If @var{size} is negative, the window is enlarged by @minus{}@var{size} | |
2165 | lines or columns. | |
2166 | @end deffn | |
2167 | ||
2168 | @deffn Command shrink-window-horizontally columns | |
2169 | This function makes the selected window @var{columns} narrower. | |
2170 | It could be defined as follows: | |
2171 | ||
2172 | @example | |
2173 | @group | |
2174 | (defun shrink-window-horizontally (columns) | |
2175 | (interactive "p") | |
2176 | (shrink-window columns t)) | |
2177 | @end group | |
2178 | @end example | |
2179 | @end deffn | |
2180 | ||
2181 | @defun adjust-window-trailing-edge window delta horizontal | |
2182 | This function makes the selected window @var{delta} lines taller or | |
2183 | @var{delta} columns wider, by moving the bottom or right edge. This | |
2184 | function does not delete other windows; if it cannot make the | |
2185 | requested size adjustment, it signals an error. On success, this | |
2186 | function returns @code{nil}. | |
2187 | @end defun | |
2188 | ||
2189 | @defun fit-window-to-buffer &optional window max-height min-height | |
2190 | This function makes @var{window} the right height to display its | |
dda87836 MR |
2191 | contents exactly. The default for @var{window} is the selected window. |
2192 | ||
2193 | The optional argument @var{max-height} specifies the maximum height the | |
2194 | window is allowed to be; @code{nil} means use the maximum permissible | |
2195 | height of a window on @var{window}'s frame. The optional argument | |
2196 | @var{min-height} specifies the minimum height for the window; @code{nil} | |
2197 | means use @code{window-min-height}. All these height values include the | |
2198 | mode line and/or header line. | |
2199 | ||
2200 | This function can delete windows when their height shrinks below | |
2201 | @var{min-height}. It returns non-@code{nil} if it orderly resized | |
2202 | @var{window}, and @code{nil} otherwise. | |
b8d4c8d0 GM |
2203 | @end defun |
2204 | ||
2205 | @deffn Command shrink-window-if-larger-than-buffer &optional window | |
0273ca3a MR |
2206 | This command shrinks @var{window} vertically to be as small as possible |
2207 | while still showing the full contents of its buffer---but not less than | |
aeeedf76 MR |
2208 | @code{window-min-height} lines. The default for @var{window} is |
2209 | the selected window. | |
b8d4c8d0 | 2210 | |
0273ca3a | 2211 | However, this command does nothing if the window is already too small to |
b8d4c8d0 GM |
2212 | display the whole text of the buffer, or if part of the contents are |
2213 | currently scrolled off screen, or if the window is not the full width of | |
2214 | its frame, or if the window is the only window in its frame. | |
2215 | ||
2216 | This command returns non-@code{nil} if it actually shrank the window | |
2217 | and @code{nil} otherwise. | |
2218 | @end deffn | |
2219 | ||
52a94b85 | 2220 | @cindex fixed-size window |
b8d4c8d0 | 2221 | @defvar window-size-fixed |
0273ca3a MR |
2222 | If this variable is non-@code{nil}, in a given buffer, then the size of |
2223 | any window displaying that buffer remains fixed unless you either | |
2224 | explicitly change it or Emacs has no other choice. | |
b8d4c8d0 GM |
2225 | |
2226 | If the value is @code{height}, then only the window's height is fixed; | |
2227 | if the value is @code{width}, then only the window's width is fixed. | |
2228 | Any other non-@code{nil} value fixes both the width and the height. | |
2229 | ||
2230 | This variable automatically becomes buffer-local when set. | |
2231 | ||
2232 | Explicit size-change functions such as @code{enlarge-window} | |
2233 | get an error if they would have to change a window size which is fixed. | |
2234 | Therefore, when you want to change the size of such a window, | |
2235 | you should bind @code{window-size-fixed} to @code{nil}, like this: | |
2236 | ||
2237 | @example | |
2238 | (let ((window-size-fixed nil)) | |
2239 | (enlarge-window 10)) | |
2240 | @end example | |
2241 | ||
0273ca3a MR |
2242 | Deleting an adjacent window or changing the frame size may change the |
2243 | size of a fixed-size window, if there is no other alternative. | |
b8d4c8d0 GM |
2244 | @end defvar |
2245 | ||
2246 | @cindex minimum window size | |
2247 | The following two variables constrain the window-structure-changing | |
2248 | functions to a minimum height and width. | |
2249 | ||
2250 | @defopt window-min-height | |
403b14d1 | 2251 | The value of this variable specifies how short a window may become |
b8d4c8d0 | 2252 | before it is automatically deleted. Making a window smaller than |
5d8dda33 MR |
2253 | @code{window-min-height} automatically deletes it, and no window may be |
2254 | created shorter than this. The value is measured in line units. When | |
0273ca3a | 2255 | the window wants a mode line and/or a header line, they are counted as |
aeeedf76 MR |
2256 | one line each. The default value is @code{4}. A value less than |
2257 | @code{1} is ignored. | |
b8d4c8d0 GM |
2258 | @end defopt |
2259 | ||
2260 | @defopt window-min-width | |
403b14d1 | 2261 | The value of this variable specifies how narrow a window may become |
b8d4c8d0 GM |
2262 | before it is automatically deleted. Making a window smaller than |
2263 | @code{window-min-width} automatically deletes it, and no window may be | |
5d8dda33 | 2264 | created narrower than this. The value is measured in characters and |
0273ca3a MR |
2265 | includes any fringes or the scroll bar. The default value is @code{10}. |
2266 | A value less than @code{2} is ignored. | |
b8d4c8d0 GM |
2267 | @end defopt |
2268 | ||
0273ca3a | 2269 | @cindex balancing window sizes |
a1401ab1 | 2270 | Emacs provides two functions to balance windows, that is, to even out |
0273ca3a MR |
2271 | the sizes of windows on the same frame. The minibuffer window and |
2272 | fixed-size windows are not resized by these functions. | |
2273 | ||
2274 | @deffn Command balance-windows &optional window-or-frame | |
2275 | This function balances windows in a way that gives more space to | |
2276 | full-width and/or full-height windows. If @var{window-or-frame} | |
2277 | specifies a frame, it balances all windows on that frame. If | |
2278 | @var{window-or-frame} specifies a window, it balances this window and | |
2279 | its ``siblings'' only. Think of a sibling as the other (original or | |
2280 | new) window with respect to the present one, involved in the process of | |
47264a97 | 2281 | splitting; see @ref{Splitting Windows}. Since a sibling may have been |
0273ca3a MR |
2282 | split again, a window can have more than one sibling. |
2283 | @end deffn | |
2284 | ||
2285 | @deffn Command balance-windows-area | |
2286 | This function attempts to give all windows on the selected frame | |
a1401ab1 | 2287 | approximately the same share of the screen area. This means that |
0273ca3a MR |
2288 | full-width or full-height windows are not given more space than other |
2289 | windows. | |
2290 | @end deffn | |
2291 | ||
b8d4c8d0 GM |
2292 | @node Coordinates and Windows |
2293 | @section Coordinates and Windows | |
2294 | ||
2295 | This section describes how to relate screen coordinates to windows. | |
2296 | ||
2297 | @defun window-at x y &optional frame | |
2298 | This function returns the window containing the specified cursor | |
2299 | position in the frame @var{frame}. The coordinates @var{x} and @var{y} | |
2300 | are measured in characters and count from the top left corner of the | |
2301 | frame. If they are out of range, @code{window-at} returns @code{nil}. | |
2302 | ||
2303 | If you omit @var{frame}, the selected frame is used. | |
2304 | @end defun | |
2305 | ||
2306 | @defun coordinates-in-window-p coordinates window | |
2307 | This function checks whether a particular frame position falls within | |
2308 | the window @var{window}. | |
2309 | ||
2310 | The argument @var{coordinates} is a cons cell of the form @code{(@var{x} | |
2311 | . @var{y})}. The coordinates @var{x} and @var{y} are measured in | |
2312 | characters, and count from the top left corner of the screen or frame. | |
2313 | ||
2314 | The value returned by @code{coordinates-in-window-p} is non-@code{nil} | |
2315 | if the coordinates are inside @var{window}. The value also indicates | |
2316 | what part of the window the position is in, as follows: | |
2317 | ||
2318 | @table @code | |
2319 | @item (@var{relx} . @var{rely}) | |
2320 | The coordinates are inside @var{window}. The numbers @var{relx} and | |
2321 | @var{rely} are the equivalent window-relative coordinates for the | |
2322 | specified position, counting from 0 at the top left corner of the | |
2323 | window. | |
2324 | ||
2325 | @item mode-line | |
2326 | The coordinates are in the mode line of @var{window}. | |
2327 | ||
2328 | @item header-line | |
2329 | The coordinates are in the header line of @var{window}. | |
2330 | ||
2331 | @item vertical-line | |
2332 | The coordinates are in the vertical line between @var{window} and its | |
2333 | neighbor to the right. This value occurs only if the window doesn't | |
2334 | have a scroll bar; positions in a scroll bar are considered outside the | |
2335 | window for these purposes. | |
2336 | ||
2337 | @item left-fringe | |
2338 | @itemx right-fringe | |
2339 | The coordinates are in the left or right fringe of the window. | |
2340 | ||
2341 | @item left-margin | |
2342 | @itemx right-margin | |
2343 | The coordinates are in the left or right margin of the window. | |
2344 | ||
2345 | @item nil | |
2346 | The coordinates are not in any part of @var{window}. | |
2347 | @end table | |
2348 | ||
2349 | The function @code{coordinates-in-window-p} does not require a frame as | |
2350 | argument because it always uses the frame that @var{window} is on. | |
2351 | @end defun | |
2352 | ||
2353 | @node Window Tree | |
2354 | @section The Window Tree | |
2355 | @cindex window tree | |
2356 | ||
2357 | A @dfn{window tree} specifies the layout, size, and relationship | |
2358 | between all windows in one frame. | |
2359 | ||
2360 | @defun window-tree &optional frame | |
2361 | This function returns the window tree for frame @var{frame}. | |
2362 | If @var{frame} is omitted, the selected frame is used. | |
2363 | ||
2364 | The return value is a list of the form @code{(@var{root} @var{mini})}, | |
2365 | where @var{root} represents the window tree of the frame's | |
2366 | root window, and @var{mini} is the frame's minibuffer window. | |
2367 | ||
2368 | If the root window is not split, @var{root} is the root window itself. | |
2369 | Otherwise, @var{root} is a list @code{(@var{dir} @var{edges} @var{w1} | |
2370 | @var{w2} ...)} where @var{dir} is @code{nil} for a horizontal split, | |
2371 | and @code{t} for a vertical split, @var{edges} gives the combined size and | |
2372 | position of the subwindows in the split, and the rest of the elements | |
2373 | are the subwindows in the split. Each of the subwindows may again be | |
2374 | a window or a list representing a window split, and so on. The | |
2375 | @var{edges} element is a list @code{(@var{left}@var{ top}@var{ right}@var{ bottom})} | |
2376 | similar to the value returned by @code{window-edges}. | |
2377 | @end defun | |
2378 | ||
2379 | @node Window Configurations | |
2380 | @section Window Configurations | |
2381 | @cindex window configurations | |
2382 | @cindex saving window information | |
2383 | ||
2384 | A @dfn{window configuration} records the entire layout of one | |
0273ca3a MR |
2385 | frame---all windows, their sizes, which buffers they contain, how those |
2386 | buffers are scrolled, and their values of point and the mark; also their | |
2387 | fringes, margins, and scroll bar settings. It also includes the value | |
2388 | of @code{minibuffer-scroll-window}. As a special exception, the window | |
2389 | configuration does not record the value of point in the selected window | |
2390 | for the current buffer. Also, the window configuration does not record | |
47264a97 | 2391 | the values of window parameters; see @ref{Window Parameters}. |
0273ca3a | 2392 | |
a1401ab1 EZ |
2393 | You can bring back an entire frame layout by restoring a previously |
2394 | saved window configuration. If you want to record the layout of all | |
0273ca3a | 2395 | frames instead of just one, use a frame configuration instead of a |
47264a97 | 2396 | window configuration; see @ref{Frame Configurations}. |
b8d4c8d0 GM |
2397 | |
2398 | @defun current-window-configuration &optional frame | |
2399 | This function returns a new object representing @var{frame}'s current | |
aeeedf76 MR |
2400 | window configuration. The default for @var{frame} is the selected |
2401 | frame. | |
b8d4c8d0 GM |
2402 | @end defun |
2403 | ||
2404 | @defun set-window-configuration configuration | |
2405 | This function restores the configuration of windows and buffers as | |
2406 | specified by @var{configuration}, for the frame that @var{configuration} | |
2407 | was created for. | |
2408 | ||
2409 | The argument @var{configuration} must be a value that was previously | |
0273ca3a | 2410 | returned by @code{current-window-configuration}. The configuration is |
b8d4c8d0 GM |
2411 | restored in the frame from which @var{configuration} was made, whether |
2412 | that frame is selected or not. This always counts as a window size | |
2413 | change and triggers execution of the @code{window-size-change-functions} | |
2414 | (@pxref{Window Hooks}), because @code{set-window-configuration} doesn't | |
2415 | know how to tell whether the new configuration actually differs from the | |
2416 | old one. | |
2417 | ||
2418 | If the frame which @var{configuration} was saved from is dead, all this | |
2419 | function does is restore the three variables @code{window-min-height}, | |
2420 | @code{window-min-width} and @code{minibuffer-scroll-window}. In this | |
2421 | case, the function returns @code{nil}. Otherwise, it returns @code{t}. | |
2422 | ||
2423 | Here is a way of using this function to get the same effect | |
2424 | as @code{save-window-excursion}: | |
2425 | ||
2426 | @example | |
2427 | @group | |
2428 | (let ((config (current-window-configuration))) | |
2429 | (unwind-protect | |
2430 | (progn (split-window-vertically nil) | |
2431 | @dots{}) | |
2432 | (set-window-configuration config))) | |
2433 | @end group | |
2434 | @end example | |
2435 | @end defun | |
2436 | ||
2437 | @defspec save-window-excursion forms@dots{} | |
2438 | This special form records the window configuration, executes @var{forms} | |
2439 | in sequence, then restores the earlier window configuration. The window | |
2440 | configuration includes, for each window, the value of point and the | |
2441 | portion of the buffer that is visible. It also includes the choice of | |
2442 | selected window. However, it does not include the value of point in | |
2443 | the current buffer; use @code{save-excursion} also, if you wish to | |
2444 | preserve that. | |
2445 | ||
2446 | Don't use this construct when @code{save-selected-window} is sufficient. | |
2447 | ||
0273ca3a | 2448 | Exit from @code{save-window-excursion} always triggers execution of |
b8d4c8d0 GM |
2449 | @code{window-size-change-functions}. (It doesn't know how to tell |
2450 | whether the restored configuration actually differs from the one in | |
2451 | effect at the end of the @var{forms}.) | |
2452 | ||
2453 | The return value is the value of the final form in @var{forms}. | |
2454 | For example: | |
2455 | ||
2456 | @example | |
2457 | @group | |
2458 | (split-window) | |
2459 | @result{} #<window 25 on control.texi> | |
2460 | @end group | |
2461 | @group | |
2462 | (setq w (selected-window)) | |
2463 | @result{} #<window 19 on control.texi> | |
2464 | @end group | |
2465 | @group | |
2466 | (save-window-excursion | |
2467 | (delete-other-windows w) | |
2468 | (switch-to-buffer "foo") | |
2469 | 'do-something) | |
2470 | @result{} do-something | |
2471 | ;; @r{The screen is now split again.} | |
2472 | @end group | |
2473 | @end example | |
2474 | @end defspec | |
2475 | ||
2476 | @defun window-configuration-p object | |
2477 | This function returns @code{t} if @var{object} is a window configuration. | |
2478 | @end defun | |
2479 | ||
2480 | @defun compare-window-configurations config1 config2 | |
2481 | This function compares two window configurations as regards the | |
2482 | structure of windows, but ignores the values of point and mark and the | |
2483 | saved scrolling positions---it can return @code{t} even if those | |
2484 | aspects differ. | |
2485 | ||
2486 | The function @code{equal} can also compare two window configurations; it | |
2487 | regards configurations as unequal if they differ in any respect, even a | |
2488 | saved point or mark. | |
2489 | @end defun | |
2490 | ||
2491 | @defun window-configuration-frame config | |
2492 | This function returns the frame for which the window configuration | |
2493 | @var{config} was made. | |
2494 | @end defun | |
2495 | ||
2496 | Other primitives to look inside of window configurations would make | |
2497 | sense, but are not implemented because we did not need them. See the | |
2498 | file @file{winner.el} for some more operations on windows | |
2499 | configurations. | |
2500 | ||
0273ca3a MR |
2501 | @node Window Parameters |
2502 | @section Window Parameters | |
2503 | @cindex window parameters | |
2504 | ||
2505 | This sections describes how window parameters can be used to associate | |
2506 | additional information with windows. | |
2507 | ||
2508 | @defun window-parameter window parameter | |
aeeedf76 MR |
2509 | This function returns @var{window}'s value for @var{parameter}. The |
2510 | default for @var{window} is the selected window. If @var{window} | |
2511 | has no setting for @var{parameter}, this function returns @code{nil}. | |
0273ca3a MR |
2512 | @end defun |
2513 | ||
a1401ab1 | 2514 | @defun window-parameters &optional window |
0273ca3a | 2515 | This function returns all parameters of @var{window} and their values. |
aeeedf76 MR |
2516 | The default for @var{window} is the selected window. The return value |
2517 | is an association list of elements of the form @code{(@var{parameter} | |
a1401ab1 | 2518 | . @var{value})}. |
0273ca3a MR |
2519 | @end defun |
2520 | ||
2521 | @defun set-window-parameter window parameter value | |
2522 | This function sets @var{window}'s value of @var{parameter} to | |
aeeedf76 MR |
2523 | @var{value} and returns @var{value}. The default for @var{window} |
2524 | is the selected window. | |
0273ca3a MR |
2525 | @end defun |
2526 | ||
2527 | Currently, window parameters are not saved in window configurations and | |
2528 | consequently not restored by @code{set-window-configuration}. Hence, | |
2529 | any change of a parameter introduced via @code{set-window-parameter} can | |
2530 | be undone only by invoking @code{set-window-parameter} for the same | |
2531 | parameter again. Since @code{save-window-excursion} relies on window | |
a1401ab1 EZ |
2532 | configurations (@pxref{Window Configurations}), window parameters are |
2533 | not saved and restored by that special form, either. | |
0273ca3a | 2534 | |
b8d4c8d0 GM |
2535 | @node Window Hooks |
2536 | @section Hooks for Window Scrolling and Changes | |
2537 | @cindex hooks for window operations | |
2538 | ||
2539 | This section describes how a Lisp program can take action whenever a | |
2540 | window displays a different part of its buffer or a different buffer. | |
2541 | There are three actions that can change this: scrolling the window, | |
2542 | switching buffers in the window, and changing the size of the window. | |
2543 | The first two actions run @code{window-scroll-functions}; the last runs | |
2544 | @code{window-size-change-functions}. | |
2545 | ||
2546 | @defvar window-scroll-functions | |
2547 | This variable holds a list of functions that Emacs should call before | |
0273ca3a MR |
2548 | redisplaying a window with scrolling. Displaying a different buffer in |
2549 | the window also runs these functions. | |
b8d4c8d0 | 2550 | |
0273ca3a MR |
2551 | This variable is not a normal hook, because each function is called with |
2552 | two arguments: the window, and its new display-start position. | |
b8d4c8d0 GM |
2553 | |
2554 | These functions must be careful in using @code{window-end} | |
0273ca3a MR |
2555 | (@pxref{Window Start and End}); if you need an up-to-date value, you |
2556 | must use the @var{update} argument to ensure you get it. | |
b8d4c8d0 GM |
2557 | |
2558 | @strong{Warning:} don't use this feature to alter the way the window | |
2559 | is scrolled. It's not designed for that, and such use probably won't | |
2560 | work. | |
2561 | @end defvar | |
2562 | ||
2563 | @defvar window-size-change-functions | |
2564 | This variable holds a list of functions to be called if the size of any | |
2565 | window changes for any reason. The functions are called just once per | |
2566 | redisplay, and just once for each frame on which size changes have | |
2567 | occurred. | |
2568 | ||
2569 | Each function receives the frame as its sole argument. There is no | |
2570 | direct way to find out which windows on that frame have changed size, or | |
2571 | precisely how. However, if a size-change function records, at each | |
2572 | call, the existing windows and their sizes, it can also compare the | |
2573 | present sizes and the previous sizes. | |
2574 | ||
2575 | Creating or deleting windows counts as a size change, and therefore | |
2576 | causes these functions to be called. Changing the frame size also | |
2577 | counts, because it changes the sizes of the existing windows. | |
2578 | ||
2579 | It is not a good idea to use @code{save-window-excursion} (@pxref{Window | |
2580 | Configurations}) in these functions, because that always counts as a | |
2581 | size change, and it would cause these functions to be called over and | |
2582 | over. In most cases, @code{save-selected-window} (@pxref{Selecting | |
2583 | Windows}) is what you need here. | |
2584 | @end defvar | |
2585 | ||
b8d4c8d0 GM |
2586 | @defvar window-configuration-change-hook |
2587 | A normal hook that is run every time you change the window configuration | |
2588 | of an existing frame. This includes splitting or deleting windows, | |
2589 | changing the sizes of windows, or displaying a different buffer in a | |
0273ca3a MR |
2590 | window. |
2591 | ||
2592 | The buffer-local part of this hook is run once per each window on the | |
2593 | affected frame, with the relevant window selected and its buffer | |
2594 | current. The global part is run once for the modified frame, with that | |
2595 | frame selected. | |
b8d4c8d0 GM |
2596 | @end defvar |
2597 | ||
38b1d346 CY |
2598 | In addition, you can use @code{jit-lock-register} to register a Font |
2599 | Lock fontification function, which will be called whenever part of the | |
2600 | buffer needs to be refontified (usually because it has been changed). | |
2601 | @xref{Other Font Lock Variables}. | |
2602 | ||
b8d4c8d0 GM |
2603 | @ignore |
2604 | arch-tag: 3f6c36e8-df49-4986-b757-417feed88be3 | |
2605 | @end ignore |