(struct window): New member height_fixed_p.
[bpt/emacs.git] / lispref / windows.texi
index bafca4e..2930746 100644 (file)
@@ -1,6 +1,6 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. 
+@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc.
 @c See the file elisp.texi for copying conditions.
 @setfilename ../info/windows
 @node Windows, Frames, Buffers, Top
@@ -11,24 +11,27 @@ Emacs windows.  See @ref{Display}, for information on how text is
 displayed in windows.
 
 @menu
-* Basic Windows::          Basic information on using windows.
-* Splitting Windows::      Splitting one window into two windows.
-* Deleting Windows::       Deleting a window gives its space to other windows.
-* Selecting Windows::      The selected window is the one that you edit in.
-* Cyclic Window Ordering:: Moving around the existing windows.
-* Buffers and Windows::    Each window displays the contents of a buffer.
-* Displaying Buffers::     Higher-lever functions for displaying a buffer
-                             and choosing a window for it.
-* Choosing Window::       How to choose a window for displaying a buffer.
-* Window Point::           Each window has its own location of point.
-* Window Start::           The display-start position controls which text
-                             is on-screen in the window. 
-* Vertical Scrolling::     Moving text up and down in the window.
-* Horizontal Scrolling::   Moving text sideways on the window.
-* Size of Window::         Accessing the size of a window.
-* Resizing Windows::       Changing the size of a window.
-* Coordinates and Windows::Converting coordinates to windows.
-* Window Configurations::  Saving and restoring the state of the screen.
+* Basic Windows::           Basic information on using windows.
+* Splitting Windows::       Splitting one window into two windows.
+* Deleting Windows::        Deleting a window gives its space to other windows.
+* Selecting Windows::       The selected window is the one that you edit in.
+* Cyclic Window Ordering::  Moving around the existing windows.
+* Buffers and Windows::     Each window displays the contents of a buffer.
+* Displaying Buffers::      Higher-lever functions for displaying a buffer
+                              and choosing a window for it.
+* Choosing Window::        How to choose a window for displaying a buffer.
+* Window Point::            Each window has its own location of point.
+* Window Start::            The display-start position controls which text
+                              is on-screen in the window.
+* Vertical Scrolling::      Moving text up and down in the window.
+* Horizontal Scrolling::    Moving text sideways on the window.
+* Size of Window::          Accessing the size of a window.
+* Resizing Windows::        Changing the size of a window.
+* Coordinates and Windows:: Converting coordinates to windows.
+* Window Configurations::   Saving and restoring the state of the screen.
+* Window Hooks::            Hooks for scrolling, window size changes,
+                              redisplay going past a certain point,
+                              or window configuration changes.
 @end menu
 
 @node Basic Windows
@@ -36,25 +39,29 @@ displayed in windows.
 @cindex window
 @cindex selected window
 
-  A @dfn{window} is the physical area of the screen in which a buffer is
-displayed.  The term is also used to refer to a Lisp object that
+  A @dfn{window} in Emacs is the physical area of the screen in which a
+buffer is displayed.  The term is also used to refer to a Lisp object that
 represents that screen area in Emacs Lisp.  It should be
 clear from the context which is meant.
 
-  There is always at least one window in any frame.  In each frame, at
-any time, one and only one window is designated as @dfn{selected within
-the frame}.  The frame's cursor appears in that window.  There is also
-one selected frame; and the window selected within that frame is
-@dfn{the selected window}.  The selected window's buffer is usually the
-current buffer (except when @code{set-buffer} has been used).
-@xref{Current Buffer}.
-
-  For practical purposes, a window exists only while it is displayed on the
-terminal.  Once removed from the display, the window is effectively
-deleted and should not be used, @emph{even though there may still be
-references to it} from other Lisp objects.  Restoring a saved window
-configuration is the only way for a window no longer on the screen to
-come back to life.  (@xref{Deleting Windows}.)
+  Emacs groups windows into frames.  A frame represents an area of
+screen available for Emacs to use.  Each frame always contains at least
+one window, but you can subdivide it vertically or horizontally into
+multiple nonoverlapping Emacs windows.
+
+  In each frame, at any time, one and only one window is designated as
+@dfn{selected within the frame}.  The frame's cursor appears in that
+window.  At any time, one frame is the selected frame; and the window
+selected within that frame is @dfn{the selected window}.  The selected
+window's buffer is usually the current buffer (except when
+@code{set-buffer} has been used).  @xref{Current Buffer}.
+
+  For practical purposes, a window exists only while it is displayed in
+a frame.  Once removed from the frame, the window is effectively deleted
+and should not be used, @emph{even though there may still be references
+to it} from other Lisp objects.  Restoring a saved window configuration
+is the only way for a window no longer on the screen to come back to
+life.  (@xref{Deleting Windows}.)
 
   Each window has the following attributes:
 
@@ -62,64 +69,63 @@ come back to life.  (@xref{Deleting Windows}.)
 @item
 containing frame
 
-@item 
+@item
 window height
 
-@item 
+@item
 window width
 
-@item 
+@item
 window edges with respect to the screen or frame
 
-@item 
+@item
 the buffer it displays
 
-@item 
+@item
 position within the buffer at the upper left of the window
 
-@item 
+@item
 amount of horizontal scrolling, in columns
 
-@item 
+@item
 point
 
-@item 
+@item
 the mark
 
-@item 
+@item
 how recently the window was selected
 @end itemize
 
 @cindex multiple windows
   Users create multiple windows so they can look at several buffers at
 once.  Lisp libraries use multiple windows for a variety of reasons, but
-most often to give different views of the same information.  In Rmail,
-for example, you can move through a summary buffer in one window while
-the other window shows messages one at a time as they are reached.
+most often to display related information.  In Rmail, for example, you
+can move through a summary buffer in one window while the other window
+shows messages one at a time as they are reached.
 
   The meaning of ``window'' in Emacs is similar to what it means in the
 context of general-purpose window systems such as X, but not identical.
