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