Merge from emacs-23; up to 2010-06-12T11:17:12Z!eliz@gnu.org.
[bpt/emacs.git] / doc / lispref / modes.texi
index 3f3eb2c..562cc76 100644 (file)
@@ -1,7 +1,6 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001,
-@c   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011  Free Software Foundation, Inc.
+@c Copyright (C) 1990-1995, 1998-1999, 2001-2011  Free Software Foundation, Inc.
 @c See the file elisp.texi for copying conditions.
 @setfilename ../../info/modes
 @node Modes, Documentation, Keymaps, Top
@@ -415,6 +414,31 @@ The mode should specify how to do highlighting for Font Lock mode, by
 setting up a buffer-local value for the variable
 @code{font-lock-defaults} (@pxref{Font Lock Mode}).
 
+@item
+Each face that the mode defines should, if possible, inherit from an
+existing Emacs face.  This reduces the chance of conflicting with a
+user's face customizations.  Useful faces include:
+
+@table @asis
+@item @code{highlight}
+for stretches of text that should temporarily stand out.
+
+@item @code{match}
+for text matching a search command.
+
+@item @code{link} and @code{link-visited}
+for clickable text buttons that send the user to a different buffer or
+``location''.
+
+@item @code{button}
+for clickable text buttons that perform other actions.
+
+@item @asis{Font Lock faces}
+for other kinds of syntactic highlighting, if highlighting is not
+handled by Font Lock mode or some Font Lock faces are not in use.
+@xref{Faces for Font Lock}, for how to assign Font Lock faces.
+@end table
+
 @item
 The mode should specify how Imenu should find the definitions or
 sections of a buffer, by setting up a buffer-local value for the
@@ -559,12 +583,9 @@ 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 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 the default value of @code{major-mode}
-(see below).
+The function calls @code{set-auto-mode} to choose a major mode.  If this
+does not specify a mode, the buffer stays in the major mode determined
+by the default value of @code{major-mode} (see below).
 
 @cindex file mode specification error
 @code{normal-mode} uses @code{condition-case} around the call to the
@@ -576,15 +597,15 @@ mode specification error},  followed by the original error message.
 @cindex visited file mode
   This function selects the major mode that is appropriate for the
 current buffer.  It bases its decision (in order of precedence) on
