Mercurial > hg > xemacs-beta
comparison lisp/font-lock.el @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | de805c49cfc1 |
children | 11054d720c21 |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
2 | 2 |
3 ;; Copyright (C) 1992-1995, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1992-1995, 1997 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@jwz.org>, for the LISPM Preservation Society. | 7 ;; Author: Jamie Zawinski <jwz@netscape.com>, for the LISPM Preservation Society. |
8 ;; Minimally merged with FSF 19.34 by Barry Warsaw <bwarsaw@python.org> | 8 ;; Minimally merged with FSF 19.34 by Barry Warsaw <bwarsaw@python.org> |
9 ;; Then (partially) synched with FSF 19.30, leading to: | 9 ;; Then (partially) synched with FSF 19.30, leading to: |
10 ;; Next Author: RMS | 10 ;; Next Author: RMS |
11 ;; Next Author: Simon Marshall <simon@gnu.ai.mit.edu> | 11 ;; Next Author: Simon Marshall <simon@gnu.ai.mit.edu> |
12 ;; Latest XEmacs Author: Ben Wing | 12 ;; Latest XEmacs Author: Ben Wing |
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, you will see status messages only if the changed region is | 181 chunk of text or revert a buffer, you will see status messages only if the |
182 large enough.) | 182 changed region is 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 defining the keywords for `font-lock-mode' to highlight. | 321 "A list of the keywords to highlight. |
322 | 322 Each element should be of the form: |
323 FONT-LOCK-KEYWORDS := List of FONT-LOCK-FORM's. | 323 |
324 | 324 MATCHER |
325 FONT-LOCK-FORM :== MATCHER | 325 (MATCHER . MATCH) |
326 | (MATCHER . MATCH) | 326 (MATCHER . FACENAME) |
327 | (MATCHER . FACE-FORM) | 327 (MATCHER . HIGHLIGHT) |
328 | (MATCHER . HIGHLIGHT) | 328 (MATCHER HIGHLIGHT ...) |
329 | (MATCHER HIGHLIGHT ...) | 329 (eval . FORM) |
330 | (eval . FORM) | 330 |
331 | 331 where HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED. |
332 MATCHER :== A string containing a regexp. | 332 |
333 | A variable containing a regexp to search for. | 333 FORM is an expression, whose value should be a keyword element, |
334 | A function to call to make the search. | 334 evaluated when the keyword is (first) used in a buffer. This feature |
335 It is called with one arg, the limit of the search, | 335 can be used to provide a keyword that can only be generated when Font |
336 and should leave MATCH results in the XEmacs global | 336 Lock mode is actually turned on. |
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.) | |
425 | 337 |
426 For highlighting single items, typically only MATCH-HIGHLIGHT is required. | 338 For highlighting single items, typically only MATCH-HIGHLIGHT is required. |
427 However, if an item or (typically) several items are to be highlighted | 339 However, if an item or (typically) items is to be highlighted following the |
428 following the instance of another item (the anchor) then MATCH-ANCHORED may be | 340 instance of another item (the anchor) then MATCH-ANCHORED may be required. |
429 required. | 341 |
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. | |
430 | 403 |
431 These regular expressions should not match text which spans lines. While | 404 These regular expressions should not match text which spans lines. While |
432 \\[font-lock-fontify-buffer] handles multi-line patterns correctly, updating when you | 405 \\[font-lock-fontify-buffer] handles multi-line patterns correctly, updating |
433 edit the buffer does not, since it considers text one line at a time. | 406 when you edit the buffer does not, since it considers text one line at a time. |
434 | 407 |
435 Be very careful composing regexps for this list; the wrong pattern can | 408 Be very careful composing regexps for this list; |
436 dramatically slow things down! | 409 the wrong pattern can dramatically slow things down!") |
437 ") | |
438 ;;;###autoload | 410 ;;;###autoload |
439 (make-variable-buffer-local 'font-lock-keywords) | 411 (make-variable-buffer-local 'font-lock-keywords) |
440 | 412 |
441 (defvar font-lock-defaults nil | 413 (defvar font-lock-defaults nil |
442 "The defaults font Font Lock mode for the current buffer. | 414 "The defaults font Font Lock mode for the current buffer. |
578 | 550 |
579 ;;; Initialization of faces. | 551 ;;; Initialization of faces. |
580 | 552 |
581 ;; #### barf gag retch. Horrid FSF lossage that we need to | 553 ;; #### barf gag retch. Horrid FSF lossage that we need to |
582 ;; keep around for compatibility with font-lock-keywords that | 554 ;; keep around for compatibility with font-lock-keywords that |
583 ;; forget to properly quote their faces. I tried just let-binding | 555 ;; forget to properly quote their faces. |
584 ;; them when we eval the face expression, but that failes because | |
585 ;; some files actually use the variables directly in their init code | |
586 ;; without quoting them. --ben | |
587 (defvar font-lock-comment-face 'font-lock-comment-face | 556 (defvar font-lock-comment-face 'font-lock-comment-face |
588 "This variable should not be set. | 557 "Don't even think of using this.") |
589 It is present only for horrid FSF compatibility reasons. | |
590 The corresponding face should be set using `edit-faces' or the | |
591 `set-face-*' functions.") | |
592 (defvar font-lock-doc-string-face 'font-lock-doc-string-face | 558 (defvar font-lock-doc-string-face 'font-lock-doc-string-face |
593 "This variable should not be set. | 559 "Don't even think of using this.") |
594 It is present only for horrid FSF compatibility reasons. | |
595 The corresponding face should be set using `edit-faces' or the | |
596 `set-face-*' functions.") | |
597 (defvar font-lock-string-face 'font-lock-string-face | 560 (defvar font-lock-string-face 'font-lock-string-face |
598 "This variable should not be set. | 561 "Don't even think of using this.") |
599 It is present only for horrid FSF compatibility reasons. | |
600 The corresponding face should be set using `edit-faces' or the | |
601 `set-face-*' functions.") | |
602 (defvar font-lock-keyword-face 'font-lock-keyword-face | 562 (defvar font-lock-keyword-face 'font-lock-keyword-face |
603 "This variable should not be set. | 563 "Don't even think of using this.") |
604 It is present only for horrid FSF compatibility reasons. | |
605 The corresponding face should be set using `edit-faces' or the | |
606 `set-face-*' functions.") | |
607 (defvar font-lock-function-name-face 'font-lock-function-name-face | 564 (defvar font-lock-function-name-face 'font-lock-function-name-face |
608 "This variable should not be set. | 565 "Don't even think of using this.") |
609 It is present only for horrid FSF compatibility reasons. | |
610 The corresponding face should be set using `edit-faces' or the | |
611 `set-face-*' functions.") | |
612 (defvar font-lock-variable-name-face 'font-lock-variable-name-face | 566 (defvar font-lock-variable-name-face 'font-lock-variable-name-face |
613 "This variable should not be set. | 567 "Don't even think of using this.") |
614 It is present only for horrid FSF compatibility reasons. | |
615 The corresponding face should be set using `edit-faces' or the | |
616 `set-face-*' functions.") | |
617 (defvar font-lock-type-face 'font-lock-type-face | 568 (defvar font-lock-type-face 'font-lock-type-face |
618 "This variable should not be set. | 569 "Don't even think of using this.") |
619 It is present only for horrid FSF compatibility reasons. | |
620 The corresponding face should be set using `edit-faces' or the | |
621 `set-face-*' functions.") | |
622 (defvar font-lock-reference-face 'font-lock-reference-face | 570 (defvar font-lock-reference-face 'font-lock-reference-face |
623 "This variable should not be set. | 571 "Don't even think of using this.") |
624 It is present only for horrid FSF compatibility reasons. | |
625 The corresponding face should be set using `edit-faces' or the | |
626 `set-face-*' functions.") | |
627 (defvar font-lock-preprocessor-face 'font-lock-preprocessor-face | 572 (defvar font-lock-preprocessor-face 'font-lock-preprocessor-face |
628 "This variable should not be set. | 573 "Don't even think of using this.") |
629 It is present only for horrid FSF compatibility reasons. | |
630 The corresponding face should be set using `edit-faces' or the | |
631 `set-face-*' functions.") | |
632 | 574 |
633 (defconst font-lock-face-list | 575 (defconst font-lock-face-list |
634 '(font-lock-comment-face | 576 '(font-lock-comment-face |
635 font-lock-string-face | 577 font-lock-string-face |
636 font-lock-doc-string-face | 578 font-lock-doc-string-face |
640 font-lock-type-face | 582 font-lock-type-face |
641 font-lock-reference-face | 583 font-lock-reference-face |
642 font-lock-preprocessor-face | 584 font-lock-preprocessor-face |
643 font-lock-warning-face)) | 585 font-lock-warning-face)) |
644 | 586 |
587 ;; #### There should be an emulation for the old font-lock-use-* | |
588 ;; settings! | |
589 | |
645 (defface font-lock-comment-face | 590 (defface font-lock-comment-face |
646 '((((class color) (background dark)) (:foreground "gray80")) | 591 '((((class color) (background dark)) (:foreground "gray80")) |
647 ;; blue4 is hardly different from black on windows. | |
648 (((class color) (background light) (type mswindows)) (:foreground "blue")) | |
649 (((class color) (background light)) (:foreground "blue4")) | 592 (((class color) (background light)) (:foreground "blue4")) |
650 (((class grayscale) (background light)) | 593 (((class grayscale) (background light)) |
651 (:foreground "DimGray" :bold t :italic t)) | 594 (:foreground "DimGray" :bold t :italic t)) |
652 (((class grayscale) (background dark)) | 595 (((class grayscale) (background dark)) |
653 (:foreground "LightGray" :bold t :italic t)) | 596 (:foreground "LightGray" :bold t :italic t)) |
666 | 609 |
667 (defface font-lock-doc-string-face | 610 (defface font-lock-doc-string-face |
668 '((((class color) (background dark)) (:foreground "light coral")) | 611 '((((class color) (background dark)) (:foreground "light coral")) |
669 (((class color) (background light)) (:foreground "green4")) | 612 (((class color) (background light)) (:foreground "green4")) |
670 (t (:bold t))) | 613 (t (:bold t))) |
671 "Font Lock mode face used to highlight documentation strings. | 614 "Font Lock mode face used to highlight documentation strings." |
672 This is currently supported only in Lisp-like modes, which are those | |
673 with \"lisp\" or \"scheme\" in their name. You can explicitly make | |
674 a mode Lisp-like by putting a non-nil `font-lock-lisp-like' property | |
675 on the major mode's symbol." | |
676 :group 'font-lock-faces) | 615 :group 'font-lock-faces) |
677 | 616 |
678 (defface font-lock-keyword-face | 617 (defface font-lock-keyword-face |
679 '((((class color) (background dark)) (:foreground "cyan")) | 618 '((((class color) (background dark)) (:foreground "cyan")) |
680 ;; red4 is hardly different from black on windows. | |
681 (((class color) (background light) (type mswindows)) (:foreground "red")) | |
682 (((class color) (background light)) (:foreground "red4")) | 619 (((class color) (background light)) (:foreground "red4")) |
683 (((class grayscale) (background light)) (:foreground "LightGray" :bold t)) | 620 (((class grayscale) (background light)) (:foreground "LightGray" :bold t)) |
684 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) | 621 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) |
685 (t (:bold t))) | 622 (t (:bold t))) |
686 "Font Lock mode face used to highlight keywords." | 623 "Font Lock mode face used to highlight keywords." |
687 :group 'font-lock-faces) | 624 :group 'font-lock-faces) |
688 | 625 |
689 (defface font-lock-function-name-face | 626 (defface font-lock-function-name-face |
690 '((((class color) (background dark)) (:foreground "aquamarine")) | 627 '((((class color) (background dark)) (:foreground "aquamarine")) |
691 ;; brown4 is hardly different from black on windows. | |
692 ;; I changed it to red because IMO it's pointless and ugly to | |
693 ;; use a million slightly different colors for niggly syntactic | |
694 ;; differences. --ben | |
695 (((class color) (background light) (type mswindows)) (:foreground "red")) | |
696 (((class color) (background light)) (:foreground "brown4")) | 628 (((class color) (background light)) (:foreground "brown4")) |
697 (t (:bold t :underline t))) | 629 (t (:bold t :underline t))) |
698 "Font Lock mode face used to highlight function names." | 630 "Font Lock mode face used to highlight function names." |
699 :group 'font-lock-faces) | 631 :group 'font-lock-faces) |
700 | 632 |
885 ;; (remove-hook 'pre-idle-hook 'font-lock-pre-idle-hook) | 817 ;; (remove-hook 'pre-idle-hook 'font-lock-pre-idle-hook) |
886 )) | 818 )) |
887 (set (make-local-variable 'font-lock-mode) on-p) | 819 (set (make-local-variable 'font-lock-mode) on-p) |
888 (cond (on-p | 820 (cond (on-p |
889 (font-lock-set-defaults-1) | 821 (font-lock-set-defaults-1) |
822 (make-local-hook 'before-revert-hook) | |
823 (make-local-hook 'after-revert-hook) | |
824 ;; If buffer is reverted, must clean up the state. | |
825 (add-hook 'before-revert-hook 'font-lock-revert-setup nil t) | |
826 (add-hook 'after-revert-hook 'font-lock-revert-cleanup nil t) | |
890 (run-hooks 'font-lock-mode-hook) | 827 (run-hooks 'font-lock-mode-hook) |
891 (cond (font-lock-fontified | 828 (cond (font-lock-fontified |
892 nil) | 829 nil) |
893 ((or (null maximum-size) (<= (buffer-size) maximum-size)) | 830 ((or (null maximum-size) (<= (buffer-size) maximum-size)) |
894 (font-lock-fontify-buffer)) | 831 (font-lock-fontify-buffer)) |
895 (font-lock-verbose | 832 (font-lock-verbose |
896 (lprogress-display 'font-lock | 833 (lmessage 'command "Fontifying %s... buffer too big." |
897 "Fontifying %s... buffer too big." 'abort | 834 (buffer-name))))) |
898 (buffer-name))))) | |
899 (font-lock-fontified | 835 (font-lock-fontified |
900 (setq font-lock-fontified nil) | 836 (setq font-lock-fontified nil) |
837 (remove-hook 'before-revert-hook 'font-lock-revert-setup t) | |
838 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup t) | |
901 (font-lock-unfontify-region (point-min) (point-max)) | 839 (font-lock-unfontify-region (point-min) (point-max)) |
902 (font-lock-thing-lock-cleanup)) | 840 (font-lock-thing-lock-cleanup)) |
903 (t | 841 (t |
842 (remove-hook 'before-revert-hook 'font-lock-revert-setup t) | |
843 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup t) | |
904 (font-lock-thing-lock-cleanup))) | 844 (font-lock-thing-lock-cleanup))) |
905 (redraw-modeline))) | 845 (redraw-modeline))) |
906 | 846 |
907 ;; For init-file hooks | 847 ;; For init-file hooks |
908 ;;;###autoload | 848 ;;;###autoload |
1021 (funcall font-lock-fontify-region-function beg end loudly)) | 961 (funcall font-lock-fontify-region-function beg end loudly)) |
1022 | 962 |
1023 (defun font-lock-unfontify-region (beg end &optional loudly) | 963 (defun font-lock-unfontify-region (beg end &optional loudly) |
1024 (funcall font-lock-unfontify-region-function beg end loudly)) | 964 (funcall font-lock-unfontify-region-function beg end loudly)) |
1025 | 965 |
966 ;; #### In these functions, the FSF is careful to do | |
967 ;; (save-restriction | |
968 ;; (widen) | |
969 ;; before anything else. Should we copy? | |
1026 (defun font-lock-default-fontify-buffer () | 970 (defun font-lock-default-fontify-buffer () |
1027 (interactive) | 971 (interactive) |
1028 ;; if we don't widen, then the C code will fail to | 972 (let ((was-on font-lock-mode) |
1029 ;; realize that we're inside a comment. | 973 (font-lock-verbose (or font-lock-verbose (interactive-p))) |
1030 (save-restriction | 974 (font-lock-message-threshold 0) |
1031 (widen) | 975 (aborted nil)) |
1032 (let ((was-on font-lock-mode) | 976 ;; Turn it on to run hooks and get the right font-lock-keywords. |
1033 (font-lock-verbose (or font-lock-verbose (interactive-p))) | 977 (or was-on (font-lock-mode 1)) |
1034 (font-lock-message-threshold 0) | 978 (font-lock-unfontify-region (point-min) (point-max) t) |
1035 (aborted nil)) | 979 ;; (buffer-syntactic-context-flush-cache) |
1036 ;; Turn it on to run hooks and get the right font-lock-keywords. | |
1037 (or was-on (font-lock-mode 1)) | |
1038 (font-lock-unfontify-region (point-min) (point-max) t) | |
1039 ;; (buffer-syntactic-context-flush-cache) | |
1040 | 980 |
1041 ;; If a ^G is typed during fontification, abort the fontification, but | 981 ;; If a ^G is typed during fontification, abort the fontification, but |
1042 ;; return normally (do not signal.) This is to make it easy to abort | 982 ;; return normally (do not signal.) This is to make it easy to abort |
1043 ;; fontification if it's taking a long time, without also causing the | 983 ;; fontification if it's taking a long time, without also causing the |
1044 ;; buffer not to pop up. If a real abort is desired, the user can ^G | 984 ;; buffer not to pop up. If a real abort is desired, the user can ^G |
1045 ;; again. | 985 ;; again. |
1046 ;; | 986 ;; |
1047 ;; Possibly this should happen down in font-lock-fontify-region instead | 987 ;; Possibly this should happen down in font-lock-fontify-region instead |
1048 ;; of here, but since that happens from the after-change-hook (meaning | 988 ;; of here, but since that happens from the after-change-hook (meaning |
1049 ;; much more frequently) I'm afraid of the bad consequences of stealing | 989 ;; much more frequently) I'm afraid of the bad consequences of stealing |
1050 ;; the interrupt character at inopportune times. | 990 ;; the interrupt character at inopportune times. |
1051 ;; | 991 ;; |
1052 (condition-case nil | 992 (condition-case nil |
1053 (save-excursion | 993 (save-excursion |
1054 (font-lock-fontify-region (point-min) (point-max))) | 994 (font-lock-fontify-region (point-min) (point-max))) |
1055 (t | 995 (quit |
1056 (setq aborted t))) | 996 (setq aborted t))) |
1057 | 997 |
1058 (or was-on ; turn it off if it was off. | 998 (or was-on ; turn it off if it was off. |
1059 (let ((font-lock-fontified nil)) ; kludge to prevent defontification | 999 (let ((font-lock-fontified nil)) ; kludge to prevent defontification |
1060 (font-lock-mode 0))) | 1000 (font-lock-mode 0))) |
1061 (set (make-local-variable 'font-lock-fontified) t) | 1001 (set (make-local-variable 'font-lock-fontified) t) |
1062 (when (and aborted font-lock-verbose) | 1002 (when (and aborted font-lock-verbose) |
1063 (lprogress-display 'font-lock "Fontifying %s... aborted." | 1003 (lmessage 'command "Fontifying %s... aborted." (buffer-name)))) |
1064 'abort (buffer-name)))) | 1004 (run-hooks 'font-lock-after-fontify-buffer-hook)) |
1065 (run-hooks 'font-lock-after-fontify-buffer-hook))) | |
1066 | 1005 |
1067 (defun font-lock-default-unfontify-buffer () | 1006 (defun font-lock-default-unfontify-buffer () |
1068 (font-lock-unfontify-region (point-min) (point-max)) | 1007 (font-lock-unfontify-region (point-min) (point-max)) |
1069 (set (make-local-variable 'font-lock-fontified) nil)) | 1008 (set (make-local-variable 'font-lock-fontified) nil)) |
1070 | 1009 |
1098 ; (font-lock-fontify-keywords-region beg end)) | 1037 ; (font-lock-fontify-keywords-region beg end)) |
1099 | 1038 |
1100 (defun font-lock-default-unfontify-region (beg end &optional maybe-loudly) | 1039 (defun font-lock-default-unfontify-region (beg end &optional maybe-loudly) |
1101 (when (and maybe-loudly font-lock-verbose | 1040 (when (and maybe-loudly font-lock-verbose |
1102 (>= (- end beg) font-lock-message-threshold)) | 1041 (>= (- end beg) font-lock-message-threshold)) |
1103 (lprogress-display 'font-lock "Fontifying %s..." 0 (buffer-name))) | 1042 (lmessage 'progress "Fontifying %s..." (buffer-name))) |
1104 (let ((modified (buffer-modified-p)) | 1043 (let ((modified (buffer-modified-p)) |
1105 (buffer-undo-list t) (inhibit-read-only t) | 1044 (buffer-undo-list t) (inhibit-read-only t) |
1106 buffer-file-name buffer-file-truename) | 1045 buffer-file-name buffer-file-truename) |
1107 (font-lock-remove-face beg end) | 1046 (font-lock-remove-face beg end) |
1108 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))) | 1047 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))) |
1109 | 1048 |
1110 ;; Following is the original FSF version (similar to our original | 1049 ;; Following is the original FSF version (similar to our original |
1111 ;; version, before the deferred stuff was added). | 1050 ;; version, before all the crap I added below). |
1051 ;; | |
1052 ;; Probably that crap should either be fixed up so it works better, | |
1053 ;; or tossed away. | |
1112 ;; | 1054 ;; |
1113 ;; I think that lazy-lock v2 tries to do something similar. | 1055 ;; I think that lazy-lock v2 tries to do something similar. |
1114 ;; Those efforts should be merged. | 1056 ;; Those efforts should be merged. |
1115 | 1057 |
1116 ;; Called when any modification is made to buffer text. | 1058 ;; Called when any modification is made to buffer text. |
1120 ; ;; Rescan between start of line from `beg' and start of line after `end'. | 1062 ; ;; Rescan between start of line from `beg' and start of line after `end'. |
1121 ; (font-lock-fontify-region | 1063 ; (font-lock-fontify-region |
1122 ; (progn (goto-char beg) (beginning-of-line) (point)) | 1064 ; (progn (goto-char beg) (beginning-of-line) (point)) |
1123 ; (progn (goto-char end) (forward-line 1) (point)))))) | 1065 ; (progn (goto-char end) (forward-line 1) (point)))))) |
1124 | 1066 |
1067 (defvar font-lock-old-extent nil) | |
1068 (defvar font-lock-old-len 0) | |
1069 | |
1070 (defun font-lock-fontify-glumped-region () | |
1071 ;; even if something goes wrong in the fontification, mark the glumped | |
1072 ;; region as fontified; otherwise, the same error might get signaled | |
1073 ;; after every command. | |
1074 (unwind-protect | |
1075 ;; buffer/extent may be deleted. | |
1076 (if (and (extent-live-p font-lock-old-extent) | |
1077 (buffer-live-p (extent-object font-lock-old-extent))) | |
1078 (save-excursion | |
1079 (set-buffer (extent-object font-lock-old-extent)) | |
1080 (font-lock-after-change-function-1 | |
1081 (extent-start-position font-lock-old-extent) | |
1082 (extent-end-position font-lock-old-extent) | |
1083 font-lock-old-len))) | |
1084 (detach-extent font-lock-old-extent) | |
1085 (setq font-lock-old-extent nil))) | |
1086 | |
1087 (defun font-lock-pre-idle-hook () | |
1088 (condition-case nil | |
1089 (if font-lock-old-extent | |
1090 (font-lock-fontify-glumped-region)) | |
1091 (error (warn "Error caught in `font-lock-pre-idle-hook'")))) | |
1092 | |
1125 (defvar font-lock-always-fontify-immediately nil | 1093 (defvar font-lock-always-fontify-immediately nil |
1126 "Set this to non-nil to disable font-lock deferral. | 1094 "Set this to non-nil to disable font-lock deferral.") |
1127 Otherwise, changes to existing text will not be processed until the | |
1128 next redisplay cycle, avoiding excessive fontification when many | |
1129 buffer modifications are performed or a buffer is reverted.") | |
1130 | |
1131 (defvar font-lock-pending-extent-table (make-hash-table :weakness 'key)) | |
1132 (defvar font-lock-range-table (make-range-table)) | |
1133 | |
1134 (defun font-lock-pre-idle-hook () | |
1135 (condition-case font-lock-error | |
1136 (if (> (hash-table-count font-lock-pending-extent-table) 0) | |
1137 (font-lock-fontify-pending-extents)) | |
1138 (error (warn "Error caught in `font-lock-pre-idle-hook': %s" | |
1139 font-lock-error)))) | |
1140 | 1095 |
1141 ;;; called when any modification is made to buffer text. This function | 1096 ;;; called when any modification is made to buffer text. This function |
1142 ;;; remembers the changed ranges until the next redisplay, at which point | 1097 ;;; attempts to glump adjacent changes together so that excessive |
1143 ;;; the extents are merged and pruned, and the resulting ranges fontified. | 1098 ;;; fontification is avoided. This function could easily be adapted |
1144 ;;; This function could easily be adapted to other after-change-functions. | 1099 ;;; to other after-change-functions. |
1145 | 1100 |
1146 (defun font-lock-after-change-function (beg end old-len) | 1101 (defun font-lock-after-change-function (beg end old-len) |
1147 (when font-lock-mode | 1102 (let ((obeg (and font-lock-old-extent |
1148 (let ((ex (make-extent beg end))) | 1103 (extent-start-position font-lock-old-extent))) |
1149 (set-extent-property ex 'detachable nil) | 1104 (oend (and font-lock-old-extent |
1150 (set-extent-property ex 'end-open nil) | 1105 (extent-end-position font-lock-old-extent))) |
1151 (let ((exs (gethash (current-buffer) font-lock-pending-extent-table))) | 1106 (bc-end (+ beg old-len))) |
1152 (push ex exs) | 1107 |
1153 (puthash (current-buffer) exs font-lock-pending-extent-table))) | 1108 ;; If this change can't be merged into the glumped one, |
1109 ;; we need to fontify the glumped one right now. | |
1110 (if (and font-lock-old-extent | |
1111 (or (not (eq (current-buffer) | |
1112 (extent-object font-lock-old-extent))) | |
1113 (< bc-end obeg) | |
1114 (> beg oend))) | |
1115 (font-lock-fontify-glumped-region)) | |
1116 | |
1117 (if font-lock-old-extent | |
1118 ;; Update glumped region. | |
1119 (progn | |
1120 ;; Any characters in the before-change region that are | |
1121 ;; outside the glumped region go into the glumped | |
1122 ;; before-change region. | |
1123 (if (> bc-end oend) | |
1124 (setq font-lock-old-len (+ font-lock-old-len (- bc-end oend)))) | |
1125 (if (> obeg beg) | |
1126 (setq font-lock-old-len (+ font-lock-old-len (- obeg beg)))) | |
1127 ;; New glumped region is the union of the glumped region | |
1128 ;; and the new region. | |
1129 (set-extent-endpoints font-lock-old-extent | |
1130 (min obeg beg) | |
1131 (max oend end))) | |
1132 | |
1133 ;; No glumped region, so create one. | |
1134 (setq font-lock-old-extent (make-extent beg end)) | |
1135 (set-extent-property font-lock-old-extent 'detachable nil) | |
1136 (set-extent-property font-lock-old-extent 'end-open nil) | |
1137 (setq font-lock-old-len old-len)) | |
1138 | |
1154 (if font-lock-always-fontify-immediately | 1139 (if font-lock-always-fontify-immediately |
1155 (font-lock-fontify-pending-extents)))) | 1140 (font-lock-fontify-glumped-region)))) |
1156 | 1141 |
1157 (defun font-lock-fontify-pending-extents () | 1142 (defun font-lock-after-change-function-1 (beg end old-len) |
1158 ;; ah, the beauty of mapping functions. | 1143 (if (null font-lock-mode) |
1159 ;; this function is actually shorter than the old version, which handled | 1144 nil |
1160 ;; only one buffer and one contiguous region! | 1145 (save-excursion |
1161 (save-match-data | 1146 (save-restriction |
1162 (maphash | 1147 ;; if we don't widen, then fill-paragraph (and any command that |
1163 #'(lambda (buffer exs) | 1148 ;; operates on a narrowed region) confuses things, because the C |
1164 ;; remove first, to avoid infinite reprocessing if error | 1149 ;; code will fail to realize that we're inside a comment. |
1165 (remhash buffer font-lock-pending-extent-table) | 1150 (widen) |
1166 (when (buffer-live-p buffer) | 1151 (save-match-data |
1167 (clear-range-table font-lock-range-table) | 1152 (let ((zmacs-region-stays zmacs-region-stays)) ; protect from change! |
1168 (with-current-buffer buffer | 1153 (goto-char beg) |
1169 (save-excursion | 1154 ;; Maybe flush the internal cache used by syntactically-sectionize. |
1170 (save-restriction | 1155 ;; (It'd be nice if this was more automatic.) Any deletions mean |
1171 ;; if we don't widen, then the C code will fail to | 1156 ;; the cache is invalid, and insertions at beginning or end of line |
1172 ;; realize that we're inside a comment. | 1157 ;; mean that the bol cache might be invalid. |
1173 (widen) | 1158 ;; (if (or (> old-len 0) (bobp) (= (preceding-char) ?\n)) |
1174 (let ((zmacs-region-stays | 1159 ;; (buffer-syntactic-context-flush-cache)) |
1175 zmacs-region-stays)) ; protect from change! | 1160 |
1176 (mapc | 1161 ;; Always recompute the whole line. |
1177 #'(lambda (ex) | 1162 (goto-char end) |
1178 ;; paranoia. | 1163 (forward-line 1) |
1179 (when (and (extent-live-p ex) | 1164 (setq end (point)) |
1180 (not (extent-detached-p ex))) | 1165 (goto-char beg) |
1181 ;; first expand the ranges to full lines, because | 1166 (beginning-of-line) |
1182 ;; that is what will be fontified; then use a | 1167 (setq beg (point)) |
1183 ;; range table to merge the ranges. | 1168 ;; Rescan between start of line from `beg' and start of line after |
1184 (let* ((beg (extent-start-position ex)) | 1169 ;; `end'. |
1185 (end (extent-end-position ex)) | 1170 (font-lock-fontify-region beg end))))))) |
1186 (beg (progn (goto-char beg) | 1171 |
1187 (beginning-of-line) | |
1188 (point))) | |
1189 (end (progn (goto-char end) | |
1190 (forward-line 1) | |
1191 (point)))) | |
1192 (detach-extent ex) | |
1193 (put-range-table beg end t | |
1194 font-lock-range-table)))) | |
1195 exs) | |
1196 (map-range-table | |
1197 #'(lambda (beg end val) | |
1198 ;; Maybe flush the internal cache used by | |
1199 ;; syntactically-sectionize. (It'd be nice if this | |
1200 ;; was more automatic.) Any deletions mean the | |
1201 ;; cache is invalid, and insertions at beginning or | |
1202 ;; end of line mean that the bol cache might be | |
1203 ;; invalid. | |
1204 ;; #### This code has been commented out for some time | |
1205 ;; now and is bit-rotting. Someone should look into | |
1206 ;; this. | |
1207 ;; (if (or change-was-deletion (bobp) | |
1208 ;; (= (preceding-char) ?\n)) | |
1209 ;; (buffer-syntactic-context-flush-cache)) | |
1210 ;; #### This creates some unnecessary progress gauges. | |
1211 ;; (if (and (= beg (point-min)) | |
1212 ;; (= end (point-max))) | |
1213 ;; (font-lock-fontify-buffer) | |
1214 ;; (font-lock-fontify-region beg end))) | |
1215 (font-lock-fontify-region beg end)) | |
1216 font-lock-range-table))))))) | |
1217 font-lock-pending-extent-table))) | |
1218 | 1172 |
1219 ;; Syntactic fontification functions. | 1173 ;; Syntactic fontification functions. |
1220 | 1174 |
1221 ;; Note: Here is the FSF version. Our version is much faster because | 1175 ;; Note: Here is the FSF version. Our version is much faster because |
1222 ;; of the C support we provide. This may be useful for reference, | 1176 ;; of the C support we provide. This may be useful for reference, |
1328 ; (setq prev nil))) | 1282 ; (setq prev nil))) |
1329 ; ;; | 1283 ; ;; |
1330 ; ;; Clean up. | 1284 ; ;; Clean up. |
1331 ; (and prev (remove-text-properties prev end '(face nil))))) | 1285 ; (and prev (remove-text-properties prev end '(face nil))))) |
1332 | 1286 |
1333 (defun font-lock-lisp-like (mode) | |
1334 ;; Note: (or (get mode 'font-lock-lisp-like) (string-match ...)) is | |
1335 ;; not enough because the property needs to be able to specify a nil | |
1336 ;; value. | |
1337 (if (plist-member (symbol-plist mode) 'font-lock-lisp-like) | |
1338 (get mode 'font-lock-lisp-like) | |
1339 ;; If the property is not specified, guess. Similar logic exists | |
1340 ;; in add-log, but I think this encompasses more modes. | |
1341 (string-match "lisp\\|scheme" (symbol-name mode)))) | |
1342 | |
1343 (defun font-lock-fontify-syntactically-region (start end &optional loudly) | 1287 (defun font-lock-fontify-syntactically-region (start end &optional loudly) |
1344 "Put proper face on each string and comment between START and END. | 1288 "Put proper face on each string and comment between START and END. |
1345 START should be at the beginning of a line." | 1289 START should be at the beginning of a line." |
1346 (if font-lock-keywords-only | 1290 (if font-lock-keywords-only |
1347 nil | 1291 nil |
1348 (when (and font-lock-verbose | 1292 (when (and font-lock-verbose |
1349 (>= (- end start) font-lock-message-threshold)) | 1293 (>= (- end start) font-lock-message-threshold)) |
1350 (lprogress-display 'font-lock "Fontifying %s... (syntactically)" 5 | 1294 (lmessage 'progress "Fontifying %s... (syntactically...)" |
1351 (buffer-name))) | 1295 (buffer-name))) |
1352 (font-lock-unfontify-region start end loudly) | 1296 (font-lock-unfontify-region start end loudly) |
1353 (goto-char start) | 1297 (goto-char start) |
1354 (if (> end (point-max)) (setq end (point-max))) | 1298 (if (> end (point-max)) (setq end (point-max))) |
1355 (let ((lisp-like (font-lock-lisp-like major-mode))) | 1299 (syntactically-sectionize |
1356 (syntactically-sectionize | 1300 #'(lambda (s e context depth) |
1357 #'(lambda (s e context depth) | 1301 (let (face) |
1358 (let (face) | 1302 (cond ((eq context 'string) |
1359 (cond ((eq context 'string) | 1303 ;;#### Should only do this is Lisp-like modes! |
1360 (setq face | 1304 (setq face |
1361 ;; #### It would be nice if we handled | 1305 (if (= depth 1) |
1362 ;; Python and other non-Lisp languages with | 1306 ;; really we should only use this if |
1363 ;; docstrings correctly. | 1307 ;; in position 3 depth 1, but that's |
1364 (if (and lisp-like (= depth 1)) | 1308 ;; too expensive to compute. |
1365 ;; really we should only use this if | 1309 'font-lock-doc-string-face |
1366 ;; in position 3 depth 1, but that's | 1310 'font-lock-string-face))) |
1367 ;; too expensive to compute. | 1311 ((or (eq context 'comment) |
1368 'font-lock-doc-string-face | 1312 (eq context 'block-comment)) |
1369 'font-lock-string-face))) | 1313 (setq face 'font-lock-comment-face) |
1370 ((or (eq context 'comment) | |
1371 (eq context 'block-comment)) | |
1372 (setq face 'font-lock-comment-face) | |
1373 ; ;; Don't fontify whitespace at the beginning of lines; | 1314 ; ;; Don't fontify whitespace at the beginning of lines; |
1374 ; ;; otherwise comment blocks may not line up with code. | 1315 ; ;; otherwise comment blocks may not line up with code. |
1375 ; ;; (This is sometimes a good idea, sometimes not; in any | 1316 ; ;; (This is sometimes a good idea, sometimes not; in any |
1376 ; ;; event it should be in C for speed --jwz) | 1317 ; ;; event it should be in C for speed --jwz) |
1377 ; (save-excursion | 1318 ; (save-excursion |
1380 ; (setq face 'font-lock-comment-face) | 1321 ; (setq face 'font-lock-comment-face) |
1381 ; (setq e (point))) | 1322 ; (setq e (point))) |
1382 ; (skip-chars-forward " \t\n") | 1323 ; (skip-chars-forward " \t\n") |
1383 ; (setq s (point))) | 1324 ; (setq s (point))) |
1384 )) | 1325 )) |
1385 (font-lock-set-face s e face))) | 1326 (font-lock-set-face s e face))) |
1386 start end) | 1327 start end) |
1387 ))) | 1328 )) |
1388 | 1329 |
1389 ;;; Additional text property functions. | 1330 ;;; Additional text property functions. |
1390 | 1331 |
1391 ;; The following three text property functions are not generally available (and | 1332 ;; The following three text property functions are not generally available (and |
1392 ;; it's not certain that they should be) so they are inlined for speed. | 1333 ;; it's not certain that they should be) so they are inlined for speed. |
1529 (defun font-lock-fontify-keywords-region (start end &optional loudvar) | 1470 (defun font-lock-fontify-keywords-region (start end &optional loudvar) |
1530 "Fontify according to `font-lock-keywords' between START and END. | 1471 "Fontify according to `font-lock-keywords' between START and END. |
1531 START should be at the beginning of a line." | 1472 START should be at the beginning of a line." |
1532 (let ((loudly (and font-lock-verbose | 1473 (let ((loudly (and font-lock-verbose |
1533 (>= (- end start) font-lock-message-threshold)))) | 1474 (>= (- end start) font-lock-message-threshold)))) |
1534 (let* ((case-fold-search font-lock-keywords-case-fold-search) | 1475 (let ((case-fold-search font-lock-keywords-case-fold-search) |
1535 (keywords (cdr (if (eq (car-safe font-lock-keywords) t) | 1476 (keywords (cdr (if (eq (car-safe font-lock-keywords) t) |
1536 font-lock-keywords | 1477 font-lock-keywords |
1537 (font-lock-compile-keywords)))) | 1478 (font-lock-compile-keywords)))) |
1538 (bufname (buffer-name)) | 1479 (bufname (buffer-name)) (count 0) |
1539 (progress 5) (old-progress 5) | 1480 keyword matcher highlights) |
1540 (iter 0) | |
1541 (nkeywords (length keywords)) | |
1542 keyword matcher highlights) | |
1543 ;; | 1481 ;; |
1544 ;; Fontify each item in `font-lock-keywords' from `start' to `end'. | 1482 ;; Fontify each item in `font-lock-keywords' from `start' to `end'. |
1545 ;; In order to measure progress accurately we need to know how | |
1546 ;; many keywords we have and how big the region is. Then progress | |
1547 ;; is ((pos - start)/ (end - start) * nkeywords | |
1548 ;; + iteration / nkeywords) * 100 | |
1549 (while keywords | 1483 (while keywords |
1484 (when loudly (lmessage 'progress "Fontifying %s... (regexps..%s)" | |
1485 bufname | |
1486 (make-string (setq count (1+ count)) ?.))) | |
1550 ;; | 1487 ;; |
1551 ;; Find an occurrence of `matcher' from `start' to `end'. | 1488 ;; Find an occurrence of `matcher' from `start' to `end'. |
1552 (setq keyword (car keywords) matcher (car keyword)) | 1489 (setq keyword (car keywords) matcher (car keyword)) |
1553 (goto-char start) | 1490 (goto-char start) |
1554 (while (and (< (point) end) | 1491 (while (and (< (point) end) |
1555 (if (stringp matcher) | 1492 (if (stringp matcher) |
1556 (re-search-forward matcher end t) | 1493 (re-search-forward matcher end t) |
1557 (funcall matcher end))) | 1494 (funcall matcher end))) |
1558 ;; calculate progress | |
1559 (setq progress | |
1560 (+ (/ (* (- (point) start) 95) (* (- end start) nkeywords)) | |
1561 (/ (* iter 95) nkeywords) 5)) | |
1562 (when (and loudly (> progress old-progress)) | |
1563 (lprogress-display 'font-lock "Fontifying %s... (regexps)" | |
1564 progress bufname)) | |
1565 (setq old-progress progress) | |
1566 ;; Apply each highlight to this instance of `matcher', which may be | 1495 ;; Apply each highlight to this instance of `matcher', which may be |
1567 ;; specific highlights or more keywords anchored to `matcher'. | 1496 ;; specific highlights or more keywords anchored to `matcher'. |
1568 (setq highlights (cdr keyword)) | 1497 (setq highlights (cdr keyword)) |
1569 (while highlights | 1498 (while highlights |
1570 (if (numberp (car (car highlights))) | 1499 (if (numberp (car (car highlights))) |
1574 ;; keyword so keywords can share bracketing | 1503 ;; keyword so keywords can share bracketing |
1575 ;; expressions. | 1504 ;; expressions. |
1576 (and end (goto-char end))) | 1505 (and end (goto-char end))) |
1577 (font-lock-fontify-anchored-keywords (car highlights) end)) | 1506 (font-lock-fontify-anchored-keywords (car highlights) end)) |
1578 (setq highlights (cdr highlights)))) | 1507 (setq highlights (cdr highlights)))) |
1579 (setq iter (1+ iter)) | |
1580 (setq keywords (cdr keywords)))) | 1508 (setq keywords (cdr keywords)))) |
1581 (if loudly (lprogress-display 'font-lock "Fontifying %s... " 100 (buffer-name))))) | 1509 (if loudly (lmessage 'progress "Fontifying %s... done." (buffer-name))))) |
1582 | 1510 |
1583 | 1511 |
1584 ;; Various functions. | 1512 ;; Various functions. |
1585 | 1513 |
1586 ;; Turn off other related packages if they're on. I prefer a hook. --sm. | 1514 ;; Turn off other related packages if they're on. I prefer a hook. --sm. |
1599 (defun font-lock-after-fontify-buffer () | 1527 (defun font-lock-after-fontify-buffer () |
1600 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode) | 1528 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode) |
1601 (fast-lock-after-fontify-buffer)) | 1529 (fast-lock-after-fontify-buffer)) |
1602 ((and (boundp 'lazy-lock-mode) lazy-lock-mode) | 1530 ((and (boundp 'lazy-lock-mode) lazy-lock-mode) |
1603 (lazy-lock-after-fontify-buffer)))) | 1531 (lazy-lock-after-fontify-buffer)))) |
1532 | |
1533 ;; If the buffer is about to be reverted, it won't be fontified afterward. | |
1534 (defun font-lock-revert-setup () | |
1535 (setq font-lock-fontified nil)) | |
1536 | |
1537 ;; If the buffer has just been reverted, normally that turns off | |
1538 ;; Font Lock mode. So turn the mode back on if necessary. | |
1539 ;; sb 1999-03-03 -- The above comment no longer appears to be operative as | |
1540 ;; the first call to normal-mode *will* restore the font-lock state and | |
1541 ;; this call forces a second font-locking to occur when reverting a buffer, | |
1542 ;; which is wasteful at best. | |
1543 ;(defalias 'font-lock-revert-cleanup 'turn-on-font-lock) | |
1544 (defun font-lock-revert-cleanup ()) | |
1604 | 1545 |
1605 | 1546 |
1606 ;; Various functions. | 1547 ;; Various functions. |
1607 | 1548 |
1608 (defun font-lock-compile-keywords (&optional keywords) | 1549 (defun font-lock-compile-keywords (&optional keywords) |
2379 ;; Special constants: | 2320 ;; Special constants: |
2380 '("\\<\\(this\\|super\\)\\>" (1 font-lock-reference-face)) | 2321 '("\\<\\(this\\|super\\)\\>" (1 font-lock-reference-face)) |
2381 '("\\<\\(false\\|null\\|true\\)\\>" (1 font-lock-keyword-face)) | 2322 '("\\<\\(false\\|null\\|true\\)\\>" (1 font-lock-keyword-face)) |
2382 | 2323 |
2383 ;; Class names: | 2324 ;; Class names: |
2384 (list (concat "\\<\\(class\\|interface\\)\\>\\s *" | 2325 (list (concat "\\<class\\>\\s *" java-font-lock-identifier-regexp) |
2385 java-font-lock-identifier-regexp) | 2326 1 'font-lock-function-name-face) |
2386 2 'font-lock-function-name-face) | |
2387 | 2327 |
2388 ;; Package declarations: | 2328 ;; Package declarations: |
2389 (list (concat "\\<\\(package\\|import\\)\\>\\s *" | 2329 (list (concat "\\<\\(package\\|import\\)\\>\\s *" |
2390 java-font-lock-identifier-regexp) | 2330 java-font-lock-identifier-regexp) |
2391 '(2 font-lock-reference-face) | 2331 '(2 font-lock-reference-face) |
2502 '(0 nil)) ; Workaround for bug in XEmacs. | 2442 '(0 nil)) ; Workaround for bug in XEmacs. |
2503 '(font-lock-match-java-declarations | 2443 '(font-lock-match-java-declarations |
2504 (goto-char (match-end 1)) | 2444 (goto-char (match-end 1)) |
2505 (goto-char (match-end 0)) | 2445 (goto-char (match-end 0)) |
2506 (1 font-lock-variable-name-face)))))) | 2446 (1 font-lock-variable-name-face)))))) |
2507 | 2447 |
2508 ;; Modifier keywords and Java doc tags | 2448 ;; Modifier keywords and Java doc tags |
2509 (setq java-font-lock-keywords-3 | 2449 (setq java-font-lock-keywords-3 |
2510 (append | 2450 (append |
2511 | 2451 |
2512 '( | 2452 '( |
2513 ;; Feature scoping: | 2453 ;; Feature scoping: |
2514 ;; These must come first or the Modifiers from keywords-1 will | 2454 ;; These must come first or the Modifiers from keywords-1 will |
2515 ;; catch them. We don't want to use override fontification here | 2455 ;; catch them. We don't want to use override fontification here |
2516 ;; because then these terms will be fontified within comments. | 2456 ;; because then these terms will be fontified within comments. |
2517 ("\\<private\\>" 0 font-lock-string-face) | 2457 ("\\<private\\>" 0 font-lock-string-face) |
2518 ("\\<protected\\>" 0 font-lock-preprocessor-face) | 2458 ("\\<protected\\>" 0 font-lock-preprocessor-face) |
2519 ("\\<public\\>" 0 font-lock-reference-face)) | 2459 ("\\<public\\>" 0 font-lock-reference-face)) |
2520 java-font-lock-keywords-2 | 2460 java-font-lock-keywords-2 |
2521 | 2461 |
2522 (list | 2462 (list |
2523 | 2463 |
2524 ;; Javadoc tags | 2464 ;; Java doc tags |
2525 '("@\\(author\\|deprecated\\|exception\\|throws\\|param\\|return\\|see\\|since\\|version\\|serial\\|serialData\\|serialField\\)\\s " | 2465 '("@\\(author\\|exception\\|param\\|return\\|see\\|version\\)\\s " |
2526 0 font-lock-keyword-face t) | 2466 0 font-lock-keyword-face t) |
2527 | 2467 |
2528 ;; Doc tag - Parameter identifiers | 2468 ;; Doc tag - Parameter identifiers |
2529 (list (concat "@param\\s +" java-font-lock-identifier-regexp) | 2469 (list (concat "@param\\s +" java-font-lock-identifier-regexp) |
2530 1 'font-lock-variable-name-face t) | 2470 1 'font-lock-variable-name-face t) |
2531 | 2471 |
2532 ;; Doc tag - Exception types | 2472 ;; Doc tag - Exception types |
2533 (list (concat "@\\(exception\\|throws\\)\\s +" | 2473 (list (concat "@exception\\ s*" |
2534 java-font-lock-identifier-regexp) | 2474 java-font-lock-identifier-regexp) |
2535 '(2 (if (equal (char-after (match-end 0)) ?.) | 2475 '(1 (if (equal (char-after (match-end 0)) ?.) |
2536 font-lock-reference-face font-lock-type-face) t) | 2476 font-lock-reference-face font-lock-type-face) t) |
2537 (list (concat "\\=\\." java-font-lock-identifier-regexp) | 2477 (list (concat "\\=\\." java-font-lock-identifier-regexp) |
2538 '(goto-char (match-end 0)) nil | 2478 '(goto-char (match-end 0)) nil |
2539 '(1 (if (equal (char-after (match-end 0)) ?.) | 2479 '(1 (if (equal (char-after (match-end 0)) ?.) |
2540 'font-lock-reference-face 'font-lock-type-face) t))) | 2480 'font-lock-reference-face 'font-lock-type-face) t))) |
2541 | 2481 |
2542 ;; Doc tag - Cross-references, usually to methods | 2482 ;; Doc tag - Cross-references, usually to methods |
2543 '("@see\\s +\\(\\S *[^][ \t\n\r\f(){},.;:]\\)" | 2483 '("@see\\s +\\(\\S *[^][ \t\n\r\f(){},.;:]\\)" |
2544 1 font-lock-function-name-face t) | 2484 1 font-lock-function-name-face t) |
2545 | 2485 |
2546 ;; Doc tag - docRoot (1.3) | |
2547 '("\\({ *@docRoot *}\\)" | |
2548 0 font-lock-keyword-face t) | |
2549 ;; Doc tag - beaninfo, unofficial but widely used, even by Sun | |
2550 '("\\(@beaninfo\\)" | |
2551 0 font-lock-keyword-face t) | |
2552 ;; Doc tag - Links | |
2553 '("{ *@link\\s +\\([^}]+\\)}" | |
2554 0 font-lock-keyword-face t) | |
2555 ;; Doc tag - Links | |
2556 '("{ *@link\\s +\\(\\(\\S +\\)\\|\\(\\S +\\s +\\S +\\)\\) *}" | |
2557 1 font-lock-function-name-face t) | |
2558 | |
2559 ))) | 2486 ))) |
2560 ) | 2487 ) |
2561 | 2488 |
2562 (defvar java-font-lock-keywords java-font-lock-keywords-1 | 2489 (defvar java-font-lock-keywords java-font-lock-keywords-1 |
2563 "Additional expressions to highlight in Java mode.") | 2490 "Additional expressions to highlight in Java mode.") |