Mercurial > hg > xemacs-beta
comparison lisp/font-lock.el @ 442:abe6d1db359e r21-2-36
Import from CVS: tag r21-2-36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:35:02 +0200 |
parents | 3a7e78e1142d |
children | 576fb035e263 |
comparison
equal
deleted
inserted
replaced
441:72a7cfa4a488 | 442:abe6d1db359e |
---|---|
1 ;;; font-lock.el --- decorating source files with fonts/colors based on syntax | 1 ;;; font-lock.el --- decorating source files with fonts/colors based on syntax |
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, 2000 Ben Wing. |
6 | 6 |
7 ;; Author: Jamie Zawinski <jwz@jwz.org>, for the LISPM Preservation Society. | 7 ;; Author: Jamie Zawinski <jwz@jwz.org>, 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 |
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. |
550 | 578 |
551 ;;; Initialization of faces. | 579 ;;; Initialization of faces. |
552 | 580 |
553 ;; #### barf gag retch. Horrid FSF lossage that we need to | 581 ;; #### barf gag retch. Horrid FSF lossage that we need to |
554 ;; keep around for compatibility with font-lock-keywords that | 582 ;; keep around for compatibility with font-lock-keywords that |
555 ;; forget to properly quote their faces. | 583 ;; forget to properly quote their faces. I tried just let-binding |
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 | |
556 (defvar font-lock-comment-face 'font-lock-comment-face | 587 (defvar font-lock-comment-face 'font-lock-comment-face |
557 "Don't even think of using this.") | 588 "This variable should not be set. |
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.") | |
558 (defvar font-lock-doc-string-face 'font-lock-doc-string-face | 592 (defvar font-lock-doc-string-face 'font-lock-doc-string-face |
559 "Don't even think of using this.") | 593 "This variable should not be set. |
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.") | |
560 (defvar font-lock-string-face 'font-lock-string-face | 597 (defvar font-lock-string-face 'font-lock-string-face |
561 "Don't even think of using this.") | 598 "This variable should not be set. |
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.") | |
562 (defvar font-lock-keyword-face 'font-lock-keyword-face | 602 (defvar font-lock-keyword-face 'font-lock-keyword-face |
563 "Don't even think of using this.") | 603 "This variable should not be set. |
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.") | |
564 (defvar font-lock-function-name-face 'font-lock-function-name-face | 607 (defvar font-lock-function-name-face 'font-lock-function-name-face |
565 "Don't even think of using this.") | 608 "This variable should not be set. |
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.") | |
566 (defvar font-lock-variable-name-face 'font-lock-variable-name-face | 612 (defvar font-lock-variable-name-face 'font-lock-variable-name-face |
567 "Don't even think of using this.") | 613 "This variable should not be set. |
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.") | |
568 (defvar font-lock-type-face 'font-lock-type-face | 617 (defvar font-lock-type-face 'font-lock-type-face |
569 "Don't even think of using this.") | 618 "This variable should not be set. |
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.") | |
570 (defvar font-lock-reference-face 'font-lock-reference-face | 622 (defvar font-lock-reference-face 'font-lock-reference-face |
571 "Don't even think of using this.") | 623 "This variable should not be set. |
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.") | |
572 (defvar font-lock-preprocessor-face 'font-lock-preprocessor-face | 627 (defvar font-lock-preprocessor-face 'font-lock-preprocessor-face |
573 "Don't even think of using this.") | 628 "This variable should not be set. |
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.") | |
574 | 632 |
575 (defconst font-lock-face-list | 633 (defconst font-lock-face-list |
576 '(font-lock-comment-face | 634 '(font-lock-comment-face |
577 font-lock-string-face | 635 font-lock-string-face |
578 font-lock-doc-string-face | 636 font-lock-doc-string-face |
582 font-lock-type-face | 640 font-lock-type-face |
583 font-lock-reference-face | 641 font-lock-reference-face |
584 font-lock-preprocessor-face | 642 font-lock-preprocessor-face |
585 font-lock-warning-face)) | 643 font-lock-warning-face)) |
586 | 644 |
587 ;; #### There should be an emulation for the old font-lock-use-* | |
588 ;; settings! | |
589 | |
590 (defface font-lock-comment-face | 645 (defface font-lock-comment-face |
591 '((((class color) (background dark)) (:foreground "gray80")) | 646 '((((class color) (background dark)) (:foreground "gray80")) |
647 ;; blue4 is hardly different from black on windows. | |
648 (((class color) (background light) (type mswindows)) (:foreground "blue")) | |
592 (((class color) (background light)) (:foreground "blue4")) | 649 (((class color) (background light)) (:foreground "blue4")) |
593 (((class grayscale) (background light)) | 650 (((class grayscale) (background light)) |
594 (:foreground "DimGray" :bold t :italic t)) | 651 (:foreground "DimGray" :bold t :italic t)) |
595 (((class grayscale) (background dark)) | 652 (((class grayscale) (background dark)) |
596 (:foreground "LightGray" :bold t :italic t)) | 653 (:foreground "LightGray" :bold t :italic t)) |
618 on the major mode's symbol." | 675 on the major mode's symbol." |
619 :group 'font-lock-faces) | 676 :group 'font-lock-faces) |
620 | 677 |
621 (defface font-lock-keyword-face | 678 (defface font-lock-keyword-face |
622 '((((class color) (background dark)) (:foreground "cyan")) | 679 '((((class color) (background dark)) (:foreground "cyan")) |
680 ;; red4 is hardly different from black on windows. | |
681 (((class color) (background light) (type mswindows)) (:foreground "red")) | |
623 (((class color) (background light)) (:foreground "red4")) | 682 (((class color) (background light)) (:foreground "red4")) |
624 (((class grayscale) (background light)) (:foreground "LightGray" :bold t)) | 683 (((class grayscale) (background light)) (:foreground "LightGray" :bold t)) |
625 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) | 684 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) |
626 (t (:bold t))) | 685 (t (:bold t))) |
627 "Font Lock mode face used to highlight keywords." | 686 "Font Lock mode face used to highlight keywords." |
628 :group 'font-lock-faces) | 687 :group 'font-lock-faces) |
629 | 688 |
630 (defface font-lock-function-name-face | 689 (defface font-lock-function-name-face |
631 '((((class color) (background dark)) (:foreground "aquamarine")) | 690 '((((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")) | |
632 (((class color) (background light)) (:foreground "brown4")) | 696 (((class color) (background light)) (:foreground "brown4")) |
633 (t (:bold t :underline t))) | 697 (t (:bold t :underline t))) |
634 "Font Lock mode face used to highlight function names." | 698 "Font Lock mode face used to highlight function names." |
635 :group 'font-lock-faces) | 699 :group 'font-lock-faces) |
636 | 700 |
821 ;; (remove-hook 'pre-idle-hook 'font-lock-pre-idle-hook) | 885 ;; (remove-hook 'pre-idle-hook 'font-lock-pre-idle-hook) |
822 )) | 886 )) |
823 (set (make-local-variable 'font-lock-mode) on-p) | 887 (set (make-local-variable 'font-lock-mode) on-p) |
824 (cond (on-p | 888 (cond (on-p |
825 (font-lock-set-defaults-1) | 889 (font-lock-set-defaults-1) |
826 (make-local-hook 'before-revert-hook) | |
827 (make-local-hook 'after-revert-hook) | |
828 ;; If buffer is reverted, must clean up the state. | |
829 (add-hook 'before-revert-hook 'font-lock-revert-setup nil t) | |
830 (add-hook 'after-revert-hook 'font-lock-revert-cleanup nil t) | |
831 (run-hooks 'font-lock-mode-hook) | 890 (run-hooks 'font-lock-mode-hook) |
832 (cond (font-lock-fontified | 891 (cond (font-lock-fontified |
833 nil) | 892 nil) |
834 ((or (null maximum-size) (<= (buffer-size) maximum-size)) | 893 ((or (null maximum-size) (<= (buffer-size) maximum-size)) |
835 (font-lock-fontify-buffer)) | 894 (font-lock-fontify-buffer)) |
836 (font-lock-verbose | 895 (font-lock-verbose |
837 (lmessage 'command "Fontifying %s... buffer too big." | 896 (progress-feedback-with-label |
838 (buffer-name))))) | 897 'font-lock |
898 "Fontifying %s... buffer too big." 'abort | |
899 (buffer-name))))) | |
839 (font-lock-fontified | 900 (font-lock-fontified |
840 (setq font-lock-fontified nil) | 901 (setq font-lock-fontified nil) |
841 (remove-hook 'before-revert-hook 'font-lock-revert-setup t) | |
842 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup t) | |
843 (font-lock-unfontify-region (point-min) (point-max)) | 902 (font-lock-unfontify-region (point-min) (point-max)) |
844 (font-lock-thing-lock-cleanup)) | 903 (font-lock-thing-lock-cleanup)) |
845 (t | 904 (t |
846 (remove-hook 'before-revert-hook 'font-lock-revert-setup t) | |
847 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup t) | |
848 (font-lock-thing-lock-cleanup))) | 905 (font-lock-thing-lock-cleanup))) |
849 (redraw-modeline))) | 906 (redraw-modeline))) |
850 | 907 |
851 ;; For init-file hooks | 908 ;; For init-file hooks |
852 ;;;###autoload | 909 ;;;###autoload |
965 (funcall font-lock-fontify-region-function beg end loudly)) | 1022 (funcall font-lock-fontify-region-function beg end loudly)) |
966 | 1023 |
967 (defun font-lock-unfontify-region (beg end &optional loudly) | 1024 (defun font-lock-unfontify-region (beg end &optional loudly) |
968 (funcall font-lock-unfontify-region-function beg end loudly)) | 1025 (funcall font-lock-unfontify-region-function beg end loudly)) |
969 | 1026 |
970 ;; #### In these functions, the FSF is careful to do | |
971 ;; (save-restriction | |
972 ;; (widen) | |
973 ;; before anything else. Should we copy? | |
974 (defun font-lock-default-fontify-buffer () | 1027 (defun font-lock-default-fontify-buffer () |
975 (interactive) | 1028 (interactive) |
976 (let ((was-on font-lock-mode) | 1029 ;; if we don't widen, then the C code will fail to |
977 (font-lock-verbose (or font-lock-verbose (interactive-p))) | 1030 ;; realize that we're inside a comment. |
978 (font-lock-message-threshold 0) | 1031 (save-restriction |
979 (aborted nil)) | 1032 (widen) |
980 ;; Turn it on to run hooks and get the right font-lock-keywords. | 1033 (let ((was-on font-lock-mode) |
981 (or was-on (font-lock-mode 1)) | 1034 (font-lock-verbose (or font-lock-verbose (interactive-p))) |
982 (font-lock-unfontify-region (point-min) (point-max) t) | 1035 (font-lock-message-threshold 0) |
983 ;; (buffer-syntactic-context-flush-cache) | 1036 (aborted nil)) |
1037 ;; Turn it on to run hooks and get the right font-lock-keywords. | |
1038 (or was-on (font-lock-mode 1)) | |
1039 (font-lock-unfontify-region (point-min) (point-max) t) | |
1040 ;; (buffer-syntactic-context-flush-cache) | |
984 | 1041 |
985 ;; If a ^G is typed during fontification, abort the fontification, but | 1042 ;; If a ^G is typed during fontification, abort the fontification, but |
986 ;; return normally (do not signal.) This is to make it easy to abort | 1043 ;; return normally (do not signal.) This is to make it easy to abort |
987 ;; fontification if it's taking a long time, without also causing the | 1044 ;; fontification if it's taking a long time, without also causing the |
988 ;; buffer not to pop up. If a real abort is desired, the user can ^G | 1045 ;; buffer not to pop up. If a real abort is desired, the user can ^G |
989 ;; again. | 1046 ;; again. |
990 ;; | 1047 ;; |
991 ;; Possibly this should happen down in font-lock-fontify-region instead | 1048 ;; Possibly this should happen down in font-lock-fontify-region instead |
992 ;; of here, but since that happens from the after-change-hook (meaning | 1049 ;; of here, but since that happens from the after-change-hook (meaning |
993 ;; much more frequently) I'm afraid of the bad consequences of stealing | 1050 ;; much more frequently) I'm afraid of the bad consequences of stealing |
994 ;; the interrupt character at inopportune times. | 1051 ;; the interrupt character at inopportune times. |
995 ;; | 1052 ;; |
996 (condition-case nil | 1053 (condition-case nil |
997 (save-excursion | 1054 (save-excursion |
998 (font-lock-fontify-region (point-min) (point-max))) | 1055 (font-lock-fontify-region (point-min) (point-max))) |
999 (quit | 1056 (t |
1000 (setq aborted t))) | 1057 (setq aborted t))) |
1001 | 1058 |
1002 (or was-on ; turn it off if it was off. | 1059 (or was-on ; turn it off if it was off. |
1003 (let ((font-lock-fontified nil)) ; kludge to prevent defontification | 1060 (let ((font-lock-fontified nil)) ; kludge to prevent defontification |
1004 (font-lock-mode 0))) | 1061 (font-lock-mode 0))) |
1005 (set (make-local-variable 'font-lock-fontified) t) | 1062 (set (make-local-variable 'font-lock-fontified) t) |
1006 (when (and aborted font-lock-verbose) | 1063 (when (and aborted font-lock-verbose) |
1007 (lmessage 'command "Fontifying %s... aborted." (buffer-name)))) | 1064 (progress-feedback-with-label 'font-lock "Fontifying %s... aborted." |
1008 (run-hooks 'font-lock-after-fontify-buffer-hook)) | 1065 'abort (buffer-name)))) |
1066 (run-hooks 'font-lock-after-fontify-buffer-hook))) | |
1009 | 1067 |
1010 (defun font-lock-default-unfontify-buffer () | 1068 (defun font-lock-default-unfontify-buffer () |
1011 (font-lock-unfontify-region (point-min) (point-max)) | 1069 (font-lock-unfontify-region (point-min) (point-max)) |
1012 (set (make-local-variable 'font-lock-fontified) nil)) | 1070 (set (make-local-variable 'font-lock-fontified) nil)) |
1013 | 1071 |
1041 ; (font-lock-fontify-keywords-region beg end)) | 1099 ; (font-lock-fontify-keywords-region beg end)) |
1042 | 1100 |
1043 (defun font-lock-default-unfontify-region (beg end &optional maybe-loudly) | 1101 (defun font-lock-default-unfontify-region (beg end &optional maybe-loudly) |
1044 (when (and maybe-loudly font-lock-verbose | 1102 (when (and maybe-loudly font-lock-verbose |
1045 (>= (- end beg) font-lock-message-threshold)) | 1103 (>= (- end beg) font-lock-message-threshold)) |
1046 (lmessage 'progress "Fontifying %s..." (buffer-name))) | 1104 (progress-feedback-with-label 'font-lock "Fontifying %s..." 0 |
1105 (buffer-name))) | |
1047 (let ((modified (buffer-modified-p)) | 1106 (let ((modified (buffer-modified-p)) |
1048 (buffer-undo-list t) (inhibit-read-only t) | 1107 (buffer-undo-list t) (inhibit-read-only t) |
1049 buffer-file-name buffer-file-truename) | 1108 buffer-file-name buffer-file-truename) |
1050 (font-lock-remove-face beg end) | 1109 (font-lock-remove-face beg end) |
1051 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))) | 1110 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))) |
1052 | 1111 |
1053 ;; Following is the original FSF version (similar to our original | 1112 ;; Following is the original FSF version (similar to our original |
1054 ;; version, before all the crap I added below). | 1113 ;; version, before the deferred stuff was added). |
1055 ;; | |
1056 ;; Probably that crap should either be fixed up so it works better, | |
1057 ;; or tossed away. | |
1058 ;; | 1114 ;; |
1059 ;; I think that lazy-lock v2 tries to do something similar. | 1115 ;; I think that lazy-lock v2 tries to do something similar. |
1060 ;; Those efforts should be merged. | 1116 ;; Those efforts should be merged. |
1061 | 1117 |
1062 ;; Called when any modification is made to buffer text. | 1118 ;; Called when any modification is made to buffer text. |
1066 ; ;; Rescan between start of line from `beg' and start of line after `end'. | 1122 ; ;; Rescan between start of line from `beg' and start of line after `end'. |
1067 ; (font-lock-fontify-region | 1123 ; (font-lock-fontify-region |
1068 ; (progn (goto-char beg) (beginning-of-line) (point)) | 1124 ; (progn (goto-char beg) (beginning-of-line) (point)) |
1069 ; (progn (goto-char end) (forward-line 1) (point)))))) | 1125 ; (progn (goto-char end) (forward-line 1) (point)))))) |
1070 | 1126 |
1071 (defvar font-lock-old-extent nil) | 1127 (defvar font-lock-always-fontify-immediately nil |
1072 (defvar font-lock-old-len 0) | 1128 "Set this to non-nil to disable font-lock deferral. |
1073 | 1129 Otherwise, changes to existing text will not be processed until the |
1074 (defun font-lock-fontify-glumped-region () | 1130 next redisplay cycle, avoiding excessive fontification when many |
1075 ;; even if something goes wrong in the fontification, mark the glumped | 1131 buffer modifications are performed or a buffer is reverted.") |
1076 ;; region as fontified; otherwise, the same error might get signaled | 1132 |
1077 ;; after every command. | 1133 (defvar font-lock-pending-extent-table (make-hash-table :weakness 'key)) |
1078 (unwind-protect | 1134 (defvar font-lock-range-table (make-range-table)) |
1079 ;; buffer/extent may be deleted. | |
1080 (if (and (extent-live-p font-lock-old-extent) | |
1081 (buffer-live-p (extent-object font-lock-old-extent))) | |
1082 (save-excursion | |
1083 (set-buffer (extent-object font-lock-old-extent)) | |
1084 (font-lock-after-change-function-1 | |
1085 (extent-start-position font-lock-old-extent) | |
1086 (extent-end-position font-lock-old-extent) | |
1087 font-lock-old-len))) | |
1088 (detach-extent font-lock-old-extent) | |
1089 (setq font-lock-old-extent nil))) | |
1090 | 1135 |
1091 (defun font-lock-pre-idle-hook () | 1136 (defun font-lock-pre-idle-hook () |
1092 (condition-case nil | 1137 (condition-case font-lock-error |
1093 (if font-lock-old-extent | 1138 (if (> (hash-table-count font-lock-pending-extent-table) 0) |
1094 (font-lock-fontify-glumped-region)) | 1139 (font-lock-fontify-pending-extents)) |
1095 (error (warn "Error caught in `font-lock-pre-idle-hook'")))) | 1140 (error (warn "Error caught in `font-lock-pre-idle-hook': %s" |
1096 | 1141 font-lock-error)))) |
1097 (defvar font-lock-always-fontify-immediately nil | |
1098 "Set this to non-nil to disable font-lock deferral.") | |
1099 | 1142 |
1100 ;;; called when any modification is made to buffer text. This function | 1143 ;;; called when any modification is made to buffer text. This function |
1101 ;;; attempts to glump adjacent changes together so that excessive | 1144 ;;; remembers the changed ranges until the next redisplay, at which point |
1102 ;;; fontification is avoided. This function could easily be adapted | 1145 ;;; the extents are merged and pruned, and the resulting ranges fontified. |
1103 ;;; to other after-change-functions. | 1146 ;;; This function could easily be adapted to other after-change-functions. |
1104 | 1147 |
1105 (defun font-lock-after-change-function (beg end old-len) | 1148 (defun font-lock-after-change-function (beg end old-len) |
1106 (let ((obeg (and font-lock-old-extent | 1149 (when font-lock-mode |
1107 (extent-start-position font-lock-old-extent))) | 1150 (let ((ex (make-extent beg end))) |
1108 (oend (and font-lock-old-extent | 1151 (set-extent-property ex 'detachable nil) |
1109 (extent-end-position font-lock-old-extent))) | 1152 (set-extent-property ex 'end-open nil) |
1110 (bc-end (+ beg old-len))) | 1153 (let ((exs (gethash (current-buffer) font-lock-pending-extent-table))) |
1111 | 1154 (push ex exs) |
1112 ;; If this change can't be merged into the glumped one, | 1155 (puthash (current-buffer) exs font-lock-pending-extent-table))) |
1113 ;; we need to fontify the glumped one right now. | |
1114 (if (and font-lock-old-extent | |
1115 (or (not (eq (current-buffer) | |
1116 (extent-object font-lock-old-extent))) | |
1117 (< bc-end obeg) | |
1118 (> beg oend))) | |
1119 (font-lock-fontify-glumped-region)) | |
1120 | |
1121 (if font-lock-old-extent | |
1122 ;; Update glumped region. | |
1123 (progn | |
1124 ;; Any characters in the before-change region that are | |
1125 ;; outside the glumped region go into the glumped | |
1126 ;; before-change region. | |
1127 (if (> bc-end oend) | |
1128 (setq font-lock-old-len (+ font-lock-old-len (- bc-end oend)))) | |
1129 (if (> obeg beg) | |
1130 (setq font-lock-old-len (+ font-lock-old-len (- obeg beg)))) | |
1131 ;; New glumped region is the union of the glumped region | |
1132 ;; and the new region. | |
1133 (set-extent-endpoints font-lock-old-extent | |
1134 (min obeg beg) | |
1135 (max oend end))) | |
1136 | |
1137 ;; No glumped region, so create one. | |
1138 (setq font-lock-old-extent (make-extent beg end)) | |
1139 (set-extent-property font-lock-old-extent 'detachable nil) | |
1140 (set-extent-property font-lock-old-extent 'end-open nil) | |
1141 (setq font-lock-old-len old-len)) | |
1142 | |
1143 (if font-lock-always-fontify-immediately | 1156 (if font-lock-always-fontify-immediately |
1144 (font-lock-fontify-glumped-region)))) | 1157 (font-lock-fontify-pending-extents)))) |
1145 | 1158 |
1146 (defun font-lock-after-change-function-1 (beg end old-len) | 1159 (defun font-lock-fontify-pending-extents () |
1147 (if (null font-lock-mode) | 1160 ;; ah, the beauty of mapping functions. |
1148 nil | 1161 ;; this function is actually shorter than the old version, which handled |
1149 (save-excursion | 1162 ;; only one buffer and one contiguous region! |
1150 (save-restriction | 1163 (save-match-data |
1151 ;; if we don't widen, then fill-paragraph (and any command that | 1164 (maphash |
1152 ;; operates on a narrowed region) confuses things, because the C | 1165 #'(lambda (buffer exs) |
1153 ;; code will fail to realize that we're inside a comment. | 1166 ;; remove first, to avoid infinite reprocessing if error |
1154 (widen) | 1167 (remhash buffer font-lock-pending-extent-table) |
1155 (save-match-data | 1168 (when (buffer-live-p buffer) |
1156 (let ((zmacs-region-stays zmacs-region-stays)) ; protect from change! | 1169 (clear-range-table font-lock-range-table) |
1157 (goto-char beg) | 1170 (with-current-buffer buffer |
1158 ;; Maybe flush the internal cache used by syntactically-sectionize. | 1171 (save-excursion |
1159 ;; (It'd be nice if this was more automatic.) Any deletions mean | 1172 (save-restriction |
1160 ;; the cache is invalid, and insertions at beginning or end of line | 1173 ;; if we don't widen, then the C code will fail to |
1161 ;; mean that the bol cache might be invalid. | 1174 ;; realize that we're inside a comment. |
1162 ;; (if (or (> old-len 0) (bobp) (= (preceding-char) ?\n)) | 1175 (widen) |
1163 ;; (buffer-syntactic-context-flush-cache)) | 1176 (let ((zmacs-region-stays |
1164 | 1177 zmacs-region-stays)) ; protect from change! |
1165 ;; Always recompute the whole line. | 1178 (mapc |
1166 (goto-char end) | 1179 #'(lambda (ex) |
1167 (forward-line 1) | 1180 ;; paranoia. |
1168 (setq end (point)) | 1181 (when (and (extent-live-p ex) |
1169 (goto-char beg) | 1182 (not (extent-detached-p ex))) |
1170 (beginning-of-line) | 1183 ;; first expand the ranges to full lines, because |
1171 (setq beg (point)) | 1184 ;; that is what will be fontified; then use a |
1172 ;; Rescan between start of line from `beg' and start of line after | 1185 ;; range table to merge the ranges. |
1173 ;; `end'. | 1186 (let* ((beg (extent-start-position ex)) |
1174 (font-lock-fontify-region beg end))))))) | 1187 (end (extent-end-position ex)) |
1175 | 1188 (beg (progn (goto-char beg) |
1189 (beginning-of-line) | |
1190 (point))) | |
1191 (end (progn (goto-char end) | |
1192 (forward-line 1) | |
1193 (point)))) | |
1194 (detach-extent ex) | |
1195 (put-range-table beg end t | |
1196 font-lock-range-table)))) | |
1197 exs) | |
1198 (map-range-table | |
1199 #'(lambda (beg end val) | |
1200 ;; Maybe flush the internal cache used by | |
1201 ;; syntactically-sectionize. (It'd be nice if this | |
1202 ;; was more automatic.) Any deletions mean the | |
1203 ;; cache is invalid, and insertions at beginning or | |
1204 ;; end of line mean that the bol cache might be | |
1205 ;; invalid. | |
1206 ;; #### This code has been commented out for some time | |
1207 ;; now and is bit-rotting. Someone should look into | |
1208 ;; this. | |
1209 ;; (if (or change-was-deletion (bobp) | |
1210 ;; (= (preceding-char) ?\n)) | |
1211 ;; (buffer-syntactic-context-flush-cache)) | |
1212 ;; #### This creates some unnecessary progress gauges. | |
1213 ;; (if (and (= beg (point-min)) | |
1214 ;; (= end (point-max))) | |
1215 ;; (font-lock-fontify-buffer) | |
1216 ;; (font-lock-fontify-region beg end))) | |
1217 (font-lock-fontify-region beg end)) | |
1218 font-lock-range-table))))))) | |
1219 font-lock-pending-extent-table))) | |
1176 | 1220 |
1177 ;; Syntactic fontification functions. | 1221 ;; Syntactic fontification functions. |
1178 | 1222 |
1179 ;; Note: Here is the FSF version. Our version is much faster because | 1223 ;; Note: Here is the FSF version. Our version is much faster because |
1180 ;; of the C support we provide. This may be useful for reference, | 1224 ;; of the C support we provide. This may be useful for reference, |
1303 START should be at the beginning of a line." | 1347 START should be at the beginning of a line." |
1304 (if font-lock-keywords-only | 1348 (if font-lock-keywords-only |
1305 nil | 1349 nil |
1306 (when (and font-lock-verbose | 1350 (when (and font-lock-verbose |
1307 (>= (- end start) font-lock-message-threshold)) | 1351 (>= (- end start) font-lock-message-threshold)) |
1308 (lmessage 'progress "Fontifying %s... (syntactically...)" | 1352 (progress-feedback-with-label 'font-lock |
1309 (buffer-name))) | 1353 "Fontifying %s... (syntactically)" 5 |
1354 (buffer-name))) | |
1310 (font-lock-unfontify-region start end loudly) | 1355 (font-lock-unfontify-region start end loudly) |
1311 (goto-char start) | 1356 (goto-char start) |
1312 (if (> end (point-max)) (setq end (point-max))) | 1357 (if (> end (point-max)) (setq end (point-max))) |
1313 (let ((lisp-like (font-lock-lisp-like major-mode))) | 1358 (let ((lisp-like (font-lock-lisp-like major-mode))) |
1314 (syntactically-sectionize | 1359 (syntactically-sectionize |
1487 (defun font-lock-fontify-keywords-region (start end &optional loudvar) | 1532 (defun font-lock-fontify-keywords-region (start end &optional loudvar) |
1488 "Fontify according to `font-lock-keywords' between START and END. | 1533 "Fontify according to `font-lock-keywords' between START and END. |
1489 START should be at the beginning of a line." | 1534 START should be at the beginning of a line." |
1490 (let ((loudly (and font-lock-verbose | 1535 (let ((loudly (and font-lock-verbose |
1491 (>= (- end start) font-lock-message-threshold)))) | 1536 (>= (- end start) font-lock-message-threshold)))) |
1492 (let ((case-fold-search font-lock-keywords-case-fold-search) | 1537 (let* ((case-fold-search font-lock-keywords-case-fold-search) |
1493 (keywords (cdr (if (eq (car-safe font-lock-keywords) t) | 1538 (keywords (cdr (if (eq (car-safe font-lock-keywords) t) |
1494 font-lock-keywords | 1539 font-lock-keywords |
1495 (font-lock-compile-keywords)))) | 1540 (font-lock-compile-keywords)))) |
1496 (bufname (buffer-name)) (count 0) | 1541 (bufname (buffer-name)) |
1497 keyword matcher highlights) | 1542 (progress 5) (old-progress 5) |
1543 (iter 0) | |
1544 (nkeywords (length keywords)) | |
1545 keyword matcher highlights) | |
1498 ;; | 1546 ;; |
1499 ;; Fontify each item in `font-lock-keywords' from `start' to `end'. | 1547 ;; Fontify each item in `font-lock-keywords' from `start' to `end'. |
1548 ;; In order to measure progress accurately we need to know how | |
1549 ;; many keywords we have and how big the region is. Then progress | |
1550 ;; is ((pos - start)/ (end - start) * nkeywords | |
1551 ;; + iteration / nkeywords) * 100 | |
1500 (while keywords | 1552 (while keywords |
1501 (when loudly (lmessage 'progress "Fontifying %s... (regexps..%s)" | |
1502 bufname | |
1503 (make-string (setq count (1+ count)) ?.))) | |
1504 ;; | 1553 ;; |
1505 ;; Find an occurrence of `matcher' from `start' to `end'. | 1554 ;; Find an occurrence of `matcher' from `start' to `end'. |
1506 (setq keyword (car keywords) matcher (car keyword)) | 1555 (setq keyword (car keywords) matcher (car keyword)) |
1507 (goto-char start) | 1556 (goto-char start) |
1508 (while (and (< (point) end) | 1557 (while (and (< (point) end) |
1509 (if (stringp matcher) | 1558 (if (stringp matcher) |
1510 (re-search-forward matcher end t) | 1559 (re-search-forward matcher end t) |
1511 (funcall matcher end))) | 1560 (funcall matcher end))) |
1561 ;; calculate progress | |
1562 (setq progress | |
1563 (+ (/ (* (- (point) start) 95) (* (- end start) nkeywords)) | |
1564 (/ (* iter 95) nkeywords) 5)) | |
1565 (when (and loudly (> progress old-progress)) | |
1566 (progress-feedback-with-label 'font-lock | |
1567 "Fontifying %s... (regexps)" | |
1568 progress bufname)) | |
1569 (setq old-progress progress) | |
1512 ;; Apply each highlight to this instance of `matcher', which may be | 1570 ;; Apply each highlight to this instance of `matcher', which may be |
1513 ;; specific highlights or more keywords anchored to `matcher'. | 1571 ;; specific highlights or more keywords anchored to `matcher'. |
1514 (setq highlights (cdr keyword)) | 1572 (setq highlights (cdr keyword)) |
1515 (while highlights | 1573 (while highlights |
1516 (if (numberp (car (car highlights))) | 1574 (if (numberp (car (car highlights))) |
1520 ;; keyword so keywords can share bracketing | 1578 ;; keyword so keywords can share bracketing |
1521 ;; expressions. | 1579 ;; expressions. |
1522 (and end (goto-char end))) | 1580 (and end (goto-char end))) |
1523 (font-lock-fontify-anchored-keywords (car highlights) end)) | 1581 (font-lock-fontify-anchored-keywords (car highlights) end)) |
1524 (setq highlights (cdr highlights)))) | 1582 (setq highlights (cdr highlights)))) |
1583 (setq iter (1+ iter)) | |
1525 (setq keywords (cdr keywords)))) | 1584 (setq keywords (cdr keywords)))) |
1526 (if loudly (lmessage 'progress "Fontifying %s... done." (buffer-name))))) | 1585 (if loudly |
1586 (progress-feedback-with-label 'font-lock "Fontifying %s... " 100 | |
1587 (buffer-name))))) | |
1527 | 1588 |
1528 | 1589 |
1529 ;; Various functions. | 1590 ;; Various functions. |
1530 | 1591 |
1531 ;; Turn off other related packages if they're on. I prefer a hook. --sm. | 1592 ;; Turn off other related packages if they're on. I prefer a hook. --sm. |
1544 (defun font-lock-after-fontify-buffer () | 1605 (defun font-lock-after-fontify-buffer () |
1545 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode) | 1606 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode) |
1546 (fast-lock-after-fontify-buffer)) | 1607 (fast-lock-after-fontify-buffer)) |
1547 ((and (boundp 'lazy-lock-mode) lazy-lock-mode) | 1608 ((and (boundp 'lazy-lock-mode) lazy-lock-mode) |
1548 (lazy-lock-after-fontify-buffer)))) | 1609 (lazy-lock-after-fontify-buffer)))) |
1549 | |
1550 ;; If the buffer is about to be reverted, it won't be fontified afterward. | |
1551 (defun font-lock-revert-setup () | |
1552 (setq font-lock-fontified nil)) | |
1553 | |
1554 ;; If the buffer has just been reverted, normally that turns off | |
1555 ;; Font Lock mode. So turn the mode back on if necessary. | |
1556 ;; sb 1999-03-03 -- The above comment no longer appears to be operative as | |
1557 ;; the first call to normal-mode *will* restore the font-lock state and | |
1558 ;; this call forces a second font-locking to occur when reverting a buffer, | |
1559 ;; which is wasteful at best. | |
1560 ;(defalias 'font-lock-revert-cleanup 'turn-on-font-lock) | |
1561 (defun font-lock-revert-cleanup ()) | |
1562 | 1610 |
1563 | 1611 |
1564 ;; Various functions. | 1612 ;; Various functions. |
1565 | 1613 |
1566 (defun font-lock-compile-keywords (&optional keywords) | 1614 (defun font-lock-compile-keywords (&optional keywords) |
1837 (append lisp-font-lock-keywords-1 | 1885 (append lisp-font-lock-keywords-1 |
1838 (list | 1886 (list |
1839 ;; | 1887 ;; |
1840 ;; Control structures. ELisp and CLisp combined. | 1888 ;; Control structures. ELisp and CLisp combined. |
1841 ;; | 1889 ;; |
1842 ;;(regexp-opt | |
1843 ;; '("cond" "if" "while" "let" "let*" "prog" "progn" "prog1" | |
1844 ;; "prog2" "progv" "catch" "throw" "save-restriction" | |
1845 ;; "save-excursion" "save-window-excursion" | |
1846 ;; "save-current-buffer" "with-current-buffer" | |
1847 ;; "with-temp-file" "with-temp-buffer" "with-output-to-string" | |
1848 ;; "with-string-as-buffer-contents" | |
1849 ;; "save-selected-window" "save-match-data" "unwind-protect" | |
1850 ;; "condition-case" "track-mouse" "autoload" | |
1851 ;; "eval-after-load" "eval-and-compile" "eval-when-compile" | |
1852 ;; "when" "unless" "do" "dolist" "dotimes" "flet" "labels" | |
1853 ;; "lambda" "return" "return-from")) | |
1854 (cons | 1890 (cons |
1855 (concat | 1891 (concat |
1856 "(\\(" | 1892 "(\\(" |
1857 "autoload\\|c\\(atch\\|ond\\(ition-case\\)?\\)\\|do\\(list\\|" | 1893 ;; beginning of generated stuff |
1858 "times\\)?\\|eval-\\(a\\(fter-load\\|nd-compile\\)\\|when-compile\\)\\|" | 1894 ;; to regenerate, use the regexp-opt below, then delete the outermost |
1859 "flet\\|if\\|l\\(a\\(bels\\|mbda\\)\\|et\\*?\\)\\|" | 1895 ;; grouping, then use the macro below to break up the string. |
1860 "prog[nv12\\*]?\\|return\\(-from\\)?\\|save-\\(current-buffer\\|" | 1896 ;; (regexp-opt |
1861 "excursion\\|match-data\\|restriction\\|selected-window\\|" | 1897 ;; '("cond" "if" "while" "let" "let*" "prog" "progn" "prog1" |
1862 "window-excursion\\)\\|t\\(hrow\\|rack-mouse\\)\\|un\\(less\\|" | 1898 ;; "prog2" "progv" "catch" "throw" "save-restriction" |
1863 "wind-protect\\)\\|w\\(h\\(en\\|ile\\)\\|ith-\\(current-buffer\\|" | 1899 ;; "save-excursion" "save-window-excursion" |
1864 "output-to-string\\|string-as-buffer-contents\\|temp-\\(buffer\\|" | 1900 ;; "save-current-buffer" "with-current-buffer" |
1865 "file\\)\\)\\)" | 1901 ;; "save-selected-window" "with-selected-window" |
1902 ;; "save-selected-frame" "with-selected-frame" | |
1903 ;; "with-temp-file" "with-temp-buffer" "with-output-to-string" | |
1904 ;; "with-string-as-buffer-contents" | |
1905 ;; "save-match-data" "unwind-protect" "call-with-condition-handler" | |
1906 ;; "condition-case" "track-mouse" "autoload" | |
1907 ;; "eval-after-load" "eval-and-compile" "eval-when-compile" | |
1908 ;; "when" "unless" "do" "dolist" "dotimes" "flet" "labels" | |
1909 ;; "lambda" "block" "return" "return-from" "loop") t) | |
1910 ;; (setq last-kbd-macro | |
1911 ;; (read-kbd-macro "\" C-7 C-1 <right> C-r \\\\| 3*<right> \" RET")) | |
1912 "autoload\\|block\\|c\\(?:a\\(?:ll-with-condition-handler\\|tch\\)\\|" | |
1913 "ond\\(?:ition-case\\)?\\)\\|do\\(?:list\\|times\\)?\\|" | |
1914 "eval-\\(?:a\\(?:fter-load\\|nd-compile\\)\\|when-compile\\)\\|flet\\|" | |
1915 "if\\|l\\(?:a\\(?:bels\\|mbda\\)\\|et\\*?\\|oop\\)\\|prog[12nv]?\\|" | |
1916 "return\\(?:-from\\)?\\|save-\\(?:current-buffer\\|excursion\\|" | |
1917 "match-data\\|restriction\\|selected-\\(?:frame\\|window\\)\\|" | |
1918 "window-excursion\\)\\|t\\(?:hrow\\|rack-mouse\\)\\|un\\(?:less\\|" | |
1919 "wind-protect\\)\\|w\\(?:h\\(?:en\\|ile\\)\\|ith-\\(?:current-buffer\\|" | |
1920 "output-to-string\\|s\\(?:elected-\\(?:frame\\|window\\)\\|" | |
1921 "tring-as-buffer-contents\\)\\|temp-\\(?:buffer\\|file\\)\\)\\)" | |
1922 ;; end of generated stuff | |
1866 "\\)\\>") 1) | 1923 "\\)\\>") 1) |
1867 ;; | 1924 ;; |
1868 ;; Feature symbols as references. | 1925 ;; Feature symbols as references. |
1869 '("(\\(featurep\\|provide\\|require\\)\\>[ \t']*\\(\\sw+\\)?" | 1926 '("(\\(featurep\\|provide\\|require\\)\\>[ \t']*\\(\\sw+\\)?" |
1870 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) | 1927 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) |
2292 (defvar java-font-lock-type-regexp | 2349 (defvar java-font-lock-type-regexp |
2293 (concat "\\<\\(boolean\\|byte\\|char\\|double\\|float\\|int" | 2350 (concat "\\<\\(boolean\\|byte\\|char\\|double\\|float\\|int" |
2294 "\\|long\\|short\\|void\\)\\>") | 2351 "\\|long\\|short\\|void\\)\\>") |
2295 "Regexp which should match a primitive type.") | 2352 "Regexp which should match a primitive type.") |
2296 | 2353 |
2297 (let ((capital-letter "A-Z\300-\326\330-\337") | |
2298 (letter "a-zA-Z_$\300-\326\330-\366\370-\377") | |
2299 (digit "0-9")) | |
2300 (defvar java-font-lock-identifier-regexp | 2354 (defvar java-font-lock-identifier-regexp |
2301 (concat "\\<\\([" letter "][" letter digit "]*\\)\\>") | 2355 (let ((letter "a-zA-Z_$\300-\326\330-\366\370-\377") |
2356 (digit "0-9")) | |
2357 (concat "\\<\\([" letter "][" letter digit "]*\\)\\>")) | |
2302 "Regexp which should match all Java identifiers.") | 2358 "Regexp which should match all Java identifiers.") |
2303 | 2359 |
2304 (defvar java-font-lock-class-name-regexp | 2360 (defvar java-font-lock-class-name-regexp |
2305 (concat "\\<\\([" capital-letter "][" letter digit "]*\\)\\>") | 2361 (let ((capital-letter "A-Z\300-\326\330-\337") |
2362 (letter "a-zA-Z_$\300-\326\330-\366\370-\377") | |
2363 (digit "0-9")) | |
2364 (concat "\\<\\([" capital-letter "][" letter digit "]*\\)\\>")) | |
2306 "Regexp which should match a class or an interface name. | 2365 "Regexp which should match a class or an interface name. |
2307 The name is assumed to begin with a capital letter.") | 2366 The name is assumed to begin with a capital letter.") |
2308 ) | |
2309 | |
2310 | 2367 |
2311 (let ((java-modifier-regexp | 2368 (let ((java-modifier-regexp |
2312 (concat "\\<\\(abstract\\|const\\|final\\|native\\|" | 2369 (concat "\\<\\(abstract\\|const\\|final\\|native\\|" |
2313 "private\\|protected\\|public\\|" | 2370 "private\\|protected\\|public\\|" |
2314 "static\\|synchronized\\|transient\\|volatile\\)\\>"))) | 2371 "static\\|synchronized\\|transient\\|volatile\\)\\>"))) |
2337 ;; Special constants: | 2394 ;; Special constants: |
2338 '("\\<\\(this\\|super\\)\\>" (1 font-lock-reference-face)) | 2395 '("\\<\\(this\\|super\\)\\>" (1 font-lock-reference-face)) |
2339 '("\\<\\(false\\|null\\|true\\)\\>" (1 font-lock-keyword-face)) | 2396 '("\\<\\(false\\|null\\|true\\)\\>" (1 font-lock-keyword-face)) |
2340 | 2397 |
2341 ;; Class names: | 2398 ;; Class names: |
2342 (list (concat "\\<class\\>\\s *" java-font-lock-identifier-regexp) | 2399 (list (concat "\\<\\(class\\|interface\\)\\>\\s *" |
2343 1 'font-lock-function-name-face) | 2400 java-font-lock-identifier-regexp) |
2401 2 'font-lock-function-name-face) | |
2344 | 2402 |
2345 ;; Package declarations: | 2403 ;; Package declarations: |
2346 (list (concat "\\<\\(package\\|import\\)\\>\\s *" | 2404 (list (concat "\\<\\(package\\|import\\)\\>\\s *" |
2347 java-font-lock-identifier-regexp) | 2405 java-font-lock-identifier-regexp) |
2348 '(2 font-lock-reference-face) | 2406 '(2 font-lock-reference-face) |
2476 ("\\<public\\>" 0 font-lock-reference-face)) | 2534 ("\\<public\\>" 0 font-lock-reference-face)) |
2477 java-font-lock-keywords-2 | 2535 java-font-lock-keywords-2 |
2478 | 2536 |
2479 (list | 2537 (list |
2480 | 2538 |
2481 ;; Java doc tags | 2539 ;; Javadoc tags |
2482 '("@\\(author\\|exception\\|throws\\|deprecated\\|param\\|return\\|see\\|since\\|version\\)\\s " | 2540 '("@\\(author\\|deprecated\\|exception\\|throws\\|param\\|return\\|see\\|since\\|version\\|serial\\|serialData\\|serialField\\)\\s " |
2483 0 font-lock-keyword-face t) | 2541 0 font-lock-keyword-face t) |
2484 | 2542 |
2485 ;; Doc tag - Parameter identifiers | 2543 ;; Doc tag - Parameter identifiers |
2486 (list (concat "@param\\s +" java-font-lock-identifier-regexp) | 2544 (list (concat "@param\\s +" java-font-lock-identifier-regexp) |
2487 1 'font-lock-variable-name-face t) | 2545 1 'font-lock-variable-name-face t) |
2488 | 2546 |
2489 ;; Doc tag - Exception types | 2547 ;; Doc tag - Exception types |
2490 (list (concat "@exception\\s +" | 2548 (list (concat "@\\(exception\\|throws\\)\\s +" |
2491 java-font-lock-identifier-regexp) | 2549 java-font-lock-identifier-regexp) |
2492 '(1 (if (equal (char-after (match-end 0)) ?.) | 2550 '(2 (if (equal (char-after (match-end 0)) ?.) |
2493 font-lock-reference-face font-lock-type-face) t) | 2551 font-lock-reference-face font-lock-type-face) t) |
2494 (list (concat "\\=\\." java-font-lock-identifier-regexp) | 2552 (list (concat "\\=\\." java-font-lock-identifier-regexp) |
2495 '(goto-char (match-end 0)) nil | 2553 '(goto-char (match-end 0)) nil |
2496 '(1 (if (equal (char-after (match-end 0)) ?.) | 2554 '(1 (if (equal (char-after (match-end 0)) ?.) |
2497 'font-lock-reference-face 'font-lock-type-face) t))) | 2555 'font-lock-reference-face 'font-lock-type-face) t))) |
2498 | 2556 |
2499 ;; Doc tag - Exception types | |
2500 (list (concat "@exception\\s +" | |
2501 java-font-lock-identifier-regexp) | |
2502 '(1 (if (equal (char-after (match-end 0)) ?.) | |
2503 font-lock-reference-face font-lock-type-face) t) | |
2504 (list (concat "\\=\\." java-font-lock-identifier-regexp) | |
2505 '(goto-char (match-end 0)) nil | |
2506 '(1 (if (equal (char-after (match-end 0)) ?.) | |
2507 'font-lock-reference-face 'font-lock-type-face) t))) | |
2508 | |
2509 ;; Doc tag - Cross-references, usually to methods | 2557 ;; Doc tag - Cross-references, usually to methods |
2510 '("@see\\s +\\(\\S *[^][ \t\n\r\f(){},.;:]\\)" | 2558 '("@see\\s +\\(\\S *[^][ \t\n\r\f(){},.;:]\\)" |
2511 1 font-lock-function-name-face t) | 2559 1 font-lock-function-name-face t) |
2512 | 2560 |
2513 ;; Doc tag - Links | 2561 ;; Doc tag - docRoot (1.3) |
2514 '("{@link\\s +\\([^}]*\\)}" | 2562 '("\\({ *@docRoot *}\\)" |
2563 0 font-lock-keyword-face t) | |
2564 ;; Doc tag - beaninfo, unofficial but widely used, even by Sun | |
2565 '("\\(@beaninfo\\)" | |
2515 0 font-lock-keyword-face t) | 2566 0 font-lock-keyword-face t) |
2516 ;; Doc tag - Links | 2567 ;; Doc tag - Links |
2517 '("{@link\\s +\\(\\S +\\s +\\S +\\)}" | 2568 '("{ *@link\\s +\\([^}]+\\)}" |
2569 0 font-lock-keyword-face t) | |
2570 ;; Doc tag - Links | |
2571 '("{ *@link\\s +\\(\\(\\S +\\)\\|\\(\\S +\\s +\\S +\\)\\) *}" | |
2518 1 font-lock-function-name-face t) | 2572 1 font-lock-function-name-face t) |
2519 | 2573 |
2520 ))) | 2574 ))) |
2521 ) | 2575 ) |
2522 | 2576 |