(Derived Modes): Clarify :group keyword.
[bpt/emacs.git] / lispref / modes.texi
index 6087d7f..f823051 100644 (file)
@@ -20,6 +20,7 @@ user.  For related topics such as keymaps and syntax tables, see
 @ref{Keymaps}, and @ref{Syntax Tables}.
 
 @menu
+* Hooks::              How to use hooks; how to write code that provides hooks.
 * Major Modes::        Defining major modes.
 * Minor Modes::        Defining minor modes.
 * Mode Line Format::   Customizing the text that appears in the mode line.
@@ -28,13 +29,152 @@ user.  For related topics such as keymaps and syntax tables, see
 * Font Lock Mode::     How modes can highlight text according to syntax.
 * Desktop Save Mode::  How modes can have buffer state saved between
                          Emacs sessions.
-* Hooks::              How to use hooks; how to write code that provides hooks.
 @end menu
 
+@node Hooks
+@section Hooks
+@cindex hooks
+
+  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 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
+  Most of the hooks in Emacs are @dfn{normal hooks}.  These variables
+contain lists of functions to be called with no arguments.  When the
+hook name ends in @samp{-hook}, that tells you it is normal.  We try to
+make all hooks normal, as much as possible, so that you can use them in
+a uniform way.
+
+  Every major mode function is supposed to run a normal hook called the
+@dfn{mode hook} as the last step of initialization.  This makes it easy
+for a user to customize the behavior of the mode, by overriding the
+buffer-local variable assignments already made by the mode.  Most
+minor modes also run a mode hook at their end.  But hooks are used in
+other contexts too.  For example, the hook @code{suspend-hook} runs
+just before Emacs suspends itself (@pxref{Suspending Emacs}).
+
+  The recommended way to add a hook function to a normal hook is by
+calling @code{add-hook} (see below).  The hook functions may be any of
+the valid kinds of functions that @code{funcall} accepts (@pxref{What
+Is a Function}).  Most normal hook variables are initially void;
+@code{add-hook} knows how to deal with this.  You can add hooks either
+globally or buffer-locally with @code{add-hook}.
+
+@cindex abnormal hook
+  If the hook variable's name does not end with @samp{-hook}, that
+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},
+then the value is a list of functions, but it is abnormal in that either
+these functions are called with arguments or their values are used in
+some way.  You can use @code{add-hook} to add a function to the list,
+but you must take care in writing the function.  (A few of these
+variables, notably those ending in @samp{-hooks}, are actually
+normal hooks which were named before we established the convention of
+using @samp{-hook} for them.)
+
+  If the variable's name ends in @samp{-function}, then its value
+is just a single function, not a list of functions.
+
+  Here's an example that uses a mode hook to turn on Auto Fill mode when
+in Lisp Interaction mode:
+
+@example
+(add-hook 'lisp-interaction-mode-hook 'turn-on-auto-fill)
+@end example
+
+  At the appropriate time, Emacs uses the @code{run-hooks} function to
+run particular hooks.
+
+@defun run-hooks &rest hookvars
+This function takes one or more normal hook variable names as
+arguments, and runs each hook in turn.  Each argument should be a
+symbol that is a normal 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.  (The former option is considered
+obsolete.)  If the value is a function (either a lambda expression or
+a symbol with a function definition), it is called.  If it is a list
+that isn't a function, its elements are called, consecutively.  All
+the hook functions are called with no arguments.
+@end defun
+
+@defun run-hook-with-args hook &rest args
+This function is the way to run an abnormal hook and always call all
+of the hook functions.  It calls each of the hook functions one by
+one, passing each of them the arguments @var{args}.
+@end defun
+
+@defun run-hook-with-args-until-failure hook &rest args
+This function is the way to run an abnormal hook until one of the hook
+functions fails.  It calls each of the hook functions, passing each of
+them the arguments @var{args}, until some hook function returns
+@code{nil}.  It then stops and returns @code{nil}.  If none of the
+hook functions return @code{nil}, it returns a non-@code{nil} value.
+@end defun
+
+@defun run-hook-with-args-until-success hook &rest args
+This function is the way to run an abnormal hook until a 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, and returns whatever was returned by
+the last hook function that was called.  If all hook functions return
+@code{nil}, it returns @code{nil} as well.
+@end defun
+
+@defun add-hook hook function &optional append local
+This function is the handy way to add function @var{function} to hook
+variable @var{hook}.  You can use it for abnormal hooks as well as for
+normal hooks.  @var{function} can be any Lisp function that can accept
+the proper number of arguments for @var{hook}.  For example,
+
+@example
+(add-hook 'text-mode-hook 'my-text-hook-function)
+@end example
+
+@noindent
+adds @code{my-text-hook-function} to the hook called @code{text-mode-hook}.
+
+If @var{function} is already present in @var{hook} (comparing using
+@code{equal}), then @code{add-hook} does not add it a second time.
+
+It is best to design your hook functions so that the order in which they
+are executed does not matter.  Any dependence on the order is ``asking
+for trouble''.  However, the order is predictable: normally,
+@var{function} goes at the front of the hook list, so it will be
+executed first (barring another @code{add-hook} call).  If the optional
+argument @var{append} is non-@code{nil}, the new hook function goes at
+the end of the hook list and will be executed last.
+
+@code{add-hook} can handle the cases where @var{hook} is void or its
+value is a single function; it sets or changes the value to a list of
+functions.
+
+If @var{local} is non-@code{nil}, that says to add @var{function} to
+the buffer-local hook list instead of to the global hook list.  If
+needed, this makes the hook buffer-local and adds @code{t} to the
+buffer-local value.  The latter acts as a flag to run the hook
+functions in the default value as well as in the local value.
+@end defun
+
+@defun remove-hook hook function &optional local
+This function removes @var{function} from the hook variable
+@var{hook}.  It compares @var{function} with elements of @var{hook}
+using @code{equal}, so it works for both symbols and lambda
+expressions.
+
+If @var{local} is non-@code{nil}, that says to remove @var{function}
+from the buffer-local hook list instead of from the global hook list.
+@end defun
+
 @node Major Modes
 @section Major Modes
 @cindex major mode
-@cindex Fundamental mode
 
   Major modes specialize Emacs for editing particular kinds of text.
 Each buffer has only one major mode at a time.  For each major mode
@@ -44,6 +184,23 @@ buffer-local variable bindings and other data associated with the
 buffer, such as a local keymap.  The effect lasts until you switch
 to another major mode in the same buffer.
 
+@menu
+* Major Mode Basics::
+* Major Mode Conventions::  Coding conventions for keymaps, etc.
+* Example Major Modes::     Text mode and Lisp modes.
+* Auto Major Mode::         How Emacs chooses the major mode automatically.
+* Mode Help::               Finding out how to use a mode.
+* Derived Modes::           Defining a new major mode based on another major
+                              mode.
+* Generic Modes::           Defining a simple major mode that supports
+                              comment syntax and Font Lock mode.
+* Mode Hooks::              Hooks run at the end of major mode functions.
+@end menu
+
+@node Major Mode Basics
+@subsection Major Mode Basics
+@cindex Fundamental mode
+
   The least specialized major mode is called @dfn{Fundamental mode}.
 This mode has no mode-specific definitions or variable settings, so each
 Emacs command behaves in its default manner, and each option is in its
