/[emacs]/emacs/lisp/font-lock.el
ViewVC logotype

Diff of /emacs/lisp/font-lock.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.211.2.3 by miles, Mon Jun 28 07:28:40 2004 UTC revision 1.211.2.4 by miles, Tue Jun 29 16:45:01 2004 UTC
# Line 340  If a number, only buffers greater than t Line 340  If a number, only buffers greater than t
340    
341  (defvar font-lock-keywords nil  (defvar font-lock-keywords nil
342    "A list of the keywords to highlight.    "A list of the keywords to highlight.
343  Each element should have one of these forms:  There are two kinds of values: user-level, and compiled.
344    
345    A user-level keywords list is what a major mode or the user would
346    set up.  Normally the list would come from `font-lock-defaults'.
347    through selection of a fontification level and evaluation of any
348    contained expressions.  You can also alter it by calling
349    `font-lock-add-keywords' or `font-lock-remove-keywords' with MODE = nil.
350    
351    Each element in a user-level keywords list should have one of these forms:
352    
353   MATCHER   MATCHER
354   (MATCHER . MATCH)   (MATCHER . MATCH)
# Line 438  support modes like jit-lock or lazy-lock Line 446  support modes like jit-lock or lazy-lock
446    
447  This variable is set by major modes via the variable `font-lock-defaults'.  This variable is set by major modes via the variable `font-lock-defaults'.
448  Be careful when composing regexps for this list; a poorly written pattern can  Be careful when composing regexps for this list; a poorly written pattern can
449  dramatically slow things down!")  dramatically slow things down!
450    
451    A compiled keywords list starts with t.  It is produced internal
452    by `font-lock-compile-keywords' from a user-level keywords list.
453    Its second element is the user-level keywords list that was
454    compiled.  The remaining elements have the same form as
455    user-level keywords, but normally their values have been
456    optimized.")
457    
458  (defvar font-lock-keywords-alist nil  (defvar font-lock-keywords-alist nil
459    "*Alist of `font-lock-keywords' local to a `major-mode'.    "*Alist of `font-lock-keywords' local to a `major-mode'.
# Line 659  see the variables `c-font-lock-extra-typ Line 674  see the variables `c-font-lock-extra-typ
674           (font-lock-update-removed-keyword-alist mode keywords append))           (font-lock-update-removed-keyword-alist mode keywords append))
675          (t          (t
676           ;; Otherwise set or add the keywords now.           ;; Otherwise set or add the keywords now.
677             ;; This is a no-op if it has been done already in this buffer.
678           (font-lock-set-defaults)           (font-lock-set-defaults)
679           (if (eq append 'set)           (let ((was-compiled (eq (car font-lock-keywords) t)))
680               (setq font-lock-keywords keywords)             ;; Bring back the user-level (uncompiled) keywords.
681             (font-lock-remove-keywords nil keywords) ;to avoid duplicates             (if was-compiled
682             (let ((old (if (eq (car-safe font-lock-keywords) t)                 (setq font-lock-keywords (cadr font-lock-keywords)))
683                            (cdr font-lock-keywords)             ;; Now modify or replace them.
684                          font-lock-keywords)))             (if (eq append 'set)
685               (setq font-lock-keywords (if append                 (setq font-lock-keywords keywords)
686                                            (append old keywords)               (font-lock-remove-keywords nil keywords) ;to avoid duplicates
687                                          (append keywords old))))))))               (let ((old (if (eq (car-safe font-lock-keywords) t)
688                                (cdr font-lock-keywords)
689                              font-lock-keywords)))
690                   (setq font-lock-keywords (if append
691                                                (append old keywords)
692                                              (append keywords old)))))
693               ;; If the keywords were compiled before, compile them again.
694               (if was-compiled
695                   (set (make-local-variable 'font-lock-keywords)
696                        (font-lock-compile-keywords keywords t)))))))
697    
698  (defun font-lock-update-removed-keyword-alist (mode keywords append)  (defun font-lock-update-removed-keyword-alist (mode keywords append)
699    ;; Update `font-lock-removed-keywords-alist' when adding new    ;; Update `font-lock-removed-keywords-alist' when adding new
# Line 762  subtle problems due to details of the im Line 787  subtle problems due to details of the im
787          (t          (t
788           ;; Otherwise remove it immediately.           ;; Otherwise remove it immediately.
789           (font-lock-set-defaults)           (font-lock-set-defaults)
790           (setq font-lock-keywords (copy-sequence font-lock-keywords))           (let ((was-compiled (eq (car font-lock-keywords) t)))
791           (dolist (keyword keywords)             ;; Bring back the user-level (uncompiled) keywords.
792             (setq font-lock-keywords             (if was-compiled
793                   (delete keyword                 (setq font-lock-keywords (cadr font-lock-keywords)))
794                           ;; The keywords might be compiled.  
795                           (delete (font-lock-compile-keyword keyword)             ;; Edit them.
796                                   font-lock-keywords)))))))             (setq font-lock-keywords (copy-sequence font-lock-keywords))
797               (dolist (keyword keywords)
798                 (setq font-lock-keywords
799                       (delete keyword font-lock-keywords)))
800    
801               ;; If the keywords were compiled before, compile them again.
802               (if was-compiled
803                   (set (make-local-variable 'font-lock-keywords)
804                        (font-lock-compile-keywords keywords t)))))))
805    
806  ;;; Font Lock Support mode.  ;;; Font Lock Support mode.
807    
# Line 1224  START should be at the beginning of a li Line 1257  START should be at the beginning of a li
1257                                          font-lock-syntactic-keywords)))                                          font-lock-syntactic-keywords)))
1258    ;; Get down to business.    ;; Get down to business.
1259    (let ((case-fold-search font-lock-keywords-case-fold-search)    (let ((case-fold-search font-lock-keywords-case-fold-search)
1260          (keywords (cdr font-lock-syntactic-keywords))          (keywords (cddr font-lock-syntactic-keywords))
1261          keyword matcher highlights)          keyword matcher highlights)
1262      (while keywords      (while keywords
1263        ;; Find an occurrence of `matcher' from `start' to `end'.        ;; Find an occurrence of `matcher' from `start' to `end'.
# Line 1349  LOUDLY, if non-nil, allows progress-mete Line 1382  LOUDLY, if non-nil, allows progress-mete
1382      (setq font-lock-keywords      (setq font-lock-keywords
1383            (font-lock-compile-keywords font-lock-keywords t)))            (font-lock-compile-keywords font-lock-keywords t)))
1384    (let ((case-fold-search font-lock-keywords-case-fold-search)    (let ((case-fold-search font-lock-keywords-case-fold-search)
1385          (keywords (cdr font-lock-keywords))          (keywords (cddr font-lock-keywords))
1386          (bufname (buffer-name)) (count 0)          (bufname (buffer-name)) (count 0)
1387          keyword matcher highlights)          keyword matcher highlights)
1388      ;;      ;;
# Line 1394  LOUDLY, if non-nil, allows progress-mete Line 1427  LOUDLY, if non-nil, allows progress-mete
1427  ;; Various functions.  ;; Various functions.
1428    
1429  (defun font-lock-compile-keywords (keywords &optional regexp)  (defun font-lock-compile-keywords (keywords &optional regexp)
1430    "Compile KEYWORDS into the form (t KEYWORD ...).    "Compile KEYWORDS into the form (t KEYWORDS COMPILED...)
1431  Here KEYWORD is of the form (MATCHER HIGHLIGHT ...) as shown in the  Here each COMPILED is of the form (MATCHER HIGHLIGHT ...) as shown in the
1432  `font-lock-keywords' doc string.  `font-lock-keywords' doc string.
1433  If REGEXP is non-nil, it means these keywords are used for  If REGEXP is non-nil, it means these keywords are used for
1434  `font-lock-keywords' rather than for `font-lock-syntactic-keywords'."  `font-lock-keywords' rather than for `font-lock-syntactic-keywords'."
1435    (if (eq (car-safe keywords) t)    (if (eq (car-safe keywords) t)
1436        keywords        keywords
1437      (setq keywords (cons t (mapcar 'font-lock-compile-keyword keywords)))      (setq keywords
1438              (cons t (cons keywords
1439                            (mapcar 'font-lock-compile-keyword keywords))))
1440      (if (and regexp      (if (and regexp
1441               (eq (or syntax-begin-function               (eq (or syntax-begin-function
1442                       font-lock-beginning-of-syntax-function)                       font-lock-beginning-of-syntax-function)
# Line 1512  Sets various variables using `font-lock- Line 1547  Sets various variables using `font-lock-
1547        ;; Variable alist?        ;; Variable alist?
1548        (dolist (x (nthcdr 5 defaults))        (dolist (x (nthcdr 5 defaults))
1549          (set (make-local-variable (car x)) (cdr x)))          (set (make-local-variable (car x)) (cdr x)))
1550        ;; Setup `font-lock-keywords' last because its value might depend        ;; Set up `font-lock-keywords' last because its value might depend
1551        ;; on other settings (e.g. font-lock-compile-keywords uses        ;; on other settings (e.g. font-lock-compile-keywords uses
1552        ;; font-lock-beginning-of-syntax-function).        ;; font-lock-beginning-of-syntax-function).
1553        (set (make-local-variable 'font-lock-keywords)        (set (make-local-variable 'font-lock-keywords)
1554             (font-lock-compile-keywords (font-lock-eval-keywords keywords) t))             (font-lock-eval-keywords keywords))
1555        ;; Local fontification?        ;; Local fontification?
1556        (while local        (while local
1557          (font-lock-add-keywords nil (car (car local)) (cdr (car local)))          (font-lock-add-keywords nil (car (car local)) (cdr (car local)))
1558          (setq local (cdr local)))          (setq local (cdr local)))
1559        (when removed-keywords        (when removed-keywords
1560          (font-lock-remove-keywords nil removed-keywords)))))          (font-lock-remove-keywords nil removed-keywords))
1561          ;; Now compile the keywords.
1562          (unless (eq (car font-lock-keywords) t)
1563            (set (make-local-variable 'font-lock-keywords)
1564                 (font-lock-compile-keywords font-lock-keywords t))))))
1565    
1566  ;;; Colour etc. support.  ;;; Colour etc. support.
1567    

Legend:
Removed from v.1.211.2.3  
changed lines
  Added in v.1.211.2.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26