-The X Window System subdivides the screen into X windows; Emacs uses one
-or more X windows, called @dfn{frames} in Emacs terminology, and
-subdivides each of them into (nonoverlapping) Emacs windows.  When you
-use Emacs on an ordinary display terminal, Emacs subdivides the terminal
-screen into Emacs windows.
+The X Window System places X windows on the screen; Emacs uses one or
+more X windows as frames, and subdivides them into
+Emacs windows.  When you use Emacs on a character-only terminal, Emacs
+treats the whole terminal screen as one frame.
 
 @cindex terminal screen
 @cindex screen of terminal
 @cindex tiled windows
   Most window systems support arbitrarily located overlapping windows.
 In contrast, Emacs windows are @dfn{tiled}; they never overlap, and
-together they fill the whole screen or frame.  Because of the way
-in which Emacs creates new windows and resizes them, you can't create
-every conceivable tiling of windows on an Emacs frame.  @xref{Splitting
-Windows}, and @ref{Size of Window}.
+together they fill the whole screen or frame.  Because of the way in
+which Emacs creates new windows and resizes them, not all conceivable
+tilings of windows on an Emacs frame are actually possible.
+@xref{Splitting Windows}, and @ref{Size of Window}.
 
   @xref{Display}, for information on how the contents of the
 window's buffer are displayed in the window.
 
 @defun windowp object
-  This function returns @code{t} if @var{object} is a window.
+This function returns @code{t} if @var{object} is a window.
 @end defun
 
 @node Splitting Windows
@@ -170,7 +176,7 @@ lines high by 80 columns wide; then the window is split.
 
 @group
 ;; @r{Returns window created}
-(setq w2 (split-window w 15))   
+(setq w2 (split-window w 15))
      @result{} #<window 28 on windows.texi>
 @end group
 @group
@@ -188,8 +194,8 @@ The screen looks like this:
 
 @smallexample
 @group
-         __________ 
-        |          |  line 0  
+         __________
+        |          |  line 0
         |    w     |
         |__________|
         |          |  line 15
@@ -221,13 +227,14 @@ Next, the top window is split horizontally:
 @end group
 @end smallexample
 
+@need 3000
 Now, the screen looks like this:
 
 @smallexample
 @group
      column 35
-         __________ 
-        |   |      |  line 0  
+         __________
+        |   |      |  line 0
         | w |  w3  |
         |___|______|
         |          |  line 15
@@ -237,19 +244,27 @@ Now, the screen looks like this:
  column 0   column 80
 @end group
 @end smallexample
+
+Normally, Emacs indicates the border between two side-by-side windows
+with a scroll bar (@pxref{Window Frame Parameters,Scroll Bars}) or @samp{|}
+characters.  The display table can specify alternative border
+characters; see @ref{Display Tables}.
 @end deffn
 
 @deffn Command split-window-vertically size
-This function splits the selected window into two windows, one above
-the other, leaving the selected window with @var{size} lines.
+This function splits the selected window into two windows, one above the
+other, leaving the upper of the two windows selected, with @var{size}
+lines.  (If @var{size} is negative, then the lower of the two windows
+gets @minus{} @var{size} lines and the upper window gets the rest, but
+the upper window is still the one selected.)
 
-This function is simply an interface to @code{split-windows}.
+This function is simply an interface to @code{split-window}.
 Here is the complete function definition for it:
 
 @smallexample
 @group
 (defun split-window-vertically (&optional arg)
-  "Split current window into two windows, one above the other."
+  "Split current window into two windows, @dots{}"
   (interactive "P")
   (split-window nil (and arg (prefix-numeric-value arg))))
 @end group
@@ -260,7 +275,7 @@ Here is the complete function definition for it:
 This function splits the selected window into two windows
 side-by-side, leaving the selected window with @var{size} columns.
 
-This function is simply an interface to @code{split-windows}.  Here is
+This function is simply an interface to @code{split-window}.  Here is
 the complete definition for @code{split-window-horizontally} (except for
 part of the documentation string):
 
@@ -278,7 +293,7 @@ part of the documentation string):
 This function returns non-@code{nil} if there is only one window.  The
 argument @var{no-mini}, if non-@code{nil}, means don't count the
 minibuffer even if it is active; otherwise, the minibuffer window is
-included, if active, in the total number of windows,  which is compared
+included, if active, in the total number of windows, which is compared
 against one.
 
 The argument @var{all-frames} specifies which frames to consider.  Here
@@ -295,6 +310,9 @@ Count all windows in all existing frames.
 @item @code{visible}
 Count all windows in all visible frames.
 
+@item 0
+Count all windows in all visible or iconified frames.
+
 @item anything else
 Count precisely the windows in the selected frame, and no others.
 @end table
@@ -313,8 +331,7 @@ of a window aside from restoring a saved window configuration
 deletes any windows that aren't part of that configuration.
 
   When you delete a window, the space it took up is given to one
-adjacent sibling.  (In Emacs version 18, the space was divided evenly
-among all the siblings.)
+adjacent sibling.
 
 @c Emacs 19 feature
 @defun window-live-p window
@@ -326,14 +343,10 @@ using a deleted window as if it were live.
 @end defun
 
 @deffn Command delete-window &optional window
-This function removes @var{window} from the display.  If @var{window}
-is omitted, then the selected window is deleted.  An error is signaled
-if there is only one window when @code{delete-window} is called.
-
-This function returns @code{nil}.
-
-When @code{delete-window} is called interactively, @var{window}
-defaults to the selected window.
+This function removes @var{window} from display, and returns @code{nil}.
+If @var{window} is omitted, then the selected window is deleted.  An
+error is signaled if there is only one window when @code{delete-window}
+is called.
 @end deffn
 
 @deffn Command delete-other-windows &optional window