@@ -71,10 +228,9 @@ 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.
 
-@findex define-generic-mode
   For a very simple programming language major mode that handles
-comments and fontification, you can use @code{define-generic-mode}
-in @file{generic.el}.
+comments and fontification, you can use @code{define-generic-mode}.
+@xref{Generic Modes}.
 
   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
@@ -96,16 +252,6 @@ for several major modes, in files such as @file{text-mode.el},
 are written.  Text mode is perhaps the simplest major mode aside from
 Fundamental mode.  Rmail mode is a complicated and specialized mode.
 
-@menu
-* Major Mode Conventions::  Coding conventions for keymaps, etc.
-* Example Major Modes::     Text mode and Lisp modes.
-* Auto Major Mode::         How Emacs chooses the major mode automatically.
-* Mode Help::               Finding out how to use a mode.
-* Derived Modes::           Defining a new major mode based on another major
-                              mode.
-* Mode Hooks::              Hooks run at the end of major mode functions.
-@end menu
-
 @node Major Mode Conventions
 @subsection Major Mode Conventions
 
@@ -239,7 +385,7 @@ related modes.  If it has its own abbrev table, it should store this
 in a variable named @code{@var{modename}-mode-abbrev-table}.  If the
 major mode command defines any abbrevs itself, it should pass @code{t}
 for the @var{system-flag} argument to @code{define-abbrev}.
-@xref{Abbrev Tables}.
+@xref{Defining Abbrevs}.
 
 @item
 The mode should specify how to do highlighting for Font Lock mode, by
@@ -254,6 +400,11 @@ variable @code{imenu-generic-expression}, for the pair of variables
 @code{imenu-extract-index-name-function}, or for the variable
 @code{imenu-create-index-function} (@pxref{Imenu}).
 
+@item
+The mode can specify a local value for
+@code{eldoc-documentation-function} to tell ElDoc mode how to handle
+this mode.
+
 @item
 Use @code{defvar} or @code{defcustom} to set mode-related variables, so
 that they are not reinitialized if they already have a value.  (Such
@@ -318,10 +469,13 @@ and Buffer List use this feature.
 @item
 If you want to make the new mode the default for files with certain
 recognizable names, add an element to @code{auto-mode-alist} to select
-the mode for those file names.  If you define the mode command to
-autoload, you should add this element in the same file that calls
-@code{autoload}.  Otherwise, it is sufficient to add the element in the
-file that contains the mode definition.  @xref{Auto Major Mode}.
+the mode for those file names (@pxref{Auto Major Mode}).  If you
+define the mode command to autoload, you should add this element in
+the same file that calls @code{autoload}.  If you use an autoload
+cookie for the mode command, you can also use an autoload cookie for
+the form that adds the element (@pxref{autoload cookie}).  If you do
+not autoload the mode command, it is sufficient to add the element in
+the file that contains the mode definition.
 
 @item
 In the comments that document the file, you should provide a sample
@@ -629,21 +783,28 @@ state of Emacs.)
 
 @deffn Command normal-mode &optional find-file
 This function establishes the proper major mode and buffer-local variable
-bindings for the current buffer.  First it calls @code{set-auto-mode},
-then it runs @code{hack-local-variables} to parse, and bind or
-evaluate as appropriate, the file's local variables.
+bindings for the current buffer.  First it calls @code{set-auto-mode}
+(see below), then it runs @code{hack-local-variables} to parse, and
+bind or evaluate as appropriate, the file's local variables
+(@pxref{File Local Variables}).
 
 If the @var{find-file} argument to @code{normal-mode} is non-@code{nil},
 @code{normal-mode} assumes that the @code{find-file} function is calling
-it.  In this case, it may process a local variables list at the end of
-the file and in the @samp{-*-} line.  The variable
+it.  In this case, it may process local variables in the @samp{-*-}
+line or at the end of the file.  The variable
 @code{enable-local-variables} controls whether to do so.  @xref{File
-variables, , Local Variables in Files, emacs, The GNU Emacs Manual}, for
-the syntax of the local variables section of a file.
+Variables, , Local Variables in Files, emacs, The GNU Emacs Manual},
+for the syntax of the local variables section of a file.
 
 If you run @code{normal-mode} interactively, the argument
 @var{find-file} is normally @code{nil}.  In this case,
-@code{normal-mode} unconditionally processes any local variables list.
+@code{normal-mode} unconditionally processes any file local variables.
+
+If @code{normal-mode} processes the local variables list and this list
+specifies a major mode, that mode overrides any mode chosen by
+@code{set-auto-mode}.  If neither @code{set-auto-mode} nor
+@code{hack-local-variables} specify a major mode, the buffer stays in
+the major mode determined by @code{default-major-mode} (see below).
 
 @cindex file mode specification error
 @code{normal-mode} uses @code{condition-case} around the call to the
@@ -651,16 +812,25 @@ major mode function, so errors are caught and reported as a @samp{File
 mode specification error},  followed by the original error message.
 @end deffn
 
-@defun set-auto-mode
+@defun set-auto-mode &optional keep-mode-if-same
 @cindex visited file mode
   This function selects the major mode that is appropriate for the
