Patch by Martin.Lorentzson@telia.com.
[bpt/emacs.git] / lispref / modes.texi
index dfbdfee..7ac30f2 100644 (file)
@@ -1,6 +1,7 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc. 
+@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
+@c   Free Software Foundation, Inc. 
 @c See the file elisp.texi for copying conditions.
 @setfilename ../info/modes
 @node Modes, Documentation,  Keymaps, Top
@@ -54,14 +55,19 @@ the old one to serve two purposes, since it may become harder to use and
 maintain.  Instead, copy and rename an existing major mode definition
 and alter the copy---or define a @dfn{derived mode} (@pxref{Derived
 Modes}).  For example, Rmail Edit mode, which is in
-@file{emacs/lisp/rmailedit.el}, is a major mode that is very similar to
-Text mode except that it provides three additional commands.  Its
-definition is distinct from that of Text mode, but was derived from it.
+@file{emacs/lisp/mail/rmailedit.el}, is a major mode that is very similar to
+Text mode except that it provides two additional commands.  Its
+definition is distinct from that of Text mode, but uses that of Text mode.
+
+  Even if the new mode is not an obvious derivative of any other mode,
+it is convenient to use @code{define-derived-mode} with a @code{nil}
+parent argument, since it automatically enforces the most important
+coding conventions for you.
 
   Rmail Edit mode offers an example of changing the major mode
 temporarily for a buffer, so it can be edited in a different way (with
-ordinary Emacs commands rather than Rmail).  In such cases, the
-temporary major mode usually has a command to switch back to the
+ordinary Emacs commands rather than Rmail commands).  In such cases, the
+temporary major mode usually provides a command to switch back to the
 buffer's usual mode (Rmail mode, in this case).  You might be tempted to
 present the temporary redefinitions inside a recursive edit and restore
 the usual ones when the user exits; but this is a bad idea because it
@@ -70,11 +76,12 @@ recursive edits must be exited most-recently-entered first.  Using an
 alternative major mode avoids this limitation.  @xref{Recursive
 Editing}.
 
-  The standard GNU Emacs Lisp library directory contains the code for
-several major modes, in files such as @file{text-mode.el},
+  The standard GNU Emacs Lisp library directory tree contains the code
+for several major modes, in files such as @file{text-mode.el},
 @file{texinfo.el}, @file{lisp-mode.el}, @file{c-mode.el}, and
-@file{rmail.el}.  You can study these libraries to see how modes are
-written.  Text mode is perhaps the simplest major mode aside from
+@file{rmail.el}.  They are found in various subdirectories of the
+@file{lisp} directory.  You can study these libraries to see how modes
+are written.  Text mode is perhaps the simplest major mode aside from
 Fundamental mode.  Rmail mode is a complicated and specialized mode.
 
 @menu
@@ -92,7 +99,14 @@ Fundamental mode.  Rmail mode is a complicated and specialized mode.
   The code for existing major modes follows various coding conventions,
 including conventions for local keymap and syntax table initialization,
 global names, and hooks.  Please follow these conventions when you
-define a new major mode:
+define a new major mode.
+
+  This list of conventions is only partial, because each major mode
+should aim for consistency in general with other Emacs major modes.
+This makes Emacs as a whole more coherent.  It is impossible to list
+here all the possible points where this issue might come up; if the
+Emacs developers point out an area where your major mode deviates from
+the usual conventions, please make it compatible.
 
 @itemize @bullet
 @item
@@ -108,7 +122,7 @@ special commands available in this mode.  @kbd{C-h m}
 
 The documentation string may include the special documentation
 substrings, @samp{\[@var{command}]}, @samp{\@{@var{keymap}@}}, and
-@samp{\<@var{keymap}>}, that enable the documentation to adapt
+@samp{\<@var{keymap}>}, which enable the documentation to adapt
 automatically to the user's own key bindings.  @xref{Keys in
 Documentation}.
 
@@ -134,6 +148,13 @@ variables, constants, and functions that are part of the mode should
 have names that start with the major mode name (or with an abbreviation
 of it if the name is long).  @xref{Coding Conventions}.
 
+@item
+In a major mode for editing some kind of structured text, such as a
+programming language, indentation of text according to structure is
+probably useful.  So the mode should set @code{indent-line-function}
+to a suitable function, and probably customize other variables
+for indentation.
+
 @item
 @cindex keymaps in modes
 The major mode should usually have its own keymap, which is used as the
@@ -166,6 +187,18 @@ Major modes such as Dired or Rmail that do not allow self-insertion of
 text can reasonably redefine letters and other printing characters as
 editing commands.  Dired and Rmail both do this.
 
+@item
+Major modes must not define @key{RET} to do anything other than insert
+a newline.  The command to insert a newline and then indent is
+@kbd{C-j}.  Please keep this distinction uniform for all major modes.
+
+@item
+Major modes should not alter options that are primary a matter of user
+preference, such as whether Auto-Fill mode is enabled.  Leave this to
+each user to decide.  However, a major mode should customize other
+variables so that Auto-Fill mode will work usefully @emph{if} the user
+decides to use it.
+
 @item
 @cindex syntax tables in modes
 The mode may have its own syntax table or may share one with other
@@ -210,8 +243,10 @@ variable local to every buffer in which it is subsequently set, which
 would affect buffers that do not use this mode.  It is undesirable for a
 mode to have such global effects.  @xref{Buffer-Local Variables}.
 
-It's OK to use @code{make-variable-buffer-local}, if you wish, for a
-variable used only within a single Lisp package.
+With rare exceptions, the only reasonable way to use 
+@code{make-variable-buffer-local} in a Lisp package is for a variable
+which is used only within that package.  Using it on a variable used by
+other packages would interfere with them.
 
 @item
 @cindex mode hook
@@ -245,7 +280,7 @@ with value @code{special}, put on as follows:
 @end example
 
 @noindent
-This tells Emacs that new buffers created while the current buffer has
+This tells Emacs that new buffers created while the current buffer is in
 Funny mode should not inherit Funny mode.  Modes such as Dired, Rmail,
 and Buffer List use this feature.
 
@@ -258,10 +293,9 @@ autoload, you should add this element in the same file that calls
 file that contains the mode definition.  @xref{Auto Major Mode}.
 
 @item
-@cindex @file{.emacs} customization
 In the documentation, you should provide a sample @code{autoload} form
 and an example of how to add to @code{auto-mode-alist}, that users can
