Mercurial > emacs
annotate lispref/windows.texi @ 13763:89bb535d206d
(struct buffer): Delete redisplay_end_trigger field.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 21 Dec 1995 16:56:26 +0000 |
parents | 33bdb63a2c59 |
children | 194145c1a2c0 |
rev | line source |
---|---|
6564 | 1 @c -*-texinfo-*- |
2 @c This is part of the GNU Emacs Lisp Reference Manual. | |
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. | |
4 @c See the file elisp.texi for copying conditions. | |
5 @setfilename ../info/windows | |
6 @node Windows, Frames, Buffers, Top | |
7 @chapter Windows | |
8 | |
9 This chapter describes most of the functions and variables related to | |
10 Emacs windows. See @ref{Display}, for information on how text is | |
11 displayed in windows. | |
12 | |
13 @menu | |
14 * Basic Windows:: Basic information on using windows. | |
15 * Splitting Windows:: Splitting one window into two windows. | |
16 * Deleting Windows:: Deleting a window gives its space to other windows. | |
17 * Selecting Windows:: The selected window is the one that you edit in. | |
18 * Cyclic Window Ordering:: Moving around the existing windows. | |
19 * Buffers and Windows:: Each window displays the contents of a buffer. | |
20 * Displaying Buffers:: Higher-lever functions for displaying a buffer | |
21 and choosing a window for it. | |
22 * Choosing Window:: How to choose a window for displaying a buffer. | |
23 * Window Point:: Each window has its own location of point. | |
24 * Window Start:: The display-start position controls which text | |
25 is on-screen in the window. | |
26 * Vertical Scrolling:: Moving text up and down in the window. | |
27 * Horizontal Scrolling:: Moving text sideways on the window. | |
28 * Size of Window:: Accessing the size of a window. | |
29 * Resizing Windows:: Changing the size of a window. | |
30 * Coordinates and Windows::Converting coordinates to windows. | |
31 * Window Configurations:: Saving and restoring the state of the screen. | |
32 @end menu | |
33 | |
34 @node Basic Windows | |
35 @section Basic Concepts of Emacs Windows | |
36 @cindex window | |
37 @cindex selected window | |
38 | |
12098 | 39 A @dfn{window} in Emacs is the physical area of the screen in which a |
40 buffer is displayed. The term is also used to refer to a Lisp object that | |
6564 | 41 represents that screen area in Emacs Lisp. It should be |
42 clear from the context which is meant. | |
43 | |
12098 | 44 Emacs groups windows into frames. A frame represents an area of |
45 screen available for Emacs to use. Each frame always contains at least | |
46 one window, but you can subdivide it vertically or horizontally into | |
47 multiple nonoverlapping Emacs windows. | |
6564 | 48 |
12098 | 49 In each frame, at any time, one and only one window is designated as |
50 @dfn{selected within the frame}. The frame's cursor appears in that | |
51 window. At ant time, one frame is the selected frame; and the window | |
52 selected within that frame is @dfn{the selected window}. The selected | |
53 window's buffer is usually the current buffer (except when | |
54 @code{set-buffer} has been used). @xref{Current Buffer}. | |
55 | |
56 For practical purposes, a window exists only while it is displayed in | |
57 a frame. Once removed from the frame, the window is effectively deleted | |
58 and should not be used, @emph{even though there may still be references | |
59 to it} from other Lisp objects. Restoring a saved window configuration | |
60 is the only way for a window no longer on the screen to come back to | |
61 life. (@xref{Deleting Windows}.) | |
6564 | 62 |
63 Each window has the following attributes: | |
64 | |
65 @itemize @bullet | |
66 @item | |
67 containing frame | |
68 | |
69 @item | |
70 window height | |
71 | |
72 @item | |
73 window width | |
74 | |
75 @item | |
76 window edges with respect to the screen or frame | |
77 | |
78 @item | |
79 the buffer it displays | |
80 | |
81 @item | |
82 position within the buffer at the upper left of the window | |
83 | |
84 @item | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
85 amount of horizontal scrolling, in columns |
6564 | 86 |
87 @item | |
88 point | |
89 | |
90 @item | |
91 the mark | |
92 | |
93 @item | |
94 how recently the window was selected | |
95 @end itemize | |
96 | |
97 @cindex multiple windows | |
98 Users create multiple windows so they can look at several buffers at | |
99 once. Lisp libraries use multiple windows for a variety of reasons, but | |
12098 | 100 most often to display related information. In Rmail, for example, you |
101 can move through a summary buffer in one window while the other window | |
102 shows messages one at a time as they are reached. | |
6564 | 103 |
104 The meaning of ``window'' in Emacs is similar to what it means in the | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
105 context of general-purpose window systems such as X, but not identical. |
12098 | 106 The X Window System places X windows on the screen; Emacs uses one or |
107 more X windows as frames, and subdivides them into | |
108 Emacs windows. When you use Emacs on a character-only terminal, Emacs | |
109 treats the whole terminal screen as one frame. | |
6564 | 110 |
111 @cindex terminal screen | |
112 @cindex screen of terminal | |
113 @cindex tiled windows | |
114 Most window systems support arbitrarily located overlapping windows. | |
115 In contrast, Emacs windows are @dfn{tiled}; they never overlap, and | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
116 together they fill the whole screen or frame. Because of the way |
6564 | 117 in which Emacs creates new windows and resizes them, you can't create |
118 every conceivable tiling of windows on an Emacs frame. @xref{Splitting | |
119 Windows}, and @ref{Size of Window}. | |
120 | |
121 @xref{Display}, for information on how the contents of the | |
122 window's buffer are displayed in the window. | |
123 | |
124 @defun windowp object | |
125 This function returns @code{t} if @var{object} is a window. | |
126 @end defun | |
127 | |
128 @node Splitting Windows | |
129 @section Splitting Windows | |
130 @cindex splitting windows | |
131 @cindex window splitting | |
132 | |
133 The functions described here are the primitives used to split a window | |
134 into two windows. Two higher level functions sometimes split a window, | |
135 but not always: @code{pop-to-buffer} and @code{display-buffer} | |
136 (@pxref{Displaying Buffers}). | |
137 | |
138 The functions described here do not accept a buffer as an argument. | |
139 The two ``halves'' of the split window initially display the same buffer | |
140 previously visible in the window that was split. | |
141 | |
142 @deffn Command split-window &optional window size horizontal | |
143 This function splits @var{window} into two windows. The original | |
144 window @var{window} remains the selected window, but occupies only | |
145 part of its former screen area. The rest is occupied by a newly created | |
146 window which is returned as the value of this function. | |
147 | |
148 If @var{horizontal} is non-@code{nil}, then @var{window} splits into | |
149 two side by side windows. The original window @var{window} keeps the | |
150 leftmost @var{size} columns, and gives the rest of the columns to the | |
151 new window. Otherwise, it splits into windows one above the other, and | |
152 @var{window} keeps the upper @var{size} lines and gives the rest of the | |
153 lines to the new window. The original window is therefore the | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
154 left-hand or upper of the two, and the new window is the right-hand or |
6564 | 155 lower. |
156 | |
157 If @var{window} is omitted or @code{nil}, then the selected window is | |
158 split. If @var{size} is omitted or @code{nil}, then @var{window} is | |
159 divided evenly into two parts. (If there is an odd line, it is | |
160 allocated to the new window.) When @code{split-window} is called | |
161 interactively, all its arguments are @code{nil}. | |
162 | |
163 The following example starts with one window on a screen that is 50 | |
164 lines high by 80 columns wide; then the window is split. | |
165 | |
166 @smallexample | |
167 @group | |
168 (setq w (selected-window)) | |
169 @result{} #<window 8 on windows.texi> | |
170 (window-edges) ; @r{Edges in order:} | |
171 @result{} (0 0 80 50) ; @r{left--top--right--bottom} | |
172 @end group | |
173 | |
174 @group | |
175 ;; @r{Returns window created} | |
176 (setq w2 (split-window w 15)) | |
177 @result{} #<window 28 on windows.texi> | |
178 @end group | |
179 @group | |
180 (window-edges w2) | |
181 @result{} (0 15 80 50) ; @r{Bottom window;} | |
182 ; @r{top is line 15} | |
183 @end group | |
184 @group | |
185 (window-edges w) | |
186 @result{} (0 0 80 15) ; @r{Top window} | |
187 @end group | |
188 @end smallexample | |
189 | |
190 The screen looks like this: | |
191 | |
192 @smallexample | |
193 @group | |
194 __________ | |
195 | | line 0 | |
196 | w | | |
197 |__________| | |
198 | | line 15 | |
199 | w2 | | |
200 |__________| | |
201 line 50 | |
202 column 0 column 80 | |
203 @end group | |
204 @end smallexample | |
205 | |
206 Next, the top window is split horizontally: | |
207 | |
208 @smallexample | |
209 @group | |
210 (setq w3 (split-window w 35 t)) | |
211 @result{} #<window 32 on windows.texi> | |
212 @end group | |
213 @group | |
214 (window-edges w3) | |
215 @result{} (35 0 80 15) ; @r{Left edge at column 35} | |
216 @end group | |
217 @group | |
218 (window-edges w) | |
219 @result{} (0 0 35 15) ; @r{Right edge at column 35} | |
220 @end group | |
221 @group | |
222 (window-edges w2) | |
223 @result{} (0 15 80 50) ; @r{Bottom window unchanged} | |
224 @end group | |
225 @end smallexample | |
226 | |
12282
586e3ea81792
updates for version 19.29 made by melissa; also needed to check out files
Melissa Weisshaus <melissa@gnu.org>
parents:
12125
diff
changeset
|
227 @need 3000 |
6564 | 228 Now, the screen looks like this: |
229 | |
230 @smallexample | |
231 @group | |
232 column 35 | |
233 __________ | |
234 | | | line 0 | |
235 | w | w3 | | |
236 |___|______| | |
237 | | line 15 | |
238 | w2 | | |
239 |__________| | |
240 line 50 | |
241 column 0 column 80 | |
242 @end group | |
243 @end smallexample | |
8926 | 244 |
245 Normally, Emacs indicates the border between two side-by-side windows | |
246 with a scroll bar (@pxref{X Frame Parameters,Scroll Bars}) or @samp{|} | |
247 characters. The display table can specify alternative border | |
248 characters; see @ref{Display Tables}. | |
6564 | 249 @end deffn |
250 | |
251 @deffn Command split-window-vertically size | |
252 This function splits the selected window into two windows, one above | |
253 the other, leaving the selected window with @var{size} lines. | |
254 | |
255 This function is simply an interface to @code{split-windows}. | |
256 Here is the complete function definition for it: | |
257 | |
258 @smallexample | |
259 @group | |
260 (defun split-window-vertically (&optional arg) | |
261 "Split current window into two windows, one above the other." | |
262 (interactive "P") | |
263 (split-window nil (and arg (prefix-numeric-value arg)))) | |
264 @end group | |
265 @end smallexample | |
266 @end deffn | |
267 | |
268 @deffn Command split-window-horizontally size | |
269 This function splits the selected window into two windows | |
270 side-by-side, leaving the selected window with @var{size} columns. | |
271 | |
272 This function is simply an interface to @code{split-windows}. Here is | |
273 the complete definition for @code{split-window-horizontally} (except for | |
274 part of the documentation string): | |
275 | |
276 @smallexample | |
277 @group | |
278 (defun split-window-horizontally (&optional arg) | |
279 "Split selected window into two windows, side by side..." | |
280 (interactive "P") | |
281 (split-window nil (and arg (prefix-numeric-value arg)) t)) | |
282 @end group | |
283 @end smallexample | |
284 @end deffn | |
285 | |
286 @defun one-window-p &optional no-mini all-frames | |
287 This function returns non-@code{nil} if there is only one window. The | |
288 argument @var{no-mini}, if non-@code{nil}, means don't count the | |
289 minibuffer even if it is active; otherwise, the minibuffer window is | |
12125
995be67f3fd1
updates for version 19.29.
Melissa Weisshaus <melissa@gnu.org>
parents:
12099
diff
changeset
|
290 included, if active, in the total number of windows, which is compared |
6564 | 291 against one. |
292 | |
293 The argument @var{all-frames} specifies which frames to consider. Here | |
294 are the possible values and their meanings: | |
295 | |
296 @table @asis | |
297 @item @code{nil} | |
298 Count the windows in the selected frame, plus the minibuffer used | |
299 by that frame even if it lies in some other frame. | |
300 | |
301 @item @code{t} | |
302 Count all windows in all existing frames. | |
303 | |
304 @item @code{visible} | |
305 Count all windows in all visible frames. | |
306 | |
12098 | 307 @item 0 |
308 Count all windows in all visible or iconified frames. | |
309 | |
6564 | 310 @item anything else |
311 Count precisely the windows in the selected frame, and no others. | |
312 @end table | |
313 @end defun | |
314 | |
315 @node Deleting Windows | |
316 @section Deleting Windows | |
317 @cindex deleting windows | |
318 | |
319 A window remains visible on its frame unless you @dfn{delete} it by | |
320 calling certain functions that delete windows. A deleted window cannot | |
321 appear on the screen, but continues to exist as a Lisp object until | |
322 there are no references to it. There is no way to cancel the deletion | |
323 of a window aside from restoring a saved window configuration | |
324 (@pxref{Window Configurations}). Restoring a window configuration also | |
325 deletes any windows that aren't part of that configuration. | |
326 | |
327 When you delete a window, the space it took up is given to one | |
328 adjacent sibling. (In Emacs version 18, the space was divided evenly | |
329 among all the siblings.) | |
330 | |
331 @c Emacs 19 feature | |
332 @defun window-live-p window | |
333 This function returns @code{nil} if @var{window} is deleted, and | |
334 @code{t} otherwise. | |
335 | |
7735
7db892210924
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7082
diff
changeset
|
336 @strong{Warning:} Erroneous information or fatal errors may result from |
6564 | 337 using a deleted window as if it were live. |
338 @end defun | |
339 | |
340 @deffn Command delete-window &optional window | |
341 This function removes @var{window} from the display. If @var{window} | |
342 is omitted, then the selected window is deleted. An error is signaled | |
343 if there is only one window when @code{delete-window} is called. | |
344 | |
345 This function returns @code{nil}. | |
346 | |
347 When @code{delete-window} is called interactively, @var{window} | |
348 defaults to the selected window. | |
349 @end deffn | |
350 | |
351 @deffn Command delete-other-windows &optional window | |
352 This function makes @var{window} the only window on its frame, by | |
353 deleting the other windows in that frame. If @var{window} is omitted or | |
354 @code{nil}, then the selected window is used by default. | |
355 | |
356 The result is @code{nil}. | |
357 @end deffn | |
358 | |
359 @deffn Command delete-windows-on buffer &optional frame | |
360 This function deletes all windows showing @var{buffer}. If there are | |
361 no windows showing @var{buffer}, it does nothing. | |
362 | |
363 @code{delete-windows-on} operates frame by frame. If a frame has | |
364 several windows showing different buffers, then those showing | |
365 @var{buffer} are removed, and the others expand to fill the space. If | |
366 all windows in some frame are showing @var{buffer} (including the case | |
367 where there is only one window), then the frame reverts to having a | |
368 single window showing another buffer chosen with @code{other-buffer}. | |
369 @xref{The Buffer List}. | |
370 | |
371 The argument @var{frame} controls which frames to operate on: | |
372 | |
373 @itemize @bullet | |
374 @item | |
375 If it is @code{nil}, operate on the selected frame. | |
376 @item | |
377 If it is @code{t}, operate on all frames. | |
378 @item | |
379 If it is @code{visible}, operate on all visible frames. | |
12098 | 380 @item 0 |
381 If it is 0, operate on all visible or iconified frames. | |
6564 | 382 @item |
383 If it is a frame, operate on that frame. | |
384 @end itemize | |
385 | |
386 This function always returns @code{nil}. | |
387 @end deffn | |
388 | |
389 @node Selecting Windows | |
390 @section Selecting Windows | |
391 @cindex selecting windows | |
392 | |
393 When a window is selected, the buffer in the window becomes the current | |
394 buffer, and the cursor will appear in it. | |
395 | |
396 @defun selected-window | |
397 This function returns the selected window. This is the window in | |
398 which the cursor appears and to which many commands apply. | |
399 @end defun | |
400 | |
401 @defun select-window window | |
402 This function makes @var{window} the selected window. The cursor then | |
403 appears in @var{window} (on redisplay). The buffer being displayed in | |
404 @var{window} is immediately designated the current buffer. | |
405 | |
406 The return value is @var{window}. | |
407 | |
408 @example | |
409 @group | |
410 (setq w (next-window)) | |
411 (select-window w) | |
412 @result{} #<window 65 on windows.texi> | |
413 @end group | |
414 @end example | |
415 @end defun | |
416 | |
12098 | 417 @defmac save-selected-window forms@dots{} |
418 This macro records the selected window, executes @var{forms} | |
419 in sequence, then restores the earlier selected window. | |
420 It does not save or restore anything about the sizes, arrangement | |
421 or contents of windows; therefore, if the @var{forms} change them, | |
422 the changes are permanent. | |
423 @end defmac | |
424 | |
6564 | 425 @cindex finding windows |
426 The following functions choose one of the windows on the screen, | |
427 offering various criteria for the choice. | |
428 | |
429 @defun get-lru-window &optional frame | |
430 This function returns the window least recently ``used'' (that is, | |
431 selected). The selected window is always the most recently used window. | |
432 | |
433 The selected window can be the least recently used window if it is the | |
434 only window. A newly created window becomes the least recently used | |
435 window until it is selected. A minibuffer window is never a candidate. | |
436 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
437 The argument @var{frame} controls which windows are considered. |
6564 | 438 |
439 @itemize @bullet | |
440 @item | |
441 If it is @code{nil}, consider windows on the selected frame. | |
442 @item | |
443 If it is @code{t}, consider windows on all frames. | |
444 @item | |
445 If it is @code{visible}, consider windows on all visible frames. | |
446 @item | |
12098 | 447 If it is 0, consider windows on all visible or iconified frames. |
448 @item | |
6564 | 449 If it is a frame, consider windows on that frame. |
450 @end itemize | |
451 @end defun | |
452 | |
453 @defun get-largest-window &optional frame | |
454 This function returns the window with the largest area (height times | |
455 width). If there are no side-by-side windows, then this is the window | |
456 with the most lines. A minibuffer window is never a candidate. | |
457 | |
458 If there are two windows of the same size, then the function returns | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
459 the window that is first in the cyclic ordering of windows (see |
6564 | 460 following section), starting from the selected window. |
461 | |
462 The argument @var{frame} controls which set of windows are | |
463 considered. See @code{get-lru-window}, above. | |
464 @end defun | |
465 | |
466 @node Cyclic Window Ordering | |
467 @comment node-name, next, previous, up | |
468 @section Cyclic Ordering of Windows | |
469 @cindex cyclic ordering of windows | |
470 @cindex ordering of windows, cyclic | |
471 @cindex window ordering, cyclic | |
472 | |
473 When you use the command @kbd{C-x o} (@code{other-window}) to select | |
474 the next window, it moves through all the windows on the screen in a | |
475 specific cyclic order. For any given configuration of windows, this | |
476 order never varies. It is called the @dfn{cyclic ordering of windows}. | |
477 | |
478 This ordering generally goes from top to bottom, and from left to | |
479 right. But it may go down first or go right first, depending on the | |
480 order in which the windows were split. | |
481 | |
482 If the first split was vertical (into windows one above each other), | |
483 and then the subwindows were split horizontally, then the ordering is | |
484 left to right in the top of the frame, and then left to right in the | |
485 next lower part of the frame, and so on. If the first split was | |
486 horizontal, the ordering is top to bottom in the left part, and so on. | |
487 In general, within each set of siblings at any level in the window tree, | |
488 the order is left to right, or top to bottom. | |
489 | |
490 @defun next-window &optional window minibuf all-frames | |
491 @cindex minibuffer window | |
492 This function returns the window following @var{window} in the cyclic | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
493 ordering of windows. This is the window that @kbd{C-x o} would select |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
494 if typed when @var{window} is selected. If @var{window} is the only |
6564 | 495 window visible, then this function returns @var{window}. If omitted, |
496 @var{window} defaults to the selected window. | |
497 | |
498 The value of the argument @var{minibuf} determines whether the | |
499 minibuffer is included in the window order. Normally, when | |
500 @var{minibuf} is @code{nil}, the minibuffer is included if it is | |
501 currently active; this is the behavior of @kbd{C-x o}. (The minibuffer | |
502 window is active while the minibuffer is in use. @xref{Minibuffers}.) | |
503 | |
504 If @var{minibuf} is @code{t}, then the cyclic ordering includes the | |
505 minibuffer window even if it is not active. | |
506 | |
507 If @var{minibuf} is neither @code{t} nor @code{nil}, then the minibuffer | |
508 window is not included even if it is active. | |
509 | |
510 The argument @var{all-frames} specifies which frames to consider. Here | |
511 are the possible values and their meanings: | |
512 | |
513 @table @asis | |
514 @item @code{nil} | |
515 Consider all the windows in @var{window}'s frame, plus the minibuffer | |
516 used by that frame even if it lies in some other frame. | |
517 | |
518 @item @code{t} | |
519 Consider all windows in all existing frames. | |
520 | |
521 @item @code{visible} | |
522 Consider all windows in all visible frames. (To get useful results, you | |
523 must ensure @var{window} is in a visible frame.) | |
524 | |
12099 | 525 @item 0 |
12098 | 526 Consider all windows in all visible or iconified frames. |
527 | |
6564 | 528 @item anything else |
529 Consider precisely the windows in @var{window}'s frame, and no others. | |
530 @end table | |
531 | |
532 This example assumes there are two windows, both displaying the | |
533 buffer @samp{windows.texi}: | |
534 | |
535 @example | |
536 @group | |
537 (selected-window) | |
538 @result{} #<window 56 on windows.texi> | |
539 @end group | |
540 @group | |
541 (next-window (selected-window)) | |
542 @result{} #<window 52 on windows.texi> | |
543 @end group | |
544 @group | |
545 (next-window (next-window (selected-window))) | |
546 @result{} #<window 56 on windows.texi> | |
547 @end group | |
548 @end example | |
549 @end defun | |
550 | |
551 @defun previous-window &optional window minibuf all-frames | |
552 This function returns the window preceding @var{window} in the cyclic | |
553 ordering of windows. The other arguments specify which windows to | |
554 include in the cycle, as in @code{next-window}. | |
555 @end defun | |
556 | |
557 @deffn Command other-window count | |
558 This function selects the @var{count}th following window in the cyclic | |
559 order. If count is negative, then it selects the @minus{}@var{count}th | |
560 preceding window. It returns @code{nil}. | |
561 | |
562 In an interactive call, @var{count} is the numeric prefix argument. | |
563 @end deffn | |
564 | |
565 @c Emacs 19 feature | |
566 @defun walk-windows proc &optional minibuf all-frames | |
567 This function cycles through all windows, calling @code{proc} | |
568 once for each window with the window as its sole argument. | |
569 | |
570 The optional arguments @var{minibuf} and @var{all-frames} specify the | |
571 set of windows to include in the scan. See @code{next-window}, above, | |
572 for details. | |
573 @end defun | |
574 | |
575 @node Buffers and Windows | |
576 @section Buffers and Windows | |
577 @cindex examining windows | |
578 @cindex windows, controlling precisely | |
579 @cindex buffers, controlled in windows | |
580 | |
581 This section describes low-level functions to examine windows or to | |
582 display buffers in windows in a precisely controlled fashion. | |
583 @iftex | |
584 See the following section for | |
585 @end iftex | |
586 @ifinfo | |
587 @xref{Displaying Buffers}, for | |
588 @end ifinfo | |
589 related functions that find a window to use and specify a buffer for it. | |
590 The functions described there are easier to use than these, but they | |
591 employ heuristics in choosing or creating a window; use these functions | |
592 when you need complete control. | |
593 | |
594 @defun set-window-buffer window buffer-or-name | |
595 This function makes @var{window} display @var{buffer-or-name} as its | |
596 contents. It returns @code{nil}. | |
597 | |
598 @example | |
599 @group | |
600 (set-window-buffer (selected-window) "foo") | |
601 @result{} nil | |
602 @end group | |
603 @end example | |
604 @end defun | |
605 | |
606 @defun window-buffer &optional window | |
607 This function returns the buffer that @var{window} is displaying. If | |
608 @var{window} is omitted, this function returns the buffer for the | |
609 selected window. | |
610 | |
611 @example | |
612 @group | |
613 (window-buffer) | |
614 @result{} #<buffer windows.texi> | |
615 @end group | |
616 @end example | |
617 @end defun | |
618 | |
619 @defun get-buffer-window buffer-or-name &optional all-frames | |
620 This function returns a window currently displaying | |
621 @var{buffer-or-name}, or @code{nil} if there is none. If there are | |
622 several such windows, then the function returns the first one in the | |
623 cyclic ordering of windows, starting from the selected window. | |
624 @xref{Cyclic Window Ordering}. | |
625 | |
626 The argument @var{all-frames} controls which windows to consider. | |
627 | |
628 @itemize @bullet | |
629 @item | |
630 If it is @code{nil}, consider windows on the selected frame. | |
631 @item | |
632 If it is @code{t}, consider windows on all frames. | |
633 @item | |
634 If it is @code{visible}, consider windows on all visible frames. | |
635 @item | |
12098 | 636 If it is 0, consider windows on all visible or iconified frames. |
637 @item | |
6564 | 638 If it is a frame, consider windows on that frame. |
639 @end itemize | |
640 @end defun | |
641 | |
642 @node Displaying Buffers | |
643 @section Displaying Buffers in Windows | |
644 @cindex switching to a buffer | |
645 @cindex displaying a buffer | |
646 | |
647 In this section we describe convenient functions that choose a window | |
648 automatically and use it to display a specified buffer. These functions | |
649 can also split an existing window in certain circumstances. We also | |
650 describe variables that parameterize the heuristics used for choosing a | |
651 window. | |
652 @iftex | |
653 See the preceding section for | |
654 @end iftex | |
655 @ifinfo | |
656 @xref{Buffers and Windows}, for | |
657 @end ifinfo | |
658 low-level functions that give you more precise control. | |
659 | |
660 Do not use the functions in this section in order to make a buffer | |
661 current so that a Lisp program can access or modify it; they are too | |
662 drastic for that purpose, since they change the display of buffers in | |
663 windows, which is gratuitous and will surprise the user. Instead, use | |
664 @code{set-buffer} (@pxref{Current Buffer}) and @code{save-excursion} | |
665 (@pxref{Excursions}), which designate buffers as current for programmed | |
666 access without affecting the display of buffers in windows. | |
667 | |
668 @deffn Command switch-to-buffer buffer-or-name &optional norecord | |
669 This function makes @var{buffer-or-name} the current buffer, and also | |
670 displays the buffer in the selected window. This means that a human can | |
671 see the buffer and subsequent keyboard commands will apply to it. | |
672 Contrast this with @code{set-buffer}, which makes @var{buffer-or-name} | |
673 the current buffer but does not display it in the selected window. | |
674 @xref{Current Buffer}. | |
675 | |
12067 | 676 If @var{buffer-or-name} does not identify an existing buffer, then a new |
677 buffer by that name is created. The major mode for the new buffer is | |
678 set according to the variable @code{default-major-mode}. @xref{Auto | |
679 Major Mode}. | |
6564 | 680 |
681 Normally the specified buffer is put at the front of the buffer list. | |
682 This affects the operation of @code{other-buffer}. However, if | |
683 @var{norecord} is non-@code{nil}, this is not done. @xref{The Buffer | |
684 List}. | |
685 | |
686 The @code{switch-to-buffer} function is often used interactively, as | |
687 the binding of @kbd{C-x b}. It is also used frequently in programs. It | |
688 always returns @code{nil}. | |
689 @end deffn | |
690 | |
691 @deffn Command switch-to-buffer-other-window buffer-or-name | |
692 This function makes @var{buffer-or-name} the current buffer and | |
693 displays it in a window not currently selected. It then selects that | |
694 window. The handling of the buffer is the same as in | |
695 @code{switch-to-buffer}. | |
696 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
697 The currently selected window is absolutely never used to do the job. |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
698 If it is the only window, then it is split to make a distinct window for |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
699 this purpose. If the selected window is already displaying the buffer, |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
700 then it continues to do so, but another window is nonetheless found to |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
701 display it in as well. |
6564 | 702 @end deffn |
703 | |
704 @defun pop-to-buffer buffer-or-name &optional other-window | |
705 This function makes @var{buffer-or-name} the current buffer and | |
706 switches to it in some window, preferably not the window previously | |
707 selected. The ``popped-to'' window becomes the selected window within | |
708 its frame. | |
709 | |
710 If the variable @code{pop-up-frames} is non-@code{nil}, | |
711 @code{pop-to-buffer} looks for a window in any visible frame already | |
712 displaying the buffer; if there is one, it returns that window and makes | |
713 it be selected within its frame. If there is none, it creates a new | |
714 frame and displays the buffer in it. | |
715 | |
716 If @code{pop-up-frames} is @code{nil}, then @code{pop-to-buffer} | |
717 operates entirely within the selected frame. (If the selected frame has | |
718 just a minibuffer, @code{pop-to-buffer} operates within the most | |
719 recently selected frame that was not just a minibuffer.) | |
720 | |
721 If the variable @code{pop-up-windows} is non-@code{nil}, windows may | |
722 be split to create a new window that is different from the original | |
723 window. For details, see @ref{Choosing Window}. | |
724 | |
725 If @var{other-window} is non-@code{nil}, @code{pop-to-buffer} finds or | |
726 creates another window even if @var{buffer-or-name} is already visible | |
727 in the selected window. Thus @var{buffer-or-name} could end up | |
728 displayed in two windows. On the other hand, if @var{buffer-or-name} is | |
729 already displayed in the selected window and @var{other-window} is | |
730 @code{nil}, then the selected window is considered sufficient display | |
731 for @var{buffer-or-name}, so that nothing needs to be done. | |
732 | |
12098 | 733 All the variables that affect @code{display-buffer} affect |
734 @code{pop-to-buffer} as well. @xref{Choosing Window}. | |
735 | |
6564 | 736 If @var{buffer-or-name} is a string that does not name an existing |
12067 | 737 buffer, a buffer by that name is created. The major mode for the new |
738 buffer is set according to the variable @code{default-major-mode}. | |
739 @xref{Auto Major Mode}. | |
6564 | 740 @end defun |
741 | |
12098 | 742 @deffn Command replace-buffer-in-windows buffer |
743 This function replaces @var{buffer} with some other buffer in all | |
744 windows displaying it. The other buffer used is chosen with | |
745 @code{other-buffer}. In the usual applications of this function, you | |
746 don't care which other buffer is used; you just want to make sure that | |
747 @var{buffer} is no longer displayed. | |
748 | |
749 This function returns @code{nil}. | |
750 @end deffn | |
751 | |
6564 | 752 @node Choosing Window |
753 @section Choosing a Window for Display | |
754 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
755 This section describes the basic facility that chooses a window to |
6564 | 756 display a buffer in---@code{display-buffer}. All the higher-level |
757 functions and commands use this subroutine. Here we describe how to use | |
758 @code{display-buffer} and how to customize it. | |
759 | |
760 @deffn Command display-buffer buffer-or-name &optional not-this-window | |
761 This command makes @var{buffer-or-name} appear in some window, like | |
762 @code{pop-to-buffer}, but it does not select that window and does not | |
763 make the buffer current. The identity of the selected window is | |
764 unaltered by this function. | |
765 | |
766 If @var{not-this-window} is non-@code{nil}, it means to display the | |
767 specified buffer in a window other than the selected one, even if it is | |
768 already on display in the selected window. This can cause the buffer to | |
769 appear in two windows at once. Otherwise, if @var{buffer-or-name} is | |
770 already being displayed in any window, that is good enough, so this | |
771 function does nothing. | |
772 | |
773 @code{display-buffer} returns the window chosen to display | |
774 @var{buffer-or-name}. | |
775 | |
776 Precisely how @code{display-buffer} finds or creates a window depends on | |
777 the variables described below. | |
778 @end deffn | |
779 | |
780 @defopt pop-up-windows | |
781 This variable controls whether @code{display-buffer} makes new windows. | |
782 If it is non-@code{nil} and there is only one window, then that window | |
783 is split. If it is @code{nil}, then @code{display-buffer} does not | |
784 split the single window, but uses it whole. | |
785 @end defopt | |
786 | |
787 @defopt split-height-threshold | |
788 This variable determines when @code{display-buffer} may split a window, | |
789 if there are multiple windows. @code{display-buffer} always splits the | |
790 largest window if it has at least this many lines. If the largest | |
791 window is not this tall, it is split only if it is the sole window and | |
792 @code{pop-up-windows} is non-@code{nil}. | |
793 @end defopt | |
794 | |
795 @c Emacs 19 feature | |
796 @defopt pop-up-frames | |
797 This variable controls whether @code{display-buffer} makes new frames. | |
798 If it is non-@code{nil}, @code{display-buffer} looks for an existing | |
799 window already displaying the desired buffer, on any visible frame. If | |
800 it finds one, it returns that window. Otherwise it makes a new frame. | |
801 The variables @code{pop-up-windows} and @code{split-height-threshold} do | |
802 not matter if @code{pop-up-frames} is non-@code{nil}. | |
803 | |
804 If @code{pop-up-frames} is @code{nil}, then @code{display-buffer} either | |
805 splits a window or reuses one. | |
806 | |
807 @xref{Frames}, for more information. | |
808 @end defopt | |
809 | |
810 @c Emacs 19 feature | |
811 @defvar pop-up-frame-function | |
812 This variable specifies how to make a new frame if @code{pop-up-frames} | |
813 is non-@code{nil}. | |
814 | |
815 Its value should be a function of no arguments. When | |
816 @code{display-buffer} makes a new frame, it does so by calling that | |
817 function, which should return a frame. The default value of the | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
818 variable is a function that creates a frame using parameters from |
6564 | 819 @code{pop-up-frame-alist}. |
820 @end defvar | |
821 | |
822 @defvar pop-up-frame-alist | |
823 This variable holds an alist specifying frame parameters used when | |
824 @code{display-buffer} makes a new frame. @xref{Frame Parameters}, for | |
825 more information about frame parameters. | |
826 @end defvar | |
827 | |
7082
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
828 @defvar special-display-buffer-names |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
829 A list of buffer names for buffers that should be displayed specially. |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
830 If the buffer's name is in this list, @code{display-buffer} handles the |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
831 buffer specially. |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
832 |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
833 By default, special display means to give the buffer a dedicated frame. |
12098 | 834 |
835 If an element is a list, instead of a string, then the @sc{car} of the | |
836 list is the buffer name, and the rest of the list says how to create the | |
837 frame. There are two possibilities for the rest of the list. It can be | |
838 an alist, specifying frame parameters, or it can contain a function and | |
839 arguments to give to it. (The function's first argument is always the | |
840 buffer to be displayed; the arguments from the list come after that.) | |
7082
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
841 @end defvar |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
842 |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
843 @defvar special-display-regexps |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
844 A list of regular expressions that specify buffers that should be |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
845 displayed specially. If the buffer's name matches any of the regular |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
846 expressions in this list, @code{display-buffer} handles the buffer |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
847 specially. |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
848 |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
849 By default, special display means to give the buffer a dedicated frame. |
12098 | 850 |
851 If an element is a list, instead of a string, then the @sc{car} of the | |
852 list is the regular expression, and the rest of the list says how to | |
853 create the frame. See above, under @code{special-display-buffer-names}. | |
7082
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
854 @end defvar |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
855 |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
856 @defvar special-display-function |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
857 This variable holds the function to call to display a buffer specially. |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
858 It receives the buffer as an argument, and should return the window in |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
859 which it is displayed. |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
860 |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
861 The default value of this variable is |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
862 @code{special-display-popup-frame}. |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
863 @end defvar |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
864 |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
865 @defun special-display-popup-frame buffer |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
866 This function makes @var{buffer} visible in a frame of its own. If |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
867 @var{buffer} is already displayed in a window in some frame, it makes |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
868 the frame visible and raises it, to use that window. Otherwise, it |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
869 creates a frame that will be dedicated to @var{buffer}. |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
870 |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
871 This function uses an existing window displaying @var{buffer} whether or |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
872 not it is in a frame of its own; but if you set up the above variables |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
873 in your init file, before @var{buffer} was created, then presumably the |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
874 window was previously made by this function. |
7082
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
875 @end defun |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
876 |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
877 @defopt special-display-frame-alist |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
878 This variable holds frame parameters for |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
879 @code{special-display-popup-frame} to use when it creates a frame. |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
880 @end defopt |
70b62e9d773b
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6564
diff
changeset
|
881 |
12673
4d6b7909a0ec
Use defopt for same-window-buffer-names and same-window-regexps.
Richard M. Stallman <rms@gnu.org>
parents:
12596
diff
changeset
|
882 @defopt same-window-buffer-names |
12098 | 883 A list of buffer names for buffers that should be displayed in the |
884 selected window. If the buffer's name is in this list, | |
885 @code{display-buffer} handles the buffer by switching to it in the | |
886 selected window. | |
12673
4d6b7909a0ec
Use defopt for same-window-buffer-names and same-window-regexps.
Richard M. Stallman <rms@gnu.org>
parents:
12596
diff
changeset
|
887 @end defopt |
12098 | 888 |
12673
4d6b7909a0ec
Use defopt for same-window-buffer-names and same-window-regexps.
Richard M. Stallman <rms@gnu.org>
parents:
12596
diff
changeset
|
889 @defopt same-window-regexps |
12098 | 890 A list of regular expressions that specify buffers that should be |
891 displayed in the selected window. If the buffer's name matches any of | |
892 the regular expressions in this list, @code{display-buffer} handles the | |
893 buffer by switching to it in the selected window. | |
12673
4d6b7909a0ec
Use defopt for same-window-buffer-names and same-window-regexps.
Richard M. Stallman <rms@gnu.org>
parents:
12596
diff
changeset
|
894 @end defopt |
12098 | 895 |
6564 | 896 @c Emacs 19 feature |
897 @defvar display-buffer-function | |
898 This variable is the most flexible way to customize the behavior of | |
899 @code{display-buffer}. If it is non-@code{nil}, it should be a function | |
900 that @code{display-buffer} calls to do the work. The function should | |
901 accept two arguments, the same two arguments that @code{display-buffer} | |
902 received. It should choose or create a window, display the specified | |
903 buffer, and then return the window. | |
904 | |
905 This hook takes precedence over all the other options and hooks | |
906 described above. | |
907 @end defvar | |
908 | |
909 @c Emacs 19 feature | |
910 @cindex dedicated window | |
911 A window can be marked as ``dedicated'' to its buffer. Then | |
912 @code{display-buffer} does not try to use that window. | |
913 | |
914 @defun window-dedicated-p window | |
915 This function returns @code{t} if @var{window} is marked as dedicated; | |
916 otherwise @code{nil}. | |
917 @end defun | |
918 | |
919 @defun set-window-dedicated-p window flag | |
920 This function marks @var{window} as dedicated if @var{flag} is | |
921 non-@code{nil}, and nondedicated otherwise. | |
922 @end defun | |
923 | |
924 @node Window Point | |
925 @section Windows and Point | |
926 @cindex window position | |
927 @cindex window point | |
928 @cindex position in window | |
929 @cindex point in window | |
930 | |
931 Each window has its own value of point, independent of the value of | |
932 point in other windows displaying the same buffer. This makes it useful | |
933 to have multiple windows showing one buffer. | |
934 | |
935 @itemize @bullet | |
936 @item | |
937 The window point is established when a window is first created; it is | |
938 initialized from the buffer's point, or from the window point of another | |
939 window opened on the buffer if such a window exists. | |
940 | |
941 @item | |
942 Selecting a window sets the value of point in its buffer to the window's | |
943 value of point. Conversely, deselecting a window sets the window's | |
944 value of point from that of the buffer. Thus, when you switch between | |
945 windows that display a given buffer, the point value for the selected | |
946 window is in effect in the buffer, while the point values for the other | |
947 windows are stored in those windows. | |
948 | |
949 @item | |
950 As long as the selected window displays the current buffer, the window's | |
951 point and the buffer's point always move together; they remain equal. | |
952 | |
953 @item | |
954 @xref{Positions}, for more details on buffer positions. | |
955 @end itemize | |
956 | |
957 As far as the user is concerned, point is where the cursor is, and | |
958 when the user switches to another buffer, the cursor jumps to the | |
959 position of point in that buffer. | |
960 | |
961 @defun window-point window | |
962 This function returns the current position of point in @var{window}. | |
963 For a nonselected window, this is the value point would have (in that | |
964 window's buffer) if that window were selected. | |
965 | |
966 When @var{window} is the selected window and its buffer is also the | |
967 current buffer, the value returned is the same as point in that buffer. | |
968 | |
969 Strictly speaking, it would be more correct to return the | |
970 ``top-level'' value of point, outside of any @code{save-excursion} | |
971 forms. But that value is hard to find. | |
972 @end defun | |
973 | |
974 @defun set-window-point window position | |
975 This function positions point in @var{window} at position | |
976 @var{position} in @var{window}'s buffer. | |
977 @end defun | |
978 | |
979 @node Window Start | |
980 @section The Window Start Position | |
981 | |
982 Each window contains a marker used to keep track of a buffer position | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
983 that specifies where in the buffer display should start. This position |
6564 | 984 is called the @dfn{display-start} position of the window (or just the |
985 @dfn{start}). The character after this position is the one that appears | |
986 at the upper left corner of the window. It is usually, but not | |
987 inevitably, at the beginning of a text line. | |
988 | |
989 @defun window-start &optional window | |
990 @cindex window top line | |
991 This function returns the display-start position of window | |
992 @var{window}. If @var{window} is @code{nil}, the selected window is | |
993 used. For example, | |
994 | |
995 @example | |
996 @group | |
997 (window-start) | |
998 @result{} 7058 | |
999 @end group | |
1000 @end example | |
1001 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1002 When you create a window, or display a different buffer in it, the |
6564 | 1003 display-start position is set to a display-start position recently used |
1004 for the same buffer, or 1 if the buffer doesn't have any. | |
1005 | |
12596
ffe0de415152
Explain how redisplay updates window-start.
Richard M. Stallman <rms@gnu.org>
parents:
12282
diff
changeset
|
1006 Redisplay updates the window-start position (if you have not specified |
ffe0de415152
Explain how redisplay updates window-start.
Richard M. Stallman <rms@gnu.org>
parents:
12282
diff
changeset
|
1007 it explicitly since the previous redisplay) so that point appears on the |
ffe0de415152
Explain how redisplay updates window-start.
Richard M. Stallman <rms@gnu.org>
parents:
12282
diff
changeset
|
1008 screen. Nothing except redisplay automatically changes the window-start |
ffe0de415152
Explain how redisplay updates window-start.
Richard M. Stallman <rms@gnu.org>
parents:
12282
diff
changeset
|
1009 position; if you move point, do not expect the window-start position to |
ffe0de415152
Explain how redisplay updates window-start.
Richard M. Stallman <rms@gnu.org>
parents:
12282
diff
changeset
|
1010 change in response until after the next redisplay. |
ffe0de415152
Explain how redisplay updates window-start.
Richard M. Stallman <rms@gnu.org>
parents:
12282
diff
changeset
|
1011 |
ffe0de415152
Explain how redisplay updates window-start.
Richard M. Stallman <rms@gnu.org>
parents:
12282
diff
changeset
|
1012 For a realistic example of using @code{window-start}, see the |
ffe0de415152
Explain how redisplay updates window-start.
Richard M. Stallman <rms@gnu.org>
parents:
12282
diff
changeset
|
1013 description of @code{count-lines} in @ref{Text Lines}. |
6564 | 1014 @end defun |
1015 | |
1016 @defun window-end &optional window | |
1017 This function returns the position of the end of the display in window | |
1018 @var{window}. If @var{window} is @code{nil}, the selected window is | |
1019 used. | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1020 |
11510
e5d3814e783a
Update info on window-end.
Richard M. Stallman <rms@gnu.org>
parents:
8926
diff
changeset
|
1021 Simply changing the buffer text or moving point does not update the |
e5d3814e783a
Update info on window-end.
Richard M. Stallman <rms@gnu.org>
parents:
8926
diff
changeset
|
1022 value that @code{window-end} returns. The value is updated only when |
e5d3814e783a
Update info on window-end.
Richard M. Stallman <rms@gnu.org>
parents:
8926
diff
changeset
|
1023 Emacs redisplays and redisplay actually finishes. |
e5d3814e783a
Update info on window-end.
Richard M. Stallman <rms@gnu.org>
parents:
8926
diff
changeset
|
1024 |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1025 If the last redisplay of @var{window} was preempted, and did not finish, |
8516
5d76d6decb35
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
8491
diff
changeset
|
1026 Emacs does not know the position of the end of display in that window. |
5d76d6decb35
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
8491
diff
changeset
|
1027 In that case, this function returns a value that is not correct. In a |
5d76d6decb35
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
8491
diff
changeset
|
1028 future version, @code{window-end} will return @code{nil} in that case. |
5d76d6decb35
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
8491
diff
changeset
|
1029 @ignore |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1030 in that case, this function returns @code{nil}. You can compute where |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1031 the end of the window @emph{would} have been, if redisplay had finished, |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1032 like this: |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1033 |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1034 @example |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1035 (save-excursion |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1036 (goto-char (window-start window)) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1037 (vertical-motion (1- (window-height window)) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1038 window) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1039 (point)) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1040 @end example |
8516
5d76d6decb35
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
8491
diff
changeset
|
1041 @end ignore |
6564 | 1042 @end defun |
1043 | |
1044 @defun set-window-start window position &optional noforce | |
1045 This function sets the display-start position of @var{window} to | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1046 @var{position} in @var{window}'s buffer. It returns @var{position}. |
6564 | 1047 |
1048 The display routines insist that the position of point be visible when a | |
1049 buffer is displayed. Normally, they change the display-start position | |
1050 (that is, scroll the window) whenever necessary to make point visible. | |
1051 However, if you specify the start position with this function using | |
1052 @code{nil} for @var{noforce}, it means you want display to start at | |
1053 @var{position} even if that would put the location of point off the | |
1054 screen. If this does place point off screen, the display routines move | |
1055 point to the left margin on the middle line in the window. | |
1056 | |
1057 For example, if point @w{is 1} and you set the start of the window @w{to | |
1058 2}, then point would be ``above'' the top of the window. The display | |
1059 routines will automatically move point if it is still 1 when redisplay | |
1060 occurs. Here is an example: | |
1061 | |
1062 @example | |
1063 @group | |
1064 ;; @r{Here is what @samp{foo} looks like before executing} | |
1065 ;; @r{the @code{set-window-start} expression.} | |
1066 @end group | |
1067 | |
1068 @group | |
1069 ---------- Buffer: foo ---------- | |
1070 @point{}This is the contents of buffer foo. | |
1071 2 | |
1072 3 | |
1073 4 | |
1074 5 | |
1075 6 | |
1076 ---------- Buffer: foo ---------- | |
1077 @end group | |
1078 | |
1079 @group | |
1080 (set-window-start | |
1081 (selected-window) | |
1082 (1+ (window-start))) | |
1083 @result{} 2 | |
1084 @end group | |
1085 | |
1086 @group | |
1087 ;; @r{Here is what @samp{foo} looks like after executing} | |
1088 ;; @r{the @code{set-window-start} expression.} | |
1089 ---------- Buffer: foo ---------- | |
1090 his is the contents of buffer foo. | |
1091 2 | |
1092 3 | |
1093 @point{}4 | |
1094 5 | |
1095 6 | |
1096 ---------- Buffer: foo ---------- | |
1097 @end group | |
1098 @end example | |
1099 | |
1100 If @var{noforce} is non-@code{nil}, and @var{position} would place point | |
1101 off screen at the next redisplay, then redisplay computes a new window-start | |
1102 position that works well with point, and thus @var{position} is not used. | |
1103 @end defun | |
1104 | |
1105 @defun pos-visible-in-window-p &optional position window | |
1106 This function returns @code{t} if @var{position} is within the range | |
1107 of text currently visible on the screen in @var{window}. It returns | |
1108 @code{nil} if @var{position} is scrolled vertically out of view. The | |
1109 argument @var{position} defaults to the current position of point; | |
1110 @var{window}, to the selected window. Here is an example: | |
1111 | |
1112 @example | |
1113 @group | |
1114 (or (pos-visible-in-window-p | |
1115 (point) (selected-window)) | |
1116 (recenter 0)) | |
1117 @end group | |
1118 @end example | |
1119 | |
1120 The @code{pos-visible-in-window-p} function considers only vertical | |
1121 scrolling. If @var{position} is out of view only because @var{window} | |
1122 has been scrolled horizontally, @code{pos-visible-in-window-p} returns | |
1123 @code{t}. @xref{Horizontal Scrolling}. | |
1124 @end defun | |
1125 | |
1126 @node Vertical Scrolling | |
1127 @section Vertical Scrolling | |
1128 @cindex vertical scrolling | |
1129 @cindex scrolling vertically | |
1130 | |
1131 Vertical scrolling means moving the text up or down in a window. It | |
1132 works by changing the value of the window's display-start location. It | |
1133 may also change the value of @code{window-point} to keep it on the | |
1134 screen. | |
1135 | |
1136 In the commands @code{scroll-up} and @code{scroll-down}, the directions | |
1137 ``up'' and ``down'' refer to the motion of the text in the buffer at which | |
1138 you are looking through the window. Imagine that the text is | |
1139 written on a long roll of paper and that the scrolling commands move the | |
1140 paper up and down. Thus, if you are looking at text in the middle of a | |
1141 buffer and repeatedly call @code{scroll-down}, you will eventually see | |
1142 the beginning of the buffer. | |
1143 | |
1144 Some people have urged that the opposite convention be used: they | |
1145 imagine that the window moves over text that remains in place. Then | |
1146 ``down'' commands would take you to the end of the buffer. This view is | |
1147 more consistent with the actual relationship between windows and the | |
1148 text in the buffer, but it is less like what the user sees. The | |
1149 position of a window on the terminal does not move, and short scrolling | |
1150 commands clearly move the text up or down on the screen. We have chosen | |
1151 names that fit the user's point of view. | |
1152 | |
1153 The scrolling functions (aside from @code{scroll-other-window}) have | |
1154 unpredictable results if the current buffer is different from the buffer | |
1155 that is displayed in the selected window. @xref{Current Buffer}. | |
1156 | |
1157 @deffn Command scroll-up &optional count | |
1158 This function scrolls the text in the selected window upward | |
1159 @var{count} lines. If @var{count} is negative, scrolling is actually | |
1160 downward. | |
1161 | |
1162 If @var{count} is @code{nil} (or omitted), then the length of scroll | |
1163 is @code{next-screen-context-lines} lines less than the usable height of | |
1164 the window (not counting its mode line). | |
1165 | |
1166 @code{scroll-up} returns @code{nil}. | |
1167 @end deffn | |
1168 | |
1169 @deffn Command scroll-down &optional count | |
1170 This function scrolls the text in the selected window downward | |
1171 @var{count} lines. If @var{count} is negative, scrolling is actually | |
1172 upward. | |
1173 | |
1174 If @var{count} is omitted or @code{nil}, then the length of the scroll | |
1175 is @code{next-screen-context-lines} lines less than the usable height of | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1176 the window (not counting its mode line). |
6564 | 1177 |
1178 @code{scroll-down} returns @code{nil}. | |
1179 @end deffn | |
1180 | |
1181 @deffn Command scroll-other-window &optional count | |
1182 This function scrolls the text in another window upward @var{count} | |
1183 lines. Negative values of @var{count}, or @code{nil}, are handled | |
1184 as in @code{scroll-up}. | |
1185 | |
1186 You can specify a buffer to scroll with the variable | |
1187 @code{other-window-scroll-buffer}. When the selected window is the | |
1188 minibuffer, the next window is normally the one at the top left corner. | |
1189 You can specify a different window to scroll with the variable | |
1190 @code{minibuffer-scroll-window}. This variable has no effect when any | |
1191 other window is selected. @xref{Minibuffer Misc}. | |
1192 | |
1193 When the minibuffer is active, it is the next window if the selected | |
1194 window is the one at the bottom right corner. In this case, | |
1195 @code{scroll-other-window} attempts to scroll the minibuffer. If the | |
1196 minibuffer contains just one line, it has nowhere to scroll to, so the | |
1197 line reappears after the echo area momentarily displays the message | |
1198 ``Beginning of buffer''. | |
1199 @end deffn | |
1200 | |
1201 @c Emacs 19 feature | |
1202 @defvar other-window-scroll-buffer | |
1203 If this variable is non-@code{nil}, it tells @code{scroll-other-window} | |
1204 which buffer to scroll. | |
1205 @end defvar | |
1206 | |
1207 @defopt scroll-step | |
1208 This variable controls how scrolling is done automatically when point | |
1209 moves off the screen. If the value is zero, then redisplay scrolls the | |
1210 text to center point vertically in the window. If the value is a | |
1211 positive integer @var{n}, then redisplay brings point back on screen by | |
1212 scrolling @var{n} lines in either direction, if possible; otherwise, it | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1213 centers point. The default value is zero. |
6564 | 1214 @end defopt |
1215 | |
1216 @defopt next-screen-context-lines | |
1217 The value of this variable is the number of lines of continuity to | |
1218 retain when scrolling by full screens. For example, @code{scroll-up} | |
1219 with an argument of @code{nil} scrolls so that this many lines at the | |
1220 bottom of the window appear instead at the top. The default value is | |
1221 @code{2}. | |
1222 @end defopt | |
1223 | |
1224 @deffn Command recenter &optional count | |
1225 @cindex centering point | |
1226 This function scrolls the selected window to put the text where point | |
1227 is located at a specified vertical position within the window. | |
1228 | |
1229 If @var{count} is a nonnegative number, it puts the line containing | |
1230 point @var{count} lines down from the top of the window. If @var{count} | |
1231 is a negative number, then it counts upward from the bottom of the | |
1232 window, so that @minus{}1 stands for the last usable line in the window. | |
1233 If @var{count} is a non-@code{nil} list, then it stands for the line in | |
1234 the middle of the window. | |
1235 | |
1236 If @var{count} is @code{nil}, @code{recenter} puts the line containing | |
1237 point in the middle of the window, then clears and redisplays the entire | |
1238 selected frame. | |
1239 | |
1240 When @code{recenter} is called interactively, @var{count} is the raw | |
1241 prefix argument. Thus, typing @kbd{C-u} as the prefix sets the | |
1242 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets | |
1243 @var{count} to 4, which positions the current line four lines from the | |
1244 top. | |
1245 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1246 With an argument of zero, @code{recenter} positions the current line at |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1247 the top of the window. This action is so handy that some people make a |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1248 separate key binding to do this. For example, |
6564 | 1249 |
1250 @example | |
1251 @group | |
1252 (defun line-to-top-of-window () | |
1253 "Scroll current line to top of window. | |
1254 Replaces three keystroke sequence C-u 0 C-l." | |
1255 (interactive) | |
1256 (recenter 0)) | |
1257 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1258 (global-set-key [kp-multiply] 'line-to-top-of-window) |
6564 | 1259 @end group |
1260 @end example | |
1261 @end deffn | |
1262 | |
1263 @node Horizontal Scrolling | |
1264 @section Horizontal Scrolling | |
1265 @cindex horizontal scrolling | |
1266 | |
1267 Because we read English first from top to bottom and second from left | |
1268 to right, horizontal scrolling is not like vertical scrolling. Vertical | |
1269 scrolling involves selection of a contiguous portion of text to display. | |
1270 Horizontal scrolling causes part of each line to go off screen. The | |
1271 amount of horizontal scrolling is therefore specified as a number of | |
1272 columns rather than as a position in the buffer. It has nothing to do | |
1273 with the display-start position returned by @code{window-start}. | |
1274 | |
1275 Usually, no horizontal scrolling is in effect; then the leftmost | |
1276 column is at the left edge of the window. In this state, scrolling to | |
1277 the right is meaningless, since there is no data to the left of the | |
1278 screen to be revealed by it; so this is not allowed. Scrolling to the | |
1279 left is allowed; it scrolls the first columns of text off the edge of | |
1280 the window and can reveal additional columns on the right that were | |
1281 truncated before. Once a window has a nonzero amount of leftward | |
1282 horizontal scrolling, you can scroll it back to the right, but only so | |
1283 far as to reduce the net horizontal scroll to zero. There is no limit | |
1284 to how far left you can scroll, but eventually all the text will | |
1285 disappear off the left edge. | |
1286 | |
1287 @deffn Command scroll-left count | |
1288 This function scrolls the selected window @var{count} columns to the | |
1289 left (or to the right if @var{count} is negative). The return value is | |
1290 the total amount of leftward horizontal scrolling in effect after the | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1291 change---just like the value returned by @code{window-hscroll} (below). |
6564 | 1292 @end deffn |
1293 | |
1294 @deffn Command scroll-right count | |
1295 This function scrolls the selected window @var{count} columns to the | |
1296 right (or to the left if @var{count} is negative). The return value is | |
1297 the total amount of leftward horizontal scrolling in effect after the | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1298 change---just like the value returned by @code{window-hscroll} (below). |
6564 | 1299 |
1300 Once you scroll a window as far right as it can go, back to its normal | |
1301 position where the total leftward scrolling is zero, attempts to scroll | |
1302 any farther right have no effect. | |
1303 @end deffn | |
1304 | |
1305 @defun window-hscroll &optional window | |
1306 This function returns the total leftward horizontal scrolling of | |
1307 @var{window}---the number of columns by which the text in @var{window} | |
1308 is scrolled left past the left margin. | |
1309 | |
1310 The value is never negative. It is zero when no horizontal scrolling | |
1311 has been done in @var{window} (which is usually the case). | |
1312 | |
1313 If @var{window} is @code{nil}, the selected window is used. | |
1314 | |
1315 @example | |
1316 @group | |
1317 (window-hscroll) | |
1318 @result{} 0 | |
1319 @end group | |
1320 @group | |
1321 (scroll-left 5) | |
1322 @result{} 5 | |
1323 @end group | |
1324 @group | |
1325 (window-hscroll) | |
1326 @result{} 5 | |
1327 @end group | |
1328 @end example | |
1329 @end defun | |
1330 | |
1331 @defun set-window-hscroll window columns | |
1332 This function sets the number of columns from the left margin that | |
1333 @var{window} is scrolled to the value of @var{columns}. The argument | |
1334 @var{columns} should be zero or positive; if not, it is taken as zero. | |
1335 | |
1336 The value returned is @var{columns}. | |
1337 | |
1338 @example | |
1339 @group | |
1340 (set-window-hscroll (selected-window) 10) | |
1341 @result{} 10 | |
1342 @end group | |
1343 @end example | |
1344 @end defun | |
1345 | |
1346 Here is how you can determine whether a given position @var{position} | |
1347 is off the screen due to horizontal scrolling: | |
1348 | |
1349 @example | |
1350 @group | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1351 (defun hscroll-on-screen (window position) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1352 (save-excursion |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1353 (goto-char position) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1354 (and |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1355 (>= (- (current-column) (window-hscroll window)) 0) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1356 (< (- (current-column) (window-hscroll window)) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1357 (window-width window))))) |
6564 | 1358 @end group |
1359 @end example | |
1360 | |
1361 @node Size of Window | |
1362 @section The Size of a Window | |
1363 @cindex window size | |
1364 @cindex size of window | |
1365 | |
1366 An Emacs window is rectangular, and its size information consists of | |
1367 the height (the number of lines) and the width (the number of character | |
1368 positions in each line). The mode line is included in the height. But | |
1369 the width does not count the scroll bar or the column of @samp{|} | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1370 characters that separates side-by-side windows. |
6564 | 1371 |
1372 The following three functions return size information about a window: | |
1373 | |
1374 @defun window-height &optional window | |
1375 This function returns the number of lines in @var{window}, including | |
1376 its mode line. If @var{window} fills its entire frame, this is one less | |
1377 than the value of @code{frame-height} on that frame (since the last line | |
1378 is always reserved for the minibuffer). | |
1379 | |
1380 If @var{window} is @code{nil}, the function uses the selected window. | |
1381 | |
1382 @example | |
1383 @group | |
1384 (window-height) | |
1385 @result{} 23 | |
1386 @end group | |
1387 @group | |
1388 (split-window-vertically) | |
1389 @result{} #<window 4 on windows.texi> | |
1390 @end group | |
1391 @group | |
1392 (window-height) | |
1393 @result{} 11 | |
1394 @end group | |
1395 @end example | |
1396 @end defun | |
1397 | |
1398 @defun window-width &optional window | |
1399 This function returns the number of columns in @var{window}. If | |
1400 @var{window} fills its entire frame, this is the same as the value of | |
1401 @code{frame-width} on that frame. The width does not include the | |
1402 window's scroll bar or the column of @samp{|} characters that separates | |
1403 side-by-side windows. | |
1404 | |
1405 If @var{window} is @code{nil}, the function uses the selected window. | |
1406 | |
1407 @example | |
1408 @group | |
1409 (window-width) | |
1410 @result{} 80 | |
1411 @end group | |
1412 @end example | |
1413 @end defun | |
1414 | |
1415 @defun window-edges &optional window | |
1416 This function returns a list of the edge coordinates of @var{window}. | |
1417 If @var{window} is @code{nil}, the selected window is used. | |
1418 | |
1419 The order of the list is @code{(@var{left} @var{top} @var{right} | |
1420 @var{bottom})}, all elements relative to 0, 0 at the top left corner of | |
1421 the frame. The element @var{right} of the value is one more than the | |
1422 rightmost column used by @var{window}, and @var{bottom} is one more than | |
1423 the bottommost row used by @var{window} and its mode-line. | |
1424 | |
1425 When you have side-by-side windows, the right edge value for a window | |
1426 with a neighbor on the right includes the width of the separator between | |
1427 the window and that neighbor. This separator may be a column of | |
1428 @samp{|} characters or it may be a scroll bar. Since the width of the | |
1429 window does not include this separator, the width does not equal the | |
1430 difference between the right and left edges in this case. | |
1431 | |
1432 Here is the result obtained on a typical 24-line terminal with just one | |
1433 window: | |
1434 | |
1435 @example | |
1436 @group | |
1437 (window-edges (selected-window)) | |
1438 @result{} (0 0 80 23) | |
1439 @end group | |
1440 @end example | |
1441 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1442 @noindent |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1443 The bottom edge is at line 23 because the last line is the echo area. |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1444 |
13275 | 1445 If @var{window} is at the upper left corner of its frame, then |
1446 @var{bottom} is the same as the value of @code{(window-height)}, | |
1447 @var{right} is almost the same as the value of | |
1448 @code{(window-width)}@footnote{They are not exactly equal because | |
1449 @var{right} includes the vertical separator line or scroll bar, while | |
1450 @code{(window-width)} does not.}, and @var{top} and @var{left} are zero. | |
1451 For example, the edges of the following window are @w{@samp{0 0 5 8}}. | |
1452 Assuming that the frame has more than 8 columns, the last column of the | |
1453 window (column 7) holds a border rather than text. The last row (row 4) | |
1454 holds the mode line, shown here with @samp{xxxxxxxxx}. | |
6564 | 1455 |
1456 @example | |
1457 @group | |
1458 0 | |
1459 _______ | |
1460 0 | | | |
1461 | | | |
1462 | | | |
1463 | | | |
1464 xxxxxxxxx 4 | |
1465 | |
1466 7 | |
1467 @end group | |
1468 @end example | |
1469 | |
1470 When there are side-by-side windows, any window not at the right edge of | |
1471 its frame has a separator in its last column or columns. The separator | |
1472 counts as one or two columns in the width of the window. A window never | |
1473 includes a separator on its left, since that belongs to the window to | |
1474 the left. | |
1475 | |
1476 In the following example, let's suppose that the frame is 7 | |
1477 columns wide. Then the edges of the left window are @w{@samp{0 0 4 3}} | |
1478 and the edges of the right window are @w{@samp{4 0 7 3}}. | |
1479 | |
1480 @example | |
1481 @group | |
1482 ___ ___ | |
1483 | | | | |
1484 | | | | |
1485 xxxxxxxxx | |
1486 | |
1487 0 34 7 | |
1488 @end group | |
1489 @end example | |
1490 @end defun | |
1491 | |
1492 @node Resizing Windows | |
1493 @section Changing the Size of a Window | |
1494 @cindex window resizing | |
1495 @cindex changing window size | |
1496 @cindex window size, changing | |
1497 | |
1498 The window size functions fall into two classes: high-level commands | |
1499 that change the size of windows and low-level functions that access | |
1500 window size. Emacs does not permit overlapping windows or gaps between | |
1501 windows, so resizing one window affects other windows. | |
1502 | |
1503 @deffn Command enlarge-window size &optional horizontal | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1504 This function makes the selected window @var{size} lines taller, |
6564 | 1505 stealing lines from neighboring windows. It takes the lines from one |
1506 window at a time until that window is used up, then takes from another. | |
1507 If a window from which lines are stolen shrinks below | |
1508 @code{window-min-height} lines, that window disappears. | |
1509 | |
1510 If @var{horizontal} is non-@code{nil}, this function makes | |
1511 @var{window} wider by @var{size} columns, stealing columns instead of | |
1512 lines. If a window from which columns are stolen shrinks below | |
1513 @code{window-min-width} columns, that window disappears. | |
1514 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1515 If the requested size would exceed that of the window's frame, then the |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1516 function makes the window occupy the entire height (or width) of the |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1517 frame. |
6564 | 1518 |
1519 If @var{size} is negative, this function shrinks the window by | |
1520 @minus{}@var{size} lines or columns. If that makes the window smaller | |
1521 than the minimum size (@code{window-min-height} and | |
1522 @code{window-min-width}), @code{enlarge-window} deletes the window. | |
1523 | |
1524 @code{enlarge-window} returns @code{nil}. | |
1525 @end deffn | |
1526 | |
1527 @deffn Command enlarge-window-horizontally columns | |
1528 This function makes the selected window @var{columns} wider. | |
1529 It could be defined as follows: | |
1530 | |
1531 @example | |
1532 @group | |
1533 (defun enlarge-window-horizontally (columns) | |
1534 (enlarge-window columns t)) | |
1535 @end group | |
1536 @end example | |
1537 @end deffn | |
1538 | |
1539 @deffn Command shrink-window size &optional horizontal | |
1540 This function is like @code{enlarge-window} but negates the argument | |
1541 @var{size}, making the selected window smaller by giving lines (or | |
1542 columns) to the other windows. If the window shrinks below | |
1543 @code{window-min-height} or @code{window-min-width}, then it disappears. | |
1544 | |
1545 If @var{size} is negative, the window is enlarged by @minus{}@var{size} | |
1546 lines or columns. | |
1547 @end deffn | |
1548 | |
1549 @deffn Command shrink-window-horizontally columns | |
1550 This function makes the selected window @var{columns} narrower. | |
1551 It could be defined as follows: | |
1552 | |
1553 @example | |
1554 @group | |
1555 (defun shrink-window-horizontally (columns) | |
1556 (shrink-window columns t)) | |
1557 @end group | |
1558 @end example | |
1559 @end deffn | |
1560 | |
1561 @cindex minimum window size | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1562 The following two variables constrain the window-size-changing |
6564 | 1563 functions to a minimum height and width. |
1564 | |
1565 @defopt window-min-height | |
1566 The value of this variable determines how short a window may become | |
1567 before it is automatically deleted. Making a window smaller than | |
1568 @code{window-min-height} automatically deletes it, and no window may be | |
1569 created shorter than this. The absolute minimum height is two (allowing | |
1570 one line for the mode line, and one line for the buffer display). | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1571 Actions that change window sizes reset this variable to two if it is |
6564 | 1572 less than two. The default value is 4. |
1573 @end defopt | |
1574 | |
1575 @defopt window-min-width | |
1576 The value of this variable determines how narrow a window may become | |
1577 before it automatically deleted. Making a window smaller than | |
1578 @code{window-min-width} automatically deletes it, and no window may be | |
1579 created narrower than this. The absolute minimum width is one; any | |
1580 value below that is ignored. The default value is 10. | |
1581 @end defopt | |
1582 | |
12067 | 1583 @defvar window-size-change-functions |
1584 This variable holds a list of functions to be called if the size of any | |
1585 window changes for any reason. The functions are called just once per | |
1586 redisplay, and just once for each frame on which size changes have | |
1587 occurred. | |
1588 | |
1589 Each function receives the frame as its sole argument. There is no | |
1590 direct way to find out which windows changed size, or precisely how; | |
1591 however, if your size-change function keeps track, after each change, of | |
1592 the windows that interest you, you can figure out what has changed by | |
1593 comparing the old size data with the new. | |
1594 | |
1595 Creating or deleting windows counts as a size change, and therefore | |
1596 causes these functions to be called. Changing the frame size also | |
1597 counts, because it changes the sizes of the existing windows. | |
12098 | 1598 |
1599 It is not a good idea to use @code{save-window-excursion} in these | |
1600 functions, because that always counts as a size change, and it would | |
1601 cause these functions to be called over and over. In most cases, | |
1602 @code{save-selected-window} is what you need here. | |
12067 | 1603 @end defvar |
1604 | |
6564 | 1605 @node Coordinates and Windows |
1606 @section Coordinates and Windows | |
1607 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1608 This section describes how to relate screen coordinates to windows. |
6564 | 1609 |
1610 @defun window-at x y &optional frame | |
1611 This function returns the window containing the specified cursor | |
1612 position in the frame @var{frame}. The coordinates @var{x} and @var{y} | |
1613 are measured in characters and count from the top left corner of the | |
1614 frame. If they are out of range, @code{window-at} returns @code{nil}. | |
1615 | |
1616 If you omit @var{frame}, the selected frame is used. | |
1617 @end defun | |
1618 | |
1619 @defun coordinates-in-window-p coordinates window | |
1620 This function checks whether a particular frame position falls within | |
1621 the window @var{window}. | |
1622 | |
12282
586e3ea81792
updates for version 19.29 made by melissa; also needed to check out files
Melissa Weisshaus <melissa@gnu.org>
parents:
12125
diff
changeset
|
1623 @need 3000 |
6564 | 1624 The argument @var{coordinates} is a cons cell of this form: |
1625 | |
1626 @example | |
1627 (@var{x} . @var{y}) | |
1628 @end example | |
1629 | |
1630 @noindent | |
1631 The coordinates @var{x} and @var{y} are measured in characters, and | |
1632 count from the top left corner of the screen or frame. | |
1633 | |
1634 The value of @code{coordinates-in-window-p} is non-@code{nil} if the | |
1635 coordinates are inside @var{window}. The value also indicates what part | |
1636 of the window the position is in, as follows: | |
1637 | |
1638 @table @code | |
1639 @item (@var{relx} . @var{rely}) | |
1640 The coordinates are inside @var{window}. The numbers @var{relx} and | |
1641 @var{rely} are the equivalent window-relative coordinates for the | |
1642 specified position, counting from 0 at the top left corner of the | |
1643 window. | |
1644 | |
1645 @item mode-line | |
1646 The coordinates are in the mode line of @var{window}. | |
1647 | |
1648 @item vertical-split | |
1649 The coordinates are in the vertical line between @var{window} and its | |
1650 neighbor to the right. This value occurs only if the window doesn't | |
1651 have a scroll bar; positions in a scroll bar are considered outside the | |
1652 window. | |
1653 | |
1654 @item nil | |
1655 The coordinates are not in any part of @var{window}. | |
1656 @end table | |
1657 | |
1658 The function @code{coordinates-in-window-p} does not require a frame as | |
1659 argument because it always uses the frame that @var{window} is on. | |
1660 @end defun | |
1661 | |
1662 @node Window Configurations | |
1663 @section Window Configurations | |
1664 @cindex window configurations | |
1665 @cindex saving window information | |
1666 | |
1667 A @dfn{window configuration} records the entire layout of a | |
1668 frame---all windows, their sizes, which buffers they contain, what part | |
1669 of each buffer is displayed, and the values of point and the mark. You | |
1670 can bring back an entire previous layout by restoring a window | |
1671 configuration previously saved. | |
1672 | |
1673 If you want to record all frames instead of just one, use a frame | |
1674 configuration instead of a window configuration. @xref{Frame | |
1675 Configurations}. | |
1676 | |
1677 @defun current-window-configuration | |
1678 This function returns a new object representing Emacs's current window | |
1679 configuration, namely the number of windows, their sizes and current | |
1680 buffers, which window is the selected window, and for each window the | |
1681 displayed buffer, the display-start position, and the positions of point | |
1682 and the mark. An exception is made for point in the current buffer, | |
1683 whose value is not saved. | |
1684 @end defun | |
1685 | |
1686 @defun set-window-configuration configuration | |
1687 This function restores the configuration of Emacs's windows and | |
1688 buffers to the state specified by @var{configuration}. The argument | |
1689 @var{configuration} must be a value that was previously returned by | |
1690 @code{current-window-configuration}. | |
1691 | |
12098 | 1692 This function always counts as a window size change and triggers |
1693 execution of the @code{window-size-change-functions}. (It doesn't know | |
1694 how to tell whether the new configuration actually differs from the old | |
1695 one.) | |
1696 | |
6564 | 1697 Here is a way of using this function to get the same effect |
1698 as @code{save-window-excursion}: | |
1699 | |
1700 @example | |
1701 @group | |
1702 (let ((config (current-window-configuration))) | |
1703 (unwind-protect | |
1704 (progn (split-window-vertically nil) | |
1705 @dots{}) | |
1706 (set-window-configuration config))) | |
1707 @end group | |
1708 @end example | |
1709 @end defun | |
1710 | |
1711 @defspec save-window-excursion forms@dots{} | |
1712 This special form records the window configuration, executes @var{forms} | |
1713 in sequence, then restores the earlier window configuration. The window | |
1714 configuration includes the value of point and the portion of the buffer | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1715 that is visible. It also includes the choice of selected window. |
6564 | 1716 However, it does not include the value of point in the current buffer; |
1717 use @code{save-excursion} if you wish to preserve that. | |
1718 | |
12098 | 1719 Don't use this construct when @code{save-selected-window} is all you need. |
1720 | |
1721 Exit from @code{save-window-excursion} always triggers execution of the | |
1722 @code{window-size-change-functions}. (It doesn't know how to tell | |
1723 whether the restored configuration actually differs from the one in | |
1724 effect at the end of the @var{forms}.) | |
1725 | |
6564 | 1726 The return value is the value of the final form in @var{forms}. |
1727 For example: | |
1728 | |
1729 @example | |
1730 @group | |
1731 (split-window) | |
1732 @result{} #<window 25 on control.texi> | |
1733 @end group | |
1734 @group | |
1735 (setq w (selected-window)) | |
1736 @result{} #<window 19 on control.texi> | |
1737 @end group | |
1738 @group | |
1739 (save-window-excursion | |
1740 (delete-other-windows w) | |
1741 (switch-to-buffer "foo") | |
1742 'do-something) | |
1743 @result{} do-something | |
1744 ;; @r{The screen is now split again.} | |
1745 @end group | |
1746 @end example | |
1747 @end defspec | |
1748 | |
1749 @defun window-configuration-p object | |
1750 This function returns @code{t} if @var{object} is a window configuration. | |
1751 @end defun | |
1752 | |
1753 Primitives to look inside of window configurations would make sense, | |
1754 but none are implemented. It is not clear they are useful enough to be | |
1755 worth implementing. |