-current buffer.  It may base its decision on the value of the @w{@samp{-*-}}
-line, on the visited file name (using @code{auto-mode-alist}), on the
-@w{@samp{#!}} line (using @code{interpreter-mode-alist}), or on the
-file's local variables list.  However, this function does not look for
-the @samp{mode:} local variable near the end of a file; the
-@code{hack-local-variables} function does that.  @xref{Choosing Modes, ,
-How Major Modes are Chosen, emacs, The GNU Emacs Manual}.
+current buffer.  It bases its decision (in order of precedence) on
+the @w{@samp{-*-}} line, on the @w{@samp{#!}} line (using
+@code{interpreter-mode-alist}), on the text at the beginning of the
+buffer (using @code{magic-mode-alist}), and finally on the visited
+file name (using @code{auto-mode-alist}).  @xref{Choosing Modes, , How
+Major Modes are Chosen, emacs, The GNU Emacs Manual}.  However, this
+function does not look for the @samp{mode:} local variable near the
+end of a file; the @code{hack-local-variables} function does that.
+If @code{enable-local-variables} is @code{nil}, @code{set-auto-mode}
+does not check the @w{@samp{-*-}} line for a mode tag either.
+
+If @var{keep-mode-if-same} is non-@code{nil}, this function does not
+call the mode command if the buffer is already in the proper major
+mode.  For instance, @code{set-visited-file-name} sets this to
+@code{t} to avoid killing buffer local variables that the user may
+have set.
 @end defun
 
 @defopt default-major-mode
@@ -668,8 +838,8 @@ This variable holds the default major mode for new buffers.  The
 standard value is @code{fundamental-mode}.
 
 If the value of @code{default-major-mode} is @code{nil}, Emacs uses
-the (previously) current buffer's major mode for the major mode of a new
-buffer.  However, if that major mode symbol has a @code{mode-class}
+the (previously) current buffer's major mode as the default major mode
+of a new buffer.  However, if that major mode symbol has a @code{mode-class}
 property with value @code{special}, then it is not used for new buffers;
 Fundamental mode is used instead.  The modes that have this property are
 those such as Dired and Rmail that are useful only with text that has
@@ -678,28 +848,50 @@ been specially prepared.
 
 @defun set-buffer-major-mode buffer
 This function sets the major mode of @var{buffer} to the value of
-@code{default-major-mode}.  If that variable is @code{nil}, it uses
-the current buffer's major mode (if that is suitable).
+@code{default-major-mode}; if that variable is @code{nil}, it uses the
+current buffer's major mode (if that is suitable).  As an exception,
+if @var{buffer}'s name is @samp{*scratch*}, it sets the mode to
+@code{initial-major-mode}.
 
 The low-level primitives for creating buffers do not use this function,
 but medium-level commands such as @code{switch-to-buffer} and
 @code{find-file-noselect} use it whenever they create buffers.
 @end defun
 
-@defvar initial-major-mode
+@defopt initial-major-mode
 @cindex @samp{*scratch*}
 The value of this variable determines the major mode of the initial
 @samp{*scratch*} buffer.  The value should be a symbol that is a major
 mode command.  The default value is @code{lisp-interaction-mode}.
+@end defopt
+
+@defvar interpreter-mode-alist
+This variable specifies major modes to use for scripts that specify a
+command interpreter in a @samp{#!} line.  Its value is an alist with
+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 an interpreter which matches @var{interpreter}.  The value
+of @var{interpreter} is actually a regular expression. @xref{Regular
+Expressions}.
+@end defvar
+
+@defvar magic-mode-alist
+This variable's value is an alist with elements of the form
+@code{(@var{regexp} .  @var{function})}, where @var{regexp} is a
+regular expression and @var{function} is a function or @code{nil}.
+After visiting a file, @code{set-auto-mode} calls @var{function} if
+the text at the beginning of the buffer matches @var{regexp} and
+@var{function} is non-@code{nil}; if @var{function} is @code{nil},
+@code{auto-mode-alist} gets to decide the mode.
 @end defvar
 
 @defvar auto-mode-alist
 This variable contains an association list of file name patterns
-(regular expressions; @pxref{Regular Expressions}) and corresponding
-major mode commands.  Usually, the file name patterns test for suffixes,
-such as @samp{.el} and @samp{.c}, but this need not be the case.  An
-ordinary element of the alist looks like @code{(@var{regexp} .
-@var{mode-function})}.
+(regular expressions) and corresponding major mode commands.  Usually,
+the file name patterns test for suffixes, such as @samp{.el} and
+@samp{.c}, but this need not be the case.  An ordinary element of the
+alist looks like @code{(@var{regexp} .  @var{mode-function})}.
 
 For example,
 
@@ -718,9 +910,11 @@ For example,
 @end smallexample
 
 When you visit a file whose expanded file name (@pxref{File Name
-Expansion}) matches a @var{regexp}, @code{set-auto-mode} calls the
-corresponding @var{mode-function}.  This feature enables Emacs to select
-the proper major mode for most files.
+Expansion}), with version numbers and backup suffixes removed using
+@code{file-name-sans-versions} (@pxref{File Name Components}), matches
+a @var{regexp}, @code{set-auto-mode} calls the corresponding
+@var{mode-function}.  This feature enables Emacs to select the proper
+major mode for most files.
 
 If an element of @code{auto-mode-alist} has the form @code{(@var{regexp}
 @var{function} t)}, then after calling @var{function}, Emacs searches
@@ -749,19 +943,6 @@ init file.)
 @end smallexample
 @end defvar
 
-@defvar interpreter-mode-alist
-This variable specifies major modes to use for scripts that specify a
-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
-an interpreter which matches @var{interpreter}.  The value of
-@var{interpreter} is actually a regular expression.
-
-This variable is applicable only when the @code{auto-mode-alist} does
-not indicate which major mode to use.
-@end defvar
-
 @node Mode Help
 @subsection Getting Help about a Major Mode
 @cindex mode help
@@ -793,50 +974,86 @@ mode.
 
 @node Derived Modes
 @subsection Defining Derived Modes
+@cindex derived mode
 
   It's often useful to define a new major mode in terms of an existing
 one.  An easy way to do this is to use @code{define-derived-mode}.
 
-@defmac define-derived-mode variant parent name docstring body@dots{}
+@defmac define-derived-mode variant parent name docstring keyword-args@dots{} body@dots{}
 This construct defines @var{variant} as a major mode command, using
-@var{name} as the string form of the mode name.
+@var{name} as the string form of the mode name.  @var{variant} and
+@var{parent} should be unquoted symbols.
 
 The new command @var{variant} is defined to call the function
 @var{parent}, then override certain aspects of that parent mode:
 
 @itemize @bullet
 @item
-The new mode has its own keymap, named @code{@var{variant}-map}.
-@code{define-derived-mode} initializes this map to inherit from
-@code{@var{parent}-map}, if it is not already set.
+The new mode has its own sparse keymap, named
+@code{@var{variant}-map}.  @code{define-derived-mode}
+makes the parent mode's keymap the parent of the new map, unless
+@code{@var{variant}-map} is already set and already has a parent.
 
 @item
 The new mode has its own syntax table, kept in the variable
-@code{@var{variant}-syntax-table}.
-@code{define-derived-mode} initializes this variable by copying
-@code{@var{parent}-syntax-table}, if it is not already set.
+@code{@var{variant}-syntax-table}, unless you override this using the
+@code{:syntax-table} keyword (see below).  @code{define-derived-mode}
+makes the parent mode's syntax-table the parent of
+@code{@var{variant}-syntax-table}, unless the latter is already set
+and already has a parent different from the standard syntax table.
 
 @item
 The new mode has its own abbrev table, kept in the variable
-@code{@var{variant}-abbrev-table}.
-@code{define-derived-mode} initializes this variable by copying
-@code{@var{parent}-abbrev-table}, if it is not already set.
+@code{@var{variant}-abbrev-table}, unless you override this using the
+@code{:abbrev-table} keyword (see below).
 
 @item
-The new mode has its own mode hook, @code{@var{variant}-hook},
-which it runs in standard fashion as the very last thing that it does.
-(The new mode also runs the mode hook of @var{parent} as part
-of calling @var{parent}.)
+The new mode has its own mode hook, @code{@var{variant}-hook}.  It
+runs this hook, after running the hooks of its ancestor modes, with
+@code{run-mode-hooks}, as the last thing it does. @xref{Mode Hooks}.
 @end itemize
 
 In addition, you can specify how to override other aspects of
 @var{parent} with @var{body}.  The command @var{variant}
 evaluates the forms in @var{body} after setting up all its usual
-overrides, just before running @code{@var{variant}-hook}.
+overrides, just before running the mode hooks.
 
-The argument @var{docstring} specifies the documentation string for the
-new mode.  If you omit @var{docstring}, @code{define-derived-mode}
-generates a documentation string.
+You can also specify @code{nil} for @var{parent}.  This gives the new
+mode no parent.  Then @code{define-derived-mode} behaves as described
+above, but, of course, omits all actions connected with @var{parent}.
+
+The argument @var{docstring} specifies the documentation string for
+the new mode.  @code{define-derived-mode} adds some general
+information about the mode's hook, followed by the mode's keymap, at
+the end of this docstring.  If you omit @var{docstring},
+@code{define-derived-mode} generates a documentation string.
+
+The @var{keyword-args} are pairs of keywords and values.  The values
+are evaluated.  The following keywords are currently supported:
+
+@table @code
+@item :syntax-table
+You can use this to explicitly specify a syntax table for the new
+mode.  If you specify a @code{nil} value, the new mode uses the same
+syntax table as @var{parent}, or the standard syntax table if
+@var{parent} is @code{nil}.  (Note that this does @emph{not} follow
+the convention used for non-keyword arguments that a @code{nil} value
+is equivalent with not specifying the argument.)
+
+@item :abbrev-table
+You can use this to explicitly specify an abbrev table for the new
+mode.  If you specify a @code{nil} value, the new mode uses the same
+abbrev table as @var{parent}, or @code{fundamental-mode-abbrev-table}
+if @var{parent} is @code{nil}.  (Again, a @code{nil} value is
+@emph{not} equivalent to not specifying this keyword.)
+
+@item :group
+If this is specified, the value should be the customization group for
+this mode.  (Not all major modes have one.)  Only the (still
+experimental and unadvertised) command @code{customize-mode} currently
+uses this.  @code{define-derived-mode} does @emph{not} automatically
+define the specified customization group.
+@end table
 
 Here is a hypothetical example:
 
@@ -855,6 +1072,48 @@ Do not write an @code{interactive} spec in the definition;
 @code{define-derived-mode} does that automatically.
 @end defmac
 
+@node Generic Modes
+@subsection Generic Modes
+@cindex generic mode
+
+@dfn{Generic modes} are simple major modes with basic support for
+comment syntax and Font Lock mode.  They are primarily useful for
+configuration files.  To define a generic mode, use the macro
+@code{define-generic-mode}.  See the file @file{generic-x.el} for some
+examples of the use of @code{define-generic-mode}.
+
+@defmac define-generic-mode mode comment-list keyword-list font-lock-list auto-mode-list function-list &optional docstring
+This macro creates a new generic mode.  The argument @var{mode} (an
+unquoted symbol) is the major mode command.  The optional argument
+@var{docstring} is the documentation for the mode command.  If you do
+not supply it, @code{define-generic-mode} uses a default documentation
+string instead.
+
+@var{comment-list} is a list in which each element is either a
+character, a string of one or two characters, or a cons cell.  A
+character or a string is set up in the mode's syntax table as a
+``comment starter.''  If the entry is a cons cell, the @sc{car} is set
+up as a ``comment starter'' and the @sc{cdr} as a ``comment ender.''
+(Use @code{nil} for the latter if you want comments to end at the end
+of the line.)  Note that the syntax table has limitations about what
+comment starters and enders are actually possible.  @xref{Syntax
+Tables}.
+
+@var{keyword-list} is a list of keywords to highlight with
+@code{font-lock-keyword-face}.  Each keyword should be a string.
+@var{font-lock-list} is a list of additional expressions to highlight.
+Each element of this list should have the same form as an element of
+@code{font-lock-keywords}.  @xref{Search-based Fontification}.
+
+@var{auto-mode-list} is a list of regular expressions to add to the
+variable @code{auto-mode-alist}.  These regular expressions are added
+when Emacs runs the macro expansion.
+
+@var{function-list} is a list of functions to call to do some
+additional setup.  The mode command calls these functions just before
+it runs the mode hook variable @code{@var{mode}-hook}.
+@end defmac
+
 @node Mode Hooks
 @subsection Mode Hooks
 
@@ -1006,8 +1265,9 @@ enable or disable the minor mode based on the raw prefix argument value.
 
 @item
 Add an element to @code{minor-mode-alist} for each minor mode
-(@pxref{Mode Line Variables}), if you want to indicate the minor mode in
-the mode line.  This element should be a list of the following form:
+(@pxref{Definition of minor-mode-alist}), if you want to indicate the
+minor mode in the mode line.  This element should be a list of the
+following form:
 
 @smallexample
 (@var{mode-variable} @var{string})
@@ -1049,7 +1309,7 @@ should also specify a @code{:set} method which enables the mode by
 invoking 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}),