@@ -341,7 +354,7 @@ This function makes @var{window} the only window on its frame, by
 deleting the other windows in that frame.  If @var{window} is omitted or
 @code{nil}, then the selected window is used by default.
 
-The result is @code{nil}.
+The return value is @code{nil}.
 @end deffn
 
 @deffn Command delete-windows-on buffer &optional frame
@@ -356,16 +369,22 @@ where there is only one window), then the frame reverts to having a
 single window showing another buffer chosen with @code{other-buffer}.
 @xref{The Buffer List}.
 
-The argument @var{frame} controls which frames to operate on:
+The argument @var{frame} controls which frames to operate on.  This
+function does not use it in quite the same way as the other functions
+which scan all windows; specifically, the values @code{t} and @code{nil}
+have the opposite of their meanings in other functions.  Here are the
+full details:
 
 @itemize @bullet
 @item
-If it is @code{nil}, operate on the selected frame.
+If it is @code{nil}, operate on all frames.
 @item
-If it is @code{t}, operate on all frames.
+If it is @code{t}, operate on the selected frame.
 @item
 If it is @code{visible}, operate on all visible frames.
 @item
+If it is 0, operate on all visible or iconified frames.
+@item
 If it is a frame, operate on that frame.
 @end itemize
 
@@ -400,6 +419,20 @@ The return value is @var{window}.
 @end example
 @end defun
 
+@defmac save-selected-window forms@dots{}
+This macro records the selected window, executes @var{forms}
+in sequence, then restores the earlier selected window.
+
+This macro does not save or restore anything about the sizes, arrangement
+or contents of windows; therefore, if the @var{forms} change them,
+the change persists.
+
+Each frame, at any time, has a window selected within the frame.  This
+macro saves only @emph{the} selected window; it does not save anything
+about other frames.  If the @var{forms} select some other frame and
+alter the window selected within it, the change persists.
+@end defmac
+
 @cindex finding windows
   The following functions choose one of the windows on the screen,
 offering various criteria for the choice.
@@ -422,6 +455,8 @@ If it is @code{t}, consider windows on all frames.
 @item
 If it is @code{visible}, consider windows on all visible frames.
 @item
+If it is 0, consider windows on all visible or iconified frames.
+@item
 If it is a frame, consider windows on that frame.
 @end itemize
 @end defun
@@ -435,8 +470,8 @@ If there are two windows of the same size, then the function returns
 the window that is first in the cyclic ordering of windows (see
 following section), starting from the selected window.
 
-The argument @var{frame} controls which set of windows are
-considered.  See @code{get-lru-window}, above.
+The argument @var{frame} controls which set of windows to
+consider.  See @code{get-lru-window}, above.
 @end defun
 
 @node Cyclic Window Ordering
@@ -444,7 +479,7 @@ considered.  See @code{get-lru-window}, above.
 @section Cyclic Ordering of Windows
 @cindex cyclic ordering of windows
 @cindex ordering of windows, cyclic
-@cindex window ordering, cyclic 
+@cindex window ordering, cyclic
 
   When you use the command @kbd{C-x o} (@code{other-window}) to select
 the next window, it moves through all the windows on the screen in a
@@ -498,11 +533,14 @@ Consider all windows in all existing frames.
 Consider all windows in all visible frames.  (To get useful results, you
 must ensure @var{window} is in a visible frame.)
 
+@item 0
+Consider all windows in all visible or iconified frames.
+
 @item anything else
 Consider precisely the windows in @var{window}'s frame, and no others.
 @end table
 
-This example assumes there are two windows, both displaying the 
+This example assumes there are two windows, both displaying the
 buffer @samp{windows.texi}:
 
 @example
@@ -529,8 +567,8 @@ include in the cycle, as in @code{next-window}.
 
 @deffn Command other-window count
 This function selects the @var{count}th following window in the cyclic
-order.  If count is negative, then it selects the @minus{}@var{count}th
-preceding window.  It returns @code{nil}.
+order.  If count is negative, then it moves back @minus{}@var{count}
+windows in the cycle, rather than forward.  It returns @code{nil}.
 
 In an interactive call, @var{count} is the numeric prefix argument.
 @end deffn
@@ -566,7 +604,9 @@ when you need complete control.
 
 @defun set-window-buffer window buffer-or-name
 This function makes @var{window} display @var{buffer-or-name} as its
-contents.  It returns @code{nil}.
+contents.  It returns @code{nil}.  This is the fundamental primitive
+for changing which buffer is displayed in a window, and all ways
+of doing that call this function.
 
 @example
 @group
@@ -606,19 +646,47 @@ If it is @code{t}, consider windows on all frames.
 @item
 If it is @code{visible}, consider windows on all visible frames.
 @item
+If it is 0, consider windows on all visible or iconified frames.
+@item
 If it is a frame, consider windows on that frame.
 @end itemize
 @end defun
 
-@deffn Command replace-buffer-in-windows buffer
-This function replaces @var{buffer} with some other buffer in all
-windows displaying it.  The other buffer used is chosen with
-@code{other-buffer}.  In the usual applications of this function, you
-don't care which other buffer is used; you just want to make sure that
-@var{buffer} is no longer displayed.
+@defun get-buffer-window-list buffer-or-name &optional minibuf all-frames
+This function returns a list of all the windows currently displaying
+@var{buffer-or-name}.
 
