diff options
| author | Simon Marshall | 1999-02-17 10:06:41 +0000 |
|---|---|---|
| committer | Simon Marshall | 1999-02-17 10:06:41 +0000 |
| commit | 68c67d1f821a97908b5cd1f12246ddc11fa1cdcb (patch) | |
| tree | f9a2ef0202f82ba61ce31b3e1cc647e24ed79d18 | |
| parent | abb7e5cfc32f1895ebe99ca5ee1b157cf74312d0 (diff) | |
| download | emacs-68c67d1f821a97908b5cd1f12246ddc11fa1cdcb.tar.gz emacs-68c67d1f821a97908b5cd1f12246ddc11fa1cdcb.zip | |
* font-lock.el (c++-font-lock-keywords-3): Use c-at-toplevel-p to distinguish
correctly an object declared via a constructor from a method.
(font-lock-defaults-alist): Don't give `.' word syntax for Java.
(java-font-lock-keywords-1): Fontify package names individually.
(java-font-lock-extra-types): Ensure regexp matches capitalised types only.
(java-font-lock-keywords-2): Simplify type fontification.
(java-font-lock-keywords-3): Likewise.
| -rw-r--r-- | lisp/font-lock.el | 115 |
1 files changed, 44 insertions, 71 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el index 7dbe8d08d9c..7801a55d07a 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; font-lock.el --- Electric font lock mode | 1 | ;;; font-lock.el --- Electric font lock mode |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1992, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1992-1999 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: jwz, then rms, then sm <simon@gnu.org> | 5 | ;; Author: jwz, then rms, then sm <simon@gnu.org> |
| 6 | ;; Maintainer: FSF | 6 | ;; Maintainer: FSF |
| @@ -458,7 +458,7 @@ and those for buffer-specialised fontification functions, | |||
| 458 | (java-mode-defaults | 458 | (java-mode-defaults |
| 459 | '((java-font-lock-keywords java-font-lock-keywords-1 | 459 | '((java-font-lock-keywords java-font-lock-keywords-1 |
| 460 | java-font-lock-keywords-2 java-font-lock-keywords-3) | 460 | java-font-lock-keywords-2 java-font-lock-keywords-3) |
| 461 | nil nil ((?_ . "w") (?$ . "w") (?. . "w")) nil | 461 | nil nil ((?_ . "w") (?$ . "w")) nil |
| 462 | (font-lock-mark-block-function . mark-defun))) | 462 | (font-lock-mark-block-function . mark-defun))) |
| 463 | (lisp-mode-defaults | 463 | (lisp-mode-defaults |
| 464 | '((lisp-font-lock-keywords | 464 | '((lisp-font-lock-keywords |
| @@ -1553,8 +1553,7 @@ Sets various variables using `font-lock-defaults' (or, if nil, using | |||
| 1553 | (mapcar 'identity (car (car slist))))) | 1553 | (mapcar 'identity (car (car slist))))) |
| 1554 | (syntax (cdr (car slist)))) | 1554 | (syntax (cdr (car slist)))) |
| 1555 | (while chars | 1555 | (while chars |
| 1556 | (modify-syntax-entry (car chars) syntax | 1556 | (modify-syntax-entry (car chars) syntax font-lock-syntax-table) |
| 1557 | font-lock-syntax-table) | ||
| 1558 | (setq chars (cdr chars))) | 1557 | (setq chars (cdr chars))) |
| 1559 | (setq slist (cdr slist)))))) | 1558 | (setq slist (cdr slist)))))) |
| 1560 | ;; Syntax function for syntactic fontification? | 1559 | ;; Syntax function for syntactic fontification? |
| @@ -2200,10 +2199,11 @@ The value of this variable is used when Font Lock mode is turned on." | |||
| 2200 | :type 'font-lock-extra-types-widget | 2199 | :type 'font-lock-extra-types-widget |
| 2201 | :group 'font-lock-extra-types) | 2200 | :group 'font-lock-extra-types) |
| 2202 | 2201 | ||
| 2203 | (defcustom java-font-lock-extra-types '("[A-Z\300-\326\330-\337]\\sw+") | 2202 | (defcustom java-font-lock-extra-types |
| 2203 | '("[A-Z\300-\326\330-\337]\\sw*[a-z]\\sw*") | ||
| 2204 | "*List of extra types to fontify in Java mode. | 2204 | "*List of extra types to fontify in Java mode. |
| 2205 | Each list item should be a regexp not containing word-delimiters. | 2205 | Each list item should be a regexp not containing word-delimiters. |
| 2206 | For example, a value of (\"[A-Z\300-\326\330-\337]\\\\sw+\") means capitalised | 2206 | For example, a value of (\"[A-Z\300-\326\330-\337]\\\\sw*[a-z]\\\\sw*\") means capitalised |
| 2207 | words (and words conforming to the Java id spec) are treated as type names. | 2207 | words (and words conforming to the Java id spec) are treated as type names. |
| 2208 | 2208 | ||
| 2209 | The value of this variable is used when Font Lock mode is turned on." | 2209 | The value of this variable is used when Font Lock mode is turned on." |
| @@ -2306,8 +2306,8 @@ See also `c-font-lock-extra-types'.") | |||
| 2306 | ;; Fontify case/goto keywords and targets, and case default/goto tags. | 2306 | ;; Fontify case/goto keywords and targets, and case default/goto tags. |
| 2307 | '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" | 2307 | '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" |
| 2308 | (1 font-lock-keyword-face) (2 font-lock-constant-face nil t)) | 2308 | (1 font-lock-keyword-face) (2 font-lock-constant-face nil t)) |
| 2309 | ;; Anders Lindgren <andersl@csd.uu.se> points out that it is quicker to use | 2309 | ;; Anders Lindgren <andersl@andersl.com> points out that it is quicker to |
| 2310 | ;; MATCH-ANCHORED to effectively anchor the regexp on the left. | 2310 | ;; use MATCH-ANCHORED to effectively anchor the regexp on the left. |
| 2311 | ;; This must come after the one for keywords and targets. | 2311 | ;; This must come after the one for keywords and targets. |
| 2312 | '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:" | 2312 | '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:" |
| 2313 | (beginning-of-line) (end-of-line) | 2313 | (beginning-of-line) (end-of-line) |
| @@ -2541,8 +2541,10 @@ See also `c++-font-lock-extra-types'.") | |||
| 2541 | ;; Fontify as a variable or function name. | 2541 | ;; Fontify as a variable or function name. |
| 2542 | '(1 (cond ((or (match-beginning 2) (match-beginning 4)) | 2542 | '(1 (cond ((or (match-beginning 2) (match-beginning 4)) |
| 2543 | font-lock-type-face) | 2543 | font-lock-type-face) |
| 2544 | ((match-beginning 6) font-lock-function-name-face) | 2544 | ((and (match-beginning 6) (c-at-toplevel-p)) |
| 2545 | (t font-lock-variable-name-face))) | 2545 | font-lock-function-name-face) |
| 2546 | (t | ||
| 2547 | font-lock-variable-name-face))) | ||
| 2546 | '(3 font-lock-type-face nil t) | 2548 | '(3 font-lock-type-face nil t) |
| 2547 | '(5 (if (match-beginning 6) | 2549 | '(5 (if (match-beginning 6) |
| 2548 | font-lock-function-name-face | 2550 | font-lock-function-name-face |
| @@ -2566,8 +2568,10 @@ See also `c++-font-lock-extra-types'.") | |||
| 2566 | ;; Fontify as a variable or function name. | 2568 | ;; Fontify as a variable or function name. |
| 2567 | '(1 (cond ((or (match-beginning 2) (match-beginning 4)) | 2569 | '(1 (cond ((or (match-beginning 2) (match-beginning 4)) |
| 2568 | font-lock-type-face) | 2570 | font-lock-type-face) |
| 2569 | ((match-beginning 6) font-lock-function-name-face) | 2571 | ((and (match-beginning 6) (c-at-toplevel-p)) |
| 2570 | (t font-lock-variable-name-face))) | 2572 | font-lock-function-name-face) |
| 2573 | (t | ||
| 2574 | font-lock-variable-name-face))) | ||
| 2571 | '(3 font-lock-type-face nil t) | 2575 | '(3 font-lock-type-face nil t) |
| 2572 | '(5 (if (match-beginning 6) | 2576 | '(5 (if (match-beginning 6) |
| 2573 | font-lock-function-name-face | 2577 | font-lock-function-name-face |
| @@ -2772,37 +2776,36 @@ See also `java-font-lock-extra-types'.") | |||
| 2772 | See also `java-font-lock-extra-types'.") | 2776 | See also `java-font-lock-extra-types'.") |
| 2773 | 2777 | ||
| 2774 | ;; Regexps written with help from Fred White <fwhite@bbn.com> and | 2778 | ;; Regexps written with help from Fred White <fwhite@bbn.com> and |
| 2775 | ;; Anders Lindgren <andersl@csd.uu.se>. | 2779 | ;; Anders Lindgren <andersl@andersl.com>. |
| 2776 | (let* ((java-keywords | 2780 | (let* ((java-keywords |
| 2777 | (eval-when-compile | 2781 | (eval-when-compile |
| 2778 | (regexp-opt | 2782 | (regexp-opt |
| 2779 | '("catch" "do" "else" "super" "this" "finally" "for" "if" | 2783 | '("catch" "do" "else" "super" "this" "finally" "for" "if" |
| 2780 | ;; Anders Lindgren <andersl@csd.uu.se> says these have gone. | 2784 | ;; Anders Lindgren <andersl@andersl.com> says these have gone. |
| 2781 | ;; "cast" "byvalue" "future" "generic" "operator" "var" | 2785 | ;; "cast" "byvalue" "future" "generic" "operator" "var" |
| 2782 | ;; "inner" "outer" "rest" | 2786 | ;; "inner" "outer" "rest" |
| 2787 | "implements" "extends" "throws" "instanceof" "new" | ||
| 2783 | "interface" "return" "switch" "throw" "try" "while") t))) | 2788 | "interface" "return" "switch" "throw" "try" "while") t))) |
| 2784 | ;; | 2789 | ;; |
| 2785 | ;; These are immediately followed by an object name. | 2790 | ;; Classes immediately followed by an object name. |
| 2786 | (java-minor-types | 2791 | (java-type-names |
| 2787 | (eval-when-compile | 2792 | `(mapconcat 'identity |
| 2788 | (regexp-opt '("boolean" "char" "byte" "short" "int" "long" | 2793 | (cons |
| 2789 | "float" "double" "void")))) | 2794 | (,@ (eval-when-compile |
| 2795 | (regexp-opt '("boolean" "char" "byte" "short" "int" "long" | ||
| 2796 | "float" "double" "void")))) | ||
| 2797 | java-font-lock-extra-types) | ||
| 2798 | "\\|")) | ||
| 2799 | (java-type-names-depth `(regexp-opt-depth (,@ java-type-names))) | ||
| 2790 | ;; | 2800 | ;; |
| 2791 | ;; These are eventually followed by an object name. | 2801 | ;; These are eventually followed by an object name. |
| 2792 | (java-major-types | 2802 | (java-type-specs |
| 2793 | (eval-when-compile | 2803 | (eval-when-compile |
| 2794 | (regexp-opt | 2804 | (regexp-opt |
| 2795 | '("abstract" "const" "final" "synchronized" "transient" "static" | 2805 | '("abstract" "const" "final" "synchronized" "transient" "static" |
| 2796 | ;; Anders Lindgren <andersl@csd.uu.se> says this has gone. | 2806 | ;; Anders Lindgren <andersl@andersl.com> says this has gone. |
| 2797 | ;; "threadsafe" | 2807 | ;; "threadsafe" |
| 2798 | "volatile" "public" "private" "protected" "native")))) | 2808 | "volatile" "public" "private" "protected" "native")))) |
| 2799 | ;; | ||
| 2800 | ;; Random types immediately followed by an object name. | ||
| 2801 | (java-other-types | ||
| 2802 | '(mapconcat 'identity (cons "\\sw+\\.\\sw+" java-font-lock-extra-types) | ||
| 2803 | "\\|")) | ||
| 2804 | (java-other-depth | ||
| 2805 | `(regexp-opt-depth (,@ java-other-types))) | ||
| 2806 | ) | 2809 | ) |
| 2807 | (setq java-font-lock-keywords-1 | 2810 | (setq java-font-lock-keywords-1 |
| 2808 | (list | 2811 | (list |
| @@ -2813,18 +2816,23 @@ See also `java-font-lock-extra-types'.") | |||
| 2813 | ;; | 2816 | ;; |
| 2814 | ;; Fontify package names in import directives. | 2817 | ;; Fontify package names in import directives. |
| 2815 | '("\\<\\(import\\|package\\)\\>[ \t]*\\(\\sw+\\)?" | 2818 | '("\\<\\(import\\|package\\)\\>[ \t]*\\(\\sw+\\)?" |
| 2816 | (1 font-lock-keyword-face) (2 font-lock-constant-face nil t)) | 2819 | (1 font-lock-keyword-face) |
| 2820 | (2 font-lock-constant-face nil t) | ||
| 2821 | ("\\=\\.\\(\\*\\|\\sw+\\)" nil nil | ||
| 2822 | (1 font-lock-constant-face nil t))) | ||
| 2817 | )) | 2823 | )) |
| 2818 | 2824 | ||
| 2819 | (setq java-font-lock-keywords-2 | 2825 | (setq java-font-lock-keywords-2 |
| 2820 | (append java-font-lock-keywords-1 | 2826 | (append java-font-lock-keywords-1 |
| 2821 | (list | 2827 | (list |
| 2822 | ;; | 2828 | ;; |
| 2823 | ;; Fontify all builtin type specifiers. | 2829 | ;; Fontify class names. |
| 2824 | (cons (concat "\\<\\(" java-minor-types "\\)\\>") 'font-lock-type-face) | 2830 | `(eval . |
| 2831 | (cons (concat "\\<\\(" (,@ java-type-names) "\\)\\>") | ||
| 2832 | 'font-lock-type-face)) | ||
| 2825 | ;; | 2833 | ;; |
| 2826 | ;; Fontify all builtin keywords (except below). | 2834 | ;; Fontify all builtin keywords (except below). |
| 2827 | (concat "\\<\\(" java-keywords "\\|" java-major-types "\\)\\>") | 2835 | (concat "\\<\\(" java-keywords "\\|" java-type-specs "\\)\\>") |
| 2828 | ;; | 2836 | ;; |
| 2829 | ;; Fontify keywords and targets, and case default/goto tags. | 2837 | ;; Fontify keywords and targets, and case default/goto tags. |
| 2830 | (list "\\<\\(break\\|case\\|continue\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" | 2838 | (list "\\<\\(break\\|case\\|continue\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" |
| @@ -2834,16 +2842,6 @@ See also `java-font-lock-extra-types'.") | |||
| 2834 | (beginning-of-line) (end-of-line) | 2842 | (beginning-of-line) (end-of-line) |
| 2835 | (1 font-lock-constant-face))) | 2843 | (1 font-lock-constant-face))) |
| 2836 | ;; | 2844 | ;; |
| 2837 | ;; Fontify keywords and types; the first can be followed by a type list. | ||
| 2838 | (list (concat "\\<\\(" | ||
| 2839 | "implements\\|throws\\|" | ||
| 2840 | "\\(extends\\|instanceof\\|new\\)" | ||
| 2841 | "\\)\\>[ \t]*\\(\\sw+\\)?") | ||
| 2842 | '(1 font-lock-keyword-face) '(3 font-lock-type-face nil t) | ||
| 2843 | '("\\=[ \t]*,[ \t]*\\(\\sw+\\)" | ||
| 2844 | (if (match-beginning 2) (goto-char (match-end 2))) nil | ||
| 2845 | (1 font-lock-type-face))) | ||
| 2846 | ;; | ||
| 2847 | ;; Fontify all constants. | 2845 | ;; Fontify all constants. |
| 2848 | '("\\<\\(false\\|null\\|true\\)\\>" . font-lock-constant-face) | 2846 | '("\\<\\(false\\|null\\|true\\)\\>" . font-lock-constant-face) |
| 2849 | ;; | 2847 | ;; |
| @@ -2862,50 +2860,25 @@ See also `java-font-lock-extra-types'.") | |||
| 2862 | ;; We still have to fontify type specifiers individually, as Java is hairy. | 2860 | ;; We still have to fontify type specifiers individually, as Java is hairy. |
| 2863 | (list | 2861 | (list |
| 2864 | ;; | 2862 | ;; |
| 2865 | ;; Fontify random types in casts. | ||
| 2866 | `(eval . | ||
| 2867 | (list (concat "(\\(" (,@ java-other-types) "\\))" | ||
| 2868 | "[ \t]*\\(\\sw\\|[\"\(]\\)") | ||
| 2869 | ;; Fontify the type name. | ||
| 2870 | '(1 font-lock-type-face))) | ||
| 2871 | ;; | ||
| 2872 | ;; Fontify random types immediately followed by an item or items. | 2863 | ;; Fontify random types immediately followed by an item or items. |
| 2873 | `(eval . | 2864 | `(eval . |
| 2874 | (list (concat "\\<\\(" (,@ java-other-types) "\\)\\>" | 2865 | (list (concat "\\<\\(" (,@ java-type-names) "\\)\\>" |
| 2875 | "\\([ \t]*\\[[ \t]*\\]\\)*" | ||
| 2876 | "[ \t]*\\sw") | ||
| 2877 | ;; Fontify the type name. | ||
| 2878 | '(1 font-lock-type-face))) | ||
| 2879 | `(eval . | ||
| 2880 | (list (concat "\\<\\(" (,@ java-other-types) "\\)\\>" | ||
| 2881 | "\\([ \t]*\\[[ \t]*\\]\\)*" | 2866 | "\\([ \t]*\\[[ \t]*\\]\\)*" |
| 2882 | "\\([ \t]*\\sw\\)") | 2867 | "\\([ \t]*\\sw\\)") |
| 2883 | ;; Fontify each declaration item. | 2868 | ;; Fontify each declaration item. |
| 2884 | (list 'font-lock-match-c-style-declaration-item-and-skip-to-next | 2869 | (list 'font-lock-match-c-style-declaration-item-and-skip-to-next |
| 2885 | ;; Start and finish with point after the type specifier. | 2870 | ;; Start and finish with point after the type specifier. |
| 2886 | (list 'goto-char (list 'match-beginning | 2871 | (list 'goto-char (list 'match-beginning |
| 2887 | (+ (,@ java-other-depth) 3))) | 2872 | (+ (,@ java-type-names-depth) 3))) |
| 2888 | (list 'goto-char (list 'match-beginning | 2873 | (list 'goto-char (list 'match-beginning |
| 2889 | (+ (,@ java-other-depth) 3))) | 2874 | (+ (,@ java-type-names-depth) 3))) |
| 2890 | ;; Fontify as a variable or function name. | 2875 | ;; Fontify as a variable or function name. |
| 2891 | '(1 (if (match-beginning 2) | 2876 | '(1 (if (match-beginning 2) |
| 2892 | font-lock-function-name-face | 2877 | font-lock-function-name-face |
| 2893 | font-lock-variable-name-face))))) | 2878 | font-lock-variable-name-face))))) |
| 2894 | ;; | 2879 | ;; |
| 2895 | ;; Fontify those that are immediately followed by an item or items. | ||
| 2896 | (list (concat "\\<\\(" java-minor-types "\\)\\>" | ||
| 2897 | "\\([ \t]*\\[[ \t]*\\]\\)*") | ||
| 2898 | ;; Fontify each declaration item. | ||
| 2899 | '(font-lock-match-c-style-declaration-item-and-skip-to-next | ||
| 2900 | ;; Start and finish with point after the type specifier. | ||
| 2901 | nil (goto-char (match-end 0)) | ||
| 2902 | ;; Fontify as a variable or function name. | ||
| 2903 | (1 (if (match-beginning 2) | ||
| 2904 | font-lock-function-name-face | ||
| 2905 | font-lock-variable-name-face)))) | ||
| 2906 | ;; | ||
| 2907 | ;; Fontify those that are eventually followed by an item or items. | 2880 | ;; Fontify those that are eventually followed by an item or items. |
| 2908 | (list (concat "\\<\\(" java-major-types "\\)\\>" | 2881 | (list (concat "\\<\\(" java-type-specs "\\)\\>" |
| 2909 | "\\([ \t]+\\sw+\\>" | 2882 | "\\([ \t]+\\sw+\\>" |
| 2910 | "\\([ \t]*\\[[ \t]*\\]\\)*" | 2883 | "\\([ \t]*\\[[ \t]*\\]\\)*" |
| 2911 | "\\)*") | 2884 | "\\)*") |