Mercurial > emacs
annotate lispref/windows.texi @ 12453:8e4f8107dcd0
(EMACS) [win95]: Removed.
(TLASTLIB): Defined.
(TEMACS): Use TLASTLIB.
author | Geoff Voelker <voelker@cs.washington.edu> |
---|---|
date | Fri, 30 Jun 1995 21:14:56 +0000 |
parents | 586e3ea81792 |
children | ffe0de415152 |
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 |
12098 | 882 @defvar same-window-buffer-names |
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. | |
887 @end defvar | |
888 | |
889 @defvar same-window-regexps | |
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. | |
894 @end defvar | |
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 | |
1006 For a realistic example, see the description of @code{count-lines} in | |
1007 @ref{Text Lines}. | |
1008 @end defun | |
1009 | |
1010 @defun window-end &optional window | |
1011 This function returns the position of the end of the display in window | |
1012 @var{window}. If @var{window} is @code{nil}, the selected window is | |
1013 used. | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1014 |
11510
e5d3814e783a
Update info on window-end.
Richard M. Stallman <rms@gnu.org>
parents:
8926
diff
changeset
|
1015 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
|
1016 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
|
1017 Emacs redisplays and redisplay actually finishes. |
e5d3814e783a
Update info on window-end.
Richard M. Stallman <rms@gnu.org>
parents:
8926
diff
changeset
|
1018 |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1019 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
|
1020 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
|
1021 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
|
1022 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
|
1023 @ignore |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1024 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
|
1025 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
|
1026 like this: |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1027 |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1028 @example |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1029 (save-excursion |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1030 (goto-char (window-start window)) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1031 (vertical-motion (1- (window-height window)) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1032 window) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1033 (point)) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1034 @end example |
8516
5d76d6decb35
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
8491
diff
changeset
|
1035 @end ignore |
6564 | 1036 @end defun |
1037 | |
1038 @defun set-window-start window position &optional noforce | |
1039 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
|
1040 @var{position} in @var{window}'s buffer. It returns @var{position}. |
6564 | 1041 |
1042 The display routines insist that the position of point be visible when a | |
1043 buffer is displayed. Normally, they change the display-start position | |
1044 (that is, scroll the window) whenever necessary to make point visible. | |
1045 However, if you specify the start position with this function using | |
1046 @code{nil} for @var{noforce}, it means you want display to start at | |
1047 @var{position} even if that would put the location of point off the | |
1048 screen. If this does place point off screen, the display routines move | |
1049 point to the left margin on the middle line in the window. | |
1050 | |
1051 For example, if point @w{is 1} and you set the start of the window @w{to | |
1052 2}, then point would be ``above'' the top of the window. The display | |
1053 routines will automatically move point if it is still 1 when redisplay | |
1054 occurs. Here is an example: | |
1055 | |
1056 @example | |
1057 @group | |
1058 ;; @r{Here is what @samp{foo} looks like before executing} | |
1059 ;; @r{the @code{set-window-start} expression.} | |
1060 @end group | |
1061 | |
1062 @group | |
1063 ---------- Buffer: foo ---------- | |
1064 @point{}This is the contents of buffer foo. | |
1065 2 | |
1066 3 | |
1067 4 | |
1068 5 | |
1069 6 | |
1070 ---------- Buffer: foo ---------- | |
1071 @end group | |
1072 | |
1073 @group | |
1074 (set-window-start | |
1075 (selected-window) | |
1076 (1+ (window-start))) | |
1077 @result{} 2 | |
1078 @end group | |
1079 | |
1080 @group | |
1081 ;; @r{Here is what @samp{foo} looks like after executing} | |
1082 ;; @r{the @code{set-window-start} expression.} | |
1083 ---------- Buffer: foo ---------- | |
1084 his is the contents of buffer foo. | |
1085 2 | |
1086 3 | |
1087 @point{}4 | |
1088 5 | |
1089 6 | |
1090 ---------- Buffer: foo ---------- | |
1091 @end group | |
1092 @end example | |
1093 | |
1094 If @var{noforce} is non-@code{nil}, and @var{position} would place point | |
1095 off screen at the next redisplay, then redisplay computes a new window-start | |
1096 position that works well with point, and thus @var{position} is not used. | |
1097 @end defun | |
1098 | |
1099 @defun pos-visible-in-window-p &optional position window | |
1100 This function returns @code{t} if @var{position} is within the range | |
1101 of text currently visible on the screen in @var{window}. It returns | |
1102 @code{nil} if @var{position} is scrolled vertically out of view. The | |
1103 argument @var{position} defaults to the current position of point; | |
1104 @var{window}, to the selected window. Here is an example: | |
1105 | |
1106 @example | |
1107 @group | |
1108 (or (pos-visible-in-window-p | |
1109 (point) (selected-window)) | |
1110 (recenter 0)) | |
1111 @end group | |
1112 @end example | |
1113 | |
1114 The @code{pos-visible-in-window-p} function considers only vertical | |
1115 scrolling. If @var{position} is out of view only because @var{window} | |
1116 has been scrolled horizontally, @code{pos-visible-in-window-p} returns | |
1117 @code{t}. @xref{Horizontal Scrolling}. | |
1118 @end defun | |
1119 | |
1120 @node Vertical Scrolling | |
1121 @section Vertical Scrolling | |
1122 @cindex vertical scrolling | |
1123 @cindex scrolling vertically | |
1124 | |
1125 Vertical scrolling means moving the text up or down in a window. It | |
1126 works by changing the value of the window's display-start location. It | |
1127 may also change the value of @code{window-point} to keep it on the | |
1128 screen. | |
1129 | |
1130 In the commands @code{scroll-up} and @code{scroll-down}, the directions | |
1131 ``up'' and ``down'' refer to the motion of the text in the buffer at which | |
1132 you are looking through the window. Imagine that the text is | |
1133 written on a long roll of paper and that the scrolling commands move the | |
1134 paper up and down. Thus, if you are looking at text in the middle of a | |
1135 buffer and repeatedly call @code{scroll-down}, you will eventually see | |
1136 the beginning of the buffer. | |
1137 | |
1138 Some people have urged that the opposite convention be used: they | |
1139 imagine that the window moves over text that remains in place. Then | |
1140 ``down'' commands would take you to the end of the buffer. This view is | |
1141 more consistent with the actual relationship between windows and the | |
1142 text in the buffer, but it is less like what the user sees. The | |
1143 position of a window on the terminal does not move, and short scrolling | |
1144 commands clearly move the text up or down on the screen. We have chosen | |
1145 names that fit the user's point of view. | |
1146 | |
1147 The scrolling functions (aside from @code{scroll-other-window}) have | |
1148 unpredictable results if the current buffer is different from the buffer | |
1149 that is displayed in the selected window. @xref{Current Buffer}. | |
1150 | |
1151 @deffn Command scroll-up &optional count | |
1152 This function scrolls the text in the selected window upward | |
1153 @var{count} lines. If @var{count} is negative, scrolling is actually | |
1154 downward. | |
1155 | |
1156 If @var{count} is @code{nil} (or omitted), then the length of scroll | |
1157 is @code{next-screen-context-lines} lines less than the usable height of | |
1158 the window (not counting its mode line). | |
1159 | |
1160 @code{scroll-up} returns @code{nil}. | |
1161 @end deffn | |
1162 | |
1163 @deffn Command scroll-down &optional count | |
1164 This function scrolls the text in the selected window downward | |
1165 @var{count} lines. If @var{count} is negative, scrolling is actually | |
1166 upward. | |
1167 | |
1168 If @var{count} is omitted or @code{nil}, then the length of the scroll | |
1169 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
|
1170 the window (not counting its mode line). |
6564 | 1171 |
1172 @code{scroll-down} returns @code{nil}. | |
1173 @end deffn | |
1174 | |
1175 @deffn Command scroll-other-window &optional count | |
1176 This function scrolls the text in another window upward @var{count} | |
1177 lines. Negative values of @var{count}, or @code{nil}, are handled | |
1178 as in @code{scroll-up}. | |
1179 | |
1180 You can specify a buffer to scroll with the variable | |
1181 @code{other-window-scroll-buffer}. When the selected window is the | |
1182 minibuffer, the next window is normally the one at the top left corner. | |
1183 You can specify a different window to scroll with the variable | |
1184 @code{minibuffer-scroll-window}. This variable has no effect when any | |
1185 other window is selected. @xref{Minibuffer Misc}. | |
1186 | |
1187 When the minibuffer is active, it is the next window if the selected | |
1188 window is the one at the bottom right corner. In this case, | |
1189 @code{scroll-other-window} attempts to scroll the minibuffer. If the | |
1190 minibuffer contains just one line, it has nowhere to scroll to, so the | |
1191 line reappears after the echo area momentarily displays the message | |
1192 ``Beginning of buffer''. | |
1193 @end deffn | |
1194 | |
1195 @c Emacs 19 feature | |
1196 @defvar other-window-scroll-buffer | |
1197 If this variable is non-@code{nil}, it tells @code{scroll-other-window} | |
1198 which buffer to scroll. | |
1199 @end defvar | |
1200 | |
1201 @defopt scroll-step | |
1202 This variable controls how scrolling is done automatically when point | |
1203 moves off the screen. If the value is zero, then redisplay scrolls the | |
1204 text to center point vertically in the window. If the value is a | |
1205 positive integer @var{n}, then redisplay brings point back on screen by | |
1206 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
|
1207 centers point. The default value is zero. |
6564 | 1208 @end defopt |
1209 | |
1210 @defopt next-screen-context-lines | |
1211 The value of this variable is the number of lines of continuity to | |
1212 retain when scrolling by full screens. For example, @code{scroll-up} | |
1213 with an argument of @code{nil} scrolls so that this many lines at the | |
1214 bottom of the window appear instead at the top. The default value is | |
1215 @code{2}. | |
1216 @end defopt | |
1217 | |
1218 @deffn Command recenter &optional count | |
1219 @cindex centering point | |
1220 This function scrolls the selected window to put the text where point | |
1221 is located at a specified vertical position within the window. | |
1222 | |
1223 If @var{count} is a nonnegative number, it puts the line containing | |
1224 point @var{count} lines down from the top of the window. If @var{count} | |
1225 is a negative number, then it counts upward from the bottom of the | |
1226 window, so that @minus{}1 stands for the last usable line in the window. | |
1227 If @var{count} is a non-@code{nil} list, then it stands for the line in | |
1228 the middle of the window. | |
1229 | |
1230 If @var{count} is @code{nil}, @code{recenter} puts the line containing | |
1231 point in the middle of the window, then clears and redisplays the entire | |
1232 selected frame. | |
1233 | |
1234 When @code{recenter} is called interactively, @var{count} is the raw | |
1235 prefix argument. Thus, typing @kbd{C-u} as the prefix sets the | |
1236 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets | |
1237 @var{count} to 4, which positions the current line four lines from the | |
1238 top. | |
1239 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1240 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
|
1241 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
|
1242 separate key binding to do this. For example, |
6564 | 1243 |
1244 @example | |
1245 @group | |
1246 (defun line-to-top-of-window () | |
1247 "Scroll current line to top of window. | |
1248 Replaces three keystroke sequence C-u 0 C-l." | |
1249 (interactive) | |
1250 (recenter 0)) | |
1251 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1252 (global-set-key [kp-multiply] 'line-to-top-of-window) |
6564 | 1253 @end group |
1254 @end example | |
1255 @end deffn | |
1256 | |
1257 @node Horizontal Scrolling | |
1258 @section Horizontal Scrolling | |
1259 @cindex horizontal scrolling | |
1260 | |
1261 Because we read English first from top to bottom and second from left | |
1262 to right, horizontal scrolling is not like vertical scrolling. Vertical | |
1263 scrolling involves selection of a contiguous portion of text to display. | |
1264 Horizontal scrolling causes part of each line to go off screen. The | |
1265 amount of horizontal scrolling is therefore specified as a number of | |
1266 columns rather than as a position in the buffer. It has nothing to do | |
1267 with the display-start position returned by @code{window-start}. | |
1268 | |
1269 Usually, no horizontal scrolling is in effect; then the leftmost | |
1270 column is at the left edge of the window. In this state, scrolling to | |
1271 the right is meaningless, since there is no data to the left of the | |
1272 screen to be revealed by it; so this is not allowed. Scrolling to the | |
1273 left is allowed; it scrolls the first columns of text off the edge of | |
1274 the window and can reveal additional columns on the right that were | |
1275 truncated before. Once a window has a nonzero amount of leftward | |
1276 horizontal scrolling, you can scroll it back to the right, but only so | |
1277 far as to reduce the net horizontal scroll to zero. There is no limit | |
1278 to how far left you can scroll, but eventually all the text will | |
1279 disappear off the left edge. | |
1280 | |
1281 @deffn Command scroll-left count | |
1282 This function scrolls the selected window @var{count} columns to the | |
1283 left (or to the right if @var{count} is negative). The return value is | |
1284 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
|
1285 change---just like the value returned by @code{window-hscroll} (below). |
6564 | 1286 @end deffn |
1287 | |
1288 @deffn Command scroll-right count | |
1289 This function scrolls the selected window @var{count} columns to the | |
1290 right (or to the left if @var{count} is negative). The return value is | |
1291 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
|
1292 change---just like the value returned by @code{window-hscroll} (below). |
6564 | 1293 |
1294 Once you scroll a window as far right as it can go, back to its normal | |
1295 position where the total leftward scrolling is zero, attempts to scroll | |
1296 any farther right have no effect. | |
1297 @end deffn | |
1298 | |
1299 @defun window-hscroll &optional window | |
1300 This function returns the total leftward horizontal scrolling of | |
1301 @var{window}---the number of columns by which the text in @var{window} | |
1302 is scrolled left past the left margin. | |
1303 | |
1304 The value is never negative. It is zero when no horizontal scrolling | |
1305 has been done in @var{window} (which is usually the case). | |
1306 | |
1307 If @var{window} is @code{nil}, the selected window is used. | |
1308 | |
1309 @example | |
1310 @group | |
1311 (window-hscroll) | |
1312 @result{} 0 | |
1313 @end group | |
1314 @group | |
1315 (scroll-left 5) | |
1316 @result{} 5 | |
1317 @end group | |
1318 @group | |
1319 (window-hscroll) | |
1320 @result{} 5 | |
1321 @end group | |
1322 @end example | |
1323 @end defun | |
1324 | |
1325 @defun set-window-hscroll window columns | |
1326 This function sets the number of columns from the left margin that | |
1327 @var{window} is scrolled to the value of @var{columns}. The argument | |
1328 @var{columns} should be zero or positive; if not, it is taken as zero. | |
1329 | |
1330 The value returned is @var{columns}. | |
1331 | |
1332 @example | |
1333 @group | |
1334 (set-window-hscroll (selected-window) 10) | |
1335 @result{} 10 | |
1336 @end group | |
1337 @end example | |
1338 @end defun | |
1339 | |
1340 Here is how you can determine whether a given position @var{position} | |
1341 is off the screen due to horizontal scrolling: | |
1342 | |
1343 @example | |
1344 @group | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1345 (defun hscroll-on-screen (window position) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1346 (save-excursion |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1347 (goto-char position) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1348 (and |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1349 (>= (- (current-column) (window-hscroll window)) 0) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1350 (< (- (current-column) (window-hscroll window)) |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1351 (window-width window))))) |
6564 | 1352 @end group |
1353 @end example | |
1354 | |
1355 @node Size of Window | |
1356 @section The Size of a Window | |
1357 @cindex window size | |
1358 @cindex size of window | |
1359 | |
1360 An Emacs window is rectangular, and its size information consists of | |
1361 the height (the number of lines) and the width (the number of character | |
1362 positions in each line). The mode line is included in the height. But | |
1363 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
|
1364 characters that separates side-by-side windows. |
6564 | 1365 |
1366 The following three functions return size information about a window: | |
1367 | |
1368 @defun window-height &optional window | |
1369 This function returns the number of lines in @var{window}, including | |
1370 its mode line. If @var{window} fills its entire frame, this is one less | |
1371 than the value of @code{frame-height} on that frame (since the last line | |
1372 is always reserved for the minibuffer). | |
1373 | |
1374 If @var{window} is @code{nil}, the function uses the selected window. | |
1375 | |
1376 @example | |
1377 @group | |
1378 (window-height) | |
1379 @result{} 23 | |
1380 @end group | |
1381 @group | |
1382 (split-window-vertically) | |
1383 @result{} #<window 4 on windows.texi> | |
1384 @end group | |
1385 @group | |
1386 (window-height) | |
1387 @result{} 11 | |
1388 @end group | |
1389 @end example | |
1390 @end defun | |
1391 | |
1392 @defun window-width &optional window | |
1393 This function returns the number of columns in @var{window}. If | |
1394 @var{window} fills its entire frame, this is the same as the value of | |
1395 @code{frame-width} on that frame. The width does not include the | |
1396 window's scroll bar or the column of @samp{|} characters that separates | |
1397 side-by-side windows. | |
1398 | |
1399 If @var{window} is @code{nil}, the function uses the selected window. | |
1400 | |
1401 @example | |
1402 @group | |
1403 (window-width) | |
1404 @result{} 80 | |
1405 @end group | |
1406 @end example | |
1407 @end defun | |
1408 | |
1409 @defun window-edges &optional window | |
1410 This function returns a list of the edge coordinates of @var{window}. | |
1411 If @var{window} is @code{nil}, the selected window is used. | |
1412 | |
1413 The order of the list is @code{(@var{left} @var{top} @var{right} | |
1414 @var{bottom})}, all elements relative to 0, 0 at the top left corner of | |
1415 the frame. The element @var{right} of the value is one more than the | |
1416 rightmost column used by @var{window}, and @var{bottom} is one more than | |
1417 the bottommost row used by @var{window} and its mode-line. | |
1418 | |
1419 When you have side-by-side windows, the right edge value for a window | |
1420 with a neighbor on the right includes the width of the separator between | |
1421 the window and that neighbor. This separator may be a column of | |
1422 @samp{|} characters or it may be a scroll bar. Since the width of the | |
1423 window does not include this separator, the width does not equal the | |
1424 difference between the right and left edges in this case. | |
1425 | |
1426 Here is the result obtained on a typical 24-line terminal with just one | |
1427 window: | |
1428 | |
1429 @example | |
1430 @group | |
1431 (window-edges (selected-window)) | |
1432 @result{} (0 0 80 23) | |
1433 @end group | |
1434 @end example | |
1435 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1436 @noindent |
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1437 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
|
1438 |
6564 | 1439 If @var{window} is at the upper left corner of its frame, @var{right} |
1440 and @var{bottom} are the same as the values returned by | |
1441 @code{(window-width)} and @code{(window-height)} respectively, and | |
1442 @var{top} and @var{bottom} are zero. For example, the edges of the | |
1443 following window are @w{@samp{0 0 5 8}}. Assuming that the frame has | |
1444 more than 8 columns, the last column of the window (column 7) holds a | |
1445 border rather than text. The last row (row 4) holds the mode line, | |
1446 shown here with @samp{xxxxxxxxx}. | |
1447 | |
1448 @example | |
1449 @group | |
1450 0 | |
1451 _______ | |
1452 0 | | | |
1453 | | | |
1454 | | | |
1455 | | | |
1456 xxxxxxxxx 4 | |
1457 | |
1458 7 | |
1459 @end group | |
1460 @end example | |
1461 | |
1462 When there are side-by-side windows, any window not at the right edge of | |
1463 its frame has a separator in its last column or columns. The separator | |
1464 counts as one or two columns in the width of the window. A window never | |
1465 includes a separator on its left, since that belongs to the window to | |
1466 the left. | |
1467 | |
1468 In the following example, let's suppose that the frame is 7 | |
1469 columns wide. Then the edges of the left window are @w{@samp{0 0 4 3}} | |
1470 and the edges of the right window are @w{@samp{4 0 7 3}}. | |
1471 | |
1472 @example | |
1473 @group | |
1474 ___ ___ | |
1475 | | | | |
1476 | | | | |
1477 xxxxxxxxx | |
1478 | |
1479 0 34 7 | |
1480 @end group | |
1481 @end example | |
1482 @end defun | |
1483 | |
1484 @node Resizing Windows | |
1485 @section Changing the Size of a Window | |
1486 @cindex window resizing | |
1487 @cindex changing window size | |
1488 @cindex window size, changing | |
1489 | |
1490 The window size functions fall into two classes: high-level commands | |
1491 that change the size of windows and low-level functions that access | |
1492 window size. Emacs does not permit overlapping windows or gaps between | |
1493 windows, so resizing one window affects other windows. | |
1494 | |
1495 @deffn Command enlarge-window size &optional horizontal | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1496 This function makes the selected window @var{size} lines taller, |
6564 | 1497 stealing lines from neighboring windows. It takes the lines from one |
1498 window at a time until that window is used up, then takes from another. | |
1499 If a window from which lines are stolen shrinks below | |
1500 @code{window-min-height} lines, that window disappears. | |
1501 | |
1502 If @var{horizontal} is non-@code{nil}, this function makes | |
1503 @var{window} wider by @var{size} columns, stealing columns instead of | |
1504 lines. If a window from which columns are stolen shrinks below | |
1505 @code{window-min-width} columns, that window disappears. | |
1506 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1507 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
|
1508 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
|
1509 frame. |
6564 | 1510 |
1511 If @var{size} is negative, this function shrinks the window by | |
1512 @minus{}@var{size} lines or columns. If that makes the window smaller | |
1513 than the minimum size (@code{window-min-height} and | |
1514 @code{window-min-width}), @code{enlarge-window} deletes the window. | |
1515 | |
1516 @code{enlarge-window} returns @code{nil}. | |
1517 @end deffn | |
1518 | |
1519 @deffn Command enlarge-window-horizontally columns | |
1520 This function makes the selected window @var{columns} wider. | |
1521 It could be defined as follows: | |
1522 | |
1523 @example | |
1524 @group | |
1525 (defun enlarge-window-horizontally (columns) | |
1526 (enlarge-window columns t)) | |
1527 @end group | |
1528 @end example | |
1529 @end deffn | |
1530 | |
1531 @deffn Command shrink-window size &optional horizontal | |
1532 This function is like @code{enlarge-window} but negates the argument | |
1533 @var{size}, making the selected window smaller by giving lines (or | |
1534 columns) to the other windows. If the window shrinks below | |
1535 @code{window-min-height} or @code{window-min-width}, then it disappears. | |
1536 | |
1537 If @var{size} is negative, the window is enlarged by @minus{}@var{size} | |
1538 lines or columns. | |
1539 @end deffn | |
1540 | |
1541 @deffn Command shrink-window-horizontally columns | |
1542 This function makes the selected window @var{columns} narrower. | |
1543 It could be defined as follows: | |
1544 | |
1545 @example | |
1546 @group | |
1547 (defun shrink-window-horizontally (columns) | |
1548 (shrink-window columns t)) | |
1549 @end group | |
1550 @end example | |
1551 @end deffn | |
1552 | |
1553 @cindex minimum window size | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1554 The following two variables constrain the window-size-changing |
6564 | 1555 functions to a minimum height and width. |
1556 | |
1557 @defopt window-min-height | |
1558 The value of this variable determines how short a window may become | |
1559 before it is automatically deleted. Making a window smaller than | |
1560 @code{window-min-height} automatically deletes it, and no window may be | |
1561 created shorter than this. The absolute minimum height is two (allowing | |
1562 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
|
1563 Actions that change window sizes reset this variable to two if it is |
6564 | 1564 less than two. The default value is 4. |
1565 @end defopt | |
1566 | |
1567 @defopt window-min-width | |
1568 The value of this variable determines how narrow a window may become | |
1569 before it automatically deleted. Making a window smaller than | |
1570 @code{window-min-width} automatically deletes it, and no window may be | |
1571 created narrower than this. The absolute minimum width is one; any | |
1572 value below that is ignored. The default value is 10. | |
1573 @end defopt | |
1574 | |
12067 | 1575 @defvar window-size-change-functions |
1576 This variable holds a list of functions to be called if the size of any | |
1577 window changes for any reason. The functions are called just once per | |
1578 redisplay, and just once for each frame on which size changes have | |
1579 occurred. | |
1580 | |
1581 Each function receives the frame as its sole argument. There is no | |
1582 direct way to find out which windows changed size, or precisely how; | |
1583 however, if your size-change function keeps track, after each change, of | |
1584 the windows that interest you, you can figure out what has changed by | |
1585 comparing the old size data with the new. | |
1586 | |
1587 Creating or deleting windows counts as a size change, and therefore | |
1588 causes these functions to be called. Changing the frame size also | |
1589 counts, because it changes the sizes of the existing windows. | |
12098 | 1590 |
1591 It is not a good idea to use @code{save-window-excursion} in these | |
1592 functions, because that always counts as a size change, and it would | |
1593 cause these functions to be called over and over. In most cases, | |
1594 @code{save-selected-window} is what you need here. | |
12067 | 1595 @end defvar |
1596 | |
6564 | 1597 @node Coordinates and Windows |
1598 @section Coordinates and Windows | |
1599 | |
8491
320375e58ee3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
7735
diff
changeset
|
1600 This section describes how to relate screen coordinates to windows. |
6564 | 1601 |
1602 @defun window-at x y &optional frame | |
1603 This function returns the window containing the specified cursor | |
1604 position in the frame @var{frame}. The coordinates @var{x} and @var{y} | |
1605 are measured in characters and count from the top left corner of the | |
1606 frame. If they are out of range, @code{window-at} returns @code{nil}. | |
1607 | |
1608 If you omit @var{frame}, the selected frame is used. | |
1609 @end defun | |
1610 | |
1611 @defun coordinates-in-window-p coordinates window | |
1612 This function checks whether a particular frame position falls within | |
1613 the window @var{window}. | |
1614 | |
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
|
1615 @need 3000 |
6564 | 1616 The argument @var{coordinates} is a cons cell of this form: |
1617 | |
1618 @example | |
1619 (@var{x} . @var{y}) | |
1620 @end example | |
1621 | |
1622 @noindent | |
1623 The coordinates @var{x} and @var{y} are measured in characters, and | |
1624 count from the top left corner of the screen or frame. | |
1625 | |
1626 The value of @code{coordinates-in-window-p} is non-@code{nil} if the | |
1627 coordinates are inside @var{window}. The value also indicates what part | |
1628 of the window the position is in, as follows: | |
1629 | |
1630 @table @code | |
1631 @item (@var{relx} . @var{rely}) | |
1632 The coordinates are inside @var{window}. The numbers @var{relx} and | |
1633 @var{rely} are the equivalent window-relative coordinates for the | |
1634 specified position, counting from 0 at the top left corner of the | |
1635 window. | |
1636 | |
1637 @item mode-line | |
1638 The coordinates are in the mode line of @var{window}. | |
1639 | |
1640 @item vertical-split | |
1641 The coordinates are in the vertical line between @var{window} and its | |
1642 neighbor to the right. This value occurs only if the window doesn't | |
1643 have a scroll bar; positions in a scroll bar are considered outside the | |
1644 window. | |
1645 | |
1646 @item nil | |
1647 The coordinates are not in any part of @var{window}. | |
1648 @end table | |
1649 | |
1650 The function @code{coordinates-in-window-p} does not require a frame as | |
1651 argument because it always uses the frame that @var{window} is on. | |
1652 @end defun | |
1653 | |
1654 @node Window Configurations | |
1655 @section Window Configurations | |
1656 @cindex window configurations | |
1657 @cindex saving window information | |
1658 | |
1659 A @dfn{window configuration} records the entire layout of a | |
1660 frame---all windows, their sizes, which buffers they contain, what part | |
1661 of each buffer is displayed, and the values of point and the mark. You | |
1662 can bring back an entire previous layout by restoring a window | |
1663 configuration previously saved. | |
1664 | |
1665 If you want to record all frames instead of just one, use a frame | |
1666 configuration instead of a window configuration. @xref{Frame | |
1667 Configurations}. | |
1668 | |
1669 @defun current-window-configuration | |
1670 This function returns a new object representing Emacs's current window | |
1671 configuration, namely the number of windows, their sizes and current | |
1672 buffers, which window is the selected window, and for each window the | |
1673 displayed buffer, the display-start position, and the positions of point | |
1674 and the mark. An exception is made for point in the current buffer, | |
1675 whose value is not saved. | |
1676 @end defun | |
1677 | |
1678 @defun set-window-configuration configuration | |
1679 This function restores the configuration of Emacs's windows and | |
1680 buffers to the state specified by @var{configuration}. The argument | |
1681 @var{configuration} must be a value that was previously returned by | |
1682 @code{current-window-configuration}. | |
1683 | |
12098 | 1684 This function always counts as a window size change and triggers |
1685 execution of the @code{window-size-change-functions}. (It doesn't know | |
1686 how to tell whether the new configuration actually differs from the old | |
1687 one.) | |
1688 | |
6564 | 1689 Here is a way of using this function to get the same effect |
1690 as @code{save-window-excursion}: | |
1691 | |
1692 @example | |
1693 @group | |
1694 (let ((config (current-window-configuration))) | |
1695 (unwind-protect | |
1696 (progn (split-window-vertically nil) | |
1697 @dots{}) | |
1698 (set-window-configuration config))) | |
1699 @end group | |
1700 @end example | |
1701 @end defun | |
1702 | |
1703 @defspec save-window-excursion forms@dots{} | |
1704 This special form records the window configuration, executes @var{forms} | |
1705 in sequence, then restores the earlier window configuration. The window | |
1706 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
|
1707 that is visible. It also includes the choice of selected window. |
6564 | 1708 However, it does not include the value of point in the current buffer; |
1709 use @code{save-excursion} if you wish to preserve that. | |
1710 | |
12098 | 1711 Don't use this construct when @code{save-selected-window} is all you need. |
1712 | |
1713 Exit from @code{save-window-excursion} always triggers execution of the | |
1714 @code{window-size-change-functions}. (It doesn't know how to tell | |
1715 whether the restored configuration actually differs from the one in | |
1716 effect at the end of the @var{forms}.) | |
1717 | |
6564 | 1718 The return value is the value of the final form in @var{forms}. |
1719 For example: | |
1720 | |
1721 @example | |
1722 @group | |
1723 (split-window) | |
1724 @result{} #<window 25 on control.texi> | |
1725 @end group | |
1726 @group | |
1727 (setq w (selected-window)) | |
1728 @result{} #<window 19 on control.texi> | |
1729 @end group | |
1730 @group | |
1731 (save-window-excursion | |
1732 (delete-other-windows w) | |
1733 (switch-to-buffer "foo") | |
1734 'do-something) | |
1735 @result{} do-something | |
1736 ;; @r{The screen is now split again.} | |
1737 @end group | |
1738 @end example | |
1739 @end defspec | |
1740 | |
1741 @defun window-configuration-p object | |
1742 This function returns @code{t} if @var{object} is a window configuration. | |
1743 @end defun | |
1744 | |
1745 Primitives to look inside of window configurations would make sense, | |
1746 but none are implemented. It is not clear they are useful enough to be | |
1747 worth implementing. |