aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2006-04-24 06:35:58 +0000
committerStefan Monnier2006-04-24 06:35:58 +0000
commitb841df8f0b91138477e33bb74b6244a8cf97a26a (patch)
tree374fc02d856928c0f2ad197061cce398a6b082f7
parent1942c962e38eb733cac748d4a8b8eb19f9019566 (diff)
downloademacs-b841df8f0b91138477e33bb74b6244a8cf97a26a.tar.gz
emacs-b841df8f0b91138477e33bb74b6244a8cf97a26a.zip
Add documentation about font-lock-multiline.
-rw-r--r--lispref/modes.texi130
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.
2623Its value should have one of the forms described in this table. 2623Its 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}
2628to match text which spans lines; this does not work reliably. While 2627to match text which spans lines; this does not work reliably.
2629@code{font-lock-fontify-buffer} handles multi-line patterns correctly, 2628For details, see @xref{Multi line Font Lock Elements}.
2630updating when you edit the buffer does not, since it considers text one
2631line at a time. If you have patterns that typically only span one
2632line but can occasionally span two or three, such as
2633@samp{<title>...</title>}, you can ask Font Lock to be more careful by
2634setting @code{font-lock-multiline} to @code{t}. But it still will not
2635work in all cases.
2636 2629
2637You can use @var{case-fold} in @code{font-lock-defaults} to specify 2630You can use @var{case-fold} in @code{font-lock-defaults} to specify
2638the value of @code{font-lock-keywords-case-fold-search} which says 2631the 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
2725default the smallest sequence of whole lines that spans the change.
2726While this works well most of the time, sometimes it doesn't---for
2727example, when a buffer change has changed the syntactic meaning of text
2728on an earlier line.
2729
2730You can enlarge (or even reduce) the region to fontify by setting either
2731of the following variables:
2732
2733@defvar font-lock-extend-region-function
2734This buffer-local variable is either @code{nil} or is a function that
2735determines the region to fontify, which Emacs then calls after each
2736buffer change.
2737
2738The function is given three parameters, the standard @var{beg},
2739@var{end}, and @var{old-len} from after-change-functions (@pxref{Change
2740Hooks}). It should return either a cons of the beginning and end buffer
2741positions (in that order) of the region to fontify, or @code{nil} (which
2742directs the caller to fontify the default region). This function need
2743not preserve point or the match-data, but must preserve the current
2744restriction. The region it returns may start or end in the middle of a
2745line.
2746
2747Since this function is called after every buffer change, it should be
2748reasonably 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
3022Normally, Font Lock elements specified via @code{font-lock-keywords}
3023should not match across multiple lines. If they do, Font Lock may
3024fail to highlight them properly. This is fundamentally due to the
3025fact that Font Lock does not always look at the whole buffer at
3026a time, for obvious performance reasons, and instead only looks
3027at a small chunk at a time. In order for the highlight to be correct,
3028a chunk should not straddle an element matched by
3029@code{font-lock-keywords}. The default heuristic used for this is to
3030start and end chunks at the beginning resp. end of a line.
3031
3032To 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
3043In order to make it possible to properly highlight elements that span
3044multiple lines, Font Lock obeys a special text property
3045@code{font-lock-multiline} which if non-@code{nil} indicates that this
3046piece of text is part of a multiline construct. So when Font Lock is
3047asked to highlight a region, it first verifies the two boundaries and
3048extends them as needed so they do not fall in the middle of a piece of
3049text marked with the @code{font-lock-multiline} property.
3050Immediately after that, it also erases all @code{font-lock-multiline}
3051properties from the region it is about to highlight, so it is the
3052responsability of the highlighting specification (mostly
3053@code{font-lock-keywords}) to make sure that this property is re-added
3054where needed so as to inform the next round of Font Locking of the
3055presence of a multiline construct.
3056
3057It is important to understand that the @code{font-lock-multiline}
3058property should preferably only be used on Font Lock elements of
3059moderate size: every time that text is modified within the multiline
3060elements (or nearby), the whole multiline element will be completely
3061re-highlighted, so if its size is large, the time to font-lock may
3062render editing painfully slow.
3063
3064@defvar font-lock-multiline
3065If the @code{font-lock-multiline} variable is set to @code{t}, Font
3066Lock will try to automatically add the @code{font-lock-multiline}
3067property on the keywords that span several lines. This is no silver
3068bullet however since it slows down Font Lock somewhat, and still does
3069not always find all multiline constructs, especially when used with
3070Jit 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
3077default the smallest sequence of whole lines that spans the change.
3078While this works well most of the time, sometimes it doesn't---for
3079example, when a buffer change has changed the syntactic meaning of text
3080on an earlier line.
3081
3082You can enlarge (or even reduce) the region to fontify by setting either
3083of the following variables:
3084
3085@defvar font-lock-extend-region-function
3086This buffer-local variable is either @code{nil} or is a function that
3087determines the region to fontify, which Emacs then calls after each
3088buffer change.
3089
3090The function is given three parameters, the standard @var{beg},
3091@var{end}, and @var{old-len} from after-change-functions (@pxref{Change
3092Hooks}). It should return either a cons of the beginning and end buffer
3093positions (in that order) of the region to fontify, or @code{nil} (which
3094directs the caller to fontify the default region). This function need
3095not preserve point or the match-data, but must preserve the current
3096restriction. The region it returns may start or end in the middle of a
3097line.
3098
3099Since this function is called after every buffer change, it should be
3100reasonably 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