aboutsummaryrefslogtreecommitdiffstats
path: root/lispref/modes.texi
diff options
context:
space:
mode:
Diffstat (limited to 'lispref/modes.texi')
-rw-r--r--lispref/modes.texi96
1 files changed, 60 insertions, 36 deletions
diff --git a/lispref/modes.texi b/lispref/modes.texi
index f8c1ae82a4e..2366fca5b96 100644
--- a/lispref/modes.texi
+++ b/lispref/modes.texi
@@ -1650,13 +1650,13 @@ properties specified by @var{props} to the result. The argument
1650@var{value}. (This feature is new as of Emacs 22.1.) 1650@var{value}. (This feature is new as of Emacs 22.1.)
1651 1651
1652@item (@var{symbol} @var{then} @var{else}) 1652@item (@var{symbol} @var{then} @var{else})
1653A list whose first element is a symbol that is not a keyword specifies a 1653A list whose first element is a symbol that is not a keyword specifies
1654conditional. Its meaning depends on the value of @var{symbol}. If the 1654a conditional. Its meaning depends on the value of @var{symbol}. If
1655value is non-@code{nil}, the second element, @var{then}, is processed 1655@var{symbol} has a non-@code{nil} value, the second element,
1656recursively as a mode-line element. But if the value of @var{symbol} is 1656@var{then}, is processed recursively as a mode-line element.
1657@code{nil}, the third element, @var{else}, is processed recursively. 1657Otherwise, the third element, @var{else}, is processed recursively.
1658You may omit @var{else}; then the mode-line element displays nothing if 1658You may omit @var{else}; then the mode-line element displays nothing
1659the value of @var{symbol} is @code{nil}. 1659if the value of @var{symbol} is @code{nil} or void.
1660 1660
1661@item (@var{width} @var{rest}@dots{}) 1661@item (@var{width} @var{rest}@dots{})
1662A list whose first element is an integer specifies truncation or 1662A list whose first element is an integer specifies truncation or
@@ -2319,6 +2319,7 @@ Search-based fontification happens second.
2319@menu 2319@menu
2320* Font Lock Basics:: Overview of customizing Font Lock. 2320* Font Lock Basics:: Overview of customizing Font Lock.
2321* Search-based Fontification:: Fontification based on regexps. 2321* Search-based Fontification:: Fontification based on regexps.
2322* Customizing Keywords:: Customizing search-based fontification.
2322* Other Font Lock Variables:: Additional customization facilities. 2323* Other Font Lock Variables:: Additional customization facilities.
2323* Levels of Font Lock:: Each mode can define alternative levels 2324* Levels of Font Lock:: Each mode can define alternative levels
2324 so that the user can select more or less. 2325 so that the user can select more or less.
@@ -2624,19 +2625,27 @@ Non-@code{nil} means that regular expression matching for the sake of
2624@code{font-lock-keywords} should be case-insensitive. 2625@code{font-lock-keywords} should be case-insensitive.
2625@end defvar 2626@end defvar
2626 2627
2627You can use @code{font-lock-add-keywords} to add additional 2628@node Customizing Keywords
2629@subsection Customizing Search-Based Fontification
2630
2631 You can use @code{font-lock-add-keywords} to add additional
2628search-based fontification rules to a major mode, and 2632search-based fontification rules to a major mode, and
2629@code{font-lock-remove-keywords} to removes rules. 2633@code{font-lock-remove-keywords} to removes rules.
2630 2634
2631@defun font-lock-add-keywords mode keywords &optional append 2635@defun font-lock-add-keywords mode keywords &optional append
2632This function adds highlighting @var{keywords} for @var{mode}. The 2636This function adds highlighting @var{keywords}, for the current buffer
2633argument @var{keywords} should be a list with the same format as the 2637or for major mode @var{mode}. The argument @var{keywords} should be a
2634variable @code{font-lock-keywords}. @var{mode} should be a symbol, 2638list with the same format as the variable @code{font-lock-keywords}.
2635the major mode command name, such as @code{c-mode}. When Font Lock 2639
2636mode is turned on in @var{mode}, it adds @var{keywords} to 2640If @var{mode} is a symbol which is a major mode command name, such as
2637@code{font-lock-keywords}. @var{mode} can also be @code{nil}; the 2641@code{c-mode}, the effect is that enabling Font Lock mode in
2638highlighting @var{keywords} are immediately added to 2642@var{mode} will add @var{keywords} to @code{font-lock-keywords}.
2639@code{font-lock-keywords} in the current buffer in that case. 2643Calling with a non-@code{nil} value of @var{mode} is correct only in
2644your @file{~/.emacs} file.
2645
2646If @var{mode} is @code{nil}, this function adds @var{keywords} to
2647@code{font-lock-keywords} in the current buffer. This way of calling
2648@code{font-lock-add-keywords} is usually used in mode hook functions.
2640 2649
2641By default, @var{keywords} are added at the beginning of 2650By default, @var{keywords} are added at the beginning of
2642@code{font-lock-keywords}. If the optional argument @var{append} is 2651@code{font-lock-keywords}. If the optional argument @var{append} is
@@ -2645,7 +2654,29 @@ By default, @var{keywords} are added at the beginning of
2645non-@code{nil} value, they are added at the end of 2654non-@code{nil} value, they are added at the end of
2646@code{font-lock-keywords}. 2655@code{font-lock-keywords}.
2647 2656
2648For example: 2657Some modes provide specialized support you can use in additional
2658highlighting patterns. See the variables
2659@code{c-font-lock-extra-types}, @code{c++-font-lock-extra-types},
2660@code{objc-font-lock-extra-types} and
2661@code{java-font-lock-extra-types}, for example.
2662
2663@strong{Warning:} major mode functions must not call
2664@code{font-lock-add-keywords} under any circumstances, either directly
2665or indirectly, except through their mode hooks. (Doing so would lead
2666to incorrect behavior for some minor modes.) They should set up their
2667rules for search-based fontification by setting
2668@code{font-lock-keywords}.
2669@end defun
2670
2671@defun font-lock-remove-keywords mode keywords
2672This function removes @var{keywords} from @code{font-lock-keywords}
2673for the current buffer or for major mode @var{mode}. As in
2674@code{font-lock-add-keywords}, @var{mode} should be a major mode
2675command name or @code{nil}. All the caveats and requirments for
2676@code{font-lock-add-keywords} apply here too.
2677@end defun
2678
2679 For example, this code
2649 2680
2650@smallexample 2681@smallexample
2651(font-lock-add-keywords 'c-mode 2682(font-lock-add-keywords 'c-mode
@@ -2653,30 +2684,23 @@ For example:
2653 ("\\<\\(and\\|or\\|not\\)\\>" . font-lock-keyword-face))) 2684 ("\\<\\(and\\|or\\|not\\)\\>" . font-lock-keyword-face)))
2654@end smallexample 2685@end smallexample
2655 2686
2687@noindent
2656adds two fontification patterns for C mode: one to fontify the word 2688adds two fontification patterns for C mode: one to fontify the word
2657@samp{FIXME}, even in comments, and another to fontify the words 2689@samp{FIXME}, even in comments, and another to fontify the words
2658@samp{and}, @samp{or} and @samp{not} as keywords. 2690@samp{and}, @samp{or} and @samp{not} as keywords.
2659 2691
2660Some modes have specialized support for additional patterns. See the 2692@noindent
2661variables @code{c-font-lock-extra-types}, 2693That example affects only C mode proper. To add the same patterns to
2662@code{c++-font-lock-extra-types}, @code{objc-font-lock-extra-types} 2694C mode @emph{and} all modes derived from it, do this instead:
2663and @code{java-font-lock-extra-types}, for example.
2664@end defun
2665
2666@defun font-lock-remove-keywords mode keywords
2667This function removes highlighting @var{keywords} for @var{mode}. As
2668in @code{font-lock-add-keywords}, @var{mode} should be a major mode
2669command name or @code{nil}. If @code{nil}, the highlighting
2670@var{keywords} are immediately removed in the current buffer.
2671@end defun
2672 2695
2673@strong{Warning:} Only use a non-@code{nil} @var{mode} argument when 2696@smallexample
2674you use @code{font-lock-add-keywords} or 2697(add-hook 'c-mode-hook
2675@code{font-lock-remove-keywords} in your @file{.emacs} file. When you 2698 (lambda ()
2676use these functions from a Lisp program (such as a minor mode), we 2699 (font-lock-add-keywords nil
2677recommend that you use @code{nil} for @var{mode} (and place the call 2700 '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
2678on a hook) to avoid subtle problems due to the details of the 2701 ("\\<\\(and\\|or\\|not\\)\\>" .
2679implementation. 2702 font-lock-keyword-face)))))
2703@end smallexample
2680 2704
2681@node Other Font Lock Variables 2705@node Other Font Lock Variables
2682@subsection Other Font Lock Variables 2706@subsection Other Font Lock Variables