diff options
| author | Luc Teirlinck | 2005-06-04 22:23:44 +0000 |
|---|---|---|
| committer | Luc Teirlinck | 2005-06-04 22:23:44 +0000 |
| commit | bed88438516314839b49b2dc2bf2c46522a59a24 (patch) | |
| tree | 6ce883530303d0442d8309c509738595a2d6a5a1 | |
| parent | 642b63e8b7b4af042904c1ade61e1e0ea647a8ee (diff) | |
| download | emacs-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.el | 36 |
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: | |||
| 683 | adds two fontification patterns for C mode, to fontify `FIXME:' words, even in | 683 | adds two fontification patterns for C mode, to fontify `FIXME:' words, even in |
| 684 | comments, and to fontify `and', `or' and `not' words as keywords. | 684 | comments, and to fontify `and', `or' and `not' words as keywords. |
| 685 | 685 | ||
| 686 | When used from a Lisp program (such as a minor mode), it is recommended to | 686 | The above procedure will only add the keywords for C mode, not |
| 687 | use nil for MODE (and place the call on a hook) to avoid subtle problems | 687 | for modes derived from C mode. To add them for derived modes too, |
| 688 | due to details of the implementation. | 688 | pass nil for MODE and add the call to c-mode-hook. |
| 689 | |||
| 690 | For 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 | |||
| 699 | The above procedure may fail to add keywords to derived modes if | ||
| 700 | some involved major mode does not follow the standard conventions. | ||
| 701 | File a bug report if this happens, so the major mode can be corrected. | ||
| 689 | 702 | ||
| 690 | Note that some modes have specialized support for additional patterns, e.g., | 703 | Note that some modes have specialized support for additional patterns, e.g., |
| 691 | see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types', | 704 | see 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', | |||
| 774 | MODE should be a symbol, the major mode command name, such as `c-mode' | 788 | MODE should be a symbol, the major mode command name, such as `c-mode' |
| 775 | or nil. If nil, highlighting keywords are removed for the current buffer. | 789 | or nil. If nil, highlighting keywords are removed for the current buffer. |
| 776 | 790 | ||
| 777 | When used from a Lisp program (such as a minor mode), it is recommended to | 791 | To make the removal apply to modes derived from MODE as well, |
| 778 | use nil for MODE (and place the call on a hook) to avoid subtle problems | 792 | pass nil for MODE and add the call to MODE-hook. This may fail |
| 779 | due to details of the implementation." | 793 | for some derived modes if some involved major mode does not |
| 794 | follow the standard conventions. File a bug report if this | ||
| 795 | happens, 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. |
| 1576 | Sets various variables using `font-lock-defaults' (or, if nil, using | 1593 | Sets 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) |