+  Also mark the definition with an autoload cookie (@pxref{autoload cookie}),
 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
@@ -1078,7 +1338,7 @@ use either \\[customize] or the function `msb-mode'."
 
   Each minor mode can have its own keymap, which is active when the mode
 is enabled.  To set up a keymap for a minor mode, add an element to the
-alist @code{minor-mode-map-alist}.  @xref{Active Keymaps}.
+alist @code{minor-mode-map-alist}.  @xref{Definition of minor-mode-map-alist}.
 
 @cindex @code{self-insert-command}, minor modes
   One use of minor mode keymaps is to modify the behavior of certain
@@ -1129,13 +1389,15 @@ corresponding values.  A few keywords have special meanings:
 @table @code
 @item :group @var{group}
 Custom group name to use in all generated @code{defcustom} forms.
-Defaults to @var{mode} without the possible trailing @samp{-mode}.  Be
-aware that this default may not be a valid customization group defined
-with @code{defgroup}.  Please make sure it is.
+Defaults to @var{mode} without the possible trailing @samp{-mode}.
+@strong{Warning:} don't use this default group name unless you have
+written a @code{defgroup} to define that group properly.  @xref{Group
+Definitions}.
 
 @item :global @var{global}
-If non-@code{nil} specifies that the minor mode should be global.
-By default, minor modes are buffer-local.
+If non-@code{nil} specifies that the minor mode should be global.  By
+default, minor modes defined with @code{define-minor-mode} are
+buffer-local.
 
 @item :init-value @var{init-value}
 This is equivalent to specifying @var{init-value} positionally.
@@ -1150,9 +1412,10 @@ This is equivalent to specifying @var{keymap} positionally.
 Any other keyword arguments are passed passed directly to the
 @code{defcustom} generated for the variable @var{mode}.
 
-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 command named @var{mode} first performs the standard actions such
+as setting the variable named @var{mode} and then executes the
+@var{body} forms, if any.  It finishes by running the mode hook
+variable @code{@var{mode}-hook}.
 @end defmac
 
 @findex easy-mmode-define-minor-mode
@@ -1216,6 +1479,17 @@ See the command \\[hungry-electric-delete]."
  :group 'hunger)
 @end smallexample
 
+@defmac define-global-minor-mode global-mode mode turn-on keyword-args...
+This defines a global minor mode named @var{global-mode} whose meaning
+is to enable the buffer-local minor mode @var{mode} in every buffer.
+To turn on the minor mode in a buffer, it uses the function
+@var{turn-on}; to turn off the minor mode, it calls @code{mode} with
+@minus{}1 as argument.
+
+Use @code{:group @var{group}} in @var{keyword-args} to specify the
+custom group for the mode variable of the global minor mode.
+@end defmac
+
 @node Mode Line Format
 @section Mode-Line Format
 @cindex mode line
@@ -1233,6 +1507,19 @@ 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.
 
+@menu
+* Mode Line Basics::
+* 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.
+* Emulating Mode Line::   Formatting text as the mode line would.
+@end menu
+
+@node Mode Line Basics
+@subsection Mode Line Basics
+
   @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}, so
@@ -1274,15 +1561,6 @@ that is two lines tall cannot display both a mode line and a header
 line at once; if the variables call for both, only the mode line
 actually appears.
 
-@menu
-* 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.
-* Emulating Mode Line::   Formatting text as the mode line would.
-@end menu
-
 @node Mode Line Data
 @subsection The Data Structure of the Mode Line
 @cindex mode-line construct
@@ -1354,7 +1632,9 @@ 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.
+@var{form}, and use the result as a string to display.  Make sure this
+evaluation cannot load any files, as doing so could cause infinite
+recursion.
 
 @item (:propertize @var{elt} @var{props}@dots{})
 A list whose first element is the symbol @code{:propertize} says to
@@ -1376,9 +1656,10 @@ the value of @var{symbol} is @code{nil}.
 A list whose first element is an integer specifies truncation or
 padding of the results of @var{rest}.  The remaining elements
 @var{rest} are processed recursively as mode-line constructs and
-concatenated together.  Then the result is space filled (if
-@var{width} is positive) or truncated (to @minus{}@var{width} columns,
-if @var{width} is negative) on the right.
+concatenated together.  When @var{width} is positive, the result is
+space filled on the right if its width is less than @var{width}.  When
+@var{width} is negative, the result is truncated on the right to
+@minus{}@var{width} columns if its width exceeds @minus{}@var{width}.
 
 For example, the usual way to show what percentage of a buffer is above
 the top of the window is to use a list like this: @code{(-3 "%p")}.
@@ -1544,6 +1825,7 @@ is @code{nil}.
 @end defvar
 
 @defvar minor-mode-alist
+@anchor{Definition of minor-mode-alist}
 This variable holds an association list whose elements specify how the
 mode line should indicate that a minor mode is active.  Each element of
 the @code{minor-mode-alist} should be a two-element list:
@@ -1615,7 +1897,8 @@ specifies addition of text properties.
 
   The following table lists the recognized @code{%}-constructs and what
 they mean.  In any construct except @samp{%%}, you can add a decimal
-integer after the @samp{%} to specify how many characters to display.
+integer after the @samp{%} to specify a minimum field width.  If the
+width is less, the field is padded with spaces to the right.
 
 @table @code
 @item %b
@@ -1720,7 +2003,7 @@ The value of @code{global-mode-string}.  Currently, only
 
   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{help-echo} property associates help strings with the text, and
 @code{local-map} can make the text mouse-sensitive.
 
   There are four ways to specify text properties for text in the mode
@@ -1788,7 +2071,7 @@ It is normally @code{nil}, so that ordinary buffers have no header line.
 
   You can use the function @code{format-mode-line} to compute
 the text that would appear in a mode line or header line
-based on certain mode-line specification.
+based on certain mode-line specification.
 
 @defun format-mode-line format &optional face window buffer
 This function formats a line of text according to @var{format} as if
@@ -1804,7 +2087,8 @@ faces, keymaps, etc., that the mode line would have.  And any character
 for which no @code{face} property is specified gets a default
 value which is usually @var{face}.  (If @var{face} is @code{t},
 that stands for either @code{mode-line} if @var{window} is selected,
-otherwise @code{mode-line-inactive}.)
+otherwise @code{mode-line-inactive}.  If @var{face} is @code{nil} or
+omitted, that stands for no face property.)
 
 However, if @var{face} is an integer, the value has no text properties.
 
@@ -2020,12 +2304,11 @@ 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 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.
+  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.
+Search-based fontification happens second.
 
 @menu
 * Font Lock Basics::            Overview of customizing Font Lock.
@@ -2036,7 +2319,8 @@ comments and string constants, and highlights them using
 * Precalculated Fontification:: How Lisp programs that produce the buffer
                                   contents can also specify how to fontify it.
 * Faces for Font Lock::         Special faces specifically for Font Lock.
-* Syntactic Font Lock::         Defining character syntax based on context
+* Syntactic Font Lock::         Fontification based on syntax tables.
+* Setting Syntax Properties::   Defining character syntax based on context
                                   using the Font Lock mechanism.
 @end menu
 
@@ -2051,45 +2335,48 @@ Lock mode is enabled, to set all the other variables.
 
 @defvar font-lock-defaults
 This variable is set by major modes, as a buffer-local variable, to
-specify how to fontify text in that mode.  The value should look like
-this:
+specify how to fontify text in that mode.  It automatically becomes
+buffer-local when you set it.  The value should look like this:
 
 @example
-(@var{keywords} @var{keywords-only} @var{case-fold}
@var{syntax-alist} @var{syntax-begin} @var{other-vars}@dots{})
+(@var{keywords} [@var{keywords-only} [@var{case-fold}
[@var{syntax-alist} [@var{syntax-begin} @var{other-vars}@dots{}]]]])
 @end example
 
 The first element, @var{keywords}, indirectly specifies the value of
-@code{font-lock-keywords}.  It can be a symbol, a variable whose value
-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.
+@code{font-lock-keywords} which directs search-based fontification.
+It can be a symbol, a variable or a function whose value 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.  @xref{Levels of Font Lock}.
 
 The second element, @var{keywords-only}, specifies the value of the
 variable @code{font-lock-keywords-only}.  If this is non-@code{nil},
 syntactic fontification (of strings and comments) is not performed.
+@xref{Syntactic Font Lock}.
 
 The third element, @var{case-fold}, specifies the value of
-@code{font-lock-keywords-case-fold-search}.  If it is non-@code{nil}, Font Lock
-mode ignores case when searching as directed by
+@code{font-lock-keywords-case-fold-search}.  If it is non-@code{nil},
+Font Lock mode ignores case when searching as directed by
 @code{font-lock-keywords}.
 
-If the fourth element, @var{syntax-alist}, is non-@code{nil}, it should be
-a list of cons cells of the form @code{(@var{char-or-string}
+If the fourth element, @var{syntax-alist}, is non-@code{nil}, it
+should be a list of cons cells of the form @code{(@var{char-or-string}
 . @var{string})}.  These are used to set up a syntax table for
-fontification (@pxref{Syntax Table Functions}).  The resulting syntax
-table is stored in @code{font-lock-syntax-table}.
+syntactic fontification (@pxref{Syntax Table Functions}).  The
+resulting syntax 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).
+@code{font-lock-beginning-of-syntax-function}.
 
 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.
+@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.  @xref{Other Font Lock Variables}.
 @end defvar
 
 @node Search-based Fontification
@@ -2097,7 +2384,8 @@ aside from those you can control with the first five elements.
 
   The most important variable for customizing Font Lock mode is
 @code{font-lock-keywords}.  It specifies the search criteria for
-search-based fontification.
+search-based fontification.  You should specify the value of this
+variable with @var{keywords} in @code{font-lock-defaults}.
 
 @defvar font-lock-keywords
 This variable's value is a list of the keywords to highlight.  Be
@@ -2187,7 +2475,8 @@ other text property names that you set in this way to the value of
 @code{font-lock-extra-managed-props} so that the properties will also
 be cleared out when they are no longer appropriate.  Alternatively,
 you can set the variable @code{font-lock-unfontify-region-function} to
-a function that clears these properties.
+a function that clears these properties.  @xref{Other Font Lock
+Variables}.
 
 @item (@var{matcher} . @var{subexp-highlighter})
 In this kind of element, @var{subexp-highlighter} is a list
@@ -2307,6 +2596,7 @@ this value of @code{font-lock-keywords} is used in a buffer.
 Its value should have one of the forms described in this table.
 @end table
 
+@vindex font-lock-multiline
 @strong{Warning:} Do not design an element of @code{font-lock-keywords}
 to match text which spans lines; this does not work reliably.  While
 @code{font-lock-fontify-buffer} handles multi-line patterns correctly,
@@ -2317,52 +2607,75 @@ line but can occasionally span two or three, such as
 setting @code{font-lock-multiline} to @code{t}.  But it still will not
 work in all cases.
 
-@node Other Font Lock Variables
-@subsection Other Font Lock Variables
-
-  This section describes additional variables that a major mode
-can set by means of @code{font-lock-defaults}.
-
-@defvar font-lock-keywords-only
-Non-@code{nil} means Font Lock should not fontify comments or strings
-syntactically; it should only fontify based on
-@code{font-lock-keywords}.
-@end defvar
-
-@ignore
-Other variables include those for buffer-specialized fontification functions,
-`font-lock-fontify-buffer-function', `font-lock-unfontify-buffer-function',
-`font-lock-fontify-region-function', `font-lock-unfontify-region-function',
-`font-lock-inhibit-thing-lock' and `font-lock-maximum-size'.
-@end ignore
+You can use @var{case-fold} in @code{font-lock-defaults} to specify
+the value of @code{font-lock-keywords-case-fold-search} which says
+whether search-based fontification should be case-insensitive.
 
 @defvar font-lock-keywords-case-fold-search
 Non-@code{nil} means that regular expression matching for the sake of
 @code{font-lock-keywords} should be case-insensitive.
 @end defvar
 
