Mercurial > emacs
comparison lisp/font-lock.el @ 18025:9f9f522cdc27
Update for syntax-table text properties.
font-lock.el now adds them via font-lock-syntactic-keywords.
author | Simon Marshall <simon@gnu.org> |
---|---|
date | Thu, 29 May 1997 07:18:05 +0000 |
parents | 9b75a01e03e5 |
children | ee997de5b74b |
comparison
equal
deleted
inserted
replaced
18024:58afe194f1bd | 18025:9f9f522cdc27 |
---|---|
58 ;; insertion or deletion). Fontification means the replacement of `face' text | 58 ;; insertion or deletion). Fontification means the replacement of `face' text |
59 ;; properties in a given region; Emacs displays text with these `face' text | 59 ;; properties in a given region; Emacs displays text with these `face' text |
60 ;; properties appropriately. | 60 ;; properties appropriately. |
61 ;; | 61 ;; |
62 ;; Fontification normally involves syntactic (i.e., strings and comments) and | 62 ;; Fontification normally involves syntactic (i.e., strings and comments) and |
63 ;; regexp (i.e., keywords and everything else) passes. The syntactic pass | 63 ;; regexp (i.e., keywords and everything else) passes. There are actually |
64 ;; involves a syntax table and a syntax parsing function to determine the | 64 ;; three passes; (a) the syntactic keyword pass, (b) the syntactic pass and (c) |
65 ;; context of different parts of a region of text. It is necessary because | 65 ;; the keyword pass. Confused? |
66 ;; generally strings and/or comments can span lines, and so the context of a | 66 ;; |
67 ;; given region is not necessarily apparent from the content of that region. | 67 ;; The syntactic keyword pass places `syntax-table' text properties in the |
68 ;; Because the regexp pass only works within a given region, it is not | 68 ;; buffer according to the variable `font-lock-syntactic-keywords'. It is |
69 ;; generally appropriate for syntactic fontification. The regexp pass involves | 69 ;; necessary because Emacs' syntax table is not powerful enough to describe all |
70 ;; searching for given regexps (or calling given functions) within the given | 70 ;; the different syntactic constructs required by the sort of people who decide |
71 ;; region. For each match of the regexp (or non-nil value of the called | 71 ;; that a single quote can be syntactic or not depending on the time of day. |
72 ;; function), `face' text properties are added appropriately. | 72 ;; (What sort of person could decide to overload the meaning of a quote?) |
73 ;; Obviously the syntactic keyword pass must occur before the syntactic pass. | |
74 ;; | |
75 ;; The syntactic pass places `face' text properties in the buffer according to | |
76 ;; syntactic context, i.e., according to the buffer's syntax table and buffer | |
77 ;; text's `syntax-table' text properties. It involves using a syntax parsing | |
78 ;; function to determine the context of different parts of a region of text. A | |
79 ;; syntax parsing function is necessary because generally strings and/or | |
80 ;; comments can span lines, and so the context of a given region is not | |
81 ;; necessarily apparent from the content of that region. Because the keyword | |
82 ;; pass only works within a given region, it is not generally appropriate for | |
83 ;; syntactic fontification. This is the first fontification pass that makes | |
84 ;; changes visible to the user; it fontifies strings and comments. | |
85 ;; | |
86 ;; The keyword pass places `face' text properties in the buffer according to | |
87 ;; the variable `font-lock-keywords'. It involves searching for given regexps | |
88 ;; (or calling given search functions) within the given region. This is the | |
89 ;; second fontification pass that makes changes visible to the user; it | |
90 ;; fontifies language reserved words, etc. | |
91 ;; | |
92 ;; Oh, and the answer is, "Yes, obviously just about everything should be done | |
93 ;; in a single syntactic pass, but the only syntactic parser available | |
94 ;; understands only strings and comments." Perhaps one day someone will write | |
95 ;; some syntactic parsers for common languages and a son-of-font-lock.el could | |
96 ;; use them rather then relying so heavily on the keyword (regexp) pass. | |
73 | 97 |
74 ;;; How Font Lock mode supports modes or is supported by modes: | 98 ;;; How Font Lock mode supports modes or is supported by modes: |
75 | 99 |
76 ;; Modes that support Font Lock mode do so by defining one or more variables | 100 ;; Modes that support Font Lock mode do so by defining one or more variables |
77 ;; whose values specify the fontification. Font Lock mode knows of these | 101 ;; whose values specify the fontification. Font Lock mode knows of these |
90 | 114 |
91 ;;; Constructing patterns: | 115 ;;; Constructing patterns: |
92 | 116 |
93 ;; See the documentation for the variable `font-lock-keywords'. | 117 ;; See the documentation for the variable `font-lock-keywords'. |
94 ;; | 118 ;; |
95 ;; Nasty regexps of the form "bar\\(\\|lo\\)\\|f\\(oo\\|u\\(\\|bar\\)\\)\\|lo" | 119 ;; Efficient regexps for use as MATCHERs for `font-lock-keywords' and |
96 ;; are made thusly: (make-regexp '("foo" "fu" "fubar" "bar" "barlo" "lo")) for | 120 ;; `font-lock-syntactic-keywords' can be generated via the function |
97 ;; efficiency. See /pub/gnu/emacs/elisp-archive/functions/make-regexp.el.Z on | 121 ;; `regexp-opt', and their depth counted via the function `regexp-opt-depth'. |
98 ;; archive.cis.ohio-state.edu for this and other functions not just by sm. | |
99 | 122 |
100 ;;; Adding patterns for modes that already support Font Lock: | 123 ;;; Adding patterns for modes that already support Font Lock: |
101 | 124 |
102 ;; Though Font Lock highlighting patterns already exist for many modes, it's | 125 ;; Though Font Lock highlighting patterns already exist for many modes, it's |
103 ;; likely there's something that you want fontified that currently isn't, even | 126 ;; likely there's something that you want fontified that currently isn't, even |
196 | 219 |
197 (defgroup font-lock-extra-types nil | 220 (defgroup font-lock-extra-types nil |
198 "Extra mode-specific type names for highlighting declarations." | 221 "Extra mode-specific type names for highlighting declarations." |
199 :group 'font-lock) | 222 :group 'font-lock) |
200 | 223 |
201 ;; Define support mode groups here for nicer `font-lock' group order. | 224 ;; Define support mode groups here to impose `font-lock' group order. |
202 (defgroup fast-lock nil | 225 (defgroup fast-lock nil |
203 "Font Lock support mode to cache fontification." | 226 "Font Lock support mode to cache fontification." |
204 :link '(custom-manual "(emacs)Support Modes") | 227 :link '(custom-manual "(emacs)Support Modes") |
205 :load 'fast-lock | 228 :load 'fast-lock |
206 :group 'font-lock) | 229 :group 'font-lock) |
269 :group 'font-lock) | 292 :group 'font-lock) |
270 | 293 |
271 ;; Fontification variables: | 294 ;; Fontification variables: |
272 | 295 |
273 (defvar font-lock-keywords nil | 296 (defvar font-lock-keywords nil |
274 "*A list of the keywords to highlight. | 297 "A list of the keywords to highlight. |
275 Each element should be of the form: | 298 Each element should be of the form: |
276 | 299 |
277 MATCHER | 300 MATCHER |
278 (MATCHER . MATCH) | 301 (MATCHER . MATCH) |
279 (MATCHER . FACENAME) | 302 (MATCHER . FACENAME) |
295 | 318 |
296 (MATCH FACENAME OVERRIDE LAXMATCH) | 319 (MATCH FACENAME OVERRIDE LAXMATCH) |
297 | 320 |
298 Where MATCHER can be either the regexp to search for, or the function name to | 321 Where MATCHER can be either the regexp to search for, or the function name to |
299 call to make the search (called with one argument, the limit of the search). | 322 call to make the search (called with one argument, the limit of the search). |
300 MATCH is the subexpression of MATCHER to be highlighted. MATCH can be | 323 MATCHER regexps can be generated via the function `regexp-opt'. MATCH is the |
301 calculated via the function `font-lock-keyword-depth'. FACENAME is an | 324 subexpression of MATCHER to be highlighted. MATCH can be calculated via the |
302 expression whose value is the face name to use. FACENAME's default attributes | 325 function `regexp-opt-depth'. FACENAME is an expression whose value is the face |
303 can be modified via \\[customize]. | 326 name to use. Face default attributes can be modified via \\[customize]. |
304 | 327 |
305 OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification can | 328 OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification can |
306 be overwritten. If `keep', only parts not already fontified are highlighted. | 329 be overwritten. If `keep', only parts not already fontified are highlighted. |
307 If `prepend' or `append', existing fontification is merged with the new, in | 330 If `prepend' or `append', existing fontification is merged with the new, in |
308 which the new or existing fontification, respectively, takes precedence. | 331 which the new or existing fontification, respectively, takes precedence. |
495 | 518 |
496 (defvar font-lock-keywords-case-fold-search nil | 519 (defvar font-lock-keywords-case-fold-search nil |
497 "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive. | 520 "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive. |
498 This is normally set via `font-lock-defaults'.") | 521 This is normally set via `font-lock-defaults'.") |
499 | 522 |
523 (defvar font-lock-syntactic-keywords nil | |
524 "A list of the syntactic keywords to highlight. | |
525 Can be the list or the name of a function or variable whose value is the list. | |
526 See `font-lock-keywords' for a description of the form of this list; | |
527 the differences are listed below. MATCH-HIGHLIGHT should be of the form: | |
528 | |
529 (MATCH SYNTAX OVERRIDE LAXMATCH) | |
530 | |
531 where SYNTAX can be of the form (SYNTAX-CODE . MATCHING-CHAR), the name of a | |
532 syntax table, or an expression whose value is such a form or a syntax table. | |
533 OVERRIDE cannot be `prepend' or `append'. | |
534 | |
535 This is normally set via `font-lock-defaults'.") | |
536 | |
500 (defvar font-lock-syntax-table nil | 537 (defvar font-lock-syntax-table nil |
501 "Non-nil means use this syntax table for fontifying. | 538 "Non-nil means use this syntax table for fontifying. |
502 If this is nil, the major mode's syntax table is used. | 539 If this is nil, the major mode's syntax table is used. |
503 This is normally set via `font-lock-defaults'.") | 540 This is normally set via `font-lock-defaults'.") |
504 | 541 |
996 (font-lock-unfontify-region (point-min) (point-max)) | 1033 (font-lock-unfontify-region (point-min) (point-max)) |
997 (font-lock-after-unfontify-buffer) | 1034 (font-lock-after-unfontify-buffer) |
998 (setq font-lock-fontified nil))) | 1035 (setq font-lock-fontified nil))) |
999 | 1036 |
1000 (defun font-lock-default-fontify-region (beg end loudly) | 1037 (defun font-lock-default-fontify-region (beg end loudly) |
1001 (save-buffer-state ((old-syntax-table (syntax-table))) | 1038 (save-buffer-state |
1039 ((parse-sexp-lookup-properties font-lock-syntactic-keywords) | |
1040 (old-syntax-table (syntax-table))) | |
1002 (unwind-protect | 1041 (unwind-protect |
1003 (save-restriction | 1042 (save-restriction |
1004 (widen) | 1043 (widen) |
1005 ;; Use the fontification syntax table, if any. | 1044 ;; Use the fontification syntax table, if any. |
1006 (when font-lock-syntax-table | 1045 (when font-lock-syntax-table |
1007 (set-syntax-table font-lock-syntax-table)) | 1046 (set-syntax-table font-lock-syntax-table)) |
1008 ;; Now do the fontification. | 1047 ;; Now do the fontification. |
1009 (font-lock-unfontify-region beg end) | 1048 (font-lock-unfontify-region beg end) |
1049 (when font-lock-syntactic-keywords | |
1050 (font-lock-fontify-syntactic-keywords-region beg end)) | |
1010 (unless font-lock-keywords-only | 1051 (unless font-lock-keywords-only |
1011 (font-lock-fontify-syntactically-region beg end loudly)) | 1052 (font-lock-fontify-syntactically-region beg end loudly)) |
1012 (font-lock-fontify-keywords-region beg end loudly)) | 1053 (font-lock-fontify-keywords-region beg end loudly)) |
1013 ;; Clean up. | 1054 ;; Clean up. |
1014 (set-syntax-table old-syntax-table)))) | 1055 (set-syntax-table old-syntax-table)))) |
1021 ; (or (nth 4 state) (nth 7 state)))) | 1062 ; (or (nth 4 state) (nth 7 state)))) |
1022 ; (font-lock-fontify-keywords-region beg end)) | 1063 ; (font-lock-fontify-keywords-region beg end)) |
1023 | 1064 |
1024 (defun font-lock-default-unfontify-region (beg end) | 1065 (defun font-lock-default-unfontify-region (beg end) |
1025 (save-buffer-state nil | 1066 (save-buffer-state nil |
1026 (remove-text-properties beg end '(face nil)))) | 1067 (remove-text-properties beg end '(face nil syntax-table nil)))) |
1027 | 1068 |
1028 ;; Called when any modification is made to buffer text. | 1069 ;; Called when any modification is made to buffer text. |
1029 (defun font-lock-after-change-function (beg end old-len) | 1070 (defun font-lock-after-change-function (beg end old-len) |
1030 (save-excursion | 1071 (save-excursion |
1031 (save-match-data | 1072 (save-match-data |
1059 | 1100 |
1060 (define-key facemenu-keymap "\M-g" 'font-lock-fontify-block) | 1101 (define-key facemenu-keymap "\M-g" 'font-lock-fontify-block) |
1061 | 1102 |
1062 ;;; End of Fontification functions. | 1103 ;;; End of Fontification functions. |
1063 | 1104 |
1064 ;;; Syntactic fontification functions. | |
1065 | |
1066 ;; These record the parse state at a particular position, always the start of a | |
1067 ;; line. Used to make `font-lock-fontify-syntactically-region' faster. | |
1068 ;; Previously, `font-lock-cache-position' was just a buffer position. However, | |
1069 ;; under certain situations, this occasionally resulted in mis-fontification. | |
1070 ;; I think the "situations" were deletion with Lazy Lock mode's deferral. sm. | |
1071 (defvar font-lock-cache-state nil) | |
1072 (defvar font-lock-cache-position nil) | |
1073 | |
1074 (defun font-lock-fontify-syntactically-region (start end &optional loudly) | |
1075 "Put proper face on each string and comment between START and END. | |
1076 START should be at the beginning of a line." | |
1077 (let ((cache (marker-position font-lock-cache-position)) | |
1078 state string beg) | |
1079 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) | |
1080 (goto-char start) | |
1081 ;; | |
1082 ;; Find the state at the `beginning-of-line' before `start'. | |
1083 (if (eq start cache) | |
1084 ;; Use the cache for the state of `start'. | |
1085 (setq state font-lock-cache-state) | |
1086 ;; Find the state of `start'. | |
1087 (if (null font-lock-beginning-of-syntax-function) | |
1088 ;; Use the state at the previous cache position, if any, or | |
1089 ;; otherwise calculate from `point-min'. | |
1090 (if (or (null cache) (< start cache)) | |
1091 (setq state (parse-partial-sexp (point-min) start)) | |
1092 (setq state (parse-partial-sexp cache start nil nil | |
1093 font-lock-cache-state))) | |
1094 ;; Call the function to move outside any syntactic block. | |
1095 (funcall font-lock-beginning-of-syntax-function) | |
1096 (setq state (parse-partial-sexp (point) start))) | |
1097 ;; Cache the state and position of `start'. | |
1098 (setq font-lock-cache-state state) | |
1099 (set-marker font-lock-cache-position start)) | |
1100 ;; | |
1101 ;; If the region starts inside a string or comment, show the extent of it. | |
1102 (when (or (nth 3 state) (nth 4 state)) | |
1103 (setq string (nth 3 state) beg (point)) | |
1104 (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table)) | |
1105 (put-text-property beg (point) 'face | |
1106 (if string | |
1107 font-lock-string-face | |
1108 font-lock-comment-face))) | |
1109 ;; | |
1110 ;; Find each interesting place between here and `end'. | |
1111 (while (and (< (point) end) | |
1112 (progn | |
1113 (setq state (parse-partial-sexp (point) end nil nil state | |
1114 'syntax-table)) | |
1115 (or (nth 3 state) (nth 4 state)))) | |
1116 (setq string (nth 3 state) beg (nth 8 state)) | |
1117 (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table)) | |
1118 (put-text-property beg (point) 'face | |
1119 (if string | |
1120 font-lock-string-face | |
1121 font-lock-comment-face))))) | |
1122 | |
1123 ;;; End of Syntactic fontification functions. | |
1124 | |
1125 ;;; Additional text property functions. | 1105 ;;; Additional text property functions. |
1126 | 1106 |
1127 ;; The following text property functions should be builtins. This means they | 1107 ;; The following text property functions should be builtins. This means they |
1128 ;; should be written in C and put with all the other text property functions. | 1108 ;; should be written in C and put with all the other text property functions. |
1129 ;; In the meantime, those that are used by font-lock.el are defined in Lisp | 1109 ;; In the meantime, those that are used by font-lock.el are defined in Lisp |
1201 ; (put-text-property start next prop new object)))))) | 1181 ; (put-text-property start next prop new object)))))) |
1202 ; (setq start (text-property-not-all next end prop nil object))))) | 1182 ; (setq start (text-property-not-all next end prop nil object))))) |
1203 | 1183 |
1204 ;;; End of Additional text property functions. | 1184 ;;; End of Additional text property functions. |
1205 | 1185 |
1206 ;;; Regexp fontification functions. | 1186 ;;; Syntactic regexp fontification functions. |
1187 | |
1188 ;; These syntactic keyword pass functions are identical to those keyword pass | |
1189 ;; functions below, with the following exceptions; (a) they operate on | |
1190 ;; `font-lock-syntactic-keywords' of course, (b) they are all `defun' as speed | |
1191 ;; is less of an issue, (c) eval of property value does not occur JIT as speed | |
1192 ;; is less of an issue, (d) OVERRIDE cannot be `prepend' or `append' as it | |
1193 ;; makes no sense for `syntax-table' property values, (e) they do not do it | |
1194 ;; LOUDLY as it is not likely to be intensive. | |
1195 | |
1196 (defun font-lock-apply-syntactic-highlight (highlight) | |
1197 "Apply HIGHLIGHT following a match. | |
1198 HIGHLIGHT should be of the form MATCH-HIGHLIGHT, | |
1199 see `font-lock-syntactic-keywords'." | |
1200 (let* ((match (nth 0 highlight)) | |
1201 (start (match-beginning match)) (end (match-end match)) | |
1202 (value (nth 1 highlight)) | |
1203 (override (nth 2 highlight))) | |
1204 (unless (numberp (car value)) | |
1205 (setq value (eval value))) | |
1206 (cond ((not start) | |
1207 ;; No match but we might not signal an error. | |
1208 (or (nth 3 highlight) | |
1209 (error "No match %d in highlight %S" match highlight))) | |
1210 ((not override) | |
1211 ;; Cannot override existing fontification. | |
1212 (or (text-property-not-all start end 'syntax-table nil) | |
1213 (put-text-property start end 'syntax-table value))) | |
1214 ((eq override t) | |
1215 ;; Override existing fontification. | |
1216 (put-text-property start end 'syntax-table value)) | |
1217 ((eq override 'keep) | |
1218 ;; Keep existing fontification. | |
1219 (font-lock-fillin-text-property start end 'syntax-table value))))) | |
1220 | |
1221 (defun font-lock-fontify-syntactic-anchored-keywords (keywords limit) | |
1222 "Fontify according to KEYWORDS until LIMIT. | |
1223 KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords', | |
1224 LIMIT can be modified by the value of its PRE-MATCH-FORM." | |
1225 (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights | |
1226 ;; Evaluate PRE-MATCH-FORM. | |
1227 (pre-match-value (eval (nth 1 keywords)))) | |
1228 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line. | |
1229 (if (and (numberp pre-match-value) (> pre-match-value (point))) | |
1230 (setq limit pre-match-value) | |
1231 (save-excursion (end-of-line) (setq limit (point)))) | |
1232 (save-match-data | |
1233 ;; Find an occurrence of `matcher' before `limit'. | |
1234 (while (if (stringp matcher) | |
1235 (re-search-forward matcher limit t) | |
1236 (funcall matcher limit)) | |
1237 ;; Apply each highlight to this instance of `matcher'. | |
1238 (setq highlights lowdarks) | |
1239 (while highlights | |
1240 (font-lock-apply-syntactic-highlight (car highlights)) | |
1241 (setq highlights (cdr highlights))))) | |
1242 ;; Evaluate POST-MATCH-FORM. | |
1243 (eval (nth 2 keywords)))) | |
1244 | |
1245 (defun font-lock-fontify-syntactic-keywords-region (start end) | |
1246 "Fontify according to `font-lock-syntactic-keywords' between START and END. | |
1247 START should be at the beginning of a line." | |
1248 ;; If `font-lock-syntactic-keywords' is a symbol, get the real keywords. | |
1249 (when (symbolp font-lock-syntactic-keywords) | |
1250 (setq font-lock-syntactic-keywords (font-lock-eval-keywords | |
1251 font-lock-syntactic-keywords))) | |
1252 ;; If `font-lock-syntactic-keywords' is not compiled, compile it. | |
1253 (unless (eq (car font-lock-syntactic-keywords) t) | |
1254 (setq font-lock-syntactic-keywords (font-lock-compile-keywords | |
1255 font-lock-syntactic-keywords))) | |
1256 ;; Get down to business. | |
1257 (let ((case-fold-search font-lock-keywords-case-fold-search) | |
1258 (keywords (cdr font-lock-syntactic-keywords)) | |
1259 keyword matcher highlights) | |
1260 (while keywords | |
1261 ;; Find an occurrence of `matcher' from `start' to `end'. | |
1262 (setq keyword (car keywords) matcher (car keyword)) | |
1263 (goto-char start) | |
1264 (while (if (stringp matcher) | |
1265 (re-search-forward matcher end t) | |
1266 (funcall matcher end)) | |
1267 ;; Apply each highlight to this instance of `matcher', which may be | |
1268 ;; specific highlights or more keywords anchored to `matcher'. | |
1269 (setq highlights (cdr keyword)) | |
1270 (while highlights | |
1271 (if (numberp (car (car highlights))) | |
1272 (font-lock-apply-syntactic-highlight (car highlights)) | |
1273 (font-lock-fontify-syntactic-anchored-keywords (car highlights) | |
1274 end)) | |
1275 (setq highlights (cdr highlights)))) | |
1276 (setq keywords (cdr keywords))))) | |
1277 | |
1278 ;;; End of Syntactic regexp fontification functions. | |
1279 | |
1280 ;;; Syntactic fontification functions. | |
1281 | |
1282 ;; These record the parse state at a particular position, always the start of a | |
1283 ;; line. Used to make `font-lock-fontify-syntactically-region' faster. | |
1284 ;; Previously, `font-lock-cache-position' was just a buffer position. However, | |
1285 ;; under certain situations, this occasionally resulted in mis-fontification. | |
1286 ;; I think the "situations" were deletion with Lazy Lock mode's deferral. sm. | |
1287 (defvar font-lock-cache-state nil) | |
1288 (defvar font-lock-cache-position nil) | |
1289 | |
1290 (defun font-lock-fontify-syntactically-region (start end &optional loudly) | |
1291 "Put proper face on each string and comment between START and END. | |
1292 START should be at the beginning of a line." | |
1293 (let ((cache (marker-position font-lock-cache-position)) | |
1294 state string beg) | |
1295 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) | |
1296 (goto-char start) | |
1297 ;; | |
1298 ;; Find the state at the `beginning-of-line' before `start'. | |
1299 (if (eq start cache) | |
1300 ;; Use the cache for the state of `start'. | |
1301 (setq state font-lock-cache-state) | |
1302 ;; Find the state of `start'. | |
1303 (if (null font-lock-beginning-of-syntax-function) | |
1304 ;; Use the state at the previous cache position, if any, or | |
1305 ;; otherwise calculate from `point-min'. | |
1306 (if (or (null cache) (< start cache)) | |
1307 (setq state (parse-partial-sexp (point-min) start)) | |
1308 (setq state (parse-partial-sexp cache start nil nil | |
1309 font-lock-cache-state))) | |
1310 ;; Call the function to move outside any syntactic block. | |
1311 (funcall font-lock-beginning-of-syntax-function) | |
1312 (setq state (parse-partial-sexp (point) start))) | |
1313 ;; Cache the state and position of `start'. | |
1314 (setq font-lock-cache-state state) | |
1315 (set-marker font-lock-cache-position start)) | |
1316 ;; | |
1317 ;; If the region starts inside a string or comment, show the extent of it. | |
1318 (when (or (nth 3 state) (nth 4 state)) | |
1319 (setq string (nth 3 state) beg (point)) | |
1320 (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table)) | |
1321 (put-text-property beg (point) 'face | |
1322 (if string | |
1323 font-lock-string-face | |
1324 font-lock-comment-face))) | |
1325 ;; | |
1326 ;; Find each interesting place between here and `end'. | |
1327 (while (and (< (point) end) | |
1328 (progn | |
1329 (setq state (parse-partial-sexp (point) end nil nil state | |
1330 'syntax-table)) | |
1331 (or (nth 3 state) (nth 4 state)))) | |
1332 (setq string (nth 3 state) beg (nth 8 state)) | |
1333 (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table)) | |
1334 (put-text-property beg (point) 'face | |
1335 (if string | |
1336 font-lock-string-face | |
1337 font-lock-comment-face))))) | |
1338 | |
1339 ;;; End of Syntactic fontification functions. | |
1340 | |
1341 ;;; Keyword regexp fontification functions. | |
1207 | 1342 |
1208 (defsubst font-lock-apply-highlight (highlight) | 1343 (defsubst font-lock-apply-highlight (highlight) |
1209 "Apply HIGHLIGHT following a match. | 1344 "Apply HIGHLIGHT following a match. |
1210 HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'." | 1345 HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'." |
1211 (let* ((match (nth 0 highlight)) | 1346 (let* ((match (nth 0 highlight)) |
1257 (eval (nth 2 keywords)))) | 1392 (eval (nth 2 keywords)))) |
1258 | 1393 |
1259 (defun font-lock-fontify-keywords-region (start end &optional loudly) | 1394 (defun font-lock-fontify-keywords-region (start end &optional loudly) |
1260 "Fontify according to `font-lock-keywords' between START and END. | 1395 "Fontify according to `font-lock-keywords' between START and END. |
1261 START should be at the beginning of a line." | 1396 START should be at the beginning of a line." |
1262 (unless (eq (car-safe font-lock-keywords) t) | 1397 (unless (eq (car font-lock-keywords) t) |
1263 (setq font-lock-keywords (font-lock-compile-keywords font-lock-keywords))) | 1398 (setq font-lock-keywords (font-lock-compile-keywords font-lock-keywords))) |
1264 (let ((case-fold-search font-lock-keywords-case-fold-search) | 1399 (let ((case-fold-search font-lock-keywords-case-fold-search) |
1265 (keywords (cdr font-lock-keywords)) | 1400 (keywords (cdr font-lock-keywords)) |
1266 (bufname (buffer-name)) (count 0) | 1401 (bufname (buffer-name)) (count 0) |
1267 keyword matcher highlights) | 1402 keyword matcher highlights) |
1285 (font-lock-apply-highlight (car highlights)) | 1420 (font-lock-apply-highlight (car highlights)) |
1286 (font-lock-fontify-anchored-keywords (car highlights) end)) | 1421 (font-lock-fontify-anchored-keywords (car highlights) end)) |
1287 (setq highlights (cdr highlights)))) | 1422 (setq highlights (cdr highlights)))) |
1288 (setq keywords (cdr keywords))))) | 1423 (setq keywords (cdr keywords))))) |
1289 | 1424 |
1290 ;;; End of Regexp fontification functions. | 1425 ;;; End of Keyword regexp fontification functions. |
1291 | 1426 |
1292 ;; Various functions. | 1427 ;; Various functions. |
1293 | 1428 |
1294 (defun font-lock-compile-keywords (keywords) | 1429 (defun font-lock-compile-keywords (keywords) |
1295 ;; Compile KEYWORDS into the form (t KEYWORD ...) where KEYWORD is of the | 1430 ;; Compile KEYWORDS into the form (t KEYWORD ...) where KEYWORD is of the |
1314 (list (car keyword) (list 0 (cdr keyword)))) | 1449 (list (car keyword) (list 0 (cdr keyword)))) |
1315 ((nlistp (nth 1 keyword)) ; (MATCHER . HIGHLIGHT) | 1450 ((nlistp (nth 1 keyword)) ; (MATCHER . HIGHLIGHT) |
1316 (list (car keyword) (cdr keyword))) | 1451 (list (car keyword) (cdr keyword))) |
1317 (t ; (MATCHER HIGHLIGHT ...) | 1452 (t ; (MATCHER HIGHLIGHT ...) |
1318 keyword))) | 1453 keyword))) |
1454 | |
1455 (defun font-lock-eval-keywords (keywords) | |
1456 ;; Evalulate KEYWORDS if a function (funcall) or variable (eval) name. | |
1457 (if (symbolp keywords) | |
1458 (font-lock-eval-keywords (if (fboundp keywords) | |
1459 (funcall keywords) | |
1460 (eval keywords))) | |
1461 keywords)) | |
1319 | 1462 |
1320 (defun font-lock-value-in-major-mode (alist) | 1463 (defun font-lock-value-in-major-mode (alist) |
1321 ;; Return value in ALIST for `major-mode', or ALIST if it is not an alist. | 1464 ;; Return value in ALIST for `major-mode', or ALIST if it is not an alist. |
1322 ;; Structure is ((MAJOR-MODE . VALUE) ...) where MAJOR-MODE may be t. | 1465 ;; Structure is ((MAJOR-MODE . VALUE) ...) where MAJOR-MODE may be t. |
1323 (if (consp alist) | 1466 (if (consp alist) |
1355 (font-lock-choose-keywords (nth 0 defaults) | 1498 (font-lock-choose-keywords (nth 0 defaults) |
1356 (font-lock-value-in-major-mode font-lock-maximum-decoration))) | 1499 (font-lock-value-in-major-mode font-lock-maximum-decoration))) |
1357 (local (cdr (assq major-mode font-lock-keywords-alist)))) | 1500 (local (cdr (assq major-mode font-lock-keywords-alist)))) |
1358 ;; Regexp fontification? | 1501 ;; Regexp fontification? |
1359 (set (make-local-variable 'font-lock-keywords) | 1502 (set (make-local-variable 'font-lock-keywords) |
1360 (if (fboundp keywords) (funcall keywords) (eval keywords))) | 1503 (font-lock-compile-keywords (font-lock-eval-keywords keywords))) |
1361 ;; Local fontification? | 1504 ;; Local fontification? |
1362 (while local | 1505 (while local |
1363 (font-lock-add-keywords nil (car (car local)) (cdr (car local))) | 1506 (font-lock-add-keywords nil (car (car local)) (cdr (car local))) |
1364 (setq local (cdr local))) | 1507 (setq local (cdr local))) |
1365 ;; Syntactic fontification? | 1508 ;; Syntactic fontification? |
1391 ;; Variable alist? | 1534 ;; Variable alist? |
1392 (let ((alist (nthcdr 5 defaults))) | 1535 (let ((alist (nthcdr 5 defaults))) |
1393 (while alist | 1536 (while alist |
1394 (let ((variable (car (car alist))) (value (cdr (car alist)))) | 1537 (let ((variable (car (car alist))) (value (cdr (car alist)))) |
1395 (unless (boundp variable) | 1538 (unless (boundp variable) |
1396 (setq variable nil)) | 1539 (set variable nil)) |
1397 (set (make-local-variable variable) value) | 1540 (set (make-local-variable variable) value) |
1398 (setq alist (cdr alist)))))))) | 1541 (setq alist (cdr alist)))))))) |
1399 | 1542 |
1400 (defun font-lock-unset-defaults () | 1543 (defun font-lock-unset-defaults () |
1401 "Unset fontification defaults. See `font-lock-set-defaults'." | 1544 "Unset fontification defaults. See `font-lock-set-defaults'." |
1515 (t (:bold t))) | 1658 (t (:bold t))) |
1516 "Font Lock mode face used to highlight builtins." | 1659 "Font Lock mode face used to highlight builtins." |
1517 :group 'font-lock-highlighting-faces) | 1660 :group 'font-lock-highlighting-faces) |
1518 | 1661 |
1519 (defface font-lock-function-name-face | 1662 (defface font-lock-function-name-face |
1520 ;; Currently, Emacs/Custom does not support a :reverse or :invert spec. | |
1521 '((((class color) (background light)) (:foreground "Blue")) | 1663 '((((class color) (background light)) (:foreground "Blue")) |
1522 (((class color) (background dark)) (:foreground "LightSkyBlue")) | 1664 (((class color) (background dark)) (:foreground "LightSkyBlue")) |
1523 (t ;(:reverse t :bold t) | 1665 (t (:inverse-video t :bold t))) |
1524 (:italic t :bold t))) | |
1525 "Font Lock mode face used to highlight function names." | 1666 "Font Lock mode face used to highlight function names." |
1526 :group 'font-lock-highlighting-faces) | 1667 :group 'font-lock-highlighting-faces) |
1527 | 1668 |
1528 (defface font-lock-variable-name-face | 1669 (defface font-lock-variable-name-face |
1529 '((((class grayscale) (background light)) | 1670 '((((class grayscale) (background light)) |
1555 (t (:bold t :underline t))) | 1696 (t (:bold t :underline t))) |
1556 "Font Lock mode face used to highlight references." | 1697 "Font Lock mode face used to highlight references." |
1557 :group 'font-lock-highlighting-faces) | 1698 :group 'font-lock-highlighting-faces) |
1558 | 1699 |
1559 (defface font-lock-warning-face | 1700 (defface font-lock-warning-face |
1560 ;; Currently, Emacs/Custom does not support a :reverse or :invert spec. | |
1561 '((((class color) (background light)) (:foreground "Red" :bold t)) | 1701 '((((class color) (background light)) (:foreground "Red" :bold t)) |
1562 (((class color) (background dark)) (:foreground "Pink" :bold t)) | 1702 (((class color) (background dark)) (:foreground "Pink" :bold t)) |
1563 (t ;(:reverse t :bold t) | 1703 (t (:inverse-video t :bold t))) |
1564 (:italic t :bold t))) | |
1565 "Font Lock mode face used to highlight warnings." | 1704 "Font Lock mode face used to highlight warnings." |
1566 :group 'font-lock-highlighting-faces) | 1705 :group 'font-lock-highlighting-faces) |
1567 | 1706 |
1568 ;;; End of Colour etc. support. | 1707 ;;; End of Colour etc. support. |
1569 | 1708 |
1680 (defun font-lock-match-c-style-declaration-item-and-skip-to-next (limit) | 1819 (defun font-lock-match-c-style-declaration-item-and-skip-to-next (limit) |
1681 "Match, and move over, any declaration/definition item after point. | 1820 "Match, and move over, any declaration/definition item after point. |
1682 Matches after point, but ignores leading whitespace and `*' characters. | 1821 Matches after point, but ignores leading whitespace and `*' characters. |
1683 Does not move further than LIMIT. | 1822 Does not move further than LIMIT. |
1684 | 1823 |
1685 The expected syntax of a declaration/definition item is `word', possibly ending | 1824 The expected syntax of a declaration/definition item is `word' (preceded by |
1686 with optional whitespace and a `('. Everything following the item (but | 1825 optional whitespace and `*' characters and proceeded by optional whitespace) |
1687 belonging to it) is expected to by skip-able by `scan-sexps', and items are | 1826 optionally followed by a `('. Everything following the item (but belonging to |
1688 expected to be separated with a `,' and to be terminated with a `;'. | 1827 it) is expected to by skip-able by `scan-sexps', and items are expected to be |
1828 separated with a `,' and to be terminated with a `;'. | |
1689 | 1829 |
1690 Thus the regexp matches after point: word ( | 1830 Thus the regexp matches after point: word ( |
1691 ^^^^ ^ | 1831 ^^^^ ^ |
1692 Where the match subexpressions are: 1 2 | 1832 Where the match subexpressions are: 1 2 |
1693 | 1833 |
1705 ;; Move over any item value, etc., to the next item. | 1845 ;; Move over any item value, etc., to the next item. |
1706 (while (not (looking-at "[ \t]*\\(\\(,\\)\\|;\\|$\\)")) | 1846 (while (not (looking-at "[ \t]*\\(\\(,\\)\\|;\\|$\\)")) |
1707 (goto-char (or (scan-sexps (point) 1) (point-max)))) | 1847 (goto-char (or (scan-sexps (point) 1) (point-max)))) |
1708 (goto-char (match-end 2))) | 1848 (goto-char (match-end 2))) |
1709 (error t))))) | 1849 (error t))))) |
1710 | |
1711 (defun font-lock-keyword-depth (keyword) | |
1712 "Return the depth of KEYWORD regexp. | |
1713 This means the number of parenthesized expressions." | |
1714 (let ((count 0) start) | |
1715 (while (string-match "\\\\(" keyword start) | |
1716 (setq count (1+ count) start (match-end 0))) | |
1717 count)) | |
1718 | 1850 |
1719 | 1851 |
1720 (defconst lisp-font-lock-keywords-1 | 1852 (defconst lisp-font-lock-keywords-1 |
1721 (eval-when-compile | 1853 (eval-when-compile |
1722 (list | 1854 (list |
1752 (append lisp-font-lock-keywords-1 | 1884 (append lisp-font-lock-keywords-1 |
1753 (eval-when-compile | 1885 (eval-when-compile |
1754 (list | 1886 (list |
1755 ;; | 1887 ;; |
1756 ;; Control structures. Emacs Lisp forms. | 1888 ;; Control structures. Emacs Lisp forms. |
1757 (cons (concat "(\\(" | 1889 (cons (concat |
1758 ; (make-regexp | 1890 "(" (regexp-opt |
1759 ; '("cond" "if" "while" "let\\*?" "prog[nv12*]?" "catch" "throw" | 1891 '("cond" "if" "while" "catch" "throw" "let" "let*" |
1760 ; "inline" "save-restriction" "save-excursion" "save-window-excursion" | 1892 "prog" "progn" "progv" "prog1" "prog2" "prog*" |
1761 ; "save-selected-window" "save-match-data" "save-current-buffer" | 1893 "inline" "save-restriction" "save-excursion" |
1762 ; "unwind-protect" "condition-case" "track-mouse" "dont-compile" | 1894 "save-window-excursion" "save-selected-window" |
1763 ; "eval-after-load" "eval-and-compile" "eval-when" "eval-when-compile" | 1895 "save-match-data" "save-current-buffer" "unwind-protect" |
1764 ; "with-output-to-temp-buffer" "with-timeout" "with-current-buffer" | 1896 "condition-case" "track-mouse" "dont-compile" |
1765 ; "with-temp-buffer" "with-temp-file")) | 1897 "eval-after-load" "eval-and-compile" "eval-when-compile" |
1766 "c\\(atch\\|ond\\(\\|ition-case\\)\\)\\|dont-compile\\|" | 1898 "eval-when" "with-output-to-temp-buffer" "with-timeout" |
1767 "eval-\\(a\\(fter-load\\|nd-compile\\)\\|" | 1899 "with-current-buffer" "with-temp-buffer" |
1768 "when\\(\\|-compile\\)\\)\\|" | 1900 "with-temp-file") t) |
1769 "i\\(f\\|nline\\)\\|let\\*?\\|prog[nv12*]?\\|" | 1901 "\\>") |
1770 "save-\\(current-buffer\\|excursion\\|match-data\\|" | |
1771 "restriction\\|selected-window\\|window-excursion\\)\\|" | |
1772 "t\\(hrow\\|rack-mouse\\)\\|unwind-protect\\|" | |
1773 "w\\(hile\\|ith-\\(current-buffer\\|" | |
1774 "output-to-temp-buffer\\|" | |
1775 "t\\(emp-\\(buffer\\|file\\)\\|imeout\\)\\)\\)" | |
1776 "\\)\\>") | |
1777 1) | 1902 1) |
1778 ;; | 1903 ;; |
1779 ;; Control structures. Common Lisp forms. | 1904 ;; Control structures. Common Lisp forms. |
1780 (cons (concat "(\\(" | 1905 (cons (concat |
1781 ; (make-regexp | 1906 "(" (regexp-opt |
1782 ; '("when" "unless" "case" "ecase" "typecase" "etypecase" | 1907 '("when" "unless" "case" "ecase" "typecase" "etypecase" |
1783 ; "loop" "do\\*?" "dotimes" "dolist" | 1908 "loop" "do" "do*" "dotimes" "dolist" |
1784 ; "proclaim" "declaim" "declare" | 1909 "proclaim" "declaim" "declare" |
1785 ; "lexical-let\\*?" "flet" "labels" "return" "return-from")) | 1910 "lexical-let" "lexical-let*" "flet" "labels" |
1786 "case\\|d\\(ecla\\(im\\|re\\)\\|o\\(\\*?\\|" | 1911 "return" "return-from") t) |
1787 "list\\|times\\)\\)\\|e\\(case\\|typecase\\)\\|flet\\|" | 1912 "\\>") |
1788 "l\\(abels\\|exical-let\\*?\\|oop\\)\\|proclaim\\|" | |
1789 "return\\(\\|-from\\)\\|typecase\\|unless\\|when" | |
1790 "\\)\\>") | |
1791 1) | 1913 1) |
1792 ;; | 1914 ;; |
1793 ;; Feature symbols as references. | 1915 ;; Feature symbols as references. |
1794 '("(\\(featurep\\|provide\\|require\\)\\>[ \t']*\\(\\sw+\\)?" | 1916 '("(\\(featurep\\|provide\\|require\\)\\>[ \t']*\\(\\sw+\\)?" |
1795 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) | 1917 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) |
1835 ((match-beginning 6) font-lock-variable-name-face) | 1957 ((match-beginning 6) font-lock-variable-name-face) |
1836 (t font-lock-type-face)) | 1958 (t font-lock-type-face)) |
1837 nil t)) | 1959 nil t)) |
1838 ;; | 1960 ;; |
1839 ;; Control structures. | 1961 ;; Control structures. |
1840 ;(make-regexp '("begin" "call-with-current-continuation" "call/cc" | |
1841 ; "call-with-input-file" "call-with-output-file" "case" "cond" | |
1842 ; "do" "else" "for-each" "if" "lambda" | |
1843 ; "let\\*?" "let-syntax" "letrec" "letrec-syntax" | |
1844 ; ;; Hannes Haug <hannes.haug@student.uni-tuebingen.de> wants: | |
1845 ; "and" "or" "delay" | |
1846 ; ;; Stefan Monnier <stefan.monnier@epfl.ch> says don't bother: | |
1847 ; ;;"quasiquote" "quote" "unquote" "unquote-splicing" | |
1848 ; "map" "syntax" "syntax-rules")) | |
1849 (cons | 1962 (cons |
1850 (concat "(\\(" | 1963 (concat |
1851 "and\\|begin\\|c\\(a\\(ll\\(-with-\\(current-continuation\\|" | 1964 "(" (regexp-opt |
1852 "input-file\\|output-file\\)\\|/cc\\)\\|se\\)\\|ond\\)\\|" | 1965 '("begin" "call-with-current-continuation" "call/cc" |
1853 "d\\(elay\\|o\\)\\|else\\|for-each\\|if\\|" | 1966 "call-with-input-file" "call-with-output-file" "case" "cond" |
1854 "l\\(ambda\\|et\\(-syntax\\|\\*?\\|rec\\(\\|-syntax\\)\\)\\)\\|" | 1967 "do" "else" "for-each" "if" "lambda" |
1855 "map\\|or\\|syntax\\(\\|-rules\\)" | 1968 "let" "let*" "let-syntax" "letrec" "letrec-syntax" |
1856 "\\)\\>") 1) | 1969 ;; Hannes Haug <hannes.haug@student.uni-tuebingen.de> wants: |
1970 "and" "or" "delay" | |
1971 ;; Stefan Monnier <stefan.monnier@epfl.ch> says don't bother: | |
1972 ;;"quasiquote" "quote" "unquote" "unquote-splicing" | |
1973 "map" "syntax" "syntax-rules") t) | |
1974 "\\>") 1) | |
1857 ;; | 1975 ;; |
1858 ;; David Fox <fox@graphics.cs.nyu.edu> for SOS/STklos class specifiers. | 1976 ;; David Fox <fox@graphics.cs.nyu.edu> for SOS/STklos class specifiers. |
1859 '("\\<<\\sw+>\\>" . font-lock-type-face) | 1977 '("\\<<\\sw+>\\>" . font-lock-type-face) |
1860 ;; | 1978 ;; |
1861 ;; Scheme `:' keywords as references. | 1979 ;; Scheme `:' keywords as references. |
1974 (defconst c-font-lock-keywords-3 nil | 2092 (defconst c-font-lock-keywords-3 nil |
1975 "Gaudy level highlighting for C mode. | 2093 "Gaudy level highlighting for C mode. |
1976 See also `c-font-lock-extra-types'.") | 2094 See also `c-font-lock-extra-types'.") |
1977 | 2095 |
1978 (let* ((c-keywords | 2096 (let* ((c-keywords |
1979 ; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while") | 2097 (eval-when-compile |
1980 "break\\|continue\\|do\\|else\\|for\\|if\\|return\\|switch\\|while") | 2098 (regexp-opt '("break" "continue" "do" "else" "for" "if" "return" |
2099 "switch" "while") t))) | |
1981 (c-type-types | 2100 (c-type-types |
1982 ; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum" | |
1983 ; "signed" "unsigned" "short" "long" "int" "char" "float" "double" | |
1984 ; "void" "volatile" "const") | |
1985 `(mapconcat 'identity | 2101 `(mapconcat 'identity |
1986 (cons | 2102 (cons |
1987 (,@ (concat "auto\\|c\\(har\\|onst\\)\\|double\\|" | 2103 (,@ (eval-when-compile |
1988 "e\\(num\\|xtern\\)\\|float\\|int\\|long\\|register\\|" | 2104 (regexp-opt |
1989 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|typedef\\|" | 2105 '("auto" "extern" "register" "static" "typedef" "struct" |
1990 "un\\(ion\\|signed\\)\\|vo\\(id\\|latile\\)")) | 2106 "union" "enum" "signed" "unsigned" "short" "long" |
2107 "int" "char" "float" "double" "void" "volatile" "const")))) | |
1991 c-font-lock-extra-types) | 2108 c-font-lock-extra-types) |
1992 "\\|")) | 2109 "\\|")) |
1993 (c-type-depth `(font-lock-keyword-depth (,@ c-type-types))) | 2110 (c-type-depth `(regexp-opt-depth (,@ c-type-types))) |
1994 ) | 2111 ) |
1995 (setq c-font-lock-keywords-1 | 2112 (setq c-font-lock-keywords-1 |
1996 (list | 2113 (list |
1997 ;; | 2114 ;; |
1998 ;; These are all anchored at the beginning of line for speed. | 2115 ;; These are all anchored at the beginning of line for speed. |
2030 ;; Fontify all type specifiers. | 2147 ;; Fontify all type specifiers. |
2031 `(eval . | 2148 `(eval . |
2032 (cons (concat "\\<\\(" (,@ c-type-types) "\\)\\>") 'font-lock-type-face)) | 2149 (cons (concat "\\<\\(" (,@ c-type-types) "\\)\\>") 'font-lock-type-face)) |
2033 ;; | 2150 ;; |
2034 ;; Fontify all builtin keywords (except case, default and goto; see below). | 2151 ;; Fontify all builtin keywords (except case, default and goto; see below). |
2035 (concat "\\<\\(" c-keywords "\\)\\>") | 2152 (concat "\\<" c-keywords "\\>") |
2036 ;; | 2153 ;; |
2037 ;; Fontify case/goto keywords and targets, and case default/goto tags. | 2154 ;; Fontify case/goto keywords and targets, and case default/goto tags. |
2038 '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" | 2155 '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" |
2039 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) | 2156 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) |
2040 ;; Anders Lindgren <andersl@csd.uu.se> points out that it is quicker to use | 2157 ;; Anders Lindgren <andersl@csd.uu.se> points out that it is quicker to use |
2117 (concat | 2234 (concat |
2118 ;; Skip any leading whitespace. | 2235 ;; Skip any leading whitespace. |
2119 "[ \t*&]*" | 2236 "[ \t*&]*" |
2120 ;; This is `c++-type-spec' from below. (Hint hint!) | 2237 ;; This is `c++-type-spec' from below. (Hint hint!) |
2121 "\\(\\sw+\\)" ; The instance? | 2238 "\\(\\sw+\\)" ; The instance? |
2122 "\\(<\\(\\sw+\\)[ \t*&]*>\\)?" ; Or template? | 2239 "\\([ \t]*<\\([^>\n]+\\)[ \t*&]*>\\)?" ; Or template? |
2123 "\\([ \t]*::[ \t*~]*\\(\\sw+\\)\\)?" ; Or member? | 2240 "\\([ \t]*::[ \t*~]*\\(\\sw+\\)\\)?" ; Or member? |
2124 ;; Match any trailing parenthesis. | 2241 ;; Match any trailing parenthesis. |
2125 "[ \t]*\\((\\)?"))) | 2242 "[ \t]*\\((\\)?"))) |
2126 (save-match-data | 2243 (save-match-data |
2127 (condition-case nil | 2244 (condition-case nil |
2134 (goto-char (or (scan-sexps (point) 1) (point-max)))) | 2251 (goto-char (or (scan-sexps (point) 1) (point-max)))) |
2135 (goto-char (match-end 2))) | 2252 (goto-char (match-end 2))) |
2136 (error t))))) | 2253 (error t))))) |
2137 | 2254 |
2138 (let* ((c++-keywords | 2255 (let* ((c++-keywords |
2139 ; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while" | 2256 (eval-when-compile |
2140 ; "asm" "catch" "delete" "new" "operator" "sizeof" "this" "throw" "try" | 2257 (regexp-opt |
2141 ; ;; Eric Hopper <hopper@omnifarious.mn.org> says these are new. | 2258 '("break" "continue" "do" "else" "for" "if" "return" "switch" |
2142 ; "static_cast" "dynamic_cast" "const_cast" "reinterpret_cast") | 2259 "while" "asm" "catch" "delete" "new" "operator" "sizeof" "this" |
2143 (concat "asm\\|break\\|c\\(atch\\|on\\(st_cast\\|tinue\\)\\)\\|" | 2260 "throw" "try" |
2144 "d\\(elete\\|o\\|ynamic_cast\\)\\|else\\|for\\|if\\|new\\|" | 2261 ;; Eric Hopper <hopper@omnifarious.mn.org> says these are new. |
2145 "operator\\|re\\(interpret_cast\\|turn\\)\\|" | 2262 "static_cast" "dynamic_cast" "const_cast" "reinterpret_cast") t))) |
2146 "s\\(izeof\\|tatic_cast\\|" | |
2147 "witch\\)\\|t\\(h\\(is\\|row\\)\\|ry\\)\\|while")) | |
2148 (c++-operators | 2263 (c++-operators |
2149 (mapconcat 'identity | 2264 (mapconcat 'identity |
2150 (mapcar 'regexp-quote | 2265 (mapcar 'regexp-quote |
2151 ;; Taken from Stroustrup, minus keywords otherwise fontified. | 2266 ;; Taken from Stroustrup, minus keywords otherwise fontified. |
2152 (sort '("+" "-" "*" "/" "%" "^" "&" "|" "~" "!" "=" "<" ">" | 2267 (sort '("+" "-" "*" "/" "%" "^" "&" "|" "~" "!" "=" "<" ">" |
2154 ">>=" "<<=" "==" "!=" "<=" ">=" "&&" "||" "++" "--" | 2269 ">>=" "<<=" "==" "!=" "<=" ">=" "&&" "||" "++" "--" |
2155 "->*" "," "->" "[]" "()") | 2270 "->*" "," "->" "[]" "()") |
2156 #'(lambda (a b) (> (length a) (length b))))) | 2271 #'(lambda (a b) (> (length a) (length b))))) |
2157 "\\|")) | 2272 "\\|")) |
2158 (c++-type-types | 2273 (c++-type-types |
2159 ; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum" | |
2160 ; "signed" "unsigned" "short" "long" "int" "char" "float" "double" | |
2161 ; "void" "volatile" "const" "inline" "friend" "bool" | |
2162 ; "virtual" "complex" "template" | |
2163 ; ;; Eric Hopper <hopper@omnifarious.mn.org> says these are new. | |
2164 ; "namespace" "using") | |
2165 `(mapconcat 'identity | 2274 `(mapconcat 'identity |
2166 (cons | 2275 (cons |
2167 (,@ (concat "auto\\|bool\\|c\\(har\\|o\\(mplex\\|nst\\)\\)\\|" | 2276 (,@ (eval-when-compile |
2168 "double\\|e\\(num\\|xtern\\)\\|f\\(loat\\|riend\\)\\|" | 2277 (regexp-opt |
2169 "in\\(line\\|t\\)\\|long\\|namespace\\|register\\|" | 2278 '("auto" "extern" "register" "static" "typedef" "struct" |
2170 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|" | 2279 "union" "enum" "signed" "unsigned" "short" "long" |
2171 "t\\(emplate\\|ypedef\\)\\|" | 2280 "int" "char" "float" "double" "void" "volatile" "const" |
2172 "u\\(n\\(ion\\|signed\\)\\|sing\\)\\|" | 2281 "inline" "friend" "bool" "virtual" "complex" "template" |
2173 "v\\(irtual\\|o\\(id\\|latile\\)\\)")) ; 12 ()s deep. | 2282 "namespace" "using")))) |
2174 c++-font-lock-extra-types) | 2283 c++-font-lock-extra-types) |
2175 "\\|")) | 2284 "\\|")) |
2176 ;; | 2285 ;; |
2177 ;; A brave attempt to match templates following a type and/or match | 2286 ;; A brave attempt to match templates following a type and/or match |
2178 ;; class membership. See and sync the above function | 2287 ;; class membership. See and sync the above function |
2179 ;; `font-lock-match-c++-style-declaration-item-and-skip-to-next'. | 2288 ;; `font-lock-match-c++-style-declaration-item-and-skip-to-next'. |
2180 (c++-type-suffix (concat "\\(<\\(\\sw+\\)[ \t*&]*>\\)?" | 2289 (c++-type-suffix (concat "\\([ \t]*<\\([^>\n]+\\)[ \t*&]*>\\)?" |
2181 "\\([ \t]*::[ \t*~]*\\(\\sw+\\)\\)?")) | 2290 "\\([ \t]*::[ \t*~]*\\(\\sw+\\)\\)?")) |
2182 ;; If the string is a type, it may be followed by the cruft above. | 2291 ;; If the string is a type, it may be followed by the cruft above. |
2183 (c++-type-spec (concat "\\(\\sw+\\)\\>" c++-type-suffix)) | 2292 (c++-type-spec (concat "\\(\\sw+\\)\\>" c++-type-suffix)) |
2184 ;; | 2293 ;; |
2185 ;; Parenthesis depth of user-defined types not forgetting their cruft. | 2294 ;; Parenthesis depth of user-defined types not forgetting their cruft. |
2186 (c++-type-depth `(font-lock-keyword-depth | 2295 (c++-type-depth `(regexp-opt-depth |
2187 (concat (,@ c++-type-types) (,@ c++-type-suffix)))) | 2296 (concat (,@ c++-type-types) (,@ c++-type-suffix)))) |
2188 ) | 2297 ) |
2189 (setq c++-font-lock-keywords-1 | 2298 (setq c++-font-lock-keywords-1 |
2190 (append | 2299 (append |
2191 ;; | 2300 ;; |
2232 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:\\($\\|[^:]\\)" | 2341 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:\\($\\|[^:]\\)" |
2233 (beginning-of-line) (end-of-line) | 2342 (beginning-of-line) (end-of-line) |
2234 (1 font-lock-reference-face))) | 2343 (1 font-lock-reference-face))) |
2235 ;; | 2344 ;; |
2236 ;; Fontify other builtin keywords. | 2345 ;; Fontify other builtin keywords. |
2237 (cons (concat "\\<\\(" c++-keywords "\\)\\>") 'font-lock-keyword-face) | 2346 (concat "\\<" c++-keywords "\\>") |
2238 ;; | 2347 ;; |
2239 ;; Eric Hopper <hopper@omnifarious.mn.org> says `true' and `false' are new. | 2348 ;; Eric Hopper <hopper@omnifarious.mn.org> says `true' and `false' are new. |
2240 '("\\<\\(false\\|true\\)\\>" . font-lock-reference-face) | 2349 '("\\<\\(false\\|true\\)\\>" . font-lock-reference-face) |
2241 ))) | 2350 ))) |
2242 | 2351 |
2310 See also `objc-font-lock-extra-types'.") | 2419 See also `objc-font-lock-extra-types'.") |
2311 | 2420 |
2312 ;; Regexps written with help from Stephen Peters <speters@us.oracle.com> and | 2421 ;; Regexps written with help from Stephen Peters <speters@us.oracle.com> and |
2313 ;; Jacques Duthen Prestataire <duthen@cegelec-red.fr>. | 2422 ;; Jacques Duthen Prestataire <duthen@cegelec-red.fr>. |
2314 (let* ((objc-keywords | 2423 (let* ((objc-keywords |
2315 ; '("break" "continue" "do" "else" "for" "if" "return" "switch" "while" | 2424 (eval-when-compile |
2316 ; "sizeof" "self" "super") | 2425 (regexp-opt '("break" "continue" "do" "else" "for" "if" "return" |
2317 (concat "break\\|continue\\|do\\|else\\|for\\|if\\|return\\|" | 2426 "switch" "while" "sizeof" "self" "super") t))) |
2318 "s\\(elf\\|izeof\\|uper\\|witch\\)\\|while")) | |
2319 (objc-type-types | 2427 (objc-type-types |
2320 `(mapconcat 'identity | 2428 `(mapconcat 'identity |
2321 (cons | 2429 (cons |
2322 ; '("auto" "extern" "register" "static" "typedef" "struct" "union" | 2430 (,@ (eval-when-compile |
2323 ; "enum" "signed" "unsigned" "short" "long" "int" "char" | 2431 (regexp-opt |
2324 ; "float" "double" "void" "volatile" "const" | 2432 '("auto" "extern" "register" "static" "typedef" "struct" |
2325 ; "id" "oneway" "in" "out" "inout" "bycopy" "byref") | 2433 "union" "enum" "signed" "unsigned" "short" "long" |
2326 (,@ (concat "auto\\|by\\(copy\\|ref\\)\\|c\\(har\\|onst\\)\\|" | 2434 "int" "char" "float" "double" "void" "volatile" "const" |
2327 "double\\|e\\(num\\|xtern\\)\\|float\\|" | 2435 "id" "oneway" "in" "out" "inout" "bycopy" "byref")))) |
2328 "i\\([dn]\\|n\\(out\\|t\\)\\)\\|long\\|" | |
2329 "o\\(neway\\|ut\\)\\|register\\|s\\(hort\\|igned\\|" | |
2330 "t\\(atic\\|ruct\\)\\)\\|typedef\\|" | |
2331 "un\\(ion\\|signed\\)\\|vo\\(id\\|latile\\)")) | |
2332 objc-font-lock-extra-types) | 2436 objc-font-lock-extra-types) |
2333 "\\|")) | 2437 "\\|")) |
2334 (objc-type-depth `(font-lock-keyword-depth (,@ objc-type-types))) | 2438 (objc-type-depth `(regexp-opt-depth (,@ objc-type-types))) |
2335 ) | 2439 ) |
2336 (setq objc-font-lock-keywords-1 | 2440 (setq objc-font-lock-keywords-1 |
2337 (append | 2441 (append |
2338 ;; | 2442 ;; |
2339 ;; The list `c-font-lock-keywords-1' less that for function names. | 2443 ;; The list `c-font-lock-keywords-1' less that for function names. |
2375 `(eval . | 2479 `(eval . |
2376 (cons (concat "\\<\\(" (,@ objc-type-types) "\\)\\>") | 2480 (cons (concat "\\<\\(" (,@ objc-type-types) "\\)\\>") |
2377 'font-lock-type-face)) | 2481 'font-lock-type-face)) |
2378 ;; | 2482 ;; |
2379 ;; Fontify all builtin keywords (except case, default and goto; see below). | 2483 ;; Fontify all builtin keywords (except case, default and goto; see below). |
2380 (concat "\\<\\(" objc-keywords "\\)\\>") | 2484 (concat "\\<" objc-keywords "\\>") |
2381 ;; | 2485 ;; |
2382 ;; Fontify case/goto keywords and targets, and case default/goto tags. | 2486 ;; Fontify case/goto keywords and targets, and case default/goto tags. |
2383 '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" | 2487 '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" |
2384 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) | 2488 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) |
2385 ;; Fontify tags iff sole statement on line, otherwise we detect selectors. | 2489 ;; Fontify tags iff sole statement on line, otherwise we detect selectors. |
2452 See also `java-font-lock-extra-types'.") | 2556 See also `java-font-lock-extra-types'.") |
2453 | 2557 |
2454 ;; Regexps written with help from Fred White <fwhite@bbn.com> and | 2558 ;; Regexps written with help from Fred White <fwhite@bbn.com> and |
2455 ;; Anders Lindgren <andersl@csd.uu.se>. | 2559 ;; Anders Lindgren <andersl@csd.uu.se>. |
2456 (let* ((java-keywords | 2560 (let* ((java-keywords |
2457 (concat "\\<\\(" | 2561 (eval-when-compile |
2458 ; '("catch" "do" "else" "super" "this" "finally" "for" "if" | 2562 (regexp-opt |
2459 ;; ;; Anders Lindgren <andersl@csd.uu.se> says these have gone. | 2563 '("catch" "do" "else" "super" "this" "finally" "for" "if" |
2460 ;; "cast" "byvalue" "future" "generic" "operator" "var" | 2564 ;; Anders Lindgren <andersl@csd.uu.se> says these have gone. |
2461 ;; "inner" "outer" "rest" | 2565 ;; "cast" "byvalue" "future" "generic" "operator" "var" |
2462 ; "interface" "return" "switch" "throw" "try" "while") | 2566 ;; "inner" "outer" "rest" |
2463 "catch\\|do\\|else\\|f\\(inally\\|or\\)\\|" | 2567 "interface" "return" "switch" "throw" "try" "while") t))) |
2464 "i\\(f\\|nterface\\)\\|return\\|s\\(uper\\|witch\\)\\|" | |
2465 "t\\(h\\(is\\|row\\)\\|ry\\)\\|while" | |
2466 "\\)\\>")) | |
2467 ;; | 2568 ;; |
2468 ;; These are immediately followed by an object name. | 2569 ;; These are immediately followed by an object name. |
2469 (java-minor-types | 2570 (java-minor-types |
2470 (mapconcat 'identity | 2571 (eval-when-compile |
2471 '("boolean" "char" "byte" "short" "int" "long" | 2572 (regexp-opt '("boolean" "char" "byte" "short" "int" "long" |
2472 "float" "double" "void") | 2573 "float" "double" "void")))) |
2473 "\\|")) | |
2474 ;; | 2574 ;; |
2475 ;; These are eventually followed by an object name. | 2575 ;; These are eventually followed by an object name. |
2476 (java-major-types | 2576 (java-major-types |
2477 ; '("abstract" "const" "final" "synchronized" "transient" "static" | 2577 (eval-when-compile |
2478 ;; ;; Anders Lindgren <andersl@csd.uu.se> says this has gone. | 2578 (regexp-opt |
2479 ;; "threadsafe" | 2579 '("abstract" "const" "final" "synchronized" "transient" "static" |
2480 ; "volatile" "public" "private" "protected" "native") | 2580 ;; Anders Lindgren <andersl@csd.uu.se> says this has gone. |
2481 (concat "abstract\\|const\\|final\\|native\\|" | 2581 ;; "threadsafe" |
2482 "p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|" | 2582 "volatile" "public" "private" "protected" "native")))) |
2483 "s\\(tatic\\|ynchronized\\)\\|transient\\|volatile")) | |
2484 ;; | 2583 ;; |
2485 ;; Random types immediately followed by an object name. | 2584 ;; Random types immediately followed by an object name. |
2486 (java-other-types | 2585 (java-other-types |
2487 '(mapconcat 'identity (cons "\\sw+\\.\\sw+" java-font-lock-extra-types) | 2586 '(mapconcat 'identity (cons "\\sw+\\.\\sw+" java-font-lock-extra-types) |
2488 "\\|")) | 2587 "\\|")) |
2489 (java-other-depth `(font-lock-keyword-depth (,@ java-other-types))) | 2588 (java-other-depth `(regexp-opt-depth (,@ java-other-types))) |
2490 ) | 2589 ) |
2491 (setq java-font-lock-keywords-1 | 2590 (setq java-font-lock-keywords-1 |
2492 (list | 2591 (list |
2493 ;; | 2592 ;; |
2494 ;; Fontify class names. | 2593 ;; Fontify class names. |
2495 '("\\<\\(class\\)\\>[ \t]*\\(\\sw+\\)?" | 2594 '("\\<\\(class\\)\\>[ \t]*\\(\\sw+\\)?" |
2507 ;; Fontify all builtin type specifiers. | 2606 ;; Fontify all builtin type specifiers. |
2508 (cons (concat "\\<\\(" java-minor-types "\\|" java-major-types "\\)\\>") | 2607 (cons (concat "\\<\\(" java-minor-types "\\|" java-major-types "\\)\\>") |
2509 'font-lock-type-face) | 2608 'font-lock-type-face) |
2510 ;; | 2609 ;; |
2511 ;; Fontify all builtin keywords (except below). | 2610 ;; Fontify all builtin keywords (except below). |
2512 (concat "\\<\\(" java-keywords "\\)\\>") | 2611 (concat "\\<" java-keywords "\\>") |
2513 ;; | 2612 ;; |
2514 ;; Fontify keywords and targets, and case default/goto tags. | 2613 ;; Fontify keywords and targets, and case default/goto tags. |
2515 (list "\\<\\(break\\|case\\|continue\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" | 2614 (list "\\<\\(break\\|case\\|continue\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?" |
2516 '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t)) | 2615 '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t)) |
2517 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:" | 2616 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:" |