-This function returns @code{nil}.
-@end deffn
+The two optional arguments work like the optional arguments of
+@code{next-window} (@pxref{Cyclic Window Ordering}); they are @emph{not}
+like the single optional argument of @code{get-buffer-window}.  Perhaps
+we should change @code{get-buffer-window} in the future to make it
+compatible with the other functions.
+
+The argument @var{all-frames} controls which windows to consider.
+
+@itemize @bullet
+@item
+If it is @code{nil}, consider windows on the selected frame.
+@item
+If it is @code{t}, consider windows on all frames.
+@item
+If it is @code{visible}, consider windows on all visible frames.
+@item
+If it is 0, consider windows on all visible or iconified frames.
+@item
+If it is a frame, consider windows on that frame.
+@end itemize
+@end defun
+
+@defvar buffer-display-time
+@tindex buffer-display-time
+This variable records the time at which a buffer was last made visible
+in a window.  It is always local in each buffer; each time
+@code{set-window-buffer} is called, it sets this variable to
+@code{(current-time)} in the specified buffer (@pxref{Time of Day}).
+When a buffer is first created, @code{buffer-display-time} starts out
+with the value @code{nil}.
+@end defvar
 
 @node Displaying Buffers
 @section Displaying Buffers in Windows
@@ -636,15 +704,16 @@ See the preceding section for
 @ifinfo
 @xref{Buffers and Windows}, for
 @end ifinfo
-low-level functions that give you more precise control.
+low-level functions that give you more precise control.  All of these
+functions work by calling @code{set-window-buffer}.
 
   Do not use the functions in this section in order to make a buffer
 current so that a Lisp program can access or modify it; they are too
 drastic for that purpose, since they change the display of buffers in
-windows, which is gratuitous and will surprise the user.  Instead, use
-@code{set-buffer} (@pxref{Current Buffer}) and @code{save-excursion}
-(@pxref{Excursions}), which designate buffers as current for programmed
-access without affecting the display of buffers in windows.
+windows, which would be gratuitous and surprise the user.  Instead, use
+@code{set-buffer} and @code{save-current-buffer} (@pxref{Current
+Buffer}), which designate buffers as current for programmed access
+without affecting the display of buffers in windows.
 
 @deffn Command switch-to-buffer buffer-or-name &optional norecord
 This function makes @var{buffer-or-name} the current buffer, and also
@@ -654,11 +723,14 @@ Contrast this with @code{set-buffer}, which makes @var{buffer-or-name}
 the current buffer but does not display it in the selected window.
 @xref{Current Buffer}.
 
-If @var{buffer-or-name} does not identify an existing buffer, then
-a new buffer by that name is created.
+If @var{buffer-or-name} does not identify an existing buffer, then a new
+buffer by that name is created.  The major mode for the new buffer is
+set according to the variable @code{default-major-mode}.  @xref{Auto
+Major Mode}.
 
-Normally the specified buffer is put at the front of the buffer list.
-This affects the operation of @code{other-buffer}.  However, if
+Normally the specified buffer is put at the front of the buffer list
+(both the selected frame's buffer list and the frame-independent buffer
+list).  This affects the operation of @code{other-buffer}.  However, if
 @var{norecord} is non-@code{nil}, this is not done.  @xref{The Buffer
 List}.
 
@@ -667,7 +739,7 @@ the binding of @kbd{C-x b}.  It is also used frequently in programs.  It
 always returns @code{nil}.
 @end deffn
 
-@deffn Command switch-to-buffer-other-window buffer-or-name
+@deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
 This function makes @var{buffer-or-name} the current buffer and
 displays it in a window not currently selected.  It then selects that
 window.  The handling of the buffer is the same as in
@@ -678,9 +750,12 @@ If it is the only window, then it is split to make a distinct window for
 this purpose.  If the selected window is already displaying the buffer,
 then it continues to do so, but another window is nonetheless found to
 display it in as well.
+
+This function updates the buffer list just like @code{switch-to-buffer}
+unless @var{norecord} is non-@code{nil}.
 @end deffn
 
-@defun pop-to-buffer buffer-or-name &optional other-window
+@defun pop-to-buffer buffer-or-name &optional other-window norecord
 This function makes @var{buffer-or-name} the current buffer and
 switches to it in some window, preferably not the window previously
 selected.  The ``popped-to'' window becomes the selected window within
@@ -709,10 +784,28 @@ already displayed in the selected window and @var{other-window} is
 @code{nil}, then the selected window is considered sufficient display
 for @var{buffer-or-name}, so that nothing needs to be done.
 
+All the variables that affect @code{display-buffer} affect
+@code{pop-to-buffer} as well.  @xref{Choosing Window}.
+
 If @var{buffer-or-name} is a string that does not name an existing
-buffer, a buffer by that name is created.
+buffer, a buffer by that name is created.  The major mode for the new
+buffer is set according to the variable @code{default-major-mode}.
+@xref{Auto Major Mode}.
+
+This function updates the buffer list just like @code{switch-to-buffer}
+unless @var{norecord} is non-@code{nil}.
 @end defun
 
+@deffn Command replace-buffer-in-windows buffer
+This function replaces @var{buffer} with some other buffer in all
+windows displaying it.  The other buffer used is chosen with
+@code{other-buffer}.  In the usual applications of this function, you
+don't care which other buffer is used; you just want to make sure that
+@var{buffer} is no longer displayed.
+
+This function returns @code{nil}.
+@end deffn
+
 @node Choosing Window
 @section Choosing a Window for Display
 
@@ -721,7 +814,7 @@ display a buffer in---@code{display-buffer}.  All the higher-level
 functions and commands use this subroutine.  Here we describe how to use
 @code{display-buffer} and how to customize it.
 
-@deffn Command display-buffer buffer-or-name &optional not-this-window
+@deffn Command display-buffer buffer-or-name &optional not-this-window frame
 This command makes @var{buffer-or-name} appear in some window, like
 @code{pop-to-buffer}, but it does not select that window and does not
 make the buffer current.  The identity of the selected window is
@@ -737,6 +830,25 @@ function does nothing.
 @code{display-buffer} returns the window chosen to display
 @var{buffer-or-name}.
 