-@defvar font-lock-syntax-table
-This variable specifies the syntax table to use for fontification of
-comments and strings.
-@end defvar
+You can use @code{font-lock-add-keywords} to add additional
+search-based fontification rules to a major mode, and
+@code{font-lock-remove-keywords} to removes rules.
+
+@defun font-lock-add-keywords mode keywords &optional append
+This function adds highlighting @var{keywords} for @var{mode}.  The
+argument @var{keywords} should be a list with the same format as the
+variable @code{font-lock-keywords}.  @var{mode} should be a symbol,
+the major mode command name, such as @code{c-mode}.  When Font Lock
+mode is turned on in @var{mode}, it adds @var{keywords} to
+@code{font-lock-keywords}.  @var{mode} can also be @code{nil}; the
+highlighting @var{keywords} are immediately added to
+@code{font-lock-keywords} in the current buffer in that case.
+
+By default, @var{keywords} are added at the beginning of
+@code{font-lock-keywords}.  If the optional argument @var{append} is
+@code{set}, they are used to replace the value of
+@code{font-lock-keywords}.  If @var{append} is any other
+non-@code{nil} value, they are added at the end of
+@code{font-lock-keywords}.
 
-@defvar font-lock-beginning-of-syntax-function
-If this variable is non-@code{nil}, it should be a function to move
-point back to a position that is syntactically at ``top level'' and
-outside of strings or comments.  Font Lock uses this when necessary
-to get the right results for syntactic fontification.
+For example:
 
