comparison lisp/font-lock.el @ 408:501cfd01ee6d r21-2-34

Import from CVS: tag r21-2-34
author cvs
date Mon, 13 Aug 2007 11:18:11 +0200
parents b8cc9ab3f761
children de805c49cfc1
comparison
equal deleted inserted replaced
407:ed6218a7d4d3 408:501cfd01ee6d
176 176
177 The size is measured in characters. This affects `font-lock-fontify-region' 177 The size is measured in characters. This affects `font-lock-fontify-region'
178 but not `font-lock-fontify-buffer'. (In other words, when you first visit 178 but not `font-lock-fontify-buffer'. (In other words, when you first visit
179 a file and it gets fontified, you will see status messages no matter what 179 a file and it gets fontified, you will see status messages no matter what
180 size the file is. However, if you do something else like paste a 180 size the file is. However, if you do something else like paste a
181 chunk of text or revert a buffer, you will see status messages only if the 181 chunk of text, you will see status messages only if the changed region is
182 changed region is large enough.) 182 large enough.)
183 183
184 Note that setting `font-lock-verbose' to nil disables the status 184 Note that setting `font-lock-verbose' to nil disables the status
185 messages entirely." 185 messages entirely."
186 :type 'integer 186 :type 'integer
187 :group 'font-lock) 187 :group 'font-lock)
316 316
317 ;; Fontification variables: 317 ;; Fontification variables:
318 318
319 ;;;###autoload 319 ;;;###autoload
320 (defvar font-lock-keywords nil 320 (defvar font-lock-keywords nil
321 "A list of the keywords to highlight. 321 "A list defining the keywords for `font-lock-mode' to highlight.
322 Each element should be of the form: 322
323 323 FONT-LOCK-KEYWORDS := List of FONT-LOCK-FORM's.
324 MATCHER 324
325 (MATCHER . MATCH) 325 FONT-LOCK-FORM :== MATCHER
326 (MATCHER . FACENAME) 326 | (MATCHER . MATCH)
327 (MATCHER . HIGHLIGHT) 327 | (MATCHER . FACE-FORM)
328 (MATCHER HIGHLIGHT ...) 328 | (MATCHER . HIGHLIGHT)
329 (eval . FORM) 329 | (MATCHER HIGHLIGHT ...)
330 330 | (eval . FORM)
331 where HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED. 331
332 332 MATCHER :== A string containing a regexp.
333 FORM is an expression, whose value should be a keyword element, 333 | A variable containing a regexp to search for.
334 evaluated when the keyword is (first) used in a buffer. This feature 334 | A function to call to make the search.
335 can be used to provide a keyword that can only be generated when Font 335 It is called with one arg, the limit of the search,
336 Lock mode is actually turned on. 336 and should leave MATCH results in the XEmacs global
337 match data.
338
339 MATCH :== An integer match subexpression number from MATCHER.
340
341 FACE-FORM :== The symbol naming a defined face.
342 | Expression whos value is the face name to use. If you
343 want FACE-FORM to be a symbol that evaluates to a face,
344 use a form like \"(progn sym)\".
345
346 HIGHLIGHT :== MATCH-HIGHLIGHT
347 | MATCH-ANCHORED
348
349 FORM :== Expression returning a FONT-LOCK-FORM, evaluated when
350 the FONT-LOCK-FORM is first used in a buffer. This
351 feature can be used to provide a FONT-LOCK-FORM that
352 can only be generated when Font Lock mode is actually
353 turned on.
354
355 MATCH-HIGHLIGHT :== (MATCH FACE-FORM OVERRIDE LAXMATCH)
356
357 OVERRIDE :== t - overwrite existing fontification
358 | 'keep - only parts not already fontified are
359 highlighted.
360 | 'prepend - merge faces, this fontification has
361 precedence over existing
362 | 'append - merge faces, existing fontification has
363 precedence over
364 this face.
365
366 LAXMATCH :== If non-nil, no error is signalled if there is no MATCH
367 in MATCHER.
368
369 MATCH-ANCHORED :== (ANCHOR-MATCHER PRE-MATCH-FORM \\
370 POST-MATCH-FORM MATCH-HIGHLIGHT ...)
371
372 ANCHOR-MATCHER :== Like a MATCHER, except that the limit of the search
373 defaults to the end of the line after PRE-MATCH-FORM
374 is evaluated. However, if PRE-MATCH-FORM returns a
375 position greater than the end of the line, that
376 position is used as the limit of the search. It is
377 generally a bad idea to return a position greater than
378 the end of the line, i.e., cause the ANCHOR-MATCHER
379 search to span lines.
380
381 PRE-MATCH-FORM :== Evaluated before the ANCHOR-MATCHER is used, therefore
382 can be used to initialize before, ANCHOR-MATCHER is
383 used. Typically, PRE-MATCH-FORM is used to move to
384 some position relative to the original MATCHER, before
385 starting with the ANCHOR-MATCHER.
386
387 POST-MATCH-FORM :== Like PRE-MATCH-FORM, but used to clean up after the
388 ANCHOR-MATCHER. It might be used to move, before
389 resuming with MATCH-ANCHORED's parent's MATCHER.
390
391 For example, an element of the first form highlights (if not already highlighted):
392
393 \"\\\\<foo\\\\>\" Discrete occurrences of \"foo\" in the value
394 of the variable `font-lock-keyword-face'.
395
396 (\"fu\\\\(bar\\\\)\" . 1) Substring \"bar\" within all occurrences of
397 \"fubar\" in the value of
398 `font-lock-keyword-face'.
399
400 (\"fubar\" . fubar-face) Occurrences of \"fubar\" in the value of
401 `fubar-face'.
402
403 (\"foo\\\\|bar\" 0 foo-bar-face t) Occurrences of either \"foo\" or \"bar\" in the
404 value of `foo-bar-face', even if already
405 highlighted.
406
407 (fubar-match 1 fubar-face) The first subexpression within all
408 occurrences of whatever the function
409 `fubar-match' finds and matches in the value
410 of `fubar-face'.
411
412 (\"\\\\<anchor\\\\>\" (0 anchor-face) (\"\\\\<item\\\\>\" nil nil (0 item-face)))
413 -------------- --------------- ------------ --- --- -------------
414 | | | | | |
415 MATCHER | ANCHOR-MATCHER | +------+ MATCH-HIGHLIGHT
416 MATCH-HIGHLIGHT PRE-MATCH-FORM |
417 POST-MATCH-FORM
418
419 Discrete occurrences of \"anchor\" in the value of `anchor-face', and
420 subsequent discrete occurrences of \"item\" (on the same line) in the value
421 of `item-face'. (Here PRE-MATCH-FORM and POST-MATCH-FORM are nil.
422 Therefore \"item\" is initially searched for starting from the end of the
423 match of \"anchor\", and searching for subsequent instance of \"anchor\"
424 resumes from where searching for \"item\" concluded.)
337 425
338 For highlighting single items, typically only MATCH-HIGHLIGHT is required. 426 For highlighting single items, typically only MATCH-HIGHLIGHT is required.
339 However, if an item or (typically) items is to be highlighted following the 427 However, if an item or (typically) several items are to be highlighted
340 instance of another item (the anchor) then MATCH-ANCHORED may be required. 428 following the instance of another item (the anchor) then MATCH-ANCHORED may be
341 429 required.
342 MATCH-HIGHLIGHT should be of the form:
343
344 (MATCH FACENAME OVERRIDE LAXMATCH)
345
346 Where MATCHER can be either the regexp to search for, a variable
347 containing the regexp to search for, or the function to call to make
348 the search (called with one argument, the limit of the search). MATCH
349 is the subexpression of MATCHER to be highlighted. FACENAME is either
350 a symbol naming a face, or an expression whose value is the face name
351 to use. If you want FACENAME to be a symbol that evaluates to a face,
352 use a form like \"(progn sym)\".
353
354 OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification may
355 be overwritten. If `keep', only parts not already fontified are highlighted.
356 If `prepend' or `append', existing fontification is merged with the new, in
357 which the new or existing fontification, respectively, takes precedence.
358 If LAXMATCH is non-nil, no error is signalled if there is no MATCH in MATCHER.
359
360 For example, an element of the form highlights (if not already highlighted):
361
362 \"\\\\\\=<foo\\\\\\=>\" Discrete occurrences of \"foo\" in the value of the
363 variable `font-lock-keyword-face'.
364 (\"fu\\\\(bar\\\\)\" . 1) Substring \"bar\" within all occurrences of \"fubar\" in
365 the value of `font-lock-keyword-face'.
366 (\"fubar\" . fubar-face) Occurrences of \"fubar\" in the value of `fubar-face'.
367 (\"foo\\\\|bar\" 0 foo-bar-face t)
368 Occurrences of either \"foo\" or \"bar\" in the value
369 of `foo-bar-face', even if already highlighted.
370
371 MATCH-ANCHORED should be of the form:
372
373 (MATCHER PRE-MATCH-FORM POST-MATCH-FORM MATCH-HIGHLIGHT ...)
374
375 Where MATCHER is as for MATCH-HIGHLIGHT with one exception; see below.
376 PRE-MATCH-FORM and POST-MATCH-FORM are evaluated before the first, and after
377 the last, instance MATCH-ANCHORED's MATCHER is used. Therefore they can be
378 used to initialize before, and cleanup after, MATCHER is used. Typically,
379 PRE-MATCH-FORM is used to move to some position relative to the original
380 MATCHER, before starting with MATCH-ANCHORED's MATCHER. POST-MATCH-FORM might
381 be used to move, before resuming with MATCH-ANCHORED's parent's MATCHER.
382
383 For example, an element of the form highlights (if not already highlighted):
384
385 (\"\\\\\\=<anchor\\\\\\=>\" (0 anchor-face) (\"\\\\\\=<item\\\\\\=>\" nil nil (0 item-face)))
386
387 Discrete occurrences of \"anchor\" in the value of `anchor-face', and subsequent
388 discrete occurrences of \"item\" (on the same line) in the value of `item-face'.
389 (Here PRE-MATCH-FORM and POST-MATCH-FORM are nil. Therefore \"item\" is
390 initially searched for starting from the end of the match of \"anchor\", and
391 searching for subsequent instance of \"anchor\" resumes from where searching
392 for \"item\" concluded.)
393
394 The above-mentioned exception is as follows. The limit of the MATCHER search
395 defaults to the end of the line after PRE-MATCH-FORM is evaluated.
396 However, if PRE-MATCH-FORM returns a position greater than the position after
397 PRE-MATCH-FORM is evaluated, that position is used as the limit of the search.
398 It is generally a bad idea to return a position greater than the end of the
399 line, i.e., cause the MATCHER search to span lines.
400
401 Note that the MATCH-ANCHORED feature is experimental; in the future, we may
402 replace it with other ways of providing this functionality.
403 430
404 These regular expressions should not match text which spans lines. While 431 These regular expressions should not match text which spans lines. While
405 \\[font-lock-fontify-buffer] handles multi-line patterns correctly, updating 432 \\[font-lock-fontify-buffer] handles multi-line patterns correctly, updating when you
406 when you edit the buffer does not, since it considers text one line at a time. 433 edit the buffer does not, since it considers text one line at a time.
407 434
408 Be very careful composing regexps for this list; 435 Be very careful composing regexps for this list; the wrong pattern can
409 the wrong pattern can dramatically slow things down!") 436 dramatically slow things down!
437 ")
410 ;;;###autoload 438 ;;;###autoload
411 (make-variable-buffer-local 'font-lock-keywords) 439 (make-variable-buffer-local 'font-lock-keywords)
412 440
413 (defvar font-lock-defaults nil 441 (defvar font-lock-defaults nil
414 "The defaults font Font Lock mode for the current buffer. 442 "The defaults font Font Lock mode for the current buffer.
827 ;; (remove-hook 'pre-idle-hook 'font-lock-pre-idle-hook) 855 ;; (remove-hook 'pre-idle-hook 'font-lock-pre-idle-hook)
828 )) 856 ))
829 (set (make-local-variable 'font-lock-mode) on-p) 857 (set (make-local-variable 'font-lock-mode) on-p)
830 (cond (on-p 858 (cond (on-p
831 (font-lock-set-defaults-1) 859 (font-lock-set-defaults-1)
832 (make-local-hook 'before-revert-hook)
833 (make-local-hook 'after-revert-hook)
834 ;; If buffer is reverted, must clean up the state.
835 (add-hook 'before-revert-hook 'font-lock-revert-setup nil t)
836 (add-hook 'after-revert-hook 'font-lock-revert-cleanup nil t)
837 (run-hooks 'font-lock-mode-hook) 860 (run-hooks 'font-lock-mode-hook)
838 (cond (font-lock-fontified 861 (cond (font-lock-fontified
839 nil) 862 nil)
840 ((or (null maximum-size) (<= (buffer-size) maximum-size)) 863 ((or (null maximum-size) (<= (buffer-size) maximum-size))
841 (font-lock-fontify-buffer)) 864 (font-lock-fontify-buffer))
843 (lprogress-display 'font-lock 866 (lprogress-display 'font-lock
844 "Fontifying %s... buffer too big." 'abort 867 "Fontifying %s... buffer too big." 'abort
845 (buffer-name))))) 868 (buffer-name)))))
846 (font-lock-fontified 869 (font-lock-fontified
847 (setq font-lock-fontified nil) 870 (setq font-lock-fontified nil)
848 (remove-hook 'before-revert-hook 'font-lock-revert-setup t)
849 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup t)
850 (font-lock-unfontify-region (point-min) (point-max)) 871 (font-lock-unfontify-region (point-min) (point-max))
851 (font-lock-thing-lock-cleanup)) 872 (font-lock-thing-lock-cleanup))
852 (t 873 (t
853 (remove-hook 'before-revert-hook 'font-lock-revert-setup t)
854 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup t)
855 (font-lock-thing-lock-cleanup))) 874 (font-lock-thing-lock-cleanup)))
856 (redraw-modeline))) 875 (redraw-modeline)))
857 876
858 ;; For init-file hooks 877 ;; For init-file hooks
859 ;;;###autoload 878 ;;;###autoload
972 (funcall font-lock-fontify-region-function beg end loudly)) 991 (funcall font-lock-fontify-region-function beg end loudly))
973 992
974 (defun font-lock-unfontify-region (beg end &optional loudly) 993 (defun font-lock-unfontify-region (beg end &optional loudly)
975 (funcall font-lock-unfontify-region-function beg end loudly)) 994 (funcall font-lock-unfontify-region-function beg end loudly))
976 995
977 ;; #### In these functions, the FSF is careful to do
978 ;; (save-restriction
979 ;; (widen)
980 ;; before anything else. Should we copy?
981 (defun font-lock-default-fontify-buffer () 996 (defun font-lock-default-fontify-buffer ()
982 (interactive) 997 (interactive)
983 (let ((was-on font-lock-mode) 998 ;; if we don't widen, then the C code will fail to
984 (font-lock-verbose (or font-lock-verbose (interactive-p))) 999 ;; realize that we're inside a comment.
985 (font-lock-message-threshold 0) 1000 (save-restriction
986 (aborted nil)) 1001 (widen)
987 ;; Turn it on to run hooks and get the right font-lock-keywords. 1002 (let ((was-on font-lock-mode)
988 (or was-on (font-lock-mode 1)) 1003 (font-lock-verbose (or font-lock-verbose (interactive-p)))
989 (font-lock-unfontify-region (point-min) (point-max) t) 1004 (font-lock-message-threshold 0)
990 ;; (buffer-syntactic-context-flush-cache) 1005 (aborted nil))
1006 ;; Turn it on to run hooks and get the right font-lock-keywords.
1007 (or was-on (font-lock-mode 1))
1008 (font-lock-unfontify-region (point-min) (point-max) t)
1009 ;; (buffer-syntactic-context-flush-cache)
991 1010
992 ;; If a ^G is typed during fontification, abort the fontification, but 1011 ;; If a ^G is typed during fontification, abort the fontification, but
993 ;; return normally (do not signal.) This is to make it easy to abort 1012 ;; return normally (do not signal.) This is to make it easy to abort
994 ;; fontification if it's taking a long time, without also causing the 1013 ;; fontification if it's taking a long time, without also causing the
995 ;; buffer not to pop up. If a real abort is desired, the user can ^G 1014 ;; buffer not to pop up. If a real abort is desired, the user can ^G
996 ;; again. 1015 ;; again.
997 ;; 1016 ;;
998 ;; Possibly this should happen down in font-lock-fontify-region instead 1017 ;; Possibly this should happen down in font-lock-fontify-region instead
999 ;; of here, but since that happens from the after-change-hook (meaning 1018 ;; of here, but since that happens from the after-change-hook (meaning
1000 ;; much more frequently) I'm afraid of the bad consequences of stealing 1019 ;; much more frequently) I'm afraid of the bad consequences of stealing
1001 ;; the interrupt character at inopportune times. 1020 ;; the interrupt character at inopportune times.
1002 ;; 1021 ;;
1003 (condition-case nil 1022 (condition-case nil
1004 (save-excursion 1023 (save-excursion
1005 (font-lock-fontify-region (point-min) (point-max))) 1024 (font-lock-fontify-region (point-min) (point-max)))
1006 (t 1025 (t
1007 (setq aborted t))) 1026 (setq aborted t)))
1008 1027
1009 (or was-on ; turn it off if it was off. 1028 (or was-on ; turn it off if it was off.
1010 (let ((font-lock-fontified nil)) ; kludge to prevent defontification 1029 (let ((font-lock-fontified nil)) ; kludge to prevent defontification
1011 (font-lock-mode 0))) 1030 (font-lock-mode 0)))
1012 (set (make-local-variable 'font-lock-fontified) t) 1031 (set (make-local-variable 'font-lock-fontified) t)
1013 (when (and aborted font-lock-verbose) 1032 (when (and aborted font-lock-verbose)
1014 (lprogress-display 'font-lock "Fontifying %s... aborted." 'abort (buffer-name)))) 1033 (lprogress-display 'font-lock "Fontifying %s... aborted."
1015 (run-hooks 'font-lock-after-fontify-buffer-hook)) 1034 'abort (buffer-name))))
1035 (run-hooks 'font-lock-after-fontify-buffer-hook)))
1016 1036
1017 (defun font-lock-default-unfontify-buffer () 1037 (defun font-lock-default-unfontify-buffer ()
1018 (font-lock-unfontify-region (point-min) (point-max)) 1038 (font-lock-unfontify-region (point-min) (point-max))
1019 (set (make-local-variable 'font-lock-fontified) nil)) 1039 (set (make-local-variable 'font-lock-fontified) nil))
1020 1040
1056 buffer-file-name buffer-file-truename) 1076 buffer-file-name buffer-file-truename)
1057 (font-lock-remove-face beg end) 1077 (font-lock-remove-face beg end)
1058 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))) 1078 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil))))
1059 1079
1060 ;; Following is the original FSF version (similar to our original 1080 ;; Following is the original FSF version (similar to our original
1061 ;; version, before all the crap I added below). 1081 ;; version, before the deferred stuff was added).
1062 ;;
1063 ;; Probably that crap should either be fixed up so it works better,
1064 ;; or tossed away.
1065 ;; 1082 ;;
1066 ;; I think that lazy-lock v2 tries to do something similar. 1083 ;; I think that lazy-lock v2 tries to do something similar.
1067 ;; Those efforts should be merged. 1084 ;; Those efforts should be merged.
1068 1085
1069 ;; Called when any modification is made to buffer text. 1086 ;; Called when any modification is made to buffer text.
1073 ; ;; Rescan between start of line from `beg' and start of line after `end'. 1090 ; ;; Rescan between start of line from `beg' and start of line after `end'.
1074 ; (font-lock-fontify-region 1091 ; (font-lock-fontify-region
1075 ; (progn (goto-char beg) (beginning-of-line) (point)) 1092 ; (progn (goto-char beg) (beginning-of-line) (point))
1076 ; (progn (goto-char end) (forward-line 1) (point)))))) 1093 ; (progn (goto-char end) (forward-line 1) (point))))))
1077 1094
1078 (defvar font-lock-old-extent nil) 1095 (defvar font-lock-always-fontify-immediately nil
1079 (defvar font-lock-old-len 0) 1096 "Set this to non-nil to disable font-lock deferral.
1080 1097 Otherwise, changes to existing text will not be processed until the
1081 (defun font-lock-fontify-glumped-region () 1098 next redisplay cycle, avoiding excessive fontification when many
1082 ;; even if something goes wrong in the fontification, mark the glumped 1099 buffer modifications are performed or a buffer is reverted.")
1083 ;; region as fontified; otherwise, the same error might get signaled 1100
1084 ;; after every command. 1101 (defvar font-lock-pending-extent-table (make-hash-table :weakness 'key))
1085 (unwind-protect 1102 (defvar font-lock-range-table (make-range-table))
1086 ;; buffer/extent may be deleted.
1087 (if (and (extent-live-p font-lock-old-extent)
1088 (buffer-live-p (extent-object font-lock-old-extent)))
1089 (save-excursion
1090 (set-buffer (extent-object font-lock-old-extent))
1091 (font-lock-after-change-function-1
1092 (extent-start-position font-lock-old-extent)
1093 (extent-end-position font-lock-old-extent)
1094 font-lock-old-len)))
1095 (detach-extent font-lock-old-extent)
1096 (setq font-lock-old-extent nil)))
1097 1103
1098 (defun font-lock-pre-idle-hook () 1104 (defun font-lock-pre-idle-hook ()
1099 (condition-case nil 1105 (condition-case font-lock-error
1100 (if font-lock-old-extent 1106 (if (> (hash-table-count font-lock-pending-extent-table) 0)
1101 (font-lock-fontify-glumped-region)) 1107 (font-lock-fontify-pending-extents))
1102 (error (warn "Error caught in `font-lock-pre-idle-hook'")))) 1108 (error (warn "Error caught in `font-lock-pre-idle-hook': %s"
1103 1109 font-lock-error))))
1104 (defvar font-lock-always-fontify-immediately nil
1105 "Set this to non-nil to disable font-lock deferral.")
1106 1110
1107 ;;; called when any modification is made to buffer text. This function 1111 ;;; called when any modification is made to buffer text. This function
1108 ;;; attempts to glump adjacent changes together so that excessive 1112 ;;; remembers the changed ranges until the next redisplay, at which point
1109 ;;; fontification is avoided. This function could easily be adapted 1113 ;;; the extents are merged and pruned, and the resulting ranges fontified.
1110 ;;; to other after-change-functions. 1114 ;;; This function could easily be adapted to other after-change-functions.
1111 1115
1112 (defun font-lock-after-change-function (beg end old-len) 1116 (defun font-lock-after-change-function (beg end old-len)
1113 (let ((obeg (and font-lock-old-extent 1117 (when font-lock-mode
1114 (extent-start-position font-lock-old-extent))) 1118 (let ((ex (make-extent beg end)))
1115 (oend (and font-lock-old-extent 1119 (set-extent-property ex 'detachable nil)
1116 (extent-end-position font-lock-old-extent))) 1120 (set-extent-property ex 'end-open nil)
1117 (bc-end (+ beg old-len))) 1121 (let ((exs (gethash (current-buffer) font-lock-pending-extent-table)))
1118 1122 (push ex exs)
1119 ;; If this change can't be merged into the glumped one, 1123 (puthash (current-buffer) exs font-lock-pending-extent-table)))
1120 ;; we need to fontify the glumped one right now.
1121 (if (and font-lock-old-extent
1122 (or (not (eq (current-buffer)
1123 (extent-object font-lock-old-extent)))
1124 (< bc-end obeg)
1125 (> beg oend)))
1126 (font-lock-fontify-glumped-region))
1127
1128 (if font-lock-old-extent
1129 ;; Update glumped region.
1130 (progn
1131 ;; Any characters in the before-change region that are
1132 ;; outside the glumped region go into the glumped
1133 ;; before-change region.
1134 (if (> bc-end oend)
1135 (setq font-lock-old-len (+ font-lock-old-len (- bc-end oend))))
1136 (if (> obeg beg)
1137 (setq font-lock-old-len (+ font-lock-old-len (- obeg beg))))
1138 ;; New glumped region is the union of the glumped region
1139 ;; and the new region.
1140 (set-extent-endpoints font-lock-old-extent
1141 (min obeg beg)
1142 (max oend end)))
1143
1144 ;; No glumped region, so create one.
1145 (setq font-lock-old-extent (make-extent beg end))
1146 (set-extent-property font-lock-old-extent 'detachable nil)
1147 (set-extent-property font-lock-old-extent 'end-open nil)
1148 (setq font-lock-old-len old-len))
1149
1150 (if font-lock-always-fontify-immediately 1124 (if font-lock-always-fontify-immediately
1151 (font-lock-fontify-glumped-region)))) 1125 (font-lock-fontify-pending-extents))))
1152 1126
1153 (defun font-lock-after-change-function-1 (beg end old-len) 1127 (defun font-lock-fontify-pending-extents ()
1154 (if (null font-lock-mode) 1128 ;; ah, the beauty of mapping functions.
1155 nil 1129 ;; this function is actually shorter than the old version, which handled
1156 (save-excursion 1130 ;; only one buffer and one contiguous region!
1157 (save-restriction 1131 (save-match-data
1158 ;; if we don't widen, then fill-paragraph (and any command that 1132 (maphash
1159 ;; operates on a narrowed region) confuses things, because the C 1133 #'(lambda (buffer exs)
1160 ;; code will fail to realize that we're inside a comment. 1134 ;; remove first, to avoid infinite reprocessing if error
1161 (widen) 1135 (remhash buffer font-lock-pending-extent-table)
1162 (save-match-data 1136 (when (buffer-live-p buffer)
1163 (let ((zmacs-region-stays zmacs-region-stays)) ; protect from change! 1137 (clear-range-table font-lock-range-table)
1164 (goto-char beg) 1138 (with-current-buffer buffer
1165 ;; Maybe flush the internal cache used by syntactically-sectionize. 1139 (save-excursion
1166 ;; (It'd be nice if this was more automatic.) Any deletions mean 1140 (save-restriction
1167 ;; the cache is invalid, and insertions at beginning or end of line 1141 ;; if we don't widen, then the C code will fail to
1168 ;; mean that the bol cache might be invalid. 1142 ;; realize that we're inside a comment.
1169 ;; (if (or (> old-len 0) (bobp) (= (preceding-char) ?\n)) 1143 (widen)
1170 ;; (buffer-syntactic-context-flush-cache)) 1144 (let ((zmacs-region-stays
1171 1145 zmacs-region-stays)) ; protect from change!
1172 ;; Always recompute the whole line. 1146 (mapc
1173 (goto-char end) 1147 #'(lambda (ex)
1174 (forward-line 1) 1148 ;; paranoia.
1175 (setq end (point)) 1149 (when (and (extent-live-p ex)
1176 (goto-char beg) 1150 (not (extent-detached-p ex)))
1177 (beginning-of-line) 1151 ;; first expand the ranges to full lines, because
1178 (setq beg (point)) 1152 ;; that is what will be fontified; then use a
1179 ;; Rescan between start of line from `beg' and start of line after 1153 ;; range table to merge the ranges.
1180 ;; `end'. 1154 (let* ((beg (extent-start-position ex))
1181 (font-lock-fontify-region beg end))))))) 1155 (end (extent-end-position ex))
1182 1156 (beg (progn (goto-char beg)
1157 (beginning-of-line)
1158 (point)))
1159 (end (progn (goto-char end)
1160 (forward-line 1)
1161 (point))))
1162 (detach-extent ex)
1163 (put-range-table beg end t
1164 font-lock-range-table))))
1165 exs)
1166 (map-range-table
1167 #'(lambda (beg end val)
1168 ;; Maybe flush the internal cache used by
1169 ;; syntactically-sectionize. (It'd be nice if this
1170 ;; was more automatic.) Any deletions mean the
1171 ;; cache is invalid, and insertions at beginning or
1172 ;; end of line mean that the bol cache might be
1173 ;; invalid.
1174 ;; #### This code has been commented out for some time
1175 ;; now and is bit-rotting. Someone should look into
1176 ;; this.
1177 ;; (if (or change-was-deletion (bobp)
1178 ;; (= (preceding-char) ?\n))
1179 ;; (buffer-syntactic-context-flush-cache))
1180 (if (and (= beg (point-min))
1181 (= end (point-max)))
1182 (font-lock-fontify-buffer)
1183 (font-lock-fontify-region beg end)))
1184 font-lock-range-table)))))))
1185 font-lock-pending-extent-table)))
1183 1186
1184 ;; Syntactic fontification functions. 1187 ;; Syntactic fontification functions.
1185 1188
1186 ;; Note: Here is the FSF version. Our version is much faster because 1189 ;; Note: Here is the FSF version. Our version is much faster because
1187 ;; of the C support we provide. This may be useful for reference, 1190 ;; of the C support we provide. This may be useful for reference,
1565 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode) 1568 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
1566 (fast-lock-after-fontify-buffer)) 1569 (fast-lock-after-fontify-buffer))
1567 ((and (boundp 'lazy-lock-mode) lazy-lock-mode) 1570 ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
1568 (lazy-lock-after-fontify-buffer)))) 1571 (lazy-lock-after-fontify-buffer))))
1569 1572
1570 ;; If the buffer is about to be reverted, it won't be fontified afterward.
1571 ;(defun font-lock-revert-setup ()
1572 ; (setq font-lock-fontified nil))
1573
1574 ;; If the buffer has just been reverted, normally that turns off
1575 ;; Font Lock mode. So turn the mode back on if necessary.
1576 ;; sb 1999-03-03 -- The above comment no longer appears to be operative as
1577 ;; the first call to normal-mode *will* restore the font-lock state and
1578 ;; this call forces a second font-locking to occur when reverting a buffer,
1579 ;; which is wasteful at best.
1580 ;;(defun font-lock-revert-cleanup ())
1581
1582 ;; <andy@xemacs.org> 12-10-99. This still does not work right, I think
1583 ;; after change functions will still get us. The simplest thing to do
1584 ;; is unconditionally turn-off font-lock before revert (and thus nuke
1585 ;; all hooks) and then turn it on again afterwards. This also happens
1586 ;; to be much faster because fontifying from scratch is better than
1587 ;; trying to do incremental changes for the whole buffer.
1588
1589 (defalias 'font-lock-revert-cleanup 'turn-on-font-lock)
1590 (defalias 'font-lock-revert-setup 'turn-off-font-lock)
1591
1592 1573
1593 ;; Various functions. 1574 ;; Various functions.
1594 1575
1595 (defun font-lock-compile-keywords (&optional keywords) 1576 (defun font-lock-compile-keywords (&optional keywords)
1596 ;; Compile `font-lock-keywords' into the form (t KEYWORD ...) where KEYWORD 1577 ;; Compile `font-lock-keywords' into the form (t KEYWORD ...) where KEYWORD
2367 '("\\<\\(this\\|super\\)\\>" (1 font-lock-reference-face)) 2348 '("\\<\\(this\\|super\\)\\>" (1 font-lock-reference-face))
2368 '("\\<\\(false\\|null\\|true\\)\\>" (1 font-lock-keyword-face)) 2349 '("\\<\\(false\\|null\\|true\\)\\>" (1 font-lock-keyword-face))
2369 2350
2370 ;; Class names: 2351 ;; Class names:
2371 (list (concat "\\<\\(class\\|interface\\)\\>\\s *" 2352 (list (concat "\\<\\(class\\|interface\\)\\>\\s *"
2372 java-font-lock-identifier-regexp) 2353 java-font-lock-identifier-regexp)
2373 2 'font-lock-function-name-face) 2354 2 'font-lock-function-name-face)
2374 2355
2375 ;; Package declarations: 2356 ;; Package declarations:
2376 (list (concat "\\<\\(package\\|import\\)\\>\\s *" 2357 (list (concat "\\<\\(package\\|import\\)\\>\\s *"
2377 java-font-lock-identifier-regexp) 2358 java-font-lock-identifier-regexp)