Show
Ignore:
Timestamp:
01/28/06 09:46:44 (3 years ago)
Author:
miyoshi
Message:

Update.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • vendor/emacs-CVS_HEAD/lisp/font-lock.el

    r3988 r4018  
    22 
    33;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 
    4 ;;   2000, 2001, 2002, 2003, 2004 2005 Free Software Foundation, Inc. 
     4;;   2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 
    55 
    66;; Author: jwz, then rms, then sm 
     
    154154;;  (add-hook 'foo-mode-hook 
    155155;;   (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)))) 
    158158 
    159159;;; Adding Font Lock support for modes: 
     
    175175;; and within `bar-mode' there could be: 
    176176;; 
    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)) 
    179179  
    180180;; What is fontification for?  You might say, "It's to make my code look nice." 
     
    213213(defgroup font-lock '((jit-lock custom-group)) 
    214214  "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") 
    217217  :group 'faces) 
    218218 
     
    464464  "Alist of additional `font-lock-keywords' elements for major modes. 
    465465 
    466 Each element has the form (MODE KEYWORDS . APPEND). 
     466Each element has the form (MODE KEYWORDS . HOW). 
    467467`font-lock-set-defaults' adds the elements in the list KEYWORDS to 
    468468`font-lock-keywords' when Font Lock is turned on in major mode MODE. 
    469469 
    470 If APPEND is nil, KEYWORDS are added at the beginning of 
     470If HOW is nil, KEYWORDS are added at the beginning of 
    471471`font-lock-keywords'.  If it is `set', they are used to replace the 
    472 value of `font-lock-keywords'.  If APPEND is any other non-nil value, 
     472value of `font-lock-keywords'.  If HOW is any other non-nil value, 
    473473they are added at the end. 
    474474 
     
    651651    (font-lock-turn-off-thing-lock))) 
    652652 
    653 (defun font-lock-add-keywords (mode keywords &optional append
     653(defun font-lock-add-keywords (mode keywords &optional how
    654654  "Add highlighting KEYWORDS for MODE. 
    655655 
     
    658658KEYWORDS should be a list; see the variable `font-lock-keywords'. 
    659659By default they are added at the beginning of the current highlighting list. 
    660 If optional argument APPEND is `set', they are used to replace the current 
    661 highlighting list.  If APPEND is any other non-nil value, they are added at the 
     660If optional argument HOW is `set', they are used to replace the current 
     661highlighting list.  If HOW is any other non-nil value, they are added at the 
    662662end of the current highlighting list. 
    663663 
     
    692692`objc-font-lock-extra-types' and `java-font-lock-extra-types'." 
    693693  (cond (mode 
    694          ;; If MODE is non-nil, add the KEYWORDS and APPEND spec to 
     694         ;; If MODE is non-nil, add the KEYWORDS and HOW spec to 
    695695         ;; `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) 
    697697           (if (setq cell (assq mode font-lock-keywords-alist)) 
    698                (if (eq append 'set) 
     698               (if (eq how 'set) 
    699699                   (setcdr cell (list spec)) 
    700700                 (setcdr cell (append (cdr cell) (list spec)))) 
     
    702702         ;; Make sure that `font-lock-removed-keywords-alist' does not 
    703703         ;; contain the new keywords. 
    704          (font-lock-update-removed-keyword-alist mode keywords append)) 
     704         (font-lock-update-removed-keyword-alist mode keywords how)) 
    705705        (t 
    706706         ;; Otherwise set or add the keywords now. 
     
    713713               (setq font-lock-keywords (cadr font-lock-keywords))) 
    714714           ;; Now modify or replace them. 
    715            (if (eq append 'set) 
     715           (if (eq how 'set) 
    716716               (setq font-lock-keywords keywords) 
    717717             (font-lock-remove-keywords nil keywords) ;to avoid duplicates 
     
    719719                            (cdr font-lock-keywords) 
    720720                          font-lock-keywords))) 
    721                (setq font-lock-keywords (if append 
     721               (setq font-lock-keywords (if how 
    722722                                            (append old keywords) 
    723723                                          (append keywords old))))) 
    724724           ;; If the keywords were compiled before, compile them again. 
    725725           (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
    730730  "Update `font-lock-removed-keywords-alist' when adding new KEYWORDS to MODE." 
    731731  ;; When font-lock is enabled first all keywords in the list 
     
    737737  (let ((cell (assq mode font-lock-removed-keywords-alist))) 
    738738    (if cell 
    739         (if (eq append 'set) 
     739        (if (eq how 'set) 
    740740            ;; A new set of keywords is defined.  Forget all about 
    741741            ;; our old keywords that should be removed. 
     
    787787             ;; `font-lock-keywords-alist'. 
    788788             (when top-cell 
    789                (dolist (keyword-list-append-pair (cdr top-cell)) 
    790                  ;; `keywords-list-append-pair' is a cons with a list of 
    791                  ;; keywords in the car top-cell and the original append 
     789               (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 
    792792                 ;; argument in the cdr top-cell. 
    793                  (setcar keyword-list-append-pair 
    794                          (delete keyword (car keyword-list-append-pair)))) 
    795                ;; Remove keyword list/append pair when the keyword list 
    796                ;; is empty and append doesn't specify `set'.  (If it 
     793                 (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 
    797797               ;; should be deleted then previously deleted keywords 
    798798               ;; would appear again.) 
     
    831831           ;; If the keywords were compiled before, compile them again. 
    832832           (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))))))) 
    835835  
    836836;;; Font Lock Support mode. 
     
    981981  "Fontify the current buffer the way the function `font-lock-mode' would." 
    982982  (interactive) 
     983  (font-lock-set-defaults) 
    983984  (let ((font-lock-verbose (or font-lock-verbose (interactive-p)))) 
    984985    (funcall font-lock-fontify-buffer-function))) 
     
    988989 
    989990(defun font-lock-fontify-region (beg end &optional loudly) 
     991  (font-lock-set-defaults) 
    990992  (funcall font-lock-fontify-region-function beg end loudly)) 
    991993 
     
    10011003        (when verbose 
    10021004          (format "Fontifying %s..." (buffer-name))) 
    1003       ;; Make sure we have the right `font-lock-keywords' etc. 
    1004       (unless font-lock-mode 
    1005         (font-lock-set-defaults)) 
    10061005      ;; Make sure we fontify etc. in the whole buffer. 
    10071006      (save-restriction 
     
    11241123          ((error quit) (message "Fontifying block...%s" error-data))))))) 
    11251124 
    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) 
    11281128 
    11291129;;; End of Fontification functions. 
     
    15081508If REGEXP is non-nil, it means these keywords are used for 
    15091509`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")) 
    15101517  (if (eq (car-safe keywords) t) 
    15111518      keywords 
     
    15741581         keywords) 
    15751582        ((numberp level) 
    1576          (or (nth level keywords) (car (reverse keywords)))) 
     1583         (or (nth level keywords) (car (last keywords)))) 
    15771584        ((eq level t) 
    1578          (car (reverse keywords))) 
     1585         (car (last keywords))) 
    15791586        (t 
    15801587         (car keywords)))) 
     
    16421649      ;; Now compile the keywords. 
    16431650      (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)))))) 
    16461653  
    16471654;;; Colour etc. support. 
     
    19571964            (goto-char (match-end 2))) 
    19581965        (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'. 
     1993Used 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  
     2034font lock keyords for C preprocessor directives. This definition is for the 
     2035other modes in which C preprocessor directives are used. e.g. `asm-mode' and 
     2036`ld-script-mode'.") 
     2037 
    19592038  
    19602039;; Lisp. 
     
    19652044      (,(concat "(\\(def\\(" 
    19662045                ;; Function declarations. 
    1967                 "\\(advice\\|varalias\\|alias\\|generic\\|macro\\*?\\|method\\|" 
     2046                "\\(advice\\|alias\\|generic\\|macro\\*?\\|method\\|" 
    19682047                "setf\\|subst\\*?\\|un\\*?\\|" 
    1969                 "ine-\\(condition\\|\\(?:derived\\|minor\\|generic\\)-mode\\|" 
     2048                "ine-\\(condition\\|" 
     2049                "\\(?:derived\\|\\(?:global-\\)?minor\\|generic\\)-mode\\|" 
    19702050                "method-combination\\|setf-expander\\|skeleton\\|widget\\|" 
    19712051                "function\\|\\(compiler\\|modify\\|symbol\\)-macro\\)\\)\\|" 
    19722052                ;; Variable declarations. 
    1973                 "\\(const\\(ant\\)?\\|custom\\|face\\|parameter\\|var\\)\\|" 
     2053                "\\(const\\(ant\\)?\\|custom\\|varalias\\|face\\|parameter\\|var\\)\\|" 
    19742054                ;; Structure declarations. 
    19752055                "\\(class\\|group\\|theme\\|package\\|struct\\|type\\)" 
     
    20472127       ("\\<:\\sw+\\>" 0 font-lock-builtin-face) 
    20482128       ;; ELisp and CLisp `&' keywords as types. 
    2049        ("\\&\\sw+\\>" . font-lock-type-face) 
     2129       ("\\<\\&\\sw+\\>" . font-lock-type-face) 
    20502130       ;; ELisp regexp grouping constructs 
    20512131       ((lambda (bound)