2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 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 * 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 * Window Hooks:: Hooks for scrolling, window size changes,
33 redisplay going past a certain point,
34 or window configuration changes.
38 @section Basic Concepts of Emacs Windows
40 @cindex selected window
42 A @dfn{window} in Emacs is the physical area of the screen in which a
43 buffer is displayed. The term is also used to refer to a Lisp object that
44 represents that screen area in Emacs Lisp. It should be
45 clear from the context which is meant.
47 Emacs groups windows into frames. A frame represents an area of
48 screen available for Emacs to use. Each frame always contains at least
49 one window, but you can subdivide it vertically or horizontally into
50 multiple nonoverlapping Emacs windows.
52 In each frame, at any time, one and only one window is designated as
53 @dfn{selected within the frame}. The frame's cursor appears in that
54 window. At any time, one frame is the selected frame; and the window
55 selected within that frame is @dfn{the selected window}. The selected
56 window's buffer is usually the current buffer (except when
57 @code{set-buffer} has been used). @xref{Current Buffer}.
59 For practical purposes, a window exists only while it is displayed in
60 a frame. Once removed from the frame, the window is effectively deleted
61 and should not be used, @emph{even though there may still be references
62 to it} from other Lisp objects. Restoring a saved window configuration
63 is the only way for a window no longer on the screen to come back to
64 life. (@xref{Deleting Windows}.)
66 Each window has the following attributes:
79 window edges with respect to the screen or frame
82 the buffer it displays
85 position within the buffer at the upper left of the window
88 amount of horizontal scrolling, in columns
97 how recently the window was selected
100 @cindex multiple windows
101 Users create multiple windows so they can look at several buffers at
102 once. Lisp libraries use multiple windows for a variety of reasons, but
103 most often to display related information. In Rmail, for example, you
104 can move through a summary buffer in one window while the other window
105 shows messages one at a time as they are reached.
107 The meaning of ``window'' in Emacs is similar to what it means in the
108 context of general-purpose window systems such as X, but not identical.
109 The X Window System places X windows on the screen; Emacs uses one or
110 more X windows as frames, and subdivides them into
111 Emacs windows. When you use Emacs on a character-only terminal, Emacs
112 treats the whole terminal screen as one frame.
114 @cindex terminal screen
115 @cindex screen of terminal
116 @cindex tiled windows
117 Most window systems support arbitrarily located overlapping windows.
118 In contrast, Emacs windows are @dfn{tiled}; they never overlap, and
119 together they fill the whole screen or frame. Because of the way in
120 which Emacs creates new windows and resizes them, not all conceivable
121 tilings of windows on an Emacs frame are actually possible.
122 @xref{Splitting Windows}, and @ref{Size of Window}.
124 @xref{Display}, for information on how the contents of the
125 window's buffer are displayed in the window.
127 @defun windowp object
128 This function returns @code{t} if @var{object} is a window.
131 @node Splitting Windows
132 @section Splitting Windows
133 @cindex splitting windows
134 @cindex window splitting
136 The functions described here are the primitives used to split a window
137 into two windows. Two higher level functions sometimes split a window,
138 but not always: @code{pop-to-buffer} and @code{display-buffer}
139 (@pxref{Displaying Buffers}).
141 The functions described here do not accept a buffer as an argument.
142 The two ``halves'' of the split window initially display the same buffer
143 previously visible in the window that was split.
145 @deffn Command split-window &optional window size horizontal
146 This function splits @var{window} into two windows. The original
147 window @var{window} remains the selected window, but occupies only
148 part of its former screen area. The rest is occupied by a newly created
149 window which is returned as the value of this function.
151 If @var{horizontal} is non-@code{nil}, then @var{window} splits into
152 two side by side windows. The original window @var{window} keeps the
153 leftmost @var{size} columns, and gives the rest of the columns to the
154 new window. Otherwise, it splits into windows one above the other, and
155 @var{window} keeps the upper @var{size} lines and gives the rest of the
156 lines to the new window. The original window is therefore the
157 left-hand or upper of the two, and the new window is the right-hand or
160 If @var{window} is omitted or @code{nil}, then the selected window is
161 split. If @var{size} is omitted or @code{nil}, then @var{window} is
162 divided evenly into two parts. (If there is an odd line, it is
163 allocated to the new window.) When @code{split-window} is called
164 interactively, all its arguments are @code{nil}.
166 The following example starts with one window on a screen that is 50
167 lines high by 80 columns wide; then the window is split.
171 (setq w (selected-window))
172 @result{} #<window 8 on windows.texi>
173 (window-edges) ; @r{Edges in order:}
174 @result{} (0 0 80 50) ; @r{left--top--right--bottom}
178 ;; @r{Returns window created}
179 (setq w2 (split-window w 15))
180 @result{} #<window 28 on windows.texi>
184 @result{} (0 15 80 50) ; @r{Bottom window;}
189 @result{} (0 0 80 15) ; @r{Top window}
193 The screen looks like this:
209 Next, the top window is split horizontally:
213 (setq w3 (split-window w 35 t))
214 @result{} #<window 32 on windows.texi>
218 @result{} (35 0 80 15) ; @r{Left edge at column 35}
222 @result{} (0 0 35 15) ; @r{Right edge at column 35}
226 @result{} (0 15 80 50) ; @r{Bottom window unchanged}
231 Now, the screen looks like this:
248 Normally, Emacs indicates the border between two side-by-side windows
249 with a scroll bar (@pxref{Window Frame Parameters,Scroll Bars}) or @samp{|}
250 characters. The display table can specify alternative border
251 characters; see @ref{Display Tables}.
254 @deffn Command split-window-vertically size
255 This function splits the selected window into two windows, one above the
256 other, leaving the upper of the two windows selected, with @var{size}
257 lines. (If @var{size} is negative, then the lower of the two windows
258 gets @minus{} @var{size} lines and the upper window gets the rest, but
259 the upper window is still the one selected.)
261 This function is simply an interface to @code{split-window}.
262 Here is the complete function definition for it:
266 (defun split-window-vertically (&optional arg)
267 "Split current window into two windows, @dots{}"
269 (split-window nil (and arg (prefix-numeric-value arg))))
274 @deffn Command split-window-horizontally size
275 This function splits the selected window into two windows
276 side-by-side, leaving the selected window with @var{size} columns.
278 This function is simply an interface to @code{split-window}. Here is
279 the complete definition for @code{split-window-horizontally} (except for
280 part of the documentation string):
284 (defun split-window-horizontally (&optional arg)
285 "Split selected window into two windows, side by side..."
287 (split-window nil (and arg (prefix-numeric-value arg)) t))
292 @defun one-window-p &optional no-mini all-frames
293 This function returns non-@code{nil} if there is only one window. The
294 argument @var{no-mini}, if non-@code{nil}, means don't count the
295 minibuffer even if it is active; otherwise, the minibuffer window is
296 included, if active, in the total number of windows, which is compared
299 The argument @var{all-frames} specifies which frames to consider. Here
300 are the possible values and their meanings:
304 Count the windows in the selected frame, plus the minibuffer used
305 by that frame even if it lies in some other frame.
308 Count all windows in all existing frames.
311 Count all windows in all visible frames.
314 Count all windows in all visible or iconified frames.
317 Count precisely the windows in the selected frame, and no others.
321 @node Deleting Windows
322 @section Deleting Windows
323 @cindex deleting windows
325 A window remains visible on its frame unless you @dfn{delete} it by
326 calling certain functions that delete windows. A deleted window cannot
327 appear on the screen, but continues to exist as a Lisp object until
328 there are no references to it. There is no way to cancel the deletion
329 of a window aside from restoring a saved window configuration
330 (@pxref{Window Configurations}). Restoring a window configuration also
331 deletes any windows that aren't part of that configuration.
333 When you delete a window, the space it took up is given to one
337 @defun window-live-p window
338 This function returns @code{nil} if @var{window} is deleted, and
341 @strong{Warning:} Erroneous information or fatal errors may result from
342 using a deleted window as if it were live.
345 @deffn Command delete-window &optional window
346 This function removes @var{window} from display, and returns @code{nil}.
347 If @var{window} is omitted, then the selected window is deleted. An
348 error is signaled if there is only one window when @code{delete-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 return value 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. This
373 function does not use it in quite the same way as the other functions
374 which scan all windows; specifically, the values @code{t} and @code{nil}
375 have the opposite of their meanings in other functions. Here are the
380 If it is @code{nil}, operate on all frames.
382 If it is @code{t}, operate on the selected frame.
384 If it is @code{visible}, operate on all visible frames.
386 If it is 0, operate on all visible or iconified frames.
388 If it is a frame, operate on that frame.
391 This function always returns @code{nil}.
394 @node Selecting Windows
395 @section Selecting Windows
396 @cindex selecting windows
398 When a window is selected, the buffer in the window becomes the current
399 buffer, and the cursor will appear in it.
401 @defun selected-window
402 This function returns the selected window. This is the window in
403 which the cursor appears and to which many commands apply.
406 @defun select-window window
407 This function makes @var{window} the selected window. The cursor then
408 appears in @var{window} (on redisplay). The buffer being displayed in
409 @var{window} is immediately designated the current buffer.
411 The return value is @var{window}.
415 (setq w (next-window))
417 @result{} #<window 65 on windows.texi>
422 @defmac save-selected-window forms@dots{}
423 This macro records the selected window, executes @var{forms}
424 in sequence, then restores the earlier selected window.
426 This macro does not save or restore anything about the sizes, arrangement
427 or contents of windows; therefore, if the @var{forms} change them,
430 Each frame, at any time, has a window selected within the frame. This
431 macro saves only @emph{the} selected window; it does not save anything
432 about other frames. If the @var{forms} select some other frame and
433 alter the window selected within it, the change persists.
436 @cindex finding windows
437 The following functions choose one of the windows on the screen,
438 offering various criteria for the choice.
440 @defun get-lru-window &optional frame
441 This function returns the window least recently ``used'' (that is,
442 selected). The selected window is always the most recently used window.
444 The selected window can be the least recently used window if it is the
445 only window. A newly created window becomes the least recently used
446 window until it is selected. A minibuffer window is never a candidate.
448 The argument @var{frame} controls which windows are considered.
452 If it is @code{nil}, consider windows on the selected frame.
454 If it is @code{t}, consider windows on all frames.
456 If it is @code{visible}, consider windows on all visible frames.
458 If it is 0, consider windows on all visible or iconified frames.
460 If it is a frame, consider windows on that frame.
464 @defun get-largest-window &optional frame
465 This function returns the window with the largest area (height times
466 width). If there are no side-by-side windows, then this is the window
467 with the most lines. A minibuffer window is never a candidate.
469 If there are two windows of the same size, then the function returns
470 the window that is first in the cyclic ordering of windows (see
471 following section), starting from the selected window.
473 The argument @var{frame} controls which set of windows to
474 consider. See @code{get-lru-window}, above.
477 @node Cyclic Window Ordering
478 @comment node-name, next, previous, up
479 @section Cyclic Ordering of Windows
480 @cindex cyclic ordering of windows
481 @cindex ordering of windows, cyclic
482 @cindex window ordering, cyclic
484 When you use the command @kbd{C-x o} (@code{other-window}) to select
485 the next window, it moves through all the windows on the screen in a
486 specific cyclic order. For any given configuration of windows, this
487 order never varies. It is called the @dfn{cyclic ordering of windows}.
489 This ordering generally goes from top to bottom, and from left to
490 right. But it may go down first or go right first, depending on the
491 order in which the windows were split.
493 If the first split was vertical (into windows one above each other),
494 and then the subwindows were split horizontally, then the ordering is
495 left to right in the top of the frame, and then left to right in the
496 next lower part of the frame, and so on. If the first split was
497 horizontal, the ordering is top to bottom in the left part, and so on.
498 In general, within each set of siblings at any level in the window tree,
499 the order is left to right, or top to bottom.
501 @defun next-window &optional window minibuf all-frames
502 @cindex minibuffer window
503 This function returns the window following @var{window} in the cyclic
504 ordering of windows. This is the window that @kbd{C-x o} would select
505 if typed when @var{window} is selected. If @var{window} is the only
506 window visible, then this function returns @var{window}. If omitted,
507 @var{window} defaults to the selected window.
509 The value of the argument @var{minibuf} determines whether the
510 minibuffer is included in the window order. Normally, when
511 @var{minibuf} is @code{nil}, the minibuffer is included if it is
512 currently active; this is the behavior of @kbd{C-x o}. (The minibuffer
513 window is active while the minibuffer is in use. @xref{Minibuffers}.)
515 If @var{minibuf} is @code{t}, then the cyclic ordering includes the
516 minibuffer window even if it is not active.
518 If @var{minibuf} is neither @code{t} nor @code{nil}, then the minibuffer
519 window is not included even if it is active.
521 The argument @var{all-frames} specifies which frames to consider. Here
522 are the possible values and their meanings:
526 Consider all the windows in @var{window}'s frame, plus the minibuffer
527 used by that frame even if it lies in some other frame.
530 Consider all windows in all existing frames.
533 Consider all windows in all visible frames. (To get useful results, you
534 must ensure @var{window} is in a visible frame.)
537 Consider all windows in all visible or iconified frames.
540 Consider precisely the windows in @var{window}'s frame, and no others.
543 This example assumes there are two windows, both displaying the
544 buffer @samp{windows.texi}:
549 @result{} #<window 56 on windows.texi>
552 (next-window (selected-window))
553 @result{} #<window 52 on windows.texi>
556 (next-window (next-window (selected-window)))
557 @result{} #<window 56 on windows.texi>
562 @defun previous-window &optional window minibuf all-frames
563 This function returns the window preceding @var{window} in the cyclic
564 ordering of windows. The other arguments specify which windows to
565 include in the cycle, as in @code{next-window}.
568 @deffn Command other-window count
569 This function selects the @var{count}th following window in the cyclic
570 order. If count is negative, then it moves back @minus{}@var{count}
571 windows in the cycle, rather than forward. It returns @code{nil}.
573 In an interactive call, @var{count} is the numeric prefix argument.
577 @defun walk-windows proc &optional minibuf all-frames
578 This function cycles through all windows, calling @code{proc}
579 once for each window with the window as its sole argument.
581 The optional arguments @var{minibuf} and @var{all-frames} specify the
582 set of windows to include in the scan. See @code{next-window}, above,
586 @node Buffers and Windows
587 @section Buffers and Windows
588 @cindex examining windows
589 @cindex windows, controlling precisely
590 @cindex buffers, controlled in windows
592 This section describes low-level functions to examine windows or to
593 display buffers in windows in a precisely controlled fashion.
595 See the following section for
598 @xref{Displaying Buffers}, for
600 related functions that find a window to use and specify a buffer for it.
601 The functions described there are easier to use than these, but they
602 employ heuristics in choosing or creating a window; use these functions
603 when you need complete control.
605 @defun set-window-buffer window buffer-or-name
606 This function makes @var{window} display @var{buffer-or-name} as its
607 contents. It returns @code{nil}. This is the fundamental primitive
608 for changing which buffer is displayed in a window, and all ways
609 of doing that call this function.
613 (set-window-buffer (selected-window) "foo")
619 @defun window-buffer &optional window
620 This function returns the buffer that @var{window} is displaying. If
621 @var{window} is omitted, this function returns the buffer for the
627 @result{} #<buffer windows.texi>
632 @defun get-buffer-window buffer-or-name &optional all-frames
633 This function returns a window currently displaying
634 @var{buffer-or-name}, or @code{nil} if there is none. If there are
635 several such windows, then the function returns the first one in the
636 cyclic ordering of windows, starting from the selected window.
637 @xref{Cyclic Window Ordering}.
639 The argument @var{all-frames} controls which windows to consider.
643 If it is @code{nil}, consider windows on the selected frame.
645 If it is @code{t}, consider windows on all frames.
647 If it is @code{visible}, consider windows on all visible frames.
649 If it is 0, consider windows on all visible or iconified frames.
651 If it is a frame, consider windows on that frame.
655 @defun get-buffer-window-list buffer-or-name &optional minibuf all-frames
656 This function returns a list of all the windows currently displaying
657 @var{buffer-or-name}.
659 The two optional arguments work like the optional arguments of
660 @code{next-window} (@pxref{Cyclic Window Ordering}); they are @emph{not}
661 like the single optional argument of @code{get-buffer-window}. Perhaps
662 we should change @code{get-buffer-window} in the future to make it
663 compatible with the other functions.
665 The argument @var{all-frames} controls which windows to consider.
669 If it is @code{nil}, consider windows on the selected frame.
671 If it is @code{t}, consider windows on all frames.
673 If it is @code{visible}, consider windows on all visible frames.
675 If it is 0, consider windows on all visible or iconified frames.
677 If it is a frame, consider windows on that frame.
681 @defvar buffer-display-time
682 @tindex buffer-display-time
683 This variable records the time at which a buffer was last made visible
684 in a window. It is always local in each buffer; each time
685 @code{set-window-buffer} is called, it sets this variable to
686 @code{(current-time)} in the specified buffer (@pxref{Time of Day}).
687 When a buffer is first created, @code{buffer-display-time} starts out
688 with the value @code{nil}.
691 @node Displaying Buffers
692 @section Displaying Buffers in Windows
693 @cindex switching to a buffer
694 @cindex displaying a buffer
696 In this section we describe convenient functions that choose a window
697 automatically and use it to display a specified buffer. These functions
698 can also split an existing window in certain circumstances. We also
699 describe variables that parameterize the heuristics used for choosing a
702 See the preceding section for
705 @xref{Buffers and Windows}, for
707 low-level functions that give you more precise control. All of these
708 functions work by calling @code{set-window-buffer}.
710 Do not use the functions in this section in order to make a buffer
711 current so that a Lisp program can access or modify it; they are too
712 drastic for that purpose, since they change the display of buffers in
713 windows, which would be gratuitous and surprise the user. Instead, use
714 @code{set-buffer} and @code{save-current-buffer} (@pxref{Current
715 Buffer}), which designate buffers as current for programmed access
716 without affecting the display of buffers in windows.
718 @deffn Command switch-to-buffer buffer-or-name &optional norecord
719 This function makes @var{buffer-or-name} the current buffer, and also
720 displays the buffer in the selected window. This means that a human can
721 see the buffer and subsequent keyboard commands will apply to it.
722 Contrast this with @code{set-buffer}, which makes @var{buffer-or-name}
723 the current buffer but does not display it in the selected window.
724 @xref{Current Buffer}.
726 If @var{buffer-or-name} does not identify an existing buffer, then a new
727 buffer by that name is created. The major mode for the new buffer is
728 set according to the variable @code{default-major-mode}. @xref{Auto
731 Normally the specified buffer is put at the front of the buffer list
732 (both the selected frame's buffer list and the frame-independent buffer
733 list). This affects the operation of @code{other-buffer}. However, if
734 @var{norecord} is non-@code{nil}, this is not done. @xref{The Buffer
737 The @code{switch-to-buffer} function is often used interactively, as
738 the binding of @kbd{C-x b}. It is also used frequently in programs. It
739 always returns @code{nil}.
742 @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
743 This function makes @var{buffer-or-name} the current buffer and
744 displays it in a window not currently selected. It then selects that
745 window. The handling of the buffer is the same as in
746 @code{switch-to-buffer}.
748 The currently selected window is absolutely never used to do the job.
749 If it is the only window, then it is split to make a distinct window for
750 this purpose. If the selected window is already displaying the buffer,
751 then it continues to do so, but another window is nonetheless found to
752 display it in as well.
754 This function updates the buffer list just like @code{switch-to-buffer}
755 unless @var{norecord} is non-@code{nil}.
758 @defun pop-to-buffer buffer-or-name &optional other-window norecord
759 This function makes @var{buffer-or-name} the current buffer and
760 switches to it in some window, preferably not the window previously
761 selected. The ``popped-to'' window becomes the selected window within
764 If the variable @code{pop-up-frames} is non-@code{nil},
765 @code{pop-to-buffer} looks for a window in any visible frame already
766 displaying the buffer; if there is one, it returns that window and makes
767 it be selected within its frame. If there is none, it creates a new
768 frame and displays the buffer in it.
770 If @code{pop-up-frames} is @code{nil}, then @code{pop-to-buffer}
771 operates entirely within the selected frame. (If the selected frame has
772 just a minibuffer, @code{pop-to-buffer} operates within the most
773 recently selected frame that was not just a minibuffer.)
775 If the variable @code{pop-up-windows} is non-@code{nil}, windows may
776 be split to create a new window that is different from the original
777 window. For details, see @ref{Choosing Window}.
779 If @var{other-window} is non-@code{nil}, @code{pop-to-buffer} finds or
780 creates another window even if @var{buffer-or-name} is already visible
781 in the selected window. Thus @var{buffer-or-name} could end up
782 displayed in two windows. On the other hand, if @var{buffer-or-name} is
783 already displayed in the selected window and @var{other-window} is
784 @code{nil}, then the selected window is considered sufficient display
785 for @var{buffer-or-name}, so that nothing needs to be done.
787 All the variables that affect @code{display-buffer} affect
788 @code{pop-to-buffer} as well. @xref{Choosing Window}.
790 If @var{buffer-or-name} is a string that does not name an existing
791 buffer, a buffer by that name is created. The major mode for the new
792 buffer is set according to the variable @code{default-major-mode}.
793 @xref{Auto Major Mode}.
795 This function updates the buffer list just like @code{switch-to-buffer}
796 unless @var{norecord} is non-@code{nil}.
799 @deffn Command replace-buffer-in-windows buffer
800 This function replaces @var{buffer} with some other buffer in all
801 windows displaying it. The other buffer used is chosen with
802 @code{other-buffer}. In the usual applications of this function, you
803 don't care which other buffer is used; you just want to make sure that
804 @var{buffer} is no longer displayed.
806 This function returns @code{nil}.
809 @node Choosing Window
810 @section Choosing a Window for Display
812 This section describes the basic facility that chooses a window to
813 display a buffer in---@code{display-buffer}. All the higher-level
814 functions and commands use this subroutine. Here we describe how to use
815 @code{display-buffer} and how to customize it.
817 @deffn Command display-buffer buffer-or-name &optional not-this-window frame
818 This command makes @var{buffer-or-name} appear in some window, like
819 @code{pop-to-buffer}, but it does not select that window and does not
820 make the buffer current. The identity of the selected window is
821 unaltered by this function.
823 If @var{not-this-window} is non-@code{nil}, it means to display the
824 specified buffer in a window other than the selected one, even if it is
825 already on display in the selected window. This can cause the buffer to
826 appear in two windows at once. Otherwise, if @var{buffer-or-name} is
827 already being displayed in any window, that is good enough, so this
828 function does nothing.
830 @code{display-buffer} returns the window chosen to display
831 @var{buffer-or-name}.
833 If the argument @var{frame} is non-@code{nil}, it specifies which frames
834 to check when deciding whether the buffer is already displayed. If the
835 buffer is already displayed in some window on one of these frames,
836 @code{display-buffer} simply returns that window. Here are the possible
837 values of @var{frame}:
841 If it is @code{nil}, consider windows on the selected frame.
843 If it is @code{t}, consider windows on all frames.
845 If it is @code{visible}, consider windows on all visible frames.
847 If it is 0, consider windows on all visible or iconified frames.
849 If it is a frame, consider windows on that frame.
852 Precisely how @code{display-buffer} finds or creates a window depends on
853 the variables described below.
856 @defopt pop-up-windows
857 This variable controls whether @code{display-buffer} makes new windows.
858 If it is non-@code{nil} and there is only one window, then that window
859 is split. If it is @code{nil}, then @code{display-buffer} does not
860 split the single window, but uses it whole.
863 @defopt split-height-threshold
864 This variable determines when @code{display-buffer} may split a window,
865 if there are multiple windows. @code{display-buffer} always splits the
866 largest window if it has at least this many lines. If the largest
867 window is not this tall, it is split only if it is the sole window and
868 @code{pop-up-windows} is non-@code{nil}.
872 @defopt pop-up-frames
873 This variable controls whether @code{display-buffer} makes new frames.
874 If it is non-@code{nil}, @code{display-buffer} looks for an existing
875 window already displaying the desired buffer, on any visible frame. If
876 it finds one, it returns that window. Otherwise it makes a new frame.
877 The variables @code{pop-up-windows} and @code{split-height-threshold} do
878 not matter if @code{pop-up-frames} is non-@code{nil}.
880 If @code{pop-up-frames} is @code{nil}, then @code{display-buffer} either
881 splits a window or reuses one.
883 @xref{Frames}, for more information.
887 @defvar pop-up-frame-function
888 This variable specifies how to make a new frame if @code{pop-up-frames}
891 Its value should be a function of no arguments. When
892 @code{display-buffer} makes a new frame, it does so by calling that
893 function, which should return a frame. The default value of the
894 variable is a function that creates a frame using parameters from
895 @code{pop-up-frame-alist}.
898 @defvar pop-up-frame-alist
899 This variable holds an alist specifying frame parameters used when
900 @code{display-buffer} makes a new frame. @xref{Frame Parameters}, for
901 more information about frame parameters.
904 @defopt special-display-buffer-names
905 A list of buffer names for buffers that should be displayed specially.
906 If the buffer's name is in this list, @code{display-buffer} handles the
909 By default, special display means to give the buffer a dedicated frame.
911 If an element is a list, instead of a string, then the @sc{car} of the
912 list is the buffer name, and the rest of the list says how to create the
913 frame. There are two possibilities for the rest of the list. It can be
914 an alist, specifying frame parameters, or it can contain a function and
915 arguments to give to it. (The function's first argument is always the
916 buffer to be displayed; the arguments from the list come after that.)
919 @defopt special-display-regexps
920 A list of regular expressions that specify buffers that should be
921 displayed specially. If the buffer's name matches any of the regular
922 expressions in this list, @code{display-buffer} handles the buffer
925 By default, special display means to give the buffer a dedicated frame.
927 If an element is a list, instead of a string, then the @sc{car} of the
928 list is the regular expression, and the rest of the list says how to
929 create the frame. See above, under @code{special-display-buffer-names}.
932 @defvar special-display-function
933 This variable holds the function to call to display a buffer specially.
934 It receives the buffer as an argument, and should return the window in
935 which it is displayed.
937 The default value of this variable is
938 @code{special-display-popup-frame}.
941 @defun special-display-popup-frame buffer
942 This function makes @var{buffer} visible in a frame of its own. If
943 @var{buffer} is already displayed in a window in some frame, it makes
944 the frame visible and raises it, to use that window. Otherwise, it
945 creates a frame that will be dedicated to @var{buffer}.
947 This function uses an existing window displaying @var{buffer} whether or
948 not it is in a frame of its own; but if you set up the above variables
949 in your init file, before @var{buffer} was created, then presumably the
950 window was previously made by this function.
953 @defopt special-display-frame-alist
954 This variable holds frame parameters for
955 @code{special-display-popup-frame} to use when it creates a frame.
958 @defopt same-window-buffer-names
959 A list of buffer names for buffers that should be displayed in the
960 selected window. If the buffer's name is in this list,
961 @code{display-buffer} handles the buffer by switching to it in the
965 @defopt same-window-regexps
966 A list of regular expressions that specify buffers that should be
967 displayed in the selected window. If the buffer's name matches any of
968 the regular expressions in this list, @code{display-buffer} handles the
969 buffer by switching to it in the selected window.
973 @defvar display-buffer-function
974 This variable is the most flexible way to customize the behavior of
975 @code{display-buffer}. If it is non-@code{nil}, it should be a function
976 that @code{display-buffer} calls to do the work. The function should
977 accept two arguments, the same two arguments that @code{display-buffer}
978 received. It should choose or create a window, display the specified
979 buffer, and then return the window.
981 This hook takes precedence over all the other options and hooks
986 @cindex dedicated window
987 A window can be marked as ``dedicated'' to its buffer. Then
988 @code{display-buffer} will not try to use that window to display any
991 @defun window-dedicated-p window
992 This function returns @code{t} if @var{window} is marked as dedicated;
993 otherwise @code{nil}.
996 @defun set-window-dedicated-p window flag
997 This function marks @var{window} as dedicated if @var{flag} is
998 non-@code{nil}, and nondedicated otherwise.
1002 @section Windows and Point
1003 @cindex window position
1004 @cindex window point
1005 @cindex position in window
1006 @cindex point in window
1008 Each window has its own value of point, independent of the value of
1009 point in other windows displaying the same buffer. This makes it useful
1010 to have multiple windows showing one buffer.
1014 The window point is established when a window is first created; it is
1015 initialized from the buffer's point, or from the window point of another
1016 window opened on the buffer if such a window exists.
1019 Selecting a window sets the value of point in its buffer from the
1020 window's value of point. Conversely, deselecting a window sets the
1021 window's value of point from that of the buffer. Thus, when you switch
1022 between windows that display a given buffer, the point value for the
1023 selected window is in effect in the buffer, while the point values for
1024 the other windows are stored in those windows.
1027 As long as the selected window displays the current buffer, the window's
1028 point and the buffer's point always move together; they remain equal.
1031 @xref{Positions}, for more details on buffer positions.
1034 As far as the user is concerned, point is where the cursor is, and
1035 when the user switches to another buffer, the cursor jumps to the
1036 position of point in that buffer.
1038 @defun window-point window
1039 This function returns the current position of point in @var{window}.
1040 For a nonselected window, this is the value point would have (in that
1041 window's buffer) if that window were selected.
1043 When @var{window} is the selected window and its buffer is also the
1044 current buffer, the value returned is the same as point in that buffer.
1046 Strictly speaking, it would be more correct to return the
1047 ``top-level'' value of point, outside of any @code{save-excursion}
1048 forms. But that value is hard to find.
1051 @defun set-window-point window position
1052 This function positions point in @var{window} at position
1053 @var{position} in @var{window}'s buffer.
1057 @section The Window Start Position
1059 Each window contains a marker used to keep track of a buffer position
1060 that specifies where in the buffer display should start. This position
1061 is called the @dfn{display-start} position of the window (or just the
1062 @dfn{start}). The character after this position is the one that appears
1063 at the upper left corner of the window. It is usually, but not
1064 inevitably, at the beginning of a text line.
1066 @defun window-start &optional window
1067 @cindex window top line
1068 This function returns the display-start position of window
1069 @var{window}. If @var{window} is @code{nil}, the selected window is
1079 When you create a window, or display a different buffer in it, the
1080 display-start position is set to a display-start position recently used
1081 for the same buffer, or 1 if the buffer doesn't have any.
1083 Redisplay updates the window-start position (if you have not specified
1084 it explicitly since the previous redisplay) so that point appears on the
1085 screen. Nothing except redisplay automatically changes the window-start
1086 position; if you move point, do not expect the window-start position to
1087 change in response until after the next redisplay.
1089 For a realistic example of using @code{window-start}, see the
1090 description of @code{count-lines} in @ref{Text Lines}.
1093 @defun window-end &optional window update
1094 This function returns the position of the end of the display in window
1095 @var{window}. If @var{window} is @code{nil}, the selected window is
1098 Simply changing the buffer text or moving point does not update the
1099 value that @code{window-end} returns. The value is updated only when
1100 Emacs redisplays and redisplay completes without being preempted.
1102 If the last redisplay of @var{window} was preempted, and did not finish,
1103 Emacs does not know the position of the end of display in that window.
1104 In that case, this function returns @code{nil}.
1106 If @var{update} is non-@code{nil}, @code{window-end} always returns
1107 an up-to-date value for where the window ends. If the saved value is
1108 valid, @code{window-end} returns that; otherwise it computes the correct
1109 value by scanning the buffer text.
1112 @defun set-window-start window position &optional noforce
1113 This function sets the display-start position of @var{window} to
1114 @var{position} in @var{window}'s buffer. It returns @var{position}.
1116 The display routines insist that the position of point be visible when a
1117 buffer is displayed. Normally, they change the display-start position
1118 (that is, scroll the window) whenever necessary to make point visible.
1119 However, if you specify the start position with this function using
1120 @code{nil} for @var{noforce}, it means you want display to start at
1121 @var{position} even if that would put the location of point off the
1122 screen. If this does place point off screen, the display routines move
1123 point to the left margin on the middle line in the window.
1125 For example, if point @w{is 1} and you set the start of the window @w{to
1126 2}, then point would be ``above'' the top of the window. The display
1127 routines will automatically move point if it is still 1 when redisplay
1128 occurs. Here is an example:
1132 ;; @r{Here is what @samp{foo} looks like before executing}
1133 ;; @r{the @code{set-window-start} expression.}
1137 ---------- Buffer: foo ----------
1138 @point{}This is the contents of buffer foo.
1144 ---------- Buffer: foo ----------
1150 (1+ (window-start)))
1155 ;; @r{Here is what @samp{foo} looks like after executing}
1156 ;; @r{the @code{set-window-start} expression.}
1157 ---------- Buffer: foo ----------
1158 his is the contents of buffer foo.
1164 ---------- Buffer: foo ----------
1168 If @var{noforce} is non-@code{nil}, and @var{position} would place point
1169 off screen at the next redisplay, then redisplay computes a new window-start
1170 position that works well with point, and thus @var{position} is not used.
1173 @defun pos-visible-in-window-p &optional position window
1174 This function returns @code{t} if @var{position} is within the range
1175 of text currently visible on the screen in @var{window}. It returns
1176 @code{nil} if @var{position} is scrolled vertically out of view. The
1177 argument @var{position} defaults to the current position of point;
1178 @var{window}, to the selected window. Here is an example:
1182 (or (pos-visible-in-window-p
1183 (point) (selected-window))
1188 The @code{pos-visible-in-window-p} function considers only vertical
1189 scrolling. If @var{position} is out of view only because @var{window}
1190 has been scrolled horizontally, @code{pos-visible-in-window-p} returns
1191 @code{t}. @xref{Horizontal Scrolling}.
1194 @node Vertical Scrolling
1195 @section Vertical Scrolling
1196 @cindex vertical scrolling
1197 @cindex scrolling vertically
1199 Vertical scrolling means moving the text up or down in a window. It
1200 works by changing the value of the window's display-start location. It
1201 may also change the value of @code{window-point} to keep it on the
1204 In the commands @code{scroll-up} and @code{scroll-down}, the directions
1205 ``up'' and ``down'' refer to the motion of the text in the buffer at which
1206 you are looking through the window. Imagine that the text is
1207 written on a long roll of paper and that the scrolling commands move the
1208 paper up and down. Thus, if you are looking at text in the middle of a
1209 buffer and repeatedly call @code{scroll-down}, you will eventually see
1210 the beginning of the buffer.
1212 Some people have urged that the opposite convention be used: they
1213 imagine that the window moves over text that remains in place. Then
1214 ``down'' commands would take you to the end of the buffer. This view is
1215 more consistent with the actual relationship between windows and the
1216 text in the buffer, but it is less like what the user sees. The
1217 position of a window on the terminal does not move, and short scrolling
1218 commands clearly move the text up or down on the screen. We have chosen
1219 names that fit the user's point of view.
1221 The scrolling functions (aside from @code{scroll-other-window}) have
1222 unpredictable results if the current buffer is different from the buffer
1223 that is displayed in the selected window. @xref{Current Buffer}.
1225 @deffn Command scroll-up &optional count
1226 This function scrolls the text in the selected window upward
1227 @var{count} lines. If @var{count} is negative, scrolling is actually
1230 If @var{count} is @code{nil} (or omitted), then the length of scroll
1231 is @code{next-screen-context-lines} lines less than the usable height of
1232 the window (not counting its mode line).
1234 @code{scroll-up} returns @code{nil}.
1237 @deffn Command scroll-down &optional count
1238 This function scrolls the text in the selected window downward
1239 @var{count} lines. If @var{count} is negative, scrolling is actually
1242 If @var{count} is omitted or @code{nil}, then the length of the scroll
1243 is @code{next-screen-context-lines} lines less than the usable height of
1244 the window (not counting its mode line).
1246 @code{scroll-down} returns @code{nil}.
1249 @deffn Command scroll-other-window &optional count
1250 This function scrolls the text in another window upward @var{count}
1251 lines. Negative values of @var{count}, or @code{nil}, are handled
1252 as in @code{scroll-up}.
1254 You can specify a buffer to scroll with the variable
1255 @code{other-window-scroll-buffer}. When the selected window is the
1256 minibuffer, the next window is normally the one at the top left corner.
1257 You can specify a different window to scroll with the variable
1258 @code{minibuffer-scroll-window}. This variable has no effect when any
1259 other window is selected. @xref{Minibuffer Misc}.
1261 When the minibuffer is active, it is the next window if the selected
1262 window is the one at the bottom right corner. In this case,
1263 @code{scroll-other-window} attempts to scroll the minibuffer. If the
1264 minibuffer contains just one line, it has nowhere to scroll to, so the
1265 line reappears after the echo area momentarily displays the message
1266 ``Beginning of buffer''.
1270 @defvar other-window-scroll-buffer
1271 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
1272 which buffer to scroll.
1275 @tindex scroll-margin
1276 @defopt scroll-margin
1277 This option specifies the size of the scroll margin---a minimum number
1278 of lines between point and the top or bottom of a window. Whenever
1279 point gets within this many lines of the top or bottom of the window,
1280 the window scrolls automatically (if possible) to move point out of the
1281 margin, closer to the center of the window.
1284 @tindex scroll-conservatively
1285 @defopt scroll-conservatively
1286 This variable controls how scrolling is done automatically when point
1287 moves off the screen (or into the scroll margin). If the value is zero,
1288 then redisplay scrolls the text to center point vertically in the
1289 window. If the value is a positive integer @var{n}, then redisplay
1290 scrolls the window up to @var{n} lines in either direction, if that will
1291 bring point back into view. Otherwise, it centers point. The default
1296 This variable is an older variant of @code{scroll-conservatively}. The
1297 difference is that it if its value is @var{n}, that permits scrolling
1298 only by precisely @var{n} lines, not a smaller number. This feature
1299 does not work with @code{scroll-margin}. The default value is zero.
1302 @tindex scroll-preserve-screen-position
1303 @defopt scroll-preserve-screen-position
1304 If this option is non-@code{nil}, the scroll functions move point so
1305 that the vertical position of the cursor is unchanged, when that is
1309 @defopt next-screen-context-lines
1310 The value of this variable is the number of lines of continuity to
1311 retain when scrolling by full screens. For example, @code{scroll-up}
1312 with an argument of @code{nil} scrolls so that this many lines at the
1313 bottom of the window appear instead at the top. The default value is
1317 @deffn Command recenter &optional count
1318 @cindex centering point
1319 This function scrolls the selected window to put the text where point
1320 is located at a specified vertical position within the window.
1322 If @var{count} is a nonnegative number, it puts the line containing
1323 point @var{count} lines down from the top of the window. If @var{count}
1324 is a negative number, then it counts upward from the bottom of the
1325 window, so that @minus{}1 stands for the last usable line in the window.
1326 If @var{count} is a non-@code{nil} list, then it stands for the line in
1327 the middle of the window.
1329 If @var{count} is @code{nil}, @code{recenter} puts the line containing
1330 point in the middle of the window, then clears and redisplays the entire
1333 When @code{recenter} is called interactively, @var{count} is the raw
1334 prefix argument. Thus, typing @kbd{C-u} as the prefix sets the
1335 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
1336 @var{count} to 4, which positions the current line four lines from the
1339 With an argument of zero, @code{recenter} positions the current line at
1340 the top of the window. This action is so handy that some people make a
1341 separate key binding to do this. For example,
1345 (defun line-to-top-of-window ()
1346 "Scroll current line to top of window.
1347 Replaces three keystroke sequence C-u 0 C-l."
1351 (global-set-key [kp-multiply] 'line-to-top-of-window)
1356 @node Horizontal Scrolling
1357 @section Horizontal Scrolling
1358 @cindex horizontal scrolling
1360 Because we read English from left to right in the ``inner loop'', and
1361 from top to bottom in the ``outer loop'', horizontal scrolling is not
1362 like vertical scrolling. Vertical scrolling involves selection of a
1363 contiguous portion of text to display, but horizontal scrolling causes
1364 part of each line to go off screen. The amount of horizontal scrolling
1365 is therefore specified as a number of columns rather than as a position
1366 in the buffer. It has nothing to do with the display-start position
1367 returned by @code{window-start}.
1369 Usually, no horizontal scrolling is in effect; then the leftmost
1370 column is at the left edge of the window. In this state, scrolling to
1371 the right is meaningless, since there is no data to the left of the
1372 screen to be revealed by it; so this is not allowed. Scrolling to the
1373 left is allowed; it scrolls the first columns of text off the edge of
1374 the window and can reveal additional columns on the right that were
1375 truncated before. Once a window has a nonzero amount of leftward
1376 horizontal scrolling, you can scroll it back to the right, but only so
1377 far as to reduce the net horizontal scroll to zero. There is no limit
1378 to how far left you can scroll, but eventually all the text will
1379 disappear off the left edge.
1381 @deffn Command scroll-left count
1382 This function scrolls the selected window @var{count} columns to the
1383 left (or to the right if @var{count} is negative). The return value is
1384 the total amount of leftward horizontal scrolling in effect after the
1385 change---just like the value returned by @code{window-hscroll} (below).
1388 @deffn Command scroll-right count
1389 This function scrolls the selected window @var{count} columns to the
1390 right (or to the left if @var{count} is negative). The return value is
1391 the total amount of leftward horizontal scrolling in effect after the
1392 change---just like the value returned by @code{window-hscroll} (below).
1394 Once you scroll a window as far right as it can go, back to its normal
1395 position where the total leftward scrolling is zero, attempts to scroll
1396 any farther right have no effect.
1399 @defun window-hscroll &optional window
1400 This function returns the total leftward horizontal scrolling of
1401 @var{window}---the number of columns by which the text in @var{window}
1402 is scrolled left past the left margin.
1404 The value is never negative. It is zero when no horizontal scrolling
1405 has been done in @var{window} (which is usually the case).
1407 If @var{window} is @code{nil}, the selected window is used.
1425 @defun set-window-hscroll window columns
1426 This function sets the number of columns from the left margin that
1427 @var{window} is scrolled from the value of @var{columns}. The argument
1428 @var{columns} should be zero or positive; if not, it is taken as zero.
1430 The value returned is @var{columns}.
1434 (set-window-hscroll (selected-window) 10)
1440 Here is how you can determine whether a given position @var{position}
1441 is off the screen due to horizontal scrolling:
1445 (defun hscroll-on-screen (window position)
1447 (goto-char position)
1449 (>= (- (current-column) (window-hscroll window)) 0)
1450 (< (- (current-column) (window-hscroll window))
1451 (window-width window)))))
1455 @node Size of Window
1456 @section The Size of a Window
1458 @cindex size of window
1460 An Emacs window is rectangular, and its size information consists of
1461 the height (the number of lines) and the width (the number of character
1462 positions in each line). The mode line is included in the height. But
1463 the width does not count the scroll bar or the column of @samp{|}
1464 characters that separates side-by-side windows.
1466 The following three functions return size information about a window:
1468 @defun window-height &optional window
1469 This function returns the number of lines in @var{window}, including its
1470 mode line. If @var{window} fills its entire frame, this is typically
1471 one less than the value of @code{frame-height} on that frame (since the
1472 last line is always reserved for the minibuffer).
1474 If @var{window} is @code{nil}, the function uses the selected window.
1482 (split-window-vertically)
1483 @result{} #<window 4 on windows.texi>
1492 @defun window-width &optional window
1493 This function returns the number of columns in @var{window}. If
1494 @var{window} fills its entire frame, this is the same as the value of
1495 @code{frame-width} on that frame. The width does not include the
1496 window's scroll bar or the column of @samp{|} characters that separates
1497 side-by-side windows.
1499 If @var{window} is @code{nil}, the function uses the selected window.
1509 @defun window-edges &optional window
1510 This function returns a list of the edge coordinates of @var{window}.
1511 If @var{window} is @code{nil}, the selected window is used.
1513 The order of the list is @code{(@var{left} @var{top} @var{right}
1514 @var{bottom})}, all elements relative to 0, 0 at the top left corner of
1515 the frame. The element @var{right} of the value is one more than the
1516 rightmost column used by @var{window}, and @var{bottom} is one more than
1517 the bottommost row used by @var{window} and its mode-line.
1519 When you have side-by-side windows, the right edge value for a window
1520 with a neighbor on the right includes the width of the separator between
1521 the window and that neighbor. This separator may be a column of
1522 @samp{|} characters or it may be a scroll bar. Since the width of the
1523 window does not include this separator, the width does not equal the
1524 difference between the right and left edges in this case.
1526 Here is the result obtained on a typical 24-line terminal with just one
1531 (window-edges (selected-window))
1532 @result{} (0 0 80 23)
1537 The bottom edge is at line 23 because the last line is the echo area.
1539 If @var{window} is at the upper left corner of its frame, then
1540 @var{bottom} is the same as the value of @code{(window-height)},
1541 @var{right} is almost the same as the value of
1542 @code{(window-width)}@footnote{They are not exactly equal because
1543 @var{right} includes the vertical separator line or scroll bar, while
1544 @code{(window-width)} does not.}, and @var{top} and @var{left} are zero.
1545 For example, the edges of the following window are @w{@samp{0 0 5 8}}.
1546 Assuming that the frame has more than 8 columns, the last column of the
1547 window (column 7) holds a border rather than text. The last row (row 4)
1548 holds the mode line, shown here with @samp{xxxxxxxxx}.
1564 When there are side-by-side windows, any window not at the right edge of
1565 its frame has a separator in its last column or columns. The separator
1566 counts as one or two columns in the width of the window. A window never
1567 includes a separator on its left, since that belongs to the window to
1570 In the following example, let's suppose that the frame is 7
1571 columns wide. Then the edges of the left window are @w{@samp{0 0 4 3}}
1572 and the edges of the right window are @w{@samp{4 0 7 3}}.
1586 @node Resizing Windows
1587 @section Changing the Size of a Window
1588 @cindex window resizing
1589 @cindex changing window size
1590 @cindex window size, changing
1592 The window size functions fall into two classes: high-level commands
1593 that change the size of windows and low-level functions that access
1594 window size. Emacs does not permit overlapping windows or gaps between
1595 windows, so resizing one window affects other windows.
1597 @deffn Command enlarge-window size &optional horizontal
1598 This function makes the selected window @var{size} lines taller,
1599 stealing lines from neighboring windows. It takes the lines from one
1600 window at a time until that window is used up, then takes from another.
1601 If a window from which lines are stolen shrinks below
1602 @code{window-min-height} lines, that window disappears.
1604 If @var{horizontal} is non-@code{nil}, this function makes
1605 @var{window} wider by @var{size} columns, stealing columns instead of
1606 lines. If a window from which columns are stolen shrinks below
1607 @code{window-min-width} columns, that window disappears.
1609 If the requested size would exceed that of the window's frame, then the
1610 function makes the window occupy the entire height (or width) of the
1613 If @var{size} is negative, this function shrinks the window by
1614 @minus{}@var{size} lines or columns. If that makes the window smaller
1615 than the minimum size (@code{window-min-height} and
1616 @code{window-min-width}), @code{enlarge-window} deletes the window.
1618 @code{enlarge-window} returns @code{nil}.
1621 @deffn Command enlarge-window-horizontally columns
1622 This function makes the selected window @var{columns} wider.
1623 It could be defined as follows:
1627 (defun enlarge-window-horizontally (columns)
1628 (enlarge-window columns t))
1633 @deffn Command shrink-window size &optional horizontal
1634 This function is like @code{enlarge-window} but negates the argument
1635 @var{size}, making the selected window smaller by giving lines (or
1636 columns) to the other windows. If the window shrinks below
1637 @code{window-min-height} or @code{window-min-width}, then it disappears.
1639 If @var{size} is negative, the window is enlarged by @minus{}@var{size}
1643 @deffn Command shrink-window-horizontally columns
1644 This function makes the selected window @var{columns} narrower.
1645 It could be defined as follows:
1649 (defun shrink-window-horizontally (columns)
1650 (shrink-window columns t))
1655 @deffn Command shrink-window-if-larger-than-buffer window
1656 This command shrinks @var{window} to be as small as possible while still
1657 showing the full contents of its buffer---but not less than
1658 @code{window-min-height} lines.
1660 However, the command does nothing if the window is already too small to
1661 display the whole text of the buffer, or if part of the contents are
1662 currently scrolled off screen, or if the window is not the full width of
1663 its frame, or if the window is the only window in its frame.
1666 @cindex minimum window size
1667 The following two variables constrain the window-size-changing
1668 functions to a minimum height and width.
1670 @defopt window-min-height
1671 The value of this variable determines how short a window may become
1672 before it is automatically deleted. Making a window smaller than
1673 @code{window-min-height} automatically deletes it, and no window may be
1674 created shorter than this. The absolute minimum height is two (allowing
1675 one line for the mode line, and one line for the buffer display).
1676 Actions that change window sizes reset this variable to two if it is
1677 less than two. The default value is 4.
1680 @defopt window-min-width
1681 The value of this variable determines how narrow a window may become
1682 before it is automatically deleted. Making a window smaller than
1683 @code{window-min-width} automatically deletes it, and no window may be
1684 created narrower than this. The absolute minimum width is one; any
1685 value below that is ignored. The default value is 10.
1688 @node Coordinates and Windows
1689 @section Coordinates and Windows
1691 This section describes how to relate screen coordinates to windows.
1693 @defun window-at x y &optional frame
1694 This function returns the window containing the specified cursor
1695 position in the frame @var{frame}. The coordinates @var{x} and @var{y}
1696 are measured in characters and count from the top left corner of the
1697 frame. If they are out of range, @code{window-at} returns @code{nil}.
1699 If you omit @var{frame}, the selected frame is used.
1702 @defun coordinates-in-window-p coordinates window
1703 This function checks whether a particular frame position falls within
1704 the window @var{window}.
1706 The argument @var{coordinates} is a cons cell of the form @code{(@var{x}
1707 . @var{y})}. The coordinates @var{x} and @var{y} are measured in
1708 characters, and count from the top left corner of the screen or frame.
1710 The value returned by @code{coordinates-in-window-p} is non-@code{nil}
1711 if the coordinates are inside @var{window}. The value also indicates
1712 what part of the window the position is in, as follows:
1715 @item (@var{relx} . @var{rely})
1716 The coordinates are inside @var{window}. The numbers @var{relx} and
1717 @var{rely} are the equivalent window-relative coordinates for the
1718 specified position, counting from 0 at the top left corner of the
1722 The coordinates are in the mode line of @var{window}.
1724 @item vertical-split
1725 The coordinates are in the vertical line between @var{window} and its
1726 neighbor to the right. This value occurs only if the window doesn't
1727 have a scroll bar; positions in a scroll bar are considered outside the
1731 The coordinates are not in any part of @var{window}.
1734 The function @code{coordinates-in-window-p} does not require a frame as
1735 argument because it always uses the frame that @var{window} is on.
1738 @node Window Configurations
1739 @section Window Configurations
1740 @cindex window configurations
1741 @cindex saving window information
1743 A @dfn{window configuration} records the entire layout of one
1744 frame---all windows, their sizes, which buffers they contain, what part
1745 of each buffer is displayed, and the values of point and the mark. You
1746 can bring back an entire previous layout by restoring a window
1747 configuration previously saved.
1749 If you want to record all frames instead of just one, use a frame
1750 configuration instead of a window configuration. @xref{Frame
1753 @defun current-window-configuration
1754 This function returns a new object representing the selected frame's
1755 current window configuration, including the number of windows, their
1756 sizes and current buffers, which window is the selected window, and for
1757 each window the displayed buffer, the display-start position, and the
1758 positions of point and the mark. It also includes the values of
1759 @code{window-min-height}, @code{window-min-width} and
1760 @code{minibuffer-scroll-window}. An exception is made for point in the
1761 current buffer, whose value is not saved.
1764 @defun set-window-configuration configuration
1765 This function restores the configuration of windows and buffers as
1766 specified by @var{configuration}. The argument @var{configuration} must
1767 be a value that was previously returned by
1768 @code{current-window-configuration}. This configuration is restored in
1769 the frame from which @var{configuration} was made, whether that frame is
1770 selected or not. This always counts as a window size change and
1771 triggers execution of the @code{window-size-change-functions}
1772 (@pxref{Window Hooks}), because @code{set-window-configuration} doesn't
1773 know how to tell whether the new configuration actually differs from the
1776 If the frame which @var{configuration} was saved from is dead, all this
1777 function does is restore the three variables @code{window-min-height},
1778 @code{window-min-width} and @code{minibuffer-scroll-window}.
1780 Here is a way of using this function to get the same effect
1781 as @code{save-window-excursion}:
1785 (let ((config (current-window-configuration)))
1787 (progn (split-window-vertically nil)
1789 (set-window-configuration config)))
1794 @defspec save-window-excursion forms@dots{}
1795 This special form records the window configuration, executes @var{forms}
1796 in sequence, then restores the earlier window configuration. The window
1797 configuration includes the value of point and the portion of the buffer
1798 that is visible. It also includes the choice of selected window.
1799 However, it does not include the value of point in the current buffer;
1800 use @code{save-excursion} also, if you wish to preserve that.
1802 Don't use this construct when @code{save-selected-window} is all you need.
1804 Exit from @code{save-window-excursion} always triggers execution of the
1805 @code{window-size-change-functions}. (It doesn't know how to tell
1806 whether the restored configuration actually differs from the one in
1807 effect at the end of the @var{forms}.)
1809 The return value is the value of the final form in @var{forms}.
1815 @result{} #<window 25 on control.texi>
1818 (setq w (selected-window))
1819 @result{} #<window 19 on control.texi>
1822 (save-window-excursion
1823 (delete-other-windows w)
1824 (switch-to-buffer "foo")
1826 @result{} do-something
1827 ;; @r{The screen is now split again.}
1832 @defun window-configuration-p object
1833 This function returns @code{t} if @var{object} is a window configuration.
1836 @defun compare-window-configurations config1 config2
1837 This function compares two window configurations as regards the
1838 structure of windows, but ignores the values of point and mark and the
1839 saved scrolling positions---it can return @code{t} even if those
1842 The function @code{equal} can also compare two window configurations; it
1843 regards configurations as unequal if they differ in any respect, even a
1844 saved point or mark.
1847 Primitives to look inside of window configurations would make sense,
1848 but none are implemented. It is not clear they are useful enough to be
1852 @section Hooks for Window Scrolling and Changes
1854 This section describes how a Lisp program can take action whenever a
1855 window displays a different part of its buffer or a different buffer.
1856 There are three actions that can change this: scrolling the window,
1857 switching buffers in the window, and changing the size of the window.
1858 The first two actions run @code{window-scroll-functions}; the last runs
1859 @code{window-size-change-functions}. The paradigmatic use of these
1860 hooks is in the implementation of Lazy Lock mode; see @ref{Support
1861 Modes, Lazy Lock, Font Lock Support Modes, emacs, The GNU Emacs Manual}.
1863 @defvar window-scroll-functions
1864 This variable holds a list of functions that Emacs should call before
1865 redisplaying a window with scrolling. It is not a normal hook, because
1866 each function is called with two arguments: the window, and its new
1867 display-start position.
1869 Displaying a different buffer in the window also runs these functions.
1871 These functions must be careful in using @code{window-end}
1872 (@pxref{Window Start}); if you need an up-to-date value, you must use
1873 the @var{update} argument to ensure you get it.
1876 @defvar window-size-change-functions
1877 This variable holds a list of functions to be called if the size of any
1878 window changes for any reason. The functions are called just once per
1879 redisplay, and just once for each frame on which size changes have
1882 Each function receives the frame as its sole argument. There is no
1883 direct way to find out which windows on that frame have changed size, or
1884 precisely how. However, if a size-change function records, at each
1885 call, the existing windows and their sizes, it can also compare the
1886 present sizes and the previous sizes.
1888 Creating or deleting windows counts as a size change, and therefore
1889 causes these functions to be called. Changing the frame size also
1890 counts, because it changes the sizes of the existing windows.
1892 It is not a good idea to use @code{save-window-excursion} (@pxref{Window
1893 Configurations}) in these functions, because that always counts as a
1894 size change, and it would cause these functions to be called over and
1895 over. In most cases, @code{save-selected-window} (@pxref{Selecting
1896 Windows}) is what you need here.
1899 @defvar redisplay-end-trigger-functions
1900 @tindex redisplay-end-trigger-functions
1901 This abnormal hook is run whenever redisplay in a window uses text that
1902 extends past a specified end trigger position. You set the end trigger
1903 position with the function @code{set-window-redisplay-end-trigger}. The
1904 functions are called with two arguments: the window, and the end trigger
1905 position. Storing @code{nil} for the end trigger position turns off the
1906 feature, and the trigger value is automatically reset to @code{nil} just
1907 after the hook is run.
1910 @defun set-window-redisplay-end-trigger window position
1911 @tindex set-window-redisplay-end-trigger
1912 This function sets @var{window}'s end trigger position at
1916 @defun window-redisplay-end-trigger window
1917 @tindex window-redisplay-end-trigger
1918 This function returns @var{window}'s current end trigger position.
1921 @defvar window-configuration-change-hook
1922 @tindex window-configuration-change-hook
1923 A normal hook that is run every time you change the window configuration
1924 of an existing frame. This includes splitting or deleting windows,
1925 changing the sizes of windows, or displaying a different buffer in a
1926 window. The frame whose window configuration has changed is the
1927 selected frame when this hook runs.