-This function is called with no arguments.  It should leave point at the
-beginning of any enclosing syntactic block.  Typical values are
-@code{beginning-of-line} (i.e., the start of the line is known to be
-outside a syntactic block), or @code{beginning-of-defun} for programming
-modes or @code{backward-paragraph} for textual modes (i.e., the
-mode-dependent function is known to move outside a syntactic block).
+@smallexample
+(font-lock-add-keywords 'c-mode
+ '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
+   ("\\<\\(and\\|or\\|not\\)\\>" . font-lock-keyword-face)))
+@end smallexample
 
-If the value is @code{nil}, the beginning of the buffer is used as a
-position outside of a syntactic block.  This cannot be wrong, but it can
-be slow.
-@end defvar
+adds two fontification patterns for C mode: one to fontify the word
+@samp{FIXME}, even in comments, and another to fontify the words
+@samp{and}, @samp{or} and @samp{not} as keywords.
+
+Some modes have specialized support for additional patterns.  See the
+variables @code{c-font-lock-extra-types},
+@code{c++-font-lock-extra-types}, @code{objc-font-lock-extra-types}
+and @code{java-font-lock-extra-types}, for example.
+@end defun
+
+@defun font-lock-remove-keywords mode keywords
+This function removes highlighting @var{keywords} for @var{mode}.  As
+in @code{font-lock-add-keywords}, @var{mode} should be a major mode
+command name or @code{nil}.  If @code{nil}, the highlighting
+@var{keywords} are immediately removed in the current buffer.
+@end defun
+
+@strong{Warning:} Only use a non-@code{nil} @var{mode} argument when
+you use @code{font-lock-add-keywords} or
+@code{font-lock-remove-keywords} in your @file{.emacs} file.  When you
+use these functions from a Lisp program (such as a minor mode), we
+recommend that you use @code{nil} for @var{mode} (and place the call
+on a hook) to avoid subtle problems due to the details of the
+implementation.
+
+@node Other Font Lock Variables
+@subsection Other Font Lock Variables
+
+  This section describes additional variables that a major mode can
+set by means of @var{other-vars} in @code{font-lock-defaults}
+(@pxref{Font Lock Basics}).
 
 @defvar font-lock-mark-block-function
 If this variable is non-@code{nil}, it should be a function that is
@@ -2378,25 +2691,38 @@ textual modes.
 @end defvar
 
 @defvar font-lock-extra-managed-props
