aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Teirlinck2005-06-04 22:23:44 +0000
committerLuc Teirlinck2005-06-04 22:23:44 +0000
commitbed88438516314839b49b2dc2bf2c46522a59a24 (patch)
tree6ce883530303d0442d8309c509738595a2d6a5a1
parent642b63e8b7b4af042904c1ade61e1e0ea647a8ee (diff)
downloademacs-bed88438516314839b49b2dc2bf2c46522a59a24.tar.gz
emacs-bed88438516314839b49b2dc2bf2c46522a59a24.zip
(font-lock-add-keywords): Doc fix. Comment change.
(font-lock-remove-keywords): Doc fix. (font-lock-mode-major-mode): Compiler defvar. (font-lock-set-defaults): Use `font-lock-mode-major-mode '.
-rw-r--r--lisp/font-lock.el36
1 files changed, 27 insertions, 9 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index d2507474f12..691f617cfb0 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -683,9 +683,22 @@ For example:
683adds two fontification patterns for C mode, to fontify `FIXME:' words, even in 683adds two fontification patterns for C mode, to fontify `FIXME:' words, even in
684comments, and to fontify `and', `or' and `not' words as keywords. 684comments, and to fontify `and', `or' and `not' words as keywords.
685 685
686When used from a Lisp program (such as a minor mode), it is recommended to 686The above procedure will only add the keywords for C mode, not
687use nil for MODE (and place the call on a hook) to avoid subtle problems 687for modes derived from C mode. To add them for derived modes too,
688due to details of the implementation. 688pass nil for MODE and add the call to c-mode-hook.
689
690For example:
691
692 (add-hook 'c-mode-hook
693 (lambda ()
694 (font-lock-add-keywords 'c-mode
695 '((\"\\\\\\=<\\\\(FIXME\\\\):\" 1 font-lock-warning-face prepend)
696 (\"\\\\\\=<\\\\(and\\\\|or\\\\|not\\\\)\\\\\\=>\" .
697 font-lock-keyword-face)))))
698
699The above procedure may fail to add keywords to derived modes if
700some involved major mode does not follow the standard conventions.
701File a bug report if this happens, so the major mode can be corrected.
689 702
690Note that some modes have specialized support for additional patterns, e.g., 703Note that some modes have specialized support for additional patterns, e.g.,
691see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types', 704see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
@@ -704,7 +717,8 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
704 (font-lock-update-removed-keyword-alist mode keywords append)) 717 (font-lock-update-removed-keyword-alist mode keywords append))
705 (t 718 (t
706 ;; Otherwise set or add the keywords now. 719 ;; Otherwise set or add the keywords now.
707 ;; This is a no-op if it has been done already in this buffer. 720 ;; This is a no-op if it has been done already in this buffer
721 ;; for the correct major mode.
708 (font-lock-set-defaults) 722 (font-lock-set-defaults)
709 (let ((was-compiled (eq (car font-lock-keywords) t))) 723 (let ((was-compiled (eq (car font-lock-keywords) t)))
710 ;; Bring back the user-level (uncompiled) keywords. 724 ;; Bring back the user-level (uncompiled) keywords.
@@ -774,9 +788,11 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
774MODE should be a symbol, the major mode command name, such as `c-mode' 788MODE should be a symbol, the major mode command name, such as `c-mode'
775or nil. If nil, highlighting keywords are removed for the current buffer. 789or nil. If nil, highlighting keywords are removed for the current buffer.
776 790
777When used from a Lisp program (such as a minor mode), it is recommended to 791To make the removal apply to modes derived from MODE as well,
778use nil for MODE (and place the call on a hook) to avoid subtle problems 792pass nil for MODE and add the call to MODE-hook. This may fail
779due to details of the implementation." 793for some derived modes if some involved major mode does not
794follow the standard conventions. File a bug report if this
795happens, so the major mode can be corrected."
780 (cond (mode 796 (cond (mode
781 ;; Remove one keyword at the time. 797 ;; Remove one keyword at the time.
782 (dolist (keyword keywords) 798 (dolist (keyword keywords)
@@ -1571,12 +1587,14 @@ A LEVEL of nil is equal to a LEVEL of 0, a LEVEL of t is equal to
1571 1587
1572(defvar font-lock-set-defaults nil) ; Whether we have set up defaults. 1588(defvar font-lock-set-defaults nil) ; Whether we have set up defaults.
1573 1589
1590(defvar font-lock-mode-major-mode)
1574(defun font-lock-set-defaults () 1591(defun font-lock-set-defaults ()
1575 "Set fontification defaults appropriately for this mode. 1592 "Set fontification defaults appropriately for this mode.
1576Sets various variables using `font-lock-defaults' (or, if nil, using 1593Sets various variables using `font-lock-defaults' (or, if nil, using
1577`font-lock-defaults-alist') and `font-lock-maximum-decoration'." 1594`font-lock-defaults-alist') and `font-lock-maximum-decoration'."
1578 ;; Set fontification defaults iff not previously set. 1595 ;; Set fontification defaults iff not previously set for correct major mode.
1579 (unless font-lock-set-defaults 1596 (unless (and font-lock-set-defaults
1597 (eq font-lock-mode-major-mode major-mode))
1580 (set (make-local-variable 'font-lock-set-defaults) t) 1598 (set (make-local-variable 'font-lock-set-defaults) t)
1581 (make-local-variable 'font-lock-fontified) 1599 (make-local-variable 'font-lock-fontified)
1582 (make-local-variable 'font-lock-multiline) 1600 (make-local-variable 'font-lock-multiline)