-the @w{@samp{-*-}} line, on the @w{@samp{#!}} line (using
+the @w{@samp{-*-}} line, on any @samp{mode:} local variable near the
+end of a file, 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.
+Major Modes are Chosen, emacs, The GNU Emacs Manual}. 
 If @code{enable-local-variables} is @code{nil}, @code{set-auto-mode}
-does not check the @w{@samp{-*-}} line for a mode tag either.
+does not check the @w{@samp{-*-}} line, or near the end of the file,
+for any mode tag.
 
 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
@@ -744,7 +765,8 @@ documentation of the major mode.
   The recommended way to define a new major mode is to derive it
 from an existing one using @code{define-derived-mode}.  If there is no
 closely related mode, you can inherit from @code{text-mode},
-@code{special-mode}, or in the worst case @code{fundamental-mode}.
+@code{special-mode}, @code{prog-mode}, or in the worst case
+@code{fundamental-mode}.
 
 @defmac define-derived-mode variant parent name docstring keyword-args@dots{} body@dots{}
 This macro defines @var{variant} as a major mode command, using
@@ -2882,73 +2904,79 @@ the normal Font Lock machinery, it should not set the variable
 @cindex faces for font lock
 @cindex font lock faces
 
-  You can make Font Lock mode use any face, but several faces are
-defined specifically for Font Lock mode.  Each of these symbols is both
-a face name, and a variable whose default value is the symbol itself.
-Thus, the default value of @code{font-lock-comment-face} is
-@code{font-lock-comment-face}.  This means you can write
-@code{font-lock-comment-face} in a context such as
-@code{font-lock-keywords} where a face-name-valued expression is used.
+  Font Lock mode can highlight using any face, but Emacs defines several
+faces specifically for syntactic highlighting.  These @dfn{Font Lock
+faces} are listed below.  They can also be used by major modes for
+syntactic highlighting outside of Font Lock mode (@pxref{Major Mode
+Conventions}).
 
-@table @code
-@item font-lock-comment-face
-@vindex font-lock-comment-face
-Used (typically) for comments.
+  Each of these symbols is both a face name, and a variable whose
+default value is the symbol itself.  Thus, the default value of
+@code{font-lock-comment-face} is @code{font-lock-comment-face}.
 
-@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.
-
-@item font-lock-string-face
-@vindex font-lock-string-face
-Used (typically) for string constants.
-
-@item font-lock-keyword-face
-@vindex font-lock-keyword-face
-Used (typically) for keywords---names that have special syntactic
-significance, like @code{for} and @code{if} in C.
+  The faces are listed with descriptions of their typical usage, and in
+order of greater to lesser ``prominence''.  If a mode's syntactic
+categories do not fit well with the usage descriptions, the faces can be
+assigned using the ordering as a guide.
 
-@item font-lock-builtin-face
-@vindex font-lock-builtin-face
-Used (typically) for built-in function names.
+@table @code
+@item font-lock-warning-face
+@vindex font-lock-warning-face
+for a construct that is peculiar, or that greatly changes the meaning of
+other text, like @samp{;;;###autoload} in Emacs Lisp and @samp{#error}
+in C.
 
 @item font-lock-function-name-face
 @vindex font-lock-function-name-face
-Used (typically) for the name of a function being defined or declared,
-in a function definition or declaration.
+for the name of a function being defined or declared.
 
 @item font-lock-variable-name-face
 @vindex font-lock-variable-name-face
-Used (typically) for the name of a variable being defined or declared,
-in a variable definition or declaration.
+for the name of a variable being defined or declared.
+
+@item font-lock-keyword-face
+@vindex font-lock-keyword-face
+for a keyword with special syntactic significance, like @samp{for} and
+@samp{if} in C.
+
+@item font-lock-comment-face
+@vindex font-lock-comment-face
+for comments.
+
+@item font-lock-comment-delimiter-face
+@vindex font-lock-comment-delimiter-face
+for comments delimiters, like @samp{/*} and @samp{*/} in C.  On most
+terminals, this inherits from @code{font-lock-comment-face}.
 
 @item font-lock-type-face
 @vindex font-lock-type-face
-Used (typically) for names of user-defined data types,
-where they are defined and where they are used.
+for the names of user-defined data types.
 
 @item font-lock-constant-face
 @vindex font-lock-constant-face
-Used (typically) for constant names.
+for the names of constants, like @samp{NULL} in C.
+
+@item font-lock-builtin-face
+@vindex font-lock-builtin-face
+for the names of built-in functions.
 
 @item font-lock-preprocessor-face
 @vindex font-lock-preprocessor-face
-Used (typically) for preprocessor commands.
+for preprocessor commands.  This inherits, by default, from
+@code{font-lock-builtin-face}.
+
+@item font-lock-string-face
+@vindex font-lock-string-face
+for string constants.
+
+@item font-lock-doc-face
+@vindex font-lock-doc-face
+for documentation strings in the code.  This inherits, by default, from
+@code{font-lock-string-face}.
 
 @item font-lock-negation-char-face
 @vindex font-lock-negation-char-face
-Used (typically) for easily-overlooked negation characters.
-
-@item font-lock-warning-face
-@vindex font-lock-warning-face
-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}
-directives in C.
+for easily-overlooked negation characters.
 @end table
 
 @node Syntactic Font Lock
@@ -3228,7 +3256,7 @@ reasonably fast.
 @end defvar
 
 @node Auto-Indentation
-@section Auto-indention of code
+@section Auto-indentation of code
 
 For programming languages, an important feature of a major mode is to
 provide automatic indentation.  This is controlled in Emacs by
@@ -3345,8 +3373,9 @@ transpose the two arguments of a @code{+} operator, taking into account
 the precedence rules of the language.
 
 Calling `smie-setup' is also sufficient to make TAB indentation work in
-the expected way, and provides some commands that you can bind in the
-major mode keymap.
+the expected way, extends @code{blink-matching-paren} to apply to
+elements like @code{begin...end}, and provides some commands that you
+can bind in the major mode keymap.
 
 @deffn Command smie-close-block
 This command closes the most recently opened (and not yet closed) block.
@@ -3374,7 +3403,7 @@ Such pairs of precedences are sufficient to express left-associativity
 or right-associativity of infix operators, nesting of tokens like
 parentheses and many other cases.
 
-@c ยกLet's leave this undocumented to leave it more open for change!
+@c Let's leave this undocumented to leave it more open for change!
 @c @defvar smie-grammar
 @c The value of this variable is an alist specifying the left and right
 @c precedence of each token.  It is meant to be initialized by using one of
@@ -3796,25 +3825,16 @@ block).
 Here is an example of an indentation function:
 
 @example
-;; For the `case' macro.
-(eval-when-compile (require 'cl))
-
 (defun sample-smie-rules (kind token)
-  (case kind
-    (:elem (case token
-             (basic sample-indent-basic)))
-    (:after
-     (cond
-      ((equal token ",") (smie-rule-separator kind))
-      ((equal token ":=") sample-indent-basic)))
-    (:before
-     (cond
-      ((equal token ",") (smie-rule-separator kind))
-      ((member token '("begin" "(" "@{"))
-       (if (smie-rule-hanging-p) (smie-rule-parent)))
-      ((equal token "if")
-       (and (not (smie-rule-bolp)) (smie-rule-prev-p "else")
-            (smie-rule-parent)))))))
+  (pcase (cons kind token)
+    (`(:elem . basic) sample-indent-basic)
+    (`(,_ . ",") (smie-rule-separator kind))
+    (`(:after . ":=") sample-indent-basic)
+    (`(:before . ,(or `"begin" `"(" `"@{")))
+     (if (smie-rule-hanging-p) (smie-rule-parent)))
+    (`(:before . "if")
+     (and (not (smie-rule-bolp)) (smie-rule-prev-p "else")
+          (smie-rule-parent)))))
 @end example
 
 @noindent
@@ -3829,10 +3849,10 @@ setting @code{smie-indent-basic}.  The major mode could have set
 is discouraged.
 
 @item
-The two (identical) rules for the token @code{","} make SMIE try to be
-more clever when the comma separator is placed at the beginning of
-lines.  It tries to outdent the separator so as to align the code after
-the comma; for example:
+The rule for the token @code{","} make SMIE try to be more clever when
+the comma separator is placed at the beginning of lines.  It tries to
+outdent the separator so as to align the code after the comma; for
+example:
 
 @example
 x = longfunctionname (