diff options
| author | Lute Kamstra | 2005-04-28 11:32:54 +0000 |
|---|---|---|
| committer | Lute Kamstra | 2005-04-28 11:32:54 +0000 |
| commit | 4f45f65edf4ddc7ecc703ec656d93b515a796598 (patch) | |
| tree | 2af3244ba5d4fcd4df44774b9a9206f85c2a9eab | |
| parent | d79b6c21bdfa03ede3b00c7c3d90789300bb1695 (diff) | |
| download | emacs-4f45f65edf4ddc7ecc703ec656d93b515a796598.tar.gz emacs-4f45f65edf4ddc7ecc703ec656d93b515a796598.zip | |
(Defining Minor Modes): Fix previous change.
(Font Lock Mode): Simplify.
(Font Lock Basics): Say that font-lock-defaults is buffer-local
when set and that some parts are optional. Add cross references.
(Search-based Fontification): Say how to specify font-lock-keywords.
Add cross references. Add font-lock-multiline to index. Move
font-lock-keywords-case-fold-search here from node "Other Font
Lock Variables". Document font-lock-add-keywords and
font-lock-remove-keywords
(Other Font Lock Variables): Move font-lock-keywords-only,
font-lock-syntax-table, font-lock-beginning-of-syntax-function,
and font-lock-syntactic-face-function to node "Syntactic Font
Lock". Move font-lock-keywords-case-fold-search to node
"Search-based Fontification". Document font-lock-inhibit-thing-lock
and font-lock-{,un}fontify-{buffer,region}-function.
(Precalculated Fontification): Remove reference to deleted variable
font-lock-core-only.
(Faces for Font Lock): Add font-lock-comment-delimiter-face.
(Syntactic Font Lock): Add intro. Move font-lock-keywords-only,
font-lock-syntax-table, font-lock-beginning-of-syntax-function,
and font-lock-syntactic-face-function here from node "Other Font
Lock Variables". Move font-lock-syntactic-keywords to "Setting
Syntax Properties". Add cross references.
(Setting Syntax Properties): New node. Move
font-lock-syntactic-keywords here from "Syntactic Font Lock".
| -rw-r--r-- | lispref/modes.texi | 318 |
1 files changed, 216 insertions, 102 deletions
diff --git a/lispref/modes.texi b/lispref/modes.texi index 4c7d1130267..e0494d4e7d9 100644 --- a/lispref/modes.texi +++ b/lispref/modes.texi | |||
| @@ -1134,9 +1134,10 @@ corresponding values. A few keywords have special meanings: | |||
| 1134 | @table @code | 1134 | @table @code |
| 1135 | @item :group @var{group} | 1135 | @item :group @var{group} |
| 1136 | Custom group name to use in all generated @code{defcustom} forms. | 1136 | Custom group name to use in all generated @code{defcustom} forms. |
| 1137 | Defaults to @var{mode} without the possible trailing @samp{-mode}. Be | 1137 | Defaults to @var{mode} without the possible trailing @samp{-mode}. |
| 1138 | aware that this default may not be a valid customization group defined | 1138 | @strong{Warning:} don't use this default group name unless you have |
| 1139 | with @code{defgroup}. Please make sure it is. | 1139 | written a @code{defgroup} to define that group properly. @xref{Group |
| 1140 | Definitions}. | ||
| 1140 | 1141 | ||
| 1141 | @item :global @var{global} | 1142 | @item :global @var{global} |
| 1142 | If non-@code{nil} specifies that the minor mode should be global. | 1143 | If non-@code{nil} specifies that the minor mode should be global. |
| @@ -2025,12 +2026,11 @@ most major modes define syntactic criteria for which faces to use in | |||
| 2025 | which contexts. This section explains how to customize Font Lock for a | 2026 | which contexts. This section explains how to customize Font Lock for a |
| 2026 | particular major mode. | 2027 | particular major mode. |
| 2027 | 2028 | ||
| 2028 | Font Lock mode finds text to highlight in two ways: through syntactic | 2029 | Font Lock mode finds text to highlight in two ways: through |
| 2029 | parsing based on the syntax table, and through searching (usually for | 2030 | syntactic parsing based on the syntax table, and through searching |
| 2030 | regular expressions). Syntactic fontification happens first; it finds | 2031 | (usually for regular expressions). Syntactic fontification happens |
| 2031 | comments and string constants, and highlights them using | 2032 | first; it finds comments and string constants and highlights them. |
| 2032 | @code{font-lock-comment-face} and @code{font-lock-string-face} | 2033 | Search-based fontification happens second. |
| 2033 | (@pxref{Faces for Font Lock}). Search-based fontification follows. | ||
| 2034 | 2034 | ||
| 2035 | @menu | 2035 | @menu |
| 2036 | * Font Lock Basics:: Overview of customizing Font Lock. | 2036 | * Font Lock Basics:: Overview of customizing Font Lock. |
| @@ -2041,7 +2041,8 @@ comments and string constants, and highlights them using | |||
| 2041 | * Precalculated Fontification:: How Lisp programs that produce the buffer | 2041 | * Precalculated Fontification:: How Lisp programs that produce the buffer |
| 2042 | contents can also specify how to fontify it. | 2042 | contents can also specify how to fontify it. |
| 2043 | * Faces for Font Lock:: Special faces specifically for Font Lock. | 2043 | * Faces for Font Lock:: Special faces specifically for Font Lock. |
| 2044 | * Syntactic Font Lock:: Defining character syntax based on context | 2044 | * Syntactic Font Lock:: Fontification based on syntax tables. |
| 2045 | * Setting Syntax Properties:: Defining character syntax based on context | ||
| 2045 | using the Font Lock mechanism. | 2046 | using the Font Lock mechanism. |
| 2046 | @end menu | 2047 | @end menu |
| 2047 | 2048 | ||
| @@ -2056,45 +2057,48 @@ Lock mode is enabled, to set all the other variables. | |||
| 2056 | 2057 | ||
| 2057 | @defvar font-lock-defaults | 2058 | @defvar font-lock-defaults |
| 2058 | This variable is set by major modes, as a buffer-local variable, to | 2059 | This variable is set by major modes, as a buffer-local variable, to |
| 2059 | specify how to fontify text in that mode. The value should look like | 2060 | specify how to fontify text in that mode. It automatically becomes |
| 2060 | this: | 2061 | buffer-local when you set it. The value should look like this: |
| 2061 | 2062 | ||
| 2062 | @example | 2063 | @example |
| 2063 | (@var{keywords} @var{keywords-only} @var{case-fold} | 2064 | (@var{keywords} [@var{keywords-only} [@var{case-fold} |
| 2064 | @var{syntax-alist} @var{syntax-begin} @var{other-vars}@dots{}) | 2065 | [@var{syntax-alist} [@var{syntax-begin} @var{other-vars}@dots{}]]]]) |
| 2065 | @end example | 2066 | @end example |
| 2066 | 2067 | ||
| 2067 | The first element, @var{keywords}, indirectly specifies the value of | 2068 | The first element, @var{keywords}, indirectly specifies the value of |
| 2068 | @code{font-lock-keywords}. It can be a symbol, a variable whose value | 2069 | @code{font-lock-keywords} which directs search-based fontification. |
| 2069 | is the list to use for @code{font-lock-keywords}. It can also be a list of | 2070 | It can be a symbol, a variable or a function whose value is the list |
| 2070 | several such symbols, one for each possible level of fontification. The | 2071 | to use for @code{font-lock-keywords}. It can also be a list of |
| 2071 | first symbol specifies how to do level 1 fontification, the second | 2072 | several such symbols, one for each possible level of fontification. |
| 2072 | symbol how to do level 2, and so on. | 2073 | The first symbol specifies how to do level 1 fontification, the second |
| 2074 | symbol how to do level 2, and so on. @xref{Levels of Font Lock}. | ||
| 2073 | 2075 | ||
| 2074 | The second element, @var{keywords-only}, specifies the value of the | 2076 | The second element, @var{keywords-only}, specifies the value of the |
| 2075 | variable @code{font-lock-keywords-only}. If this is non-@code{nil}, | 2077 | variable @code{font-lock-keywords-only}. If this is non-@code{nil}, |
| 2076 | syntactic fontification (of strings and comments) is not performed. | 2078 | syntactic fontification (of strings and comments) is not performed. |
| 2079 | @xref{Syntactic Font Lock}. | ||
| 2077 | 2080 | ||
| 2078 | The third element, @var{case-fold}, specifies the value of | 2081 | The third element, @var{case-fold}, specifies the value of |
| 2079 | @code{font-lock-keywords-case-fold-search}. If it is non-@code{nil}, Font Lock | 2082 | @code{font-lock-keywords-case-fold-search}. If it is non-@code{nil}, |
| 2080 | mode ignores case when searching as directed by | 2083 | Font Lock mode ignores case when searching as directed by |
| 2081 | @code{font-lock-keywords}. | 2084 | @code{font-lock-keywords}. |
| 2082 | 2085 | ||
| 2083 | If the fourth element, @var{syntax-alist}, is non-@code{nil}, it should be | 2086 | If the fourth element, @var{syntax-alist}, is non-@code{nil}, it |
| 2084 | a list of cons cells of the form @code{(@var{char-or-string} | 2087 | should be a list of cons cells of the form @code{(@var{char-or-string} |
| 2085 | . @var{string})}. These are used to set up a syntax table for | 2088 | . @var{string})}. These are used to set up a syntax table for |
| 2086 | fontification (@pxref{Syntax Table Functions}). The resulting syntax | 2089 | syntactic fontification (@pxref{Syntax Table Functions}). The |
| 2087 | table is stored in @code{font-lock-syntax-table}. | 2090 | resulting syntax table is stored in @code{font-lock-syntax-table}. |
| 2088 | 2091 | ||
| 2089 | The fifth element, @var{syntax-begin}, specifies the value of | 2092 | The fifth element, @var{syntax-begin}, specifies the value of |
| 2090 | @code{font-lock-beginning-of-syntax-function} (see below). | 2093 | @code{font-lock-beginning-of-syntax-function}. |
| 2091 | 2094 | ||
| 2092 | All the remaining elements (if any) are collectively called | 2095 | All the remaining elements (if any) are collectively called |
| 2093 | @var{other-vars}. Each of these elements should have the form | 2096 | @var{other-vars}. Each of these elements should have the form |
| 2094 | @code{(@var{variable} . @var{value})}---which means, make @var{variable} | 2097 | @code{(@var{variable} . @var{value})}---which means, make |
| 2095 | buffer-local and then set it to @var{value}. You can use these | 2098 | @var{variable} buffer-local and then set it to @var{value}. You can |
| 2096 | @var{other-vars} to set other variables that affect fontification, | 2099 | use these @var{other-vars} to set other variables that affect |
| 2097 | aside from those you can control with the first five elements. | 2100 | fontification, aside from those you can control with the first five |
| 2101 | elements. @xref{Other Font Lock Variables}. | ||
| 2098 | @end defvar | 2102 | @end defvar |
| 2099 | 2103 | ||
| 2100 | @node Search-based Fontification | 2104 | @node Search-based Fontification |
| @@ -2102,7 +2106,8 @@ aside from those you can control with the first five elements. | |||
| 2102 | 2106 | ||
| 2103 | The most important variable for customizing Font Lock mode is | 2107 | The most important variable for customizing Font Lock mode is |
| 2104 | @code{font-lock-keywords}. It specifies the search criteria for | 2108 | @code{font-lock-keywords}. It specifies the search criteria for |
| 2105 | search-based fontification. | 2109 | search-based fontification. You should specify the value of this |
| 2110 | variable with @var{keywords} in @code{font-lock-defaults}. | ||
| 2106 | 2111 | ||
| 2107 | @defvar font-lock-keywords | 2112 | @defvar font-lock-keywords |
| 2108 | This variable's value is a list of the keywords to highlight. Be | 2113 | This variable's value is a list of the keywords to highlight. Be |
| @@ -2192,7 +2197,8 @@ other text property names that you set in this way to the value of | |||
| 2192 | @code{font-lock-extra-managed-props} so that the properties will also | 2197 | @code{font-lock-extra-managed-props} so that the properties will also |
| 2193 | be cleared out when they are no longer appropriate. Alternatively, | 2198 | be cleared out when they are no longer appropriate. Alternatively, |
| 2194 | you can set the variable @code{font-lock-unfontify-region-function} to | 2199 | you can set the variable @code{font-lock-unfontify-region-function} to |
| 2195 | a function that clears these properties. | 2200 | a function that clears these properties. @xref{Other Font Lock |
| 2201 | Variables}. | ||
| 2196 | 2202 | ||
| 2197 | @item (@var{matcher} . @var{subexp-highlighter}) | 2203 | @item (@var{matcher} . @var{subexp-highlighter}) |
| 2198 | In this kind of element, @var{subexp-highlighter} is a list | 2204 | In this kind of element, @var{subexp-highlighter} is a list |
| @@ -2312,6 +2318,7 @@ this value of @code{font-lock-keywords} is used in a buffer. | |||
| 2312 | Its value should have one of the forms described in this table. | 2318 | Its value should have one of the forms described in this table. |
| 2313 | @end table | 2319 | @end table |
| 2314 | 2320 | ||
| 2321 | @vindex font-lock-multiline | ||
| 2315 | @strong{Warning:} Do not design an element of @code{font-lock-keywords} | 2322 | @strong{Warning:} Do not design an element of @code{font-lock-keywords} |
| 2316 | to match text which spans lines; this does not work reliably. While | 2323 | to match text which spans lines; this does not work reliably. While |
| 2317 | @code{font-lock-fontify-buffer} handles multi-line patterns correctly, | 2324 | @code{font-lock-fontify-buffer} handles multi-line patterns correctly, |
| @@ -2322,52 +2329,75 @@ line but can occasionally span two or three, such as | |||
| 2322 | setting @code{font-lock-multiline} to @code{t}. But it still will not | 2329 | setting @code{font-lock-multiline} to @code{t}. But it still will not |
| 2323 | work in all cases. | 2330 | work in all cases. |
| 2324 | 2331 | ||
| 2325 | @node Other Font Lock Variables | 2332 | You can use @var{case-fold} in @code{font-lock-defaults} to specify |
| 2326 | @subsection Other Font Lock Variables | 2333 | the value of @code{font-lock-keywords-case-fold-search} which says |
| 2327 | 2334 | whether search-based fontification should be case-insensitive. | |
| 2328 | This section describes additional variables that a major mode | ||
| 2329 | can set by means of @code{font-lock-defaults}. | ||
| 2330 | |||
| 2331 | @defvar font-lock-keywords-only | ||
| 2332 | Non-@code{nil} means Font Lock should not fontify comments or strings | ||
| 2333 | syntactically; it should only fontify based on | ||
| 2334 | @code{font-lock-keywords}. | ||
| 2335 | @end defvar | ||
| 2336 | |||
| 2337 | @ignore | ||
| 2338 | Other variables include those for buffer-specialized fontification functions, | ||
| 2339 | `font-lock-fontify-buffer-function', `font-lock-unfontify-buffer-function', | ||
| 2340 | `font-lock-fontify-region-function', `font-lock-unfontify-region-function', | ||
| 2341 | `font-lock-inhibit-thing-lock' and `font-lock-maximum-size'. | ||
| 2342 | @end ignore | ||
| 2343 | 2335 | ||
| 2344 | @defvar font-lock-keywords-case-fold-search | 2336 | @defvar font-lock-keywords-case-fold-search |
| 2345 | Non-@code{nil} means that regular expression matching for the sake of | 2337 | Non-@code{nil} means that regular expression matching for the sake of |
| 2346 | @code{font-lock-keywords} should be case-insensitive. | 2338 | @code{font-lock-keywords} should be case-insensitive. |
| 2347 | @end defvar | 2339 | @end defvar |
| 2348 | 2340 | ||
| 2349 | @defvar font-lock-syntax-table | 2341 | You can use @code{font-lock-add-keywords} to add additional |
| 2350 | This variable specifies the syntax table to use for fontification of | 2342 | search-based fontification rules to a major mode, and |
| 2351 | comments and strings. | 2343 | @code{font-lock-remove-keywords} to removes rules. |
| 2352 | @end defvar | 2344 | |
| 2345 | @defun font-lock-add-keywords mode keywords &optional append | ||
| 2346 | This function adds highlighting @var{keywords} for @var{mode}. The | ||
| 2347 | argument @var{keywords} should be a list with the same format as the | ||
| 2348 | variable @code{font-lock-keywords}. @var{mode} should be a symbol, | ||
| 2349 | the major mode command name, such as @code{c-mode}. When Font Lock | ||
| 2350 | mode is turned on in @var{mode}, it adds @var{keywords} to | ||
| 2351 | @code{font-lock-keywords}. @var{mode} can also be @code{nil}; the | ||
| 2352 | highlighting @var{keywords} are immediately added to | ||
| 2353 | @code{font-lock-keywords} in the current buffer in that case. | ||
| 2354 | |||
| 2355 | By default, @var{keywords} are added at the beginning of | ||
| 2356 | @code{font-lock-keywords}. If the optional argument @var{append} is | ||
| 2357 | @code{set}, they are used to replace the value of | ||
| 2358 | @code{font-lock-keywords}. If @var{append} is any other | ||
| 2359 | non-@code{nil} value, they are added at the end of | ||
| 2360 | @code{font-lock-keywords}. | ||
| 2353 | 2361 | ||
| 2354 | @defvar font-lock-beginning-of-syntax-function | 2362 | For example: |
| 2355 | If this variable is non-@code{nil}, it should be a function to move | ||
| 2356 | point back to a position that is syntactically at ``top level'' and | ||
| 2357 | outside of strings or comments. Font Lock uses this when necessary | ||
| 2358 | to get the right results for syntactic fontification. | ||
| 2359 | 2363 | ||
| 2360 | This function is called with no arguments. It should leave point at the | 2364 | @smallexample |
| 2361 | beginning of any enclosing syntactic block. Typical values are | 2365 | (font-lock-add-keywords 'c-mode |
| 2362 | @code{beginning-of-line} (i.e., the start of the line is known to be | 2366 | '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend) |
| 2363 | outside a syntactic block), or @code{beginning-of-defun} for programming | 2367 | ("\\<\\(and\\|or\\|not\\)\\>" . font-lock-keyword-face))) |
| 2364 | modes or @code{backward-paragraph} for textual modes (i.e., the | 2368 | @end smallexample |
| 2365 | mode-dependent function is known to move outside a syntactic block). | ||
| 2366 | 2369 | ||
| 2367 | If the value is @code{nil}, the beginning of the buffer is used as a | 2370 | adds two fontification patterns for C mode: one to fontify the word |
| 2368 | position outside of a syntactic block. This cannot be wrong, but it can | 2371 | @samp{FIXME}, even in comments, and another to fontify the words |
| 2369 | be slow. | 2372 | @samp{and}, @samp{or} and @samp{not} as keywords. |
| 2370 | @end defvar | 2373 | |
| 2374 | Some modes have specialized support for additional patterns. See the | ||
| 2375 | variables @code{c-font-lock-extra-types}, | ||
| 2376 | @code{c++-font-lock-extra-types}, @code{objc-font-lock-extra-types} | ||
| 2377 | and @code{java-font-lock-extra-types}, for example. | ||
| 2378 | @end defun | ||
| 2379 | |||
| 2380 | @defun font-lock-remove-keywords mode keywords | ||
| 2381 | This function removes highlighting @var{keywords} for @var{mode}. As | ||
| 2382 | in @code{font-lock-add-keywords}, @var{mode} should be a major mode | ||
| 2383 | command name or @code{nil}. If @code{nil}, the highlighting | ||
| 2384 | @var{keywords} are immediately removed in the current buffer. | ||
| 2385 | @end defun | ||
| 2386 | |||
| 2387 | @strong{Warning:} Only use a non-@code{nil} @var{mode} argument when | ||
| 2388 | you use @code{font-lock-add-keywords} or | ||
| 2389 | @code{font-lock-remove-keywords} in your @file{.emacs} file. When you | ||
| 2390 | use these functions from a Lisp program (such as a minor mode), we | ||
| 2391 | recommend that you use @code{nil} for @var{mode} (and place the call | ||
| 2392 | on a hook) to avoid subtle problems due to the details of the | ||
| 2393 | implementation. | ||
| 2394 | |||
| 2395 | @node Other Font Lock Variables | ||
| 2396 | @subsection Other Font Lock Variables | ||
| 2397 | |||
| 2398 | This section describes additional variables that a major mode can | ||
| 2399 | set by means of @var{other-vars} in @code{font-lock-defaults} | ||
| 2400 | (@pxref{Font Lock Basics}). | ||
| 2371 | 2401 | ||
| 2372 | @defvar font-lock-mark-block-function | 2402 | @defvar font-lock-mark-block-function |
| 2373 | If this variable is non-@code{nil}, it should be a function that is | 2403 | If this variable is non-@code{nil}, it should be a function that is |
| @@ -2383,25 +2413,38 @@ textual modes. | |||
| 2383 | @end defvar | 2413 | @end defvar |
| 2384 | 2414 | ||
| 2385 | @defvar font-lock-extra-managed-props | 2415 | @defvar font-lock-extra-managed-props |
| 2386 | Additional properties (other than @code{font-lock-face}) that are | 2416 | This variable specifies additional properties (other than |
| 2387 | being managed by Font Lock mode. Font Lock mode normally manages only | 2417 | @code{font-lock-face}) that are being managed by Font Lock mode. It |
| 2388 | the @code{font-lock-face} property; if you want it to manage others as | 2418 | is used by @code{font-lock-default-unfontify-region}, which normally |
| 2389 | well, you must specify them in a @var{facespec} in | 2419 | only manages the @code{font-lock-face} property. If you want Font |
| 2390 | @code{font-lock-keywords} as well as adding them to this list. | 2420 | Lock to manage other properties as well, you must specify them in a |
| 2421 | @var{facespec} in @code{font-lock-keywords} as well as add them to | ||
| 2422 | this list. @xref{Search-based Fontification}. | ||
| 2391 | @end defvar | 2423 | @end defvar |
| 2392 | 2424 | ||
| 2393 | @defvar font-lock-syntactic-face-function | 2425 | @defvar font-lock-fontify-buffer-function |
| 2394 | A function to determine which face to use for a given syntactic | 2426 | Function to use for fontifying the buffer. The default value is |
| 2395 | element (a string or a comment). The function is called with one | 2427 | @code{font-lock-default-fontify-buffer}. |
| 2396 | argument, the parse state at point returned by | 2428 | @end defvar |
| 2397 | @code{parse-partial-sexp}, and should return a face. The default | ||
| 2398 | value returns @code{font-lock-comment-face} for comments and | ||
| 2399 | @code{font-lock-string-face} for strings. | ||
| 2400 | 2429 | ||
| 2401 | This can be used to highlighting different kinds of strings or | 2430 | @defvar font-lock-unfontify-buffer-function |
| 2402 | comments differently. It is also sometimes abused together with | 2431 | Function to use for unfontifying the buffer. This is used when |
| 2403 | @code{font-lock-syntactic-keywords} to highlight elements that span | 2432 | turning off Font Lock mode. The default value is |
| 2404 | multiple lines, but this is too obscure to document in this manual. | 2433 | @code{font-lock-default-unfontify-buffer}. |
| 2434 | @end defvar | ||
| 2435 | |||
| 2436 | @defvar font-lock-fontify-region-function | ||
| 2437 | Function to use for fontifying a region. It should take two | ||
| 2438 | arguments, the beginning and end of the region, and an optional third | ||
| 2439 | argument @var{verbose}. If @var{verbose} is non-@code{nil}, the | ||
| 2440 | function should print status messages. The default value is | ||
| 2441 | @code{font-lock-default-fontify-region}. | ||
| 2442 | @end defvar | ||
| 2443 | |||
| 2444 | @defvar font-lock-unfontify-region-function | ||
| 2445 | Function to use for unfontifying a region. It should take two | ||
| 2446 | arguments, the beginning and end of the region. The default value is | ||
| 2447 | @code{font-lock-default-unfontify-region}. | ||
| 2405 | @end defvar | 2448 | @end defvar |
| 2406 | 2449 | ||
| 2407 | @defvar font-lock-lines-before | 2450 | @defvar font-lock-lines-before |
| @@ -2412,6 +2455,14 @@ default is 1, but using a larger value can be useful for coping with | |||
| 2412 | multi-line patterns. | 2455 | multi-line patterns. |
| 2413 | @end defvar | 2456 | @end defvar |
| 2414 | 2457 | ||
| 2458 | @ignore | ||
| 2459 | @defvar font-lock-inhibit-thing-lock | ||
| 2460 | List of Font Lock mode related modes that should not be turned on. | ||
| 2461 | Currently, valid mode names are @code{fast-lock-mode}, | ||
| 2462 | @code{jit-lock-mode} and @code{lazy-lock-mode}. | ||
| 2463 | @end defvar | ||
| 2464 | @end ignore | ||
| 2465 | |||
| 2415 | @node Levels of Font Lock | 2466 | @node Levels of Font Lock |
| 2416 | @subsection Levels of Font Lock | 2467 | @subsection Levels of Font Lock |
| 2417 | 2468 | ||
| @@ -2456,16 +2507,9 @@ which construct their text programmatically, such as | |||
| 2456 | @code{list-buffers} and @code{occur}. | 2507 | @code{list-buffers} and @code{occur}. |
| 2457 | 2508 | ||
| 2458 | If your mode does not use any of the other machinery of Font Lock | 2509 | If your mode does not use any of the other machinery of Font Lock |
| 2459 | (i.e. it only uses the @code{font-lock-face} property), you can tell | 2510 | (i.e. it only uses the @code{font-lock-face} property), it should not |
| 2460 | Emacs not to load all of font-lock.el (unless it's already loaded), by | 2511 | set the variable @code{font-lock-defaults}. That way, it will not |
| 2461 | setting the variable @code{font-lock-core-only} to non-@code{nil} as | 2512 | cause loading of the @file{font-lock} library. |
| 2462 | part of the @code{font-lock-defaults} settings. Here is the canonical | ||
| 2463 | way to do this: | ||
| 2464 | |||
| 2465 | @example | ||
| 2466 | (set (make-local-variable 'font-lock-defaults) | ||
| 2467 | '(nil t nil nil nil (font-lock-core-only . t))) | ||
| 2468 | @end example | ||
| 2469 | 2513 | ||
| 2470 | @node Faces for Font Lock | 2514 | @node Faces for Font Lock |
| 2471 | @subsection Faces for Font Lock | 2515 | @subsection Faces for Font Lock |
| @@ -2483,6 +2527,10 @@ Thus, the default value of @code{font-lock-comment-face} is | |||
| 2483 | @vindex font-lock-comment-face | 2527 | @vindex font-lock-comment-face |
| 2484 | Used (typically) for comments. | 2528 | Used (typically) for comments. |
| 2485 | 2529 | ||
| 2530 | @item font-lock-comment-delimiter-face | ||
| 2531 | @vindex font-lock-comment-delimiter-face | ||
| 2532 | Used (typically) for comments delimiters. | ||
| 2533 | |||
| 2486 | @item font-lock-doc-face | 2534 | @item font-lock-doc-face |
| 2487 | @vindex font-lock-doc-face | 2535 | @vindex font-lock-doc-face |
| 2488 | Used (typically) for documentation strings in the code. | 2536 | Used (typically) for documentation strings in the code. |
| @@ -2534,14 +2582,78 @@ directives in C. | |||
| 2534 | @node Syntactic Font Lock | 2582 | @node Syntactic Font Lock |
| 2535 | @subsection Syntactic Font Lock | 2583 | @subsection Syntactic Font Lock |
| 2536 | 2584 | ||
| 2585 | Syntactic fontification uses the syntax table to find comments and | ||
| 2586 | string constants (@pxref{Syntax Tables}). It highlights them using | ||
| 2587 | @code{font-lock-comment-face} and @code{font-lock-string-face} | ||
| 2588 | (@pxref{Faces for Font Lock}). There are several variables that | ||
| 2589 | affect syntactic fontification; you should set them by means of | ||
| 2590 | @code{font-lock-defaults} (@pxref{Font Lock Basics}). | ||
| 2591 | |||
| 2592 | @defvar font-lock-keywords-only | ||
| 2593 | Non-@code{nil} means Font Lock should not do syntactic fontification; | ||
| 2594 | it should only fontify based on @code{font-lock-keywords}. The normal | ||
| 2595 | way for a mode to set this variable to @code{t} is with | ||
| 2596 | @var{keywords-only} in @code{font-lock-defaults}. | ||
| 2597 | @end defvar | ||
| 2598 | |||
| 2599 | @defvar font-lock-syntax-table | ||
| 2600 | This variable holds the syntax table to use for fontification of | ||
| 2601 | comments and strings. Specify it using @var{syntax-alist} in | ||
| 2602 | @code{font-lock-defaults}. | ||
| 2603 | @end defvar | ||
| 2604 | |||
| 2605 | @c ??? | ||
| 2606 | @c The docstring says that font-lock-syntax-table is semi-obsolete. | ||
| 2607 | @c How the alternative should be used is not clear. --lute | ||
| 2608 | |||
| 2609 | @defvar font-lock-beginning-of-syntax-function | ||
| 2610 | If this variable is non-@code{nil}, it should be a function to move | ||
| 2611 | point back to a position that is syntactically at ``top level'' and | ||
| 2612 | outside of strings or comments. Font Lock uses this when necessary | ||
| 2613 | to get the right results for syntactic fontification. | ||
| 2614 | |||
| 2615 | This function is called with no arguments. It should leave point at | ||
| 2616 | the beginning of any enclosing syntactic block. Typical values are | ||
| 2617 | @code{beginning-of-line} (used when the start of the line is known to | ||
| 2618 | be outside a syntactic block), or @code{beginning-of-defun} for | ||
| 2619 | programming modes, or @code{backward-paragraph} for textual modes. | ||
| 2620 | |||
| 2621 | If the value is @code{nil}, the beginning of the buffer is used as a | ||
| 2622 | position outside of a syntactic block. This cannot be wrong, but it | ||
| 2623 | can be slow. | ||
| 2624 | |||
| 2625 | Specify this variable using @var{syntax-begin} in | ||
| 2626 | @code{font-lock-defaults}. | ||
| 2627 | @end defvar | ||
| 2628 | |||
| 2629 | @defvar font-lock-syntactic-face-function | ||
| 2630 | A function to determine which face to use for a given syntactic | ||
| 2631 | element (a string or a comment). The function is called with one | ||
| 2632 | argument, the parse state at point returned by | ||
| 2633 | @code{parse-partial-sexp}, and should return a face. The default | ||
| 2634 | value returns @code{font-lock-comment-face} for comments and | ||
| 2635 | @code{font-lock-string-face} for strings. | ||
| 2636 | |||
| 2637 | This can be used to highlighting different kinds of strings or | ||
| 2638 | comments differently. It is also sometimes abused together with | ||
| 2639 | @code{font-lock-syntactic-keywords} to highlight elements that span | ||
| 2640 | multiple lines, but this is too obscure to document in this manual. | ||
| 2641 | |||
| 2642 | Specify this variable using @var{other-vars} in | ||
| 2643 | @code{font-lock-defaults}. | ||
| 2644 | @end defvar | ||
| 2645 | |||
| 2646 | @node Setting Syntax Properties | ||
| 2647 | @subsection Setting Syntax Properties | ||
| 2648 | |||
| 2537 | Font Lock mode can be used to update @code{syntax-table} properties | 2649 | Font Lock mode can be used to update @code{syntax-table} properties |
| 2538 | automatically. This is useful in languages for which a single syntax | 2650 | automatically (@pxref{Syntax Properties}). This is useful in |
| 2539 | table by itself is not sufficient. | 2651 | languages for which a single syntax table by itself is not sufficient. |
| 2540 | 2652 | ||
| 2541 | @defvar font-lock-syntactic-keywords | 2653 | @defvar font-lock-syntactic-keywords |
| 2542 | This variable enables and controls syntactic Font Lock. It is | 2654 | This variable enables and controls updating @code{syntax-table} |
| 2543 | normally set via @code{font-lock-defaults}. Its value should be a | 2655 | properties by Font Lock. Its value should be a list of elements of |
| 2544 | list of elements of this form: | 2656 | this form: |
| 2545 | 2657 | ||
| 2546 | @example | 2658 | @example |
| 2547 | (@var{matcher} @var{subexp} @var{syntax} @var{override} @var{laxmatch}) | 2659 | (@var{matcher} @var{subexp} @var{syntax} @var{override} @var{laxmatch}) |
| @@ -2551,10 +2663,10 @@ The parts of this element have the same meanings as in the corresponding | |||
| 2551 | sort of element of @code{font-lock-keywords}, | 2663 | sort of element of @code{font-lock-keywords}, |
| 2552 | 2664 | ||
| 2553 | @example | 2665 | @example |
| 2554 | (@var{matcher} @var{subexp} @var{facename} @var{override} @var{laxmatch}) | 2666 | (@var{matcher} @var{subexp} @var{facespec} @var{override} @var{laxmatch}) |
| 2555 | @end example | 2667 | @end example |
| 2556 | 2668 | ||
| 2557 | However, instead of specifying the value @var{facename} to use for the | 2669 | However, instead of specifying the value @var{facespec} to use for the |
| 2558 | @code{face} property, it specifies the value @var{syntax} to use for | 2670 | @code{face} property, it specifies the value @var{syntax} to use for |
| 2559 | the @code{syntax-table} property. Here, @var{syntax} can be a string | 2671 | the @code{syntax-table} property. Here, @var{syntax} can be a string |
| 2560 | (as taken by @code{modify-syntax-entry}), a syntax table, a cons cell | 2672 | (as taken by @code{modify-syntax-entry}), a syntax table, a cons cell |
| @@ -2591,6 +2703,8 @@ the form @samp{'@var{c}'} as strings syntactically. Other forms, such | |||
| 2591 | as @samp{foo'bar} or @samp{'fubar'}, will not be highlighted as | 2703 | as @samp{foo'bar} or @samp{'fubar'}, will not be highlighted as |
| 2592 | strings. | 2704 | strings. |
| 2593 | 2705 | ||
| 2706 | Major modes normally set this variable with @var{other-vars} in | ||
| 2707 | @code{font-lock-defaults}. | ||
| 2594 | @end defvar | 2708 | @end defvar |
| 2595 | 2709 | ||
| 2596 | @node Desktop Save Mode | 2710 | @node Desktop Save Mode |