+If the argument @var{frame} is non-@code{nil}, it specifies which frames
+to check when deciding whether the buffer is already displayed.  If the
+buffer is already displayed in some window on one of these frames,
+@code{display-buffer} simply returns that window.  Here are the possible
+values of @var{frame}:
+
+@itemize @bullet
+@item
+If it is @code{nil}, consider windows on the selected frame.
+@item
+If it is @code{t}, consider windows on all frames.
+@item
+If it is @code{visible}, consider windows on all visible frames.
+@item
+If it is 0, consider windows on all visible or iconified frames.
+@item
+If it is a frame, consider windows on that frame.
+@end itemize
+
 Precisely how @code{display-buffer} finds or creates a window depends on
 the variables described below.
 @end deffn
@@ -789,22 +901,33 @@ This variable holds an alist specifying frame parameters used when
 more information about frame parameters.
 @end defvar
 
-@defvar special-display-buffer-names
+@defopt special-display-buffer-names
 A list of buffer names for buffers that should be displayed specially.
 If the buffer's name is in this list, @code{display-buffer} handles the
 buffer specially.
 
 By default, special display means to give the buffer a dedicated frame.
-@end defvar
 
-@defvar special-display-regexps
+If an element is a list, instead of a string, then the @sc{car} of the
+list is the buffer name, and the rest of the list says how to create the
+frame.  There are two possibilities for the rest of the list.  It can be
+an alist, specifying frame parameters, or it can contain a function and
+arguments to give to it.  (The function's first argument is always the
+buffer to be displayed; the arguments from the list come after that.)
+@end defopt
+
+@defopt special-display-regexps
 A list of regular expressions that specify buffers that should be
 displayed specially.  If the buffer's name matches any of the regular
 expressions in this list, @code{display-buffer} handles the buffer
 specially.
 
 By default, special display means to give the buffer a dedicated frame.
-@end defvar
+
+If an element is a list, instead of a string, then the @sc{car} of the
+list is the regular expression, and the rest of the list says how to
+create the frame.  See above, under @code{special-display-buffer-names}.
+@end defopt
 
 @defvar special-display-function
 This variable holds the function to call to display a buffer specially.
@@ -832,6 +955,20 @@ This variable holds frame parameters for
 @code{special-display-popup-frame} to use when it creates a frame.
 @end defopt
 
+@defopt same-window-buffer-names
+A list of buffer names for buffers that should be displayed in the
+selected window.  If the buffer's name is in this list,
+@code{display-buffer} handles the buffer by switching to it in the
+selected window.
+@end defopt
+
+@defopt same-window-regexps
+A list of regular expressions that specify buffers that should be
+displayed in the selected window.  If the buffer's name matches any of
+the regular expressions in this list, @code{display-buffer} handles the
+buffer by switching to it in the selected window.
+@end defopt
+
 @c Emacs 19 feature
 @defvar display-buffer-function
 This variable is the most flexible way to customize the behavior of
@@ -848,7 +985,8 @@ described above.
 @c Emacs 19 feature
 @cindex dedicated window
 A window can be marked as ``dedicated'' to its buffer.  Then
-@code{display-buffer} does not try to use that window.
+@code{display-buffer} will not try to use that window to display any
+other buffer.
 
 @defun window-dedicated-p window
 This function returns @code{t} if @var{window} is marked as dedicated;
@@ -878,12 +1016,12 @@ initialized from the buffer's point, or from the window point of another
 window opened on the buffer if such a window exists.
 
 @item
-Selecting a window sets the value of point in its buffer to the window's
-value of point.  Conversely, deselecting a window sets the window's
-value of point from that of the buffer.  Thus, when you switch between
-windows that display a given buffer, the point value for the selected
-window is in effect in the buffer, while the point values for the other
-windows are stored in those windows.
+Selecting a window sets the value of point in its buffer from the
+window's value of point.  Conversely, deselecting a window sets the
+window's value of point from that of the buffer.  Thus, when you switch
+between windows that display a given buffer, the point value for the
+selected window is in effect in the buffer, while the point values for
+the other windows are stored in those windows.
 
 @item
 As long as the selected window displays the current buffer, the window's
@@ -929,7 +1067,7 @@ inevitably, at the beginning of a text line.
 @cindex window top line
 This function returns the display-start position of window
 @var{window}.  If @var{window} is @code{nil}, the selected window is
-used.  For example, 
+used.  For example,
 
 @example
 @group
@@ -942,28 +1080,33 @@ When you create a window, or display a different buffer in it, the
 display-start position is set to a display-start position recently used
 for the same buffer, or 1 if the buffer doesn't have any.
 
-For a realistic example, see the description of @code{count-lines} in
-@ref{Text Lines}.
+Redisplay updates the window-start position (if you have not specified
+it explicitly since the previous redisplay) so that point appears on the
+screen.  Nothing except redisplay automatically changes the window-start
+position; if you move point, do not expect the window-start position to
+change in response until after the next redisplay.
+
+For a realistic example of using @code{window-start}, see the
+description of @code{count-lines} in @ref{Text Lines}.
 @end defun
 
-@defun window-end &optional window
+@defun window-end &optional window update
 This function returns the position of the end of the display in window
 @var{window}.  If @var{window} is @code{nil}, the selected window is
 used.
 
+Simply changing the buffer text or moving point does not update the
+value that @code{window-end} returns.  The value is updated only when
+Emacs redisplays and redisplay completes without being preempted.
+
 If the last redisplay of @var{window} was preempted, and did not finish,
-Emacs does not know the position of the end of display in that window;
-in that case, this function returns @code{nil}.  You can compute where
-the end of the window @emph{would} have been, if redisplay had finished,
-like this:
+Emacs does not know the position of the end of display in that window.
+In that case, this function returns @code{nil}.
 
