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