Mercurial > hg > xemacs-beta
comparison lisp/packages/font-lock.el @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | 56c54cf7c5b6 |
children | c0c698873ce1 |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
3 ;; Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. |
4 ;; Copyright (C) 1995 Amdahl Corporation. | 4 ;; Copyright (C) 1995 Amdahl Corporation. |
5 ;; Copyright (C) 1996 Ben Wing. | 5 ;; Copyright (C) 1996 Ben Wing. |
6 | 6 |
7 ;; Author: Jamie Zawinski <jwz@lucid.com>, for the LISPM Preservation Society. | 7 ;; Author: Jamie Zawinski <jwz@lucid.com>, for the LISPM Preservation Society. |
8 ;; Minimally merged with FSF 19.34 by Barry Warsaw <bwarsaw@python.org> | |
9 ;; Then (partially) synched with FSF 19.30, leading to: | 8 ;; Then (partially) synched with FSF 19.30, leading to: |
10 ;; Next Author: RMS | 9 ;; Next Author: RMS |
11 ;; Next Author: Simon Marshall <simon@gnu.ai.mit.edu> | 10 ;; Next Author: Simon Marshall <simon@gnu.ai.mit.edu> |
12 ;; Latest XEmacs Author: Ben Wing | 11 ;; Latest XEmacs Author: Ben Wing |
13 ;; Maintainer: FSF (well, maybe) | 12 ;; Maintainer: FSF (well, maybe) |
24 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | 23 ;; WITHOUT ANY WARRANTY; without even the implied warranty of |
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
26 ;; General Public License for more details. | 25 ;; General Public License for more details. |
27 | 26 |
28 ;; You should have received a copy of the GNU General Public License | 27 ;; You should have received a copy of the GNU General Public License |
29 ;; along with XEmacs; see the file COPYING. If not, write to the Free | 28 ;; along with XEmacs; see the file COPYING. If not, write to the |
30 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, | 29 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
31 ;; Boston, MA 02111-1307, USA. | 30 ;; Boston, MA 02111-1307, USA. |
32 | 31 |
33 ;;; Synched up with: FSF 19.30 except for the code to initialize the faces. | 32 ;;; Synched up with: FSF 19.30 except for the code to initialize the faces. |
34 | 33 |
35 ;;; Commentary: | 34 ;;; Commentary: |
75 ;; | 74 ;; |
76 ;; The same is true of `c-font-lock-keywords-1' and `c-font-lock-keywords-2'; | 75 ;; The same is true of `c-font-lock-keywords-1' and `c-font-lock-keywords-2'; |
77 ;; the former is subdued, the latter is loud. | 76 ;; the former is subdued, the latter is loud. |
78 ;; | 77 ;; |
79 ;; You can make font-lock default to the gaudier variety of keyword | 78 ;; You can make font-lock default to the gaudier variety of keyword |
80 ;; highlighting by setting the variable `font-lock-maximum-decoration' | 79 ;; highlighting by setting the variable `font-lock-use-maximal-decoration' |
81 ;; before loading font-lock, or by calling the functions | 80 ;; before loading font-lock, or by calling the functions |
82 ;; `font-lock-use-default-maximal-decoration' or | 81 ;; `font-lock-use-default-maximal-decoration' or |
83 ;; `font-lock-use-default-minimal-decoration'. | 82 ;; `font-lock-use-default-minimal-decoration'. |
84 ;; | 83 ;; |
85 ;; On a Sparc10, the initial fontification takes about 6 seconds for a typical | 84 ;; On a Sparc10, the initial fontification takes about 6 seconds for a typical |
139 ;; - Err, that's it. | 138 ;; - Err, that's it. |
140 | 139 |
141 | 140 |
142 ;;; Code: | 141 ;;; Code: |
143 | 142 |
144 (require 'fontl-hooks) | |
145 | |
146 ;;;;;;;;;;;;;;;;;;;;;; user variables ;;;;;;;;;;;;;;;;;;;;;; | 143 ;;;;;;;;;;;;;;;;;;;;;; user variables ;;;;;;;;;;;;;;;;;;;;;; |
147 | 144 |
148 (defvar font-lock-verbose t | 145 (defvar font-lock-verbose t |
149 "*If non-nil, means show status messages when fontifying. | 146 "*If non-nil, means show status messages when fontifying. |
150 See also `font-lock-message-threshold'.") | 147 See also `font-lock-message-threshold'.") |
262 MATCHER | 259 MATCHER |
263 (MATCHER . MATCH) | 260 (MATCHER . MATCH) |
264 (MATCHER . FACENAME) | 261 (MATCHER . FACENAME) |
265 (MATCHER . HIGHLIGHT) | 262 (MATCHER . HIGHLIGHT) |
266 (MATCHER HIGHLIGHT ...) | 263 (MATCHER HIGHLIGHT ...) |
267 (eval . FORM) | |
268 | 264 |
269 where HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED. | 265 where HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED. |
270 | 266 |
271 FORM is an expression, whose value should be a keyword element, | |
272 evaluated when the keyword is (first) used in a buffer. This feature | |
273 can be used to provide a keyword that can only be generated when Font | |
274 Lock mode is actually turned on. | |
275 | |
276 For highlighting single items, typically only MATCH-HIGHLIGHT is required. | 267 For highlighting single items, typically only MATCH-HIGHLIGHT is required. |
277 However, if an item or (typically) items is to be highlighted following the | 268 However, if an item or (typically) items is to be hightlighted following the |
278 instance of another item (the anchor) then MATCH-ANCHORED may be required. | 269 instance of another item (the anchor) then MATCH-ANCHORED may be required. |
279 | 270 |
280 MATCH-HIGHLIGHT should be of the form: | 271 MATCH-HIGHLIGHT should be of the form: |
281 | 272 |
282 (MATCH FACENAME OVERRIDE LAXMATCH) | 273 (MATCH FACENAME OVERRIDE LAXMATCH) |
283 | 274 |
284 Where MATCHER can be either the regexp to search for, a variable | 275 Where MATCHER can be either the regexp to search for, or the function name to |
285 containing the regexp to search for, or the function to call to make | 276 call to make the search (called with one argument, the limit of the search). |
286 the search (called with one argument, the limit of the search). MATCH | 277 MATCH is the subexpression of MATCHER to be highlighted. FACENAME is either |
287 is the subexpression of MATCHER to be highlighted. FACENAME is either | 278 a symbol naming a face, or an expression whose value is the face name to use. |
288 a symbol naming a face, or an expression whose value is the face name | 279 If you want FACENAME to be a symbol that evaluates to a face, use a form |
289 to use. If you want FACENAME to be a symbol that evaluates to a face, | 280 like \"(progn sym)\". |
290 use a form like \"(progn sym)\". | |
291 | 281 |
292 OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification may | 282 OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification may |
293 be overwritten. If `keep', only parts not already fontified are highlighted. | 283 be overwritten. If `keep', only parts not already fontified are highlighted. |
294 If `prepend' or `append', existing fontification is merged with the new, in | 284 If `prepend' or `append', existing fontification is merged with the new, in |
295 which the new or existing fontification, respectively, takes precedence. | 285 which the new or existing fontification, respectively, takes precedence. |
488 ;;; extents, or resizing existing ones. | 478 ;;; extents, or resizing existing ones. |
489 ;;; | 479 ;;; |
490 ;;; Each time a modification happens to a line, we re-fontify the entire line. | 480 ;;; Each time a modification happens to a line, we re-fontify the entire line. |
491 ;;; We do this by first removing the extents (text properties) on the line, | 481 ;;; We do this by first removing the extents (text properties) on the line, |
492 ;;; and then doing the syntactic and keyword passes again on that line. (More | 482 ;;; and then doing the syntactic and keyword passes again on that line. (More |
493 ;;; generally, each modified region is extended to include the preceding and | 483 ;;; generally, each modified region is extended to include the preceeding and |
494 ;;; following BOL or EOL.) | 484 ;;; following BOL or EOL.) |
495 ;;; | 485 ;;; |
496 ;;; This means that, as the user types, we repeatedly go back to the beginning | 486 ;;; This means that, as the user types, we repeatedly go back to the beginning |
497 ;;; of the line, doing more work the longer the line gets. This doesn't cost | 487 ;;; of the line, doing more work the longer the line gets. This doesn't cost |
498 ;;; much in practice, and if we don't, then we incorrectly fontify things when, | 488 ;;; much in practice, and if we don't, then we incorrectly fontify things when, |
560 'font-lock-after-change-function nil t) | 550 'font-lock-after-change-function nil t) |
561 (add-hook 'pre-idle-hook 'font-lock-pre-idle-hook)) | 551 (add-hook 'pre-idle-hook 'font-lock-pre-idle-hook)) |
562 (t | 552 (t |
563 (remove-hook 'after-change-functions | 553 (remove-hook 'after-change-functions |
564 'font-lock-after-change-function t) | 554 'font-lock-after-change-function t) |
565 (setq font-lock-defaults-computed nil | 555 (remove-hook 'pre-idle-hook 'font-lock-pre-idle-hook) |
566 font-lock-keywords nil) | |
567 ;; We have no business doing this here, since | |
568 ;; pre-idle-hook is global. Other buffers may | |
569 ;; still be in font-lock mode. -dkindred@cs.cmu.edu | |
570 ;; (remove-hook 'pre-idle-hook 'font-lock-pre-idle-hook) | |
571 )) | 556 )) |
572 (set (make-local-variable 'font-lock-mode) on-p) | 557 (set (make-local-variable 'font-lock-mode) on-p) |
573 (cond (on-p | 558 (cond (on-p |
574 (font-lock-set-defaults-1) | 559 (font-lock-set-defaults-1) |
575 (make-local-hook 'before-revert-hook) | 560 (make-local-hook 'before-revert-hook) |
768 font-lock-old-len))) | 753 font-lock-old-len))) |
769 (detach-extent font-lock-old-extent) | 754 (detach-extent font-lock-old-extent) |
770 (setq font-lock-old-extent nil))) | 755 (setq font-lock-old-extent nil))) |
771 | 756 |
772 (defun font-lock-pre-idle-hook () | 757 (defun font-lock-pre-idle-hook () |
773 (condition-case nil | 758 (if font-lock-old-extent |
774 (if font-lock-old-extent | 759 (font-lock-fontify-glumped-region))) |
775 (font-lock-fontify-glumped-region)) | |
776 (error (warn "Error caught in `font-lock-pre-idle-hook'")))) | |
777 | 760 |
778 (defvar font-lock-always-fontify-immediately nil | 761 (defvar font-lock-always-fontify-immediately nil |
779 "Set this to non-nil to disable font-lock deferral.") | 762 "Set this to non-nil to disable font-lock deferral.") |
780 | 763 |
781 ;;; called when any modification is made to buffer text. This function | 764 ;;; called when any modification is made to buffer text. This function |
1099 "Apply HIGHLIGHT following a match. | 1082 "Apply HIGHLIGHT following a match. |
1100 HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'." | 1083 HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'." |
1101 (let* ((match (nth 0 highlight)) | 1084 (let* ((match (nth 0 highlight)) |
1102 (start (match-beginning match)) (end (match-end match)) | 1085 (start (match-beginning match)) (end (match-end match)) |
1103 (override (nth 2 highlight))) | 1086 (override (nth 2 highlight))) |
1087 (and end | |
1088 (goto-char end)) ;; tlp00 hack to allow for back to back fonts | |
1104 (let ((newface (nth 1 highlight))) | 1089 (let ((newface (nth 1 highlight))) |
1105 (or (symbolp newface) | 1090 (or (symbolp newface) |
1106 (setq newface (eval newface))) | 1091 (setq newface (eval newface))) |
1107 (cond ((not start) | 1092 (cond ((not start) |
1108 ;; No match but we might not signal an error. | 1093 ;; No match but we might not signal an error. |
1166 (make-string (setq count (1+ count)) ?.))) | 1151 (make-string (setq count (1+ count)) ?.))) |
1167 ;; | 1152 ;; |
1168 ;; Find an occurrence of `matcher' from `start' to `end'. | 1153 ;; Find an occurrence of `matcher' from `start' to `end'. |
1169 (setq keyword (car keywords) matcher (car keyword)) | 1154 (setq keyword (car keywords) matcher (car keyword)) |
1170 (goto-char start) | 1155 (goto-char start) |
1171 (while (and (< (point) end) | 1156 (while (if (stringp matcher) |
1172 (if (stringp matcher) | 1157 (re-search-forward matcher end t) |
1173 (re-search-forward matcher end t) | 1158 (funcall matcher end)) |
1174 (funcall matcher end))) | |
1175 ;; Apply each highlight to this instance of `matcher', which may be | 1159 ;; Apply each highlight to this instance of `matcher', which may be |
1176 ;; specific highlights or more keywords anchored to `matcher'. | 1160 ;; specific highlights or more keywords anchored to `matcher'. |
1177 (setq highlights (cdr keyword)) | 1161 (setq highlights (cdr keyword)) |
1178 (while highlights | 1162 (while highlights |
1179 (if (numberp (car (car highlights))) | 1163 (if (numberp (car (car highlights))) |
1209 | 1193 |
1210 ;; If the buffer has just been reverted, normally that turns off | 1194 ;; If the buffer has just been reverted, normally that turns off |
1211 ;; Font Lock mode. So turn the mode back on if necessary. | 1195 ;; Font Lock mode. So turn the mode back on if necessary. |
1212 (defalias 'font-lock-revert-cleanup 'turn-on-font-lock) | 1196 (defalias 'font-lock-revert-cleanup 'turn-on-font-lock) |
1213 | 1197 |
1214 | |
1215 (defun font-lock-compile-keywords (&optional keywords) | 1198 (defun font-lock-compile-keywords (&optional keywords) |
1216 ;; Compile `font-lock-keywords' into the form (t KEYWORD ...) where KEYWORD | 1199 ;; Compile `font-lock-keywords' into the form (t KEYWORD ...) where KEYWORD |
1217 ;; is the (MATCHER HIGHLIGHT ...) shown in the variable's doc string. | 1200 ;; is the (MATCHER HIGHLIGHT ...) shown in the variable's doc string. |
1218 (let ((keywords (or keywords font-lock-keywords))) | 1201 (let ((keywords (or keywords font-lock-keywords))) |
1219 (setq font-lock-keywords | 1202 (setq font-lock-keywords |
1220 (if (eq (car-safe keywords) t) | 1203 (if (eq (car-safe keywords) t) |
1221 keywords | 1204 keywords |
1222 (cons t (mapcar 'font-lock-compile-keyword keywords)))))) | 1205 (cons t |
1223 | 1206 (mapcar |
1224 (defun font-lock-compile-keyword (keyword) | 1207 (function (lambda (item) |
1225 (cond ((nlistp keyword) ; Just MATCHER | 1208 (cond ((nlistp item) |
1226 (list keyword '(0 font-lock-keyword-face))) | 1209 (list item '(0 font-lock-keyword-face))) |
1227 ((eq (car keyword) 'eval) ; Specified (eval . FORM) | 1210 ((numberp (cdr item)) |
1228 (font-lock-compile-keyword (eval (cdr keyword)))) | 1211 (list (car item) (list (cdr item) 'font-lock-keyword-face))) |
1229 ((numberp (cdr keyword)) ; Specified (MATCHER . MATCH) | 1212 ((symbolp (cdr item)) |
1230 (list (car keyword) (list (cdr keyword) 'font-lock-keyword-face))) | 1213 (list (car item) (list 0 (cdr item)))) |
1231 ((symbolp (cdr keyword)) ; Specified (MATCHER . FACENAME) | 1214 ((nlistp (nth 1 item)) |
1232 (list (car keyword) (list 0 (cdr keyword)))) | 1215 (list (car item) (cdr item))) |
1233 ((nlistp (nth 1 keyword)) ; Specified (MATCHER . HIGHLIGHT) | 1216 (t |
1234 (list (car keyword) (cdr keyword))) | 1217 item)))) |
1235 (t ; Hopefully (MATCHER HIGHLIGHT ...) | 1218 keywords)))))) |
1236 keyword))) | |
1237 | 1219 |
1238 (defun font-lock-choose-keywords (keywords level) | 1220 (defun font-lock-choose-keywords (keywords level) |
1239 ;; Return LEVELth element of KEYWORDS. A LEVEL of nil is equal to a | 1221 ;; Return LEVELth element of KEYWORDS. A LEVEL of nil is equal to a |
1240 ;; LEVEL of 0, a LEVEL of t is equal to (1- (length KEYWORDS)). | 1222 ;; LEVEL of 0, a LEVEL of t is equal to (1- (length KEYWORDS)). |
1241 (let ((level (if (not (consp level)) | 1223 (let ((level (if (not (consp level)) |
1272 ;; Really, the standard-syntax-table shouldn't have comments and | 1254 ;; Really, the standard-syntax-table shouldn't have comments and |
1273 ;; strings in it, but changing that now might break things. | 1255 ;; strings in it, but changing that now might break things. |
1274 nil | 1256 nil |
1275 ;; else map over the syntax table looking for strings or comments. | 1257 ;; else map over the syntax table looking for strings or comments. |
1276 (let (got-one) | 1258 (let (got-one) |
1277 ;; older Emacsen. | 1259 ;; XEmacs 20.0 ... |
1278 (let ((i (1- (length (syntax-table))))) | 1260 (if (fboundp 'map-syntax-table) |
1279 (while (>= i 0) | 1261 (setq got-one |
1280 (if (memq (char-syntax i) '(?\" ?\< ?\> ?\$)) | 1262 (map-syntax-table |
1281 (setq got-one t i 0)) | 1263 #'(lambda (key value) |
1282 (setq i (1- i)))) | 1264 (memq (char-syntax-from-code value) |
1265 '(?\" ?\< ?\> ?\$))) | |
1266 (syntax-table))) | |
1267 ;; older Emacsen. | |
1268 (let ((i (1- (length (syntax-table))))) | |
1269 (while (>= i 0) | |
1270 (if (memq (char-syntax i) '(?\" ?\< ?\> ?\$)) | |
1271 (setq got-one t i 0)) | |
1272 (setq i (1- i))))) | |
1283 (set (make-local-variable 'font-lock-keywords-only) (not got-one))))) | 1273 (set (make-local-variable 'font-lock-keywords-only) (not got-one))))) |
1284 | 1274 |
1285 ;; font-lock-set-defaults is in fontl-hooks.el. | 1275 ;; font-lock-set-defaults is in fontl-hooks.el. |
1286 | 1276 |
1287 (defun font-lock-set-defaults-1 (&optional explicit-defaults) | 1277 (defun font-lock-set-defaults-1 (&optional explicit-defaults) |
1521 c++-font-lock-keywords-3) | 1511 c++-font-lock-keywords-3) |
1522 nil nil ((?_ . "w") (?~ . "w")) beginning-of-defun)) | 1512 nil nil ((?_ . "w") (?~ . "w")) beginning-of-defun)) |
1523 | 1513 |
1524 (put 'java-mode 'font-lock-defaults | 1514 (put 'java-mode 'font-lock-defaults |
1525 '((java-font-lock-keywords | 1515 '((java-font-lock-keywords |
1526 java-font-lock-keywords-1 java-font-lock-keywords-2 | 1516 java-font-lock-keywords-1 java-font-lock-keywords-2) |
1527 java-font-lock-keywords-3) | 1517 nil nil ((?_ . "w")) beginning-of-defun)) |
1528 nil nil ((?_ . "w")) beginning-of-defun | |
1529 (font-lock-mark-block-function . mark-defun))) | |
1530 | 1518 |
1531 (put 'lisp-mode 'font-lock-defaults | 1519 (put 'lisp-mode 'font-lock-defaults |
1532 '((lisp-font-lock-keywords | 1520 '((lisp-font-lock-keywords |
1533 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2) | 1521 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2) |
1534 nil nil | 1522 nil nil |
1816 ;; | 1804 ;; |
1817 ;; Fontify function name definitions (GNU style; without type on line). | 1805 ;; Fontify function name definitions (GNU style; without type on line). |
1818 | 1806 |
1819 ;; In FSF this has the simpler definition of "\\sw+" for ctoken. | 1807 ;; In FSF this has the simpler definition of "\\sw+" for ctoken. |
1820 ;; I'm not sure if ours is more correct. | 1808 ;; I'm not sure if ours is more correct. |
1821 ;; This is a subset of the next rule, and is slower when present. --dmoore | 1809 (list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face) |
1822 ;; (list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face) | |
1823 ;; | 1810 ;; |
1824 ;; fontify the names of functions being defined. | 1811 ;; fontify the names of functions being defined. |
1825 ;; FSF doesn't have this but I think it should be fast for us because | 1812 ;; FSF doesn't have this but I think it should be fast for us because |
1826 ;; our regexp routines are more intelligent than FSF's about handling | 1813 ;; our regexp routines are more intelligent than FSF's about handling |
1827 ;; anchored-at-newline. (When I added this hack in regex.c, it halved | 1814 ;; anchored-at-newline. (When I added this hack in regex.c, it halved |
1828 ;; the time to do the regexp phase of font-lock for a C file!) Not | 1815 ;; the time to do the regexp phase of font-lock for a C file!) Not |
1829 ;; including this discriminates against those who don't follow the | 1816 ;; including this discriminates against those who don't follow the |
1830 ;; GNU coding style. --ben | 1817 ;; GNU coding style. --ben |
1831 ;; x?x?x?y?z should always be: (x(xx?)?)?y?z --dmoore | |
1832 (list (concat | 1818 (list (concat |
1833 "^\\(" | 1819 "^\\(" ctoken "[ \t]+\\)?" ; type specs; there can be no |
1834 "\\(" ctoken "[ \t]+\\)" ; type specs; there can be no | 1820 "\\(" ctoken "[ \t]+\\)?" ; more than 3 tokens, right? |
1835 "\\(" | 1821 "\\(" ctoken "[ \t]+\\)?" |
1836 "\\(" ctoken "[ \t]+\\)" ; more than 3 tokens, right? | |
1837 "\\(" ctoken "[ \t]+\\)" | |
1838 "?\\)?\\)?" | |
1839 "\\([*&]+[ \t]*\\)?" ; pointer | 1822 "\\([*&]+[ \t]*\\)?" ; pointer |
1840 "\\(" ctoken "\\)[ \t]*(") ; name | 1823 "\\(" ctoken "\\)[ \t]*(") ; name |
1841 10 'font-lock-function-name-face) | 1824 8 'font-lock-function-name-face) |
1842 ;; | 1825 ;; |
1843 ;; This is faster but not by much. I don't see why not. | 1826 ;; This is faster but not by much. I don't see why not. |
1844 ;(list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face) | 1827 ;(list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face) |
1845 ;; | 1828 ;; |
1846 ;; Added next two; they're both jolly-good fastmatch candidates so | 1829 ;; Added next two; they're both jolly-good fastmatch candidates so |
1935 | 1918 |
1936 (setq c++-font-lock-keywords-1 | 1919 (setq c++-font-lock-keywords-1 |
1937 (append | 1920 (append |
1938 ;; | 1921 ;; |
1939 ;; The list `c-font-lock-keywords-1' less that for function names. | 1922 ;; The list `c-font-lock-keywords-1' less that for function names. |
1940 ;; the simple function form regexp has been removed. --dmoore | 1923 (cdr c-font-lock-keywords-1) |
1941 ;;(cdr c-font-lock-keywords-1) | |
1942 c-font-lock-keywords-1 | |
1943 ;; | 1924 ;; |
1944 ;; Fontify function name definitions, possibly incorporating class name. | 1925 ;; Fontify function name definitions, possibly incorporating class name. |
1945 (list | 1926 (list |
1946 '("^\\(\\sw+\\)\\(::\\(\\sw+\\)\\)?[ \t]*(" | 1927 '("^\\(\\sw+\\)\\(::\\(\\sw+\\)\\)?[ \t]*(" |
1947 (1 (if (match-beginning 2) | 1928 (1 (if (match-beginning 2) |
2193 ; ) | 2174 ; ) |
2194 ; | 2175 ; |
2195 ;(defconst c++-font-lock-keywords c++-font-lock-keywords-1 | 2176 ;(defconst c++-font-lock-keywords c++-font-lock-keywords-1 |
2196 ; "Additional expressions to highlight in C++ mode.") | 2177 ; "Additional expressions to highlight in C++ mode.") |
2197 | 2178 |
2198 ;; Java support from Anders Lindgren and Bob Weiner | |
2199 | |
2200 (defconst java-font-lock-keywords-1 nil | 2179 (defconst java-font-lock-keywords-1 nil |
2201 "For consideration as a value of `java-font-lock-keywords'. | 2180 "For consideration as a value of `java-font-lock-keywords'. |
2202 This does fairly subdued highlighting.") | 2181 This does fairly subdued highlighting.") |
2203 | 2182 |
2204 (defconst java-font-lock-keywords-2 nil | 2183 (defconst java-font-lock-keywords-2 nil |
2205 "For consideration as a value of `java-font-lock-keywords'. | 2184 "For consideration as a value of `java-font-lock-keywords'. |
2206 This adds highlighting of types and identifier names.") | 2185 This does a lot more highlighting.") |
2207 | 2186 |
2208 (defconst java-font-lock-keywords-3 nil | 2187 (let ((storage (concat "static\\|abstract\\|const\\|final\\|" |
2209 "For consideration as a value of `java-font-lock-keywords'. | 2188 "synchronized\\|threadsafe\\|transient\\|native")) |
2210 This adds highlighting of Java documentation tags, such as @see.") | 2189 (types (concat |
2211 | 2190 "boolean\\|int\\|char\\|byte\\|short\\|long\\|" |
2212 (defvar java-font-lock-type-regexp | 2191 "float\\|double\\|void")) |
2213 (concat "\\<\\(boolean\\|byte\\|char\\|double\\|float\\|int" | 2192 (reserved-words |
2214 "\\|long\\|short\\|void\\)\\>") | 2193 '("private" "protected" "public" "break" "byvalue" |
2215 "Regexp which should match a primitive type.") | 2194 "case" "catch" "class" |
2216 | 2195 "continue" "default" "do" "else if" |
2217 (let ((capital-letter "A-Z\300-\326\330-\337") | 2196 "else" "extends" "false" "finally" |
2218 (letter "a-zA-Z_$\300-\326\330-\366\370-\377") | 2197 "for" "if" "implements" "import" |
2219 (digit "0-9")) | 2198 "instanceof" "interface" |
2220 (defvar java-font-lock-identifier-regexp | 2199 "new" "null" "package" "return" |
2221 (concat "\\<\\([" letter "][" letter digit "]*\\)\\>") | 2200 "super" "switch" |
2222 "Regexp which should match all Java identifiers.") | 2201 "this" "throw" "throws" |
2223 | 2202 "true" "try" "synchronize" "while")) |
2224 (defvar java-font-lock-class-name-regexp | 2203 |
2225 (concat "\\<\\([" capital-letter "][" letter digit "]*\\)\\>") | 2204 ; (java-token "\\w+") |
2226 "Regexp which should match a class or an interface name. | 2205 (java-token "[a-zA-Z0-9_\.]+") |
2227 The name is assumed to begin with a capital letter.") | 2206 (java-modifying-token "[a-zA-Z0-9_\.]+\\([ \t]*\\[\\]\\)?") |
2228 ) | 2207 ) |
2229 | |
2230 | |
2231 (let ((java-modifier-regexp | |
2232 (concat "\\<\\(abstract\\|const\\|final\\|native\\|" | |
2233 "private\\|protected\\|public\\|" | |
2234 "static\\|synchronized\\|transient\\|volatile\\)\\>"))) | |
2235 | |
2236 ;; Basic font-lock support: | |
2237 (setq java-font-lock-keywords-1 | 2208 (setq java-font-lock-keywords-1 |
2238 (list | 2209 (list |
2239 ;; Keywords: | 2210 ;;------------------------------------------------------------------ |
2240 (list | 2211 ;; fontify C++-style comments as comments. |
2241 (concat | 2212 ;;------------------------------------------------------------------ |
2242 "\\<\\(" | 2213 |
2243 "break\\|byvalue\\|" | 2214 '("//.*" . font-lock-comment-face) |
2244 "case\\|cast\\|catch\\|class\\|continue\\|" | 2215 |
2245 "do\\|else\\|extends\\|" | 2216 ;;------------------------------------------------------------------ |
2246 "finally\\|for\\|future\\|" | 2217 ;; I think static deserves special attention |
2247 "generic\\|goto\\|" | 2218 ;;------------------------------------------------------------------ |
2248 "if\\|implements\\|import\\|" | 2219 |
2249 "instanceof\\|interface\\|" | 2220 '("static" . font-lock-keyword-face) |
2250 "new\\|package\\|return\\|switch\\|" | 2221 |
2251 "throws?\\|try\\|while\\)\\>") | 2222 ;;------------------------------------------------------------------ |
2252 1 'font-lock-keyword-face) | 2223 ;; Make the "public" keyword standout (should we do private instead?) |
2253 | 2224 ;;------------------------------------------------------------------ |
2254 ;; Modifiers: | 2225 |
2255 (list java-modifier-regexp 1 font-lock-type-face) | 2226 ;; these depend on some personal SMF faces |
2256 | 2227 |
2257 ;; Special constants: | 2228 ;; I wish I knew elisp, etc enough to know if it's |
2258 '("\\<\\(this\\|super\\)\\>" (1 font-lock-reference-face)) | 2229 ;; faster to use 1 regex for n words, or n |
2259 '("\\<\\(false\\|null\\|true\\)\\>" (1 font-lock-keyword-face)) | 2230 ;; unglobbed entries in this list... |
2260 | 2231 |
2261 ;; Class names: | 2232 ;; '("private" . font-lock-pale-face) |
2262 (list (concat "\\<class\\>\\s *" java-font-lock-identifier-regexp) | 2233 ;; '("protected" . font-lock-pale-face) |
2263 1 'font-lock-function-name-face) | 2234 |
2264 | 2235 ;;------------------------------------------------------------------ |
2265 ;; Package declarations: | 2236 ;; special case so "new Foo();" doesn't map to method declaration |
2266 (list (concat "\\<\\(package\\|import\\)\\>\\s *" | 2237 ;;------------------------------------------------------------------ |
2267 java-font-lock-identifier-regexp) | 2238 |
2268 '(2 font-lock-reference-face) | 2239 (list (concat |
2269 (list (concat | 2240 "^.*[ \t]+\\(new\\|return\\)[ \t]+" |
2270 "\\=\\.\\(" java-font-lock-identifier-regexp "\\)") | 2241 "\\(" java-token "\\)") |
2271 nil nil '(1 (let ((c (char-after (match-end 0)))) | 2242 2 'default) |
2272 (if (and (characterp c) | 2243 |
2273 (= c ?.)) | 2244 ;;------------------------------------------------------------------ |
2274 'font-lock-reference-face | 2245 ;; special case so "else if();" doesn't map to method declaration |
2275 'font-lock-type-face))))) | 2246 ;;------------------------------------------------------------------ |
2276 | 2247 |
2277 ;; Constructors: | 2248 (list "^.*[ \t]+else[ \t]+\\(if\\)" |
2278 (list (concat | 2249 1 'default) |
2279 "^\\s *\\(" java-modifier-regexp "\\s +\\)*" | 2250 |
2280 java-font-lock-class-name-regexp "\\s *\(") | 2251 ;;------------------------------------------------------------------ |
2281 (list 3 | 2252 ;; METHOD IDENTIFICATION |
2282 '(condition-case nil | 2253 ;; |
2283 (save-excursion | 2254 ;; fontify the (first word of) names of methods being defined. |
2284 (goto-char (scan-sexps (- (match-end 0) 1) 1)) | 2255 ;;------------------------------------------------------------------ |
2285 (parse-partial-sexp (point) (point-max) nil t) | 2256 |
2286 (and (looking-at "\\($\\|\\<throws\\>\\|{\\)") | 2257 (list (concat |
2287 'font-lock-function-name-face)) | 2258 "^[ \t]+" ;; indent of line |
2288 (error 'font-lock-function-name-face)))) | 2259 |
2289 | 2260 ;;------------------------------------------------------- |
2290 ;; Methods: | 2261 ;; Demanding a token 1st doesn't recognize constructors |
2291 (list (concat "\\(" java-font-lock-type-regexp "\\|" | 2262 ;; w/out any access specifiers. Unfortunately, that also |
2292 java-font-lock-class-name-regexp "\\)" | 2263 ;; looks like many other things, including "if (foo) {", |
2293 "\\s *\\(\\[\\s *\\]\\s *\\)*" | 2264 ;; so it's not an easy case to detect -- I'm just going |
2294 java-font-lock-identifier-regexp "\\s *\(") | 2265 ;; to live w/out it for now... |
2295 5 | 2266 ;;------------------------------------------------------- |
2296 'font-lock-function-name-face) | 2267 |
2297 | 2268 "\\(" java-modifying-token "[ \t]+\\)" |
2298 ;; Labels: | 2269 |
2299 (list ":" | 2270 ; "\\(" |
2300 (list | 2271 ; "\\(^[ \t]+\\(" java-token "[ \t]+\\)\\)" |
2301 (concat "^\\s *" java-font-lock-identifier-regexp "\\s *:") | 2272 ; "\\|" |
2302 '(beginning-of-line) '(end-of-line) | 2273 ; "\\( \\)" |
2303 '(1 font-lock-reference-face))) | 2274 ; "\\)" |
2304 | 2275 ; failed attempt to hack in ^ followed by exactly 4 spaces allowance to |
2305 ;; `break' and continue' destination labels: | 2276 ; recognize constructions with no access specified |
2306 (list (concat "\\<\\(break\\|continue\\)\\>\\s *" | 2277 |
2307 java-font-lock-identifier-regexp) | 2278 "\\(" java-modifying-token "[ \t]+\\)?" |
2308 2 'font-lock-reference-face) | 2279 "\\(" java-modifying-token "[ \t]+\\)?" |
2309 | 2280 "\\(" java-modifying-token "[ \t]+\\)?" |
2310 ;; Case statements: | 2281 "\\(" java-modifying-token "[ \t]+\\)?" |
2311 ;; In Java, any constant expression is allowed. | 2282 "\\(" java-modifying-token "[ \t]+\\)?" |
2312 '("\\<case\\>\\s *\\(.*\\):" 1 font-lock-reference-face))) | 2283 "\\(" java-token "\\)[ \t]*(") |
2313 | 2284 |
2314 ;; Types and declared variable names: | 2285 ; "\\(" java-token "\\)[ \t]*(.*{") |
2286 | |
2287 ;; SMF: while demanding { at EOL is stylistic, | |
2288 ;; it DOESN'T hilite the likes of: | |
2289 ;; return new Dimension() | |
2290 ;; "\\(" java-token "\\)[ \t]*(") | |
2291 ;; PROBLEM -- it leaves out abstract and native methods! | |
2292 | |
2293 13 'font-lock-function-name-face) | |
2294 | |
2295 ;;------------------------------------------------------------------ | |
2296 ;; Fontify class names ... | |
2297 ;; (info-node is another personal SMF face) | |
2298 ;;------------------------------------------------------------------ | |
2299 | |
2300 (list (concat | |
2301 "^[ \t]*\\([a-z]+[ \t]+\\)?\\([a-z]+[ \t]+\\)?class[ \t]+\\(" | |
2302 java-token "\\)") | |
2303 3 'font-lock-reference-face) | |
2304 | |
2305 ;;------------------------------------------------------------------ | |
2306 ;; Package names | |
2307 ;;------------------------------------------------------------------ | |
2308 | |
2309 (list (concat | |
2310 "package[ \t]+\\(" java-token "\\)") | |
2311 1 'font-lock-reference-face) | |
2312 | |
2313 ;; | |
2314 ;; Fontify case clauses. This is fast because its anchored on the left. | |
2315 | |
2316 '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\):". 1) | |
2317 '("\\<\\(default\\):". 1) | |
2318 )) | |
2319 | |
2315 (setq java-font-lock-keywords-2 | 2320 (setq java-font-lock-keywords-2 |
2316 (append | 2321 (append java-font-lock-keywords-1 |
2317 | 2322 (list |
2318 java-font-lock-keywords-1 | 2323 ;; |
2319 (list | 2324 ;; fontify all storage classes and type specifiers |
2320 ;; Keywords followed by a type: | 2325 (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face) |
2321 (list (concat "\\<\\(extends\\|instanceof\\|new\\)\\>\\s *" | 2326 (cons (concat "\\<\\(" types "\\)\\>") 'font-lock-type-face) |
2322 java-font-lock-identifier-regexp) | 2327 |
2323 '(2 (if (= (char-after (match-end 0)) ?.) | 2328 ;; |
2324 'font-lock-reference-face 'font-lock-type-face)) | 2329 ;; fontify all builtin tokens |
2325 (list (concat "\\=\\." java-font-lock-identifier-regexp) | 2330 (cons (concat |
2326 '(goto-char (match-end 0)) nil | 2331 "[ \t]\\(" |
2327 '(1 (if (= (char-after (match-end 0)) ?.) | 2332 (mapconcat 'identity reserved-words "\\|") |
2328 'font-lock-reference-face 'font-lock-type-face)))) | 2333 "\\)[ \t\n(){};,]") |
2329 | 2334 1) |
2330 ;; Keywords followed by a type list: | 2335 (cons (concat |
2331 (list (concat "\\<\\(implements\\|throws\\)\\>\\ s*" | 2336 "^\\(" |
2332 java-font-lock-identifier-regexp) | 2337 (mapconcat 'identity reserved-words "\\|") |
2333 '(2 (if (= (char-after (match-end 0)) ?.) | 2338 "\\)[ \t\n(){};,]") |
2334 font-lock-reference-face font-lock-type-face)) | 2339 1) |
2335 (list (concat "\\=\\(\\.\\|\\s *\\(,\\)\\s *\\)" | 2340 ))) |
2336 java-font-lock-identifier-regexp) | |
2337 '(goto-char (match-end 0)) nil | |
2338 '(3 (if (= (char-after (match-end 0)) ?.) | |
2339 font-lock-reference-face font-lock-type-face)))) | |
2340 | |
2341 ;; primitive types, can't be confused with anything else. | |
2342 (list java-font-lock-type-regexp | |
2343 '(1 font-lock-type-face) | |
2344 '(font-lock-match-java-declarations | |
2345 (goto-char (match-end 0)) | |
2346 (goto-char (match-end 0)) | |
2347 (0 font-lock-variable-name-face))) | |
2348 | |
2349 ;; Declarations, class types and capitalized variables: | |
2350 ;; | |
2351 ;; Declarations are easy to recognize. Capitalized words | |
2352 ;; followed by a closing parenthesis are treated as casts if they | |
2353 ;; also are followed by an expression. Expressions beginning with | |
2354 ;; a unary numerical operator, e.g. +, can't be cast to an object | |
2355 ;; type. | |
2356 ;; | |
2357 ;; The path of a fully qualified type, e.g. java.lang.Foo, is | |
2358 ;; fontified in the reference face. | |
2359 ;; | |
2360 ;; An access to a static field, e.g. System.out.println, is | |
2361 ;; not fontified since it can't be distinguished from the | |
2362 ;; usage of a capitalized variable, e.g. Foo.out.println. | |
2363 | |
2364 (list (concat java-font-lock-class-name-regexp | |
2365 "\\s *\\(\\[\\s *\\]\\s *\\)*" | |
2366 "\\(\\<\\|$\\|)\\s *\\([\(\"]\\|\\<\\)\\)") | |
2367 '(1 (save-match-data | |
2368 (save-excursion | |
2369 (goto-char | |
2370 (match-beginning 3)) | |
2371 (if (not (looking-at "\\<instanceof\\>")) | |
2372 'font-lock-type-face)))) | |
2373 (list (concat "\\=" java-font-lock-identifier-regexp "\\.") | |
2374 '(progn | |
2375 (goto-char (match-beginning 0)) | |
2376 (while (or (= (preceding-char) ?.) | |
2377 (= (char-syntax (preceding-char)) ?w)) | |
2378 (backward-char))) | |
2379 '(goto-char (match-end 0)) | |
2380 '(1 font-lock-reference-face) | |
2381 '(0 nil)) ; Workaround for bug in XEmacs. | |
2382 '(font-lock-match-java-declarations | |
2383 (goto-char (match-end 1)) | |
2384 (goto-char (match-end 0)) | |
2385 (1 font-lock-variable-name-face)))))) | |
2386 | |
2387 ;; Modifier keywords and Java doc tags | |
2388 (setq java-font-lock-keywords-3 | |
2389 (append | |
2390 | |
2391 '( | |
2392 ;; Feature scoping: | |
2393 ;; These must come first or the Modifiers from keywords-1 will | |
2394 ;; catch them. We don't want to use override fontification here | |
2395 ;; because then these terms will be fontified within comments. | |
2396 ("\\<private\\>" 0 font-lock-string-face) | |
2397 ("\\<protected\\>" 0 font-lock-preprocessor-face) | |
2398 ("\\<public\\>" 0 font-lock-reference-face)) | |
2399 | |
2400 java-font-lock-keywords-2 | |
2401 | |
2402 (list | |
2403 | |
2404 ;; Java doc tags | |
2405 '("@\\(author\\|exception\\|param\\|return\\|see\\|version\\)\\s " | |
2406 0 font-lock-keyword-face t) | |
2407 | |
2408 ;; Doc tag - Parameter identifiers | |
2409 (list (concat "@param\\s +" java-font-lock-identifier-regexp) | |
2410 1 'font-lock-variable-name-face t) | |
2411 | |
2412 ;; Doc tag - Exception types | |
2413 (list (concat "@exception\\ s*" | |
2414 java-font-lock-identifier-regexp) | |
2415 '(1 (if (= (char-after (match-end 0)) ?.) | |
2416 font-lock-reference-face font-lock-type-face) t) | |
2417 (list (concat "\\=\\." java-font-lock-identifier-regexp) | |
2418 '(goto-char (match-end 0)) nil | |
2419 '(1 (if (= (char-after (match-end 0)) ?.) | |
2420 'font-lock-reference-face 'font-lock-type-face) t))) | |
2421 | |
2422 ;; Doc tag - Cross-references, usually to methods | |
2423 '("@see\\s +\\(\\S *[^][ \t\n\r\f(){},.;:]\\)" | |
2424 1 font-lock-function-name-face t) | |
2425 | |
2426 ))) | |
2427 ) | 2341 ) |
2428 | 2342 |
2429 (defvar java-font-lock-keywords java-font-lock-keywords-1 | 2343 (defvar java-font-lock-keywords java-font-lock-keywords-1 |
2430 "Additional expressions to highlight in Java mode.") | 2344 "Additional expressions to highlight in Java mode.") |
2431 | |
2432 ;; Match and move over any declaration/definition item after | |
2433 ;; point. Does not match items which look like a type declaration | |
2434 ;; (primitive types and class names, i.e. capitalized words.) | |
2435 ;; Should the variable name be followed by a comma, we reposition | |
2436 ;; the cursor to fontify more identifiers. | |
2437 (defun font-lock-match-java-declarations (limit) | |
2438 "Match and skip over variable definitions." | |
2439 (if (looking-at "\\s *\\(\\[\\s *\\]\\s *\\)*") | |
2440 (goto-char (match-end 0))) | |
2441 (and | |
2442 (looking-at java-font-lock-identifier-regexp) | |
2443 (save-match-data | |
2444 (not (string-match java-font-lock-type-regexp | |
2445 (buffer-substring (match-beginning 1) | |
2446 (match-end 1))))) | |
2447 (save-match-data | |
2448 (save-excursion | |
2449 (goto-char (match-beginning 1)) | |
2450 (not (looking-at | |
2451 (concat java-font-lock-class-name-regexp | |
2452 "\\s *\\(\\[\\s *\\]\\s *\\)*\\<"))))) | |
2453 (save-match-data | |
2454 (condition-case nil | |
2455 (save-restriction | |
2456 (narrow-to-region (point-min) limit) | |
2457 (goto-char (match-end 0)) | |
2458 ;; Note: Both `scan-sexps' and the second goto-char can | |
2459 ;; generate an error which is caught by the | |
2460 ;; `condition-case' expression. | |
2461 (while (not (looking-at "\\s *\\(\\(,\\)\\|;\\|$\\)")) | |
2462 (goto-char (or (scan-sexps (point) 1) (point-max)))) | |
2463 (goto-char (match-end 2))) ; non-nil | |
2464 (error t))))) | |
2465 | |
2466 | 2345 |
2467 (defvar tex-font-lock-keywords | 2346 (defvar tex-font-lock-keywords |
2468 ; ;; Regexps updated with help from Ulrik Dickow <dickow@nbi.dk>. | 2347 ; ;; Regexps updated with help from Ulrik Dickow <dickow@nbi.dk>. |
2469 ; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}" | 2348 ; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}" |
2470 ; 2 font-lock-function-name-face) | 2349 ; 2 font-lock-function-name-face) |
2538 '("\\[.*\\]" . font-lock-type-face) | 2417 '("\\[.*\\]" . font-lock-type-face) |
2539 '("`.*`" . font-lock-type-face) | 2418 '("`.*`" . font-lock-type-face) |
2540 )) | 2419 )) |
2541 "Additional expressions to highlight in sh-mode.") | 2420 "Additional expressions to highlight in sh-mode.") |
2542 | 2421 |
2422 (defconst python-font-lock-keywords | |
2423 (purecopy | |
2424 (list | |
2425 (cons (concat "\\b\\(" | |
2426 (mapconcat 'identity | |
2427 '("access" "del" "from" | |
2428 "lambda" "return" "and" | |
2429 "elif" "global" "not" | |
2430 "try:" "break " "else:" | |
2431 "if" "or" "while" | |
2432 "except" "except:" "import" | |
2433 "pass" "continue" "finally:" | |
2434 "in" "print" "for" | |
2435 "is" "raise") | |
2436 "\\|") | |
2437 "\\)[ \n\t(]") | |
2438 1) | |
2439 '("\\bclass[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)" | |
2440 1 font-lock-type-face) | |
2441 '("\\bdef[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)" | |
2442 1 font-lock-function-name-face) | |
2443 )) | |
2444 "Additional expressions to highlight in Python mode.") | |
2445 | |
2446 | |
2543 | 2447 |
2544 ;; Install ourselves: | 2448 ;; Install ourselves: |
2545 | 2449 |
2546 (add-hook 'find-file-hooks 'font-lock-set-defaults t) | 2450 (add-hook 'find-file-hooks 'font-lock-set-defaults t) |
2547 | 2451 |