-@example
-(save-excursion
-  (goto-char (window-start window))
-  (vertical-motion (1- (window-height window))
-                   window)
-  (point))
-@end example
+If @var{update} is non-@code{nil}, @code{window-end} always returns
+an up-to-date value for where the window ends.  If the saved value is
+valid, @code{window-end} returns that; otherwise it computes the correct
+value by scanning the buffer text.
 @end defun
 
 @defun set-window-start window position &optional noforce
@@ -1108,10 +1251,6 @@ This function scrolls the text in another window upward @var{count}
 lines.  Negative values of @var{count}, or @code{nil}, are handled
 as in @code{scroll-up}.
 
-The window that is scrolled is normally the one following the selected
-window in the cyclic ordering of windows---the window that
-@code{next-window} would return.  @xref{Cyclic Window Ordering}.
-
 You can specify a buffer to scroll with the variable
 @code{other-window-scroll-buffer}.  When the selected window is the
 minibuffer, the next window is normally the one at the top left corner.
@@ -1133,13 +1272,38 @@ If this variable is non-@code{nil}, it tells @code{scroll-other-window}
 which buffer to scroll.
 @end defvar
 
-@defopt scroll-step
+@tindex scroll-margin
+@defopt scroll-margin
+This option specifies the size of the scroll margin---a minimum number
+of lines between point and the top or bottom of a window.  Whenever
+point gets within this many lines of the top or bottom of the window,
+the window scrolls automatically (if possible) to move point out of the
+margin, closer to the center of the window.
+@end defopt
+
+@tindex scroll-conservatively
+@defopt scroll-conservatively
 This variable controls how scrolling is done automatically when point
-moves off the screen.  If the value is zero, then redisplay scrolls the
-text to center point vertically in the window.  If the value is a
-positive integer @var{n}, then redisplay brings point back on screen by
-scrolling @var{n} lines in either direction, if possible; otherwise, it
-centers point.  The default value is zero.
+moves off the screen (or into the scroll margin).  If the value is zero,
+then redisplay scrolls the text to center point vertically in the
+window.  If the value is a positive integer @var{n}, then redisplay
+scrolls the window up to @var{n} lines in either direction, if that will
+bring point back into view.  Otherwise, it centers point.  The default
+value is zero.
+@end defopt
+
+@defopt scroll-step
+This variable is an older variant of @code{scroll-conservatively}.  The
+difference is that it if its value is @var{n}, that permits scrolling
+only by precisely @var{n} lines, not a smaller number.  This feature
+does not work with @code{scroll-margin}.  The default value is zero.
+@end defopt
+
+@tindex scroll-preserve-screen-position
+@defopt scroll-preserve-screen-position
+If this option is non-@code{nil}, the scroll functions move point so
+that the vertical position of the cursor is unchanged, when that is
+possible.
 @end defopt
 
 @defopt next-screen-context-lines
@@ -1181,10 +1345,10 @@ separate key binding to do this.  For example,
 (defun line-to-top-of-window ()
   "Scroll current line to top of window.
 Replaces three keystroke sequence C-u 0 C-l."
-  (interactive) 
+  (interactive)
   (recenter 0))
 
