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
9 This chapter describes most of the functions and variables related to
10 Emacs windows. See @ref{Display}, for information on how text is
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 * Scrolling Hooks:: Hooks that run when you scroll a window.
28 * Horizontal Scrolling:: Moving text sideways on the window.
29 * Size of Window:: Accessing the size of a window.
30 * Resizing Windows:: Changing the size of a window.
31 * Coordinates and Windows:: Converting coordinates to windows.
32 * Window Configurations:: Saving and restoring the state of the screen.
36 @section Basic Concepts of Emacs Windows
38 @cindex selected window
40 A @dfn{window} in Emacs is the physical area of the screen in which a
41 buffer is displayed. The term is also used to refer to a Lisp object that
42 represents that screen area in Emacs Lisp. It should be
43 clear from the context which is meant.
45 Emacs groups windows into frames. A frame represents an area of
46 screen available for Emacs to use. Each frame always contains at least
47 one window, but you can subdivide it vertically or horizontally into
48 multiple nonoverlapping Emacs windows.
50 In each frame, at any time, one and only one window is designated as
51 @dfn{selected within the frame}. The frame's cursor appears in that
52 window. At ant time, one frame is the selected frame; and the window
53 selected within that frame is @dfn{the selected window}. The selected
54 window's buffer is usually the current buffer (except when
55 @code{set-buffer} has been used). @xref{Current Buffer}.
57 For practical purposes, a window exists only while it is displayed in
58 a frame. Once removed from the frame, the window is effectively deleted
59 and should not be used, @emph{even though there may still be references
60 to it} from other Lisp objects. Restoring a saved window configuration
61 is the only way for a window no longer on the screen to come back to
62 life. (@xref{Deleting Windows}.)
64 Each window has the following attributes:
77 window edges with respect to the screen or frame
80 the buffer it displays
83 position within the buffer at the upper left of the window
86 amount of horizontal scrolling, in columns
95 how recently the window was selected
98 @cindex multiple windows
99 Users create multiple windows so they can look at several buffers at
100 once. Lisp libraries use multiple windows for a variety of reasons, but
101 most often to display related information. In Rmail, for example, you
102 can move through a summary buffer in one window while the other window
103 shows messages one at a time as they are reached.
105 The meaning of ``window'' in Emacs is similar to what it means in the
106 context of general-purpose window systems such as X, but not identical.
107 The X Window System places X windows on the screen; Emacs uses one or
108 more X windows as frames, and subdivides them into
109 Emacs windows. When you use Emacs on a character-only terminal, Emacs
110 treats the whole terminal screen as one frame.
112 @cindex terminal screen
113 @cindex screen of terminal
114 @cindex tiled windows
115 Most window systems support arbitrarily located overlapping windows.
116 In contrast, Emacs windows are @dfn{tiled}; they never overlap, and
117 together they fill the whole screen or frame. Because of the way
118 in which Emacs creates new windows and resizes them, you can't create
119 every conceivable tiling of windows on an Emacs frame. @xref{Splitting
120 Windows}, and @ref{Size of Window}.
122 @xref{Display}, for information on how the contents of the
123 window's buffer are displayed in the window.
125 @defun windowp object
126 This function returns @code{t} if @var{object} is a window.
129 @node Splitting Windows
130 @section Splitting Windows
131 @cindex splitting windows
132 @cindex window splitting
134 The functions described here are the primitives used to split a window
135 into two windows. Two higher level functions sometimes split a window,
136 but not always: @code{pop-to-buffer} and @code{display-buffer}
137 (@pxref{Displaying Buffers}).
139 The functions described here do not accept a buffer as an argument.
140 The two ``halves'' of the split window initially display the same buffer
141 previously visible in the window that was split.
143 @deffn Command split-window &optional window size horizontal
144 This function splits @var{window} into two windows. The original
145 window @var{window} remains the selected window, but occupies only
146 part of its former screen area. The rest is occupied by a newly created
147 window which is returned as the value of this function.
149 If @var{horizontal} is non-@code{nil}, then @var{window} splits into
150 two side by side windows. The original window @var{window} keeps the
151 leftmost @var{size} columns, and gives the rest of the columns to the
152 new window. Otherwise, it splits into windows one above the other, and
153 @var{window} keeps the upper @var{size} lines and gives the rest of the
154 lines to the new window. The original window is therefore the
155 left-hand or upper of the two, and the new window is the right-hand or
158 If @var{window} is omitted or @code{nil}, then the selected window is
159 split. If @var{size} is omitted or @code{nil}, then @var{window} is
160 divided evenly into two parts. (If there is an odd line, it is
161 allocated to the new window.) When @code{split-window} is called
162 interactively, all its arguments are @code{nil}.
164 The following example starts with one window on a screen that is 50
165 lines high by 80 columns wide; then the window is split.
169 (setq w (selected-window))
170 @result{} #<window 8 on windows.texi>
171 (window-edges) ; @r{Edges in order:}
172 @result{} (0 0 80 50) ; @r{left--top--right--bottom}
176 ;; @r{Returns window created}
177 (setq w2 (split-window w 15))
178 @result{} #<window 28 on windows.texi>
182 @result{} (0 15 80 50) ; @r{Bottom window;}
187 @result{} (0 0 80 15) ; @r{Top window}
191 The screen looks like this:
207 Next, the top window is split horizontally:
211 (setq w3 (split-window w 35 t))
212 @result{} #<window 32 on windows.texi>
216 @result{} (35 0 80 15) ; @r{Left edge at column 35}
220 @result{} (0 0 35 15) ; @r{Right edge at column 35}
224 @result{} (0 15 80 50) ; @r{Bottom window unchanged}
229 Now, the screen looks like this:
246 Normally, Emacs indicates the border between two side-by-side windows
247 with a scroll bar (@pxref{X Frame Parameters,Scroll Bars}) or @samp{|}
248 characters. The display table can specify alternative border
249 characters; see @ref{Display Tables}.
252 @deffn Command split-window-vertically size
253 This function splits the selected window into two windows, one above
254 the other, leaving the selected window with @var{size} lines.
256 This function is simply an interface to @code{split-windows}.
257 Here is the complete function definition for it:
261 (defun split-window-vertically (&optional arg)
262 "Split current window into two windows, one above the other."
264 (split-window nil (and arg (prefix-numeric-value arg))))
269 @deffn Command split-window-horizontally size
270 This function splits the selected window into two windows
271 side-by-side, leaving the selected window with @var{size} columns.
273 This function is simply an interface to @code{split-windows}. Here is
274 the complete definition for @code{split-window-horizontally} (except for
275 part of the documentation string):
279 (defun split-window-horizontally (&optional arg)
280 "Split selected window into two windows, side by side..."
282 (split-window nil (and arg (prefix-numeric-value arg)) t))
287 @defun one-window-p &optional no-mini all-frames
288 This function returns non-@code{nil} if there is only one window. The
289 argument @var{no-mini}, if non-@code{nil}, means don't count the
290 minibuffer even if it is active; otherwise, the minibuffer window is
291 included, if active, in the total number of windows, which is compared
294 The argument @var{all-frames} specifies which frames to consider. Here
295 are the possible values and their meanings:
299 Count the windows in the selected frame, plus the minibuffer used
300 by that frame even if it lies in some other frame.
303 Count all windows in all existing frames.
306 Count all windows in all visible frames.
309 Count all windows in all visible or iconified frames.
312 Count precisely the windows in the selected frame, and no others.
316 @node Deleting Windows
317 @section Deleting Windows
318 @cindex deleting windows
320 A window remains visible on its frame unless you @dfn{delete} it by
321 calling certain functions that delete windows. A deleted window cannot
322 appear on the screen, but continues to exist as a Lisp object until
323 there are no references to it. There is no way to cancel the deletion
324 of a window aside from restoring a saved window configuration
325 (@pxref{Window Configurations}). Restoring a window configuration also
326 deletes any windows that aren't part of that configuration.
328 When you delete a window, the space it took up is given to one
329 adjacent sibling. (In Emacs version 18, the space was divided evenly
330 among all the siblings.)
333 @defun window-live-p window
334 This function returns @code{nil} if @var{window} is deleted, and
337 @strong{Warning:} Erroneous information or fatal errors may result from
338 using a deleted window as if it were live.
341 @deffn Command delete-window &optional window
342 This function removes @var{window} from the display. If @var{window}
343 is omitted, then the selected window is deleted. An error is signaled
344 if there is only one window when @code{delete-window} is called.
346 This function returns @code{nil}.
348 When @code{delete-window} is called interactively, @var{window}
349 defaults to the selected window.
352 @deffn Command delete-other-windows &optional window
353 This function makes @var{window} the only window on its frame, by
354 deleting the other windows in that frame. If @var{window} is omitted or
355 @code{nil}, then the selected window is used by default.
357 The result is @code{nil}.
360 @deffn Command delete-windows-on buffer &optional frame
361 This function deletes all windows showing @var{buffer}. If there are
362 no windows showing @var{buffer}, it does nothing.
364 @code{delete-windows-on} operates frame by frame. If a frame has
365 several windows showing different buffers, then those showing
366 @var{buffer} are removed, and the others expand to fill the space. If
367 all windows in some frame are showing @var{buffer} (including the case
368 where there is only one window), then the frame reverts to having a
369 single window showing another buffer chosen with @code{other-buffer}.
370 @xref{The Buffer List}.
372 The argument @var{frame} controls which frames to operate on:
376 If it is @code{nil}, operate on the selected frame.
378 If it is @code{t}, operate on all frames.
380 If it is @code{visible}, operate on all visible frames.
382 If it is 0, operate on all visible or iconified frames.
384 If it is a frame, operate on that frame.
387 This function always returns @code{nil}.
390 @node Selecting Windows
391 @section Selecting Windows
392 @cindex selecting windows
394 When a window is selected, the buffer in the window becomes the current
395 buffer, and the cursor will appear in it.
397 @defun selected-window
398 This function returns the selected window. This is the window in
399 which the cursor appears and to which many commands apply.
402 @defun select-window window
403 This function makes @var{window} the selected window. The cursor then
404 appears in @var{window} (on redisplay). The buffer being displayed in
405 @var{window} is immediately designated the current buffer.
407 The return value is @var{window}.
411 (setq w (next-window))
413 @result{} #<window 65 on windows.texi>
418 @defmac save-selected-window forms@dots{}
419 This macro records the selected window, executes @var{forms}
420 in sequence, then restores the earlier selected window.
422 This macro does not save or restore anything about the sizes, arrangement
423 or contents of windows; therefore, if the @var{forms} change them,
426 Each frame, at any time, has a window selected within the frame. This
427 macro only saves @emph{the} selected window; it does not save anything
428 about other frames. If the @var{forms} select some other frame and
429 alter the window selected within it, the change persists.
432 @cindex finding windows
433 The following functions choose one of the windows on the screen,
434 offering various criteria for the choice.
436 @defun get-lru-window &optional frame
437 This function returns the window least recently ``used'' (that is,
438 selected). The selected window is always the most recently used window.
440 The selected window can be the least recently used window if it is the
441 only window. A newly created window becomes the least recently used
442 window until it is selected. A minibuffer window is never a candidate.
444 The argument @var{frame} controls which windows are considered.
448 If it is @code{nil}, consider windows on the selected frame.
450 If it is @code{t}, consider windows on all frames.
452 If it is @code{visible}, consider windows on all visible frames.
454 If it is 0, consider windows on all visible or iconified frames.
456 If it is a frame, consider windows on that frame.
460 @defun get-largest-window &optional frame
461 This function returns the window with the largest area (height times
462 width). If there are no side-by-side windows, then this is the window
463 with the most lines. A minibuffer window is never a candidate.
465 If there are two windows of the same size, then the function returns
466 the window that is first in the cyclic ordering of windows (see
467 following section), starting from the selected window.
469 The argument @var{frame} controls which set of windows are
470 considered. See @code{get-lru-window}, above.
473 @node Cyclic Window Ordering
474 @comment node-name, next, previous, up
475 @section Cyclic Ordering of Windows
476 @cindex cyclic ordering of windows
477 @cindex ordering of windows, cyclic
478 @cindex window ordering, cyclic
480 When you use the command @kbd{C-x o} (@code{other-window}) to select
481 the next window, it moves through all the windows on the screen in a
482 specific cyclic order. For any given configuration of windows, this
483 order never varies. It is called the @dfn{cyclic ordering of windows}.
485 This ordering generally goes from top to bottom, and from left to
486 right. But it may go down first or go right first, depending on the
487 order in which the windows were split.
489 If the first split was vertical (into windows one above each other),
490 and then the subwindows were split horizontally, then the ordering is
491 left to right in the top of the frame, and then left to right in the
492 next lower part of the frame, and so on. If the first split was
493 horizontal, the ordering is top to bottom in the left part, and so on.
494 In general, within each set of siblings at any level in the window tree,
495 the order is left to right, or top to bottom.
497 @defun next-window &optional window minibuf all-frames
498 @cindex minibuffer window
499 This function returns the window following @var{window} in the cyclic
500 ordering of windows. This is the window that @kbd{C-x o} would select
501 if typed when @var{window} is selected. If @var{window} is the only
502 window visible, then this function returns @var{window}. If omitted,
503 @var{window} defaults to the selected window.
505 The value of the argument @var{minibuf} determines whether the
506 minibuffer is included in the window order. Normally, when
507 @var{minibuf} is @code{nil}, the minibuffer is included if it is
508 currently active; this is the behavior of @kbd{C-x o}. (The minibuffer
509 window is active while the minibuffer is in use. @xref{Minibuffers}.)
511 If @var{minibuf} is @code{t}, then the cyclic ordering includes the
512 minibuffer window even if it is not active.
514 If @var{minibuf} is neither @code{t} nor @code{nil}, then the minibuffer
515 window is not included even if it is active.
517 The argument @var{all-frames} specifies which frames to consider. Here
518 are the possible values and their meanings:
522 Consider all the windows in @var{window}'s frame, plus the minibuffer
523 used by that frame even if it lies in some other frame.
526 Consider all windows in all existing frames.
529 Consider all windows in all visible frames. (To get useful results, you
530 must ensure @var{window} is in a visible frame.)
533 Consider all windows in all visible or iconified frames.
536 Consider precisely the windows in @var{window}'s frame, and no others.
539 This example assumes there are two windows, both displaying the
540 buffer @samp{windows.texi}:
545 @result{} #<window 56 on windows.texi>
548 (next-window (selected-window))
549 @result{} #<window 52 on windows.texi>
552 (next-window (next-window (selected-window)))
553 @result{} #<window 56 on windows.texi>
558 @defun previous-window &optional window minibuf all-frames
559 This function returns the window preceding @var{window} in the cyclic
560 ordering of windows. The other arguments specify which windows to
561 include in the cycle, as in @code{next-window}.
564 @deffn Command other-window count
565 This function selects the @var{count}th following window in the cyclic
566 order. If count is negative, then it selects the @minus{}@var{count}th
567 preceding window. It returns @code{nil}.
569 In an interactive call, @var{count} is the numeric prefix argument.
573 @defun walk-windows proc &optional minibuf all-frames
574 This function cycles through all windows, calling @code{proc}
575 once for each window with the window as its sole argument.
577 The optional arguments @var{minibuf} and @var{all-frames} specify the
578 set of windows to include in the scan. See @code{next-window}, above,
582 @node Buffers and Windows
583 @section Buffers and Windows
584 @cindex examining windows
585 @cindex windows, controlling precisely
586 @cindex buffers, controlled in windows
588 This section describes low-level functions to examine windows or to
589 display buffers in windows in a precisely controlled fashion.
591 See the following section for
594 @xref{Displaying Buffers}, for
596 related functions that find a window to use and specify a buffer for it.
597 The functions described there are easier to use than these, but they
598 employ heuristics in choosing or creating a window; use these functions
599 when you need complete control.
601 @defun set-window-buffer window buffer-or-name
602 This function makes @var{window} display @var{buffer-or-name} as its
603 contents. It returns @code{nil}.
607 (set-window-buffer (selected-window) "foo")
613 @defun window-buffer &optional window
614 This function returns the buffer that @var{window} is displaying. If
615 @var{window} is omitted, this function returns the buffer for the
621 @result{} #<buffer windows.texi>
626 @defun get-buffer-window buffer-or-name &optional all-frames
627 This function returns a window currently displaying
628 @var{buffer-or-name}, or @code{nil} if there is none. If there are
629 several such windows, then the function returns the first one in the
630 cyclic ordering of windows, starting from the selected window.
631 @xref{Cyclic Window Ordering}.
633 The argument @var{all-frames} controls which windows to consider.
637 If it is @code{nil}, consider windows on the selected frame.
639 If it is @code{t}, consider windows on all frames.
641 If it is @code{visible}, consider windows on all visible frames.
643 If it is 0, consider windows on all visible or iconified frames.
645 If it is a frame, consider windows on that frame.
649 @defun get-buffer-window-list buffer-or-name &optional minibuf all-frames
650 This function returns a list of all the windows currently displaying
651 @var{buffer-or-name}.
653 The two optional arguments work like the optional arguments of
654 @code{next-window} (@pxref{Cyclic Window Ordering}); they are @emph{not}
655 like the single optional argument of @code{get-buffer-window}. Perhaps
656 we should change @code{get-buffer-window} in the future to make it
657 compatible with the other functions.
659 The argument @var{all-frames} controls which windows to consider.
663 If it is @code{nil}, consider windows on the selected frame.
665 If it is @code{t}, consider windows on all frames.
667 If it is @code{visible}, consider windows on all visible frames.
669 If it is 0, consider windows on all visible or iconified frames.
671 If it is a frame, consider windows on that frame.
675 @node Displaying Buffers
676 @section Displaying Buffers in Windows
677 @cindex switching to a buffer
678 @cindex displaying a buffer
680 In this section we describe convenient functions that choose a window
681 automatically and use it to display a specified buffer. These functions
682 can also split an existing window in certain circumstances. We also
683 describe variables that parameterize the heuristics used for choosing a
686 See the preceding section for
689 @xref{Buffers and Windows}, for
691 low-level functions that give you more precise control.
693 Do not use the functions in this section in order to make a buffer
694 current so that a Lisp program can access or modify it; they are too
695 drastic for that purpose, since they change the display of buffers in
696 windows, which is gratuitous and will surprise the user. Instead, use
697 @code{set-buffer} (@pxref{Current Buffer}) and @code{save-excursion}
698 (@pxref{Excursions}), which designate buffers as current for programmed
699 access without affecting the display of buffers in windows.
701 @deffn Command switch-to-buffer buffer-or-name &optional norecord
702 This function makes @var{buffer-or-name} the current buffer, and also
703 displays the buffer in the selected window. This means that a human can
704 see the buffer and subsequent keyboard commands will apply to it.
705 Contrast this with @code{set-buffer}, which makes @var{buffer-or-name}
706 the current buffer but does not display it in the selected window.
707 @xref{Current Buffer}.
709 If @var{buffer-or-name} does not identify an existing buffer, then a new
710 buffer by that name is created. The major mode for the new buffer is
711 set according to the variable @code{default-major-mode}. @xref{Auto
714 Normally the specified buffer is put at the front of the buffer list.
715 This affects the operation of @code{other-buffer}. However, if
716 @var{norecord} is non-@code{nil}, this is not done. @xref{The Buffer
719 The @code{switch-to-buffer} function is often used interactively, as
720 the binding of @kbd{C-x b}. It is also used frequently in programs. It
721 always returns @code{nil}.
724 @deffn Command switch-to-buffer-other-window buffer-or-name
725 This function makes @var{buffer-or-name} the current buffer and
726 displays it in a window not currently selected. It then selects that
727 window. The handling of the buffer is the same as in
728 @code{switch-to-buffer}.
730 The currently selected window is absolutely never used to do the job.
731 If it is the only window, then it is split to make a distinct window for
732 this purpose. If the selected window is already displaying the buffer,
733 then it continues to do so, but another window is nonetheless found to
734 display it in as well.
737 @defun pop-to-buffer buffer-or-name &optional other-window
738 This function makes @var{buffer-or-name} the current buffer and
739 switches to it in some window, preferably not the window previously
740 selected. The ``popped-to'' window becomes the selected window within
743 If the variable @code{pop-up-frames} is non-@code{nil},
744 @code{pop-to-buffer} looks for a window in any visible frame already
745 displaying the buffer; if there is one, it returns that window and makes
746 it be selected within its frame. If there is none, it creates a new
747 frame and displays the buffer in it.
749 If @code{pop-up-frames} is @code{nil}, then @code{pop-to-buffer}
750 operates entirely within the selected frame. (If the selected frame has
751 just a minibuffer, @code{pop-to-buffer} operates within the most
752 recently selected frame that was not just a minibuffer.)
754 If the variable @code{pop-up-windows} is non-@code{nil}, windows may
755 be split to create a new window that is different from the original
756 window. For details, see @ref{Choosing Window}.
758 If @var{other-window} is non-@code{nil}, @code{pop-to-buffer} finds or
759 creates another window even if @var{buffer-or-name} is already visible
760 in the selected window. Thus @var{buffer-or-name} could end up
761 displayed in two windows. On the other hand, if @var{buffer-or-name} is
762 already displayed in the selected window and @var{other-window} is
763 @code{nil}, then the selected window is considered sufficient display
764 for @var{buffer-or-name}, so that nothing needs to be done.
766 All the variables that affect @code{display-buffer} affect
767 @code{pop-to-buffer} as well. @xref{Choosing Window}.
769 If @var{buffer-or-name} is a string that does not name an existing
770 buffer, a buffer by that name is created. The major mode for the new
771 buffer is set according to the variable @code{default-major-mode}.
772 @xref{Auto Major Mode}.
775 @deffn Command replace-buffer-in-windows buffer
776 This function replaces @var{buffer} with some other buffer in all
777 windows displaying it. The other buffer used is chosen with
778 @code{other-buffer}. In the usual applications of this function, you
779 don't care which other buffer is used; you just want to make sure that
780 @var{buffer} is no longer displayed.
782 This function returns @code{nil}.
785 @node Choosing Window
786 @section Choosing a Window for Display
788 This section describes the basic facility that chooses a window to
789 display a buffer in---@code{display-buffer}. All the higher-level
790 functions and commands use this subroutine. Here we describe how to use
791 @code{display-buffer} and how to customize it.
793 @deffn Command display-buffer buffer-or-name &optional not-this-window
794 This command makes @var{buffer-or-name} appear in some window, like
795 @code{pop-to-buffer}, but it does not select that window and does not
796 make the buffer current. The identity of the selected window is
797 unaltered by this function.
799 If @var{not-this-window} is non-@code{nil}, it means to display the
800 specified buffer in a window other than the selected one, even if it is
801 already on display in the selected window. This can cause the buffer to
802 appear in two windows at once. Otherwise, if @var{buffer-or-name} is
803 already being displayed in any window, that is good enough, so this
804 function does nothing.
806 @code{display-buffer} returns the window chosen to display
807 @var{buffer-or-name}.
809 Precisely how @code{display-buffer} finds or creates a window depends on
810 the variables described below.
813 @defopt pop-up-windows
814 This variable controls whether @code{display-buffer} makes new windows.
815 If it is non-@code{nil} and there is only one window, then that window
816 is split. If it is @code{nil}, then @code{display-buffer} does not
817 split the single window, but uses it whole.
820 @defopt split-height-threshold
821 This variable determines when @code{display-buffer} may split a window,
822 if there are multiple windows. @code{display-buffer} always splits the
823 largest window if it has at least this many lines. If the largest
824 window is not this tall, it is split only if it is the sole window and
825 @code{pop-up-windows} is non-@code{nil}.
829 @defopt pop-up-frames
830 This variable controls whether @code{display-buffer} makes new frames.
831 If it is non-@code{nil}, @code{display-buffer} looks for an existing
832 window already displaying the desired buffer, on any visible frame. If
833 it finds one, it returns that window. Otherwise it makes a new frame.
834 The variables @code{pop-up-windows} and @code{split-height-threshold} do
835 not matter if @code{pop-up-frames} is non-@code{nil}.
837 If @code{pop-up-frames} is @code{nil}, then @code{display-buffer} either
838 splits a window or reuses one.
840 @xref{Frames}, for more information.
844 @defvar pop-up-frame-function
845 This variable specifies how to make a new frame if @code{pop-up-frames}
848 Its value should be a function of no arguments. When
849 @code{display-buffer} makes a new frame, it does so by calling that
850 function, which should return a frame. The default value of the
851 variable is a function that creates a frame using parameters from
852 @code{pop-up-frame-alist}.
855 @defvar pop-up-frame-alist
856 This variable holds an alist specifying frame parameters used when
857 @code{display-buffer} makes a new frame. @xref{Frame Parameters}, for
858 more information about frame parameters.
861 @defvar special-display-buffer-names
862 A list of buffer names for buffers that should be displayed specially.
863 If the buffer's name is in this list, @code{display-buffer} handles the
866 By default, special display means to give the buffer a dedicated frame.
868 If an element is a list, instead of a string, then the @sc{car} of the
869 list is the buffer name, and the rest of the list says how to create the
870 frame. There are two possibilities for the rest of the list. It can be
871 an alist, specifying frame parameters, or it can contain a function and
872 arguments to give to it. (The function's first argument is always the
873 buffer to be displayed; the arguments from the list come after that.)
876 @defvar special-display-regexps
877 A list of regular expressions that specify buffers that should be
878 displayed specially. If the buffer's name matches any of the regular
879 expressions in this list, @code{display-buffer} handles the buffer
882 By default, special display means to give the buffer a dedicated frame.
884 If an element is a list, instead of a string, then the @sc{car} of the
885 list is the regular expression, and the rest of the list says how to
886 create the frame. See above, under @code{special-display-buffer-names}.
889 @defvar special-display-function
890 This variable holds the function to call to display a buffer specially.
891 It receives the buffer as an argument, and should return the window in
892 which it is displayed.
894 The default value of this variable is
895 @code{special-display-popup-frame}.
898 @defun special-display-popup-frame buffer
899 This function makes @var{buffer} visible in a frame of its own. If
900 @var{buffer} is already displayed in a window in some frame, it makes
901 the frame visible and raises it, to use that window. Otherwise, it
902 creates a frame that will be dedicated to @var{buffer}.
904 This function uses an existing window displaying @var{buffer} whether or
905 not it is in a frame of its own; but if you set up the above variables
906 in your init file, before @var{buffer} was created, then presumably the
907 window was previously made by this function.
910 @defopt special-display-frame-alist
911 This variable holds frame parameters for
912 @code{special-display-popup-frame} to use when it creates a frame.
915 @defopt same-window-buffer-names
916 A list of buffer names for buffers that should be displayed in the
917 selected window. If the buffer's name is in this list,
918 @code{display-buffer} handles the buffer by switching to it in the
922 @defopt same-window-regexps
923 A list of regular expressions that specify buffers that should be
924 displayed in the selected window. If the buffer's name matches any of
925 the regular expressions in this list, @code{display-buffer} handles the
926 buffer by switching to it in the selected window.
930 @defvar display-buffer-function
931 This variable is the most flexible way to customize the behavior of
932 @code{display-buffer}. If it is non-@code{nil}, it should be a function
933 that @code{display-buffer} calls to do the work. The function should
934 accept two arguments, the same two arguments that @code{display-buffer}
935 received. It should choose or create a window, display the specified
936 buffer, and then return the window.
938 This hook takes precedence over all the other options and hooks
943 @cindex dedicated window
944 A window can be marked as ``dedicated'' to its buffer. Then
945 @code{display-buffer} does not try to use that window.
947 @defun window-dedicated-p window
948 This function returns @code{t} if @var{window} is marked as dedicated;
949 otherwise @code{nil}.
952 @defun set-window-dedicated-p window flag
953 This function marks @var{window} as dedicated if @var{flag} is
954 non-@code{nil}, and nondedicated otherwise.
958 @section Windows and Point
959 @cindex window position
961 @cindex position in window
962 @cindex point in window
964 Each window has its own value of point, independent of the value of
965 point in other windows displaying the same buffer. This makes it useful
966 to have multiple windows showing one buffer.
970 The window point is established when a window is first created; it is
971 initialized from the buffer's point, or from the window point of another
972 window opened on the buffer if such a window exists.
975 Selecting a window sets the value of point in its buffer to the window's
976 value of point. Conversely, deselecting a window sets the window's
977 value of point from that of the buffer. Thus, when you switch between
978 windows that display a given buffer, the point value for the selected
979 window is in effect in the buffer, while the point values for the other
980 windows are stored in those windows.
983 As long as the selected window displays the current buffer, the window's
984 point and the buffer's point always move together; they remain equal.
987 @xref{Positions}, for more details on buffer positions.
990 As far as the user is concerned, point is where the cursor is, and
991 when the user switches to another buffer, the cursor jumps to the
992 position of point in that buffer.
994 @defun window-point window
995 This function returns the current position of point in @var{window}.
996 For a nonselected window, this is the value point would have (in that
997 window's buffer) if that window were selected.
999 When @var{window} is the selected window and its buffer is also the
1000 current buffer, the value returned is the same as point in that buffer.
1002 Strictly speaking, it would be more correct to return the
1003 ``top-level'' value of point, outside of any @code{save-excursion}
1004 forms. But that value is hard to find.
1007 @defun set-window-point window position
1008 This function positions point in @var{window} at position
1009 @var{position} in @var{window}'s buffer.
1013 @section The Window Start Position
1015 Each window contains a marker used to keep track of a buffer position
1016 that specifies where in the buffer display should start. This position
1017 is called the @dfn{display-start} position of the window (or just the
1018 @dfn{start}). The character after this position is the one that appears
1019 at the upper left corner of the window. It is usually, but not
1020 inevitably, at the beginning of a text line.
1022 @defun window-start &optional window
1023 @cindex window top line
1024 This function returns the display-start position of window
1025 @var{window}. If @var{window} is @code{nil}, the selected window is
1035 When you create a window, or display a different buffer in it, the
1036 display-start position is set to a display-start position recently used
1037 for the same buffer, or 1 if the buffer doesn't have any.
1039 Redisplay updates the window-start position (if you have not specified
1040 it explicitly since the previous redisplay) so that point appears on the
1041 screen. Nothing except redisplay automatically changes the window-start
1042 position; if you move point, do not expect the window-start position to
1043 change in response until after the next redisplay.
1045 For a realistic example of using @code{window-start}, see the
1046 description of @code{count-lines} in @ref{Text Lines}.
1049 @defun window-end &optional window
1050 This function returns the position of the end of the display in window
1051 @var{window}. If @var{window} is @code{nil}, the selected window is
1054 Simply changing the buffer text or moving point does not update the
1055 value that @code{window-end} returns. The value is updated only when
1056 Emacs redisplays and redisplay actually finishes.
1058 If the last redisplay of @var{window} was preempted, and did not finish,
1059 Emacs does not know the position of the end of display in that window.
1060 In that case, this function returns a value that is not correct. In a
1061 future version, @code{window-end} will return @code{nil} in that case.
1063 in that case, this function returns @code{nil}. You can compute where
1064 the end of the window @emph{would} have been, if redisplay had finished,
1069 (goto-char (window-start window))
1070 (vertical-motion (1- (window-height window))
1077 @defun set-window-start window position &optional noforce
1078 This function sets the display-start position of @var{window} to
1079 @var{position} in @var{window}'s buffer. It returns @var{position}.
1081 The display routines insist that the position of point be visible when a
1082 buffer is displayed. Normally, they change the display-start position
1083 (that is, scroll the window) whenever necessary to make point visible.
1084 However, if you specify the start position with this function using
1085 @code{nil} for @var{noforce}, it means you want display to start at
1086 @var{position} even if that would put the location of point off the
1087 screen. If this does place point off screen, the display routines move
1088 point to the left margin on the middle line in the window.
1090 For example, if point @w{is 1} and you set the start of the window @w{to
1091 2}, then point would be ``above'' the top of the window. The display
1092 routines will automatically move point if it is still 1 when redisplay
1093 occurs. Here is an example:
1097 ;; @r{Here is what @samp{foo} looks like before executing}
1098 ;; @r{the @code{set-window-start} expression.}
1102 ---------- Buffer: foo ----------
1103 @point{}This is the contents of buffer foo.
1109 ---------- Buffer: foo ----------
1115 (1+ (window-start)))
1120 ;; @r{Here is what @samp{foo} looks like after executing}
1121 ;; @r{the @code{set-window-start} expression.}
1122 ---------- Buffer: foo ----------
1123 his is the contents of buffer foo.
1129 ---------- Buffer: foo ----------
1133 If @var{noforce} is non-@code{nil}, and @var{position} would place point
1134 off screen at the next redisplay, then redisplay computes a new window-start
1135 position that works well with point, and thus @var{position} is not used.
1138 @defun pos-visible-in-window-p &optional position window
1139 This function returns @code{t} if @var{position} is within the range
1140 of text currently visible on the screen in @var{window}. It returns
1141 @code{nil} if @var{position} is scrolled vertically out of view. The
1142 argument @var{position} defaults to the current position of point;
1143 @var{window}, to the selected window. Here is an example:
1147 (or (pos-visible-in-window-p
1148 (point) (selected-window))
1153 The @code{pos-visible-in-window-p} function considers only vertical
1154 scrolling. If @var{position} is out of view only because @var{window}
1155 has been scrolled horizontally, @code{pos-visible-in-window-p} returns
1156 @code{t}. @xref{Horizontal Scrolling}.
1159 @node Vertical Scrolling
1160 @section Vertical Scrolling
1161 @cindex vertical scrolling
1162 @cindex scrolling vertically
1164 Vertical scrolling means moving the text up or down in a window. It
1165 works by changing the value of the window's display-start location. It
1166 may also change the value of @code{window-point} to keep it on the
1169 In the commands @code{scroll-up} and @code{scroll-down}, the directions
1170 ``up'' and ``down'' refer to the motion of the text in the buffer at which
1171 you are looking through the window. Imagine that the text is
1172 written on a long roll of paper and that the scrolling commands move the
1173 paper up and down. Thus, if you are looking at text in the middle of a
1174 buffer and repeatedly call @code{scroll-down}, you will eventually see
1175 the beginning of the buffer.
1177 Some people have urged that the opposite convention be used: they
1178 imagine that the window moves over text that remains in place. Then
1179 ``down'' commands would take you to the end of the buffer. This view is
1180 more consistent with the actual relationship between windows and the
1181 text in the buffer, but it is less like what the user sees. The
1182 position of a window on the terminal does not move, and short scrolling
1183 commands clearly move the text up or down on the screen. We have chosen
1184 names that fit the user's point of view.
1186 The scrolling functions (aside from @code{scroll-other-window}) have
1187 unpredictable results if the current buffer is different from the buffer
1188 that is displayed in the selected window. @xref{Current Buffer}.
1190 @deffn Command scroll-up &optional count
1191 This function scrolls the text in the selected window upward
1192 @var{count} lines. If @var{count} is negative, scrolling is actually
1195 If @var{count} is @code{nil} (or omitted), then the length of scroll
1196 is @code{next-screen-context-lines} lines less than the usable height of
1197 the window (not counting its mode line).
1199 @code{scroll-up} returns @code{nil}.
1202 @deffn Command scroll-down &optional count
1203 This function scrolls the text in the selected window downward
1204 @var{count} lines. If @var{count} is negative, scrolling is actually
1207 If @var{count} is omitted or @code{nil}, then the length of the scroll
1208 is @code{next-screen-context-lines} lines less than the usable height of
1209 the window (not counting its mode line).
1211 @code{scroll-down} returns @code{nil}.
1214 @deffn Command scroll-other-window &optional count
1215 This function scrolls the text in another window upward @var{count}
1216 lines. Negative values of @var{count}, or @code{nil}, are handled
1217 as in @code{scroll-up}.
1219 You can specify a buffer to scroll with the variable
1220 @code{other-window-scroll-buffer}. When the selected window is the
1221 minibuffer, the next window is normally the one at the top left corner.
1222 You can specify a different window to scroll with the variable
1223 @code{minibuffer-scroll-window}. This variable has no effect when any
1224 other window is selected. @xref{Minibuffer Misc}.
1226 When the minibuffer is active, it is the next window if the selected
1227 window is the one at the bottom right corner. In this case,
1228 @code{scroll-other-window} attempts to scroll the minibuffer. If the
1229 minibuffer contains just one line, it has nowhere to scroll to, so the
1230 line reappears after the echo area momentarily displays the message
1231 ``Beginning of buffer''.
1235 @defvar other-window-scroll-buffer
1236 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
1237 which buffer to scroll.
1241 This variable controls how scrolling is done automatically when point
1242 moves off the screen. If the value is zero, then redisplay scrolls the
1243 text to center point vertically in the window. If the value is a
1244 positive integer @var{n}, then redisplay brings point back on screen by
1245 scrolling @var{n} lines in either direction, if possible; otherwise, it
1246 centers point. The default value is zero.
1249 @defopt next-screen-context-lines
1250 The value of this variable is the number of lines of continuity to
1251 retain when scrolling by full screens. For example, @code{scroll-up}
1252 with an argument of @code{nil} scrolls so that this many lines at the
1253 bottom of the window appear instead at the top. The default value is
1257 @deffn Command recenter &optional count
1258 @cindex centering point
1259 This function scrolls the selected window to put the text where point
1260 is located at a specified vertical position within the window.
1262 If @var{count} is a nonnegative number, it puts the line containing
1263 point @var{count} lines down from the top of the window. If @var{count}
1264 is a negative number, then it counts upward from the bottom of the
1265 window, so that @minus{}1 stands for the last usable line in the window.
1266 If @var{count} is a non-@code{nil} list, then it stands for the line in
1267 the middle of the window.
1269 If @var{count} is @code{nil}, @code{recenter} puts the line containing
1270 point in the middle of the window, then clears and redisplays the entire
1273 When @code{recenter} is called interactively, @var{count} is the raw
1274 prefix argument. Thus, typing @kbd{C-u} as the prefix sets the
1275 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
1276 @var{count} to 4, which positions the current line four lines from the
1279 With an argument of zero, @code{recenter} positions the current line at
1280 the top of the window. This action is so handy that some people make a
1281 separate key binding to do this. For example,
1285 (defun line-to-top-of-window ()
1286 "Scroll current line to top of window.
1287 Replaces three keystroke sequence C-u 0 C-l."
1291 (global-set-key [kp-multiply] 'line-to-top-of-window)
1296 @node Scrolling Hooks
1297 @section Hooks for Vertical Scrolling
1299 This section describes how a Lisp program can take action whenever a
1300 window displays a different part of its buffer or a different buffer.
1301 There are three actions that can change this: scrolling the window,
1302 switching buffers in the window, and changing the size of the window.
1303 The first two actions run @code{window-scroll-functions}; the last runs
1304 @code{window-size-change-functions}. The paradigmatic use of these
1305 hooks is Lazy Lock mode; see @ref{Support Modes, Lazy Lock, Font Lock
1306 Support Modes, emacs, The GNU Emacs Manual}.
1308 @defvar window-scroll-functions
1309 This variable holds a list of functions that Emacs should call before
1310 redisplaying a window with scrolling. It is not a normal hook, because
1311 each function is called with two arguments: the window, and its new
1312 display-start position.
1314 Displaying a different buffer in the window also runs these functions.
1316 These functions cannot expect @code{window-end} (@pxref{Window Start})
1317 to return a meaningful value, because that value is updated only by
1318 redisplaying the buffer. So if one of these functions needs to know the
1319 last character that will fit in the window with its current
1320 display-start position, it has to find that character using
1321 @code{vertical-motion} (@pxref{Screen Lines}).
1324 @defvar window-size-change-functions
1325 This variable holds a list of functions to be called if the size of any
1326 window changes for any reason. The functions are called just once per
1327 redisplay, and just once for each frame on which size changes have
1330 Each function receives the frame as its sole argument. There is no
1331 direct way to find out which windows on that frame have changed size, or
1332 precisely how. However, if a size-change function records, at each
1333 call, the existing windows and their sizes, it can also compare the
1334 present sizes and the previous sizes.
1336 Creating or deleting windows counts as a size change, and therefore
1337 causes these functions to be called. Changing the frame size also
1338 counts, because it changes the sizes of the existing windows.
1340 It is not a good idea to use @code{save-window-excursion} (@pxref{Window
1341 Configurations}) in these functions, because that always counts as a
1342 size change, and it would cause these functions to be called over and
1343 over. In most cases, @code{save-selected-window} (@pxref{Selecting
1344 Windows}) is what you need here.
1347 @node Horizontal Scrolling
1348 @section Horizontal Scrolling
1349 @cindex horizontal scrolling
1351 Because we read English first from top to bottom and second from left
1352 to right, horizontal scrolling is not like vertical scrolling. Vertical
1353 scrolling involves selection of a contiguous portion of text to display.
1354 Horizontal scrolling causes part of each line to go off screen. The
1355 amount of horizontal scrolling is therefore specified as a number of
1356 columns rather than as a position in the buffer. It has nothing to do
1357 with the display-start position returned by @code{window-start}.
1359 Usually, no horizontal scrolling is in effect; then the leftmost
1360 column is at the left edge of the window. In this state, scrolling to
1361 the right is meaningless, since there is no data to the left of the
1362 screen to be revealed by it; so this is not allowed. Scrolling to the
1363 left is allowed; it scrolls the first columns of text off the edge of
1364 the window and can reveal additional columns on the right that were
1365 truncated before. Once a window has a nonzero amount of leftward
1366 horizontal scrolling, you can scroll it back to the right, but only so
1367 far as to reduce the net horizontal scroll to zero. There is no limit
1368 to how far left you can scroll, but eventually all the text will
1369 disappear off the left edge.
1371 @deffn Command scroll-left count
1372 This function scrolls the selected window @var{count} columns to the
1373 left (or to the right if @var{count} is negative). The return value is
1374 the total amount of leftward horizontal scrolling in effect after the
1375 change---just like the value returned by @code{window-hscroll} (below).
1378 @deffn Command scroll-right count
1379 This function scrolls the selected window @var{count} columns to the
1380 right (or to the left if @var{count} is negative). The return value is
1381 the total amount of leftward horizontal scrolling in effect after the
1382 change---just like the value returned by @code{window-hscroll} (below).
1384 Once you scroll a window as far right as it can go, back to its normal
1385 position where the total leftward scrolling is zero, attempts to scroll
1386 any farther right have no effect.
1389 @defun window-hscroll &optional window
1390 This function returns the total leftward horizontal scrolling of
1391 @var{window}---the number of columns by which the text in @var{window}
1392 is scrolled left past the left margin.
1394 The value is never negative. It is zero when no horizontal scrolling
1395 has been done in @var{window} (which is usually the case).
1397 If @var{window} is @code{nil}, the selected window is used.
1415 @defun set-window-hscroll window columns
1416 This function sets the number of columns from the left margin that
1417 @var{window} is scrolled to the value of @var{columns}. The argument
1418 @var{columns} should be zero or positive; if not, it is taken as zero.
1420 The value returned is @var{columns}.
1424 (set-window-hscroll (selected-window) 10)
1430 Here is how you can determine whether a given position @var{position}
1431 is off the screen due to horizontal scrolling:
1435 (defun hscroll-on-screen (window position)
1437 (goto-char position)
1439 (>= (- (current-column) (window-hscroll window)) 0)
1440 (< (- (current-column) (window-hscroll window))
1441 (window-width window)))))
1445 @node Size of Window
1446 @section The Size of a Window
1448 @cindex size of window
1450 An Emacs window is rectangular, and its size information consists of
1451 the height (the number of lines) and the width (the number of character
1452 positions in each line). The mode line is included in the height. But
1453 the width does not count the scroll bar or the column of @samp{|}
1454 characters that separates side-by-side windows.
1456 The following three functions return size information about a window:
1458 @defun window-height &optional window
1459 This function returns the number of lines in @var{window}, including
1460 its mode line. If @var{window} fills its entire frame, this is one less
1461 than the value of @code{frame-height} on that frame (since the last line
1462 is always reserved for the minibuffer).
1464 If @var{window} is @code{nil}, the function uses the selected window.
1472 (split-window-vertically)
1473 @result{} #<window 4 on windows.texi>
1482 @defun window-width &optional window
1483 This function returns the number of columns in @var{window}. If
1484 @var{window} fills its entire frame, this is the same as the value of
1485 @code{frame-width} on that frame. The width does not include the
1486 window's scroll bar or the column of @samp{|} characters that separates
1487 side-by-side windows.
1489 If @var{window} is @code{nil}, the function uses the selected window.
1499 @defun window-edges &optional window
1500 This function returns a list of the edge coordinates of @var{window}.
1501 If @var{window} is @code{nil}, the selected window is used.
1503 The order of the list is @code{(@var{left} @var{top} @var{right}
1504 @var{bottom})}, all elements relative to 0, 0 at the top left corner of
1505 the frame. The element @var{right} of the value is one more than the
1506 rightmost column used by @var{window}, and @var{bottom} is one more than
1507 the bottommost row used by @var{window} and its mode-line.
1509 When you have side-by-side windows, the right edge value for a window
1510 with a neighbor on the right includes the width of the separator between
1511 the window and that neighbor. This separator may be a column of
1512 @samp{|} characters or it may be a scroll bar. Since the width of the
1513 window does not include this separator, the width does not equal the
1514 difference between the right and left edges in this case.
1516 Here is the result obtained on a typical 24-line terminal with just one
1521 (window-edges (selected-window))
1522 @result{} (0 0 80 23)
1527 The bottom edge is at line 23 because the last line is the echo area.
1529 If @var{window} is at the upper left corner of its frame, then
1530 @var{bottom} is the same as the value of @code{(window-height)},
1531 @var{right} is almost the same as the value of
1532 @code{(window-width)}@footnote{They are not exactly equal because
1533 @var{right} includes the vertical separator line or scroll bar, while
1534 @code{(window-width)} does not.}, and @var{top} and @var{left} are zero.
1535 For example, the edges of the following window are @w{@samp{0 0 5 8}}.
1536 Assuming that the frame has more than 8 columns, the last column of the
1537 window (column 7) holds a border rather than text. The last row (row 4)
1538 holds the mode line, shown here with @samp{xxxxxxxxx}.
1554 When there are side-by-side windows, any window not at the right edge of
1555 its frame has a separator in its last column or columns. The separator
1556 counts as one or two columns in the width of the window. A window never
1557 includes a separator on its left, since that belongs to the window to
1560 In the following example, let's suppose that the frame is 7
1561 columns wide. Then the edges of the left window are @w{@samp{0 0 4 3}}
1562 and the edges of the right window are @w{@samp{4 0 7 3}}.
1576 @node Resizing Windows
1577 @section Changing the Size of a Window
1578 @cindex window resizing
1579 @cindex changing window size
1580 @cindex window size, changing
1582 The window size functions fall into two classes: high-level commands
1583 that change the size of windows and low-level functions that access
1584 window size. Emacs does not permit overlapping windows or gaps between
1585 windows, so resizing one window affects other windows.
1587 @deffn Command enlarge-window size &optional horizontal
1588 This function makes the selected window @var{size} lines taller,
1589 stealing lines from neighboring windows. It takes the lines from one
1590 window at a time until that window is used up, then takes from another.
1591 If a window from which lines are stolen shrinks below
1592 @code{window-min-height} lines, that window disappears.
1594 If @var{horizontal} is non-@code{nil}, this function makes
1595 @var{window} wider by @var{size} columns, stealing columns instead of
1596 lines. If a window from which columns are stolen shrinks below
1597 @code{window-min-width} columns, that window disappears.
1599 If the requested size would exceed that of the window's frame, then the
1600 function makes the window occupy the entire height (or width) of the
1603 If @var{size} is negative, this function shrinks the window by
1604 @minus{}@var{size} lines or columns. If that makes the window smaller
1605 than the minimum size (@code{window-min-height} and
1606 @code{window-min-width}), @code{enlarge-window} deletes the window.
1608 @code{enlarge-window} returns @code{nil}.
1611 @deffn Command enlarge-window-horizontally columns
1612 This function makes the selected window @var{columns} wider.
1613 It could be defined as follows:
1617 (defun enlarge-window-horizontally (columns)
1618 (enlarge-window columns t))
1623 @deffn Command shrink-window size &optional horizontal
1624 This function is like @code{enlarge-window} but negates the argument
1625 @var{size}, making the selected window smaller by giving lines (or
1626 columns) to the other windows. If the window shrinks below
1627 @code{window-min-height} or @code{window-min-width}, then it disappears.
1629 If @var{size} is negative, the window is enlarged by @minus{}@var{size}
1633 @deffn Command shrink-window-horizontally columns
1634 This function makes the selected window @var{columns} narrower.
1635 It could be defined as follows:
1639 (defun shrink-window-horizontally (columns)
1640 (shrink-window columns t))
1645 @cindex minimum window size
1646 The following two variables constrain the window-size-changing
1647 functions to a minimum height and width.
1649 @defopt window-min-height
1650 The value of this variable determines how short a window may become
1651 before it is automatically deleted. Making a window smaller than
1652 @code{window-min-height} automatically deletes it, and no window may be
1653 created shorter than this. The absolute minimum height is two (allowing
1654 one line for the mode line, and one line for the buffer display).
1655 Actions that change window sizes reset this variable to two if it is
1656 less than two. The default value is 4.
1659 @defopt window-min-width
1660 The value of this variable determines how narrow a window may become
1661 before it automatically deleted. Making a window smaller than
1662 @code{window-min-width} automatically deletes it, and no window may be
1663 created narrower than this. The absolute minimum width is one; any
1664 value below that is ignored. The default value is 10.
1667 @node Coordinates and Windows
1668 @section Coordinates and Windows
1670 This section describes how to relate screen coordinates to windows.
1672 @defun window-at x y &optional frame
1673 This function returns the window containing the specified cursor
1674 position in the frame @var{frame}. The coordinates @var{x} and @var{y}
1675 are measured in characters and count from the top left corner of the
1676 frame. If they are out of range, @code{window-at} returns @code{nil}.
1678 If you omit @var{frame}, the selected frame is used.
1681 @defun coordinates-in-window-p coordinates window
1682 This function checks whether a particular frame position falls within
1683 the window @var{window}.
1686 The argument @var{coordinates} is a cons cell of this form:
1693 The coordinates @var{x} and @var{y} are measured in characters, and
1694 count from the top left corner of the screen or frame.
1696 The value of @code{coordinates-in-window-p} is non-@code{nil} if the
1697 coordinates are inside @var{window}. The value also indicates what part
1698 of the window the position is in, as follows:
1701 @item (@var{relx} . @var{rely})
1702 The coordinates are inside @var{window}. The numbers @var{relx} and
1703 @var{rely} are the equivalent window-relative coordinates for the
1704 specified position, counting from 0 at the top left corner of the
1708 The coordinates are in the mode line of @var{window}.
1710 @item vertical-split
1711 The coordinates are in the vertical line between @var{window} and its
1712 neighbor to the right. This value occurs only if the window doesn't
1713 have a scroll bar; positions in a scroll bar are considered outside the
1717 The coordinates are not in any part of @var{window}.
1720 The function @code{coordinates-in-window-p} does not require a frame as
1721 argument because it always uses the frame that @var{window} is on.
1724 @node Window Configurations
1725 @section Window Configurations
1726 @cindex window configurations
1727 @cindex saving window information
1729 A @dfn{window configuration} records the entire layout of a
1730 frame---all windows, their sizes, which buffers they contain, what part
1731 of each buffer is displayed, and the values of point and the mark. You
1732 can bring back an entire previous layout by restoring a window
1733 configuration previously saved.
1735 If you want to record all frames instead of just one, use a frame
1736 configuration instead of a window configuration. @xref{Frame
1739 @defun current-window-configuration
1740 This function returns a new object representing Emacs's current window
1741 configuration, namely the number of windows, their sizes and current
1742 buffers, which window is the selected window, and for each window the
1743 displayed buffer, the display-start position, and the positions of point
1744 and the mark. An exception is made for point in the current buffer,
1745 whose value is not saved.
1748 @defun set-window-configuration configuration
1749 This function restores the configuration of Emacs's windows and
1750 buffers to the state specified by @var{configuration}. The argument
1751 @var{configuration} must be a value that was previously returned by
1752 @code{current-window-configuration}.
1754 This function always counts as a window size change and triggers
1755 execution of the @code{window-size-change-functions}. (It doesn't know
1756 how to tell whether the new configuration actually differs from the old
1759 Here is a way of using this function to get the same effect
1760 as @code{save-window-excursion}:
1764 (let ((config (current-window-configuration)))
1766 (progn (split-window-vertically nil)
1768 (set-window-configuration config)))
1773 @defspec save-window-excursion forms@dots{}
1774 This special form records the window configuration, executes @var{forms}
1775 in sequence, then restores the earlier window configuration. The window
1776 configuration includes the value of point and the portion of the buffer
1777 that is visible. It also includes the choice of selected window.
1778 However, it does not include the value of point in the current buffer;
1779 use @code{save-excursion} if you wish to preserve that.
1781 Don't use this construct when @code{save-selected-window} is all you need.
1783 Exit from @code{save-window-excursion} always triggers execution of the
1784 @code{window-size-change-functions}. (It doesn't know how to tell
1785 whether the restored configuration actually differs from the one in
1786 effect at the end of the @var{forms}.)
1788 The return value is the value of the final form in @var{forms}.
1794 @result{} #<window 25 on control.texi>
1797 (setq w (selected-window))
1798 @result{} #<window 19 on control.texi>
1801 (save-window-excursion
1802 (delete-other-windows w)
1803 (switch-to-buffer "foo")
1805 @result{} do-something
1806 ;; @r{The screen is now split again.}
1811 @defun window-configuration-p object
1812 This function returns @code{t} if @var{object} is a window configuration.
1815 Primitives to look inside of window configurations would make sense,
1816 but none are implemented. It is not clear they are useful enough to be