-include in their @file{.emacs} files.
+include in their init files (@pxref{Init File}).
 
 @item
 @cindex mode loading
@@ -300,11 +334,15 @@ the conventions listed above:
 @end group
 
 @group
-(defvar text-mode-map nil)   ; @r{Create a mode-specific keymap.}
+(defvar text-mode-map nil    ; @r{Create a mode-specific keymap.}
+  "Keymap for Text mode.
+Many other modes, such as Mail mode, Outline mode and Indented Text mode,
+inherit all the commands defined in this map.")
 
 (if text-mode-map
     ()              ; @r{Do not change the keymap if it is already set up.}
   (setq text-mode-map (make-sparse-keymap))
+  (define-key text-mode-map "\e\t" 'ispell-complete-word)
   (define-key text-mode-map "\t" 'indent-relative)
   (define-key text-mode-map "\es" 'center-line)
   (define-key text-mode-map "\eS" 'center-paragraph))
@@ -316,7 +354,7 @@ the conventions listed above:
 @smallexample
 @group
 (defun text-mode ()
-  "Major mode for editing text intended for humans to read@enddots{}
+  "Major mode for editing text intended for humans to read...
  Special commands: \\@{text-mode-map@}
 @end group
 @group
@@ -334,6 +372,8 @@ Turning on text-mode runs the hook `text-mode-hook'."
   (setq paragraph-start (concat "[ \t]*$\\|" page-delimiter))
   (make-local-variable 'paragraph-separate)
   (setq paragraph-separate paragraph-start)
+  (make-local-variable 'indent-line-function)
+  (setq indent-line-function 'indent-relative-maybe)
 @end group
 @group
   (setq mode-name "Text")
@@ -368,7 +408,7 @@ correspondingly more complicated.  Here are excerpts from
 @group
       ;; @r{Set syntax of chars up to 0 to class of chars that are}
       ;;   @r{part of symbol names but not words.}
-      ;;   @r{(The number 0 is @code{48} in the @sc{ASCII} character set.)}
+      ;;   @r{(The number 0 is @code{48} in the @sc{ascii} character set.)}
       (while (< i ?0) 
         (modify-syntax-entry i "_   " emacs-lisp-mode-syntax-table)
         (setq i (1+ i)))
@@ -422,6 +462,7 @@ rest of @code{lisp-mode-variables}.
 @group
   (make-local-variable 'comment-indent-function)
   (setq comment-indent-function 'lisp-comment-indent))
+  @dots{}
 @end group
 @end smallexample
 
@@ -450,7 +491,7 @@ And here is the code to set up the keymap for Lisp mode:
 @smallexample
 @group
 (defvar lisp-mode-map ()
-  "Keymap for ordinary Lisp mode@enddots{}")
+  "Keymap for ordinary Lisp mode...")
 
 (if lisp-mode-map
     ()
@@ -462,7 +503,7 @@ And here is the code to set up the keymap for Lisp mode:
 @end smallexample
 
   Finally, here is the complete major mode function definition for
-Emacs Lisp mode.  
+Lisp mode.  
 
 @smallexample
 @group
@@ -538,29 +579,6 @@ major mode function, so errors are caught and reported as a @samp{File
 mode specification error},  followed by the original error message.
 @end deffn
 
-@defopt enable-local-variables
-This variable controls processing of local variables lists in files
-being visited.  A value of @code{t} means process the local variables
-lists unconditionally; @code{nil} means ignore them; anything else means
-ask the user what to do for each file.  The default value is @code{t}.
-@end defopt
-
-@defvar ignored-local-variables
-This variable holds a list of variables that should not be
-set by a file's local variables list.  Any value specified
-for one of these variables is ignored.
-@end defvar
-
-In addition to this list, any variable whose name has a non-@code{nil}
-@code{risky-local-variable} property is also ignored.
-
-@defopt enable-local-eval
-This variable controls processing of @samp{Eval:} in local variables
-lists in files being visited.  A value of @code{t} means process them
-unconditionally; @code{nil} means ignore them; anything else means ask
-the user what to do for each file.  The default value is @code{maybe}.
-@end defopt
-
 @defun set-auto-mode
 @cindex visited file mode
   This function selects the major mode that is appropriate for the
@@ -642,7 +660,7 @@ file in the proper mode according to the name sans @samp{.gz}.
 
 Here is an example of how to prepend several pattern pairs to
 @code{auto-mode-alist}.  (You might use this sort of expression in your
-@file{.emacs} file.)
+init file.)
 
 @smallexample
 @group
@@ -661,7 +679,7 @@ Here is an example of how to prepend several pattern pairs to
 
 @defvar interpreter-mode-alist
 This variable specifies major modes to use for scripts that specify a
-command interpreter in an @samp{#!} line.  Its value is a list of
+command interpreter in a @samp{#!} line.  Its value is a list of
 elements of the form @code{(@var{interpreter} . @var{mode})}; for
 example, @code{("perl" . perl-mode)} is one element present by default.
 The element says to use mode @var{mode} if the file specifies
@@ -672,16 +690,6 @@ This variable is applicable only when the @code{auto-mode-alist} does
 not indicate which major mode to use.
 @end defvar
 
-@defun hack-local-variables &optional force
-This function parses, and binds or evaluates as appropriate, any local
-variables specified by the contents of the current buffer.
-
-The handling of @code{enable-local-variables} documented for
-@code{normal-mode} actually takes place here.  The argument @var{force}
-usually comes from the argument @var{find-file} given to
-@code{normal-mode}.
-@end defun
-
 @node Mode Help
 @subsection Getting Help about a Major Mode
 @cindex mode help
@@ -770,6 +778,9 @@ Here is a hypothetical example:
 (define-key hypertext-mode-map
   [down-mouse-3] 'do-hyper-link)
 @end example
+
+Do not write an @code{interactive} spec in the definition;
+@code{define-derived-mode} does that automatically.
 @end defmac
 
 @node Minor Modes
@@ -782,7 +793,8 @@ individually or in combination.  Minor modes would be better named
 ``generally available, optional feature modes,'' except that such a name
 would be unwieldy.
 
-  A minor mode is not usually a modification of single major mode.  For
+  A minor mode is not usually meant as a variation of a single major mode.
+Usually they are general and can apply to many major modes.  For
 example, Auto Fill mode works with any major mode that permits text
 insertion.  To be general, a minor mode must be effectively independent
 of the things major modes do.
@@ -800,7 +812,7 @@ keymaps make this easier than it used to be.
 @menu
 * Minor Mode Conventions::      Tips for writing a minor mode.
 * Keymaps and Minor Modes::     How a minor mode can have its own keymap.
-* Easy-Mmode::                  A convenient facility for defining minor modes.
+* Defining Minor Modes::        A convenient facility for defining minor modes.
 @end menu
 
 @node Minor Mode Conventions
@@ -823,11 +835,11 @@ minor modes.
 Make a variable whose name ends in @samp{-mode} to control the minor
 mode.  We call this the @dfn{mode variable}.  The minor mode command
 should set this variable (@code{nil} to disable; anything else to
-enable.)
+enable).
 
-If it is possible, implement the mode so that setting the variable
+If possible, implement the mode so that setting the variable
 automatically enables or disables the mode.  Then the minor mode command
-does not need to do anything except the variable.
+does not need to do anything except set the variable.
 
 This variable is used in conjunction with the @code{minor-mode-alist} to
 display the minor mode name in the mode line.  It can also enable
@@ -880,13 +892,56 @@ check for an existing element, to avoid duplication.  For example:
 
 @smallexample
 @group
-(or (assq 'leif-mode minor-mode-alist)
-    (setq minor-mode-alist
-          (cons '(leif-mode " Leif") minor-mode-alist)))
+(unless (assq 'leif-mode minor-mode-alist)
+  (setq minor-mode-alist
+        (cons '(leif-mode " Leif") minor-mode-alist)))
+@end group
+@end smallexample
+
+@noindent
+or like this, using @code{add-to-list} (@pxref{Setting Variables}):
+
+@smallexample
+@group
+(add-to-list 'minor-mode-alist '(leif-mode " Leif"))
 @end group
 @end smallexample
 @end itemize
 
+  Global minor modes distributed with Emacs should if possible support
+enabling and disabling via Custom (@pxref{Customization}).  To do this,
+the first step is to define the mode variable with @code{defcustom}, and
+specify @code{:type boolean}.
+
+  If just setting the variable is not sufficient to enable the mode, you
+should also specify a @code{:set} method which enables the mode by
+invoke the mode command.  Note in the variable's documentation string that
+setting the variable other than via Custom may not take effect.
+
+  Also mark the definition with an autoload cookie (@pxref{Autoload}),
+and specify a @code{:require} so that customizing the variable will load
+the library that defines the mode.  This will copy suitable definitions
+into @file{loaddefs.el} so that users can use @code{customize-option} to
+enable the mode.  For example:
+
+@smallexample
+@group
+
+;;;###autoload
+(defcustom msb-mode nil
+  "Toggle msb-mode.
+Setting this variable directly does not take effect;
+use either \\[customize] or the function `msb-mode'."
+  :set (lambda (symbol value)
+        (msb-mode (or value 0)))
+  :initialize 'custom-initialize-default
+  :version "20.4"
+  :type    'boolean
+  :group   'msb
+  :require 'msb)
+@end group
+@end smallexample
+
 @node Keymaps and Minor Modes
 @subsection Keymaps and Minor Modes
 
@@ -905,26 +960,28 @@ standard one.  The editor command loop handles this function specially.)
 
 The key sequences bound in a minor mode should consist of @kbd{C-c}
 followed by a punctuation character @emph{other than} @kbd{@{},
-@kbd{@}}, @kbd{<}, @kbd{>}, @kbd{:} or @kbd{;}.  (Those few punctuation
+@kbd{@}}, @kbd{<}, @kbd{>}, @kbd{:}, and @kbd{;}.  (Those few punctuation
 characters are reserved for major modes.)
 
-@node Easy-Mmode
-@subsection Easy-Mmode
+@node Defining Minor Modes
+@subsection Defining Minor Modes
 
-  The easy-mmode package provides a convenient way of implementing a
-minor mode; with it, you can specify all about a simple minor mode in
-one self-contained definition.
+  The macro @code{define-minor-mode} offers a convenient way of
+implementing a mode in one self-contained definition.  It supports only
+buffer-local minor modes, not global ones.
 
-@defmac easy-mmode-define-minor-mode mode doc &optional init-value mode-indicator keymap
-@tindex easy-mmode-define-minor-mode
+@defmac define-minor-mode mode doc &optional init-value mode-indicator keymap body...
+@tindex define-minor-mode
 This macro defines a new minor mode whose name is @var{mode} (a symbol).
+It defines a command named @var{mode} to toggle the minor
+mode, with @var{doc} as its documentation string.  It also defines a
+variable named @var{mode}, which is set to @code{t} or @code{nil} by
+enabling or disabling the mode.  The variable is initialized to
+@var{init-value}.
 
-This macro defines a command named @var{mode} which toggles the minor
-mode, and has @var{doc} as its documentation string.
-
-It also defines a variable named @var{mode}, which is set to @code{t} or
-@code{nil} by enabling or disabling the mode.  The variable is
-initialized to @var{init-value}.
+The command named @var{mode} finishes by executing the @var{body} forms,
+if any, after it has performed the standard actions such as setting
+the variable named @var{mode}.
 
 The string @var{mode-indicator} says what to display in the mode line
 when the mode is enabled; if it is @code{nil}, the mode is not displayed
@@ -939,10 +996,10 @@ specifying bindings in this form:
 @end example
 @end defmac
 
-  Here is an example of using @code{easy-mmode-define-minor-mode}:
+  Here is an example of using @code{define-minor-mode}:
 
 @smallexample
-(easy-mmode-define-minor-mode hungry-mode
+(define-minor-mode hungry-mode
   "Toggle Hungry mode.
 With no argument, this command toggles the mode. 
 Non-null prefix argument turns on the mode.
@@ -971,39 +1028,55 @@ which indicates whether the mode is enabled, and a variable named
 mode is enabled.  It initializes the keymap with key bindings for
 @kbd{C-@key{DEL}} and @kbd{C-M-@key{DEL}}.
 
+
+@findex easy-mmode-define-minor-mode
+  The name @code{easy-mmode-define-minor-mode} is an alias
+for this macro.
+
 @node Mode Line Format
 @section Mode Line Format
 @cindex mode line
 
-  Each Emacs window (aside from minibuffer windows) includes a mode line,
-which displays status information about the buffer displayed in the
-window.  The mode line contains information about the buffer, such as its
-name, associated file, depth of recursive editing, and the major and
-minor modes.
+  Each Emacs window (aside from minibuffer windows) typically has a mode
+line at the bottom, which displays status information about the buffer
+displayed in the window.  The mode line contains information about the
+buffer, such as its name, associated file, depth of recursive editing,
+and major and minor modes.  A window can also have a @dfn{header
+line}, which is much like the mode line but appears at the top of the
+window (starting in Emacs 21).
 
-  This section describes how the contents of the mode line are
-controlled.  We include it in this chapter because much of the
+  This section describes how to control the contents of the mode line
+and header line.  We include it in this chapter because much of the
 information displayed in the mode line relates to the enabled major and
 minor modes.
 
   @code{mode-line-format} is a buffer-local variable that holds a
 template used to display the mode line of the current buffer.  All
-windows for the same buffer use the same @code{mode-line-format} and
-their mode lines appear the same (except for scrolling percentages, and
-line and column numbers).
-
-  The mode line of a window is normally updated whenever a different
-buffer is shown in the window, or when the buffer's modified-status
-changes from @code{nil} to @code{t} or vice-versa.  If you modify any of
-the variables referenced by @code{mode-line-format} (@pxref{Mode Line
-Variables}), or any other variables and data structures that affect how
-text is displayed (@pxref{Display}), you may want to force an update of
-the mode line so as to display the new information or display it in
-the new way.
+windows for the same buffer use the same @code{mode-line-format}, so
+their mode lines appear the same---except for scrolling percentages, and
+line and column numbers, since those depend on point and on how the
+window is scrolled.  @code{header-line-format} is used likewise for
+header lines.
+
+  For efficiency, Emacs does not recompute the mode line and header
+line of a window in every redisplay.  It does so when circumstances
+appear to call for it---for instance, if you change the window
+configuration, switch buffers, narrow or widen the buffer, scroll, or
+change the buffer's modification status.  If you modify any of the
+variables referenced by @code{mode-line-format} (@pxref{Mode Line
+Variables}), or any other variables and data structures that affect
+how text is displayed (@pxref{Display}), you may want to force an
+update of the mode line so as to display the new information or
+display it in the new way.
 
 @c Emacs 19 feature
 @defun force-mode-line-update
-Force redisplay of the current buffer's mode line.
+Force redisplay of the current buffer's mode line and header line.
+The next redisplay will update the mode line and header line based on
+the latest values of all relevant variables.
+
+This function also forces recomputation of the menu bar menus
+and the frame title.
 @end defun
 
   The mode line is usually displayed in inverse video; see
@@ -1013,6 +1086,8 @@ Force redisplay of the current buffer's mode line.
 * Mode Line Data::        The data structure that controls the mode line.
 * Mode Line Variables::   Variables used in that data structure.
 * %-Constructs::          Putting information into a mode line.
+* Properties in Mode::    Using text properties in the mode line.
+* Header Lines::          Like a mode line, but at the top.
 @end menu
 
 @node Mode Line Data
@@ -1020,17 +1095,20 @@ Force redisplay of the current buffer's mode line.
 @cindex mode line construct
 
   The mode line contents are controlled by a data structure of lists,
-strings, symbols, and numbers kept in the buffer-local variable
-@code{mode-line-format}.  The data structure is called a @dfn{mode line
-construct}, and it is built in recursive fashion out of simpler mode line
-constructs.  The same data structure is used for constructing
-frame titles (@pxref{Frame Titles}).
+strings, symbols, and numbers kept in buffer-local variables.  The data
+structure is called a @dfn{mode line construct}, and it is built in
+recursive fashion out of simpler mode line constructs.  The same data
+structure is used for constructing frame titles (@pxref{Frame Titles})
+and header lines (@pxref{Header Lines}).
 
 @defvar mode-line-format
 The value of this variable is a mode line construct with overall
 responsibility for the mode line format.  The value of this variable
 controls which other variables are used to form the mode line text, and
 where they appear.
+
+If you set this variable to @code{nil} in a buffer, that buffer does not
+have a mode line.  (This feature was added in Emacs 21.)
 @end defvar
 
   A mode line construct may be as simple as a fixed string of text, but
@@ -1047,6 +1125,11 @@ variables that @code{mode-line-format} refers to.
   A mode line construct may be a list, a symbol, or a string.  If the
 value is a list, each element may be a list, a symbol, or a string.
 
+  The mode line can display various faces, if the strings that control
+it have the @code{face} property.  @xref{Properties in Mode}.  In
+addition, the face @code{mode-line} is used as a default for the whole
+mode line (@pxref{Standard Faces}).
+
 @table @code
 @cindex percent symbol in mode line
 @item @var{string}
@@ -1058,7 +1141,7 @@ is left justified).  @xref{%-Constructs}.
 @item @var{symbol}
 A symbol as a mode line construct stands for its value.  The value of
 @var{symbol} is used as a mode line construct, in place of @var{symbol}.
-However, the symbols @code{t} and @code{nil} are ignored; so is any
+However, the symbols @code{t} and @code{nil} are ignored, as is any
 symbol whose value is void.
 
 There is one exception: if the value of @var{symbol} is a string, it is
@@ -1069,14 +1152,19 @@ A list whose first element is a string or list means to process all the
 elements recursively and concatenate the results.  This is the most
 common form of mode line construct.
 
+@item (:eval @var{form})
+A list whose first element is the symbol @code{:eval} says to evaluate
+@var{form}, and use the result as a string to display.
+(This feature is new as of Emacs 21.)
+
 @item (@var{symbol} @var{then} @var{else})
-A list whose first element is a symbol is a conditional.  Its meaning
-depends on the value of @var{symbol}.  If the value is non-@code{nil},
-the second element, @var{then}, is processed recursively as a mode line
-element.  But if the value of @var{symbol} is @code{nil}, the third
-element, @var{else}, is processed recursively.  You may omit @var{else};
-then the mode line element displays nothing if the value of @var{symbol}
-is @code{nil}.
+A list whose first element is a symbol that is not a keyword specifies a
+conditional.  Its meaning depends on the value of @var{symbol}.  If the
+value is non-@code{nil}, the second element, @var{then}, is processed
+recursively as a mode line element.  But if the value of @var{symbol} is
+@code{nil}, the third element, @var{else}, is processed recursively.
+You may omit @var{else}; then the mode line element displays nothing if
+the value of @var{symbol} is @code{nil}.
 
 @item (@var{width} @var{rest}@dots{})
 A list whose first element is an integer specifies truncation or
@@ -1121,7 +1209,7 @@ directory.
    "   "
    'global-mode-string
    "   %[("
-   'mode-name 
+   '(:eval (mode-line-mode-name))
    'mode-line-process  
    'minor-mode-alist 
    "%n" 
@@ -1135,6 +1223,11 @@ directory.
 @end group
 @end example
 
+@noindent
+(The variables @code{line-number-mode}, @code{column-number-mode}
+and @code{which-func-mode} enable particular minor modes; as usual,
+these variable names are also the minor mode command names.)
+
 @node Mode Line Variables
 @subsection Variables Used in the Mode Line
 
@@ -1145,7 +1238,6 @@ other variables could have the same effects on the mode line if
 @code{mode-line-format} were changed to use them.
 
 @defvar mode-line-mule-info
-@tindex mode-line-mule-info
 This variable holds the value of the mode-line construct that displays
 information about the language environment, buffer coding system, and
 current input method.  @xref{Non-ASCII Characters}.
@@ -1165,7 +1257,6 @@ Changing this variable does not force an update of the mode line.
 @end defvar
 
 @defvar mode-line-frame-identification
-@tindex mode-line-frame-identification
 This variable identifies the current frame.  The default value is
 @code{" "} if you are using a window system which can show multiple
 frames, or @code{"-%F "} on an ordinary terminal which shows only one
@@ -1174,12 +1265,8 @@ frame at a time.
 
 @defvar mode-line-buffer-identification
 This variable identifies the buffer being displayed in the window.  Its
-default value is @code{("%12b")}, which means that it usually
-displays @samp{Emacs:} followed by seventeen characters of the buffer
-name.  (In a terminal frame, it displays the frame name instead of
-@samp{Emacs}; this has the effect of showing the frame number.)  You may
-want to change this in modes such as Rmail that do not behave like a
-``normal'' Emacs.
+default value is @code{("%12b")}, which displays the buffer name, padded
+with spaces to at least 12 columns.
 @end defvar
 
 @defvar global-mode-string
@@ -1240,11 +1327,25 @@ This buffer-local variable contains the mode line information on process
 status in modes used for communicating with subprocesses.  It is
 displayed immediately following the major mode name, with no intervening
 space.  For example, its value in the @samp{*shell*} buffer is
-@code{(":@: %s")}, which allows the shell to display its status along
-with the major mode as: @samp{(Shell:@: run)}.  Normally this variable
+@code{(":%s")}, which allows the shell to display its status along
+with the major mode as: @samp{(Shell:run)}.  Normally this variable
 is @code{nil}.
 @end defvar
 
+  Some variables are used by @code{minor-mode-alist} to display
+a string for various minor modes when enabled.  This is a typical
+example:
+
+@defvar vc-mode
+The variable @code{vc-mode}, buffer-local in each buffer, records
+whether the buffer's visited file is maintained with version control,
+and, if so, which kind.  Its value is a string that appears in the mode
+line, or @code{nil} for no version control.
+@end defvar
+
+  The variable @code{default-mode-line-format} is where
+@code{mode-line-format} usually gets its value:
+
 @defvar default-mode-line-format
 This variable holds the default @code{mode-line-format} for buffers
 that do not override it.  This is the same as @code{(default-value
@@ -1264,7 +1365,10 @@ The default value of @code{default-mode-line-format} is this list:
  global-mode-string
 @group
  "   %[("
- mode-name 
+ ;; @r{@code{mode-line-mode-name} is a function}
+ ;; @r{that copies the mode name and adds text}
+ ;; @r{properties to make it mouse-sensitive.}
+ (:eval (mode-line-mode-name))
  mode-line-process
  minor-mode-alist 
  "%n" 
@@ -1280,13 +1384,6 @@ The default value of @code{default-mode-line-format} is this list:
 @end example
 @end defvar
 
-@defvar vc-mode
-The variable @code{vc-mode}, buffer-local in each buffer, records
-whether the buffer's visited file is maintained with version control,
-and, if so, which kind.  Its value is @code{nil} for no version control,
-or a string that appears in the mode line.
-@end defvar
-
 @node %-Constructs
 @subsection @code{%}-Constructs in the Mode Line
 
@@ -1299,6 +1396,9 @@ integer after the @samp{%} to specify how many characters to display.
 The current buffer name, obtained with the @code{buffer-name} function.
 @xref{Buffer Names}.
 
+@item %c
+The current column number of point.
+
 @item %f
 The visited file name, obtained with the @code{buffer-file-name}
 function.  @xref{Buffer File Name}.
@@ -1307,11 +1407,33 @@ function.  @xref{Buffer File Name}.
 The title (only on a window system) or the name of the selected frame.
 @xref{Window Frame Parameters}.
 
-@item %c
-The current column number of point.
-
 @item %l
-The current line number of point.
+The current line number of point, counting within the accessible portion
+of the buffer.
+
+@item %n
+@samp{Narrow} when narrowing is in effect; nothing otherwise (see
+@code{narrow-to-region} in @ref{Narrowing}).
+
+@item %p
+The percentage of the buffer text above the @strong{top} of window, or
+@samp{Top}, @samp{Bottom} or @samp{All}.  Note that the default
+mode-line specification truncates this to three characters.
+
+@item %P
+The percentage of the buffer text that is above the @strong{bottom} of
+the window (which includes the text visible in the window, as well as
+the text above the top), plus @samp{Top} if the top of the buffer is
+visible on screen; or @samp{Bottom} or @samp{All}.
+
+@item %s
+The status of the subprocess belonging to the current buffer, obtained with
+@code{process-status}.  @xref{Process Information}.
+
+@item %t
+Whether the visited file is a text file or a binary file.  This is a
+meaningful distinction only on certain operating systems (@pxref{MS-DOS
+File Types}).
 
 @item %*
 @samp{%} if the buffer is read only (see @code{buffer-read-only}); @*
@@ -1327,28 +1449,6 @@ read-only buffer.  @xref{Buffer Modification}.
 @item %&
 @samp{*} if the buffer is modified, and @samp{-} otherwise.
 
-@item %s
-The status of the subprocess belonging to the current buffer, obtained with
-@code{process-status}.  @xref{Process Information}.
-
-@item %t
-Whether the visited file is a text file or a binary file.  (This is a
-meaningful distinction only on certain operating systems.)
-
-@item %p
-The percentage of the buffer text above the @strong{top} of window, or
-@samp{Top}, @samp{Bottom} or @samp{All}.
-
-@item %P
-The percentage of the buffer text that is above the @strong{bottom} of
-the window (which includes the text visible in the window, as well as
-the text above the top), plus @samp{Top} if the top of the buffer is
-visible on screen; or @samp{Bottom} or @samp{All}.
-
-@item %n
-@samp{Narrow} when narrowing is in effect; nothing otherwise (see
-@code{narrow-to-region} in @ref{Narrowing}).
-
 @item %[
 An indication of the depth of recursive editing levels (not counting
 minibuffer levels): one @samp{[} for each editing level.
@@ -1358,12 +1458,12 @@ minibuffer levels): one @samp{[} for each editing level.
 One @samp{]} for each recursive editing level (not counting minibuffer
 levels).
 
+@item %-
+Dashes sufficient to fill the remainder of the mode line.
+
 @item %%
 The character @samp{%}---this is how to include a literal @samp{%} in a
 string in which @code{%}-constructs are allowed.
-
-@item %-
-Dashes sufficient to fill the remainder of the mode line.
 @end table
 
 The following two @code{%}-constructs are still supported, but they are
@@ -1379,6 +1479,64 @@ The value of @code{global-mode-string}.  Currently, only
 @code{display-time} modifies the value of @code{global-mode-string}.
 @end table
 
+@node Properties in Mode
+@subsection Properties in the Mode Line
+
+  Starting in Emacs 21, certain text properties are meaningful in the
+mode line.  The @code{face} property affects the appearance of text; the
+@code{help-echo} property associate help strings with the text, and
+@code{local-map} can make the text mouse-sensitive.
+
+  There are three ways to specify text properties for text in the mode
+line:
+
+@enumerate
+@item
+Put a string with the @code{local-map} property directly into the
+mode-line data structure.
+
+@item
+Put a @code{local-map} property on a mode-line %-construct
+such as @samp{%12b}; then the expansion of the %-construct
+will have that same text property.
+
+@item
+Use a list containing @code{:eval @var{form}} in the mode-line data
+structure, and make @var{form} evaluate to a string that has a
+@code{local-map} property.
+@end enumerate
+
+  You use the @code{local-map} property to specify a keymap.  Like any
+keymap, it can bind character keys and function keys; but that has no
+effect, since it is impossible to move point into the mode line.  This
+keymap can only take real effect for mouse clicks.
+
+@node Header Lines
+@subsection Window Header Lines
+@cindex header line (of a window)
+@cindex window header line
+
+  Starting in Emacs 21, a window can have a @dfn{header line} at the
+top, just as it can have a mode line at the bottom.  The header line
+feature works just like the mode line feature, except that it's
+controlled by different variables.
+
+@tindex header-line-format
+@defvar header-line-format
+This variable, local in every buffer, specifies how to display the
+header line, for windows displaying the buffer.  The format of the value
+is the same as for @code{mode-line-format} (@pxref{Mode Line Data}).
+@end defvar
+
+@tindex default-header-line-format
+@defvar default-header-line-format
+This variable holds the default @code{header-line-format} for buffers
+that do not override it.  This is the same as @code{(default-value
+'header-line-format)}.
+
+It is normally @code{nil}, so that ordinary buffers have no header line.
+@end defvar
+
 @node Imenu
 @section Imenu
 
@@ -1386,9 +1544,11 @@ The value of @code{global-mode-string}.  Currently, only
   @dfn{Imenu} is a feature that lets users select a definition or
 section in the buffer, from a menu which lists all of them, to go
 directly to that location in the buffer.  Imenu works by constructing a
-buffer index which lists the names and positions of the definitions or
-portions of in the buffer, so the user can pick one of them to move to.
-This section explains how to customize Imenu for a major mode.
+buffer index which lists the names and buffer positions of the
+definitions, or other named portions of the buffer; then the user can
+choose one of them and move point to it.  This section explains how to
+customize how Imenu finds the definitions or buffer portions for a
+particular major mode.
 
   The usual and simplest way is to set the variable
 @code{imenu-generic-expression}:
@@ -1409,9 +1569,10 @@ for this element should go in a submenu of the buffer index;
 in the top level of the buffer index.
 
 The second item in the list, @var{regexp}, is a regular expression
-(@pxref{Regular Expressions}); wherever it matches, that is a definition
-to mention in the buffer index.  The third item, @var{subexp}, indicates
-which subexpression in @var{regexp} matches the definition's name.
+(@pxref{Regular Expressions}); anything in the buffer that it matches is
+considered a definition, something to mention in the buffer index.  The
+third item, @var{subexp}, indicates which subexpression in @var{regexp}
+matches the definition's name.
 
 An element can also look like this:
 
@@ -1420,8 +1581,8 @@ An element can also look like this:
 @end example
 
 Each match for this element creates a special index item which, if
-selected by the user, calls @var{function} with arguments
-@var{item-name}, the buffer position, and @var{arguments}.
+selected by the user, calls @var{function} with arguments consisting of
+the item name, the buffer position, and @var{arguments}.
 
 For Emacs Lisp mode, @var{pattern} could look like this:
 
@@ -1456,8 +1617,8 @@ Setting this variable makes it buffer-local in the current buffer.
 
 @defvar imenu-syntax-alist
 This variable is an alist of syntax table modifiers to use while
-executing @code{imenu--generic-function} to override the syntax table of
-the current buffer.  Each element should have this form:
+processing @code{imenu-generic-expression}, to override the syntax table
+of the current buffer.  Each element should have this form:
 
 @example
 (@var{characters} . @var{syntax-description})
@@ -1478,9 +1639,10 @@ For example, Fortran mode uses it this way:
 @end example
 
 The @code{imenu-generic-expression} patterns can then use @samp{\\sw+}
-instead of @samp{\\(\\sw\\|\\s_\\)\\}.  Note that this technique may be
-inconvenient to use when the mode needs to limit the initial character
-of a name to a smaller set of characters
+instead of @samp{\\(\\sw\\|\\s_\\)+}.  Note that this technique may be
+inconvenient when the mode needs to limit the initial character
+of a name to a smaller set of characters than are allowed in the rest
+of a name.
 
 Setting this variable makes it buffer-local in the current buffer.
 @end defvar
@@ -1490,12 +1652,12 @@ variables @code{imenu-prev-index-position-function} and
 @code{imenu-extract-index-name-function}:
 
 @defvar imenu-prev-index-position-function
-If this variable is non-@code{nil}, its value should be a function for
-finding the next definition to mention in the buffer index, moving
-backwards in the file.
-
-The function should leave point at the place to be connected to the
-index item; it should return @code{nil} if it doesn't find another item.
+If this variable is non-@code{nil}, its value should be a function that
+finds the next ``definition'' to put in the buffer index, scanning
+backward in the buffer from point.  It should return @code{nil} if it
+doesn't find another ``definition'' before point.  Otherwise it shuould
+leave point at the place it finds a ``definition,'' and return any
+non-@code{nil} value.
 
 Setting this variable makes it buffer-local in the current buffer.
 @end defvar
@@ -1510,7 +1672,7 @@ Setting this variable makes it buffer-local in the current buffer.
 @end defvar
 
   The last way to customize Imenu for a major mode is to set the
-variables @code{imenu-create-index-function}:
+variable @code{imenu-create-index-function}:
 
 @defvar imenu-create-index-function
 This variable specifies the function to use for creating a buffer index.
@@ -1553,16 +1715,16 @@ A nested sub-alist element looks like @code{(@var{index-name}
   @dfn{Font Lock mode} is a feature that automatically attaches
 @code{face} properties to certain parts of the buffer based on their
 syntactic role.  How it parses the buffer depends on the major mode;
-most major modes define syntactic criteria for which faces to use, in
+most major modes define syntactic criteria for which faces to use in
 which contexts.  This section explains how to customize Font Lock for a
-particular language---in other words, for a particular major mode.
+particular major mode.
 
   Font Lock mode finds text to highlight in two ways: through syntactic
 parsing based on the syntax table, and through searching (usually for
 regular expressions).  Syntactic fontification happens first; it finds
 comments and string constants, and highlights them using
 @code{font-lock-comment-face} and @code{font-lock-string-face}
-(@pxref{Faces for Font Lock}); search-based fontification follows.
+(@pxref{Faces for Font Lock}).  Search-based fontification follows.
 
 @menu
 * Font Lock Basics::
@@ -1578,7 +1740,7 @@ comments and string constants, and highlights them using
 
   There are several variables that control how Font Lock mode highlights
 text.  But major modes should not set any of these variables directly.
-Instead, it should set @code{font-lock-defaults} as a buffer-local
+Instead, they should set @code{font-lock-defaults} as a buffer-local
 variable.  The value assigned to this variable is used, if and when Font
 Lock mode is enabled, to set all the other variables.
 
@@ -1594,7 +1756,7 @@ this:
 
 The first element, @var{keywords}, indirectly specifies the value of
 @code{font-lock-keywords}.  It can be a symbol, a variable whose value
-is list to use for @code{font-lock-keywords}.  It can also be a list of
+is the list to use for @code{font-lock-keywords}.  It can also be a list of
 several such symbols, one for each possible level of fontification.  The
 first symbol specifies how to do level 1 fontification, the second
 symbol how to do level 2, and so on.
@@ -1617,10 +1779,12 @@ table is stored in @code{font-lock-syntax-table}.
 The fifth element, @var{syntax-begin}, specifies the value of
 @code{font-lock-beginning-of-syntax-function} (see below).
 
-Any further elements @var{other-vars} are have form
-@code{(@var{variable} . @var{value})}.  This kind of element means to
-make @var{variable} buffer-local and then set it to @var{value}.  This
-is used to set other variables that affect fontification.
+All the remaining elements (if any) are collectively called
+@var{other-vars}.  Each of these elements should have the form
+@code{(@var{variable} . @var{value})}---which means, make @var{variable}
+buffer-local and then set it to @var{value}.  You can use these
+@var{other-vars} to set other variables that affect fontification,
+aside from those you can control with the first five elements.
 @end defvar
 
 @node Search-based Fontification
@@ -1667,17 +1831,24 @@ Find text by calling @var{function}, and highlight the matches
 it finds using @code{font-lock-keyword-face}.
 
 When @var{function} is called, it receives one argument, the limit of
-the search.  It should return non-@code{nil} if it succeeds, and set the
-match data to describe the match that was found.
+the search; it should searching at point, and not search beyond the
+limit.  It should return non-@code{nil} if it succeeds, and set the
+match data to describe the match that was found.  Returning @code{nil}
+indicates failure of the search.
+
+Fontification will call @var{function} repeatedly with the same limit,
+and with point where the previous invocation left it, until
+@var{function} fails.  On failure, @var{function} need not reset point
+in any particular way.
 
 @item (@var{matcher} . @var{match})
-In this kind of element, @var{matcher} stands for either a regular
+In this kind of element, @var{matcher} is either a regular
 expression or a function, as described above.  The @sc{cdr},
 @var{match}, specifies which subexpression of @var{matcher} should be
 highlighted (instead of the entire text that @var{matcher} matched).
 
 @example
-;; @r{Highlight the @samp{bar} in each occurrences of @samp{fubar},}
+;; @r{Highlight the @samp{bar} in each occurrence of @samp{fubar},}
 ;; @r{using @code{font-lock-keyword-face}.}
 ("fu\\(bar\\)" . 1)
 @end example
@@ -1720,6 +1891,11 @@ beginning of the @code{face} property.  If it is @code{append}, the face
 
 If @var{laxmatch} is non-@code{nil}, it means there should be no error
 if there is no subexpression numbered @var{subexp} in @var{matcher}.
+Obviously, fontification of the subexpression numbered @var{subexp} will
+not occur.  However, fontification of other subexpressions (and other
+regexps) will continue.  If @var{laxmatch} is @code{nil}, and the
+specified subexpression is missing, then an error is signalled which
+terminates search-based fontification.
 
 Here are some examples of elements of this kind, and what they do:
 
@@ -1729,7 +1905,7 @@ Here are some examples of elements of this kind, and what they do:
 ;; @r{@code{foo-bar-face} should be a variable whose value is a face.}
 ("foo\\|bar" 0 foo-bar-face t)
 
-;; @r{Highlight the first subexpression within each occurrences}
+;; @r{Highlight the first subexpression within each occurrence}
 ;; @r{that the function @code{fubar-match} finds,}
 ;; @r{using the face which is the value of @code{fubar-face}.}
 (fubar-match 1 fubar-face)
@@ -1911,51 +2087,42 @@ Thus, the default value of @code{font-lock-comment-face} is
 @table @code
 @item font-lock-comment-face
 @vindex font-lock-comment-face
-@kindex font-lock-comment-face @r{(face name)}
 Used (typically) for comments.
 
 @item font-lock-string-face
 @vindex font-lock-string-face
-@kindex font-lock-string-face @r{(face name)}
 Used (typically) for string constants.
 
 @item font-lock-keyword-face
 @vindex font-lock-keyword-face
-@kindex font-lock-keyword-face @r{(face name)}
 Used (typically) for keywords---names that have special syntactic
 significance, like @code{for} and @code{if} in C.
 
 @item font-lock-builtin-face
 @vindex font-lock-builtin-face
-@kindex font-lock-builtin-face @r{(face name)}
 Used (typically) for built-in function names.
 
 @item font-lock-function-name-face
 @vindex font-lock-function-name-face
-@kindex font-lock-function-name-face @r{(face name)}
 Used (typically) for the name of a function being defined or declared,
 in a function definition or declaration. 
 
 @item font-lock-variable-name-face
 @vindex font-lock-variable-name-face
-@kindex font-lock-variable-name-face @r{(face name)}
 Used (typically) for the name of a variable being defined or declared,
 in a variable definition or declaration.
 
 @item font-lock-type-face
 @vindex font-lock-type-face
-@kindex font-lock-type-face @r{(face name)}
 Used (typically) for names of user-defined data types,
 where they are defined and where they are used.
 
 @item font-lock-constant-face
 @vindex font-lock-constant-face
-@kindex font-lock-constant-face @r{(face name)}
 Used (typically) for constant names.
 
 @item font-lock-warning-face
 @vindex font-lock-warning-face
-@kindex font-lock-warning-face @r{(face name)}
 Used (typically) for constructs that are peculiar, or that greatly
 change the meaning of other text.  For example, this is used for
 @samp{;;;###autoload} cookies in Emacs Lisp, and for @code{#error}
@@ -1999,7 +2166,7 @@ value is one of those two types.
   A @dfn{hook} is a variable where you can store a function or functions
 to be called on a particular occasion by an existing program.  Emacs
 provides hooks for the sake of customization.  Most often, hooks are set
-up in the @file{.emacs} file, but Lisp programs can set them also.
+up in the init file (@pxref{Init File}), but Lisp programs can set them also.
 @xref{Standard Hooks}, for a list of standard hook variables.
 
 @cindex normal hook
@@ -2025,7 +2192,7 @@ a Function}).  Most normal hook variables are initially void;
 
 @cindex abnormal hook
   If the hook variable's name does not end with @samp{-hook}, that
-indicates it is probably an @dfn{abnormal hook}; you should look at its
+indicates it is probably an @dfn{abnormal hook}.  Then you should look at its
 documentation to see how to use the hook properly.
 
   If the variable's name ends in @samp{-functions} or @samp{-hooks},
@@ -2050,11 +2217,10 @@ in Lisp Interaction mode:
 run particular hooks.  This function calls the hook functions that have
 been added with @code{add-hook}.
 
-@defun run-hooks &rest hookvar
+@defun run-hooks &rest hookvars
 This function takes one or more hook variable names as arguments, and
-runs each hook in turn.  Each @var{hookvar} argument should be a symbol
-that is a hook variable.  These arguments are processed in the order
-specified.
+runs each hook in turn.  Each argument should be a symbol that is a hook
+variable.  These arguments are processed in the order specified.
 
 If a hook variable has a non-@code{nil} value, that value may be a
 function or a list of functions.  If the value is a function (either a
@@ -2081,7 +2247,9 @@ each of them the arguments @var{args}.
 This function is the way to run an abnormal hook which passes arguments
 to the hook functions, and stops as soon as any hook function fails.  It
 calls each of the hook functions, passing each of them the arguments
-@var{args}, until some hook function returns @code{nil}.  Then it stops.
+@var{args}, until some hook function returns @code{nil}.  Then it stops,
+and returns @code{nil} if some hook function returned @code{nil}.
+Otherwise it returns a non-@code{nil} value.
 @end defun
 
 @defun run-hook-with-args-until-success hook &rest args
@@ -2089,7 +2257,8 @@ This function is the way to run an abnormal hook which passes arguments
 to the hook functions, and stops as soon as any hook function succeeds.
 It calls each of the hook functions, passing each of them the arguments
 @var{args}, until some hook function returns non-@code{nil}.  Then it
-stops.
+stops, and returns whatever was returned by the last hook function
+that was called.
 @end defun
 
 @defun add-hook hook function &optional append local
@@ -2116,11 +2285,8 @@ argument @var{append} is non-@code{nil}, the new hook function goes at
 the end of the hook list and will be executed last.
 
 If @var{local} is non-@code{nil}, that says to make the new hook
-function buffer-local in the current buffer.  Before you can do this, you must
-make the hook itself buffer-local by calling @code{make-local-hook}
-(@strong{not} @code{make-local-variable}).  If the hook itself is not
-buffer-local, then the value of @var{local} makes no difference---the
-hook function is always global.
+function buffer-local in the current buffer and automatically calls
+@code{make-local-hook} to make the hook itself buffer-local.
 @end defun
 
 @defun remove-hook hook function &optional local
@@ -2138,9 +2304,9 @@ current buffer.  When a hook variable is buffer-local, it can have
 buffer-local and global hook functions, and @code{run-hooks} runs all of
 them.
 
-This function works by making @code{t} an element of the buffer-local
-value.  That serves as a flag to use the hook functions in the default
-value of the hook variable as well as those in the buffer-local value.
+This function works by adding @code{t} as an element of the buffer-local
+value.  That serves as a flag to use the hook functions listed in the default
+value of the hook variable, as well as those listed in the buffer-local value.
 Since @code{run-hooks} understands this flag, @code{make-local-hook}
 works with all normal hooks.  It works for only some non-normal
 hooks---those whose callers have been updated to understand this meaning