aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2012-02-16 14:04:38 +0800
committerChong Yidong2012-02-16 14:04:38 +0800
commitf700caa38bb4972bec481cca3af0778706b02498 (patch)
treec4dfc10309448fadf463178334b9b3f984b746a3
parent60236b0dca0416202da5c3e39564b85b2ae3c9fa (diff)
downloademacs-f700caa38bb4972bec481cca3af0778706b02498.tar.gz
emacs-f700caa38bb4972bec481cca3af0778706b02498.zip
Updates to Font Lock docs in Lisp manual.
* doc/lispref/modes.texi (Minor Modes): Update how mode commands should treat arguments now. (Mode Line Basics): Clarify force-mode-line-update. (Mode Line Top): Note that the example is not realistic. (Mode Line Variables, Mode Line Data, %-Constructs, Header Lines) (Emulating Mode Line): Use "mode line" instead of "mode-line", and "mode line construct" instead of "mode line specification". (Syntactic Font Lock): Remove mention of obsolete variable font-lock-syntactic-keywords. (Setting Syntax Properties): Node deleted. (Font Lock Mode): Note that Font Lock mode is a minor mode. (Font Lock Basics): Note that syntactic fontification falls back on `syntax-table'. (Search-based Fontification): Emphasize that font-lock-keywords should not be set directly. (Faces for Font Lock): Avoid some confusing terminology. (Syntactic Font Lock): Minor clarifications.
-rw-r--r--doc/lispref/ChangeLog24
-rw-r--r--doc/lispref/elisp.texi2
-rw-r--r--doc/lispref/modes.texi626
-rw-r--r--doc/lispref/syntax.texi4
-rw-r--r--doc/lispref/vol1.texi2
-rw-r--r--doc/lispref/vol2.texi2
6 files changed, 302 insertions, 358 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 1e369f3b627..fb58e04ac53 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,23 @@
12012-02-16 Chong Yidong <cyd@gnu.org>
2
3 * modes.texi (Minor Modes): Update how mode commands should treat
4 arguments now.
5 (Mode Line Basics): Clarify force-mode-line-update.
6 (Mode Line Top): Note that the example is not realistic.
7 (Mode Line Variables, Mode Line Data, %-Constructs, Header Lines)
8 (Emulating Mode Line): Use "mode line" instead of "mode-line", and
9 "mode line construct" instead of "mode line specification".
10 (Syntactic Font Lock): Remove mention of obsolete variable
11 font-lock-syntactic-keywords.
12 (Setting Syntax Properties): Node deleted.
13 (Font Lock Mode): Note that Font Lock mode is a minor mode.
14 (Font Lock Basics): Note that syntactic fontification falls back
15 on `syntax-table'.
16 (Search-based Fontification): Emphasize that font-lock-keywords
17 should not be set directly.
18 (Faces for Font Lock): Avoid some confusing terminology.
19 (Syntactic Font Lock): Minor clarifications.
20
12012-02-15 Chong Yidong <cyd@gnu.org> 212012-02-15 Chong Yidong <cyd@gnu.org>
2 22
3 * minibuf.texi (Basic Completion): Define "completion table". 23 * minibuf.texi (Basic Completion): Define "completion table".
@@ -9,6 +29,10 @@
9 (Setting Hooks): Update minor mode usage example. 29 (Setting Hooks): Update minor mode usage example.
10 (Major Mode Conventions): Note that completion-at-point-functions 30 (Major Mode Conventions): Note that completion-at-point-functions
11 should be altered locally. Add xref to Completion in Buffers. 31 should be altered locally. Add xref to Completion in Buffers.
32 Remove duplicate tip about auto-mode-alist.
33 (Minor Modes): Rewrite introduction.
34 (Minor Mode Conventions): Copyedits. Don't recommend
35 variable-only minor modes since few minor modes are like that.
12 36
132012-02-15 Glenn Morris <rgm@gnu.org> 372012-02-15 Glenn Morris <rgm@gnu.org>
14 38
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index 5dd8994f439..2719a024ac6 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -814,8 +814,6 @@ Font Lock Mode
814 contents can also specify how to fontify it. 814 contents can also specify how to fontify it.
815* Faces for Font Lock:: Special faces specifically for Font Lock. 815* Faces for Font Lock:: Special faces specifically for Font Lock.
816* Syntactic Font Lock:: Fontification based on syntax tables. 816* Syntactic Font Lock:: Fontification based on syntax tables.
817* Setting Syntax Properties:: Defining character syntax based on context
818 using the Font Lock mechanism.
819* Multiline Font Lock:: How to coerce Font Lock into properly 817* Multiline Font Lock:: How to coerce Font Lock into properly
820 highlighting multiline constructs. 818 highlighting multiline constructs.
821 819
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 94ae767586b..c3356ef882a 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -464,11 +464,6 @@ more buffer-local entries to the special hook
464@code{completion-at-point-functions}. @xref{Completion in Buffers}. 464@code{completion-at-point-functions}. @xref{Completion in Buffers}.
465 465
466@item 466@item
467Use @code{defvar} or @code{defcustom} to set mode-related variables, so
468that they are not reinitialized if they already have a value. (Such
469reinitialization could discard customizations made by the user.)
470
471@item
472@cindex buffer-local variables in modes 467@cindex buffer-local variables in modes
473To make a buffer-local binding for an Emacs customization variable, use 468To make a buffer-local binding for an Emacs customization variable, use
474@code{make-local-variable} in the major mode command, not 469@code{make-local-variable} in the major mode command, not
@@ -546,15 +541,13 @@ not autoload the mode command, it is sufficient to add the element in
546the file that contains the mode definition. 541the file that contains the mode definition.
547 542
548@item 543@item
549In the comments that document the file, you should provide a sample
550@code{autoload} form and an example of how to add to
551@code{auto-mode-alist}, that users can include in their init files
552(@pxref{Init File}).
553
554@item
555@cindex mode loading 544@cindex mode loading
556The top-level forms in the file defining the mode should be written so 545The top-level forms in the file defining the mode should be written so
557that they may be evaluated more than once without adverse consequences. 546that they may be evaluated more than once without adverse consequences.
547For instance, use @code{defvar} or @code{defcustom} to set mode-related
548variables, so that they are not reinitialized if they already have a
549value (@pxref{Defining Variables}).
550
558@end itemize 551@end itemize
559 552
560@node Auto Major Mode 553@node Auto Major Mode
@@ -1201,27 +1194,20 @@ if that value is non-nil."
1201@section Minor Modes 1194@section Minor Modes
1202@cindex minor mode 1195@cindex minor mode
1203 1196
1204 A @dfn{minor mode} provides features that users may enable or disable 1197 A @dfn{minor mode} provides optional features that users may enable or
1205independently of the choice of major mode. Minor modes can be enabled 1198disable independently of the choice of major mode. Minor modes can be
1206individually or in combination. Minor modes would be better named 1199enabled individually or in combination.
1207``generally available, optional feature modes,'' except that such a name
1208would be unwieldy.
1209
1210 A minor mode is not usually meant as a variation of a single major mode.
1211Usually they are general and can apply to many major modes. For
1212example, Auto Fill mode works with any major mode that permits text
1213insertion. To be general, a minor mode must be effectively independent
1214of the things major modes do.
1215 1200
1216 A minor mode is often much more difficult to implement than a major 1201 Most minor modes implement features that are independent of the major
1217mode. One reason is that you should be able to activate and deactivate 1202mode, and can thus be used with most major modes. For example, Auto
1218minor modes in any order. A minor mode should be able to have its 1203Fill mode works with any major mode that permits text insertion. A few
1219desired effect regardless of the major mode and regardless of the other 1204minor modes, however, are specific to a particular major mode. For
1220minor modes in effect. 1205example, Diff Auto Refine mode is a minor mode that is intended to be
1206used only with Diff mode.
1221 1207
1222 Often the biggest problem in implementing a minor mode is finding a 1208 Ideally, a minor mode should have its desired effect regardless of the
1223way to insert the necessary hook into the rest of Emacs. Minor mode 1209other minor modes in effect. It should be possible to activate and
1224keymaps make this easier than it used to be. 1210deactivate minor modes in any order.
1225 1211
1226@defvar minor-mode-list 1212@defvar minor-mode-list
1227The value of this variable is a list of all minor mode commands. 1213The value of this variable is a list of all minor mode commands.
@@ -1239,60 +1225,76 @@ The value of this variable is a list of all minor mode commands.
1239@cindex conventions for writing minor modes 1225@cindex conventions for writing minor modes
1240 1226
1241 There are conventions for writing minor modes just as there are for 1227 There are conventions for writing minor modes just as there are for
1242major modes. Several of the major mode conventions apply to minor 1228major modes. These conventions are described below. The easiest way to
1243modes as well: those regarding the name of the mode initialization 1229follow them is to use the macro @code{define-minor-mode}.
1244function, the names of global symbols, the use of a hook at the end of 1230@xref{Defining Minor Modes}.
1245the initialization function, and the use of keymaps and other tables.
1246
1247 In addition, there are several conventions that are specific to
1248minor modes. (The easiest way to follow all the conventions is to use
1249the macro @code{define-minor-mode}; @ref{Defining Minor Modes}.)
1250 1231
1251@itemize @bullet 1232@itemize @bullet
1252@item 1233@item
1253@cindex mode variable 1234@cindex mode variable
1254Make a variable whose name ends in @samp{-mode} to control the minor 1235Define a variable whose name ends in @samp{-mode}. We call this the
1255mode. We call this the @dfn{mode variable}. The minor mode command 1236@dfn{mode variable}. The minor mode command should set this variable.
1256should set this variable (@code{nil} to disable; anything else to 1237The value will be @code{nil} is the mode is disabled, and non-@code{nil}
1257enable). 1238if the mode is enabled. The variable should be buffer-local if the
1258 1239minor mode is buffer-local.
1259If possible, implement the mode so that setting the variable
1260automatically enables or disables the mode. Then the minor mode command
1261does not need to do anything except set the variable.
1262 1240
1263This variable is used in conjunction with the @code{minor-mode-alist} to 1241This variable is used in conjunction with the @code{minor-mode-alist} to
1264display the minor mode name in the mode line. It can also enable 1242display the minor mode name in the mode line. It also determines
1265or disable a minor mode keymap. Individual commands or hooks can also 1243whether the minor mode keymap is active, via @code{minor-mode-map-alist}
1266check the variable's value. 1244(@pxref{Controlling Active Maps}). Individual commands or hooks can
1267 1245also check its value.
1268If you want the minor mode to be enabled separately in each buffer,
1269make the variable buffer-local.
1270 1246
1271@item 1247@item
1272Define a command whose name is the same as the mode variable. 1248Define a command, called the @dfn{mode command}, whose name is the same
1273Its job is to enable and disable the mode by setting the variable. 1249as the mode variable. Its job is to set the value of the mode variable,
1250plus anything else that needs to be done to actually enable or disable
1251the mode's features.
1274 1252
1275The command should accept one optional argument. If the argument is 1253The mode command should accept one optional argument. If called
1276@code{nil}, it should toggle the mode (turn it on if it is off, and 1254interactively with no prefix argument, it should toggle the mode
1277off if it is on). It should turn the mode on if the argument is a 1255(i.e.@: enable if it is disabled, and disable if it is enabled). If
1278positive integer, the symbol @code{t}, or a list whose @sc{car} is one 1256called interactively with a prefix argument, it should enable the mode
1279of those. It should turn the mode off if the argument is a negative 1257if the argument is positive and disable it otherwise.
1280integer or zero, the symbol @code{-}, or a list whose @sc{car} is a
1281negative integer or zero. The meaning of other arguments is not
1282specified.
1283 1258
1284Here is an example taken from the definition of @code{transient-mark-mode}. 1259If the mode command is called from Lisp (i.e.@: non-interactively), it
1285It shows the use of @code{transient-mark-mode} as a variable that enables or 1260should enable the mode if the argument is omitted or @code{nil}; it
1286disables the mode's behavior, and also shows the proper way to toggle, 1261should toggle the mode if the argument is the symbol @code{toggle};
1287enable or disable the minor mode based on the raw prefix argument value. 1262otherwise it should treat the argument in the same way as for an
1263interactive call with a numeric prefix argument, as described above.
1288 1264
1289@smallexample 1265The following example shows how to implement this behavior (it is
1290@group 1266similar to the code generated by the @code{define-minor-mode} macro):
1291(setq transient-mark-mode 1267
1292 (if (null arg) (not transient-mark-mode) 1268@example
1293 (> (prefix-numeric-value arg) 0))) 1269(interactive (list (or current-prefix-arg 'toggle)))
1294@end group 1270(let ((enable (if (eq arg 'toggle)
1295@end smallexample 1271 (not foo-mode) ; @r{this mode's mode variable}
1272 (> (prefix-numeric-value arg) 0))))
1273 (if enable
1274 @var{do-enable}
1275 @var{do-disable}))
1276@end example
1277
1278The reason for this somewhat complex behavior is that it lets users
1279easily toggle the minor mode interactively, and also lets the minor mode
1280be easily enabled in a mode hook, like this:
1281
1282@example
1283(add-hook 'text-mode-hook 'foo-mode)
1284@end example
1285
1286@noindent
1287This behaves correctly whether or not @code{foo-mode} was already
1288enabled, since the @code{foo-mode} mode command unconditionally enables
1289the minor mode when it is called from Lisp with no argument. Disabling
1290a minor mode in a mode hook is a little uglier:
1291
1292@example
1293(add-hook 'text-mode-hook (lambda () (foo-mode -1)))
1294@end example
1295
1296@noindent
1297However, this is not very commonly done.
1296 1298
1297@item 1299@item
1298Add an element to @code{minor-mode-alist} for each minor mode 1300Add an element to @code{minor-mode-alist} for each minor mode
@@ -1315,8 +1317,7 @@ check for an existing element, to avoid duplication. For example:
1315@smallexample 1317@smallexample
1316@group 1318@group
1317(unless (assq 'leif-mode minor-mode-alist) 1319(unless (assq 'leif-mode minor-mode-alist)
1318 (setq minor-mode-alist 1320 (push '(leif-mode " Leif") minor-mode-alist))
1319 (cons '(leif-mode " Leif") minor-mode-alist)))
1320@end group 1321@end group
1321@end smallexample 1322@end smallexample
1322 1323
@@ -1330,25 +1331,24 @@ or like this, using @code{add-to-list} (@pxref{List Variables}):
1330@end smallexample 1331@end smallexample
1331@end itemize 1332@end itemize
1332 1333
1333 Global minor modes distributed with Emacs should if possible support 1334 In addition, several major mode conventions apply to minor modes as
1334enabling and disabling via Custom (@pxref{Customization}). To do this, 1335well: those regarding the names of global symbols, the use of a hook at
1335the first step is to define the mode variable with @code{defcustom}, and 1336the end of the initialization function, and the use of keymaps and other
1336specify @code{:type 'boolean}. 1337tables.
1337 1338
1338 If just setting the variable is not sufficient to enable the mode, you 1339 The minor mode should, if possible, support enabling and disabling via
1340Custom (@pxref{Customization}). To do this, the mode variable should be
1341defined with @code{defcustom}, usually with @code{:type 'boolean}. If
1342just setting the variable is not sufficient to enable the mode, you
1339should also specify a @code{:set} method which enables the mode by 1343should also specify a @code{:set} method which enables the mode by
1340invoking the mode command. Note in the variable's documentation string that 1344invoking the mode command. Note in the variable's documentation string
1341setting the variable other than via Custom may not take effect. 1345that setting the variable other than via Custom may not take effect.
1342 1346Also, mark the definition with an autoload cookie (@pxref{autoload
1343 Also mark the definition with an autoload cookie (@pxref{autoload cookie}), 1347cookie}), and specify a @code{:require} so that customizing the variable
1344and specify a @code{:require} so that customizing the variable will load 1348will load the library that defines the mode. For example:
1345the library that defines the mode. This will copy suitable definitions
1346into @file{loaddefs.el} so that users can use @code{customize-option} to
1347enable the mode. For example:
1348 1349
1349@smallexample 1350@smallexample
1350@group 1351@group
1351
1352;;;###autoload 1352;;;###autoload
1353(defcustom msb-mode nil 1353(defcustom msb-mode nil
1354 "Toggle msb-mode. 1354 "Toggle msb-mode.
@@ -1578,7 +1578,7 @@ mode's hook.
1578 1578
1579 1579
1580@node Mode Line Format 1580@node Mode Line Format
1581@section Mode-Line Format 1581@section Mode Line Format
1582@cindex mode line 1582@cindex mode line
1583 1583
1584 Each Emacs window (aside from minibuffer windows) typically has a mode 1584 Each Emacs window (aside from minibuffer windows) typically has a mode
@@ -1608,61 +1608,59 @@ minor modes.
1608@node Mode Line Basics 1608@node Mode Line Basics
1609@subsection Mode Line Basics 1609@subsection Mode Line Basics
1610 1610
1611 @code{mode-line-format} is a buffer-local variable that holds a 1611 The contents of each mode line are specified by the buffer-local
1612@dfn{mode line construct}, a kind of template, which controls what is 1612variable @code{mode-line-format} (@pxref{Mode Line Top}). This variable
1613displayed on the mode line of the current buffer. The value of 1613holds a @dfn{mode line construct}: a template that controls what is
1614@code{header-line-format} specifies the buffer's header line in the 1614displayed on the buffer's mode line. The value of
1615same way. All windows for the same buffer use the same 1615@code{header-line-format} specifies the buffer's header line in the same
1616way. All windows for the same buffer use the same
1616@code{mode-line-format} and @code{header-line-format}. 1617@code{mode-line-format} and @code{header-line-format}.
1617 1618
1618 For efficiency, Emacs does not continuously recompute the mode 1619 For efficiency, Emacs does not continuously recompute each window's
1619line and header line of a window. It does so when circumstances 1620mode line and header line. It does so when circumstances appear to call
1620appear to call for it---for instance, if you change the window 1621for it---for instance, if you change the window configuration, switch
1621configuration, switch buffers, narrow or widen the buffer, scroll, or 1622buffers, narrow or widen the buffer, scroll, or modify the buffer. If
1622change the buffer's modification status. If you modify any of the 1623you alter any of the variables referenced by @code{mode-line-format} or
1623variables referenced by @code{mode-line-format} (@pxref{Mode Line 1624@code{header-line-format} (@pxref{Mode Line Variables}), or any other
1624Variables}), or any other variables and data structures that affect 1625data structures that affect how text is displayed (@pxref{Display}), you
1625how text is displayed (@pxref{Display}), you may want to force an 1626should use the function @code{force-mode-line-update} to update the
1626update of the mode line so as to display the new information or 1627display.
1627display it in the new way.
1628 1628
1629@defun force-mode-line-update &optional all 1629@defun force-mode-line-update &optional all
1630Force redisplay of the current buffer's mode line and header line. 1630This function forces Emacs to update the current buffer's mode line and
1631The next redisplay will update the mode line and header line based on 1631header line, based on the latest values of all relevant variables,
1632the latest values of all relevant variables. With optional 1632during its next redisplay cycle. If the optional argument @var{all} is
1633non-@code{nil} @var{all}, force redisplay of all mode lines and header 1633non-@code{nil}, it forces an update for all mode lines and header lines.
1634lines. 1634
1635 1635This function also forces an update of the menu bar and frame title.
1636This function also forces recomputation of the menu bar menus
1637and the frame title.
1638@end defun 1636@end defun
1639 1637
1640 The selected window's mode line is usually displayed in a different 1638 The selected window's mode line is usually displayed in a different
1641color using the face @code{mode-line}. Other windows' mode lines 1639color using the face @code{mode-line}. Other windows' mode lines appear
1642appear in the face @code{mode-line-inactive} instead. @xref{Faces}. 1640in the face @code{mode-line-inactive} instead. @xref{Faces}.
1643 1641
1644@node Mode Line Data 1642@node Mode Line Data
1645@subsection The Data Structure of the Mode Line 1643@subsection The Data Structure of the Mode Line
1646@cindex mode-line construct 1644@cindex mode line construct
1647 1645
1648 The mode-line contents are controlled by a data structure called a 1646 The mode line contents are controlled by a data structure called a
1649@dfn{mode-line construct}, made up of lists, strings, symbols, and 1647@dfn{mode line construct}, made up of lists, strings, symbols, and
1650numbers kept in buffer-local variables. Each data type has a specific 1648numbers kept in buffer-local variables. Each data type has a specific
1651meaning for the mode-line appearance, as described below. The same 1649meaning for the mode line appearance, as described below. The same data
1652data structure is used for constructing frame titles (@pxref{Frame 1650structure is used for constructing frame titles (@pxref{Frame Titles})
1653Titles}) and header lines (@pxref{Header Lines}). 1651and header lines (@pxref{Header Lines}).
1654 1652
1655 A mode-line construct may be as simple as a fixed string of text, 1653 A mode line construct may be as simple as a fixed string of text,
1656but it usually specifies how to combine fixed strings with variables' 1654but it usually specifies how to combine fixed strings with variables'
1657values to construct the text. Many of these variables are themselves 1655values to construct the text. Many of these variables are themselves
1658defined to have mode-line constructs as their values. 1656defined to have mode line constructs as their values.
1659 1657
1660 Here are the meanings of various data types as mode-line constructs: 1658 Here are the meanings of various data types as mode line constructs:
1661 1659
1662@table @code 1660@table @code
1663@cindex percent symbol in mode line 1661@cindex percent symbol in mode line
1664@item @var{string} 1662@item @var{string}
1665A string as a mode-line construct appears verbatim except for 1663A string as a mode line construct appears verbatim except for
1666@dfn{@code{%}-constructs} in it. These stand for substitution of 1664@dfn{@code{%}-constructs} in it. These stand for substitution of
1667other data; see @ref{%-Constructs}. 1665other data; see @ref{%-Constructs}.
1668 1666
@@ -1675,8 +1673,8 @@ default, in the face @code{mode-line} or @code{mode-line-inactive}
1675special meanings. @xref{Properties in Mode}. 1673special meanings. @xref{Properties in Mode}.
1676 1674
1677@item @var{symbol} 1675@item @var{symbol}
1678A symbol as a mode-line construct stands for its value. The value of 1676A symbol as a mode line construct stands for its value. The value of
1679@var{symbol} is used as a mode-line construct, in place of @var{symbol}. 1677@var{symbol} is used as a mode line construct, in place of @var{symbol}.
1680However, the symbols @code{t} and @code{nil} are ignored, as is any 1678However, the symbols @code{t} and @code{nil} are ignored, as is any
1681symbol whose value is void. 1679symbol whose value is void.
1682 1680
@@ -1685,17 +1683,17 @@ displayed verbatim: the @code{%}-constructs are not recognized.
1685 1683
1686Unless @var{symbol} is marked as ``risky'' (i.e., it has a 1684Unless @var{symbol} is marked as ``risky'' (i.e., it has a
1687non-@code{nil} @code{risky-local-variable} property), all text 1685non-@code{nil} @code{risky-local-variable} property), all text
1688properties specified in @var{symbol}'s value are ignored. This 1686properties specified in @var{symbol}'s value are ignored. This includes
1689includes the text properties of strings in @var{symbol}'s value, as 1687the text properties of strings in @var{symbol}'s value, as well as all
1690well as all @code{:eval} and @code{:propertize} forms in it. (The 1688@code{:eval} and @code{:propertize} forms in it. (The reason for this
1691reason for this is security: non-risky variables could be set 1689is security: non-risky variables could be set automatically from file
1692automatically from file variables without prompting the user.) 1690variables without prompting the user.)
1693 1691
1694@item (@var{string} @var{rest}@dots{}) 1692@item (@var{string} @var{rest}@dots{})
1695@itemx (@var{list} @var{rest}@dots{}) 1693@itemx (@var{list} @var{rest}@dots{})
1696A list whose first element is a string or list means to process all the 1694A list whose first element is a string or list means to process all the
1697elements recursively and concatenate the results. This is the most 1695elements recursively and concatenate the results. This is the most
1698common form of mode-line construct. 1696common form of mode line construct.
1699 1697
1700@item (:eval @var{form}) 1698@item (:eval @var{form})
1701A list whose first element is the symbol @code{:eval} says to evaluate 1699A list whose first element is the symbol @code{:eval} says to evaluate
@@ -1705,24 +1703,24 @@ recursion.
1705 1703
1706@item (:propertize @var{elt} @var{props}@dots{}) 1704@item (:propertize @var{elt} @var{props}@dots{})
1707A list whose first element is the symbol @code{:propertize} says to 1705A list whose first element is the symbol @code{:propertize} says to
1708process the mode-line construct @var{elt} recursively, then add the text 1706process the mode line construct @var{elt} recursively, then add the text
1709properties specified by @var{props} to the result. The argument 1707properties specified by @var{props} to the result. The argument
1710@var{props} should consist of zero or more pairs @var{text-property} 1708@var{props} should consist of zero or more pairs @var{text-property}
1711@var{value}. (This feature is new as of Emacs 22.1.) 1709@var{value}.
1712 1710
1713@item (@var{symbol} @var{then} @var{else}) 1711@item (@var{symbol} @var{then} @var{else})
1714A list whose first element is a symbol that is not a keyword specifies 1712A list whose first element is a symbol that is not a keyword specifies
1715a conditional. Its meaning depends on the value of @var{symbol}. If 1713a conditional. Its meaning depends on the value of @var{symbol}. If
1716@var{symbol} has a non-@code{nil} value, the second element, 1714@var{symbol} has a non-@code{nil} value, the second element,
1717@var{then}, is processed recursively as a mode-line element. 1715@var{then}, is processed recursively as a mode line element.
1718Otherwise, the third element, @var{else}, is processed recursively. 1716Otherwise, the third element, @var{else}, is processed recursively.
1719You may omit @var{else}; then the mode-line element displays nothing 1717You may omit @var{else}; then the mode line element displays nothing
1720if the value of @var{symbol} is @code{nil} or void. 1718if the value of @var{symbol} is @code{nil} or void.
1721 1719
1722@item (@var{width} @var{rest}@dots{}) 1720@item (@var{width} @var{rest}@dots{})
1723A list whose first element is an integer specifies truncation or 1721A list whose first element is an integer specifies truncation or
1724padding of the results of @var{rest}. The remaining elements 1722padding of the results of @var{rest}. The remaining elements
1725@var{rest} are processed recursively as mode-line constructs and 1723@var{rest} are processed recursively as mode line constructs and
1726concatenated together. When @var{width} is positive, the result is 1724concatenated together. When @var{width} is positive, the result is
1727space filled on the right if its width is less than @var{width}. When 1725space filled on the right if its width is less than @var{width}. When
1728@var{width} is negative, the result is truncated on the right to 1726@var{width} is negative, the result is truncated on the right to
@@ -1739,12 +1737,12 @@ the top of the window is to use a list like this: @code{(-3 "%p")}.
1739@code{mode-line-format}. 1737@code{mode-line-format}.
1740 1738
1741@defopt mode-line-format 1739@defopt mode-line-format
1742The value of this variable is a mode-line construct that controls the 1740The value of this variable is a mode line construct that controls the
1743contents of the mode-line. It is always buffer-local in all buffers. 1741contents of the mode-line. It is always buffer-local in all buffers.
1744 1742
1745If you set this variable to @code{nil} in a buffer, that buffer does 1743If you set this variable to @code{nil} in a buffer, that buffer does not
1746not have a mode line. (A window that is just one line tall never 1744have a mode line. (A window that is just one line tall also does not
1747displays a mode line.) 1745display a mode line.)
1748@end defopt 1746@end defopt
1749 1747
1750 The default value of @code{mode-line-format} is designed to use the 1748 The default value of @code{mode-line-format} is designed to use the
@@ -1762,9 +1760,9 @@ the information in another fashion. This way, customizations made by
1762the user or by Lisp programs (such as @code{display-time} and major 1760the user or by Lisp programs (such as @code{display-time} and major
1763modes) via changes to those variables remain effective. 1761modes) via changes to those variables remain effective.
1764 1762
1765 Here is an example of a @code{mode-line-format} that might be 1763 Here is a hypothetical example of a @code{mode-line-format} that might
1766useful for @code{shell-mode}, since it contains the host name and default 1764be useful for Shell mode (in reality, Shell mode does not set
1767directory. 1765@code{mode-line-format}):
1768 1766
1769@example 1767@example
1770@group 1768@group
@@ -1777,7 +1775,7 @@ directory.
1777@end group 1775@end group
1778@group 1776@group
1779 ;; @r{Note that this is evaluated while making the list.} 1777 ;; @r{Note that this is evaluated while making the list.}
1780 ;; @r{It makes a mode-line construct which is just a string.} 1778 ;; @r{It makes a mode line construct which is just a string.}
1781 (getenv "HOST") 1779 (getenv "HOST")
1782@end group 1780@end group
1783 ":" 1781 ":"
@@ -1794,8 +1792,7 @@ directory.
1794 '(which-func-mode ("" which-func-format "--")) 1792 '(which-func-mode ("" which-func-format "--"))
1795 '(line-number-mode "L%l--") 1793 '(line-number-mode "L%l--")
1796 '(column-number-mode "C%c--") 1794 '(column-number-mode "C%c--")
1797 '(-3 "%p") 1795 '(-3 "%p")))
1798 "-%-"))
1799@end group 1796@end group
1800@end example 1797@end example
1801 1798
@@ -1807,23 +1804,23 @@ these variable names are also the minor mode command names.)
1807@node Mode Line Variables 1804@node Mode Line Variables
1808@subsection Variables Used in the Mode Line 1805@subsection Variables Used in the Mode Line
1809 1806
1810 This section describes variables incorporated by the standard value 1807 This section describes variables incorporated by the standard value of
1811of @code{mode-line-format} into the text of the mode line. There is 1808@code{mode-line-format} into the text of the mode line. There is
1812nothing inherently special about these variables; any other variables 1809nothing inherently special about these variables; any other variables
1813could have the same effects on the mode line if 1810could have the same effects on the mode line if the value of
1814@code{mode-line-format}'s value were changed to use them. However, 1811@code{mode-line-format} is changed to use them. However, various parts
1815various parts of Emacs set these variables on the understanding that 1812of Emacs set these variables on the understanding that they will control
1816they will control parts of the mode line; therefore, practically 1813parts of the mode line; therefore, practically speaking, it is essential
1817speaking, it is essential for the mode line to use them. 1814for the mode line to use them.
1818 1815
1819@defvar mode-line-mule-info 1816@defvar mode-line-mule-info
1820This variable holds the value of the mode-line construct that displays 1817This variable holds the value of the mode line construct that displays
1821information about the language environment, buffer coding system, and 1818information about the language environment, buffer coding system, and
1822current input method. @xref{Non-ASCII Characters}. 1819current input method. @xref{Non-ASCII Characters}.
1823@end defvar 1820@end defvar
1824 1821
1825@defvar mode-line-modified 1822@defvar mode-line-modified
1826This variable holds the value of the mode-line construct that displays 1823This variable holds the value of the mode line construct that displays
1827whether the current buffer is modified. Its default value displays 1824whether the current buffer is modified. Its default value displays
1828@samp{**} if the buffer is modified, @samp{--} if the buffer is not 1825@samp{**} if the buffer is modified, @samp{--} if the buffer is not
1829modified, @samp{%%} if the buffer is read only, and @samp{%*} if the 1826modified, @samp{%%} if the buffer is read only, and @samp{%*} if the
@@ -1886,7 +1883,7 @@ identify the mode name in the mode line, use @code{format-mode-line}
1886@end defvar 1883@end defvar
1887 1884
1888@defvar mode-line-process 1885@defvar mode-line-process
1889This buffer-local variable contains the mode-line information on process 1886This buffer-local variable contains the mode line information on process
1890status in modes used for communicating with subprocesses. It is 1887status in modes used for communicating with subprocesses. It is
1891displayed immediately following the major mode name, with no intervening 1888displayed immediately following the major mode name, with no intervening
1892space. For example, its value in the @samp{*shell*} buffer is 1889space. For example, its value in the @samp{*shell*} buffer is
@@ -1905,12 +1902,12 @@ the @code{minor-mode-alist} should be a two-element list:
1905(@var{minor-mode-variable} @var{mode-line-string}) 1902(@var{minor-mode-variable} @var{mode-line-string})
1906@end example 1903@end example
1907 1904
1908More generally, @var{mode-line-string} can be any mode-line spec. It 1905More generally, @var{mode-line-string} can be any mode line construct.
1909appears in the mode line when the value of @var{minor-mode-variable} 1906It appears in the mode line when the value of @var{minor-mode-variable}
1910is non-@code{nil}, and not otherwise. These strings should begin with 1907is non-@code{nil}, and not otherwise. These strings should begin with
1911spaces so that they don't run together. Conventionally, the 1908spaces so that they don't run together. Conventionally, the
1912@var{minor-mode-variable} for a specific mode is set to a 1909@var{minor-mode-variable} for a specific mode is set to a non-@code{nil}
1913non-@code{nil} value when that minor mode is activated. 1910value when that minor mode is activated.
1914 1911
1915@code{minor-mode-alist} itself is not buffer-local. Each variable 1912@code{minor-mode-alist} itself is not buffer-local. Each variable
1916mentioned in the alist should be buffer-local if its minor mode can be 1913mentioned in the alist should be buffer-local if its minor mode can be
@@ -1918,12 +1915,12 @@ enabled separately in each buffer.
1918@end defvar 1915@end defvar
1919 1916
1920@defvar global-mode-string 1917@defvar global-mode-string
1921This variable holds a mode-line spec that, by default, appears in the 1918This variable holds a mode line construct that, by default, appears in
1922mode line just after the @code{which-func-mode} minor mode if set, 1919the mode line just after the @code{which-func-mode} minor mode if set,
1923else after @code{mode-line-modes}. The command @code{display-time} 1920else after @code{mode-line-modes}. The command @code{display-time} sets
1924sets @code{global-mode-string} to refer to the variable 1921@code{global-mode-string} to refer to the variable
1925@code{display-time-string}, which holds a string containing the time 1922@code{display-time-string}, which holds a string containing the time and
1926and load information. 1923load information.
1927 1924
1928The @samp{%M} construct substitutes the value of 1925The @samp{%M} construct substitutes the value of
1929@code{global-mode-string}, but that is obsolete, since the variable is 1926@code{global-mode-string}, but that is obsolete, since the variable is
@@ -1957,7 +1954,7 @@ specifies addition of text properties.
1957@node %-Constructs 1954@node %-Constructs
1958@subsection @code{%}-Constructs in the Mode Line 1955@subsection @code{%}-Constructs in the Mode Line
1959 1956
1960 Strings used as mode-line constructs can use certain 1957 Strings used as mode line constructs can use certain
1961@code{%}-constructs to substitute various kinds of data. Here is a 1958@code{%}-constructs to substitute various kinds of data. Here is a
1962list of the defined @code{%}-constructs, and what they mean. In any 1959list of the defined @code{%}-constructs, and what they mean. In any
1963construct except @samp{%%}, you can add a decimal integer after the 1960construct except @samp{%%}, you can add a decimal integer after the
@@ -2003,8 +2000,8 @@ of the buffer.
2003 2000
2004@item %p 2001@item %p
2005The percentage of the buffer text above the @strong{top} of window, or 2002The percentage of the buffer text above the @strong{top} of window, or
2006@samp{Top}, @samp{Bottom} or @samp{All}. Note that the default 2003@samp{Top}, @samp{Bottom} or @samp{All}. Note that the default mode
2007mode-line specification truncates this to three characters. 2004line construct truncates this to three characters.
2008 2005
2009@item %P 2006@item %P
2010The percentage of the buffer text that is above the @strong{bottom} of 2007The percentage of the buffer text that is above the @strong{bottom} of
@@ -2084,11 +2081,11 @@ line:
2084 2081
2085@enumerate 2082@enumerate
2086@item 2083@item
2087Put a string with a text property directly into the mode-line data 2084Put a string with a text property directly into the mode line data
2088structure. 2085structure.
2089 2086
2090@item 2087@item
2091Put a text property on a mode-line %-construct such as @samp{%12b}; then 2088Put a text property on a mode line %-construct such as @samp{%12b}; then
2092the expansion of the %-construct will have that same text property. 2089the expansion of the %-construct will have that same text property.
2093 2090
2094@item 2091@item
@@ -2096,7 +2093,7 @@ Use a @code{(:propertize @var{elt} @var{props}@dots{})} construct to
2096give @var{elt} a text property specified by @var{props}. 2093give @var{elt} a text property specified by @var{props}.
2097 2094
2098@item 2095@item
2099Use a list containing @code{:eval @var{form}} in the mode-line data 2096Use a list containing @code{:eval @var{form}} in the mode line data
2100structure, and make @var{form} evaluate to a string that has a text 2097structure, and make @var{form} evaluate to a string that has a text
2101property. 2098property.
2102@end enumerate 2099@end enumerate
@@ -2118,10 +2115,10 @@ local variables.
2118@cindex header line (of a window) 2115@cindex header line (of a window)
2119@cindex window header line 2116@cindex window header line
2120 2117
2121 A window can have a @dfn{header line} at the 2118 A window can have a @dfn{header line} at the top, just as it can have
2122top, just as it can have a mode line at the bottom. The header line 2119a mode line at the bottom. The header line feature works just like the
2123feature works just like the mode-line feature, except that it's 2120mode line feature, except that it's controlled by
2124controlled by different variables. 2121@code{header-line-format}:
2125 2122
2126@defvar header-line-format 2123@defvar header-line-format
2127This variable, local in every buffer, specifies how to display the 2124This variable, local in every buffer, specifies how to display the
@@ -2136,11 +2133,11 @@ header line at once; if it has a mode line, then it does not display a
2136header line. 2133header line.
2137 2134
2138@node Emulating Mode Line 2135@node Emulating Mode Line
2139@subsection Emulating Mode-Line Formatting 2136@subsection Emulating Mode Line Formatting
2140 2137
2141 You can use the function @code{format-mode-line} to compute 2138 You can use the function @code{format-mode-line} to compute the text
2142the text that would appear in a mode line or header line 2139that would appear in a mode line or header line based on a certain
2143based on a certain mode-line specification. 2140mode line construct.
2144 2141
2145@defun format-mode-line format &optional face window buffer 2142@defun format-mode-line format &optional face window buffer
2146This function formats a line of text according to @var{format} as if it 2143This function formats a line of text according to @var{format} as if it
@@ -2374,12 +2371,12 @@ Setting this variable makes it buffer-local in the current buffer.
2374@section Font Lock Mode 2371@section Font Lock Mode
2375@cindex Font Lock mode 2372@cindex Font Lock mode
2376 2373
2377 @dfn{Font Lock mode} is a feature that automatically attaches 2374 @dfn{Font Lock mode} is a buffer-local minor mode that automatically
2378@code{face} properties to certain parts of the buffer based on their 2375attaches @code{face} properties to certain parts of the buffer based on
2379syntactic role. How it parses the buffer depends on the major mode; 2376their syntactic role. How it parses the buffer depends on the major
2380most major modes define syntactic criteria for which faces to use in 2377mode; most major modes define syntactic criteria for which faces to use
2381which contexts. This section explains how to customize Font Lock for a 2378in which contexts. This section explains how to customize Font Lock for
2382particular major mode. 2379a particular major mode.
2383 2380
2384 Font Lock mode finds text to highlight in two ways: through 2381 Font Lock mode finds text to highlight in two ways: through
2385syntactic parsing based on the syntax table, and through searching 2382syntactic parsing based on the syntax table, and through searching
@@ -2398,8 +2395,6 @@ Search-based fontification happens second.
2398 contents can also specify how to fontify it. 2395 contents can also specify how to fontify it.
2399* Faces for Font Lock:: Special faces specifically for Font Lock. 2396* Faces for Font Lock:: Special faces specifically for Font Lock.
2400* Syntactic Font Lock:: Fontification based on syntax tables. 2397* Syntactic Font Lock:: Fontification based on syntax tables.
2401* Setting Syntax Properties:: Defining character syntax based on context
2402 using the Font Lock mechanism.
2403* Multiline Font Lock:: How to coerce Font Lock into properly 2398* Multiline Font Lock:: How to coerce Font Lock into properly
2404 highlighting multiline constructs. 2399 highlighting multiline constructs.
2405@end menu 2400@end menu
@@ -2414,12 +2409,12 @@ variable. The value assigned to this variable is used, if and when Font
2414Lock mode is enabled, to set all the other variables. 2409Lock mode is enabled, to set all the other variables.
2415 2410
2416@defvar font-lock-defaults 2411@defvar font-lock-defaults
2417This variable is set by major modes, as a buffer-local variable, to 2412This variable is set by major modes to specify how to fontify text in
2418specify how to fontify text in that mode. It automatically becomes 2413that mode. It automatically becomes buffer-local when set. If its
2419buffer-local when you set it. If its value is @code{nil}, Font-Lock 2414value is @code{nil}, Font Lock mode does no highlighting, and you can
2420mode does no highlighting, and you can use the @samp{Faces} menu 2415use the @samp{Faces} menu (under @samp{Edit} and then @samp{Text
2421(under @samp{Edit} and then @samp{Text Properties} in the menu bar) to 2416Properties} in the menu bar) to assign faces explicitly to text in the
2422assign faces explicitly to text in the buffer. 2417buffer.
2423 2418
2424If non-@code{nil}, the value should look like this: 2419If non-@code{nil}, the value should look like this:
2425 2420
@@ -2442,19 +2437,20 @@ value. @xref{Levels of Font Lock}.
2442The second element, @var{keywords-only}, specifies the value of the 2437The second element, @var{keywords-only}, specifies the value of the
2443variable @code{font-lock-keywords-only}. If this is omitted or 2438variable @code{font-lock-keywords-only}. If this is omitted or
2444@code{nil}, syntactic fontification (of strings and comments) is also 2439@code{nil}, syntactic fontification (of strings and comments) is also
2445performed. If this is non-@code{nil}, such fontification is not 2440performed. If this is non-@code{nil}, syntactic fontification is not
2446performed. @xref{Syntactic Font Lock}. 2441performed. @xref{Syntactic Font Lock}.
2447 2442
2448The third element, @var{case-fold}, specifies the value of 2443The third element, @var{case-fold}, specifies the value of
2449@code{font-lock-keywords-case-fold-search}. If it is non-@code{nil}, 2444@code{font-lock-keywords-case-fold-search}. If it is non-@code{nil},
2450Font Lock mode ignores case when searching as directed by 2445Font Lock mode ignores case during search-based fontification.
2451@code{font-lock-keywords}.
2452 2446
2453If the fourth element, @var{syntax-alist}, is non-@code{nil}, it 2447If the fourth element, @var{syntax-alist}, is non-@code{nil}, it should
2454should be a list of cons cells of the form @code{(@var{char-or-string} 2448be a list of cons cells of the form @code{(@var{char-or-string}
2455. @var{string})}. These are used to set up a syntax table for 2449. @var{string})}. These are used to set up a syntax table for syntactic
2456syntactic fontification (@pxref{Syntax Table Functions}). The 2450fontification; the resulting syntax table is stored in
2457resulting syntax table is stored in @code{font-lock-syntax-table}. 2451@code{font-lock-syntax-table}. If @var{syntax-alist} is omitted or
2452@code{nil}, syntactic fontification uses the syntax table returned by
2453the @code{syntax-table} function. @xref{Syntax Table Functions}.
2458 2454
2459The fifth element, @var{syntax-begin}, specifies the value of 2455The fifth element, @var{syntax-begin}, specifies the value of
2460@code{font-lock-beginning-of-syntax-function}. We recommend setting 2456@code{font-lock-beginning-of-syntax-function}. We recommend setting
@@ -2480,15 +2476,17 @@ fontification for other parts of the text.
2480@node Search-based Fontification 2476@node Search-based Fontification
2481@subsection Search-based Fontification 2477@subsection Search-based Fontification
2482 2478
2483 The most important variable for customizing Font Lock mode is 2479 The variable which directly controls search-based fontification is
2484@code{font-lock-keywords}. It specifies the search criteria for 2480@code{font-lock-keywords}, which is typically specified via the
2485search-based fontification. You should specify the value of this 2481@var{keywords} element in @code{font-lock-defaults}.
2486variable with @var{keywords} in @code{font-lock-defaults}.
2487 2482
2488@defvar font-lock-keywords 2483@defvar font-lock-keywords
2489This variable's value is a list of the keywords to highlight. Be 2484The value of this variable is a list of the keywords to highlight. Lisp
2490careful when composing regular expressions for this list; a poorly 2485programs should not set this variable directly. Normally, the value is
2491written pattern can dramatically slow things down! 2486automatically set by Font Lock mode, using the @var{keywords} element in
2487@code{font-lock-defaults}. The value can also be altered using the
2488functions @code{font-lock-add-keywords} and
2489@code{font-lock-remove-keywords} (@pxref{Customizing Keywords}).
2492@end defvar 2490@end defvar
2493 2491
2494 Each element of @code{font-lock-keywords} specifies how to find 2492 Each element of @code{font-lock-keywords} specifies how to find
@@ -2513,9 +2511,10 @@ Highlight all matches for @var{regexp} using
2513"\\<foo\\>" 2511"\\<foo\\>"
2514@end example 2512@end example
2515 2513
2516The function @code{regexp-opt} (@pxref{Regexp Functions}) is useful 2514Be careful when composing these regular expressions; a poorly written
2517for calculating optimal regular expressions to match a number of 2515pattern can dramatically slow things down! The function
2518different keywords. 2516@code{regexp-opt} (@pxref{Regexp Functions}) is useful for calculating
2517optimal regular expressions to match several keywords.
2519 2518
2520@item @var{function} 2519@item @var{function}
2521Find text by calling @var{function}, and highlight the matches 2520Find text by calling @var{function}, and highlight the matches
@@ -2740,7 +2739,7 @@ highlighting patterns. See the variables
2740@code{c-font-lock-extra-types}, @code{c++-font-lock-extra-types}, 2739@code{c-font-lock-extra-types}, @code{c++-font-lock-extra-types},
2741and @code{java-font-lock-extra-types}, for example. 2740and @code{java-font-lock-extra-types}, for example.
2742 2741
2743@strong{Warning:} major mode commands must not call 2742@strong{Warning:} Major mode commands must not call
2744@code{font-lock-add-keywords} under any circumstances, either directly 2743@code{font-lock-add-keywords} under any circumstances, either directly
2745or indirectly, except through their mode hooks. (Doing so would lead to 2744or indirectly, except through their mode hooks. (Doing so would lead to
2746incorrect behavior for some minor modes.) They should set up their 2745incorrect behavior for some minor modes.) They should set up their
@@ -2756,7 +2755,10 @@ command name or @code{nil}. All the caveats and requirements for
2756@code{font-lock-add-keywords} apply here too. 2755@code{font-lock-add-keywords} apply here too.
2757@end defun 2756@end defun
2758 2757
2759 For example, this code 2758 For example, the following code adds two fontification patterns for C
2759mode: one to fontify the word @samp{FIXME}, even in comments, and
2760another to fontify the words @samp{and}, @samp{or} and @samp{not} as
2761keywords.
2760 2762
2761@smallexample 2763@smallexample
2762(font-lock-add-keywords 'c-mode 2764(font-lock-add-keywords 'c-mode
@@ -2765,13 +2767,8 @@ command name or @code{nil}. All the caveats and requirements for
2765@end smallexample 2767@end smallexample
2766 2768
2767@noindent 2769@noindent
2768adds two fontification patterns for C mode: one to fontify the word 2770This example affects only C mode proper. To add the same patterns to C
2769@samp{FIXME}, even in comments, and another to fontify the words 2771mode @emph{and} all modes derived from it, do this instead:
2770@samp{and}, @samp{or} and @samp{not} as keywords.
2771
2772@noindent
2773That example affects only C mode proper. To add the same patterns to
2774C mode @emph{and} all modes derived from it, do this instead:
2775 2772
2776@smallexample 2773@smallexample
2777(add-hook 'c-mode-hook 2774(add-hook 'c-mode-hook
@@ -2858,13 +2855,13 @@ function using @code{jit-lock-register}, this function unregisters it.
2858@node Levels of Font Lock 2855@node Levels of Font Lock
2859@subsection Levels of Font Lock 2856@subsection Levels of Font Lock
2860 2857
2861 Many major modes offer three different levels of fontification. You 2858 Some major modes offer three different levels of fontification. You
2862can define multiple levels by using a list of symbols for @var{keywords} 2859can define multiple levels by using a list of symbols for @var{keywords}
2863in @code{font-lock-defaults}. Each symbol specifies one level of 2860in @code{font-lock-defaults}. Each symbol specifies one level of
2864fontification; it is up to the user to choose one of these levels, 2861fontification; it is up to the user to choose one of these levels,
2865normally by setting @code{font-lock-maximum-decoration} (@pxref{Font 2862normally by setting @code{font-lock-maximum-decoration} (@pxref{Font
2866Lock,,, emacs, the GNU Emacs Manual}). The chosen level's symbol 2863Lock,,, emacs, the GNU Emacs Manual}). The chosen level's symbol value
2867value is used to initialize @code{font-lock-keywords}. 2864is used to initialize @code{font-lock-keywords}.
2868 2865
2869 Here are the conventions for how to define the levels of 2866 Here are the conventions for how to define the levels of
2870fontification: 2867fontification:
@@ -2912,10 +2909,10 @@ the normal Font Lock machinery, it should not set the variable
2912@cindex font lock faces 2909@cindex font lock faces
2913 2910
2914 Font Lock mode can highlight using any face, but Emacs defines several 2911 Font Lock mode can highlight using any face, but Emacs defines several
2915faces specifically for syntactic highlighting. These @dfn{Font Lock 2912faces specifically for Font Lock to use to highlight text. These
2916faces} are listed below. They can also be used by major modes for 2913@dfn{Font Lock faces} are listed below. They can also be used by major
2917syntactic highlighting outside of Font Lock mode (@pxref{Major Mode 2914modes for syntactic highlighting outside of Font Lock mode (@pxref{Major
2918Conventions}). 2915Mode Conventions}).
2919 2916
2920 Each of these symbols is both a face name, and a variable whose 2917 Each of these symbols is both a face name, and a variable whose
2921default value is the symbol itself. Thus, the default value of 2918default value is the symbol itself. Thus, the default value of
@@ -2990,128 +2987,60 @@ for easily-overlooked negation characters.
2990@subsection Syntactic Font Lock 2987@subsection Syntactic Font Lock
2991@cindex syntactic font lock 2988@cindex syntactic font lock
2992 2989
2993Syntactic fontification uses the syntax table to find comments and 2990Syntactic fontification uses a syntax table (@pxref{Syntax Tables}) to
2994string constants (@pxref{Syntax Tables}). It highlights them using 2991find and highlight syntactically relevant text. If enabled, it runs
2995@code{font-lock-comment-face} and @code{font-lock-string-face} 2992prior to search-based fontification. The variable
2996(@pxref{Faces for Font Lock}), or whatever 2993@code{font-lock-syntactic-face-function}, documented below, determines
2997@code{font-lock-syntactic-face-function} chooses. There are several 2994which syntactic constructs to highlight. There are several variables
2998variables that affect syntactic fontification; you should set them by 2995that affect syntactic fontification; you should set them by means of
2999means of @code{font-lock-defaults} (@pxref{Font Lock Basics}). 2996@code{font-lock-defaults} (@pxref{Font Lock Basics}).
3000 2997
3001@defvar font-lock-keywords-only 2998@defvar font-lock-keywords-only
3002Non-@code{nil} means Font Lock should not do syntactic fontification; 2999If the value of this variable is non-@code{nil}, Font Lock does not do
3003it should only fontify based on @code{font-lock-keywords}. The normal 3000syntactic fontification, only search-based fontification based on
3004way for a mode to set this variable to @code{t} is with 3001@code{font-lock-keywords}. It is normally set by Font Lock mode based
3005@var{keywords-only} in @code{font-lock-defaults}. 3002on the @var{keywords-only} element in @code{font-lock-defaults}.
3006@end defvar 3003@end defvar
3007 3004
3008@defvar font-lock-syntax-table 3005@defvar font-lock-syntax-table
3009This variable holds the syntax table to use for fontification of 3006This variable holds the syntax table to use for fontification of
3010comments and strings. Specify it using @var{syntax-alist} in 3007comments and strings. It is normally set by Font Lock mode based on the
3011@code{font-lock-defaults}. If this is @code{nil}, fontification uses 3008@var{syntax-alist} element in @code{font-lock-defaults}. If this value
3012the buffer's syntax table. 3009is @code{nil}, syntactic fontification uses the buffer's syntax table
3010(the value returned by the function @code{syntax-table}; @pxref{Syntax
3011Table Functions}).
3013@end defvar 3012@end defvar
3014 3013
3015@defvar font-lock-beginning-of-syntax-function 3014@defvar font-lock-beginning-of-syntax-function
3016If this variable is non-@code{nil}, it should be a function to move 3015If this variable is non-@code{nil}, it should be a function to move
3017point back to a position that is syntactically at ``top level'' and 3016point back to a position that is syntactically at ``top level'' and
3018outside of strings or comments. Font Lock uses this when necessary 3017outside of strings or comments. The value is normally set through an
3019to get the right results for syntactic fontification. 3018@var{other-vars} element in @code{font-lock-defaults}. If it is
3020 3019@code{nil}, Font Lock uses @code{syntax-begin-function} to move back
3021This function is called with no arguments. It should leave point at 3020outside of any comment, string, or sexp (@pxref{Position Parse}).
3022the beginning of any enclosing syntactic block. Typical values are 3021
3023@code{beginning-of-line} (used when the start of the line is known to 3022This variable is semi-obsolete; we usually recommend setting
3024be outside a syntactic block), or @code{beginning-of-defun} for 3023@code{syntax-begin-function} instead. One of its uses is to tune the
3024behavior of syntactic fontification, e.g.@: to ensure that different
3025kinds of strings or comments are highlighted differently.
3026
3027The specified function is called with no arguments. It should leave
3028point at the beginning of any enclosing syntactic block. Typical values
3029are @code{beginning-of-line} (used when the start of the line is known
3030to be outside a syntactic block), or @code{beginning-of-defun} for
3025programming modes, or @code{backward-paragraph} for textual modes. 3031programming modes, or @code{backward-paragraph} for textual modes.
3026
3027If the value is @code{nil}, Font Lock uses
3028@code{syntax-begin-function} to move back outside of any comment,
3029string, or sexp. This variable is semi-obsolete; we recommend setting
3030@code{syntax-begin-function} instead.
3031
3032Specify this variable using @var{syntax-begin} in
3033@code{font-lock-defaults}.
3034@end defvar 3032@end defvar
3035 3033
3036@defvar font-lock-syntactic-face-function 3034@defvar font-lock-syntactic-face-function
3037A function to determine which face to use for a given syntactic 3035If this variable is non-@code{nil}, it should be a function to determine
3038element (a string or a comment). The function is called with one 3036which face to use for a given syntactic element (a string or a comment).
3039argument, the parse state at point returned by 3037The value is normally set through an @var{other-vars} element in
3040@code{parse-partial-sexp}, and should return a face. The default
3041value returns @code{font-lock-comment-face} for comments and
3042@code{font-lock-string-face} for strings.
3043
3044This can be used to highlighting different kinds of strings or
3045comments differently. It is also sometimes abused together with
3046@code{font-lock-syntactic-keywords} to highlight constructs that span
3047multiple lines, but this is too esoteric to document here.
3048
3049Specify this variable using @var{other-vars} in
3050@code{font-lock-defaults}. 3038@code{font-lock-defaults}.
3051@end defvar
3052
3053@node Setting Syntax Properties
3054@subsection Setting Syntax Properties
3055
3056 Font Lock mode can be used to update @code{syntax-table} properties
3057automatically (@pxref{Syntax Properties}). This is useful in
3058languages for which a single syntax table by itself is not sufficient.
3059
3060@defvar font-lock-syntactic-keywords
3061This variable enables and controls updating @code{syntax-table}
3062properties by Font Lock. Its value should be a list of elements of
3063this form:
3064
3065@example
3066(@var{matcher} @var{subexp} @var{syntax} @var{override} @var{laxmatch})
3067@end example
3068
3069The parts of this element have the same meanings as in the corresponding
3070sort of element of @code{font-lock-keywords},
3071 3039
3072@example 3040The function is called with one argument, the parse state at point
3073(@var{matcher} @var{subexp} @var{facespec} @var{override} @var{laxmatch}) 3041returned by @code{parse-partial-sexp}, and should return a face. The
3074@end example 3042default value returns @code{font-lock-comment-face} for comments and
3075 3043@code{font-lock-string-face} for strings (@pxref{Faces for Font Lock}).
3076However, instead of specifying the value @var{facespec} to use for the
3077@code{face} property, it specifies the value @var{syntax} to use for
3078the @code{syntax-table} property. Here, @var{syntax} can be a string
3079(as taken by @code{modify-syntax-entry}), a syntax table, a cons cell
3080(as returned by @code{string-to-syntax}), or an expression whose value
3081is one of those two types. @var{override} cannot be @code{prepend} or
3082@code{append}.
3083
3084For example, an element of the form:
3085
3086@example
3087("\\$\\(#\\)" 1 ".")
3088@end example
3089
3090highlights syntactically a hash character when following a dollar
3091character, with a SYNTAX of @code{"."} (meaning punctuation syntax).
3092Assuming that the buffer syntax table specifies hash characters to
3093have comment start syntax, the element will only highlight hash
3094characters that do not follow dollar characters as comments
3095syntactically.
3096
3097An element of the form:
3098
3099@example
3100 ("\\('\\).\\('\\)"
3101 (1 "\"")
3102 (2 "\""))
3103@end example
3104
3105highlights syntactically both single quotes which surround a single
3106character, with a SYNTAX of @code{"\""} (meaning string quote syntax).
3107Assuming that the buffer syntax table does not specify single quotes
3108to have quote syntax, the element will only highlight single quotes of
3109the form @samp{'@var{c}'} as strings syntactically. Other forms, such
3110as @samp{foo'bar} or @samp{'fubar'}, will not be highlighted as
3111strings.
3112
3113Major modes normally set this variable with @var{other-vars} in
3114@code{font-lock-defaults}.
3115@end defvar 3044@end defvar
3116 3045
3117@node Multiline Font Lock 3046@node Multiline Font Lock
@@ -3220,18 +3149,17 @@ easy to add the @code{font-lock-multiline} property by hand.
3220 3149
3221 The @code{font-lock-multiline} property is meant to ensure proper 3150 The @code{font-lock-multiline} property is meant to ensure proper
3222refontification; it does not automatically identify new multiline 3151refontification; it does not automatically identify new multiline
3223constructs. Identifying the requires that Font-Lock operate on large 3152constructs. Identifying the requires that Font Lock mode operate on
3224enough chunks at a time. This will happen by accident on many cases, 3153large enough chunks at a time. This will happen by accident on many
3225which may give the impression that multiline constructs magically work. 3154cases, which may give the impression that multiline constructs magically
3226If you set the @code{font-lock-multiline} variable non-@code{nil}, 3155work. If you set the @code{font-lock-multiline} variable
3227this impression will be even stronger, since the highlighting of those 3156non-@code{nil}, this impression will be even stronger, since the
3228constructs which are found will be properly updated from then on. 3157highlighting of those constructs which are found will be properly
3229But that does not work reliably. 3158updated from then on. But that does not work reliably.
3230 3159
3231 To find multiline constructs reliably, you must either manually 3160 To find multiline constructs reliably, you must either manually place
3232place the @code{font-lock-multiline} property on the text before 3161the @code{font-lock-multiline} property on the text before Font Lock
3233Font-Lock looks at it, or use 3162mode looks at it, or use @code{font-lock-fontify-region-function}.
3234@code{font-lock-fontify-region-function}.
3235 3163
3236@node Region to Refontify 3164@node Region to Refontify
3237@subsubsection Region to Fontify after a Buffer Change 3165@subsubsection Region to Fontify after a Buffer Change
@@ -3246,8 +3174,8 @@ earlier line.
3246the following variable: 3174the following variable:
3247 3175
3248@defvar font-lock-extend-after-change-region-function 3176@defvar font-lock-extend-after-change-region-function
3249This buffer-local variable is either @code{nil} or a function for 3177This buffer-local variable is either @code{nil} or a function for Font
3250Font-Lock to call to determine the region to scan and fontify. 3178Lock mode to call to determine the region to scan and fontify.
3251 3179
3252The function is given three parameters, the standard @var{beg}, 3180The function is given three parameters, the standard @var{beg},
3253@var{end}, and @var{old-len} from @code{after-change-functions} 3181@var{end}, and @var{old-len} from @code{after-change-functions}
diff --git a/doc/lispref/syntax.texi b/doc/lispref/syntax.texi
index 3d153e43b2d..8b3e3a3febb 100644
--- a/doc/lispref/syntax.texi
+++ b/doc/lispref/syntax.texi
@@ -536,9 +536,7 @@ execution starts. Other buffers are not affected.
536When the syntax table is not flexible enough to specify the syntax of 536When the syntax table is not flexible enough to specify the syntax of
537a language, you can use @code{syntax-table} text properties to 537a language, you can use @code{syntax-table} text properties to
538override the syntax table for specific character occurrences in the 538override the syntax table for specific character occurrences in the
539buffer. @xref{Text Properties}. You can use Font Lock mode to set 539buffer. @xref{Text Properties}.
540@code{syntax-table} text properties. @xref{Setting Syntax
541Properties}.
542 540
543The valid values of @code{syntax-table} text property are: 541The valid values of @code{syntax-table} text property are:
544 542
diff --git a/doc/lispref/vol1.texi b/doc/lispref/vol1.texi
index dbab287b273..c0d5767697d 100644
--- a/doc/lispref/vol1.texi
+++ b/doc/lispref/vol1.texi
@@ -835,8 +835,6 @@ Font Lock Mode
835 contents can also specify how to fontify it. 835 contents can also specify how to fontify it.
836* Faces for Font Lock:: Special faces specifically for Font Lock. 836* Faces for Font Lock:: Special faces specifically for Font Lock.
837* Syntactic Font Lock:: Fontification based on syntax tables. 837* Syntactic Font Lock:: Fontification based on syntax tables.
838* Setting Syntax Properties:: Defining character syntax based on context
839 using the Font Lock mechanism.
840* Multiline Font Lock:: How to coerce Font Lock into properly 838* Multiline Font Lock:: How to coerce Font Lock into properly
841 highlighting multiline constructs. 839 highlighting multiline constructs.
842 840
diff --git a/doc/lispref/vol2.texi b/doc/lispref/vol2.texi
index 38e2f1dc5e9..0c6deb5671a 100644
--- a/doc/lispref/vol2.texi
+++ b/doc/lispref/vol2.texi
@@ -834,8 +834,6 @@ Font Lock Mode
834 contents can also specify how to fontify it. 834 contents can also specify how to fontify it.
835* Faces for Font Lock:: Special faces specifically for Font Lock. 835* Faces for Font Lock:: Special faces specifically for Font Lock.
836* Syntactic Font Lock:: Fontification based on syntax tables. 836* Syntactic Font Lock:: Fontification based on syntax tables.
837* Setting Syntax Properties:: Defining character syntax based on context
838 using the Font Lock mechanism.
839* Multiline Font Lock:: How to coerce Font Lock into properly 837* Multiline Font Lock:: How to coerce Font Lock into properly
840 highlighting multiline constructs. 838 highlighting multiline constructs.
841 839