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{X 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
256 the other, leaving the selected window with @var{size} lines.
258 This function is simply an interface to @code{split-windows}.
259 Here is the complete function definition for it:
263 (defun split-window-vertically (&optional arg)
264 "Split current window into two windows, @dots{}"
266 (split-window nil (and arg (prefix-numeric-value arg))))
271 @deffn Command split-window-horizontally size
272 This function splits the selected window into two windows
273 side-by-side, leaving the selected window with @var{size} columns.
275 This function is simply an interface to @code{split-windows}. Here is
276 the complete definition for @code{split-window-horizontally} (except for
277 part of the documentation string):
281 (defun split-window-horizontally (&optional arg)
282 "Split selected window into two windows, side by side..."
284 (split-window nil (and arg (prefix-numeric-value arg)) t))
289 @defun one-window-p &optional no-mini all-frames
290 This function returns non-@code{nil} if there is only one window. The
291 argument @var{no-mini}, if non-@code{nil}, means don't count the
292 minibuffer even if it is active; otherwise, the minibuffer window is
293 included, if active, in the total number of windows, which is compared
296 The argument @var{all-frames} specifies which frames to consider. Here
297 are the possible values and their meanings:
301 Count the windows in the selected frame, plus the minibuffer used
302 by that frame even if it lies in some other frame.
305 Count all windows in all existing frames.
308 Count all windows in all visible frames.
311 Count all windows in all visible or iconified frames.
314 Count precisely the windows in the selected frame, and no others.
318 @node Deleting Windows
319 @section Deleting Windows
320 @cindex deleting windows
322 A window remains visible on its frame unless you @dfn{delete} it by
323 calling certain functions that delete windows. A deleted window cannot
324 appear on the screen, but continues to exist as a Lisp object until
325 there are no references to it. There is no way to cancel the deletion
326 of a window aside from restoring a saved window configuration
327 (@pxref{Window Configurations}). Restoring a window configuration also
328 deletes any windows that aren't part of that configuration.
330 When you delete a window, the space it took up is given to one
331 adjacent sibling. (In Emacs version 18, the space was divided evenly
332 among all the siblings.)
335 @defun window-live-p window
336 This function returns @code{nil} if @var{window} is deleted, and
339 @strong{Warning:} Erroneous information or fatal errors may result from
340 using a deleted window as if it were live.
343 @deffn Command delete-window &optional window
344 This function removes @var{window} from the display. If @var{window}
345 is omitted, then the selected window is deleted. An error is signaled
346 if there is only one window when @code{delete-window} is called.
348 This function returns @code{nil}.
350 When @code{delete-window} is called interactively, @var{window}
351 defaults to the selected window.
354 @deffn Command delete-other-windows &optional window
355 This function makes @var{window} the only window on its frame, by
356 deleting the other windows in that frame. If @var{window} is omitted or
357 @code{nil}, then the selected window is used by default.
359 The result is @code{nil}.
362 @deffn Command delete-windows-on buffer &optional frame
363 This function deletes all windows showing @var{buffer}. If there are
364 no windows showing @var{buffer}, it does nothing.
366 @code{delete-windows-on} operates frame by frame. If a frame has
367 several windows showing different buffers, then those showing
368 @var{buffer} are removed, and the others expand to fill the space. If
369 all windows in some frame are showing @var{buffer} (including the case
370 where there is only one window), then the frame reverts to having a
371 single window showing another buffer chosen with @code{other-buffer}.
372 @xref{The Buffer List}.
374 The argument @var{frame} controls which frames to operate on:
378 If it is @code{nil}, operate on the selected frame.
380 If it is @code{t}, operate on all frames.
382 If it is @code{visible}, operate on all visible frames.
384 If it is 0, operate on all visible or iconified frames.
386 If it is a frame, operate on that frame.
389 This function always returns @code{nil}.
392 @node Selecting Windows
393 @section Selecting Windows
394 @cindex selecting windows
396 When a window is selected, the buffer in the window becomes the current
397 buffer, and the cursor will appear in it.
399 @defun selected-window
400 This function returns the selected window. This is the window in
401 which the cursor appears and to which many commands apply.
404 @defun select-window window
405 This function makes @var{window} the selected window. The cursor then
406 appears in @var{window} (on redisplay). The buffer being displayed in
407 @var{window} is immediately designated the current buffer.
409 The return value is @var{window}.
413 (setq w (next-window))
415 @result{} #<window 65 on windows.texi>
420 @defmac save-selected-window forms@dots{}
421 This macro records the selected window, executes @var{forms}
422 in sequence, then restores the earlier selected window.
424 This macro does not save or restore anything about the sizes, arrangement
425 or contents of windows; therefore, if the @var{forms} change them,
428 Each frame, at any time, has a window selected within the frame. This
429 macro only saves @emph{the} selected window; it does not save anything
430 about other frames. If the @var{forms} select some other frame and
431 alter the window selected within it, the change persists.
434 @cindex finding windows
435 The following functions choose one of the windows on the screen,
436 offering various criteria for the choice.
438 @defun get-lru-window &optional frame
439 This function returns the window least recently ``used'' (that is,
440 selected). The selected window is always the most recently used window.
442 The selected window can be the least recently used window if it is the
443 only window. A newly created window becomes the least recently used
444 window until it is selected. A minibuffer window is never a candidate.
446 The argument @var{frame} controls which windows are considered.
450 If it is @code{nil}, consider windows on the selected frame.
452 If it is @code{t}, consider windows on all frames.
454 If it is @code{visible}, consider windows on all visible frames.
456 If it is 0, consider windows on all visible or iconified frames.
458 If it is a frame, consider windows on that frame.
462 @defun get-largest-window &optional frame
463 This function returns the window with the largest area (height times
464 width). If there are no side-by-side windows, then this is the window
465 with the most lines. A minibuffer window is never a candidate.
467 If there are two windows of the same size, then the function returns
468 the window that is first in the cyclic ordering of windows (see
469 following section), starting from the selected window.
471 The argument @var{frame} controls which set of windows are
472 considered. See @code{get-lru-window}, above.
475 @node Cyclic Window Ordering
476 @comment node-name, next, previous, up
477 @section Cyclic Ordering of Windows
478 @cindex cyclic ordering of windows
479 @cindex ordering of windows, cyclic
480 @cindex window ordering, cyclic
482 When you use the command @kbd{C-x o} (@code{other-window}) to select
483 the next window, it moves through all the windows on the screen in a
484 specific cyclic order. For any given configuration of windows, this
485 order never varies. It is called the @dfn{cyclic ordering of windows}.
487 This ordering generally goes from top to bottom, and from left to
488 right. But it may go down first or go right first, depending on the
489 order in which the windows were split.
491 If the first split was vertical (into windows one above each other),
492 and then the subwindows were split horizontally, then the ordering is
493 left to right in the top of the frame, and then left to right in the
494 next lower part of the frame, and so on. If the first split was
495 horizontal, the ordering is top to bottom in the left part, and so on.
496 In general, within each set of siblings at any level in the window tree,
497 the order is left to right, or top to bottom.
499 @defun next-window &optional window minibuf all-frames
500 @cindex minibuffer window
501 This function returns the window following @var{window} in the cyclic
502 ordering of windows. This is the window that @kbd{C-x o} would select
503 if typed when @var{window} is selected. If @var{window} is the only
504 window visible, then this function returns @var{window}. If omitted,
505 @var{window} defaults to the selected window.
507 The value of the argument @var{minibuf} determines whether the
508 minibuffer is included in the window order. Normally, when
509 @var{minibuf} is @code{nil}, the minibuffer is included if it is
510 currently active; this is the behavior of @kbd{C-x o}. (The minibuffer
511 window is active while the minibuffer is in use. @xref{Minibuffers}.)
513 If @var{minibuf} is @code{t}, then the cyclic ordering includes the
514 minibuffer window even if it is not active.
516 If @var{minibuf} is neither @code{t} nor @code{nil}, then the minibuffer
517 window is not included even if it is active.
519 The argument @var{all-frames} specifies which frames to consider. Here
520 are the possible values and their meanings:
524 Consider all the windows in @var{window}'s frame, plus the minibuffer
525 used by that frame even if it lies in some other frame.
528 Consider all windows in all existing frames.
531 Consider all windows in all visible frames. (To get useful results, you
532 must ensure @var{window} is in a visible frame.)
535 Consider all windows in all visible or iconified frames.
538 Consider precisely the windows in @var{window}'s frame, and no others.
541 This example assumes there are two windows, both displaying the
542 buffer @samp{windows.texi}:
547 @result{} #<window 56 on windows.texi>
550 (next-window (selected-window))
551 @result{} #<window 52 on windows.texi>
554 (next-window (next-window (selected-window)))
555 @result{} #<window 56 on windows.texi>
560 @defun previous-window &optional window minibuf all-frames
561 This function returns the window preceding @var{window} in the cyclic
562 ordering of windows. The other arguments specify which windows to
563 include in the cycle, as in @code{next-window}.
566 @deffn Command other-window count
567 This function selects the @var{count}th following window in the cyclic
568 order. If count is negative, then it selects the @minus{}@var{count}th
569 preceding window. It returns @code{nil}.
571 In an interactive call, @var{count} is the numeric prefix argument.
575 @defun walk-windows proc &optional minibuf all-frames
576 This function cycles through all windows, calling @code{proc}
577 once for each window with the window as its sole argument.
579 The optional arguments @var{minibuf} and @var{all-frames} specify the
580 set of windows to include in the scan. See @code{next-window}, above,
584 @node Buffers and Windows
585 @section Buffers and Windows
586 @cindex examining windows
587 @cindex windows, controlling precisely
588 @cindex buffers, controlled in windows
590 This section describes low-level functions to examine windows or to
591 display buffers in windows in a precisely controlled fashion.
593 See the following section for
596 @xref{Displaying Buffers}, for
598 related functions that find a window to use and specify a buffer for it.
599 The functions described there are easier to use than these, but they
600 employ heuristics in choosing or creating a window; use these functions
601 when you need complete control.
603 @defun set-window-buffer window buffer-or-name
604 This function makes @var{window} display @var{buffer-or-name} as its
605 contents. It returns @code{nil}.
609 (set-window-buffer (selected-window) "foo")
615 @defun window-buffer &optional window
616 This function returns the buffer that @var{window} is displaying. If
617 @var{window} is omitted, this function returns the buffer for the
623 @result{} #<buffer windows.texi>
628 @defun get-buffer-window buffer-or-name &optional all-frames
629 This function returns a window currently displaying
630 @var{buffer-or-name}, or @code{nil} if there is none. If there are
631 several such windows, then the function returns the first one in the
632 cyclic ordering of windows, starting from the selected window.
633 @xref{Cyclic Window Ordering}.
635 The argument @var{all-frames} controls which windows to consider.
639 If it is @code{nil}, consider windows on the selected frame.
641 If it is @code{t}, consider windows on all frames.
643 If it is @code{visible}, consider windows on all visible frames.
645 If it is 0, consider windows on all visible or iconified frames.
647 If it is a frame, consider windows on that frame.
651 @defun get-buffer-window-list buffer-or-name &optional minibuf all-frames
652 This function returns a list of all the windows currently displaying
653 @var{buffer-or-name}.
655 The two optional arguments work like the optional arguments of
656 @code{next-window} (@pxref{Cyclic Window Ordering}); they are @emph{not}
657 like the single optional argument of @code{get-buffer-window}. Perhaps
658 we should change @code{get-buffer-window} in the future to make it
659 compatible with the other functions.
661 The argument @var{all-frames} controls which windows to consider.
665 If it is @code{nil}, consider windows on the selected frame.
667 If it is @code{t}, consider windows on all frames.
669 If it is @code{visible}, consider windows on all visible frames.
671 If it is 0, consider windows on all visible or iconified frames.
673 If it is a frame, consider windows on that frame.
677 @node Displaying Buffers
678 @section Displaying Buffers in Windows
679 @cindex switching to a buffer
680 @cindex displaying a buffer
682 In this section we describe convenient functions that choose a window
683 automatically and use it to display a specified buffer. These functions
684 can also split an existing window in certain circumstances. We also
685 describe variables that parameterize the heuristics used for choosing a
688 See the preceding section for
691 @xref{Buffers and Windows}, for
693 low-level functions that give you more precise control.
695 Do not use the functions in this section in order to make a buffer
696 current so that a Lisp program can access or modify it; they are too
697 drastic for that purpose, since they change the display of buffers in
698 windows, which is gratuitous and will surprise the user. Instead, use
699 @code{set-buffer} (@pxref{Current Buffer}) and @code{save-excursion}
700 (@pxref{Excursions}), which designate buffers as current for programmed
701 access without affecting the display of buffers in windows.
703 @deffn Command switch-to-buffer buffer-or-name &optional norecord
704 This function makes @var{buffer-or-name} the current buffer, and also
705 displays the buffer in the selected window. This means that a human can
706 see the buffer and subsequent keyboard commands will apply to it.
707 Contrast this with @code{set-buffer}, which makes @var{buffer-or-name}
708 the current buffer but does not display it in the selected window.
709 @xref{Current Buffer}.
711 If @var{buffer-or-name} does not identify an existing buffer, then a new
712 buffer by that name is created. The major mode for the new buffer is
713 set according to the variable @code{default-major-mode}. @xref{Auto
716 Normally the specified buffer is put at the front of the buffer list.
717 This affects the operation of @code{other-buffer}. However, if
718 @var{norecord} is non-@code{nil}, this is not done. @xref{The Buffer
721 The @code{switch-to-buffer} function is often used interactively, as
722 the binding of @kbd{C-x b}. It is also used frequently in programs. It
723 always returns @code{nil}.
726 @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
727 This function makes @var{buffer-or-name} the current buffer and
728 displays it in a window not currently selected. It then selects that
729 window. The handling of the buffer is the same as in
730 @code{switch-to-buffer}.
732 The currently selected window is absolutely never used to do the job.
733 If it is the only window, then it is split to make a distinct window for
734 this purpose. If the selected window is already displaying the buffer,
735 then it continues to do so, but another window is nonetheless found to
736 display it in as well.
738 This function updates the buffer list just like @code{switch-to-buffer}
739 unless @var{norecord} is non-@code{nil}.
742 @defun pop-to-buffer buffer-or-name &optional other-window norecord
743 This function makes @var{buffer-or-name} the current buffer and
744 switches to it in some window, preferably not the window previously
745 selected. The ``popped-to'' window becomes the selected window within
748 If the variable @code{pop-up-frames} is non-@code{nil},
749 @code{pop-to-buffer} looks for a window in any visible frame already
750 displaying the buffer; if there is one, it returns that window and makes
751 it be selected within its frame. If there is none, it creates a new
752 frame and displays the buffer in it.
754 If @code{pop-up-frames} is @code{nil}, then @code{pop-to-buffer}
755 operates entirely within the selected frame. (If the selected frame has
756 just a minibuffer, @code{pop-to-buffer} operates within the most
757 recently selected frame that was not just a minibuffer.)
759 If the variable @code{pop-up-windows} is non-@code{nil}, windows may
760 be split to create a new window that is different from the original
761 window. For details, see @ref{Choosing Window}.
763 If @var{other-window} is non-@code{nil}, @code{pop-to-buffer} finds or
764 creates another window even if @var{buffer-or-name} is already visible
765 in the selected window. Thus @var{buffer-or-name} could end up
766 displayed in two windows. On the other hand, if @var{buffer-or-name} is
767 already displayed in the selected window and @var{other-window} is
768 @code{nil}, then the selected window is considered sufficient display
769 for @var{buffer-or-name}, so that nothing needs to be done.
771 All the variables that affect @code{display-buffer} affect
772 @code{pop-to-buffer} as well. @xref{Choosing Window}.
774 If @var{buffer-or-name} is a string that does not name an existing
775 buffer, a buffer by that name is created. The major mode for the new
776 buffer is set according to the variable @code{default-major-mode}.
777 @xref{Auto Major Mode}.
779 This function updates the buffer list just like @code{switch-to-buffer}
780 unless @var{norecord} is non-@code{nil}.
783 @deffn Command replace-buffer-in-windows buffer
784 This function replaces @var{buffer} with some other buffer in all
785 windows displaying it. The other buffer used is chosen with
786 @code{other-buffer}. In the usual applications of this function, you
787 don't care which other buffer is used; you just want to make sure that
788 @var{buffer} is no longer displayed.
790 This function returns @code{nil}.
793 @tindex buffer-display-count
794 @defvar buffer-display-count
795 This variable is always local in each buffer. When the buffer is
796 created, @code{buffer-display-count} has value 0. Each time the buffer
797 is displayed in a window, that increments the value of
798 @code{buffer-display-count}.
801 @node Choosing Window
802 @section Choosing a Window for Display
804 This section describes the basic facility that chooses a window to
805 display a buffer in---@code{display-buffer}. All the higher-level
806 functions and commands use this subroutine. Here we describe how to use
807 @code{display-buffer} and how to customize it.
809 @deffn Command display-buffer buffer-or-name &optional not-this-window frame
810 This command makes @var{buffer-or-name} appear in some window, like
811 @code{pop-to-buffer}, but it does not select that window and does not
812 make the buffer current. The identity of the selected window is
813 unaltered by this function.
815 If @var{not-this-window} is non-@code{nil}, it means to display the
816 specified buffer in a window other than the selected one, even if it is
817 already on display in the selected window. This can cause the buffer to
818 appear in two windows at once. Otherwise, if @var{buffer-or-name} is
819 already being displayed in any window, that is good enough, so this
820 function does nothing.
822 @code{display-buffer} returns the window chosen to display
823 @var{buffer-or-name}.
825 If the argument @var{frame} is non-@code{nil}, it specifies which frames
826 to check when deciding whether the buffer is already displayed. Its
827 value means the same thing as in functions @code{get-buffer-window}
828 (@pxref{Buffers and Windows}). If the buffer is already displayed
829 in some window on one of these frames, @code{display-buffer} simply
832 Precisely how @code{display-buffer} finds or creates a window depends on
833 the variables described below.
836 @defopt pop-up-windows
837 This variable controls whether @code{display-buffer} makes new windows.
838 If it is non-@code{nil} and there is only one window, then that window
839 is split. If it is @code{nil}, then @code{display-buffer} does not
840 split the single window, but uses it whole.
843 @defopt split-height-threshold
844 This variable determines when @code{display-buffer} may split a window,
845 if there are multiple windows. @code{display-buffer} always splits the
846 largest window if it has at least this many lines. If the largest
847 window is not this tall, it is split only if it is the sole window and
848 @code{pop-up-windows} is non-@code{nil}.
852 @defopt pop-up-frames
853 This variable controls whether @code{display-buffer} makes new frames.
854 If it is non-@code{nil}, @code{display-buffer} looks for an existing
855 window already displaying the desired buffer, on any visible frame. If
856 it finds one, it returns that window. Otherwise it makes a new frame.
857 The variables @code{pop-up-windows} and @code{split-height-threshold} do
858 not matter if @code{pop-up-frames} is non-@code{nil}.
860 If @code{pop-up-frames} is @code{nil}, then @code{display-buffer} either
861 splits a window or reuses one.
863 @xref{Frames}, for more information.
867 @defvar pop-up-frame-function
868 This variable specifies how to make a new frame if @code{pop-up-frames}
871 Its value should be a function of no arguments. When
872 @code{display-buffer} makes a new frame, it does so by calling that
873 function, which should return a frame. The default value of the
874 variable is a function that creates a frame using parameters from
875 @code{pop-up-frame-alist}.
878 @defvar pop-up-frame-alist
879 This variable holds an alist specifying frame parameters used when
880 @code{display-buffer} makes a new frame. @xref{Frame Parameters}, for
881 more information about frame parameters.
884 @defvar special-display-buffer-names
885 A list of buffer names for buffers that should be displayed specially.
886 If the buffer's name is in this list, @code{display-buffer} handles the
889 By default, special display means to give the buffer a dedicated frame.
891 If an element is a list, instead of a string, then the @sc{car} of the
892 list is the buffer name, and the rest of the list says how to create the
893 frame. There are two possibilities for the rest of the list. It can be
894 an alist, specifying frame parameters, or it can contain a function and
895 arguments to give to it. (The function's first argument is always the
896 buffer to be displayed; the arguments from the list come after that.)
899 @defvar special-display-regexps
900 A list of regular expressions that specify buffers that should be
901 displayed specially. If the buffer's name matches any of the regular
902 expressions in this list, @code{display-buffer} handles the buffer
905 By default, special display means to give the buffer a dedicated frame.
907 If an element is a list, instead of a string, then the @sc{car} of the
908 list is the regular expression, and the rest of the list says how to
909 create the frame. See above, under @code{special-display-buffer-names}.
912 @defvar special-display-function
913 This variable holds the function to call to display a buffer specially.
914 It receives the buffer as an argument, and should return the window in
915 which it is displayed.
917 The default value of this variable is
918 @code{special-display-popup-frame}.
921 @defun special-display-popup-frame buffer
922 This function makes @var{buffer} visible in a frame of its own. If
923 @var{buffer} is already displayed in a window in some frame, it makes
924 the frame visible and raises it, to use that window. Otherwise, it
925 creates a frame that will be dedicated to @var{buffer}.
927 This function uses an existing window displaying @var{buffer} whether or
928 not it is in a frame of its own; but if you set up the above variables
929 in your init file, before @var{buffer} was created, then presumably the
930 window was previously made by this function.
933 @defopt special-display-frame-alist
934 This variable holds frame parameters for
935 @code{special-display-popup-frame} to use when it creates a frame.
938 @defopt same-window-buffer-names
939 A list of buffer names for buffers that should be displayed in the
940 selected window. If the buffer's name is in this list,
941 @code{display-buffer} handles the buffer by switching to it in the
945 @defopt same-window-regexps
946 A list of regular expressions that specify buffers that should be
947 displayed in the selected window. If the buffer's name matches any of
948 the regular expressions in this list, @code{display-buffer} handles the
949 buffer by switching to it in the selected window.
953 @defvar display-buffer-function
954 This variable is the most flexible way to customize the behavior of
955 @code{display-buffer}. If it is non-@code{nil}, it should be a function
956 that @code{display-buffer} calls to do the work. The function should
957 accept two arguments, the same two arguments that @code{display-buffer}
958 received. It should choose or create a window, display the specified
959 buffer, and then return the window.
961 This hook takes precedence over all the other options and hooks
966 @cindex dedicated window
967 A window can be marked as ``dedicated'' to its buffer. Then
968 @code{display-buffer} does not try to use that window.
970 @defun window-dedicated-p window
971 This function returns @code{t} if @var{window} is marked as dedicated;
972 otherwise @code{nil}.
975 @defun set-window-dedicated-p window flag
976 This function marks @var{window} as dedicated if @var{flag} is
977 non-@code{nil}, and nondedicated otherwise.
981 @section Windows and Point
982 @cindex window position
984 @cindex position in window
985 @cindex point in window
987 Each window has its own value of point, independent of the value of
988 point in other windows displaying the same buffer. This makes it useful
989 to have multiple windows showing one buffer.
993 The window point is established when a window is first created; it is
994 initialized from the buffer's point, or from the window point of another
995 window opened on the buffer if such a window exists.
998 Selecting a window sets the value of point in its buffer from the
999 window's value of point. Conversely, deselecting a window sets the
1000 window's value of point from that of the buffer. Thus, when you switch
1001 between windows that display a given buffer, the point value for the
1002 selected window is in effect in the buffer, while the point values for
1003 the other windows are stored in those windows.
1006 As long as the selected window displays the current buffer, the window's
1007 point and the buffer's point always move together; they remain equal.
1010 @xref{Positions}, for more details on buffer positions.
1013 As far as the user is concerned, point is where the cursor is, and
1014 when the user switches to another buffer, the cursor jumps to the
1015 position of point in that buffer.
1017 @defun window-point window
1018 This function returns the current position of point in @var{window}.
1019 For a nonselected window, this is the value point would have (in that
1020 window's buffer) if that window were selected.
1022 When @var{window} is the selected window and its buffer is also the
1023 current buffer, the value returned is the same as point in that buffer.
1025 Strictly speaking, it would be more correct to return the
1026 ``top-level'' value of point, outside of any @code{save-excursion}
1027 forms. But that value is hard to find.
1030 @defun set-window-point window position
1031 This function positions point in @var{window} at position
1032 @var{position} in @var{window}'s buffer.
1036 @section The Window Start Position
1038 Each window contains a marker used to keep track of a buffer position
1039 that specifies where in the buffer display should start. This position
1040 is called the @dfn{display-start} position of the window (or just the
1041 @dfn{start}). The character after this position is the one that appears
1042 at the upper left corner of the window. It is usually, but not
1043 inevitably, at the beginning of a text line.
1045 @defun window-start &optional window
1046 @cindex window top line
1047 This function returns the display-start position of window
1048 @var{window}. If @var{window} is @code{nil}, the selected window is
1058 When you create a window, or display a different buffer in it, the
1059 display-start position is set to a display-start position recently used
1060 for the same buffer, or 1 if the buffer doesn't have any.
1062 Redisplay updates the window-start position (if you have not specified
1063 it explicitly since the previous redisplay) so that point appears on the
1064 screen. Nothing except redisplay automatically changes the window-start
1065 position; if you move point, do not expect the window-start position to
1066 change in response until after the next redisplay.
1068 For a realistic example of using @code{window-start}, see the
1069 description of @code{count-lines} in @ref{Text Lines}.
1072 @defun window-end &optional window
1073 This function returns the position of the end of the display in window
1074 @var{window}. If @var{window} is @code{nil}, the selected window is
1077 Simply changing the buffer text or moving point does not update the
1078 value that @code{window-end} returns. The value is updated only when
1079 Emacs redisplays and redisplay actually finishes.
1081 If the last redisplay of @var{window} was preempted, and did not finish,
1082 Emacs does not know the position of the end of display in that window.
1083 In that case, this function returns a value that is not correct. In a
1084 future version, @code{window-end} will return @code{nil} in that case.
1086 in that case, this function returns @code{nil}. You can compute where
1087 the end of the window @emph{would} have been, if redisplay had finished,
1092 (goto-char (window-start window))
1093 (vertical-motion (1- (window-height window))
1100 @defun set-window-start window position &optional noforce
1101 This function sets the display-start position of @var{window} to
1102 @var{position} in @var{window}'s buffer. It returns @var{position}.
1104 The display routines insist that the position of point be visible when a
1105 buffer is displayed. Normally, they change the display-start position
1106 (that is, scroll the window) whenever necessary to make point visible.
1107 However, if you specify the start position with this function using
1108 @code{nil} for @var{noforce}, it means you want display to start at
1109 @var{position} even if that would put the location of point off the
1110 screen. If this does place point off screen, the display routines move
1111 point to the left margin on the middle line in the window.
1113 For example, if point @w{is 1} and you set the start of the window @w{to
1114 2}, then point would be ``above'' the top of the window. The display
1115 routines will automatically move point if it is still 1 when redisplay
1116 occurs. Here is an example:
1120 ;; @r{Here is what @samp{foo} looks like before executing}
1121 ;; @r{the @code{set-window-start} expression.}
1125 ---------- Buffer: foo ----------
1126 @point{}This is the contents of buffer foo.
1132 ---------- Buffer: foo ----------
1138 (1+ (window-start)))
1143 ;; @r{Here is what @samp{foo} looks like after executing}
1144 ;; @r{the @code{set-window-start} expression.}
1145 ---------- Buffer: foo ----------
1146 his is the contents of buffer foo.
1152 ---------- Buffer: foo ----------
1156 If @var{noforce} is non-@code{nil}, and @var{position} would place point
1157 off screen at the next redisplay, then redisplay computes a new window-start
1158 position that works well with point, and thus @var{position} is not used.
1161 @defun pos-visible-in-window-p &optional position window
1162 This function returns @code{t} if @var{position} is within the range
1163 of text currently visible on the screen in @var{window}. It returns
1164 @code{nil} if @var{position} is scrolled vertically out of view. The
1165 argument @var{position} defaults to the current position of point;
1166 @var{window}, to the selected window. Here is an example:
1170 (or (pos-visible-in-window-p
1171 (point) (selected-window))
1176 The @code{pos-visible-in-window-p} function considers only vertical
1177 scrolling. If @var{position} is out of view only because @var{window}
1178 has been scrolled horizontally, @code{pos-visible-in-window-p} returns
1179 @code{t}. @xref{Horizontal Scrolling}.
1182 @node Vertical Scrolling
1183 @section Vertical Scrolling
1184 @cindex vertical scrolling
1185 @cindex scrolling vertically
1187 Vertical scrolling means moving the text up or down in a window. It
1188 works by changing the value of the window's display-start location. It
1189 may also change the value of @code{window-point} to keep it on the
1192 In the commands @code{scroll-up} and @code{scroll-down}, the directions
1193 ``up'' and ``down'' refer to the motion of the text in the buffer at which
1194 you are looking through the window. Imagine that the text is
1195 written on a long roll of paper and that the scrolling commands move the
1196 paper up and down. Thus, if you are looking at text in the middle of a
1197 buffer and repeatedly call @code{scroll-down}, you will eventually see
1198 the beginning of the buffer.
1200 Some people have urged that the opposite convention be used: they
1201 imagine that the window moves over text that remains in place. Then
1202 ``down'' commands would take you to the end of the buffer. This view is
1203 more consistent with the actual relationship between windows and the
1204 text in the buffer, but it is less like what the user sees. The
1205 position of a window on the terminal does not move, and short scrolling
1206 commands clearly move the text up or down on the screen. We have chosen
1207 names that fit the user's point of view.
1209 The scrolling functions (aside from @code{scroll-other-window}) have
1210 unpredictable results if the current buffer is different from the buffer
1211 that is displayed in the selected window. @xref{Current Buffer}.
1213 @deffn Command scroll-up &optional count
1214 This function scrolls the text in the selected window upward
1215 @var{count} lines. If @var{count} is negative, scrolling is actually
1218 If @var{count} is @code{nil} (or omitted), then the length of scroll
1219 is @code{next-screen-context-lines} lines less than the usable height of
1220 the window (not counting its mode line).
1222 @code{scroll-up} returns @code{nil}.
1225 @deffn Command scroll-down &optional count
1226 This function scrolls the text in the selected window downward
1227 @var{count} lines. If @var{count} is negative, scrolling is actually
1230 If @var{count} is omitted or @code{nil}, then the length of the 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-down} returns @code{nil}.
1237 @deffn Command scroll-other-window &optional count
1238 This function scrolls the text in another window upward @var{count}
1239 lines. Negative values of @var{count}, or @code{nil}, are handled
1240 as in @code{scroll-up}.
1242 You can specify a buffer to scroll with the variable
1243 @code{other-window-scroll-buffer}. When the selected window is the
1244 minibuffer, the next window is normally the one at the top left corner.
1245 You can specify a different window to scroll with the variable
1246 @code{minibuffer-scroll-window}. This variable has no effect when any
1247 other window is selected. @xref{Minibuffer Misc}.
1249 When the minibuffer is active, it is the next window if the selected
1250 window is the one at the bottom right corner. In this case,
1251 @code{scroll-other-window} attempts to scroll the minibuffer. If the
1252 minibuffer contains just one line, it has nowhere to scroll to, so the
1253 line reappears after the echo area momentarily displays the message
1254 ``Beginning of buffer''.
1258 @defvar other-window-scroll-buffer
1259 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
1260 which buffer to scroll.
1264 This variable controls how scrolling is done automatically when point
1265 moves off the screen. If the value is zero, then redisplay scrolls the
1266 text to center point vertically in the window. If the value is a
1267 positive integer @var{n}, then redisplay brings point back on screen by
1268 scrolling @var{n} lines in either direction, if possible; otherwise, it
1269 centers point. The default value is zero.
1272 @defopt next-screen-context-lines
1273 The value of this variable is the number of lines of continuity to
1274 retain when scrolling by full screens. For example, @code{scroll-up}
1275 with an argument of @code{nil} scrolls so that this many lines at the
1276 bottom of the window appear instead at the top. The default value is
1280 @deffn Command recenter &optional count
1281 @cindex centering point
1282 This function scrolls the selected window to put the text where point
1283 is located at a specified vertical position within the window.
1285 If @var{count} is a nonnegative number, it puts the line containing
1286 point @var{count} lines down from the top of the window. If @var{count}
1287 is a negative number, then it counts upward from the bottom of the
1288 window, so that @minus{}1 stands for the last usable line in the window.
1289 If @var{count} is a non-@code{nil} list, then it stands for the line in
1290 the middle of the window.
1292 If @var{count} is @code{nil}, @code{recenter} puts the line containing
1293 point in the middle of the window, then clears and redisplays the entire
1296 When @code{recenter} is called interactively, @var{count} is the raw
1297 prefix argument. Thus, typing @kbd{C-u} as the prefix sets the
1298 @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
1299 @var{count} to 4, which positions the current line four lines from the
1302 With an argument of zero, @code{recenter} positions the current line at
1303 the top of the window. This action is so handy that some people make a
1304 separate key binding to do this. For example,
1308 (defun line-to-top-of-window ()
1309 "Scroll current line to top of window.
1310 Replaces three keystroke sequence C-u 0 C-l."
1314 (global-set-key [kp-multiply] 'line-to-top-of-window)
1319 @node Horizontal Scrolling
1320 @section Horizontal Scrolling
1321 @cindex horizontal scrolling
1323 Because we read English first from top to bottom and second from left
1324 to right, horizontal scrolling is not like vertical scrolling. Vertical
1325 scrolling involves selection of a contiguous portion of text to display.
1326 Horizontal scrolling causes part of each line to go off screen. The
1327 amount of horizontal scrolling is therefore specified as a number of
1328 columns rather than as a position in the buffer. It has nothing to do
1329 with the display-start position returned by @code{window-start}.
1331 Usually, no horizontal scrolling is in effect; then the leftmost
1332 column is at the left edge of the window. In this state, scrolling to
1333 the right is meaningless, since there is no data to the left of the
1334 screen to be revealed by it; so this is not allowed. Scrolling to the
1335 left is allowed; it scrolls the first columns of text off the edge of
1336 the window and can reveal additional columns on the right that were
1337 truncated before. Once a window has a nonzero amount of leftward
1338 horizontal scrolling, you can scroll it back to the right, but only so
1339 far as to reduce the net horizontal scroll to zero. There is no limit
1340 to how far left you can scroll, but eventually all the text will
1341 disappear off the left edge.
1343 @deffn Command scroll-left count
1344 This function scrolls the selected window @var{count} columns to the
1345 left (or to the right if @var{count} is negative). The return value is
1346 the total amount of leftward horizontal scrolling in effect after the
1347 change---just like the value returned by @code{window-hscroll} (below).
1350 @deffn Command scroll-right count
1351 This function scrolls the selected window @var{count} columns to the
1352 right (or to the left if @var{count} is negative). The return value is
1353 the total amount of leftward horizontal scrolling in effect after the
1354 change---just like the value returned by @code{window-hscroll} (below).
1356 Once you scroll a window as far right as it can go, back to its normal
1357 position where the total leftward scrolling is zero, attempts to scroll
1358 any farther right have no effect.
1361 @defun window-hscroll &optional window
1362 This function returns the total leftward horizontal scrolling of
1363 @var{window}---the number of columns by which the text in @var{window}
1364 is scrolled left past the left margin.
1366 The value is never negative. It is zero when no horizontal scrolling
1367 has been done in @var{window} (which is usually the case).
1369 If @var{window} is @code{nil}, the selected window is used.
1387 @defun set-window-hscroll window columns
1388 This function sets the number of columns from the left margin that
1389 @var{window} is scrolled from the value of @var{columns}. The argument
1390 @var{columns} should be zero or positive; if not, it is taken as zero.
1392 The value returned is @var{columns}.
1396 (set-window-hscroll (selected-window) 10)
1402 Here is how you can determine whether a given position @var{position}
1403 is off the screen due to horizontal scrolling:
1407 (defun hscroll-on-screen (window position)
1409 (goto-char position)
1411 (>= (- (current-column) (window-hscroll window)) 0)
1412 (< (- (current-column) (window-hscroll window))
1413 (window-width window)))))
1417 @node Size of Window
1418 @section The Size of a Window
1420 @cindex size of window
1422 An Emacs window is rectangular, and its size information consists of
1423 the height (the number of lines) and the width (the number of character
1424 positions in each line). The mode line is included in the height. But
1425 the width does not count the scroll bar or the column of @samp{|}
1426 characters that separates side-by-side windows.
1428 The following three functions return size information about a window:
1430 @defun window-height &optional window
1431 This function returns the number of lines in @var{window}, including
1432 its mode line. If @var{window} fills its entire frame, this is one less
1433 than the value of @code{frame-height} on that frame (since the last line
1434 is always reserved for the minibuffer).
1436 If @var{window} is @code{nil}, the function uses the selected window.
1444 (split-window-vertically)
1445 @result{} #<window 4 on windows.texi>
1454 @defun window-width &optional window
1455 This function returns the number of columns in @var{window}. If
1456 @var{window} fills its entire frame, this is the same as the value of
1457 @code{frame-width} on that frame. The width does not include the
1458 window's scroll bar or the column of @samp{|} characters that separates
1459 side-by-side windows.
1461 If @var{window} is @code{nil}, the function uses the selected window.
1471 @defun window-edges &optional window
1472 This function returns a list of the edge coordinates of @var{window}.
1473 If @var{window} is @code{nil}, the selected window is used.
1475 The order of the list is @code{(@var{left} @var{top} @var{right}
1476 @var{bottom})}, all elements relative to 0, 0 at the top left corner of
1477 the frame. The element @var{right} of the value is one more than the
1478 rightmost column used by @var{window}, and @var{bottom} is one more than
1479 the bottommost row used by @var{window} and its mode-line.
1481 When you have side-by-side windows, the right edge value for a window
1482 with a neighbor on the right includes the width of the separator between
1483 the window and that neighbor. This separator may be a column of
1484 @samp{|} characters or it may be a scroll bar. Since the width of the
1485 window does not include this separator, the width does not equal the
1486 difference between the right and left edges in this case.
1488 Here is the result obtained on a typical 24-line terminal with just one
1493 (window-edges (selected-window))
1494 @result{} (0 0 80 23)
1499 The bottom edge is at line 23 because the last line is the echo area.
1501 If @var{window} is at the upper left corner of its frame, then
1502 @var{bottom} is the same as the value of @code{(window-height)},
1503 @var{right} is almost the same as the value of
1504 @code{(window-width)}@footnote{They are not exactly equal because
1505 @var{right} includes the vertical separator line or scroll bar, while
1506 @code{(window-width)} does not.}, and @var{top} and @var{left} are zero.
1507 For example, the edges of the following window are @w{@samp{0 0 5 8}}.
1508 Assuming that the frame has more than 8 columns, the last column of the
1509 window (column 7) holds a border rather than text. The last row (row 4)
1510 holds the mode line, shown here with @samp{xxxxxxxxx}.
1526 When there are side-by-side windows, any window not at the right edge of
1527 its frame has a separator in its last column or columns. The separator
1528 counts as one or two columns in the width of the window. A window never
1529 includes a separator on its left, since that belongs to the window to
1532 In the following example, let's suppose that the frame is 7
1533 columns wide. Then the edges of the left window are @w{@samp{0 0 4 3}}
1534 and the edges of the right window are @w{@samp{4 0 7 3}}.
1548 @node Resizing Windows
1549 @section Changing the Size of a Window
1550 @cindex window resizing
1551 @cindex changing window size
1552 @cindex window size, changing
1554 The window size functions fall into two classes: high-level commands
1555 that change the size of windows and low-level functions that access
1556 window size. Emacs does not permit overlapping windows or gaps between
1557 windows, so resizing one window affects other windows.
1559 @deffn Command enlarge-window size &optional horizontal
1560 This function makes the selected window @var{size} lines taller,
1561 stealing lines from neighboring windows. It takes the lines from one
1562 window at a time until that window is used up, then takes from another.
1563 If a window from which lines are stolen shrinks below
1564 @code{window-min-height} lines, that window disappears.
1566 If @var{horizontal} is non-@code{nil}, this function makes
1567 @var{window} wider by @var{size} columns, stealing columns instead of
1568 lines. If a window from which columns are stolen shrinks below
1569 @code{window-min-width} columns, that window disappears.
1571 If the requested size would exceed that of the window's frame, then the
1572 function makes the window occupy the entire height (or width) of the
1575 If @var{size} is negative, this function shrinks the window by
1576 @minus{}@var{size} lines or columns. If that makes the window smaller
1577 than the minimum size (@code{window-min-height} and
1578 @code{window-min-width}), @code{enlarge-window} deletes the window.
1580 @code{enlarge-window} returns @code{nil}.
1583 @deffn Command enlarge-window-horizontally columns
1584 This function makes the selected window @var{columns} wider.
1585 It could be defined as follows:
1589 (defun enlarge-window-horizontally (columns)
1590 (enlarge-window columns t))
1595 @deffn Command shrink-window size &optional horizontal
1596 This function is like @code{enlarge-window} but negates the argument
1597 @var{size}, making the selected window smaller by giving lines (or
1598 columns) to the other windows. If the window shrinks below
1599 @code{window-min-height} or @code{window-min-width}, then it disappears.
1601 If @var{size} is negative, the window is enlarged by @minus{}@var{size}
1605 @deffn Command shrink-window-horizontally columns
1606 This function makes the selected window @var{columns} narrower.
1607 It could be defined as follows:
1611 (defun shrink-window-horizontally (columns)
1612 (shrink-window columns t))
1617 @cindex minimum window size
1618 The following two variables constrain the window-size-changing
1619 functions to a minimum height and width.
1621 @defopt window-min-height
1622 The value of this variable determines how short a window may become
1623 before it is automatically deleted. Making a window smaller than
1624 @code{window-min-height} automatically deletes it, and no window may be
1625 created shorter than this. The absolute minimum height is two (allowing
1626 one line for the mode line, and one line for the buffer display).
1627 Actions that change window sizes reset this variable to two if it is
1628 less than two. The default value is 4.
1631 @defopt window-min-width
1632 The value of this variable determines how narrow a window may become
1633 before it automatically deleted. Making a window smaller than
1634 @code{window-min-width} automatically deletes it, and no window may be
1635 created narrower than this. The absolute minimum width is one; any
1636 value below that is ignored. The default value is 10.
1639 @node Coordinates and Windows
1640 @section Coordinates and Windows
1642 This section describes how to relate screen coordinates to windows.
1644 @defun window-at x y &optional frame
1645 This function returns the window containing the specified cursor
1646 position in the frame @var{frame}. The coordinates @var{x} and @var{y}
1647 are measured in characters and count from the top left corner of the
1648 frame. If they are out of range, @code{window-at} returns @code{nil}.
1650 If you omit @var{frame}, the selected frame is used.
1653 @defun coordinates-in-window-p coordinates window
1654 This function checks whether a particular frame position falls within
1655 the window @var{window}.
1658 The argument @var{coordinates} is a cons cell of this form:
1665 The coordinates @var{x} and @var{y} are measured in characters, and
1666 count from the top left corner of the screen or frame.
1668 The value returned by @code{coordinates-in-window-p} is non-@code{nil}
1669 if the coordinates are inside @var{window}. The value also indicates
1670 what part of the window the position is in, as follows:
1673 @item (@var{relx} . @var{rely})
1674 The coordinates are inside @var{window}. The numbers @var{relx} and
1675 @var{rely} are the equivalent window-relative coordinates for the
1676 specified position, counting from 0 at the top left corner of the
1680 The coordinates are in the mode line of @var{window}.
1682 @item vertical-split
1683 The coordinates are in the vertical line between @var{window} and its
1684 neighbor to the right. This value occurs only if the window doesn't
1685 have a scroll bar; positions in a scroll bar are considered outside the
1689 The coordinates are not in any part of @var{window}.
1692 The function @code{coordinates-in-window-p} does not require a frame as
1693 argument because it always uses the frame that @var{window} is on.
1696 @node Window Configurations
1697 @section Window Configurations
1698 @cindex window configurations
1699 @cindex saving window information
1701 A @dfn{window configuration} records the entire layout of one
1702 frame---all windows, their sizes, which buffers they contain, what part
1703 of each buffer is displayed, and the values of point and the mark. You
1704 can bring back an entire previous layout by restoring a window
1705 configuration previously saved.
1707 If you want to record all frames instead of just one, use a frame
1708 configuration instead of a window configuration. @xref{Frame
1711 @defun current-window-configuration
1712 This function returns a new object representing the selected frame's
1713 current window configuration, including the number of windows, their
1714 sizes and current buffers, which window is the selected window, and for
1715 each window the displayed buffer, the display-start position, and the
1716 positions of point and the mark. An exception is made for point in the
1717 current buffer, whose value is not saved.
1720 @defun set-window-configuration configuration
1721 This function restores the configuration of windows and buffers as
1722 specified by @var{configuration}. The argument @var{configuration} must
1723 be a value that was previously returned by
1724 @code{current-window-configuration}. This function operates on the
1725 frame for which @var{configuration} was made, whether that frame is
1728 This function always counts as a window size change and triggers
1729 execution of the @code{window-size-change-functions}. (It doesn't know
1730 how to tell whether the new configuration actually differs from the old
1733 Here is a way of using this function to get the same effect
1734 as @code{save-window-excursion}:
1738 (let ((config (current-window-configuration)))
1740 (progn (split-window-vertically nil)
1742 (set-window-configuration config)))
1747 @defspec save-window-excursion forms@dots{}
1748 This special form records the window configuration, executes @var{forms}
1749 in sequence, then restores the earlier window configuration. The window
1750 configuration includes the value of point and the portion of the buffer
1751 that is visible. It also includes the choice of selected window.
1752 However, it does not include the value of point in the current buffer;
1753 use @code{save-excursion} also, if you wish to preserve that.
1755 Don't use this construct when @code{save-selected-window} is all you need.
1757 Exit from @code{save-window-excursion} always triggers execution of the
1758 @code{window-size-change-functions}. (It doesn't know how to tell
1759 whether the restored configuration actually differs from the one in
1760 effect at the end of the @var{forms}.)
1762 The return value is the value of the final form in @var{forms}.
1768 @result{} #<window 25 on control.texi>
1771 (setq w (selected-window))
1772 @result{} #<window 19 on control.texi>
1775 (save-window-excursion
1776 (delete-other-windows w)
1777 (switch-to-buffer "foo")
1779 @result{} do-something
1780 ;; @r{The screen is now split again.}
1785 @defun window-configuration-p object
1786 This function returns @code{t} if @var{object} is a window configuration.
1789 Primitives to look inside of window configurations would make sense,
1790 but none are implemented. It is not clear they are useful enough to be
1794 @section Hooks for Window Scrolling and Changes
1796 This section describes how a Lisp program can take action whenever a
1797 window displays a different part of its buffer or a different buffer.
1798 There are three actions that can change this: scrolling the window,
1799 switching buffers in the window, and changing the size of the window.
1800 The first two actions run @code{window-scroll-functions}; the last runs
1801 @code{window-size-change-functions}. The paradigmatic use of these
1802 hooks is Lazy Lock mode; see @ref{Support Modes, Lazy Lock, Font Lock
1803 Support Modes, emacs, The GNU Emacs Manual}.
1805 @defvar window-scroll-functions
1806 This variable holds a list of functions that Emacs should call before
1807 redisplaying a window with scrolling. It is not a normal hook, because
1808 each function is called with two arguments: the window, and its new
1809 display-start position.
1811 Displaying a different buffer in the window also runs these functions.
1813 These functions cannot expect @code{window-end} (@pxref{Window Start})
1814 to return a meaningful value, because that value is updated only by
1815 redisplaying the buffer. So if one of these functions needs to know the
1816 last character that will fit in the window with its current
1817 display-start position, it has to find that character using
1818 @code{vertical-motion} (@pxref{Screen Lines}).
1821 @defvar window-size-change-functions
1822 This variable holds a list of functions to be called if the size of any
1823 window changes for any reason. The functions are called just once per
1824 redisplay, and just once for each frame on which size changes have
1827 Each function receives the frame as its sole argument. There is no
1828 direct way to find out which windows on that frame have changed size, or
1829 precisely how. However, if a size-change function records, at each
1830 call, the existing windows and their sizes, it can also compare the
1831 present sizes and the previous sizes.
1833 Creating or deleting windows counts as a size change, and therefore
1834 causes these functions to be called. Changing the frame size also
1835 counts, because it changes the sizes of the existing windows.
1837 It is not a good idea to use @code{save-window-excursion} (@pxref{Window
1838 Configurations}) in these functions, because that always counts as a
1839 size change, and it would cause these functions to be called over and
1840 over. In most cases, @code{save-selected-window} (@pxref{Selecting
1841 Windows}) is what you need here.
1844 @tindex redisplay-end-trigger-functions
1845 @defvar redisplay-end-trigger-functions
1846 This abnormal hook is run whenever redisplay in window uses text that
1847 extends past a specified end trigger position. You set the end trigger
1848 position with the function @code{set-window-redisplay-end-trigger}. The
1849 functions are called with two arguments: the window, and the end trigger
1850 position. Storing @code{nil} for the end trigger position turns off the
1851 feature, and the trigger value is automatically reset to @code{nil} just
1852 after the hook is run.
1855 @tindex set-window-redisplay-end-trigger
1856 @defun set-window-redisplay-end-trigger window position
1857 This function sets @var{window}'s end trigger position at
1861 @tindex window-redisplay-end-trigger
1862 @defun window-redisplay-end-trigger window
1863 This function returns @var{window}'s current end trigger position.
1866 @tindex window-configuration-change-hook
1867 @defvar window-configuration-change-hook
1868 A normal hook that is run every time you change the window configuration
1869 of an existing frame. This includes splitting or deleting windows,
1870 changing the sizes of windows, or displaying a different buffer in a
1871 window. The frame whose window configuration has changed is the
1872 selected frame when this hook runs.