-(global-set-key [kp-multiply] 'line-to-top-of-window)  
+(global-set-key [kp-multiply] 'line-to-top-of-window)
 @end group
 @end example
 @end deffn
@@ -1193,13 +1357,14 @@ Replaces three keystroke sequence C-u 0 C-l."
 @section Horizontal Scrolling
 @cindex horizontal scrolling
 
-  Because we read English first from top to bottom and second from left
-to right, horizontal scrolling is not like vertical scrolling.  Vertical
-scrolling involves selection of a contiguous portion of text to display.
-Horizontal scrolling causes part of each line to go off screen.  The
-amount of horizontal scrolling is therefore specified as a number of
-columns rather than as a position in the buffer.  It has nothing to do
-with the display-start position returned by @code{window-start}.
+  Because we read English from left to right in the ``inner loop'', and
+from top to bottom in the ``outer loop'', horizontal scrolling is not
+like vertical scrolling.  Vertical scrolling involves selection of a
+contiguous portion of text to display, but horizontal scrolling causes
+part of each line to go off screen.  The amount of horizontal scrolling
+is therefore specified as a number of columns rather than as a position
+in the buffer.  It has nothing to do with the display-start position
+returned by @code{window-start}.
 
   Usually, no horizontal scrolling is in effect; then the leftmost
 column is at the left edge of the window.  In this state, scrolling to
@@ -1259,7 +1424,7 @@ If @var{window} is @code{nil}, the selected window is used.
 
 @defun set-window-hscroll window columns
 This function sets the number of columns from the left margin that
-@var{window} is scrolled to the value of @var{columns}.  The argument
+@var{window} is scrolled from the value of @var{columns}.  The argument
 @var{columns} should be zero or positive; if not, it is taken as zero.
 
 The value returned is @var{columns}.
@@ -1278,9 +1443,9 @@ is off the screen due to horizontal scrolling:
 @example
 @group
 (defun hscroll-on-screen (window position)
-  (save-excursion 
+  (save-excursion
     (goto-char position)
-    (and 
+    (and
      (>= (- (current-column) (window-hscroll window)) 0)
      (< (- (current-column) (window-hscroll window))
         (window-width window)))))
@@ -1301,10 +1466,10 @@ characters that separates side-by-side windows.
   The following three functions return size information about a window:
 
 @defun window-height &optional window
-This function returns the number of lines in @var{window}, including
-its mode line.  If @var{window} fills its entire frame, this is one less
-than the value of @code{frame-height} on that frame (since the last line
-is always reserved for the minibuffer).
+This function returns the number of lines in @var{window}, including its
+mode line.  If @var{window} fills its entire frame, this is typically
+one less than the value of @code{frame-height} on that frame (since the
+last line is always reserved for the minibuffer).
 
 If @var{window} is @code{nil}, the function uses the selected window.
 
@@ -1371,26 +1536,28 @@ window:
 @noindent
 The bottom edge is at line 23 because the last line is the echo area.
 
-If @var{window} is at the upper left corner of its frame, @var{right}
-and @var{bottom} are the same as the values returned by
-@code{(window-width)} and @code{(window-height)} respectively, and
-@var{top} and @var{bottom} are zero.  For example, the edges of the
-following window are @w{@samp{0 0 5 8}}.  Assuming that the frame has
-more than 8 columns, the last column of the window (column 7) holds a
-border rather than text.  The last row (row 4) holds the mode line,
-shown here with @samp{xxxxxxxxx}.
+If @var{window} is at the upper left corner of its frame, then
+@var{bottom} is the same as the value of @code{(window-height)},
+@var{right} is almost the same as the value of
+@code{(window-width)}@footnote{They are not exactly equal because
+@var{right} includes the vertical separator line or scroll bar, while
+@code{(window-width)} does not.}, and @var{top} and @var{left} are zero.
+For example, the edges of the following window are @w{@samp{0 0 5 8}}.
+Assuming that the frame has more than 8 columns, the last column of the
+window (column 7) holds a border rather than text.  The last row (row 4)
+holds the mode line, shown here with @samp{xxxxxxxxx}.
 
 @example
 @group
-           0    
+           0
            _______
-        0 |       | 
-          |       |   
-          |       | 
-          |       | 
+        0 |       |
+          |       |
+          |       |
+          |       |
           xxxxxxxxx  4
 
-                  7  
+                  7
 @end group
 @end example
 
@@ -1407,9 +1574,9 @@ and the edges of the right window are @w{@samp{4 0 7 3}}.
 @example
 @group
            ___ ___
-          |   |   |    
-          |   |   |    
-          xxxxxxxxx 
+          |   |   |
+          |   |   |
+          xxxxxxxxx
 
            0  34  7
 @end group
@@ -1448,7 +1615,7 @@ If @var{size} is negative, this function shrinks the window by
 than the minimum size (@code{window-min-height} and
 @code{window-min-width}), @code{enlarge-window} deletes the window.
 
-@code{enlarge-window} returns @code{nil}.  
+@code{enlarge-window} returns @code{nil}.
 @end deffn
 
 @deffn Command enlarge-window-horizontally columns
@@ -1485,6 +1652,17 @@ It could be defined as follows:
 @end example
 @end deffn
 
+@deffn Command shrink-window-if-larger-than-buffer window
+This command shrinks @var{window} to be as small as possible while still
+showing the full contents of its buffer---but not less than
+@code{window-min-height} lines.
+
+However, the command does nothing if the window is already too small to
+display the whole text of the buffer, or if part of the contents are
+currently scrolled off screen, or if the window is not the full width of
+its frame, or if the window is the only window in its frame.
+@end deffn
+
 @cindex minimum window size
   The following two variables constrain the window-size-changing
 functions to a minimum height and width.
@@ -1501,7 +1679,7 @@ less than two.  The default value is 4.
 
 @defopt window-min-width
 The value of this variable determines how narrow a window may become
-before it automatically deleted.  Making a window smaller than
+before it is automatically deleted.  Making a window smaller than
 @code{window-min-width} automatically deletes it, and no window may be
 created narrower than this.  The absolute minimum width is one; any
 value below that is ignored.  The default value is 10.
@@ -1525,19 +1703,13 @@ If you omit @var{frame}, the selected frame is used.
 This function checks whether a particular frame position falls within
 the window @var{window}.
 
-The argument @var{coordinates} is a cons cell of this form:
-
-@example
-(@var{x} . @var{y})
-@end example
-
-@noindent
-The coordinates @var{x} and @var{y} are measured in characters, and
-count from the top left corner of the screen or frame.
+The argument @var{coordinates} is a cons cell of the form @code{(@var{x}
+. @var{y})}.  The coordinates @var{x} and @var{y} are measured in
+characters, and count from the top left corner of the screen or frame.
 
-The value of @code{coordinates-in-window-p} is non-@code{nil} if the
-coordinates are inside @var{window}.  The value also indicates what part
-of the window the position is in, as follows:
+The value returned by @code{coordinates-in-window-p} is non-@code{nil}
+if the coordinates are inside @var{window}.  The value also indicates
+what part of the window the position is in, as follows:
 
 @table @code
 @item (@var{relx} . @var{rely})
@@ -1551,7 +1723,7 @@ The coordinates are in the mode line of @var{window}.
 
 @item vertical-split
 The coordinates are in the vertical line between @var{window} and its
-neighbor to the right.  This value occurs only if the window doesn't 
+neighbor to the right.  This value occurs only if the window doesn't
 have a scroll bar; positions in a scroll bar are considered outside the
 window.
 
@@ -1568,7 +1740,7 @@ argument because it always uses the frame that @var{window} is on.
 @cindex window configurations
 @cindex saving window information
 
-  A @dfn{window configuration} records the entire layout of a
+  A @dfn{window configuration} records the entire layout of one
 frame---all windows, their sizes, which buffers they contain, what part
 of each buffer is displayed, and the values of point and the mark.  You
 can bring back an entire previous layout by restoring a window
@@ -1579,19 +1751,31 @@ configuration instead of a window configuration.  @xref{Frame
 Configurations}.
 
 @defun current-window-configuration
-This function returns a new object representing Emacs's current window
-configuration, namely the number of windows, their sizes and current
-buffers, which window is the selected window, and for each window the
-displayed buffer, the display-start position, and the positions of point
-and the mark.  An exception is made for point in the current buffer,
-whose value is not saved.
+This function returns a new object representing the selected frame's
+current window configuration, including the number of windows, their
+sizes and current buffers, which window is the selected window, and for
+each window the displayed buffer, the display-start position, and the
+positions of point and the mark.  It also includes the values of
+@code{window-min-height}, @code{window-min-width} and
+@code{minibuffer-scroll-window}.  An exception is made for point in the
+current buffer, whose value is not saved.
 @end defun
 
 @defun set-window-configuration configuration
-This function restores the configuration of Emacs's windows and
-buffers to the state specified by @var{configuration}.  The argument
-@var{configuration} must be a value that was previously returned by
-@code{current-window-configuration}.
+This function restores the configuration of windows and buffers as
+specified by @var{configuration}.  The argument @var{configuration} must
+be a value that was previously returned by
+@code{current-window-configuration}.  This configuration is restored in
+the frame from which @var{configuration} was made, whether that frame is
+selected or not.  This always counts as a window size change and
+triggers execution of the @code{window-size-change-functions}
+(@pxref{Window Hooks}), because @code{set-window-configuration} doesn't
+know how to tell whether the new configuration actually differs from the
+old one.
+
+If the frame which @var{configuration} was saved from is dead, all this
+function does is restore the three variables @code{window-min-height},
+@code{window-min-width} and @code{minibuffer-scroll-window}.
 
 Here is a way of using this function to get the same effect
 as @code{save-window-excursion}:
@@ -1613,7 +1797,14 @@ in sequence, then restores the earlier window configuration.  The window
 configuration includes the value of point and the portion of the buffer
 that is visible.  It also includes the choice of selected window.
 However, it does not include the value of point in the current buffer;
-use @code{save-excursion} if you wish to preserve that.
+use @code{save-excursion} also, if you wish to preserve that.
+
+Don't use this construct when @code{save-selected-window} is all you need.
+
+Exit from @code{save-window-excursion} always triggers execution of the
+@code{window-size-change-functions}.  (It doesn't know how to tell
+whether the restored configuration actually differs from the one in
+effect at the end of the @var{forms}.)
 
 The return value is the value of the final form in @var{forms}.
 For example:
@@ -1640,8 +1831,98 @@ For example:
 
 @defun window-configuration-p object
 This function returns @code{t} if @var{object} is a window configuration.
+@end defun
+
+@defun compare-window-configurations config1 config2
+This function compares two window configurations as regards the
+structure of windows, but ignores the values of point and mark and the
+saved scrolling positions---it can return @code{t} even if those
+aspects differ.
+
+The function @code{equal} can also compare two window configurations; it
+regards configurations as unequal if they differ in any respect, even a
+saved point or mark.
 @end defun
 
   Primitives to look inside of window configurations would make sense,
 but none are implemented.  It is not clear they are useful enough to be
 worth implementing.
+
+@node Window Hooks
+@section Hooks for Window Scrolling and Changes
+
+This section describes how a Lisp program can take action whenever a
+window displays a different part of its buffer or a different buffer.
+There are three actions that can change this: scrolling the window,
+switching buffers in the window, and changing the size of the window.
+The first two actions run @code{window-scroll-functions}; the last runs
+@code{window-size-change-functions}.  The paradigmatic use of these
+hooks is in the implementation of Lazy Lock mode; see @ref{Support
+Modes, Lazy Lock, Font Lock Support Modes, emacs, The GNU Emacs Manual}.
+
+@defvar window-scroll-functions
+This variable holds a list of functions that Emacs should call before
+redisplaying a window with scrolling.  It is not a normal hook, because
+each function is called with two arguments: the window, and its new
+display-start position.
+
+Displaying a different buffer in the window also runs these functions.
+
+These functions must be careful in using @code{window-end}
+(@pxref{Window Start}); if you need an up-to-date value, you must use
+the @var{update} argument to ensure you get it.
+@end defvar
+
+@defvar window-size-change-functions
+This variable holds a list of functions to be called if the size of any
+window changes for any reason.  The functions are called just once per
+redisplay, and just once for each frame on which size changes have
+occurred.
+
+Each function receives the frame as its sole argument.  There is no
+direct way to find out which windows on that frame have changed size, or
+precisely how.  However, if a size-change function records, at each
+call, the existing windows and their sizes, it can also compare the
+present sizes and the previous sizes.
+
+Creating or deleting windows counts as a size change, and therefore
+causes these functions to be called.  Changing the frame size also
+counts, because it changes the sizes of the existing windows.
+
+It is not a good idea to use @code{save-window-excursion} (@pxref{Window
+Configurations}) in these functions, because that always counts as a
+size change, and it would cause these functions to be called over and
+over.  In most cases, @code{save-selected-window} (@pxref{Selecting
+Windows}) is what you need here.
+@end defvar
+
+@defvar redisplay-end-trigger-functions
+@tindex redisplay-end-trigger-functions
+This abnormal hook is run whenever redisplay in a window uses text that
+extends past a specified end trigger position.  You set the end trigger
+position with the function @code{set-window-redisplay-end-trigger}.  The
+functions are called with two arguments: the window, and the end trigger
+position.  Storing @code{nil} for the end trigger position turns off the
+feature, and the trigger value is automatically reset to @code{nil} just
+after the hook is run.
+@end defvar
+
+@defun set-window-redisplay-end-trigger window position
+@tindex set-window-redisplay-end-trigger
+This function sets @var{window}'s end trigger position at
+@var{position}.
+@end defun
+
+@defun window-redisplay-end-trigger window
+@tindex window-redisplay-end-trigger
+This function returns @var{window}'s current end trigger position.
+@end defun
+
+@defvar window-configuration-change-hook
+@tindex window-configuration-change-hook
+A normal hook that is run every time you change the window configuration
+of an existing frame.  This includes splitting or deleting windows,
+changing the sizes of windows, or displaying a different buffer in a
+window.  The frame whose window configuration has changed is the
+selected frame when this hook runs.
+@end defvar