diff options
| author | Stefan Monnier | 2006-04-24 06:35:58 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2006-04-24 06:35:58 +0000 |
| commit | b841df8f0b91138477e33bb74b6244a8cf97a26a (patch) | |
| tree | 374fc02d856928c0f2ad197061cce398a6b082f7 | |
| parent | 1942c962e38eb733cac748d4a8b8eb19f9019566 (diff) | |
| download | emacs-b841df8f0b91138477e33bb74b6244a8cf97a26a.tar.gz emacs-b841df8f0b91138477e33bb74b6244a8cf97a26a.zip | |
Add documentation about font-lock-multiline.
| -rw-r--r-- | lispref/modes.texi | 130 |
1 files changed, 89 insertions, 41 deletions
diff --git a/lispref/modes.texi b/lispref/modes.texi index b33424a58be..12e419e8e37 100644 --- a/lispref/modes.texi +++ b/lispref/modes.texi | |||
| @@ -2336,8 +2336,6 @@ Search-based fontification happens second. | |||
| 2336 | * Font Lock Basics:: Overview of customizing Font Lock. | 2336 | * Font Lock Basics:: Overview of customizing Font Lock. |
| 2337 | * Search-based Fontification:: Fontification based on regexps. | 2337 | * Search-based Fontification:: Fontification based on regexps. |
| 2338 | * Customizing Keywords:: Customizing search-based fontification. | 2338 | * Customizing Keywords:: Customizing search-based fontification. |
| 2339 | * Region to Fontify:: Controlling which region gets refontified | ||
| 2340 | after a buffer change. | ||
| 2341 | * Other Font Lock Variables:: Additional customization facilities. | 2339 | * Other Font Lock Variables:: Additional customization facilities. |
| 2342 | * Levels of Font Lock:: Each mode can define alternative levels | 2340 | * Levels of Font Lock:: Each mode can define alternative levels |
| 2343 | so that the user can select more or less. | 2341 | so that the user can select more or less. |
| @@ -2347,6 +2345,8 @@ Search-based fontification happens second. | |||
| 2347 | * Syntactic Font Lock:: Fontification based on syntax tables. | 2345 | * Syntactic Font Lock:: Fontification based on syntax tables. |
| 2348 | * Setting Syntax Properties:: Defining character syntax based on context | 2346 | * Setting Syntax Properties:: Defining character syntax based on context |
| 2349 | using the Font Lock mechanism. | 2347 | using the Font Lock mechanism. |
| 2348 | * Multi line Font Lock Elements:: How to coerce Font Lock into properly | ||
| 2349 | highlighting multiline elements. | ||
| 2350 | @end menu | 2350 | @end menu |
| 2351 | 2351 | ||
| 2352 | @node Font Lock Basics | 2352 | @node Font Lock Basics |
| @@ -2623,16 +2623,9 @@ this value of @code{font-lock-keywords} is used in a buffer. | |||
| 2623 | Its value should have one of the forms described in this table. | 2623 | Its value should have one of the forms described in this table. |
| 2624 | @end table | 2624 | @end table |
| 2625 | 2625 | ||
| 2626 | @vindex font-lock-multiline | ||
| 2627 | @strong{Warning:} Do not design an element of @code{font-lock-keywords} | 2626 | @strong{Warning:} Do not design an element of @code{font-lock-keywords} |
| 2628 | to match text which spans lines; this does not work reliably. While | 2627 | to match text which spans lines; this does not work reliably. |
| 2629 | @code{font-lock-fontify-buffer} handles multi-line patterns correctly, | 2628 | For details, see @xref{Multi line Font Lock Elements}. |
| 2630 | updating when you edit the buffer does not, since it considers text one | ||
| 2631 | line at a time. If you have patterns that typically only span one | ||
| 2632 | line but can occasionally span two or three, such as | ||
| 2633 | @samp{<title>...</title>}, you can ask Font Lock to be more careful by | ||
| 2634 | setting @code{font-lock-multiline} to @code{t}. But it still will not | ||
| 2635 | work in all cases. | ||
| 2636 | 2629 | ||
| 2637 | You can use @var{case-fold} in @code{font-lock-defaults} to specify | 2630 | You can use @var{case-fold} in @code{font-lock-defaults} to specify |
| 2638 | the value of @code{font-lock-keywords-case-fold-search} which says | 2631 | the value of @code{font-lock-keywords-case-fold-search} which says |
| @@ -2718,36 +2711,6 @@ C mode @emph{and} all modes derived from it, do this instead: | |||
| 2718 | font-lock-keyword-face))))) | 2711 | font-lock-keyword-face))))) |
| 2719 | @end smallexample | 2712 | @end smallexample |
| 2720 | 2713 | ||
| 2721 | @node Region to Fontify | ||
| 2722 | @subsection Region to Fontify after a Buffer Change | ||
| 2723 | |||
| 2724 | When a buffer is changed, the region that Font Lock refontifies is by | ||
| 2725 | default the smallest sequence of whole lines that spans the change. | ||
| 2726 | While this works well most of the time, sometimes it doesn't---for | ||
| 2727 | example, when a buffer change has changed the syntactic meaning of text | ||
| 2728 | on an earlier line. | ||
| 2729 | |||
| 2730 | You can enlarge (or even reduce) the region to fontify by setting either | ||
| 2731 | of the following variables: | ||
| 2732 | |||
| 2733 | @defvar font-lock-extend-region-function | ||
| 2734 | This buffer-local variable is either @code{nil} or is a function that | ||
| 2735 | determines the region to fontify, which Emacs then calls after each | ||
| 2736 | buffer change. | ||
| 2737 | |||
| 2738 | The function is given three parameters, the standard @var{beg}, | ||
| 2739 | @var{end}, and @var{old-len} from after-change-functions (@pxref{Change | ||
| 2740 | Hooks}). It should return either a cons of the beginning and end buffer | ||
| 2741 | positions (in that order) of the region to fontify, or @code{nil} (which | ||
| 2742 | directs the caller to fontify the default region). This function need | ||
| 2743 | not preserve point or the match-data, but must preserve the current | ||
| 2744 | restriction. The region it returns may start or end in the middle of a | ||
| 2745 | line. | ||
| 2746 | |||
| 2747 | Since this function is called after every buffer change, it should be | ||
| 2748 | reasonably fast. | ||
| 2749 | @end defvar | ||
| 2750 | |||
| 2751 | @node Other Font Lock Variables | 2714 | @node Other Font Lock Variables |
| 2752 | @subsection Other Font Lock Variables | 2715 | @subsection Other Font Lock Variables |
| 2753 | 2716 | ||
| @@ -3052,6 +3015,91 @@ Major modes normally set this variable with @var{other-vars} in | |||
| 3052 | @code{font-lock-defaults}. | 3015 | @code{font-lock-defaults}. |
| 3053 | @end defvar | 3016 | @end defvar |
| 3054 | 3017 | ||
| 3018 | @node Multi line Font Lock Elements | ||
| 3019 | @subsection Multi line Font Lock Elements | ||
| 3020 | @cindex multi line font lock | ||
| 3021 | |||
| 3022 | Normally, Font Lock elements specified via @code{font-lock-keywords} | ||
| 3023 | should not match across multiple lines. If they do, Font Lock may | ||
| 3024 | fail to highlight them properly. This is fundamentally due to the | ||
| 3025 | fact that Font Lock does not always look at the whole buffer at | ||
| 3026 | a time, for obvious performance reasons, and instead only looks | ||
| 3027 | at a small chunk at a time. In order for the highlight to be correct, | ||
| 3028 | a chunk should not straddle an element matched by | ||
| 3029 | @code{font-lock-keywords}. The default heuristic used for this is to | ||
| 3030 | start and end chunks at the beginning resp. end of a line. | ||
| 3031 | |||
| 3032 | To work around this limitations, a few tools are provided. | ||
| 3033 | |||
| 3034 | @menu | ||
| 3035 | * Font Lock Multiline:: Marking multiline chunks with a text property | ||
| 3036 | * Region to Fontify:: Controlling which region gets refontified | ||
| 3037 | after a buffer change. | ||
| 3038 | @end menu | ||
| 3039 | |||
| 3040 | @node Font Lock Multiline | ||
| 3041 | @subsubsection Font Lock Multiline | ||
| 3042 | |||
| 3043 | In order to make it possible to properly highlight elements that span | ||
| 3044 | multiple lines, Font Lock obeys a special text property | ||
| 3045 | @code{font-lock-multiline} which if non-@code{nil} indicates that this | ||
| 3046 | piece of text is part of a multiline construct. So when Font Lock is | ||
| 3047 | asked to highlight a region, it first verifies the two boundaries and | ||
| 3048 | extends them as needed so they do not fall in the middle of a piece of | ||
| 3049 | text marked with the @code{font-lock-multiline} property. | ||
| 3050 | Immediately after that, it also erases all @code{font-lock-multiline} | ||
| 3051 | properties from the region it is about to highlight, so it is the | ||
| 3052 | responsability of the highlighting specification (mostly | ||
| 3053 | @code{font-lock-keywords}) to make sure that this property is re-added | ||
| 3054 | where needed so as to inform the next round of Font Locking of the | ||
| 3055 | presence of a multiline construct. | ||
| 3056 | |||
| 3057 | It is important to understand that the @code{font-lock-multiline} | ||
| 3058 | property should preferably only be used on Font Lock elements of | ||
| 3059 | moderate size: every time that text is modified within the multiline | ||
| 3060 | elements (or nearby), the whole multiline element will be completely | ||
| 3061 | re-highlighted, so if its size is large, the time to font-lock may | ||
| 3062 | render editing painfully slow. | ||
| 3063 | |||
| 3064 | @defvar font-lock-multiline | ||
| 3065 | If the @code{font-lock-multiline} variable is set to @code{t}, Font | ||
| 3066 | Lock will try to automatically add the @code{font-lock-multiline} | ||
| 3067 | property on the keywords that span several lines. This is no silver | ||
| 3068 | bullet however since it slows down Font Lock somewhat, and still does | ||
| 3069 | not always find all multiline constructs, especially when used with | ||
| 3070 | Jit Lock, which is enabled by default. | ||
| 3071 | @end defvar | ||
| 3072 | |||
| 3073 | @node Region to Fontify | ||
| 3074 | @subsubsection Region to Fontify after a Buffer Change | ||
| 3075 | |||
| 3076 | When a buffer is changed, the region that Font Lock refontifies is by | ||
| 3077 | default the smallest sequence of whole lines that spans the change. | ||
| 3078 | While this works well most of the time, sometimes it doesn't---for | ||
| 3079 | example, when a buffer change has changed the syntactic meaning of text | ||
| 3080 | on an earlier line. | ||
| 3081 | |||
| 3082 | You can enlarge (or even reduce) the region to fontify by setting either | ||
| 3083 | of the following variables: | ||
| 3084 | |||
| 3085 | @defvar font-lock-extend-region-function | ||
| 3086 | This buffer-local variable is either @code{nil} or is a function that | ||
| 3087 | determines the region to fontify, which Emacs then calls after each | ||
| 3088 | buffer change. | ||
| 3089 | |||
| 3090 | The function is given three parameters, the standard @var{beg}, | ||
| 3091 | @var{end}, and @var{old-len} from after-change-functions (@pxref{Change | ||
| 3092 | Hooks}). It should return either a cons of the beginning and end buffer | ||
| 3093 | positions (in that order) of the region to fontify, or @code{nil} (which | ||
| 3094 | directs the caller to fontify the default region). This function need | ||
| 3095 | not preserve point or the match-data, but must preserve the current | ||
| 3096 | restriction. The region it returns may start or end in the middle of a | ||
| 3097 | line. | ||
| 3098 | |||
| 3099 | Since this function is called after every buffer change, it should be | ||
| 3100 | reasonably fast. | ||
| 3101 | @end defvar | ||
| 3102 | |||
| 3055 | @node Desktop Save Mode | 3103 | @node Desktop Save Mode |
| 3056 | @section Desktop Save Mode | 3104 | @section Desktop Save Mode |
| 3057 | @cindex desktop save mode | 3105 | @cindex desktop save mode |