Mercurial > hg > xemacs-beta
comparison lisp/packages/font-lock.el @ 30:ec9a17fef872 r19-15b98
Import from CVS: tag r19-15b98
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:52:29 +0200 |
parents | 441bb1e64a06 |
children | 1a767b41a199 |
comparison
equal
deleted
inserted
replaced
29:7976500f47f9 | 30:ec9a17fef872 |
---|---|
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> | |
8 ;; Then (partially) synched with FSF 19.30, leading to: | 9 ;; Then (partially) synched with FSF 19.30, leading to: |
9 ;; Next Author: RMS | 10 ;; Next Author: RMS |
10 ;; Next Author: Simon Marshall <simon@gnu.ai.mit.edu> | 11 ;; Next Author: Simon Marshall <simon@gnu.ai.mit.edu> |
11 ;; Latest XEmacs Author: Ben Wing | 12 ;; Latest XEmacs Author: Ben Wing |
12 ;; Maintainer: FSF (well, maybe) | 13 ;; Maintainer: FSF (well, maybe) |
261 MATCHER | 262 MATCHER |
262 (MATCHER . MATCH) | 263 (MATCHER . MATCH) |
263 (MATCHER . FACENAME) | 264 (MATCHER . FACENAME) |
264 (MATCHER . HIGHLIGHT) | 265 (MATCHER . HIGHLIGHT) |
265 (MATCHER HIGHLIGHT ...) | 266 (MATCHER HIGHLIGHT ...) |
267 (eval . FORM) | |
266 | 268 |
267 where HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED. | 269 where HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED. |
268 | 270 |
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 | |
269 For highlighting single items, typically only MATCH-HIGHLIGHT is required. | 276 For highlighting single items, typically only MATCH-HIGHLIGHT is required. |
270 However, if an item or (typically) items is to be hightlighted following the | 277 However, if an item or (typically) items is to be highlighted following the |
271 instance of another item (the anchor) then MATCH-ANCHORED may be required. | 278 instance of another item (the anchor) then MATCH-ANCHORED may be required. |
272 | 279 |
273 MATCH-HIGHLIGHT should be of the form: | 280 MATCH-HIGHLIGHT should be of the form: |
274 | 281 |
275 (MATCH FACENAME OVERRIDE LAXMATCH) | 282 (MATCH FACENAME OVERRIDE LAXMATCH) |
481 ;;; extents, or resizing existing ones. | 488 ;;; extents, or resizing existing ones. |
482 ;;; | 489 ;;; |
483 ;;; Each time a modification happens to a line, we re-fontify the entire line. | 490 ;;; Each time a modification happens to a line, we re-fontify the entire line. |
484 ;;; We do this by first removing the extents (text properties) on the line, | 491 ;;; We do this by first removing the extents (text properties) on the line, |
485 ;;; and then doing the syntactic and keyword passes again on that line. (More | 492 ;;; and then doing the syntactic and keyword passes again on that line. (More |
486 ;;; generally, each modified region is extended to include the preceeding and | 493 ;;; generally, each modified region is extended to include the preceding and |
487 ;;; following BOL or EOL.) | 494 ;;; following BOL or EOL.) |
488 ;;; | 495 ;;; |
489 ;;; This means that, as the user types, we repeatedly go back to the beginning | 496 ;;; This means that, as the user types, we repeatedly go back to the beginning |
490 ;;; of the line, doing more work the longer the line gets. This doesn't cost | 497 ;;; of the line, doing more work the longer the line gets. This doesn't cost |
491 ;;; much in practice, and if we don't, then we incorrectly fontify things when, | 498 ;;; much in practice, and if we don't, then we incorrectly fontify things when, |
553 'font-lock-after-change-function nil t) | 560 'font-lock-after-change-function nil t) |
554 (add-hook 'pre-idle-hook 'font-lock-pre-idle-hook)) | 561 (add-hook 'pre-idle-hook 'font-lock-pre-idle-hook)) |
555 (t | 562 (t |
556 (remove-hook 'after-change-functions | 563 (remove-hook 'after-change-functions |
557 'font-lock-after-change-function t) | 564 'font-lock-after-change-function t) |
565 (setq font-lock-defaults-computed nil | |
566 font-lock-keywords nil) | |
558 ;; We have no business doing this here, since | 567 ;; We have no business doing this here, since |
559 ;; pre-idle-hook is global. Other buffers may | 568 ;; pre-idle-hook is global. Other buffers may |
560 ;; still be in font-lock mode. -dkindred@cs.cmu.edu | 569 ;; still be in font-lock mode. -dkindred@cs.cmu.edu |
561 ;; (remove-hook 'pre-idle-hook 'font-lock-pre-idle-hook) | 570 ;; (remove-hook 'pre-idle-hook 'font-lock-pre-idle-hook) |
562 )) | 571 )) |
1126 (save-excursion (end-of-line) (setq limit (min limit (point)))) | 1135 (save-excursion (end-of-line) (setq limit (min limit (point)))) |
1127 ;; Evaluate PRE-MATCH-FORM. | 1136 ;; Evaluate PRE-MATCH-FORM. |
1128 (eval (nth 1 keywords)) | 1137 (eval (nth 1 keywords)) |
1129 (save-match-data | 1138 (save-match-data |
1130 ;; Find an occurrence of `matcher' before `limit'. | 1139 ;; Find an occurrence of `matcher' before `limit'. |
1131 (if (and (not (stringp matcher)) | |
1132 (not (functionp matcher)) | |
1133 (boundp matcher)) | |
1134 (setq matcher (symbol-value matcher))) | |
1135 (while (if (stringp matcher) | 1140 (while (if (stringp matcher) |
1136 (re-search-forward matcher limit t) | 1141 (re-search-forward matcher limit t) |
1137 (funcall matcher limit)) | 1142 (funcall matcher limit)) |
1138 ;; Apply each highlight to this instance of `matcher'. | 1143 ;; Apply each highlight to this instance of `matcher'. |
1139 (setq highlights lowdarks) | 1144 (setq highlights lowdarks) |
1160 (if loudly (message "Fontifying %s... (regexps..%s)" bufname | 1165 (if loudly (message "Fontifying %s... (regexps..%s)" bufname |
1161 (make-string (setq count (1+ count)) ?.))) | 1166 (make-string (setq count (1+ count)) ?.))) |
1162 ;; | 1167 ;; |
1163 ;; Find an occurrence of `matcher' from `start' to `end'. | 1168 ;; Find an occurrence of `matcher' from `start' to `end'. |
1164 (setq keyword (car keywords) matcher (car keyword)) | 1169 (setq keyword (car keywords) matcher (car keyword)) |
1165 (if (and (not (stringp matcher)) | |
1166 (not (functionp matcher)) | |
1167 (boundp matcher)) | |
1168 (setq matcher (symbol-value matcher))) | |
1169 (goto-char start) | 1170 (goto-char start) |
1170 (while (and (< (point) end) | 1171 (while (and (< (point) end) |
1171 (if (stringp matcher) | 1172 (if (stringp matcher) |
1172 (re-search-forward matcher end t) | 1173 (re-search-forward matcher end t) |
1173 (funcall matcher end))) | 1174 (funcall matcher end))) |
1208 | 1209 |
1209 ;; If the buffer has just been reverted, normally that turns off | 1210 ;; If the buffer has just been reverted, normally that turns off |
1210 ;; Font Lock mode. So turn the mode back on if necessary. | 1211 ;; Font Lock mode. So turn the mode back on if necessary. |
1211 (defalias 'font-lock-revert-cleanup 'turn-on-font-lock) | 1212 (defalias 'font-lock-revert-cleanup 'turn-on-font-lock) |
1212 | 1213 |
1214 | |
1213 (defun font-lock-compile-keywords (&optional keywords) | 1215 (defun font-lock-compile-keywords (&optional keywords) |
1214 ;; Compile `font-lock-keywords' into the form (t KEYWORD ...) where KEYWORD | 1216 ;; Compile `font-lock-keywords' into the form (t KEYWORD ...) where KEYWORD |
1215 ;; is the (MATCHER HIGHLIGHT ...) shown in the variable's doc string. | 1217 ;; is the (MATCHER HIGHLIGHT ...) shown in the variable's doc string. |
1216 (let ((keywords (or keywords font-lock-keywords))) | 1218 (let ((keywords (or keywords font-lock-keywords))) |
1217 (setq font-lock-keywords | 1219 (setq font-lock-keywords |
1218 (if (eq (car-safe keywords) t) | 1220 (if (eq (car-safe keywords) t) |
1219 keywords | 1221 keywords |
1220 (cons t | 1222 (cons t (mapcar 'font-lock-compile-keyword keywords)))))) |
1221 (mapcar | 1223 |
1222 (function (lambda (item) | 1224 (defun font-lock-compile-keyword (keyword) |
1223 (cond ((nlistp item) | 1225 (cond ((nlistp keyword) ; Just MATCHER |
1224 (list item '(0 font-lock-keyword-face))) | 1226 (list keyword '(0 font-lock-keyword-face))) |
1225 ((numberp (cdr item)) | 1227 ((eq (car keyword) 'eval) ; Specified (eval . FORM) |
1226 (list (car item) (list (cdr item) 'font-lock-keyword-face))) | 1228 (font-lock-compile-keyword (eval (cdr keyword)))) |
1227 ((symbolp (cdr item)) | 1229 ((numberp (cdr keyword)) ; Specified (MATCHER . MATCH) |
1228 (list (car item) (list 0 (cdr item)))) | 1230 (list (car keyword) (list (cdr keyword) 'font-lock-keyword-face))) |
1229 ((nlistp (nth 1 item)) | 1231 ((symbolp (cdr keyword)) ; Specified (MATCHER . FACENAME) |
1230 (list (car item) (cdr item))) | 1232 (list (car keyword) (list 0 (cdr keyword)))) |
1231 (t | 1233 ((nlistp (nth 1 keyword)) ; Specified (MATCHER . HIGHLIGHT) |
1232 item)))) | 1234 (list (car keyword) (cdr keyword))) |
1233 keywords)))))) | 1235 (t ; Hopefully (MATCHER HIGHLIGHT ...) |
1236 keyword))) | |
1234 | 1237 |
1235 (defun font-lock-choose-keywords (keywords level) | 1238 (defun font-lock-choose-keywords (keywords level) |
1236 ;; Return LEVELth element of KEYWORDS. A LEVEL of nil is equal to a | 1239 ;; Return LEVELth element of KEYWORDS. A LEVEL of nil is equal to a |
1237 ;; LEVEL of 0, a LEVEL of t is equal to (1- (length KEYWORDS)). | 1240 ;; LEVEL of 0, a LEVEL of t is equal to (1- (length KEYWORDS)). |
1238 (let ((level (if (not (consp level)) | 1241 (let ((level (if (not (consp level)) |