aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/font-lock.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/font-lock.el')
-rw-r--r--lisp/font-lock.el62
1 files changed, 45 insertions, 17 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 10b4d67aabe..06afd1017e7 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 nil
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)
@@ -889,7 +905,7 @@ The value of this variable is used when Font Lock mode is turned on."
889 'font-lock-after-change-function t) 905 'font-lock-after-change-function t)
890 (set (make-local-variable 'font-lock-fontify-buffer-function) 906 (set (make-local-variable 'font-lock-fontify-buffer-function)
891 'jit-lock-refontify) 907 'jit-lock-refontify)
892 ;; Don't fontify eagerly (and don't abort is the buffer is large). 908 ;; Don't fontify eagerly (and don't abort if the buffer is large).
893 (set (make-local-variable 'font-lock-fontified) t) 909 (set (make-local-variable 'font-lock-fontified) t)
894 ;; Use jit-lock. 910 ;; Use jit-lock.
895 (jit-lock-register 'font-lock-fontify-region 911 (jit-lock-register 'font-lock-fontify-region
@@ -1571,12 +1587,15 @@ 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))
1598 (setq font-lock-mode-major-mode major-mode)
1580 (set (make-local-variable 'font-lock-set-defaults) t) 1599 (set (make-local-variable 'font-lock-set-defaults) t)
1581 (make-local-variable 'font-lock-fontified) 1600 (make-local-variable 'font-lock-fontified)
1582 (make-local-variable 'font-lock-multiline) 1601 (make-local-variable 'font-lock-multiline)
@@ -1807,6 +1826,17 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
1807 "Font Lock mode face used to highlight preprocessor directives." 1826 "Font Lock mode face used to highlight preprocessor directives."
1808 :group 'font-lock-highlighting-faces) 1827 :group 'font-lock-highlighting-faces)
1809 1828
1829(defface font-lock-regexp-backslash
1830 '((((class color) (min-colors 16)) :inherit escape-glyph)
1831 (t :inherit bold))
1832 "Font Lock mode face used to highlight a backslash in Lisp regexps."
1833 :group 'font-lock-highlighting-faces)
1834
1835(defface font-lock-regexp-backslash-construct
1836 '((t :inherit bold))
1837 "Font Lock mode face used to highlight `\' constructs in Lisp regexps."
1838 :group 'font-lock-highlighting-faces)
1839
1810;;; End of Colour etc. support. 1840;;; End of Colour etc. support.
1811 1841
1812;;; Menu support. 1842;;; Menu support.
@@ -2000,7 +2030,7 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
2000 `(;; Control structures. Emacs Lisp forms. 2030 `(;; Control structures. Emacs Lisp forms.
2001 (,(concat 2031 (,(concat
2002 "(" (regexp-opt 2032 "(" (regexp-opt
2003 '("cond" "if" "while" "let" "let*" 2033 '("cond" "if" "while" "while-no-input" "let" "let*"
2004 "prog" "progn" "progv" "prog1" "prog2" "prog*" 2034 "prog" "progn" "progv" "prog1" "prog2" "prog*"
2005 "inline" "lambda" "save-restriction" "save-excursion" 2035 "inline" "lambda" "save-restriction" "save-excursion"
2006 "save-window-excursion" "save-selected-window" 2036 "save-window-excursion" "save-selected-window"
@@ -2056,16 +2086,14 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
2056 ;; Make regexp grouping constructs bold, so they stand out, but only 2086 ;; Make regexp grouping constructs bold, so they stand out, but only
2057 ;; in strings. 2087 ;; in strings.
2058 ((lambda (bound) 2088 ((lambda (bound)
2059 (if (re-search-forward "\\(\\\\\\\\\\)\\([(|)]\\)\\(\\?:\\)?" bound t) 2089 (if (re-search-forward "\\(\\\\\\\\\\)\\((\\(?:?:\\)?\\|[|)]\\)" bound t)
2060 (let ((face (get-text-property (1- (point)) 'face))) 2090 (let ((face (get-text-property (1- (point)) 'face)))
2061 (if (listp face) 2091 (if (listp face)
2062 (memq 'font-lock-string-face face) 2092 (memq 'font-lock-string-face face)
2063 (eq 'font-lock-string-face face))))) 2093 (eq 'font-lock-string-face face)))))
2064 ;; Should we introduce a lowlight face for this? 2094 (1 'font-lock-regexp-backslash prepend)
2065 ;; Ideally that would retain the color, dimmed. 2095 (2 'font-lock-regexp-backslash-construct prepend))
2066 (1 font-lock-comment-face prepend) 2096
2067 (2 'bold prepend)
2068 (3 font-lock-type-face prepend t))
2069 ;; Underline innermost grouping, so that you can more easily see what 2097 ;; Underline innermost grouping, so that you can more easily see what
2070 ;; belongs together. 2005-05-12: Font-lock can go into an 2098 ;; belongs together. 2005-05-12: Font-lock can go into an
2071 ;; unbreakable endless loop on this -- something's broken. 2099 ;; unbreakable endless loop on this -- something's broken.