• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10.1/emacs-93/emacs/lisp/

Lines Matching +defs:font +defs:lock +defs:keywords

0 ;;; font-lock.el --- Electric font lock mode
32 ;; Comments will be displayed in `font-lock-comment-face'.
33 ;; Strings will be displayed in `font-lock-string-face'.
36 ;; To make the text you type be fontified, use M-x font-lock-mode RET.
42 ;; (add-hook 'emacs-lisp-mode-hook 'turn-on-font-lock)
46 ;; (global-font-lock-mode t)
50 ;; it takes to fontify. See the variable `font-lock-maximum-decoration', and
51 ;; also the variable `font-lock-maximum-size'. Support modes for Font Lock
52 ;; mode can be used to speed up Font Lock mode. See `font-lock-support-mode'.
65 ;; regexp (i.e., keywords and everything else) passes. There are actually
70 ;; buffer according to the variable `font-lock-syntactic-keywords'. It is
89 ;; the variable `font-lock-keywords'. It involves searching for given regexps
97 ;; some syntactic parsers for common languages and a son-of-font-lock.el could
104 ;; variable names from (a) the buffer local variable `font-lock-defaults', if
105 ;; non-nil, or (b) the global variable `font-lock-defaults-alist', if the major
108 ;; mode's patterns are distributed with font-lock.el itself. An example of (a)
112 ;; fontification based on `font-lock-maximum-decoration'.
119 ;; See the documentation for the variable `font-lock-keywords'.
121 ;; Efficient regexps for use as MATCHERs for `font-lock-keywords' and
122 ;; `font-lock-syntactic-keywords' can be generated via the function
130 ;; `font-lock-add-keywords'. For example, say in some C
134 ;; (font-lock-add-keywords 'c-mode '("\\<\\(and\\|or\\|not\\)\\>"))
138 ;; variable `c-font-lock-extra-types'.
145 ;; Font Lock mode, via the mode hook setting `font-lock-defaults', exactly what
150 ;; (defvar foo-font-lock-keywords
151 ;; '(("\\<\\(one\\|two\\|three\\)\\>" . font-lock-keyword-face)
152 ;; ("\\<\\(four\\|five\\|six\\)\\>" . font-lock-type-face))
157 ;; (set (make-local-variable 'font-lock-defaults)
158 ;; '(foo-font-lock-keywords t))))
166 ;; via `font-lock-defaults', exactly what support is required. For example,
171 ;; (defvar bar-font-lock-keywords
172 ;; '(("\\<\\(uno\\|due\\|tre\\)\\>" . font-lock-keyword-face)
173 ;; ("\\<\\(quattro\\|cinque\\|sei\\)\\>" . font-lock-type-face))
178 ;; (set (make-local-variable 'font-lock-defaults)
179 ;; '(bar-font-lock-keywords nil t))
199 ;; keywords, should be highlighted with the same face, etc.
207 ;; Don't use it to, say, highlight keywords in commented out code or strings.
215 ;; Define core `font-lock' group.
216 (defgroup font-lock '((jit-lock custom-group))
222 (defgroup font-lock-faces nil
224 :prefix "font-lock-"
225 :group 'font-lock)
227 (defgroup font-lock-extra-types nil
229 :group 'font-lock)
234 (defcustom font-lock-maximum-size 256000
254 :group 'font-lock)
256 (defcustom font-lock-maximum-decoration t
279 :group 'font-lock)
281 (defcustom font-lock-verbose 0
287 :group 'font-lock)
294 ;; We now allow a FACENAME in `font-lock-keywords' to be any expression that
297 (defvar font-lock-comment-face 'font-lock-comment-face
300 (defvar font-lock-comment-delimiter-face 'font-lock-comment-delimiter-face
303 (defvar font-lock-string-face 'font-lock-string-face
306 (defvar font-lock-doc-face 'font-lock-doc-face
309 (defvar font-lock-keyword-face 'font-lock-keyword-face
310 "Face name to use for keywords.")
312 (defvar font-lock-builtin-face 'font-lock-builtin-face
315 (defvar font-lock-function-name-face 'font-lock-function-name-face
318 (defvar font-lock-variable-name-face 'font-lock-variable-name-face
321 (defvar font-lock-type-face 'font-lock-type-face
324 (defvar font-lock-constant-face 'font-lock-constant-face
327 (defvar font-lock-warning-face 'font-lock-warning-face
330 (defvar font-lock-negation-char-face 'font-lock-negation-char-face
334 (defvar font-lock-preprocessor-face 'font-lock-preprocessor-face
337 (defvar font-lock-reference-face 'font-lock-constant-face)
338 (make-obsolete-variable 'font-lock-reference-face 'font-lock-constant-face)
342 (defvar font-lock-keywords nil
343 "A list of the keywords to highlight.
346 A user-level keywords list is what a major mode or the user would
347 set up. Normally the list would come from `font-lock-defaults'.
350 `font-lock-add-keywords' or `font-lock-remove-keywords' with MODE = nil.
352 Each element in a user-level keywords list should have one of these forms:
390 properties in `font-lock-extra-managed-props' or to override
391 `font-lock-unfontify-region-function'.
403 variable `font-lock-keyword-face'.
405 the value of `font-lock-keyword-face'.
449 support modes like jit-lock or lazy-lock.
451 This variable is set by major modes via the variable `font-lock-defaults'.
455 A compiled keywords list starts with t. It is produced internal
456 by `font-lock-compile-keywords' from a user-level keywords list.
457 Its second element is the user-level keywords list that was
459 user-level keywords, but normally their values have been
462 (defvar font-lock-keywords-alist nil
463 "Alist of additional `font-lock-keywords' elements for major modes.
466 `font-lock-set-defaults' adds the elements in the list KEYWORDS to
467 `font-lock-keywords' when Font Lock is turned on in major mode MODE.
470 `font-lock-keywords'. If it is `set', they are used to replace the
471 value of `font-lock-keywords'. If HOW is any other non-nil value,
474 This is normally set via `font-lock-add-keywords' and
475 `font-lock-remove-keywords'.")
476 (put 'font-lock-keywords-alist 'risky-local-variable t)
478 (defvar font-lock-removed-keywords-alist nil
479 "Alist of `font-lock-keywords' elements to be removed for major modes.
481 Each element has the form (MODE . KEYWORDS). `font-lock-set-defaults'
482 removes the elements in the list KEYWORDS from `font-lock-keywords'
485 This is normally set via `font-lock-add-keywords' and
486 `font-lock-remove-keywords'.")
488 (defvar font-lock-keywords-only nil
490 This is normally set via `font-lock-defaults'.")
492 (defvar font-lock-keywords-case-fold-search nil
493 "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.
494 This is normally set via `font-lock-defaults'.")
495 (make-variable-buffer-local 'font-lock-keywords-case-fold-search)
497 (defvar font-lock-syntactically-fontified 0
498 "Point up to which `font-lock-syntactic-keywords' has been applied.
501 (make-variable-buffer-local 'font-lock-syntactically-fontified)
503 (defvar font-lock-syntactic-face-function
505 (if (nth 3 state) font-lock-string-face font-lock-comment-face))
509 should return a face. This is normally set via `font-lock-defaults'.")
511 (defvar font-lock-syntactic-keywords nil
512 "A list of the syntactic keywords to put syntax properties on.
516 See `font-lock-keywords' for a description of the form of this list;
525 Here are two examples of elements of `font-lock-syntactic-keywords'
542 This is normally set via `font-lock-defaults'.")
544 (defvar font-lock-syntax-table nil
547 This is normally set via `font-lock-defaults'.")
549 (defvar font-lock-beginning-of-syntax-function nil
560 This is normally set via `font-lock-defaults'.")
562 (defvar font-lock-mark-block-function nil
566 This is normally set via `font-lock-defaults'.")
568 (defvar font-lock-fontify-buffer-function 'font-lock-default-fontify-buffer
570 This is normally set via `font-lock-defaults'.")
572 (defvar font-lock-unfontify-buffer-function 'font-lock-default-unfontify-buffer
575 This is normally set via `font-lock-defaults'.")
577 (defvar font-lock-fontify-region-function 'font-lock-default-fontify-region
581 messages. This is normally set via `font-lock-defaults'.")
583 (defvar font-lock-unfontify-region-function 'font-lock-default-unfontify-region
586 This is normally set via `font-lock-defaults'.")
588 (defvar font-lock-inhibit-thing-lock nil
590 Currently, valid mode names are `fast-lock-mode', `jit-lock-mode' and
591 `lazy-lock-mode'. This is normally set via `font-lock-defaults'.")
593 (defvar font-lock-multiline nil
594 "Whether font-lock should cater to multiline keywords.
600 (defvar font-lock-fontified nil) ; Whether we have fontified the buffer.
610 ;; Borrowed from lazy-lock.el.
631 (defvar font-lock-face-attributes)) ; Obsolete but respected if set.
633 (defun font-lock-mode-internal (arg)
636 (add-hook 'after-change-functions 'font-lock-after-change-function t t)
637 (font-lock-set-defaults)
638 (font-lock-turn-on-thing-lock)
640 (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size)))
641 (cond (font-lock-fontified
644 (font-lock-fontify-buffer))
645 (font-lock-verbose
646 (message "Fontifying %s...buffer size greater than font-lock-maximum-size"
649 (unless font-lock-mode
650 (remove-hook 'after-change-functions 'font-lock-after-change-function t)
651 (font-lock-unfontify-buffer)
652 (font-lock-turn-off-thing-lock)))
654 (defun font-lock-add-keywords (mode keywords &optional how)
658 or nil. If nil, highlighting keywords are added for the current buffer.
659 KEYWORDS should be a list; see the variable `font-lock-keywords'.
667 (font-lock-add-keywords 'c-mode
668 '((\"\\\\\\=<\\\\(FIXME\\\\):\" 1 font-lock-warning-face prepend)
669 (\"\\\\\\=<\\\\(and\\\\|or\\\\|not\\\\)\\\\\\=>\" . font-lock-keyword-face)))
672 comments, and to fontify `and', `or' and `not' words as keywords.
674 The above procedure will only add the keywords for C mode, not
682 (font-lock-add-keywords nil
683 '((\"\\\\\\=<\\\\(FIXME\\\\):\" 1 font-lock-warning-face prepend)
685 font-lock-keyword-face)))))
687 The above procedure may fail to add keywords to derived modes if
692 see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
693 `objc-font-lock-extra-types' and `java-font-lock-extra-types'."
696 ;; `font-lock-keywords-alist' so `font-lock-set-defaults' uses them.
697 (let ((spec (cons keywords how)) cell)
698 (if (setq cell (assq mode font-lock-keywords-alist))
702 (push (list mode spec) font-lock-keywords-alist)))
703 ;; Make sure that `font-lock-removed-keywords-alist' does not
704 ;; contain the new keywords.
705 (font-lock-update-removed-keyword-alist mode keywords how))
707 ;; Otherwise set or add the keywords now.
710 (font-lock-set-defaults)
711 (let ((was-compiled (eq (car font-lock-keywords) t)))
712 ;; Bring back the user-level (uncompiled) keywords.
714 (setq font-lock-keywords (cadr font-lock-keywords)))
717 (setq font-lock-keywords keywords)
718 (font-lock-remove-keywords nil keywords) ;to avoid duplicates
719 (let ((old (if (eq (car-safe font-lock-keywords) t)
720 (cdr font-lock-keywords)
721 font-lock-keywords)))
722 (setq font-lock-keywords (if how
723 (append old keywords)
724 (append keywords old)))))
725 ;; If the keywords were compiled before, compile them again.
727 (setq font-lock-keywords
728 (font-lock-compile-keywords font-lock-keywords)))))))
730 (defun font-lock-update-removed-keyword-alist (mode keywords how)
731 "Update `font-lock-removed-keywords-alist' when adding new KEYWORDS to MODE."
732 ;; When font-lock is enabled first all keywords in the list
733 ;; `font-lock-keywords-alist' are added, then all keywords in the
734 ;; list `font-lock-removed-keywords-alist' are removed. If a
736 ;; removed from the removed-keywords list. Otherwise the second add
738 (let ((cell (assq mode font-lock-removed-keywords-alist)))
741 ;; A new set of keywords is defined. Forget all about
742 ;; our old keywords that should be removed.
743 (setq font-lock-removed-keywords-alist
744 (delq cell font-lock-removed-keywords-alist))
745 ;; Delete all previously removed keywords.
746 (dolist (kword keywords)
750 (setq font-lock-removed-keywords-alist
751 (delq cell font-lock-removed-keywords-alist)))))))
756 ;; (I) The keywords are removed from a major mode.
758 ;; `font-lock-add-keywords'), global, or both.
760 ;; (a) In the local case we remove the keywords from the variable
761 ;; `font-lock-keywords-alist'.
763 ;; (b) The actual global keywords are not known at this time.
764 ;; All keywords are added to `font-lock-removed-keywords-alist',
765 ;; when font-lock is enabled those keywords are removed.
767 ;; Note that added keywords are taken out of the list of removed
768 ;; keywords. This ensure correct operation when the same keyword
771 ;; (II) The keywords are removed from the current buffer.
772 (defun font-lock-remove-keywords (mode keywords)
776 or nil. If nil, highlighting keywords are removed for the current buffer.
785 (dolist (keyword keywords)
786 (let ((top-cell (assq mode font-lock-keywords-alist)))
788 ;; `font-lock-keywords-alist'.
791 ;; `keywords-list-how-pair' is a cons with a list of
792 ;; keywords in the car top-cell and the original how
798 ;; should be deleted then previously deleted keywords
809 (setq font-lock-keywords-alist
810 (delq top-cell font-lock-keywords-alist))))
812 (let ((cell (assq mode font-lock-removed-keywords-alist)))
817 font-lock-removed-keywords-alist))))))
820 (font-lock-set-defaults)
821 (let ((was-compiled (eq (car font-lock-keywords) t)))
822 ;; Bring back the user-level (uncompiled) keywords.
824 (setq font-lock-keywords (cadr font-lock-keywords)))
827 (setq font-lock-keywords (copy-sequence font-lock-keywords))
828 (dolist (keyword keywords)
829 (setq font-lock-keywords
830 (delete keyword font-lock-keywords)))
832 ;; If the keywords were compiled before, compile them again.
834 (setq font-lock-keywords
835 (font-lock-compile-keywords font-lock-keywords)))))))
840 ;; This is the code used to interface font-lock.el with any of its add-on
843 ;; `font-lock-after-fontify-buffer' and/or `font-lock-after-unfontify-buffer'
846 (defcustom font-lock-support-mode 'jit-lock-mode
850 `jit-lock-mode'), is recommended.
852 Other, older support modes are Fast Lock mode (symbol `fast-lock-mode') and
853 Lazy Lock mode (symbol `lazy-lock-mode'). See those modes for more info.
860 ((c-mode . fast-lock-mode) (c++-mode . fast-lock-mode) (t . lazy-lock-mode))
866 (const :tag "fast lock" fast-lock-mode)
867 (const :tag "lazy lock" lazy-lock-mode)
868 (const :tag "jit lock" jit-lock-mode)
870 :value ((t . jit-lock-mode))
877 (const :tag "fast lock" fast-lock-mode)
878 (const :tag "lazy lock" lazy-lock-mode)
879 (const :tag "JIT lock" jit-lock-mode)))
882 :group 'font-lock)
884 (defvar fast-lock-mode)
885 (defvar lazy-lock-mode)
886 (defvar jit-lock-mode)
888 (defun font-lock-turn-on-thing-lock ()
889 (let ((thing-mode (font-lock-value-in-major-mode font-lock-support-mode)))
890 (cond ((eq thing-mode 'fast-lock-mode)
891 (fast-lock-mode t))
892 ((eq thing-mode 'lazy-lock-mode)
893 (lazy-lock-mode t))
894 ((eq thing-mode 'jit-lock-mode)
895 ;; Prepare for jit-lock
897 'font-lock-after-change-function t)
898 (set (make-local-variable 'font-lock-fontify-buffer-function)
899 'jit-lock-refontify)
901 (set (make-local-variable 'font-lock-fontified) t)
902 ;; Use jit-lock.
903 (jit-lock-register 'font-lock-fontify-region
904 (not font-lock-keywords-only))
905 ;; Tell jit-lock how we extend the region to refontify.
906 (add-hook 'jit-lock-after-change-extend-region-functions
907 'font-lock-extend-jit-lock-region-after-change
910 (defun font-lock-turn-off-thing-lock ()
911 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
912 (fast-lock-mode -1))
913 ((and (boundp 'jit-lock-mode) jit-lock-mode)
914 (jit-lock-unregister 'font-lock-fontify-region)
915 ;; Reset local vars to the non-jit-lock case.
916 (kill-local-variable 'font-lock-fontify-buffer-function))
917 ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
918 (lazy-lock-mode -1))))
920 (defun font-lock-after-fontify-buffer ()
921 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
922 (fast-lock-after-fontify-buffer))
923 ;; Useless now that jit-lock intercepts font-lock-fontify-buffer. -sm
924 ;; (jit-lock-mode
925 ;; (jit-lock-after-fontify-buffer))
926 ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
927 (lazy-lock-after-fontify-buffer))))
929 (defun font-lock-after-unfontify-buffer ()
930 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
931 (fast-lock-after-unfontify-buffer))
933 ;; - turning off font-lock: it does not matter if we leave spurious
934 ;; `fontified' text props around since jit-lock-mode is also off.
935 ;; - font-lock-default-fontify-buffer fails: this is not run
938 ;; (jit-lock-mode
939 ;; (jit-lock-after-unfontify-buffer))
940 ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
941 (lazy-lock-after-unfontify-buffer))))
948 ;; Rather than the function, e.g., `font-lock-fontify-region' containing the
950 ;; value of the variable, e.g., `font-lock-fontify-region-function'. Normally,
951 ;; the value of this variable is, e.g., `font-lock-default-fontify-region'
953 ;; variable could be anything and thus, e.g., `font-lock-fontify-region' could
955 ;; modes the capability of modifying the way font-lock.el fontifies. Major
956 ;; modes can modify the values of, e.g., `font-lock-fontify-region-function',
957 ;; via the variable `font-lock-defaults'.
959 ;; For example, Rmail mode sets the variable `font-lock-defaults' so that
960 ;; font-lock.el uses its own function for buffer fontification. This function
976 ;; comments are just too hairy for `font-lock-fontify-syntactically-region' to
980 ;; `font-lock-fontify-keywords-region' for the normal regexp fontification
981 ;; pass. And Hairy mode would set `font-lock-defaults' so that font-lock.el
987 (defvar font-lock-extend-after-change-region-function nil
992 It is usually set by the major mode via `font-lock-defaults'.
993 Font-lock calls this function after each buffer change.
1002 (defun font-lock-fontify-buffer ()
1003 "Fontify the current buffer the way the function `font-lock-mode' would."
1005 (font-lock-set-defaults)
1006 (let ((font-lock-verbose (or font-lock-verbose (interactive-p))))
1007 (funcall font-lock-fontify-buffer-function)))
1009 (defun font-lock-unfontify-buffer ()
1010 (funcall font-lock-unfontify-buffer-function))
1012 (defun font-lock-fontify-region (beg end &optional loudly)
1013 (font-lock-set-defaults)
1014 (funcall font-lock-fontify-region-function beg end loudly))
1016 (defun font-lock-unfontify-region (beg end)
1018 (funcall font-lock-unfontify-region-function beg end)))
1020 (defun font-lock-default-fontify-buffer ()
1021 (let ((verbose (if (numberp font-lock-verbose)
1022 (> (buffer-size) font-lock-verbose)
1023 font-lock-verbose)))
1033 (font-lock-fontify-region (point-min) (point-max) verbose)
1034 (font-lock-after-fontify-buffer)
1035 (setq font-lock-fontified t)))
1037 (quit (font-lock-unfontify-buffer)))))))
1039 (defun font-lock-default-unfontify-buffer ()
1043 (font-lock-unfontify-region (point-min) (point-max))
1044 (font-lock-after-unfontify-buffer)
1045 (setq font-lock-fontified nil)))
1047 (defvar font-lock-dont-widen nil
1048 "If non-nil, font-lock will work on the non-widened buffer.
1053 (defvar font-lock-beg) (defvar font-lock-end)
1054 (defvar font-lock-extend-region-functions
1055 '(font-lock-extend-region-wholelines
1056 ;; This use of font-lock-multiline property is unreliable but is just
1060 ;; cases), in which case the font-lock-multiline property can help make
1062 font-lock-extend-region-multiline)
1064 This is used to allow major modes to help font-lock find safe buffer positions
1070 dynamically bound variables `font-lock-beg' and `font-lock-end'; and return
1076 (make-variable-buffer-local 'font-lock-extend-region-functions)
1078 (defun font-lock-extend-region-multiline ()
1079 "Move fontification boundaries away from any `font-lock-multiline' property."
1081 (when (and (> font-lock-beg (point-min))
1082 (get-text-property (1- font-lock-beg) 'font-lock-multiline))
1084 (setq font-lock-beg (or (previous-single-property-change
1085 font-lock-beg 'font-lock-multiline)
1088 (when (get-text-property font-lock-end 'font-lock-multiline)
1090 (setq font-lock-end (or (text-property-any font-lock-end (point-max)
1091 'font-lock-multiline nil)
1095 (defun font-lock-extend-region-wholelines ()
1098 (goto-char font-lock-beg)
1100 (setq changed t font-lock-beg (line-beginning-position)))
1101 (goto-char font-lock-end)
1103 (unless (eq font-lock-end
1104 (setq font-lock-end (line-beginning-position 2)))
1108 (defun font-lock-default-fontify-region (beg end loudly)
1111 (or parse-sexp-lookup-properties font-lock-syntactic-keywords))
1115 (unless font-lock-dont-widen (widen))
1117 (when font-lock-syntax-table
1118 (set-syntax-table font-lock-syntax-table))
1121 (let ((funs font-lock-extend-region-functions)
1122 (font-lock-beg beg)
1123 (font-lock-end end))
1126 (eq funs font-lock-extend-region-functions))
1132 font-lock-extend-region-functions)))
1133 (setq beg font-lock-beg end font-lock-end))
1135 (font-lock-unfontify-region beg end)
1136 (when font-lock-syntactic-keywords
1137 (font-lock-fontify-syntactic-keywords-region beg end))
1138 (unless font-lock-keywords-only
1139 (font-lock-fontify-syntactically-region beg end loudly))
1140 (font-lock-fontify-keywords-region beg end loudly))
1144 ;; The following must be rethought, since keywords can override fontification.
1145 ;; ;; Now scan for keywords, but not if we are inside a comment now.
1146 ;; (or (and (not font-lock-keywords-only)
1148 ;; font-lock-cache-state)))
1150 ;; (font-lock-fontify-keywords-region beg end))
1152 (defvar font-lock-extra-managed-props nil
1153 "Additional text properties managed by font-lock.
1154 This is used by `font-lock-default-unfontify-region' to decide
1157 (defun font-lock-default-unfontify-region (beg end)
1160 font-lock-extra-managed-props
1161 (if font-lock-syntactic-keywords
1162 '(syntax-table face font-lock-multiline)
1163 '(face font-lock-multiline)))))
1166 (defun font-lock-after-change-function (beg end old-len)
1170 (region (if font-lock-extend-after-change-region-function
1171 (funcall font-lock-extend-after-change-region-function
1179 ;; font-lock-default-fontify-region already rounds up to a whole
1189 (font-lock-fontify-region beg end)))))
1191 (defvar jit-lock-start) (defvar jit-lock-end)
1192 (defun font-lock-extend-jit-lock-region-after-change (beg end old-len)
1193 "Function meant for `jit-lock-after-change-extend-region-functions'.
1198 `font-lock-default-fontify-region', in order to avoid the need for
1199 double-redisplay in `jit-lock-fontify-now'."
1201 ;; First extend the region as font-lock-after-change-function would.
1202 (let ((region (if font-lock-extend-after-change-region-function
1203 (funcall font-lock-extend-after-change-region-function
1206 (setq beg (min jit-lock-start (car region))
1207 end (max jit-lock-end (cdr region))))
1208 ;; Then extend the region obeying font-lock-multiline properties,
1210 ;; !!! This is the *main* user of font-lock-multiline property !!!
1211 ;; font-lock-after-change-function could/should also do that, but it
1212 ;; doesn't need to because font-lock-default-fontify-region does
1214 ;; font-lock-default-fontify-region will be executed on this region
1216 ;; Note: contrary to font-lock-default-fontify-region, we do not do
1221 (get-text-property (1- beg) 'font-lock-multiline))
1223 beg 'font-lock-multiline)
1227 (if (get-text-property end 'font-lock-multiline)
1229 'font-lock-multiline nil)
1237 ;; and anticipate what font-lock-default-fontify-region will do, so as to
1239 ;; We could just run `font-lock-extend-region-functions', but since
1242 (when (memq 'font-lock-extend-region-wholelines
1243 font-lock-extend-region-functions)
1245 (setq jit-lock-start (min jit-lock-start (line-beginning-position)))
1247 (setq jit-lock-end
1248 (max jit-lock-end
1251 (defun font-lock-fontify-block (&optional arg)
1252 "Fontify some lines the way `font-lock-fontify-buffer' would.
1255 no ARG is given and `font-lock-mark-block-function' is nil.
1256 If `font-lock-mark-block-function' non-nil and no ARG is given, it is used to
1259 (let ((inhibit-point-motion-hooks t) font-lock-beginning-of-syntax-function
1261 ;; Make sure we have the right `font-lock-keywords' etc.
1262 (if (not font-lock-mode) (font-lock-set-defaults))
1266 (if (or arg (not font-lock-mark-block-function))
1268 (font-lock-fontify-region
1271 (funcall font-lock-mark-block-function)
1272 (font-lock-fontify-region (point) (mark)))
1276 (error "facemenu must be loaded before font-lock"))
1277 (define-key facemenu-keymap "\M-o" 'font-lock-fontify-block)
1286 ;; In the meantime, those that are used by font-lock.el are defined in Lisp
1287 ;; below and given a `font-lock-' prefix. Those that are not used are defined
1290 (defun font-lock-prepend-text-property (start end prop value &optional object)
1304 (defun font-lock-append-text-property (start end prop value &optional object)
1318 (defun font-lock-fillin-text-property (start end prop value &optional object)
1368 ;; `font-lock-syntactic-keywords' of course, (b) they are all `defun' as speed
1374 (defun font-lock-apply-syntactic-highlight (highlight)
1377 see `font-lock-syntactic-keywords'."
1390 ;; font-lock's use of syntax-ppss, but I'm not 100% sure and it can
1403 (font-lock-fillin-text-property start end 'syntax-table value))))))
1405 (defun font-lock-fontify-syntactic-anchored-keywords (keywords limit)
1407 KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
1409 (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
1411 (pre-match-value (eval (nth 1 keywords))))
1424 (font-lock-apply-syntactic-highlight (car highlights))
1427 (eval (nth 2 keywords))))
1429 (defun font-lock-fontify-syntactic-keywords-region (start end)
1430 "Fontify according to `font-lock-syntactic-keywords' between START and END.
1433 (when (and font-lock-syntactically-fontified
1434 (< font-lock-syntactically-fontified start))
1435 (setq start (max font-lock-syntactically-fontified (point-min)))
1436 (setq font-lock-syntactically-fontified end))
1437 ;; If `font-lock-syntactic-keywords' is a symbol, get the real keywords.
1438 (when (symbolp font-lock-syntactic-keywords)
1439 (setq font-lock-syntactic-keywords (font-lock-eval-keywords
1440 font-lock-syntactic-keywords)))
1441 ;; If `font-lock-syntactic-keywords' is not compiled, compile it.
1442 (unless (eq (car font-lock-syntactic-keywords) t)
1443 (setq font-lock-syntactic-keywords (font-lock-compile-keywords
1444 font-lock-syntactic-keywords
1447 (let ((case-fold-search font-lock-keywords-case-fold-search)
1448 (keywords (cddr font-lock-syntactic-keywords))
1450 (while keywords
1452 (setq keyword (car keywords) matcher (car keyword))
1458 ;; specific highlights or more keywords anchored to `matcher'.
1462 (font-lock-apply-syntactic-highlight (car highlights))
1463 (font-lock-fontify-syntactic-anchored-keywords (car highlights)
1466 (setq keywords (cdr keywords)))))
1473 (defvar font-lock-comment-start-skip nil
1476 (defvar font-lock-comment-end-skip nil
1479 (defun font-lock-fontify-syntactically-region (start end &optional loudly ppss)
1483 (or font-lock-comment-end-skip
1497 (setq face (funcall font-lock-syntactic-face-function state))
1502 (when (and (eq face 'font-lock-comment-face)
1503 (or font-lock-comment-start-skip
1506 ;; and use font-lock-comment-delimiter-face for them.
1509 (if (looking-at (or font-lock-comment-start-skip
1512 font-lock-comment-delimiter-face)))
1515 font-lock-comment-delimiter-face))))
1525 (defsubst font-lock-apply-highlight (highlight)
1527 HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'."
1543 ;; font-lock-append-text-property, the property is actually
1555 (font-lock-prepend-text-property start end 'face val))
1558 (font-lock-append-text-property start end 'face val))
1561 (font-lock-fillin-text-property start end 'face val)))))))
1563 (defsubst font-lock-fontify-anchored-keywords (keywords limit)
1565 KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
1567 (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
1570 (pre-match-value (eval (nth 1 keywords))))
1575 (when (and font-lock-multiline (>= limit (line-beginning-position 2)))
1577 ;; (setq font-lock-multiline t)
1582 'font-lock-multiline t)))
1592 (font-lock-apply-highlight (car highlights))
1595 (eval (nth 2 keywords))))
1597 (defun font-lock-fontify-keywords-region (start end &optional loudly)
1598 "Fontify according to `font-lock-keywords' between START and END.
1601 (unless (eq (car font-lock-keywords) t)
1602 (setq font-lock-keywords
1603 (font-lock-compile-keywords font-lock-keywords)))
1604 (let ((case-fold-search font-lock-keywords-case-fold-search)
1605 (keywords (cddr font-lock-keywords))
1610 ;; Fontify each item in `font-lock-keywords' from `start' to `end'.
1611 (while keywords
1616 (setq keyword (car keywords) matcher (car keyword))
1626 (when (and font-lock-multiline
1631 ;; (setq font-lock-multiline t)
1639 'font-lock-multiline t))
1641 ;; specific highlights or more keywords anchored to `matcher'.
1645 (font-lock-apply-highlight (car highlights))
1647 (font-lock-fontify-anchored-keywords (car highlights) end)
1652 (setq keywords (cdr keywords)))
1660 (defun font-lock-compile-keywords (keywords &optional syntactic-keywords)
1663 `font-lock-keywords' doc string.
1664 If SYNTACTIC-KEYWORDS is non-nil, it means these keywords are used for
1665 `font-lock-syntactic-keywords' rather than for `font-lock-keywords'."
1666 (if (not font-lock-set-defaults)
1668 ;; call font-lock in unexpected and incorrect ways. It's important to
1670 ;; global value of font-lock-keywords and break highlighting in many
1672 (error "Font-lock trying to use keywords before setting them up"))
1673 (if (eq (car-safe keywords) t)
1674 keywords
1675 (setq keywords
1676 (cons t (cons keywords
1677 (mapcar 'font-lock-compile-keyword keywords))))
1678 (if (and (not syntactic-keywords)
1680 (or font-lock-beginning-of-syntax-function
1683 (get beg-function 'font-lock-syntax-paren-check)))
1686 ;; looks like a defun and would thus confuse font-lock.
1687 (nconc keywords
1693 '(font-lock-string-face font-lock-doc-face
1694 font-lock-comment-face))
1695 (list 'face font-lock-warning-face
1698 keywords))
1700 (defun font-lock-compile-keyword (keyword)
1702 (list keyword '(0 font-lock-keyword-face)))
1704 (font-lock-compile-keyword (eval (cdr keyword))))
1709 (font-lock-compile-keyword (cons (car keyword) (nth 2 keyword)))))
1711 (list (car keyword) (list (cdr keyword) 'font-lock-keyword-face)))
1719 (defun font-lock-eval-keywords (keywords)
1721 (if (listp keywords)
1722 keywords
1723 (font-lock-eval-keywords (if (fboundp keywords)
1724 (funcall keywords)
1725 (eval keywords)))))
1727 (defun font-lock-value-in-major-mode (alist)
1734 (defun font-lock-choose-keywords (keywords level)
1738 (cond ((not (and (listp keywords) (symbolp (car keywords))))
1739 keywords)
1741 (or (nth level keywords) (car (last keywords))))
1743 (car (last keywords)))
1745 (car keywords))))
1747 (defvar font-lock-set-defaults nil) ; Whether we have set up defaults.
1749 (defvar font-lock-mode-major-mode)
1750 (defun font-lock-set-defaults ()
1752 Sets various variables using `font-lock-defaults' (or, if nil, using
1753 `font-lock-defaults-alist') and `font-lock-maximum-decoration'."
1755 (unless (and font-lock-set-defaults
1756 (eq font-lock-mode-major-mode major-mode))
1757 (setq font-lock-mode-major-mode major-mode)
1758 (set (make-local-variable 'font-lock-set-defaults) t)
1759 (make-local-variable 'font-lock-fontified)
1760 (make-local-variable 'font-lock-multiline)
1761 (let* ((defaults (or font-lock-defaults
1764 font-lock-defaults-alist)))))
1765 (keywords
1766 (font-lock-choose-keywords (nth 0 defaults)
1767 (font-lock-value-in-major-mode font-lock-maximum-decoration)))
1768 (local (cdr (assq major-mode font-lock-keywords-alist)))
1769 (removed-keywords
1770 (cdr-safe (assq major-mode font-lock-removed-keywords-alist))))
1771 (set (make-local-variable 'font-lock-defaults) defaults)
1774 (set (make-local-variable 'font-lock-keywords-only) t))
1777 (set (make-local-variable 'font-lock-keywords-case-fold-search) t))
1780 (set (make-local-variable 'font-lock-syntax-table)
1788 (modify-syntax-entry char syntax font-lock-syntax-table)))))
1791 (set (make-local-variable 'font-lock-beginning-of-syntax-function)
1796 ;; Set up `font-lock-keywords' last because its value might depend
1797 ;; on other settings (e.g. font-lock-compile-keywords uses
1798 ;; font-lock-beginning-of-syntax-function).
1799 (set (make-local-variable 'font-lock-keywords)
1800 (font-lock-eval-keywords keywords))
1803 (font-lock-add-keywords nil (car (car local)) (cdr (car local)))
1805 (when removed-keywords
1806 (font-lock-remove-keywords nil removed-keywords))
1807 ;; Now compile the keywords.
1808 (unless (eq (car font-lock-keywords) t)
1809 (setq font-lock-keywords
1810 (font-lock-compile-keywords font-lock-keywords))))))
1817 (defface font-lock-comment-face
1836 :group 'font-lock-faces)
1838 (defface font-lock-comment-delimiter-face
1839 '((default :inherit font-lock-comment-face)
1847 :group 'font-lock-faces)
1849 (defface font-lock-string-face
1859 :group 'font-lock-faces)
1861 (defface font-lock-doc-face
1862 '((t :inherit font-lock-string-face))
1864 :group 'font-lock-faces)
1866 (defface font-lock-keyword-face
1875 "Font Lock mode face used to highlight keywords."
1876 :group 'font-lock-faces)
1878 (defface font-lock-builtin-face
1888 :group 'font-lock-faces)
1890 (defface font-lock-function-name-face
1898 :group 'font-lock-faces)
1900 (defface font-lock-variable-name-face
1912 :group 'font-lock-faces)
1914 (defface font-lock-type-face
1924 :group 'font-lock-faces)
1926 (defface font-lock-constant-face
1938 :group 'font-lock-faces)
1940 (defface font-lock-warning-face
1948 :group 'font-lock-faces)
1950 (defface font-lock-negation-char-face
1953 :group 'font-lock-faces)
1955 (defface font-lock-preprocessor-face
1956 '((t :inherit font-lock-builtin-face))
1958 :group 'font-lock-faces)
1960 (defface font-lock-regexp-grouping-backslash
1963 :group 'font-lock-faces)
1965 (defface font-lock-regexp-grouping-construct
1968 :group 'font-lock-faces)
1981 ;; (define-key menu-bar-edit-menu [font-lock]
1982 ;; (cons "Syntax Highlighting" font-lock-menu))
1992 ;; (defvar font-lock-menu (make-sparse-keymap "Syntax Highlighting"))
1994 ;; (define-key font-lock-menu [fontify-less]
1995 ;; '("Less In Current Buffer" . font-lock-fontify-less))
1996 ;; (define-key font-lock-menu [fontify-more]
1997 ;; '("More In Current Buffer" . font-lock-fontify-more))
1998 ;; (define-key font-lock-menu [font-lock-sep]
2000 ;; (define-key font-lock-menu [font-lock-mode]
2001 ;; '("In Current Buffer" . font-lock-mode))
2002 ;; (define-key font-lock-menu [global-font-lock-mode]
2003 ;; '("In All Buffers" . global-font-lock-mode)))
2008 ;; ;; font-lock.el is loaded, so we don't need to autoload the three variables.
2009 ;; (put 'global-font-lock-mode 'menu-toggle t)
2010 ;; (put 'font-lock-mode 'menu-toggle t)
2011 ;; (put 'font-lock-fontify-more 'menu-enable '(identity))
2012 ;; (put 'font-lock-fontify-less 'menu-enable '(identity)))
2015 ;;(put 'global-font-lock-mode 'menu-selected 'global-font-lock-mode)
2016 ;;(put 'font-lock-mode 'menu-selected 'font-lock-mode)
2017 ;;(put 'font-lock-fontify-more 'menu-enable '(nth 2 font-lock-fontify-level))
2018 ;;(put 'font-lock-fontify-less 'menu-enable '(nth 1 font-lock-fontify-level))
2020 ;;(defvar font-lock-fontify-level nil) ; For less/more fontification.
2022 ;;(defun font-lock-fontify-level (level)
2023 ;; (let ((font-lock-maximum-decoration level))
2024 ;; (when font-lock-mode
2025 ;; (font-lock-mode))
2026 ;; (font-lock-mode)
2027 ;; (when font-lock-verbose
2030 ;;(defun font-lock-fontify-less ()
2032 ;;See `font-lock-maximum-decoration'."
2035 ;; (if (nth 1 font-lock-fontify-level)
2036 ;; (font-lock-fontify-level (1- (car font-lock-fontify-level)))
2039 ;;(defun font-lock-fontify-more ()
2041 ;;See `font-lock-maximum-decoration'."
2044 ;; (if (nth 2 font-lock-fontify-level)
2045 ;; (font-lock-fontify-level (1+ (car font-lock-fontify-level)))
2048 ;; ;; This should be called by `font-lock-set-defaults'.
2049 ;;(defun font-lock-set-menu ()
2051 ;; ;; the current buffer. Sets `font-lock-fontify-level' to be of the form
2053 ;; (let ((keywords (or (nth 0 font-lock-defaults)
2054 ;; (nth 1 (assq major-mode font-lock-defaults-alist))))
2055 ;; (level (font-lock-value-in-major-mode font-lock-maximum-decoration)))
2056 ;; (make-local-variable 'font-lock-fontify-level)
2057 ;; (if (or (symbolp keywords) (= (length keywords) 1))
2058 ;; (font-lock-unset-menu)
2060 ;; (setq level (1- (length keywords))))
2063 ;; (setq level (- (length keywords)
2064 ;; (length (member (eval (car keywords))
2065 ;; (mapcar 'eval (cdr keywords))))))))
2066 ;; (setq font-lock-fontify-level (list level (> level 1)
2067 ;; (< level (1- (length keywords))))))))
2069 ;; ;; This should be called by `font-lock-unset-defaults'.
2070 ;;(defun font-lock-unset-menu ()
2072 ;; (setq font-lock-fontify-level nil))
2082 ;; should stay in font-lock.el, since it is used by other libraries. sm.
2084 (defun font-lock-match-c-style-declaration-item-and-skip-to-next (limit)
2102 This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
2130 ;; `cpp-font-lock-keywords' is handy for modes for the files.
2133 ;; while font-lock.el is preloaded to emacs. So values pre-calculated with
2136 ;; `cpp-font-lock-keywords-source-directives' is calculated from:
2142 (defconst cpp-font-lock-keywords-source-directives
2144 "Regular expressoin used in `cpp-font-lock-keywords'.")
2146 ;; `cpp-font-lock-keywords-source-depth' is calculated from:
2152 (defconst cpp-font-lock-keywords-source-depth 0
2153 "An integer representing regular expression depth of `cpp-font-lock-keywords-source-directives'.
2154 Used in `cpp-font-lock-keywords'.")
2156 (defconst cpp-font-lock-keywords
2157 (let* ((directives cpp-font-lock-keywords-source-directives)
2158 (directives-depth cpp-font-lock-keywords-source-depth))
2162 '("^#[ \t]*\\(?:error\\|warning\\)[ \t]+\\(.+\\)" 1 font-lock-warning-face prepend)
2166 1 font-lock-string-face prepend)
2170 (1 font-lock-function-name-face prepend)
2179 nil nil (1 font-lock-variable-name-face prepend)))
2184 (1 font-lock-builtin-face prepend) (2 font-lock-variable-name-face prepend t)))
2190 '(1 font-lock-preprocessor-face prepend)
2192 'font-lock-variable-name-face nil t))))
2193 "Font lock keyords for C preprocessor directives.
2195 font lock keyords for C preprocessor directives. This definition is for the
2203 (defconst lisp-font-lock-keywords-1
2222 (1 font-lock-keyword-face)
2223 (9 (cond ((match-beginning 3) font-lock-function-name-face)
2224 ((match-beginning 6) font-lock-variable-name-face)
2225 (t font-lock-type-face))
2228 ("^;;;###\\(autoload\\)" 1 font-lock-warning-face prepend)
2230 ("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend)))
2233 (defconst lisp-font-lock-keywords-2
2234 (append lisp-font-lock-keywords-1
2280 (1 font-lock-keyword-face)
2281 (2 font-lock-constant-face nil t))
2283 ("(\\(abort\\|assert\\|warn\\|check-type\\|cerror\\|error\\|signal\\)\\>" 1 font-lock-warning-face)
2285 ("\\\\\\\\\\[\\(\\sw+\\)\\]" 1 font-lock-constant-face prepend)
2287 ("`\\(\\sw\\sw+\\)'" 1 font-lock-constant-face prepend)
2289 ("\\<:\\sw+\\>" 0 font-lock-builtin-face)
2290 ;; ELisp and CLisp `&' keywords as types.
2291 ("\\<\\&\\sw+\\>" . font-lock-type-face)
2303 (memq 'font-lock-string-face face))
2304 (eq 'font-lock-string-face face))
2306 (1 'font-lock-regexp-grouping-backslash prepend)
2307 (3 'font-lock-regexp-grouping-construct prepend))
2312 ;;; ("(\\(\\(do-\\|with-\\)\\(\\s_\\|\\w\\)*\\)" 1 font-lock-keyword-face)
2316 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
2320 (provide 'font-lock)
2323 ;;; font-lock.el ends here