-Additional properties (other than @code{font-lock-face}) that are
-being managed by Font Lock mode.  Font Lock mode normally manages only
-the @code{font-lock-face} property; if you want it to manage others as
-well, you must specify them in a @var{facespec} in
-@code{font-lock-keywords} as well as adding them to this list.
+This variable specifies additional properties (other than
+@code{font-lock-face}) that are being managed by Font Lock mode.  It
+is used by @code{font-lock-default-unfontify-region}, which normally
+only manages the @code{font-lock-face} property.  If you want Font
+Lock to manage other properties as well, you must specify them in a
+@var{facespec} in @code{font-lock-keywords} as well as add them to
+this list.  @xref{Search-based Fontification}.
 @end defvar
 
-@defvar font-lock-syntactic-face-function
-A function to determine which face to use for a given syntactic
-element (a string or a comment).  The function is called with one
-argument, the parse state at point returned by
-@code{parse-partial-sexp}, and should return a face.  The default
-value returns @code{font-lock-comment-face} for comments and
-@code{font-lock-string-face} for strings.
+@defvar font-lock-fontify-buffer-function
+Function to use for fontifying the buffer.  The default value is
+@code{font-lock-default-fontify-buffer}.
+@end defvar
 
-This can be used to highlighting different kinds of strings or
-comments differently.  It is also sometimes abused together with
-@code{font-lock-syntactic-keywords} to highlight elements that span
-multiple lines, but this is too obscure to document in this manual.
+@defvar font-lock-unfontify-buffer-function
+Function to use for unfontifying the buffer.  This is used when
+turning off Font Lock mode.  The default value is
+@code{font-lock-default-unfontify-buffer}.
+@end defvar
+
+@defvar font-lock-fontify-region-function
+Function to use for fontifying a region.  It should take two
+arguments, the beginning and end of the region, and an optional third
+argument @var{verbose}.  If @var{verbose} is non-@code{nil}, the
+function should print status messages.  The default value is
+@code{font-lock-default-fontify-region}.
+@end defvar
+
+@defvar font-lock-unfontify-region-function
+Function to use for unfontifying a region.  It should take two
+arguments, the beginning and end of the region.  The default value is
+@code{font-lock-default-unfontify-region}.
 @end defvar
 
 @defvar font-lock-lines-before
@@ -2407,6 +2733,14 @@ default is 1, but using a larger value can be useful for coping with
 multi-line patterns.
 @end defvar
 
+@ignore
+@defvar font-lock-inhibit-thing-lock
+List of Font Lock mode related modes that should not be turned on.
+Currently, valid mode names are @code{fast-lock-mode},
+@code{jit-lock-mode} and @code{lazy-lock-mode}.
+@end defvar
+@end ignore
+
 @node Levels of Font Lock
 @subsection Levels of Font Lock
 
@@ -2451,16 +2785,9 @@ which construct their text programmatically, such as
 @code{list-buffers} and @code{occur}.
 
 If your mode does not use any of the other machinery of Font Lock
