diff options
| author | Simon Marshall | 1997-02-21 09:36:18 +0000 |
|---|---|---|
| committer | Simon Marshall | 1997-02-21 09:36:18 +0000 |
| commit | 56fcbd7e9d76f143abef1c13361efe41052ef59d (patch) | |
| tree | 23282e96878d86ce94e4988f14d180529193f283 | |
| parent | acffd065e3d99c26172070b4b745d55a7e828c72 (diff) | |
| download | emacs-56fcbd7e9d76f143abef1c13361efe41052ef59d.tar.gz emacs-56fcbd7e9d76f143abef1c13361efe41052ef59d.zip | |
1. If PRE-MATCH-FORM returns a suitable number, use that as a value for LIMIT.
2. Commented out menu code.
| -rw-r--r-- | lisp/font-lock.el | 237 |
1 files changed, 206 insertions, 31 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el index d3bb3d11d6b..380d41261ae 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el | |||
| @@ -50,6 +50,27 @@ | |||
| 50 | ;; also the variable `font-lock-maximum-size'. Support modes for Font Lock | 50 | ;; also the variable `font-lock-maximum-size'. Support modes for Font Lock |
| 51 | ;; mode can be used to speed up Font Lock mode. See `font-lock-support-mode'. | 51 | ;; mode can be used to speed up Font Lock mode. See `font-lock-support-mode'. |
| 52 | 52 | ||
| 53 | ;;; How Font Lock mode fontifies: | ||
| 54 | |||
| 55 | ;; When Font Lock mode is turned on in a buffer, it (a) fontifies the entire | ||
| 56 | ;; buffer and (b) installs one of its fontification functions on one of the | ||
| 57 | ;; hook variables that are run by Emacs after every buffer change (i.e., an | ||
| 58 | ;; insertion or deletion). Fontification means the replacement of `face' text | ||
| 59 | ;; properties in a given region; Emacs displays text with these `face' text | ||
| 60 | ;; properties appropriately. | ||
| 61 | ;; | ||
| 62 | ;; Fontification normally involves syntactic (i.e., strings and comments) and | ||
| 63 | ;; regexp (i.e., keywords and everything else) passes. The syntactic pass | ||
| 64 | ;; involves a syntax table and a syntax parsing function to determine the | ||
| 65 | ;; context of different parts of a region of text. It is necessary because | ||
| 66 | ;; generally strings and/or comments can span lines, and so the context of a | ||
| 67 | ;; given region is not necessarily apparent from the content of that region. | ||
| 68 | ;; Because the regexp pass only works within a given region, it is not | ||
| 69 | ;; generally appropriate for syntactic fontification. The regexp pass involves | ||
| 70 | ;; searching for given regexps (or calling given functions) within the given | ||
| 71 | ;; region. For each match of the regexp (or non-nil value of the called | ||
| 72 | ;; function), `face' text properties are added appropriately. | ||
| 73 | |||
| 53 | ;;; How Font Lock mode supports modes or is supported by modes: | 74 | ;;; How Font Lock mode supports modes or is supported by modes: |
| 54 | 75 | ||
| 55 | ;; Modes that support Font Lock mode do so by defining one or more variables | 76 | ;; Modes that support Font Lock mode do so by defining one or more variables |
| @@ -63,6 +84,9 @@ | |||
| 63 | ;; (a); (b) is used where it is not clear which package library should contain | 84 | ;; (a); (b) is used where it is not clear which package library should contain |
| 64 | ;; the pattern definitions.) Font Lock mode chooses which variable to use for | 85 | ;; the pattern definitions.) Font Lock mode chooses which variable to use for |
| 65 | ;; fontification based on `font-lock-maximum-decoration'. | 86 | ;; fontification based on `font-lock-maximum-decoration'. |
| 87 | ;; | ||
| 88 | ;; Font Lock mode fontification behaviour can be modified in a number of ways. | ||
| 89 | ;; See the below comments and the comments distributed throughout this file. | ||
| 66 | 90 | ||
| 67 | ;;; Constructing patterns: | 91 | ;;; Constructing patterns: |
| 68 | 92 | ||
| @@ -71,7 +95,7 @@ | |||
| 71 | ;; Nasty regexps of the form "bar\\(\\|lo\\)\\|f\\(oo\\|u\\(\\|bar\\)\\)\\|lo" | 95 | ;; Nasty regexps of the form "bar\\(\\|lo\\)\\|f\\(oo\\|u\\(\\|bar\\)\\)\\|lo" |
| 72 | ;; are made thusly: (make-regexp '("foo" "fu" "fubar" "bar" "barlo" "lo")) for | 96 | ;; are made thusly: (make-regexp '("foo" "fu" "fubar" "bar" "barlo" "lo")) for |
| 73 | ;; efficiency. See /pub/gnu/emacs/elisp-archive/functions/make-regexp.el.Z on | 97 | ;; efficiency. See /pub/gnu/emacs/elisp-archive/functions/make-regexp.el.Z on |
| 74 | ;; archive.cis.ohio-state.edu for this and other functions not just by simon. | 98 | ;; archive.cis.ohio-state.edu for this and other functions not just by sm. |
| 75 | 99 | ||
| 76 | ;;; Adding patterns for modes that already support Font Lock: | 100 | ;;; Adding patterns for modes that already support Font Lock: |
| 77 | 101 | ||
| @@ -275,8 +299,7 @@ MATCH-ANCHORED should be of the form: | |||
| 275 | 299 | ||
| 276 | (MATCHER PRE-MATCH-FORM POST-MATCH-FORM MATCH-HIGHLIGHT ...) | 300 | (MATCHER PRE-MATCH-FORM POST-MATCH-FORM MATCH-HIGHLIGHT ...) |
| 277 | 301 | ||
| 278 | Where MATCHER is as for MATCH-HIGHLIGHT with one exception. The limit of the | 302 | Where MATCHER is as for MATCH-HIGHLIGHT with one exception; see below. |
| 279 | search is currently guaranteed to be (no greater than) the end of the line. | ||
| 280 | PRE-MATCH-FORM and POST-MATCH-FORM are evaluated before the first, and after | 303 | PRE-MATCH-FORM and POST-MATCH-FORM are evaluated before the first, and after |
| 281 | the last, instance MATCH-ANCHORED's MATCHER is used. Therefore they can be | 304 | the last, instance MATCH-ANCHORED's MATCHER is used. Therefore they can be |
| 282 | used to initialise before, and cleanup after, MATCHER is used. Typically, | 305 | used to initialise before, and cleanup after, MATCHER is used. Typically, |
| @@ -295,6 +318,13 @@ For example, an element of the form highlights (if not already highlighted): | |||
| 295 | searching for subsequent instance of \"anchor\" resumes from where searching | 318 | searching for subsequent instance of \"anchor\" resumes from where searching |
| 296 | for \"item\" concluded.) | 319 | for \"item\" concluded.) |
| 297 | 320 | ||
| 321 | The above-mentioned exception is as follows. The limit of the MATCHER search | ||
| 322 | defaults to the end of the line after PRE-MATCH-FORM is evaluated. | ||
| 323 | However, if PRE-MATCH-FORM returns a position greater than the position after | ||
| 324 | PRE-MATCH-FORM is evaluated, that position is used as the limit of the search. | ||
| 325 | It is generally a bad idea to return a position greater than the end of the | ||
| 326 | line, i.e., cause the MATCHER search to span lines. | ||
| 327 | |||
| 298 | Note that the MATCH-ANCHORED feature is experimental; in the future, we may | 328 | Note that the MATCH-ANCHORED feature is experimental; in the future, we may |
| 299 | replace it with other ways of providing this functionality. | 329 | replace it with other ways of providing this functionality. |
| 300 | 330 | ||
| @@ -499,10 +529,6 @@ This is normally set via `font-lock-defaults'.") | |||
| 499 | ;; We don't do this at the top-level as we only use non-autoloaded macros. | 529 | ;; We don't do this at the top-level as we only use non-autoloaded macros. |
| 500 | (require 'cl) | 530 | (require 'cl) |
| 501 | ;; | 531 | ;; |
| 502 | ;; Shut the byte-compiler up. | ||
| 503 | (require 'fast-lock) | ||
| 504 | (require 'lazy-lock) | ||
| 505 | ;; | ||
| 506 | ;; Borrowed from lazy-lock.el. | 532 | ;; Borrowed from lazy-lock.el. |
| 507 | ;; We use this to preserve or protect things when modifying text properties. | 533 | ;; We use this to preserve or protect things when modifying text properties. |
| 508 | (defmacro save-buffer-state (varlist &rest body) | 534 | (defmacro save-buffer-state (varlist &rest body) |
| @@ -553,6 +579,10 @@ mode and use maximum levels of fontification, put in your ~/.emacs: | |||
| 553 | (setq font-lock-support-mode 'lazy-lock-mode) | 579 | (setq font-lock-support-mode 'lazy-lock-mode) |
| 554 | (setq font-lock-maximum-decoration t) | 580 | (setq font-lock-maximum-decoration t) |
| 555 | 581 | ||
| 582 | To add your own highlighting for some major mode, and modify the highlighting | ||
| 583 | selected automatically via the variable `font-lock-maximum-decoration', you can | ||
| 584 | use `font-lock-add-keywords'. | ||
| 585 | |||
| 556 | To fontify a buffer, without turning on Font Lock mode and regardless of buffer | 586 | To fontify a buffer, without turning on Font Lock mode and regardless of buffer |
| 557 | size, you can use \\[font-lock-fontify-buffer]. | 587 | size, you can use \\[font-lock-fontify-buffer]. |
| 558 | 588 | ||
| @@ -560,10 +590,6 @@ To fontify a block (the function or paragraph containing point, or a number of | |||
| 560 | lines around point), perhaps because modification on the current line caused | 590 | lines around point), perhaps because modification on the current line caused |
| 561 | syntactic change on other lines, you can use \\[font-lock-fontify-block]. | 591 | syntactic change on other lines, you can use \\[font-lock-fontify-block]. |
| 562 | 592 | ||
| 563 | The default Font Lock mode highlighting are normally selected via the variable | ||
| 564 | `font-lock-maximum-decoration'. You can add your own highlighting for some | ||
| 565 | mode, by calling `font-lock-add-keywords'. | ||
| 566 | |||
| 567 | The default Font Lock mode faces and their attributes are defined in the | 593 | The default Font Lock mode faces and their attributes are defined in the |
| 568 | variable `font-lock-face-attributes', and Font Lock mode default settings in | 594 | variable `font-lock-face-attributes', and Font Lock mode default settings in |
| 569 | the variable `font-lock-defaults-alist'. You can set your own default settings | 595 | the variable `font-lock-defaults-alist'. You can set your own default settings |
| @@ -605,8 +631,8 @@ its mode hook." | |||
| 605 | (defun turn-on-font-lock () | 631 | (defun turn-on-font-lock () |
| 606 | "Turn on Font Lock mode conditionally. | 632 | "Turn on Font Lock mode conditionally. |
| 607 | Turn on only if the terminal can display it." | 633 | Turn on only if the terminal can display it." |
| 608 | (when window-system | 634 | (when (and (not font-lock-mode) window-system) |
| 609 | (font-lock-mode t))) | 635 | (font-lock-mode))) |
| 610 | 636 | ||
| 611 | ;;;###autoload | 637 | ;;;###autoload |
| 612 | (defun font-lock-add-keywords (major-mode keywords &optional append) | 638 | (defun font-lock-add-keywords (major-mode keywords &optional append) |
| @@ -738,7 +764,7 @@ turned on in a buffer if its major mode is one of `font-lock-global-modes'." | |||
| 738 | (defun font-lock-change-major-mode () | 764 | (defun font-lock-change-major-mode () |
| 739 | ;; Turn off Font Lock mode if it's on. | 765 | ;; Turn off Font Lock mode if it's on. |
| 740 | (when font-lock-mode | 766 | (when font-lock-mode |
| 741 | (font-lock-mode nil)) | 767 | (font-lock-mode)) |
| 742 | ;; Gross hack warning: Delicate readers should avert eyes now. | 768 | ;; Gross hack warning: Delicate readers should avert eyes now. |
| 743 | ;; Something is running `kill-all-local-variables', which generally means the | 769 | ;; Something is running `kill-all-local-variables', which generally means the |
| 744 | ;; major mode is being changed. Run `turn-on-font-lock-if-enabled' after the | 770 | ;; major mode is being changed. Run `turn-on-font-lock-if-enabled' after the |
| @@ -826,6 +852,45 @@ The value of this variable is used when Font Lock mode is turned on.") | |||
| 826 | 852 | ||
| 827 | ;; Fontification functions. | 853 | ;; Fontification functions. |
| 828 | 854 | ||
| 855 | ;; Rather than the function, e.g., `font-lock-fontify-region' containing the | ||
| 856 | ;; code to fontify a region, the function runs the function whose name is the | ||
| 857 | ;; value of the variable, e.g., `font-lock-fontify-region-function'. Normally, | ||
| 858 | ;; the value of this variable is, e.g., `font-lock-default-fontify-region' | ||
| 859 | ;; which does contain the code to fontify a region. However, the value of the | ||
| 860 | ;; variable could be anything and thus, e.g., `font-lock-fontify-region' could | ||
| 861 | ;; do anything. The indirection of the fontification functions gives major | ||
| 862 | ;; modes the capability of modifying the way font-lock.el fontifies. Major | ||
| 863 | ;; modes can modify the values of, e.g., `font-lock-fontify-region-function', | ||
| 864 | ;; via the variable `font-lock-defaults'. | ||
| 865 | ;; | ||
| 866 | ;; For example, Rmail mode sets the variable `font-lock-defaults' so that | ||
| 867 | ;; font-lock.el uses its own function for buffer fontification. This function | ||
| 868 | ;; makes fontification be on a message-by-message basis and so visiting an | ||
| 869 | ;; RMAIL file is much faster. A clever implementation of the function might | ||
| 870 | ;; fontify the headers differently than the message body. (It should, and | ||
| 871 | ;; correspondingly for Mail mode, but I can't be bothered to do the work. Can | ||
| 872 | ;; you?) This hints at a more interesting use... | ||
| 873 | ;; | ||
| 874 | ;; Languages that contain text normally contained in different major modes | ||
| 875 | ;; could define their own fontification functions that treat text differently | ||
| 876 | ;; depending on its context. For example, Perl mode could arrange that here | ||
| 877 | ;; docs are fontified differently than Perl code. Or Yacc mode could fontify | ||
| 878 | ;; rules one way and C code another. Neat! | ||
| 879 | ;; | ||
| 880 | ;; A further reason to use the fontification indirection feature is when the | ||
| 881 | ;; default syntactual fontification, or the default fontification in general, | ||
| 882 | ;; is not flexible enough for a particular major mode. For example, perhaps | ||
| 883 | ;; comments are just too hairy for `font-lock-fontify-syntactically-region' and | ||
| 884 | ;; `font-lock-comment-start-regexp' to cope with. You need to write your own | ||
| 885 | ;; version of that function, e.g., `hairy-fontify-syntactically-region', and | ||
| 886 | ;; make your own version of `hairy-fontify-region' call it before calling | ||
| 887 | ;; `font-lock-fontify-keywords-region' for the normal regexp fontification | ||
| 888 | ;; pass. And Hairy mode would set `font-lock-defaults' so that font-lock.el | ||
| 889 | ;; would call your region fontification function instead of its own. For | ||
| 890 | ;; example, TeX modes could fontify {\foo ...} and \bar{...} etc. multi-line | ||
| 891 | ;; directives correctly and cleanly. (It is the same problem as fontifying | ||
| 892 | ;; multi-line strings and comments; regexps are not appropriate for the job.) | ||
| 893 | |||
| 829 | ;;;###autoload | 894 | ;;;###autoload |
| 830 | (defun font-lock-fontify-buffer () | 895 | (defun font-lock-fontify-buffer () |
| 831 | "Fontify the current buffer the way `font-lock-mode' would." | 896 | "Fontify the current buffer the way `font-lock-mode' would." |
| @@ -846,9 +911,11 @@ The value of this variable is used when Font Lock mode is turned on.") | |||
| 846 | (let ((verbose (if (numberp font-lock-verbose) | 911 | (let ((verbose (if (numberp font-lock-verbose) |
| 847 | (> (buffer-size) font-lock-verbose) | 912 | (> (buffer-size) font-lock-verbose) |
| 848 | font-lock-verbose))) | 913 | font-lock-verbose))) |
| 849 | (if verbose (message "Fontifying %s..." (buffer-name))) | 914 | (when verbose |
| 915 | (message "Fontifying %s..." (buffer-name))) | ||
| 850 | ;; Make sure we have the right `font-lock-keywords' etc. | 916 | ;; Make sure we have the right `font-lock-keywords' etc. |
| 851 | (if (not font-lock-mode) (font-lock-set-defaults)) | 917 | (unless font-lock-mode |
| 918 | (font-lock-set-defaults)) | ||
| 852 | ;; Make sure we fontify etc. in the whole buffer. | 919 | ;; Make sure we fontify etc. in the whole buffer. |
| 853 | (save-restriction | 920 | (save-restriction |
| 854 | (widen) | 921 | (widen) |
| @@ -860,10 +927,14 @@ The value of this variable is used when Font Lock mode is turned on.") | |||
| 860 | (setq font-lock-fontified t))) | 927 | (setq font-lock-fontified t))) |
| 861 | ;; We don't restore the old fontification, so it's best to unfontify. | 928 | ;; We don't restore the old fontification, so it's best to unfontify. |
| 862 | (quit (font-lock-unfontify-buffer)))) | 929 | (quit (font-lock-unfontify-buffer)))) |
| 930 | ;; Make sure we undo `font-lock-keywords' etc. | ||
| 931 | (unless font-lock-mode | ||
| 932 | (font-lock-unset-defaults)) | ||
| 863 | (if verbose (message "Fontifying %s...%s" (buffer-name) | 933 | (if verbose (message "Fontifying %s...%s" (buffer-name) |
| 864 | (if font-lock-fontified "done" "quit"))))) | 934 | (if font-lock-fontified "done" "quit"))))) |
| 865 | 935 | ||
| 866 | (defun font-lock-default-unfontify-buffer () | 936 | (defun font-lock-default-unfontify-buffer () |
| 937 | ;; Make sure we unfontify etc. in the whole buffer. | ||
| 867 | (save-restriction | 938 | (save-restriction |
| 868 | (widen) | 939 | (widen) |
| 869 | (font-lock-unfontify-region (point-min) (point-max)) | 940 | (font-lock-unfontify-region (point-min) (point-max)) |
| @@ -1154,12 +1225,15 @@ HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'." | |||
| 1154 | 1225 | ||
| 1155 | (defsubst font-lock-fontify-anchored-keywords (keywords limit) | 1226 | (defsubst font-lock-fontify-anchored-keywords (keywords limit) |
| 1156 | "Fontify according to KEYWORDS until LIMIT. | 1227 | "Fontify according to KEYWORDS until LIMIT. |
| 1157 | KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords'." | 1228 | KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords', |
| 1158 | (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights) | 1229 | LIMIT can be modified by the value of its PRE-MATCH-FORM." |
| 1159 | ;; Until we come up with a cleaner solution, we make LIMIT the end of line. | 1230 | (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights |
| 1160 | (save-excursion (end-of-line) (setq limit (min limit (point)))) | 1231 | ;; Evaluate PRE-MATCH-FORM. |
| 1161 | ;; Evaluate PRE-MATCH-FORM. | 1232 | (pre-match-value (eval (nth 1 keywords)))) |
| 1162 | (eval (nth 1 keywords)) | 1233 | ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line. |
| 1234 | (if (and (numberp pre-match-value) (> pre-match-value (point))) | ||
| 1235 | (setq limit pre-match-value) | ||
| 1236 | (save-excursion (end-of-line) (setq limit (point)))) | ||
| 1163 | (save-match-data | 1237 | (save-match-data |
| 1164 | ;; Find an occurrence of `matcher' before `limit'. | 1238 | ;; Find an occurrence of `matcher' before `limit'. |
| 1165 | (while (if (stringp matcher) | 1239 | (while (if (stringp matcher) |
| @@ -1539,12 +1613,113 @@ the face is also set; its value is the face name." | |||
| 1539 | (set-face-underline-p face (nth 5 face-attributes))) | 1613 | (set-face-underline-p face (nth 5 face-attributes))) |
| 1540 | (set face face))) | 1614 | (set face face))) |
| 1541 | 1615 | ||
| 1616 | ;;; Menu support. | ||
| 1617 | |||
| 1618 | ;; This section of code is commented out because Emacs does not have real menu | ||
| 1619 | ;; buttons. (We can mimic them by putting "( ) " or "(X) " at the beginning of | ||
| 1620 | ;; the menu entry text, but with Xt it looks both ugly and embarrassingly | ||
| 1621 | ;; amateur.) If/When Emacs gets real menus buttons, put in menu-bar.el after | ||
| 1622 | ;; the entry for "Text Properties" something like: | ||
| 1623 | ;; | ||
| 1624 | ;; (define-key menu-bar-edit-menu [font-lock] | ||
| 1625 | ;; '("Syntax Highlighting" . font-lock-menu)) | ||
| 1626 | ;; | ||
| 1627 | ;; and remove a single ";" from the beginning of each line in the rest of this | ||
| 1628 | ;; section. Probably the mechanism for telling the menu code what are menu | ||
| 1629 | ;; buttons and when they are on or off needs tweaking. I have assumed that the | ||
| 1630 | ;; mechanism is via `menu-toggle' and `menu-selected' symbol properties. sm. | ||
| 1631 | |||
| 1632 | ;;;;###autoload | ||
| 1633 | ;(progn | ||
| 1634 | ; ;; Make the Font Lock menu. | ||
| 1635 | ; (defvar font-lock-menu (make-sparse-keymap "Syntax Highlighting")) | ||
| 1636 | ; ;; Add the menu items in reverse order. | ||
| 1637 | ; (define-key font-lock-menu [fontify-less] | ||
| 1638 | ; '("Less In Current Buffer" . font-lock-fontify-less)) | ||
| 1639 | ; (define-key font-lock-menu [fontify-more] | ||
| 1640 | ; '("More In Current Buffer" . font-lock-fontify-more)) | ||
| 1641 | ; (define-key font-lock-menu [font-lock-sep] | ||
| 1642 | ; '("--")) | ||
| 1643 | ; (define-key font-lock-menu [font-lock-mode] | ||
| 1644 | ; '("In Current Buffer" . font-lock-mode)) | ||
| 1645 | ; (define-key font-lock-menu [global-font-lock-mode] | ||
| 1646 | ; '("In All Buffers" . global-font-lock-mode))) | ||
| 1647 | ; | ||
| 1648 | ;;;;###autoload | ||
| 1649 | ;(progn | ||
| 1650 | ; ;; We put the appropriate `menu-enable' etc. symbol property values on when | ||
| 1651 | ; ;; font-lock.el is loaded, so we don't need to autoload the three variables. | ||
| 1652 | ; (put 'global-font-lock-mode 'menu-toggle t) | ||
| 1653 | ; (put 'font-lock-mode 'menu-toggle t) | ||
| 1654 | ; (put 'font-lock-fontify-more 'menu-enable '(identity)) | ||
| 1655 | ; (put 'font-lock-fontify-less 'menu-enable '(identity))) | ||
| 1656 | ; | ||
| 1657 | ;;; Put the appropriate symbol property values on now. See above. | ||
| 1658 | ;(put 'global-font-lock-mode 'menu-selected 'global-font-lock-mode)) | ||
| 1659 | ;(put 'font-lock-mode 'menu-selected 'font-lock-mode) | ||
| 1660 | ;(put 'font-lock-fontify-more 'menu-enable '(nth 2 font-lock-fontify-level)) | ||
| 1661 | ;(put 'font-lock-fontify-less 'menu-enable '(nth 1 font-lock-fontify-level)) | ||
| 1662 | ; | ||
| 1663 | ;(defvar font-lock-fontify-level nil) ; For less/more fontification. | ||
| 1664 | ; | ||
| 1665 | ;(defun font-lock-fontify-level (level) | ||
| 1666 | ; (let ((font-lock-maximum-decoration level)) | ||
| 1667 | ; (when font-lock-mode | ||
| 1668 | ; (font-lock-mode)) | ||
| 1669 | ; (font-lock-mode) | ||
| 1670 | ; (when font-lock-verbose | ||
| 1671 | ; (message "Fontifying %s... level %d" (buffer-name) level)))) | ||
| 1672 | ; | ||
| 1673 | ;(defun font-lock-fontify-less () | ||
| 1674 | ; "Fontify the current buffer with less decoration. | ||
| 1675 | ;See `font-lock-maximum-decoration'." | ||
| 1676 | ; (interactive) | ||
| 1677 | ; ;; Check in case we get called interactively. | ||
| 1678 | ; (if (nth 1 font-lock-fontify-level) | ||
| 1679 | ; (font-lock-fontify-level (1- (car font-lock-fontify-level))) | ||
| 1680 | ; (error "No less decoration"))) | ||
| 1681 | ; | ||
| 1682 | ;(defun font-lock-fontify-more () | ||
| 1683 | ; "Fontify the current buffer with more decoration. | ||
| 1684 | ;See `font-lock-maximum-decoration'." | ||
| 1685 | ; (interactive) | ||
| 1686 | ; ;; Check in case we get called interactively. | ||
| 1687 | ; (if (nth 2 font-lock-fontify-level) | ||
| 1688 | ; (font-lock-fontify-level (1+ (car font-lock-fontify-level))) | ||
| 1689 | ; (error "No more decoration"))) | ||
| 1690 | ; | ||
| 1691 | ;;; This should be called by `font-lock-set-defaults'. | ||
| 1692 | ;(defun font-lock-set-menu () | ||
| 1693 | ; ;; Activate less/more fontification entries if there are multiple levels for | ||
| 1694 | ; ;; the current buffer. Sets `font-lock-fontify-level' to be of the form | ||
| 1695 | ; ;; (CURRENT-LEVEL IS-LOWER-LEVEL-P IS-HIGHER-LEVEL-P) for menu activation. | ||
| 1696 | ; (let ((keywords (or (nth 0 font-lock-defaults) | ||
| 1697 | ; (nth 1 (assq major-mode font-lock-defaults-alist)))) | ||
| 1698 | ; (level (font-lock-value-in-major-mode font-lock-maximum-decoration))) | ||
| 1699 | ; (make-local-variable 'font-lock-fontify-level) | ||
| 1700 | ; (if (or (symbolp keywords) (= (length keywords) 1)) | ||
| 1701 | ; (font-lock-unset-menu) | ||
| 1702 | ; (cond ((eq level t) | ||
| 1703 | ; (setq level (1- (length keywords)))) | ||
| 1704 | ; ((or (null level) (zerop level)) | ||
| 1705 | ; ;; The default level is usually, but not necessarily, level 1. | ||
| 1706 | ; (setq level (- (length keywords) | ||
| 1707 | ; (length (member (eval (car keywords)) | ||
| 1708 | ; (mapcar 'eval (cdr keywords)))))))) | ||
| 1709 | ; (setq font-lock-fontify-level (list level (> level 1) | ||
| 1710 | ; (< level (1- (length keywords)))))))) | ||
| 1711 | ; | ||
| 1712 | ;;; This should be called by `font-lock-unset-defaults'. | ||
| 1713 | ;(defun font-lock-unset-menu () | ||
| 1714 | ; ;; Deactivate less/more fontification entries. | ||
| 1715 | ; (setq font-lock-fontify-level nil)) | ||
| 1716 | |||
| 1542 | ;;; Various regexp information shared by several modes. | 1717 | ;;; Various regexp information shared by several modes. |
| 1543 | ;;; Information specific to a single mode should go in its load library. | 1718 | ;;; Information specific to a single mode should go in its load library. |
| 1544 | 1719 | ||
| 1545 | ;; Font Lock support for C, C++, Objective-C and Java modes will one day be in | 1720 | ;; Font Lock support for C, C++, Objective-C and Java modes will one day be in |
| 1546 | ;; cc-font.el (and required by cc-mode.el). However, the below function should | 1721 | ;; some cc-font.el (and required by cc-mode.el). However, the below function |
| 1547 | ;; stay in font-lock.el, since it is used by other libraries. sm. | 1722 | ;; should stay in font-lock.el, since it is used by other libraries. sm. |
| 1548 | 1723 | ||
| 1549 | (defun font-lock-match-c-style-declaration-item-and-skip-to-next (limit) | 1724 | (defun font-lock-match-c-style-declaration-item-and-skip-to-next (limit) |
| 1550 | "Match, and move over, any declaration/definition item after point. | 1725 | "Match, and move over, any declaration/definition item after point. |
| @@ -1586,9 +1761,9 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item." | |||
| 1586 | ;; about five times slower. | 1761 | ;; about five times slower. |
| 1587 | (list (concat "^(\\(def\\(" | 1762 | (list (concat "^(\\(def\\(" |
| 1588 | ;; Variable declarations. | 1763 | ;; Variable declarations. |
| 1589 | "\\(const\\|custom\\|var\\)\\|" | 1764 | "\\(const\\|custom\\|face\\|var\\)\\|" |
| 1590 | ;; Structure declarations. | 1765 | ;; Structure declarations. |
| 1591 | "\\(class\\|struct\\|type\\)\\|" | 1766 | "\\(class\\|group\\|struct\\|type\\)\\|" |
| 1592 | ;; Everything else is a function declaration. | 1767 | ;; Everything else is a function declaration. |
| 1593 | "\\sw+" | 1768 | "\\sw+" |
| 1594 | "\\)\\)\\>" | 1769 | "\\)\\)\\>" |
| @@ -1601,7 +1776,7 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item." | |||
| 1601 | (t font-lock-function-name-face)) | 1776 | (t font-lock-function-name-face)) |
| 1602 | nil t)) | 1777 | nil t)) |
| 1603 | )) | 1778 | )) |
| 1604 | "Subdued level highlighting for Lisp modes.") | 1779 | "Subdued level highlighting for Lisp modes.") |
| 1605 | 1780 | ||
| 1606 | (defconst lisp-font-lock-keywords-2 | 1781 | (defconst lisp-font-lock-keywords-2 |
| 1607 | (append lisp-font-lock-keywords-1 | 1782 | (append lisp-font-lock-keywords-1 |
| @@ -1855,7 +2030,7 @@ See also `c-font-lock-extra-types'.") | |||
| 1855 | (concat "\\<\\(" c-keywords "\\)\\>") | 2030 | (concat "\\<\\(" c-keywords "\\)\\>") |
| 1856 | ;; | 2031 | ;; |
| 1857 | ;; Fontify case/goto keywords and targets, and case default/goto tags. | 2032 | ;; Fontify case/goto keywords and targets, and case default/goto tags. |
| 1858 | '("\\<\\(case\\|goto\\)\\>[ \t]*\\(\\sw+\\)?" | 2033 | '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" |
| 1859 | (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) | 2034 | (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) |
| 1860 | ;; Anders Lindgren <andersl@csd.uu.se> points out that it is quicker to use | 2035 | ;; Anders Lindgren <andersl@csd.uu.se> points out that it is quicker to use |
| 1861 | ;; MATCH-ANCHORED to effectively anchor the regexp on the left. | 2036 | ;; MATCH-ANCHORED to effectively anchor the regexp on the left. |
| @@ -2030,7 +2205,7 @@ See also `c++-font-lock-extra-types'.") | |||
| 2030 | '(2 font-lock-builtin-face nil t)) | 2205 | '(2 font-lock-builtin-face nil t)) |
| 2031 | ;; | 2206 | ;; |
| 2032 | ;; Fontify case/goto keywords and targets, and case default/goto tags. | 2207 | ;; Fontify case/goto keywords and targets, and case default/goto tags. |
| 2033 | '("\\<\\(case\\|goto\\)\\>[ \t]*\\(\\sw+\\)?" | 2208 | '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" |
| 2034 | (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) | 2209 | (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) |
| 2035 | '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:\\($\\|[^:]\\)" | 2210 | '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:\\($\\|[^:]\\)" |
| 2036 | (beginning-of-line) (end-of-line) | 2211 | (beginning-of-line) (end-of-line) |
| @@ -2181,7 +2356,7 @@ See also `objc-font-lock-extra-types'.") | |||
| 2181 | (concat "\\<\\(" objc-keywords "\\)\\>") | 2356 | (concat "\\<\\(" objc-keywords "\\)\\>") |
| 2182 | ;; | 2357 | ;; |
| 2183 | ;; Fontify case/goto keywords and targets, and case default/goto tags. | 2358 | ;; Fontify case/goto keywords and targets, and case default/goto tags. |
| 2184 | '("\\<\\(case\\|goto\\)\\>[ \t]*\\(\\sw+\\)?" | 2359 | '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" |
| 2185 | (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) | 2360 | (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) |
| 2186 | ;; Fontify tags iff sole statement on line, otherwise we detect selectors. | 2361 | ;; Fontify tags iff sole statement on line, otherwise we detect selectors. |
| 2187 | '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*$" | 2362 | '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*$" |
| @@ -2311,7 +2486,7 @@ See also `java-font-lock-extra-types'.") | |||
| 2311 | (concat "\\<\\(" java-keywords "\\)\\>") | 2486 | (concat "\\<\\(" java-keywords "\\)\\>") |
| 2312 | ;; | 2487 | ;; |
| 2313 | ;; Fontify keywords and targets, and case default/goto tags. | 2488 | ;; Fontify keywords and targets, and case default/goto tags. |
| 2314 | (list "\\<\\(break\\|case\\|continue\\|goto\\)\\>[ \t]*\\(\\sw+\\)?" | 2489 | (list "\\<\\(break\\|case\\|continue\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" |
| 2315 | '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t)) | 2490 | '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t)) |
| 2316 | '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:" | 2491 | '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:" |
| 2317 | (beginning-of-line) (end-of-line) | 2492 | (beginning-of-line) (end-of-line) |