aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2016-04-30 16:08:07 +0200
committerLars Ingebrigtsen2016-04-30 16:08:07 +0200
commitc05716d3a26ea7518b89eacfccaf70c9d0731df7 (patch)
tree09ba2b15822258646fbf82e060dc5e936b6174b3
parentbc00dcf12983cd399127d0eea39647f29778eb02 (diff)
downloademacs-c05716d3a26ea7518b89eacfccaf70c9d0731df7.tar.gz
emacs-c05716d3a26ea7518b89eacfccaf70c9d0731df7.zip
Fill the doc string of font-lock-keywords
* lisp/font-lock.el (font-lock-keywords): Fill the lines and reorganise some explanations (bug#21427).
-rw-r--r--lisp/font-lock.el174
1 files changed, 97 insertions, 77 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 48a96f2741e..b5ff5cfd0af 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -364,105 +364,125 @@ Each element in a user-level keywords list should have one of these forms:
364 (MATCHER HIGHLIGHT ...) 364 (MATCHER HIGHLIGHT ...)
365 (eval . FORM) 365 (eval . FORM)
366 366
367where MATCHER can be either the regexp to search for, or the function name to 367where MATCHER can be either the regexp to search for, or the
368call to make the search (called with one argument, the limit of the search; 368function name to call to make the search (called with one
369it should return non-nil, move point, and set `match-data' appropriately if 369argument, the limit of the search; it should return non-nil, move
370it succeeds; like `re-search-forward' would). 370point, and set `match-data' appropriately if it succeeds; like
371MATCHER regexps can be generated via the function `regexp-opt'. 371`re-search-forward' would). MATCHER regexps can be generated via
372 372the function `regexp-opt'.
373FORM is an expression, whose value should be a keyword element, evaluated when 373
374the keyword is (first) used in a buffer. This feature can be used to provide a 374FORM is an expression, whose value should be a keyword element,
375keyword that can only be generated when Font Lock mode is actually turned on. 375evaluated when the keyword is (first) used in a buffer. This
376feature can be used to provide a keyword that can only be
377generated when Font Lock mode is actually turned on.
376 378
377HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED. 379HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED.
378 380
379For highlighting single items, for example each instance of the word \"foo\", 381For highlighting single items, for example each instance of the
380typically only MATCH-HIGHLIGHT is required. 382word \"foo\", typically only MATCH-HIGHLIGHT is required.
381However, if an item or (typically) items are to be highlighted following the 383However, if an item or (typically) items are to be highlighted
382instance of another item (the anchor), for example each instance of the 384following the instance of another item (the anchor), for example
383word \"bar\" following the word \"anchor\" then MATCH-ANCHORED may be required. 385each instance of the word \"bar\" following the word \"anchor\"
386then MATCH-ANCHORED may be required.
384 387
385MATCH-HIGHLIGHT should be of the form: 388MATCH-HIGHLIGHT should be of the form:
386 389
387 (SUBEXP FACENAME [OVERRIDE [LAXMATCH]]) 390 (SUBEXP FACENAME [OVERRIDE [LAXMATCH]])
388 391
389SUBEXP is the number of the subexpression of MATCHER to be highlighted. 392SUBEXP is the number of the subexpression of MATCHER to be
393highlighted.
390 394
391FACENAME is an expression whose value is the face name to use. 395FACENAME is an expression whose value is the face name to use.
392Instead of a face, FACENAME can evaluate to a property list 396Instead of a face, FACENAME can evaluate to a property list of
393of the form (face FACE PROP1 VAL1 PROP2 VAL2 ...) 397the form (face FACE PROP1 VAL1 PROP2 VAL2 ...) in which case all
394in which case all the listed text-properties will be set rather than 398the listed text-properties will be set rather than just FACE. In
395just FACE. In such a case, you will most likely want to put those 399such a case, you will most likely want to put those properties in
396properties in `font-lock-extra-managed-props' or to override 400`font-lock-extra-managed-props' or to override
397`font-lock-unfontify-region-function'. 401`font-lock-unfontify-region-function'.
398 402
399OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification can 403OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing
400be overwritten. If `keep', only parts not already fontified are highlighted. 404fontification can be overwritten. If `keep', only parts not
401If `prepend' or `append', existing fontification is merged with the new, in 405already fontified are highlighted. If `prepend' or `append',
402which the new or existing fontification, respectively, takes precedence. 406existing fontification is merged with the new, in which the new
403If LAXMATCH is non-nil, that means don't signal an error if there is 407or existing fontification, respectively, takes precedence. If
408LAXMATCH is non-nil, that means don't signal an error if there is
404no match for SUBEXP in MATCHER. 409no match for SUBEXP in MATCHER.
405 410
406For example, an element of the form highlights (if not already highlighted): 411For example, an element of the form highlights (if not already
412highlighted):
413
414 \"\\\\\\=<foo\\\\\\=>\"
415 Discrete occurrences of \"foo\" in the value of the variable
416 `font-lock-keyword-face'.
417
418 (\"fu\\\\(bar\\\\)\" . 1)
419 Substring \"bar\" within all occurrences of \"fubar\" in the
420 value of `font-lock-keyword-face'.
421
422 (\"fubar\" . fubar-face)
423 Occurrences of \"fubar\" in the value of `fubar-face'.
407 424
408 \"\\\\\\=<foo\\\\\\=>\" discrete occurrences of \"foo\" in the value of the
409 variable `font-lock-keyword-face'.
410 (\"fu\\\\(bar\\\\)\" . 1) substring \"bar\" within all occurrences of \"fubar\" in
411 the value of `font-lock-keyword-face'.
412 (\"fubar\" . fubar-face) Occurrences of \"fubar\" in the value of `fubar-face'.
413 (\"foo\\\\|bar\" 0 foo-bar-face t) 425 (\"foo\\\\|bar\" 0 foo-bar-face t)
414 occurrences of either \"foo\" or \"bar\" in the value 426 Occurrences of either \"foo\" or \"bar\" in the value of
415 of `foo-bar-face', even if already highlighted. 427 `foo-bar-face', even if already highlighted.
428
416 (fubar-match 1 fubar-face) 429 (fubar-match 1 fubar-face)
417 the first subexpression within all occurrences of 430 The first subexpression within all occurrences of whatever the
418 whatever the function `fubar-match' finds and matches 431 function `fubar-match' finds and matches in the value of
419 in the value of `fubar-face'. 432 `fubar-face'.
420 433
421MATCH-ANCHORED should be of the form: 434MATCH-ANCHORED should be of the form:
422 435
423 (MATCHER PRE-MATCH-FORM POST-MATCH-FORM MATCH-HIGHLIGHT ...) 436 (MATCHER PRE-MATCH-FORM POST-MATCH-FORM MATCH-HIGHLIGHT ...)
424 437
425where MATCHER is a regexp to search for or the function name to call to make 438where MATCHER is a regexp to search for or the function name to
426the search, as for MATCH-HIGHLIGHT above, but with one exception; see below. 439call to make the search, as for MATCH-HIGHLIGHT above, but with
427PRE-MATCH-FORM and POST-MATCH-FORM are evaluated before the first, and after 440one exception; see below. PRE-MATCH-FORM and POST-MATCH-FORM are
428the last, instance MATCH-ANCHORED's MATCHER is used. Therefore they can be 441evaluated before the first, and after the last, instance
429used to initialize before, and cleanup after, MATCHER is used. Typically, 442MATCH-ANCHORED's MATCHER is used. Therefore they can be used to
430PRE-MATCH-FORM is used to move to some position relative to the original 443initialize before, and cleanup after, MATCHER is used.
431MATCHER, before starting with MATCH-ANCHORED's MATCHER. POST-MATCH-FORM might 444Typically, PRE-MATCH-FORM is used to move to some position
432be used to move back, before resuming with MATCH-ANCHORED's parent's MATCHER. 445relative to the original MATCHER, before starting with
433 446MATCH-ANCHORED's MATCHER. POST-MATCH-FORM might be used to move
434For example, an element of the form highlights (if not already highlighted): 447back, before resuming with MATCH-ANCHORED's parent's MATCHER.
435 448
436 (\"\\\\\\=<anchor\\\\\\=>\" (0 anchor-face) (\"\\\\\\=<item\\\\\\=>\" nil nil (0 item-face))) 449For example, an element of the form highlights (if not already
437 450highlighted):
438 discrete occurrences of \"anchor\" in the value of `anchor-face', and subsequent 451
439 discrete occurrences of \"item\" (on the same line) in the value of `item-face'. 452 (\"\\\\\\=<anchor\\\\\\=>\" (0 anchor-face)
440 (Here PRE-MATCH-FORM and POST-MATCH-FORM are nil. Therefore \"item\" is 453 (\"\\\\\\=<item\\\\\\=>\" nil nil (0 item-face)))
441 initially searched for starting from the end of the match of \"anchor\", and 454
442 searching for subsequent instances of \"anchor\" resumes from where searching 455 Discrete occurrences of \"anchor\" in the value of
443 for \"item\" concluded.) 456 `anchor-face', and subsequent discrete occurrences of
444 457 \"item\" (on the same line) in the value of `item-face'.
445The above-mentioned exception is as follows. The limit of the MATCHER search 458 (Here PRE-MATCH-FORM and POST-MATCH-FORM are nil. Therefore
446defaults to the end of the line after PRE-MATCH-FORM is evaluated. 459 \"item\" is initially searched for starting from the end of the
447However, if PRE-MATCH-FORM returns a position greater than the position after 460 match of \"anchor\", and searching for subsequent instances of
448PRE-MATCH-FORM is evaluated, that position is used as the limit of the search. 461 \"anchor\" resumes from where searching for \"item\" concluded.)
449It is generally a bad idea to return a position greater than the end of the 462
450line, i.e., cause the MATCHER search to span lines. 463The above-mentioned exception is as follows. The limit of the
451 464MATCHER search defaults to the end of the line after
452These regular expressions can match text which spans lines, although 465PRE-MATCH-FORM is evaluated. However, if PRE-MATCH-FORM returns
453it is better to avoid it if possible since updating them while editing 466a position greater than the position after PRE-MATCH-FORM is
454text is slower, and it is not guaranteed to be always correct when using 467evaluated, that position is used as the limit of the search. It
455support modes like jit-lock or lazy-lock. 468is generally a bad idea to return a position greater than the end
456 469of the line, i.e., cause the MATCHER search to span lines.
457This variable is set by major modes via the variable `font-lock-defaults'. 470
458Be careful when composing regexps for this list; a poorly written pattern can 471These regular expressions can match text which spans lines,
459dramatically slow things down! 472although it is better to avoid it if possible since updating them
460 473while editing text is slower, and it is not guaranteed to be
461A compiled keywords list starts with t. It is produced internally 474always correct when using support modes like jit-lock or
462by `font-lock-compile-keywords' from a user-level keywords list. 475lazy-lock.
463Its second element is the user-level keywords list that was 476
464compiled. The remaining elements have the same form as 477This variable is set by major modes via the variable
465user-level keywords, but normally their values have been 478`font-lock-defaults'. Be careful when composing regexps for this
479list; a poorly written pattern can dramatically slow things down!
480
481A compiled keywords list starts with t. It is produced
482internally by `font-lock-compile-keywords' from a user-level
483keywords list. Its second element is the user-level keywords
484list that was compiled. The remaining elements have the same
485form as user-level keywords, but normally their values have been
466optimized.") 486optimized.")
467 487
468(defvar font-lock-keywords-alist nil 488(defvar font-lock-keywords-alist nil