]> code.delx.au - gnu-emacs/blob - lispref/windows.texi
*** empty log message ***
[gnu-emacs] / lispref / windows.texi
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
324 @strong{Warning:} erroneous information or fatal errors may result from
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
796 @c Emacs 19 feature
797 @defvar display-buffer-function
798 This variable is the most flexible way to customize the behavior of
799 @code{display-buffer}. If it is non-@code{nil}, it should be a function
800 that @code{display-buffer} calls to do the work. The function should
801 accept two arguments, the same two arguments that @code{display-buffer}
802 received. It should choose or create a window, display the specified
803 buffer, and then return the window.
804
805 This hook takes precedence over all the other options and hooks
806 described above.
807 @end defvar
808
809 @c Emacs 19 feature
810 @cindex dedicated window
811 A window can be marked as ``dedicated'' to its buffer. Then
812 @code{display-buffer} does not try to use that window.
813
814 @defun window-dedicated-p window
815 This function returns @code{t} if @var{window} is marked as dedicated;
816 otherwise @code{nil}.
817 @end defun
818
819 @defun set-window-dedicated-p window flag
820 This function marks @var{window} as dedicated if @var{flag} is
821 non-@code{nil}, and nondedicated otherwise.
822 @end defun
823
824 @node Window Point
825 @section Windows and Point
826 @cindex window position
827 @cindex window point
828 @cindex position in window
829 @cindex point in window
830
831 Each window has its own value of point, independent of the value of
832 point in other windows displaying the same buffer. This makes it useful
833 to have multiple windows showing one buffer.
834
835 @itemize @bullet
836 @item
837 The window point is established when a window is first created; it is
838 initialized from the buffer's point, or from the window point of another
839 window opened on the buffer if such a window exists.
840
841 @item
842 Selecting a window sets the value of point in its buffer to the window's
843 value of point. Conversely, deselecting a window sets the window's
844 value of point from that of the buffer. Thus, when you switch between
845 windows that display a given buffer, the point value for the selected
846 window is in effect in the buffer, while the point values for the other
847 windows are stored in those windows.
848
849 @item
850 As long as the selected window displays the current buffer, the window's
851 point and the buffer's point always move together; they remain equal.
852
853 @item
854 @xref{Positions}, for more details on buffer positions.
855 @end itemize
856
857 As far as the user is concerned, point is where the cursor is, and
858 when the user switches to another buffer, the cursor jumps to the
859 position of point in that buffer.
860
861 @defun window-point window
862 This function returns the current position of point in @var{window}.
863 For a nonselected window, this is the value point would have (in that
864 window's buffer) if that window were selected.
865
866 When @var{window} is the selected window and its buffer is also the
867 current buffer, the value returned is the same as point in that buffer.
868
869 Strictly speaking, it would be more correct to return the
870 ``top-level'' value of point, outside of any @code{save-excursion}
871 forms. But that value is hard to find.
872 @end defun
873
874 @defun set-window-point window position
875 This function positions point in @var{window} at position
876 @var{position} in @var{window}'s buffer.
877 @end defun
878
879 @node Window Start
880 @section The Window Start Position
881
882 Each window contains a marker used to keep track of a buffer position
883 which specifies where in the buffer display should start. This position
884 is called the @dfn{display-start} position of the window (or just the
885 @dfn{start}). The character after this position is the one that appears
886 at the upper left corner of the window. It is usually, but not
887 inevitably, at the beginning of a text line.
888
889 @defun window-start &optional window
890 @cindex window top line
891 This function returns the display-start position of window
892 @var{window}. If @var{window} is @code{nil}, the selected window is
893 used. For example,
894
895 @example
896 @group
897 (window-start)
898 @result{} 7058
899 @end group
900 @end example
901
902 When you create a window, or display a different buffer in it, the the
903 display-start position is set to a display-start position recently used
904 for the same buffer, or 1 if the buffer doesn't have any.
905
906 For a realistic example, see the description of @code{count-lines} in
907 @ref{Text Lines}.
908 @end defun
909
910 @defun window-end &optional window
911 This function returns the position of the end of the display in window
912 @var{window}. If @var{window} is @code{nil}, the selected window is
913 used.
914 @end defun
915
916 @defun set-window-start window position &optional noforce
917 This function sets the display-start position of @var{window} to
918 @var{position} in @var{window}'s buffer.
919
920 The display routines insist that the position of point be visible when a
921 buffer is displayed. Normally, they change the display-start position
922 (that is, scroll the window) whenever necessary to make point visible.
923 However, if you specify the start position with this function using
924 @code{nil} for @var{noforce}, it means you want display to start at
925 @var{position} even if that would put the location of point off the
926 screen. If this does place point off screen, the display routines move
927 point to the left margin on the middle line in the window.
928
929 For example, if point @w{is 1} and you set the start of the window @w{to
930 2}, then point would be ``above'' the top of the window. The display
931 routines will automatically move point if it is still 1 when redisplay
932 occurs. Here is an example:
933
934 @example
935 @group
936 ;; @r{Here is what @samp{foo} looks like before executing}
937 ;; @r{the @code{set-window-start} expression.}
938 @end group
939
940 @group
941 ---------- Buffer: foo ----------
942 @point{}This is the contents of buffer foo.
943 2
944 3
945 4
946 5
947 6
948 ---------- Buffer: foo ----------
949 @end group
950
951 @group
952 (set-window-start
953 (selected-window)
954 (1+ (window-start)))
955 @result{} 2
956 @end group
957
958 @group
959 ;; @r{Here is what @samp{foo} looks like after executing}
960 ;; @r{the @code{set-window-start} expression.}
961 ---------- Buffer: foo ----------
962 his is the contents of buffer foo.
963 2
964 3
965 @point{}4
966 5
967 6
968 ---------- Buffer: foo ----------
969 @end group
970 @end example
971
972 If @var{noforce} is non-@code{nil}, and @var{position} would place point
973 off screen at the next redisplay, then redisplay computes a new window-start
974 position that works well with point, and thus @var{position} is not used.
975
976 This function returns @var{position}.
977 @end defun
978
979 @defun pos-visible-in-window-p &optional position window
980 This function returns @code{t} if @var{position} is within the range
981 of text currently visible on the screen in @var{window}. It returns
982 @code{nil} if @var{position} is scrolled vertically out of view. The
983 argument @var{position} defaults to the current position of point;
984 @var{window}, to the selected window. Here is an example:
985
986 @example
987 @group
988 (or (pos-visible-in-window-p
989 (point) (selected-window))
990 (recenter 0))
991 @end group
992 @end example
993
994 The @code{pos-visible-in-window-p} function considers only vertical
995 scrolling. If @var{position} is out of view only because @var{window}
996 has been scrolled horizontally, @code{pos-visible-in-window-p} returns
997 @code{t}. @xref{Horizontal Scrolling}.
998 @end defun
999
1000 @node Vertical Scrolling
1001 @section Vertical Scrolling
1002 @cindex vertical scrolling
1003 @cindex scrolling vertically
1004
1005 Vertical scrolling means moving the text up or down in a window. It
1006 works by changing the value of the window's display-start location. It
1007 may also change the value of @code{window-point} to keep it on the
1008 screen.
1009
1010 In the commands @code{scroll-up} and @code{scroll-down}, the directions
1011 ``up'' and ``down'' refer to the motion of the text in the buffer at which
1012 you are looking through the window. Imagine that the text is
1013 written on a long roll of paper and that the scrolling commands move the
1014 paper up and down. Thus, if you are looking at text in the middle of a
1015 buffer and repeatedly call @code{scroll-down}, you will eventually see
1016 the beginning of the buffer.
1017
1018 Some people have urged that the opposite convention be used: they
1019 imagine that the window moves over text that remains in place. Then
1020 ``down'' commands would take you to the end of the buffer. This view is
1021 more consistent with the actual relationship between windows and the
1022 text in the buffer, but it is less like what the user sees. The
1023 position of a window on the terminal does not move, and short scrolling
1024 commands clearly move the text up or down on the screen. We have chosen
1025 names that fit the user's point of view.
1026
1027 The scrolling functions (aside from @code{scroll-other-window}) have
1028 unpredictable results if the current buffer is different from the buffer
1029 that is displayed in the selected window. @xref{Current Buffer}.
1030
1031 @deffn Command scroll-up &optional count
1032 This function scrolls the text in the selected window upward
1033 @var{count} lines. If @var{count} is negative, scrolling is actually
1034 downward.
1035
1036 If @var{count} is @code{nil} (or omitted), then the length of scroll
1037 is @code{next-screen-context-lines} lines less than the usable height of
1038 the window (not counting its mode line).
1039
1040 @code{scroll-up} returns @code{nil}.
1041 @end deffn
1042
1043 @deffn Command scroll-down &optional count
1044 This function scrolls the text in the selected window downward
1045 @var{count} lines. If @var{count} is negative, scrolling is actually
1046 upward.
1047
1048 If @var{count} is omitted or @code{nil}, then the length of the scroll
1049 is @code{next-screen-context-lines} lines less than the usable height of
1050 the window.
1051
1052 @code{scroll-down} returns @code{nil}.
1053 @end deffn
1054
1055 @deffn Command scroll-other-window &optional count
1056 This function scrolls the text in another window upward @var{count}
1057 lines. Negative values of @var{count}, or @code{nil}, are handled
1058 as in @code{scroll-up}.
1059
1060 The window that is scrolled is normally the one following the selected
1061 window in the cyclic ordering of windows---the window that
1062 @code{next-window} would return. @xref{Cyclic Window Ordering}.
1063
1064 You can specify a buffer to scroll with the variable
1065 @code{other-window-scroll-buffer}. When the selected window is the
1066 minibuffer, the next window is normally the one at the top left corner.
1067 You can specify a different window to scroll with the variable
1068 @code{minibuffer-scroll-window}. This variable has no effect when any
1069 other window is selected. @xref{Minibuffer Misc}.
1070
1071 When the minibuffer is active, it is the next window if the selected
1072 window is the one at the bottom right corner. In this case,
1073 @code{scroll-other-window} attempts to scroll the minibuffer. If the
1074 minibuffer contains just one line, it has nowhere to scroll to, so the
1075 line reappears after the echo area momentarily displays the message
1076 ``Beginning of buffer''.
1077 @end deffn
1078
1079 @c Emacs 19 feature
1080 @defvar other-window-scroll-buffer
1081 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
1082 which buffer to scroll.
1083 @end defvar
1084
1085 @defopt scroll-step
1086 This variable controls how scrolling is done automatically when point
1087 moves off the screen. If the value is zero, then redisplay scrolls the
1088 text to center point vertically in the window. If the value is a
1089 positive integer @var{n}, then redisplay brings point back on screen by
1090 scrolling @var{n} lines in either direction, if possible; otherwise, it
1091 centers point if possible. The default value is zero.
1092 @end defopt
1093
1094 @defopt next-screen-context-lines
1095 The value of this variable is the number of lines of continuity to
1096 retain when scrolling by full screens. For example, @code{scroll-up}
1097 with an argument of @code{nil} scrolls so that this many lines at the
1098 bottom of the window appear instead at the top. The default value is
1099 @code{2}.
1100 @end defopt
1101
1102 @deffn Command recenter &optional count
1103 @cindex centering point
1104 This function scrolls the selected window to put the text where point
1105 is located at a specified vertical position within the window.
1106
1107 If @var{count} is a nonnegative number, it puts the line containing
1108 point @var{count} lines down from the top of the window. If @var{count}
1109 is a negative number, then it counts upward from the bottom of the
1110 window, so that @minus{}1 stands for the last usable line in the window.
1111 If @var{count} is a non-@code{nil} list, then it stands for the line in
1112 the middle of the window.
1113
1114 If @var{count} is @code{nil}, @code{recenter} puts the line containing
1115 point in the middle of the window, then clears and redisplays the entire
1116 selected frame.
1117
1118 When @code{recenter} is called interactively, @var{count} is the raw
1119 prefix argument. Thus, typing @kbd{C-u} as the prefix sets the
1120 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
1121 @var{count} to 4, which positions the current line four lines from the
1122 top.
1123
1124 Typing @kbd{C-u 0 C-l} positions the current line at the top of the
1125 window. This action is so handy that some people bind the command to a
1126 function key. For example,
1127
1128 @example
1129 @group
1130 (defun line-to-top-of-window ()
1131 "Scroll current line to top of window.
1132 Replaces three keystroke sequence C-u 0 C-l."
1133 (interactive)
1134 (recenter 0))
1135
1136 (global-set-key "\C-cl" 'line-to-top-of-window)
1137 @end group
1138 @end example
1139 @end deffn
1140
1141 @node Horizontal Scrolling
1142 @section Horizontal Scrolling
1143 @cindex horizontal scrolling
1144
1145 Because we read English first from top to bottom and second from left
1146 to right, horizontal scrolling is not like vertical scrolling. Vertical
1147 scrolling involves selection of a contiguous portion of text to display.
1148 Horizontal scrolling causes part of each line to go off screen. The
1149 amount of horizontal scrolling is therefore specified as a number of
1150 columns rather than as a position in the buffer. It has nothing to do
1151 with the display-start position returned by @code{window-start}.
1152
1153 Usually, no horizontal scrolling is in effect; then the leftmost
1154 column is at the left edge of the window. In this state, scrolling to
1155 the right is meaningless, since there is no data to the left of the
1156 screen to be revealed by it; so this is not allowed. Scrolling to the
1157 left is allowed; it scrolls the first columns of text off the edge of
1158 the window and can reveal additional columns on the right that were
1159 truncated before. Once a window has a nonzero amount of leftward
1160 horizontal scrolling, you can scroll it back to the right, but only so
1161 far as to reduce the net horizontal scroll to zero. There is no limit
1162 to how far left you can scroll, but eventually all the text will
1163 disappear off the left edge.
1164
1165 @deffn Command scroll-left count
1166 This function scrolls the selected window @var{count} columns to the
1167 left (or to the right if @var{count} is negative). The return value is
1168 the total amount of leftward horizontal scrolling in effect after the
1169 change---just like the value returned by @code{window-hscroll}.
1170 @end deffn
1171
1172 @deffn Command scroll-right count
1173 This function scrolls the selected window @var{count} columns to the
1174 right (or to the left if @var{count} is negative). The return value is
1175 the total amount of leftward horizontal scrolling in effect after the
1176 change---just like the value returned by @code{window-hscroll}.
1177
1178 Once you scroll a window as far right as it can go, back to its normal
1179 position where the total leftward scrolling is zero, attempts to scroll
1180 any farther right have no effect.
1181 @end deffn
1182
1183 @defun window-hscroll &optional window
1184 This function returns the total leftward horizontal scrolling of
1185 @var{window}---the number of columns by which the text in @var{window}
1186 is scrolled left past the left margin.
1187
1188 The value is never negative. It is zero when no horizontal scrolling
1189 has been done in @var{window} (which is usually the case).
1190
1191 If @var{window} is @code{nil}, the selected window is used.
1192
1193 @example
1194 @group
1195 (window-hscroll)
1196 @result{} 0
1197 @end group
1198 @group
1199 (scroll-left 5)
1200 @result{} 5
1201 @end group
1202 @group
1203 (window-hscroll)
1204 @result{} 5
1205 @end group
1206 @end example
1207 @end defun
1208
1209 @defun set-window-hscroll window columns
1210 This function sets the number of columns from the left margin that
1211 @var{window} is scrolled to the value of @var{columns}. The argument
1212 @var{columns} should be zero or positive; if not, it is taken as zero.
1213
1214 The value returned is @var{columns}.
1215
1216 @example
1217 @group
1218 (set-window-hscroll (selected-window) 10)
1219 @result{} 10
1220 @end group
1221 @end example
1222 @end defun
1223
1224 Here is how you can determine whether a given position @var{position}
1225 is off the screen due to horizontal scrolling:
1226
1227 @example
1228 @group
1229 (save-excursion
1230 (goto-char @var{position})
1231 (and
1232 (>= (- (current-column) (window-hscroll @var{window})) 0)
1233 (< (- (current-column) (window-hscroll @var{window}))
1234 (window-width @var{window}))))
1235 @end group
1236 @end example
1237
1238 @node Size of Window
1239 @section The Size of a Window
1240 @cindex window size
1241 @cindex size of window
1242
1243 An Emacs window is rectangular, and its size information consists of
1244 the height (the number of lines) and the width (the number of character
1245 positions in each line). The mode line is included in the height. But
1246 the width does not count the scroll bar or the column of @samp{|}
1247 characters separates side-by-side windows.
1248
1249 The following three functions return size information about a window:
1250
1251 @defun window-height &optional window
1252 This function returns the number of lines in @var{window}, including
1253 its mode line. If @var{window} fills its entire frame, this is one less
1254 than the value of @code{frame-height} on that frame (since the last line
1255 is always reserved for the minibuffer).
1256
1257 If @var{window} is @code{nil}, the function uses the selected window.
1258
1259 @example
1260 @group
1261 (window-height)
1262 @result{} 23
1263 @end group
1264 @group
1265 (split-window-vertically)
1266 @result{} #<window 4 on windows.texi>
1267 @end group
1268 @group
1269 (window-height)
1270 @result{} 11
1271 @end group
1272 @end example
1273 @end defun
1274
1275 @defun window-width &optional window
1276 This function returns the number of columns in @var{window}. If
1277 @var{window} fills its entire frame, this is the same as the value of
1278 @code{frame-width} on that frame. The width does not include the
1279 window's scroll bar or the column of @samp{|} characters that separates
1280 side-by-side windows.
1281
1282 If @var{window} is @code{nil}, the function uses the selected window.
1283
1284 @example
1285 @group
1286 (window-width)
1287 @result{} 80
1288 @end group
1289 @end example
1290 @end defun
1291
1292 @defun window-edges &optional window
1293 This function returns a list of the edge coordinates of @var{window}.
1294 If @var{window} is @code{nil}, the selected window is used.
1295
1296 The order of the list is @code{(@var{left} @var{top} @var{right}
1297 @var{bottom})}, all elements relative to 0, 0 at the top left corner of
1298 the frame. The element @var{right} of the value is one more than the
1299 rightmost column used by @var{window}, and @var{bottom} is one more than
1300 the bottommost row used by @var{window} and its mode-line.
1301
1302 When you have side-by-side windows, the right edge value for a window
1303 with a neighbor on the right includes the width of the separator between
1304 the window and that neighbor. This separator may be a column of
1305 @samp{|} characters or it may be a scroll bar. Since the width of the
1306 window does not include this separator, the width does not equal the
1307 difference between the right and left edges in this case.
1308
1309 Here is the result obtained on a typical 24-line terminal with just one
1310 window:
1311
1312 @example
1313 @group
1314 (window-edges (selected-window))
1315 @result{} (0 0 80 23)
1316 @end group
1317 @end example
1318
1319 If @var{window} is at the upper left corner of its frame, @var{right}
1320 and @var{bottom} are the same as the values returned by
1321 @code{(window-width)} and @code{(window-height)} respectively, and
1322 @var{top} and @var{bottom} are zero. For example, the edges of the
1323 following window are @w{@samp{0 0 5 8}}. Assuming that the frame has
1324 more than 8 columns, the last column of the window (column 7) holds a
1325 border rather than text. The last row (row 4) holds the mode line,
1326 shown here with @samp{xxxxxxxxx}.
1327
1328 @example
1329 @group
1330 0
1331 _______
1332 0 | |
1333 | |
1334 | |
1335 | |
1336 xxxxxxxxx 4
1337
1338 7
1339 @end group
1340 @end example
1341
1342 When there are side-by-side windows, any window not at the right edge of
1343 its frame has a separator in its last column or columns. The separator
1344 counts as one or two columns in the width of the window. A window never
1345 includes a separator on its left, since that belongs to the window to
1346 the left.
1347
1348 In the following example, let's suppose that the frame is 7
1349 columns wide. Then the edges of the left window are @w{@samp{0 0 4 3}}
1350 and the edges of the right window are @w{@samp{4 0 7 3}}.
1351
1352 @example
1353 @group
1354 ___ ___
1355 | | |
1356 | | |
1357 xxxxxxxxx
1358
1359 0 34 7
1360 @end group
1361 @end example
1362 @end defun
1363
1364 @node Resizing Windows
1365 @section Changing the Size of a Window
1366 @cindex window resizing
1367 @cindex changing window size
1368 @cindex window size, changing
1369
1370 The window size functions fall into two classes: high-level commands
1371 that change the size of windows and low-level functions that access
1372 window size. Emacs does not permit overlapping windows or gaps between
1373 windows, so resizing one window affects other windows.
1374
1375 @deffn Command enlarge-window size &optional horizontal
1376 This function makes the selected window @var{size} lines bigger,
1377 stealing lines from neighboring windows. It takes the lines from one
1378 window at a time until that window is used up, then takes from another.
1379 If a window from which lines are stolen shrinks below
1380 @code{window-min-height} lines, that window disappears.
1381
1382 If @var{horizontal} is non-@code{nil}, this function makes
1383 @var{window} wider by @var{size} columns, stealing columns instead of
1384 lines. If a window from which columns are stolen shrinks below
1385 @code{window-min-width} columns, that window disappears.
1386
1387 If the window's frame is smaller than @var{size} lines (or columns),
1388 then the function makes the window occupy the entire height (or width)
1389 of the frame.
1390
1391 If @var{size} is negative, this function shrinks the window by
1392 @minus{}@var{size} lines or columns. If that makes the window smaller
1393 than the minimum size (@code{window-min-height} and
1394 @code{window-min-width}), @code{enlarge-window} deletes the window.
1395
1396 @code{enlarge-window} returns @code{nil}.
1397 @end deffn
1398
1399 @deffn Command enlarge-window-horizontally columns
1400 This function makes the selected window @var{columns} wider.
1401 It could be defined as follows:
1402
1403 @example
1404 @group
1405 (defun enlarge-window-horizontally (columns)
1406 (enlarge-window columns t))
1407 @end group
1408 @end example
1409 @end deffn
1410
1411 @deffn Command shrink-window size &optional horizontal
1412 This function is like @code{enlarge-window} but negates the argument
1413 @var{size}, making the selected window smaller by giving lines (or
1414 columns) to the other windows. If the window shrinks below
1415 @code{window-min-height} or @code{window-min-width}, then it disappears.
1416
1417 If @var{size} is negative, the window is enlarged by @minus{}@var{size}
1418 lines or columns.
1419 @end deffn
1420
1421 @deffn Command shrink-window-horizontally columns
1422 This function makes the selected window @var{columns} narrower.
1423 It could be defined as follows:
1424
1425 @example
1426 @group
1427 (defun shrink-window-horizontally (columns)
1428 (shrink-window columns t))
1429 @end group
1430 @end example
1431 @end deffn
1432
1433 @cindex minimum window size
1434 The following two variables constrain the window size changing
1435 functions to a minimum height and width.
1436
1437 @defopt window-min-height
1438 The value of this variable determines how short a window may become
1439 before it is automatically deleted. Making a window smaller than
1440 @code{window-min-height} automatically deletes it, and no window may be
1441 created shorter than this. The absolute minimum height is two (allowing
1442 one line for the mode line, and one line for the buffer display).
1443 Actions which change window sizes reset this variable to two if it is
1444 less than two. The default value is 4.
1445 @end defopt
1446
1447 @defopt window-min-width
1448 The value of this variable determines how narrow a window may become
1449 before it automatically deleted. Making a window smaller than
1450 @code{window-min-width} automatically deletes it, and no window may be
1451 created narrower than this. The absolute minimum width is one; any
1452 value below that is ignored. The default value is 10.
1453 @end defopt
1454
1455 @node Coordinates and Windows
1456 @section Coordinates and Windows
1457
1458 This section describes how to compare screen coordinates with windows.
1459
1460 @defun window-at x y &optional frame
1461 This function returns the window containing the specified cursor
1462 position in the frame @var{frame}. The coordinates @var{x} and @var{y}
1463 are measured in characters and count from the top left corner of the
1464 frame. If they are out of range, @code{window-at} returns @code{nil}.
1465
1466 If you omit @var{frame}, the selected frame is used.
1467 @end defun
1468
1469 @defun coordinates-in-window-p coordinates window
1470 This function checks whether a particular frame position falls within
1471 the window @var{window}.
1472
1473 The argument @var{coordinates} is a cons cell of this form:
1474
1475 @example
1476 (@var{x} . @var{y})
1477 @end example
1478
1479 @noindent
1480 The coordinates @var{x} and @var{y} are measured in characters, and
1481 count from the top left corner of the screen or frame.
1482
1483 The value of @code{coordinates-in-window-p} is non-@code{nil} if the
1484 coordinates are inside @var{window}. The value also indicates what part
1485 of the window the position is in, as follows:
1486
1487 @table @code
1488 @item (@var{relx} . @var{rely})
1489 The coordinates are inside @var{window}. The numbers @var{relx} and
1490 @var{rely} are the equivalent window-relative coordinates for the
1491 specified position, counting from 0 at the top left corner of the
1492 window.
1493
1494 @item mode-line
1495 The coordinates are in the mode line of @var{window}.
1496
1497 @item vertical-split
1498 The coordinates are in the vertical line between @var{window} and its
1499 neighbor to the right. This value occurs only if the window doesn't
1500 have a scroll bar; positions in a scroll bar are considered outside the
1501 window.
1502
1503 @item nil
1504 The coordinates are not in any part of @var{window}.
1505 @end table
1506
1507 The function @code{coordinates-in-window-p} does not require a frame as
1508 argument because it always uses the frame that @var{window} is on.
1509 @end defun
1510
1511 @node Window Configurations
1512 @section Window Configurations
1513 @cindex window configurations
1514 @cindex saving window information
1515
1516 A @dfn{window configuration} records the entire layout of a
1517 frame---all windows, their sizes, which buffers they contain, what part
1518 of each buffer is displayed, and the values of point and the mark. You
1519 can bring back an entire previous layout by restoring a window
1520 configuration previously saved.
1521
1522 If you want to record all frames instead of just one, use a frame
1523 configuration instead of a window configuration. @xref{Frame
1524 Configurations}.
1525
1526 @defun current-window-configuration
1527 This function returns a new object representing Emacs's current window
1528 configuration, namely the number of windows, their sizes and current
1529 buffers, which window is the selected window, and for each window the
1530 displayed buffer, the display-start position, and the positions of point
1531 and the mark. An exception is made for point in the current buffer,
1532 whose value is not saved.
1533 @end defun
1534
1535 @defun set-window-configuration configuration
1536 This function restores the configuration of Emacs's windows and
1537 buffers to the state specified by @var{configuration}. The argument
1538 @var{configuration} must be a value that was previously returned by
1539 @code{current-window-configuration}.
1540
1541 Here is a way of using this function to get the same effect
1542 as @code{save-window-excursion}:
1543
1544 @example
1545 @group
1546 (let ((config (current-window-configuration)))
1547 (unwind-protect
1548 (progn (split-window-vertically nil)
1549 @dots{})
1550 (set-window-configuration config)))
1551 @end group
1552 @end example
1553 @end defun
1554
1555 @defspec save-window-excursion forms@dots{}
1556 This special form records the window configuration, executes @var{forms}
1557 in sequence, then restores the earlier window configuration. The window
1558 configuration includes the value of point and the portion of the buffer
1559 which is visible. It also includes the choice of selected window.
1560 However, it does not include the value of point in the current buffer;
1561 use @code{save-excursion} if you wish to preserve that.
1562
1563 The return value is the value of the final form in @var{forms}.
1564 For example:
1565
1566 @example
1567 @group
1568 (split-window)
1569 @result{} #<window 25 on control.texi>
1570 @end group
1571 @group
1572 (setq w (selected-window))
1573 @result{} #<window 19 on control.texi>
1574 @end group
1575 @group
1576 (save-window-excursion
1577 (delete-other-windows w)
1578 (switch-to-buffer "foo")
1579 'do-something)
1580 @result{} do-something
1581 ;; @r{The screen is now split again.}
1582 @end group
1583 @end example
1584 @end defspec
1585
1586 @defun window-configuration-p object
1587 This function returns @code{t} if @var{object} is a window configuration.
1588 @end defun
1589
1590 Primitives to look inside of window configurations would make sense,
1591 but none are implemented. It is not clear they are useful enough to be
1592 worth implementing.