-(i.e. it only uses the @code{font-lock-face} property), you can tell
-Emacs not to load all of font-lock.el (unless it's already loaded), by
-setting the variable @code{font-lock-core-only} to non-@code{nil} as
-part of the @code{font-lock-defaults} settings.  Here is the canonical
-way to do this:
-
-@example
-(set (make-local-variable 'font-lock-defaults)
-     '(nil t nil nil nil (font-lock-core-only . t)))
-@end example
+(i.e. it only uses the @code{font-lock-face} property), it should not
+set the variable @code{font-lock-defaults}.  That way, it will not
+cause loading of the @file{font-lock} library.
 
 @node Faces for Font Lock
 @subsection Faces for Font Lock
@@ -2478,6 +2805,10 @@ Thus, the default value of @code{font-lock-comment-face} is
 @vindex font-lock-comment-face
 Used (typically) for comments.
 
+@item font-lock-comment-delimiter-face
+@vindex font-lock-comment-delimiter-face
+Used (typically) for comments delimiters.
+
 @item font-lock-doc-face
 @vindex font-lock-doc-face
 Used (typically) for documentation strings in the code.
@@ -2529,14 +2860,78 @@ directives in C.
 @node Syntactic Font Lock
 @subsection Syntactic Font Lock
 
+Syntactic fontification uses the syntax table to find comments and
+string constants (@pxref{Syntax Tables}).  It highlights them using
+@code{font-lock-comment-face} and @code{font-lock-string-face}
+(@pxref{Faces for Font Lock}).  There are several variables that
+affect syntactic fontification; you should set them by means of
+@code{font-lock-defaults} (@pxref{Font Lock Basics}).
+
+@defvar font-lock-keywords-only
+Non-@code{nil} means Font Lock should not do syntactic fontification;
+it should only fontify based on @code{font-lock-keywords}.  The normal
+way for a mode to set this variable to @code{t} is with
+@var{keywords-only} in @code{font-lock-defaults}.
+@end defvar
+
+@defvar font-lock-syntax-table
+This variable holds the syntax table to use for fontification of
+comments and strings.  Specify it using @var{syntax-alist} in
+@code{font-lock-defaults}.
+@end defvar
+
+@c ???
+@c The docstring says that font-lock-syntax-table is semi-obsolete.
+@c How the alternative should be used is not clear.  --lute
+
+@defvar font-lock-beginning-of-syntax-function
+If this variable is non-@code{nil}, it should be a function to move
+point back to a position that is syntactically at ``top level'' and
+outside of strings or comments.  Font Lock uses this when necessary
+to get the right results for syntactic fontification.
+
+This function is called with no arguments.  It should leave point at
+the beginning of any enclosing syntactic block.  Typical values are
+@code{beginning-of-line} (used when the start of the line is known to
+be outside a syntactic block), or @code{beginning-of-defun} for
+programming modes, or @code{backward-paragraph} for textual modes.
+
+If the value is @code{nil}, the beginning of the buffer is used as a
+position outside of a syntactic block.  This cannot be wrong, but it
+can be slow.
+
+Specify this variable using @var{syntax-begin} in
+@code{font-lock-defaults}.
+@end defvar
+
+@defvar font-lock-syntactic-face-function
+A function to determine which face to use for a given syntactic
+element (a string or a comment).  The function is called with one
+argument, the parse state at point returned by
+@code{parse-partial-sexp}, and should return a face.  The default
+value returns @code{font-lock-comment-face} for comments and
+@code{font-lock-string-face} for strings.
+
+This can be used to highlighting different kinds of strings or
+comments differently.  It is also sometimes abused together with
+@code{font-lock-syntactic-keywords} to highlight elements that span
+multiple lines, but this is too obscure to document in this manual.
+
+Specify this variable using @var{other-vars} in
+@code{font-lock-defaults}.
+@end defvar
+
+@node Setting Syntax Properties
+@subsection Setting Syntax Properties
+
   Font Lock mode can be used to update @code{syntax-table} properties
-automatically.  This is useful in languages for which a single syntax
-table by itself is not sufficient.
+automatically (@pxref{Syntax Properties}).  This is useful in
+languages for which a single syntax table by itself is not sufficient.
 
 @defvar font-lock-syntactic-keywords
-This variable enables and controls syntactic Font Lock.  It is
-normally set via @code{font-lock-defaults}.  Its value should be a
-list of elements of this form:
+This variable enables and controls updating @code{syntax-table}
+properties by Font Lock.  Its value should be a list of elements of
+this form:
 
 @example
 (@var{matcher} @var{subexp} @var{syntax} @var{override} @var{laxmatch})
@@ -2546,10 +2941,10 @@ The parts of this element have the same meanings as in the corresponding
 sort of element of @code{font-lock-keywords},
 
 @example
-(@var{matcher} @var{subexp} @var{facename} @var{override} @var{laxmatch})
+(@var{matcher} @var{subexp} @var{facespec} @var{override} @var{laxmatch})
 @end example
 
-However, instead of specifying the value @var{facename} to use for the
+However, instead of specifying the value @var{facespec} to use for the
 @code{face} property, it specifies the value @var{syntax} to use for
 the @code{syntax-table} property.  Here, @var{syntax} can be a string
 (as taken by @code{modify-syntax-entry}), a syntax table, a cons cell
@@ -2586,6 +2981,8 @@ the form @samp{'@var{c}'} as strings syntactically.  Other forms, such
 as @samp{foo'bar} or @samp{'fubar'}, will not be highlighted as
 strings.
 
+Major modes normally set this variable with @var{other-vars} in
+@code{font-lock-defaults}.
 @end defvar
 
 @node Desktop Save Mode
@@ -2638,147 +3035,8 @@ argument list
 and it should return the restored buffer.
 Here @var{desktop-buffer-misc} is the value returned by the function
 optionally bound to @code{desktop-save-buffer}.
-
 @end defvar
 
-@node Hooks
-@section Hooks
-@cindex hooks
-
-  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 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
-  Most of the hooks in Emacs are @dfn{normal hooks}.  These variables
-contain lists of functions to be called with no arguments.  When the
-hook name ends in @samp{-hook}, that tells you it is normal.  We try to
-make all hooks normal, as much as possible, so that you can use them in
-a uniform way.
-
-  Every major mode function is supposed to run a normal hook called the
-@dfn{mode hook} as the last step of initialization.  This makes it easy
-for a user to customize the behavior of the mode, by overriding the
-buffer-local variable assignments already made by the mode.  But hooks
-are used in other contexts too.  For example, the hook
-@code{suspend-hook} runs just before Emacs suspends itself
-(@pxref{Suspending Emacs}).
-
-  The recommended way to add a hook function to a normal hook is by
-calling @code{add-hook} (see below).  The hook functions may be any of
-the valid kinds of functions that @code{funcall} accepts (@pxref{What
-Is a Function}).  Most normal hook variables are initially void;
-@code{add-hook} knows how to deal with this.  You can add hooks either
-globally or buffer-locally with @code{add-hook}.
-
-@cindex abnormal hook
-  If the hook variable's name does not end with @samp{-hook}, that
-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},
-then the value is a list of functions, but it is abnormal in that either
-these functions are called with arguments or their values are used in
-some way.  You can use @code{add-hook} to add a function to the list,
-but you must take care in writing the function.  (A few of these
-variables, notably those ending in @samp{-hooks}, are actually
-normal hooks which were named before we established the convention of
-using @samp{-hook} for them.)
-
-  If the variable's name ends in @samp{-function}, then its value
-is just a single function, not a list of functions.
-
-  Here's an example that uses a mode hook to turn on Auto Fill mode when
-in Lisp Interaction mode:
-
-@example
-(add-hook 'lisp-interaction-mode-hook 'turn-on-auto-fill)
-@end example
-
-  At the appropriate time, Emacs uses the @code{run-hooks} function to
-run particular hooks.  This function calls the hook functions that have
-been added with @code{add-hook}.
-
-@defun run-hooks &rest hookvars
-This function takes one or more normal hook variable names as
-arguments, and runs each hook in turn.  Each argument should be a
-symbol that is a normal 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.  (The former option is considered
-obsolete.)  If the value is a function (either a lambda expression or
-a symbol with a function definition), it is called.  If it is a list
-that isn't a function, its elements are called, consecutively.  All
-the hook functions are called with no arguments.
-@end defun
-
-@defun run-hook-with-args hook &rest args
-This function is the way to run an abnormal hook and always call all
-of the hook functions.  It calls each of the hook functions one by
-one, passing each of them the arguments @var{args}.
-@end defun
-
-@defun run-hook-with-args-until-failure hook &rest args
-This function is the way to run an abnormal hook until one of the hook
-functions fails.  It calls each of the hook functions, passing each of
-them the arguments @var{args}, until some hook function returns
-@code{nil}.  It then stops and returns @code{nil}.  If none of the
-hook functions return @code{nil}, it returns a non-@code{nil} value.
-@end defun
-
-@defun run-hook-with-args-until-success hook &rest args
-This function is the way to run an abnormal hook until a 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, and returns whatever was returned by
-the last hook function that was called.  If all hook functions return
-@code{nil}, it returns @code{nil} as well.
-@end defun
-
-@defun add-hook hook function &optional append local
-This function is the handy way to add function @var{function} to hook
-variable @var{hook}.  You can use it for abnormal hooks as well as for
-normal hooks.  @var{function} can be any Lisp function that can accept
-the proper number of arguments for @var{hook}.  For example,
-
-@example
-(add-hook 'text-mode-hook 'my-text-hook-function)
-@end example
-
-@noindent
-adds @code{my-text-hook-function} to the hook called @code{text-mode-hook}.
-
-If @var{function} is already present in @var{hook} (comparing using
-@code{equal}), then @code{add-hook} does not add it a second time.
-
-It is best to design your hook functions so that the order in which they
-are executed does not matter.  Any dependence on the order is ``asking
-for trouble''.  However, the order is predictable: normally,
-@var{function} goes at the front of the hook list, so it will be
-executed first (barring another @code{add-hook} call).  If the optional
-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 add @var{function} to
-the buffer-local hook list instead of to the global hook list.  If
-needed, this makes the hook buffer-local and adds @code{t} to the
-buffer-local value.  The latter acts as a flag to run the hook
-functions in the default value as well as in the local value.
-@end defun
-
-@defun remove-hook hook function &optional local
-This function removes @var{function} from the hook variable
-@var{hook}.  It compares @var{function} with elements of @var{hook}
-using @code{equal}, so it works for both symbols and lambda
-expressions.
-
-If @var{local} is non-@code{nil}, that says to remove @var{function}
-from the buffer-local hook list instead of from the global hook list.
-@end defun
-
 @ignore
    arch-tag: 4c7bff41-36e6-4da6-9e7f-9b9289e27c8e
 @end ignore