Changeset 4018 for vendor/emacs-CVS_HEAD/lisp/font-lock.el
- Timestamp:
- 01/28/06 09:46:44 (3 years ago)
- Files:
-
- vendor/emacs-CVS_HEAD/lisp/font-lock.el (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
vendor/emacs-CVS_HEAD/lisp/font-lock.el
r3988 r4018 2 2 3 3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 4 ;; 2000, 2001, 2002, 2003, 2004 2005Free Software Foundation, Inc.4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 5 5 6 6 ;; Author: jwz, then rms, then sm … … 154 154 ;; (add-hook 'foo-mode-hook 155 155 ;; (lambda () 156 ;; ( make-local-variable 'font-lock-defaults)157 ;; (setq font-lock-defaults'(foo-font-lock-keywords t))))156 ;; (set (make-local-variable 'font-lock-defaults) 157 ;; '(foo-font-lock-keywords t)))) 158 158 159 159 ;;; Adding Font Lock support for modes: … … 175 175 ;; and within `bar-mode' there could be: 176 176 ;; 177 ;; ( make-local-variable 'font-lock-defaults)178 ;; (setq font-lock-defaults'(bar-font-lock-keywords nil t))177 ;; (set (make-local-variable 'font-lock-defaults) 178 ;; '(bar-font-lock-keywords nil t)) 179 179 180 180 ;; What is fontification for? You might say, "It's to make my code look nice." … … 213 213 (defgroup font-lock '((jit-lock custom-group)) 214 214 "Font Lock mode text highlighting package." 215 :link '(custom-manual "(emacs)Font Lock")216 :link '(custom-manual "(elisp)Font Lock Mode")215 :link '(custom-manual :tag "Emacs Manual" "(emacs)Font Lock") 216 :link '(custom-manual :tag "Elisp Manual" "(elisp)Font Lock Mode") 217 217 :group 'faces) 218 218 … … 464 464 "Alist of additional `font-lock-keywords' elements for major modes. 465 465 466 Each element has the form (MODE KEYWORDS . APPEND).466 Each element has the form (MODE KEYWORDS . HOW). 467 467 `font-lock-set-defaults' adds the elements in the list KEYWORDS to 468 468 `font-lock-keywords' when Font Lock is turned on in major mode MODE. 469 469 470 If APPENDis nil, KEYWORDS are added at the beginning of470 If HOW is nil, KEYWORDS are added at the beginning of 471 471 `font-lock-keywords'. If it is `set', they are used to replace the 472 value of `font-lock-keywords'. If APPENDis any other non-nil value,472 value of `font-lock-keywords'. If HOW is any other non-nil value, 473 473 they are added at the end. 474 474 … … 651 651 (font-lock-turn-off-thing-lock))) 652 652 653 (defun font-lock-add-keywords (mode keywords &optional append)653 (defun font-lock-add-keywords (mode keywords &optional how) 654 654 "Add highlighting KEYWORDS for MODE. 655 655 … … 658 658 KEYWORDS should be a list; see the variable `font-lock-keywords'. 659 659 By default they are added at the beginning of the current highlighting list. 660 If optional argument APPENDis `set', they are used to replace the current661 highlighting list. If APPENDis any other non-nil value, they are added at the660 If optional argument HOW is `set', they are used to replace the current 661 highlighting list. If HOW is any other non-nil value, they are added at the 662 662 end of the current highlighting list. 663 663 … … 692 692 `objc-font-lock-extra-types' and `java-font-lock-extra-types'." 693 693 (cond (mode 694 ;; If MODE is non-nil, add the KEYWORDS and APPENDspec to694 ;; If MODE is non-nil, add the KEYWORDS and HOW spec to 695 695 ;; `font-lock-keywords-alist' so `font-lock-set-defaults' uses them. 696 (let ((spec (cons keywords append)) cell)696 (let ((spec (cons keywords how)) cell) 697 697 (if (setq cell (assq mode font-lock-keywords-alist)) 698 (if (eq append'set)698 (if (eq how 'set) 699 699 (setcdr cell (list spec)) 700 700 (setcdr cell (append (cdr cell) (list spec)))) … … 702 702 ;; Make sure that `font-lock-removed-keywords-alist' does not 703 703 ;; contain the new keywords. 704 (font-lock-update-removed-keyword-alist mode keywords append))704 (font-lock-update-removed-keyword-alist mode keywords how)) 705 705 (t 706 706 ;; Otherwise set or add the keywords now. … … 713 713 (setq font-lock-keywords (cadr font-lock-keywords))) 714 714 ;; Now modify or replace them. 715 (if (eq append'set)715 (if (eq how 'set) 716 716 (setq font-lock-keywords keywords) 717 717 (font-lock-remove-keywords nil keywords) ;to avoid duplicates … … 719 719 (cdr font-lock-keywords) 720 720 font-lock-keywords))) 721 (setq font-lock-keywords (if append721 (setq font-lock-keywords (if how 722 722 (append old keywords) 723 723 (append keywords old))))) 724 724 ;; If the keywords were compiled before, compile them again. 725 725 (if was-compiled 726 (set (make-local-variable 'font-lock-keywords)727 (font-lock-compile-keywords font-lock-keywords t)))))))728 729 (defun font-lock-update-removed-keyword-alist (mode keywords append)726 (setq font-lock-keywords 727 (font-lock-compile-keywords font-lock-keywords t))))))) 728 729 (defun font-lock-update-removed-keyword-alist (mode keywords how) 730 730 "Update `font-lock-removed-keywords-alist' when adding new KEYWORDS to MODE." 731 731 ;; When font-lock is enabled first all keywords in the list … … 737 737 (let ((cell (assq mode font-lock-removed-keywords-alist))) 738 738 (if cell 739 (if (eq append'set)739 (if (eq how 'set) 740 740 ;; A new set of keywords is defined. Forget all about 741 741 ;; our old keywords that should be removed. … … 787 787 ;; `font-lock-keywords-alist'. 788 788 (when top-cell 789 (dolist (keyword-list- append-pair (cdr top-cell))790 ;; `keywords-list- append-pair' is a cons with a list of791 ;; keywords in the car top-cell and the original append789 (dolist (keyword-list-how-pair (cdr top-cell)) 790 ;; `keywords-list-how-pair' is a cons with a list of 791 ;; keywords in the car top-cell and the original how 792 792 ;; argument in the cdr top-cell. 793 (setcar keyword-list- append-pair794 (delete keyword (car keyword-list- append-pair))))795 ;; Remove keyword list/ appendpair when the keyword list796 ;; is empty and appenddoesn't specify `set'. (If it793 (setcar keyword-list-how-pair 794 (delete keyword (car keyword-list-how-pair)))) 795 ;; Remove keyword list/how pair when the keyword list 796 ;; is empty and how doesn't specify `set'. (If it 797 797 ;; should be deleted then previously deleted keywords 798 798 ;; would appear again.) … … 831 831 ;; If the keywords were compiled before, compile them again. 832 832 (if was-compiled 833 (set (make-local-variable 'font-lock-keywords)834 (font-lock-compile-keywords font-lock-keywords t)))))))833 (setq font-lock-keywords 834 (font-lock-compile-keywords font-lock-keywords t))))))) 835 835 836 836 ;;; Font Lock Support mode. … … 981 981 "Fontify the current buffer the way the function `font-lock-mode' would." 982 982 (interactive) 983 (font-lock-set-defaults) 983 984 (let ((font-lock-verbose (or font-lock-verbose (interactive-p)))) 984 985 (funcall font-lock-fontify-buffer-function))) … … 988 989 989 990 (defun font-lock-fontify-region (beg end &optional loudly) 991 (font-lock-set-defaults) 990 992 (funcall font-lock-fontify-region-function beg end loudly)) 991 993 … … 1001 1003 (when verbose 1002 1004 (format "Fontifying %s..." (buffer-name))) 1003 ;; Make sure we have the right `font-lock-keywords' etc.1004 (unless font-lock-mode1005 (font-lock-set-defaults))1006 1005 ;; Make sure we fontify etc. in the whole buffer. 1007 1006 (save-restriction … … 1124 1123 ((error quit) (message "Fontifying block...%s" error-data))))))) 1125 1124 1126 (if (boundp 'facemenu-keymap) 1127 (define-key facemenu-keymap "\M-o" 'font-lock-fontify-block)) 1125 (unless (featurep 'facemenu) 1126 (error "facemenu must be loaded before font-lock")) 1127 (define-key facemenu-keymap "\M-o" 'font-lock-fontify-block) 1128 1128 1129 1129 ;;; End of Fontification functions. … … 1508 1508 If REGEXP is non-nil, it means these keywords are used for 1509 1509 `font-lock-keywords' rather than for `font-lock-syntactic-keywords'." 1510 (if (not font-lock-set-defaults) 1511 ;; This should never happen. But some external packages sometimes 1512 ;; call font-lock in unexpected and incorrect ways. It's important to 1513 ;; stop processing at this point, otherwise we may end up changing the 1514 ;; global value of font-lock-keywords and break highlighting in many 1515 ;; other buffers. 1516 (error "Font-lock trying to use keywords before setting them up")) 1510 1517 (if (eq (car-safe keywords) t) 1511 1518 keywords … … 1574 1581 keywords) 1575 1582 ((numberp level) 1576 (or (nth level keywords) (car ( reversekeywords))))1583 (or (nth level keywords) (car (last keywords)))) 1577 1584 ((eq level t) 1578 (car ( reversekeywords)))1585 (car (last keywords))) 1579 1586 (t 1580 1587 (car keywords)))) … … 1642 1649 ;; Now compile the keywords. 1643 1650 (unless (eq (car font-lock-keywords) t) 1644 (set (make-local-variable 'font-lock-keywords)1645 (font-lock-compile-keywords font-lock-keywords t))))))1651 (setq font-lock-keywords 1652 (font-lock-compile-keywords font-lock-keywords t)))))) 1646 1653 1647 1654 ;;; Colour etc. support. … … 1957 1964 (goto-char (match-end 2))) 1958 1965 (error t))))) 1966 1967 ;; C preprocessor(cpp) is used outside of C, C++ and Objective-C source file. 1968 ;; e.g. assembler code and GNU linker script in Linux kernel. 1969 ;; `cpp-font-lock-keywords' is handy for modes for the files. 1970 ;; 1971 ;; Here we cannot use `regexp-opt' because because regex-opt is not preloaded 1972 ;; while font-lock.el is preloaded to emacs. So values pre-calculated with 1973 ;; regexp-opt are used here. 1974 1975 ;; `cpp-font-lock-keywords-source-directives' is calculated from: 1976 ;; 1977 ;; (regexp-opt 1978 ;; '("define" "elif" "else" "endif" "error" "file" "if" "ifdef" 1979 ;; "ifndef" "include" "line" "pragma" "undef")) 1980 ;; 1981 (defconst cpp-font-lock-keywords-source-directives 1982 "define\\|e\\(?:l\\(?:if\\|se\\)\\|ndif\\|rror\\)\\|file\\|i\\(?:f\\(?:n?def\\)?\\|nclude\\)\\|line\\|pragma\\|undef" 1983 "Regular expressoin used in `cpp-font-lock-keywords'.") 1984 1985 ;; `cpp-font-lock-keywords-source-depth' is calculated from: 1986 ;; 1987 ;; (regexp-opt-depth (regexp-opt 1988 ;; '("define" "elif" "else" "endif" "error" "file" "if" "ifdef" 1989 ;; "ifndef" "include" "line" "pragma" "undef"))) 1990 ;; 1991 (defconst cpp-font-lock-keywords-source-depth 0 1992 "An integer representing regular expression depth of `cpp-font-lock-keywords-source-directives'. 1993 Used in `cpp-font-lock-keywords'.") 1994 1995 (defconst cpp-font-lock-keywords 1996 (let* ((directives cpp-font-lock-keywords-source-directives) 1997 (directives-depth cpp-font-lock-keywords-source-depth)) 1998 (list 1999 ;; 2000 ;; Fontify error directives. 2001 '("^#[ \t]*error[ \t]+\\(.+\\)" 1 font-lock-warning-face prepend) 2002 ;; 2003 ;; Fontify filenames in #include <...> preprocessor directives as strings. 2004 '("^#[ \t]*\\(?:import\\|include\\)[ \t]*\\(<[^>\"\n]*>?\\)" 2005 1 font-lock-string-face prepend) 2006 ;; 2007 ;; Fontify function macro names. 2008 '("^#[ \t]*define[ \t]+\\([[:alpha:]_][[:alnum:]_$]*\\)(" 2009 (1 font-lock-function-name-face prepend) 2010 ;; 2011 ;; Macro arguments. 2012 ((lambda (limit) 2013 (re-search-forward 2014 "\\(?:\\([[:alpha:]_][[:alnum:]_]*\\)[,]?\\)" 2015 (or (save-excursion (re-search-forward ")" limit t)) 2016 limit) 2017 t)) 2018 nil nil (1 font-lock-variable-name-face prepend))) 2019 ;; 2020 ;; Fontify symbol names in #elif or #if ... defined preprocessor directives. 2021 '("^#[ \t]*\\(?:elif\\|if\\)\\>" 2022 ("\\<\\(defined\\)\\>[ \t]*(?\\([[:alpha:]_][[:alnum:]_]*\\)?" nil nil 2023 (1 font-lock-builtin-face prepend) (2 font-lock-variable-name-face prepend t))) 2024 ;; 2025 ;; Fontify otherwise as symbol names, and the preprocessor directive names. 2026 (list 2027 (concat "^\\(#[ \t]*\\(?:" directives 2028 "\\)\\)\\>[ \t!]*\\([[:alpha:]_][[:alnum:]_]*\\)?") 2029 '(1 font-lock-preprocessor-face prepend) 2030 (list (+ 2 directives-depth) 2031 'font-lock-variable-name-face nil t)))) 2032 "Font lock keyords for C preprocessor directives. 2033 `c-mode', `c++-mode' and `objc-mode' have their own 2034 font lock keyords for C preprocessor directives. This definition is for the 2035 other modes in which C preprocessor directives are used. e.g. `asm-mode' and 2036 `ld-script-mode'.") 2037 1959 2038 1960 2039 ;; Lisp. … … 1965 2044 (,(concat "(\\(def\\(" 1966 2045 ;; Function declarations. 1967 "\\(advice\\| varalias\\|alias\\|generic\\|macro\\*?\\|method\\|"2046 "\\(advice\\|alias\\|generic\\|macro\\*?\\|method\\|" 1968 2047 "setf\\|subst\\*?\\|un\\*?\\|" 1969 "ine-\\(condition\\|\\(?:derived\\|minor\\|generic\\)-mode\\|" 2048 "ine-\\(condition\\|" 2049 "\\(?:derived\\|\\(?:global-\\)?minor\\|generic\\)-mode\\|" 1970 2050 "method-combination\\|setf-expander\\|skeleton\\|widget\\|" 1971 2051 "function\\|\\(compiler\\|modify\\|symbol\\)-macro\\)\\)\\|" 1972 2052 ;; Variable declarations. 1973 "\\(const\\(ant\\)?\\|custom\\| face\\|parameter\\|var\\)\\|"2053 "\\(const\\(ant\\)?\\|custom\\|varalias\\|face\\|parameter\\|var\\)\\|" 1974 2054 ;; Structure declarations. 1975 2055 "\\(class\\|group\\|theme\\|package\\|struct\\|type\\)" … … 2047 2127 ("\\<:\\sw+\\>" 0 font-lock-builtin-face) 2048 2128 ;; ELisp and CLisp `&' keywords as types. 2049 ("\\ &\\sw+\\>" . font-lock-type-face)2129 ("\\<\\&\\sw+\\>" . font-lock-type-face) 2050 2130 ;; ELisp regexp grouping constructs 2051 2131 ((lambda (bound)
