aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/font-lock.el1092
1 files changed, 756 insertions, 336 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index fd3ccdc0d1a..91bad065390 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -135,6 +135,8 @@
135;; Don't use it to, say, highlight keywords in commented out code or strings. 135;; Don't use it to, say, highlight keywords in commented out code or strings.
136;; - Err, that's it. 136;; - Err, that's it.
137 137
138;;; Code:
139
138;; User variables. 140;; User variables.
139 141
140(defvar font-lock-verbose (* 0 1024) 142(defvar font-lock-verbose (* 0 1024)
@@ -166,6 +168,12 @@ for buffers in Rmail mode, and size is irrelevant otherwise.")
166 168
167;; Fontification variables: 169;; Fontification variables:
168 170
171;; Originally these variables defaulted to face names such as `bold' etc.
172;; Now we create our own faces, but we keep these variables for compatibility
173;; and they give users another mechanism for changing face appearance.
174;; We now allow a FACENAME in `font-lock-keywords' to be any expression that
175;; returns a face. So the easiest thing is to continue using these variables,
176;; rather than sometimes evaling FACENAME and sometimes not.
169(defvar font-lock-comment-face 'font-lock-comment-face 177(defvar font-lock-comment-face 'font-lock-comment-face
170 "Face to use for comments.") 178 "Face to use for comments.")
171 179
@@ -175,6 +183,9 @@ for buffers in Rmail mode, and size is irrelevant otherwise.")
175(defvar font-lock-keyword-face 'font-lock-keyword-face 183(defvar font-lock-keyword-face 'font-lock-keyword-face
176 "Face to use for keywords.") 184 "Face to use for keywords.")
177 185
186(defvar font-lock-builtin-face 'font-lock-builtin-face
187 "Face to use for builtins.")
188
178(defvar font-lock-function-name-face 'font-lock-function-name-face 189(defvar font-lock-function-name-face 'font-lock-function-name-face
179 "Face to use for function names.") 190 "Face to use for function names.")
180 191
@@ -187,6 +198,9 @@ for buffers in Rmail mode, and size is irrelevant otherwise.")
187(defvar font-lock-reference-face 'font-lock-reference-face 198(defvar font-lock-reference-face 'font-lock-reference-face
188 "Face to use for reference names.") 199 "Face to use for reference names.")
189 200
201(defvar font-lock-warning-face 'font-lock-warning-face
202 "Face to use for things that should stand out.")
203
190(defvar font-lock-keywords nil 204(defvar font-lock-keywords nil
191 "*A list of the keywords to highlight. 205 "*A list of the keywords to highlight.
192Each element should be of the form: 206Each element should be of the form:
@@ -270,14 +284,18 @@ Be very careful composing regexps for this list;
270the wrong pattern can dramatically slow things down!") 284the wrong pattern can dramatically slow things down!")
271(make-variable-buffer-local 'font-lock-keywords) 285(make-variable-buffer-local 'font-lock-keywords)
272 286
287;; This variable is used by mode packages that support Font Lock mode by
288;; defining their own keywords to use for `font-lock-keywords'. (The mode
289;; command should make it buffer-local and set it to provide the set up.)
273(defvar font-lock-defaults nil 290(defvar font-lock-defaults nil
274 "If set by a major mode, should be the defaults for Font Lock mode. 291 "If set by a major mode, should be the defaults for Font Lock mode.
275The value should be like the `cdr' of an item in `font-lock-defaults-alist'.") 292The value should be like the `cdr' of an item in `font-lock-defaults-alist'.")
276 293
294;; This variable is used where font-lock.el itself supplies the keywords.
277(defvar font-lock-defaults-alist 295(defvar font-lock-defaults-alist
278 (let (;; For C and Lisp modes we use `beginning-of-defun', rather than nil, 296 (let (;; We use `beginning-of-defun', rather than nil, for SYNTAX-BEGIN.
279 ;; for SYNTAX-BEGIN. Thus the calculation of the cache is usually 297 ;; Thus the calculation of the cache is usually faster but not
280 ;; faster but not infallible, so we risk mis-fontification. --sm. 298 ;; infallible, so we risk mis-fontification. sm.
281 (c-mode-defaults 299 (c-mode-defaults
282 '((c-font-lock-keywords c-font-lock-keywords-1 300 '((c-font-lock-keywords c-font-lock-keywords-1
283 c-font-lock-keywords-2 c-font-lock-keywords-3) 301 c-font-lock-keywords-2 c-font-lock-keywords-3)
@@ -290,6 +308,18 @@ The value should be like the `cdr' of an item in `font-lock-defaults-alist'.")
290 nil nil ((?_ . "w") (?~ . "w")) beginning-of-defun 308 nil nil ((?_ . "w") (?~ . "w")) beginning-of-defun
291 (font-lock-comment-start-regexp . "/[*/]") 309 (font-lock-comment-start-regexp . "/[*/]")
292 (font-lock-mark-block-function . mark-defun))) 310 (font-lock-mark-block-function . mark-defun)))
311 (objc-mode-defaults
312 '((objc-font-lock-keywords objc-font-lock-keywords-1
313 objc-font-lock-keywords-2 objc-font-lock-keywords-3)
314 nil nil ((?_ . "w") (?$ . "w")) nil
315 (font-lock-comment-start-regexp . "/[*/]")
316 (font-lock-mark-block-function . mark-defun)))
317 (java-mode-defaults
318 '((java-font-lock-keywords java-font-lock-keywords-1
319 java-font-lock-keywords-2 java-font-lock-keywords-3)
320 nil nil ((?_ . "w") (?$ . "w") (?. . "w")) nil
321 (font-lock-comment-start-regexp . "/[*/]")
322 (font-lock-mark-block-function . mark-defun)))
293 (lisp-mode-defaults 323 (lisp-mode-defaults
294 '((lisp-font-lock-keywords 324 '((lisp-font-lock-keywords
295 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2) 325 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2)
@@ -312,10 +342,10 @@ The value should be like the `cdr' of an item in `font-lock-defaults-alist'.")
312 (font-lock-mark-block-function . mark-paragraph))) 342 (font-lock-mark-block-function . mark-paragraph)))
313 ) 343 )
314 (list 344 (list
315 (cons 'c++-c-mode c-mode-defaults)
316 (cons 'c++-mode c++-mode-defaults)
317 (cons 'c-mode c-mode-defaults) 345 (cons 'c-mode c-mode-defaults)
318 (cons 'elec-c-mode c-mode-defaults) 346 (cons 'c++-mode c++-mode-defaults)
347 (cons 'objc-mode objc-mode-defaults)
348 (cons 'java-mode java-mode-defaults)
319 (cons 'emacs-lisp-mode lisp-mode-defaults) 349 (cons 'emacs-lisp-mode lisp-mode-defaults)
320 (cons 'inferior-scheme-mode scheme-mode-defaults) 350 (cons 'inferior-scheme-mode scheme-mode-defaults)
321 (cons 'latex-mode tex-mode-defaults) 351 (cons 'latex-mode tex-mode-defaults)
@@ -439,8 +469,23 @@ This is normally set via `font-lock-defaults'.")
439;; Font Lock mode. 469;; Font Lock mode.
440 470
441(eval-when-compile 471(eval-when-compile
472 ;;
442 ;; We don't do this at the top-level as we only use non-autoloaded macros. 473 ;; We don't do this at the top-level as we only use non-autoloaded macros.
443 (require 'cl)) 474 (require 'cl)
475 ;;
476 ;; Borrowed from lazy-lock.el.
477 ;; We use this to preserve or protect things when modifying text properties.
478 (defmacro save-buffer-state (varlist &rest body)
479 "Bind variables according to VARLIST and eval BODY restoring buffer state."
480 (` (let* ((,@ (append varlist
481 '((modified (buffer-modified-p))
482 (inhibit-read-only t) (buffer-undo-list t)
483 before-change-functions after-change-functions
484 deactivate-mark buffer-file-name buffer-file-truename))))
485 (,@ body)
486 (when (and (not modified) (buffer-modified-p))
487 (set-buffer-modified-p nil)))))
488 (put 'save-buffer-state 'lisp-indent-function 1))
444 489
445;;;###autoload 490;;;###autoload
446(defun font-lock-mode (&optional arg) 491(defun font-lock-mode (&optional arg)
@@ -501,10 +546,9 @@ its mode hook."
501 (set (make-local-variable 'font-lock-mode) on-p) 546 (set (make-local-variable 'font-lock-mode) on-p)
502 ;; Turn on Font Lock mode. 547 ;; Turn on Font Lock mode.
503 (when on-p 548 (when on-p
549 (make-local-hook 'after-change-functions)
550 (add-hook 'after-change-functions 'font-lock-after-change-function nil t)
504 (font-lock-set-defaults) 551 (font-lock-set-defaults)
505 (unless (eq font-lock-fontify-region-function 'ignore)
506 (make-local-hook 'after-change-functions)
507 (add-hook 'after-change-functions 'font-lock-after-change-function nil t))
508 (font-lock-turn-on-thing-lock) 552 (font-lock-turn-on-thing-lock)
509 (run-hooks 'font-lock-mode-hook) 553 (run-hooks 'font-lock-mode-hook)
510 ;; Fontify the buffer if we have to. 554 ;; Fontify the buffer if we have to.
@@ -516,7 +560,7 @@ its mode hook."
516 (font-lock-verbose 560 (font-lock-verbose
517 (message "Fontifying %s...buffer too big" (buffer-name)))))) 561 (message "Fontifying %s...buffer too big" (buffer-name))))))
518 ;; Turn off Font Lock mode. 562 ;; Turn off Font Lock mode.
519 (when (not on-p) 563 (unless on-p
520 (remove-hook 'after-change-functions 'font-lock-after-change-function t) 564 (remove-hook 'after-change-functions 'font-lock-after-change-function t)
521 (font-lock-unfontify-buffer) 565 (font-lock-unfontify-buffer)
522 (font-lock-turn-off-thing-lock) 566 (font-lock-turn-off-thing-lock)
@@ -576,13 +620,12 @@ Turn on only if the terminal can display it."
576;; command to toggle the feature (`global-font-lock-mode') with a variable for 620;; command to toggle the feature (`global-font-lock-mode') with a variable for
577;; finer control of the mode's behaviour (`font-lock-global-modes'). 621;; finer control of the mode's behaviour (`font-lock-global-modes').
578;; 622;;
579;; I don't think it is better that the feature be enabled via a variable, since 623;; The feature should not be enabled by loading font-lock.el, since other
580;; it does not conform to the usual convention. I don't think the feature 624;; mechanisms for turning on Font Lock mode, such as M-x font-lock-mode RET or
581;; should be enabled by loading font-lock.el, since other mechanisms such as 625;; (add-hook 'c-mode-hook 'turn-on-font-lock), would cause Font Lock mode to be
582;; M-x font-lock-mode RET or (add-hook 'c-mode-hook 'turn-on-font-lock) would 626;; turned on everywhere. That would not be intuitive or informative because
583;; cause Font Lock mode to be turned on everywhere, and it is not intuitive or 627;; loading a file tells you nothing about the feature or how to control it. It
584;; informative because loading a file tells you nothing about the feature or 628;; would also be contrary to the Principle of Least Surprise.
585;; how to control it. It would be contrary to the Principle of Least Surprise.
586 629
587(defvar font-lock-buffers nil) ; For remembering buffers. 630(defvar font-lock-buffers nil) ; For remembering buffers.
588(defvar global-font-lock-mode nil) 631(defvar global-font-lock-mode nil)
@@ -680,6 +723,9 @@ C++ modes, and Lazy Lock mode is used to support Font Lock mode otherwise.
680 723
681The value of this variable is used when Font Lock mode is turned on.") 724The value of this variable is used when Font Lock mode is turned on.")
682 725
726(defvar fast-lock-mode nil)
727(defvar lazy-lock-mode nil)
728
683(defun font-lock-turn-on-thing-lock () 729(defun font-lock-turn-on-thing-lock ()
684 (let ((thing-mode (font-lock-value-in-major-mode font-lock-support-mode))) 730 (let ((thing-mode (font-lock-value-in-major-mode font-lock-support-mode)))
685 (cond ((eq thing-mode 'fast-lock-mode) 731 (cond ((eq thing-mode 'fast-lock-mode)
@@ -687,9 +733,6 @@ The value of this variable is used when Font Lock mode is turned on.")
687 ((eq thing-mode 'lazy-lock-mode) 733 ((eq thing-mode 'lazy-lock-mode)
688 (lazy-lock-mode t))))) 734 (lazy-lock-mode t)))))
689 735
690(defvar fast-lock-mode nil)
691(defvar lazy-lock-mode nil)
692
693(defun font-lock-turn-off-thing-lock () 736(defun font-lock-turn-off-thing-lock ()
694 (cond (fast-lock-mode 737 (cond (fast-lock-mode
695 (fast-lock-mode nil)) 738 (fast-lock-mode nil))
@@ -747,7 +790,7 @@ The value of this variable is used when Font Lock mode is turned on.")
747 ;; We don't restore the old fontification, so it's best to unfontify. 790 ;; We don't restore the old fontification, so it's best to unfontify.
748 (quit (font-lock-unfontify-buffer)))) 791 (quit (font-lock-unfontify-buffer))))
749 (if verbose (message "Fontifying %s...%s" (buffer-name) 792 (if verbose (message "Fontifying %s...%s" (buffer-name)
750 (if font-lock-fontified "done" "aborted"))))) 793 (if font-lock-fontified "done" "quit")))))
751 794
752(defun font-lock-default-unfontify-buffer () 795(defun font-lock-default-unfontify-buffer ()
753 (save-restriction 796 (save-restriction
@@ -756,28 +799,21 @@ The value of this variable is used when Font Lock mode is turned on.")
756 (font-lock-after-unfontify-buffer) 799 (font-lock-after-unfontify-buffer)
757 (setq font-lock-fontified nil))) 800 (setq font-lock-fontified nil)))
758 801
759;; We use this wrapper. However, `font-lock-fontify-region' used to be the
760;; name used for `font-lock-fontify-syntactically-region', so a change isn't
761;; back-compatible. But you shouldn't be calling these directly, should you?
762(defun font-lock-default-fontify-region (beg end loudly) 802(defun font-lock-default-fontify-region (beg end loudly)
763 (let ((modified (buffer-modified-p)) 803 (save-buffer-state ((old-syntax-table (syntax-table)))
764 (buffer-undo-list t) (inhibit-read-only t)
765 (old-syntax-table (syntax-table))
766 before-change-functions after-change-functions
767 buffer-file-name buffer-file-truename)
768 (unwind-protect 804 (unwind-protect
769 (save-restriction 805 (save-restriction
770 (widen) 806 (widen)
771 ;; Use the fontification syntax table, if any. 807 ;; Use the fontification syntax table, if any.
772 (if font-lock-syntax-table (set-syntax-table font-lock-syntax-table)) 808 (when font-lock-syntax-table
809 (set-syntax-table font-lock-syntax-table))
773 ;; Now do the fontification. 810 ;; Now do the fontification.
774 (if font-lock-keywords-only 811 (font-lock-unfontify-region beg end)
775 (font-lock-unfontify-region beg end) 812 (unless font-lock-keywords-only
776 (font-lock-fontify-syntactically-region beg end loudly)) 813 (font-lock-fontify-syntactically-region beg end loudly))
777 (font-lock-fontify-keywords-region beg end loudly)) 814 (font-lock-fontify-keywords-region beg end loudly))
778 ;; Clean up. 815 ;; Clean up.
779 (set-syntax-table old-syntax-table) 816 (set-syntax-table old-syntax-table))))
780 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))))
781 817
782;; The following must be rethought, since keywords can override fontification. 818;; The following must be rethought, since keywords can override fontification.
783; ;; Now scan for keywords, but not if we are inside a comment now. 819; ;; Now scan for keywords, but not if we are inside a comment now.
@@ -788,21 +824,17 @@ The value of this variable is used when Font Lock mode is turned on.")
788; (font-lock-fontify-keywords-region beg end)) 824; (font-lock-fontify-keywords-region beg end))
789 825
790(defun font-lock-default-unfontify-region (beg end) 826(defun font-lock-default-unfontify-region (beg end)
791 (let ((modified (buffer-modified-p)) 827 (save-buffer-state nil
792 (buffer-undo-list t) (inhibit-read-only t) 828 (remove-text-properties beg end '(face nil))))
793 before-change-functions after-change-functions
794 buffer-file-name buffer-file-truename)
795 (remove-text-properties beg end '(face nil))
796 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil))))
797 829
798;; Called when any modification is made to buffer text. 830;; Called when any modification is made to buffer text.
799(defun font-lock-after-change-function (beg end old-len) 831(defun font-lock-after-change-function (beg end old-len)
800 (save-excursion 832 (save-excursion
801 (save-match-data 833 (save-match-data
802 ;; Rescan between start of line from `beg' and start of line after `end'. 834 ;; Rescan between start of lines enclosing the region.
803 (font-lock-fontify-region 835 (font-lock-fontify-region
804 (progn (goto-char beg) (beginning-of-line) (point)) 836 (progn (goto-char beg) (beginning-of-line) (point))
805 (progn (goto-char end) (forward-line 1) (point)))))) 837 (progn (goto-char (+ end old-len)) (forward-line 1) (point))))))
806 838
807(defun font-lock-fontify-block (&optional arg) 839(defun font-lock-fontify-block (&optional arg)
808 "Fontify some lines the way `font-lock-fontify-buffer' would. 840 "Fontify some lines the way `font-lock-fontify-buffer' would.
@@ -833,10 +865,11 @@ delimit the region to fontify."
833 865
834;; These record the parse state at a particular position, always the start of a 866;; These record the parse state at a particular position, always the start of a
835;; line. Used to make `font-lock-fontify-syntactically-region' faster. 867;; line. Used to make `font-lock-fontify-syntactically-region' faster.
836(defvar font-lock-cache-position nil) 868;; Previously, `font-lock-cache-position' was just a buffer position. However,
869;; under certain situations, this occasionally resulted in mis-fontification.
870;; I think those "situations" were deletion with Lazy Lock mode's deferral.
837(defvar font-lock-cache-state nil) 871(defvar font-lock-cache-state nil)
838(make-variable-buffer-local 'font-lock-cache-position) 872(defvar font-lock-cache-position nil)
839(make-variable-buffer-local 'font-lock-cache-state)
840 873
841(defun font-lock-fontify-syntactically-region (start end &optional loudly) 874(defun font-lock-fontify-syntactically-region (start end &optional loudly)
842 "Put proper face on each string and comment between START and END. 875 "Put proper face on each string and comment between START and END.
@@ -847,105 +880,98 @@ START should be at the beginning of a line."
847 (concat "\\s\"\\|" comment-start-skip)) 880 (concat "\\s\"\\|" comment-start-skip))
848 (t 881 (t
849 "\\s\""))) 882 "\\s\"")))
850 (comstart (cond (font-lock-comment-start-regexp 883 (cache (marker-position font-lock-cache-position))
851 font-lock-comment-start-regexp) 884 state prev here beg)
852 (comment-start-skip
853 (concat "\\s<\\|" comment-start-skip))
854 (t
855 "\\s<")))
856 state prev prevstate)
857 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) 885 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name)))
858 (goto-char start) 886 (goto-char start)
859 ;; 887 ;;
860 ;; Find the state at the `beginning-of-line' before `start'. 888 ;; Find the state at the `beginning-of-line' before `start'.
861 (if (eq start font-lock-cache-position) 889 (if (eq start cache)
862 ;; Use the cache for the state of `start'. 890 ;; Use the cache for the state of `start'.
863 (setq state font-lock-cache-state) 891 (setq state font-lock-cache-state)
864 ;; Find the state of `start'. 892 ;; Find the state of `start'.
865 (if (null font-lock-beginning-of-syntax-function) 893 (if (null font-lock-beginning-of-syntax-function)
866 ;; Use the state at the previous cache position, if any, or 894 ;; Use the state at the previous cache position, if any, or
867 ;; otherwise calculate from `point-min'. 895 ;; otherwise calculate from `point-min'.
868 (if (or (null font-lock-cache-position) 896 (if (or (null cache) (< start cache))
869 (< start font-lock-cache-position))
870 (setq state (parse-partial-sexp (point-min) start)) 897 (setq state (parse-partial-sexp (point-min) start))
871 (setq state (parse-partial-sexp font-lock-cache-position start 898 (setq state (parse-partial-sexp cache start nil nil
872 nil nil font-lock-cache-state))) 899 font-lock-cache-state)))
873 ;; Call the function to move outside any syntactic block. 900 ;; Call the function to move outside any syntactic block.
874 (funcall font-lock-beginning-of-syntax-function) 901 (funcall font-lock-beginning-of-syntax-function)
875 (setq state (parse-partial-sexp (point) start))) 902 (setq state (parse-partial-sexp (point) start)))
876 ;; Cache the state and position of `start'. 903 ;; Cache the state and position of `start'.
877 (setq font-lock-cache-state state 904 (setq font-lock-cache-state state)
878 font-lock-cache-position start)) 905 (set-marker font-lock-cache-position start))
879 ;; 906 ;;
880 ;; If the region starts inside a string, show the extent of it. 907 ;; If the region starts inside a string, show the extent of it.
881 (if (nth 3 state) 908 (when (nth 3 state)
882 (let ((beg (point))) 909 (setq here (point))
883 (while (and (re-search-forward "\\s\"" end 'move) 910 (while (and (re-search-forward "\\s\"" end 'move)
884 (nth 3 (parse-partial-sexp beg (point) nil nil state)))) 911 ;; Verify the state so we don't get fooled by quoting.
885 (put-text-property beg (point) 'face font-lock-string-face) 912 (nth 3 (parse-partial-sexp here (point) nil nil state))))
886 (setq state (parse-partial-sexp beg (point) nil nil state)))) 913 (put-text-property here (point) 'face font-lock-string-face)
914 (setq state (parse-partial-sexp here (point) nil nil state)))
887 ;; 915 ;;
888 ;; Likewise for a comment. 916 ;; Likewise for a comment.
889 (if (or (nth 4 state) (nth 7 state)) 917 (when (or (nth 4 state) (nth 7 state))
890 (let ((beg (point))) 918 (let ((comstart (cond (font-lock-comment-start-regexp
891 (save-restriction 919 font-lock-comment-start-regexp)
892 (narrow-to-region (point-min) end) 920 (comment-start-skip
893 (condition-case nil 921 (concat "\\s<\\|" comment-start-skip))
894 (progn 922 (t
895 (re-search-backward comstart (point-min) 'move) 923 "\\s<")))
896 (forward-comment 1) 924 (count 1))
897 ;; forward-comment skips all whitespace, 925 (setq here (point))
898 ;; so go back to the real end of the comment. 926 (condition-case nil
899 (skip-chars-backward " \t")) 927 (save-restriction
900 (error (goto-char end)))) 928 (narrow-to-region (point-min) end)
901 (put-text-property beg (point) 'face font-lock-comment-face) 929 ;; Go back to the real start of the comment.
902 (setq state (parse-partial-sexp beg (point) nil nil state)))) 930 (re-search-backward comstart)
931 (forward-comment 1)
932 ;; If there is more than one comment type, then the previous
933 ;; comment start might not be the real comment start.
934 ;; For example, in C++ code, `here' might be on a line following
935 ;; a // comment that is actually within a /* */ comment.
936 (while (<= (point) here)
937 (goto-char here)
938 (re-search-backward comstart nil nil (incf count))
939 (forward-comment 1))
940 ;; Go back to the real end of the comment.
941 (skip-chars-backward " \t"))
942 (error (goto-char end)))
943 (put-text-property here (point) 'face font-lock-comment-face)
944 (setq state (parse-partial-sexp here (point) nil nil state))))
903 ;; 945 ;;
904 ;; Find each interesting place between here and `end'. 946 ;; Find each interesting place between here and `end'.
905 (while (and (< (point) end) 947 (while (and (< (point) end)
906 (setq prev (point) prevstate state) 948 (setq prev (point))
907 (re-search-forward synstart end t) 949 (re-search-forward synstart end t)
908 (progn 950 (setq state (parse-partial-sexp prev (point) nil nil state)))
909 ;; Clear out the fonts of what we skip over. 951 (cond ((nth 3 state)
910 (remove-text-properties prev (point) '(face nil)) 952 ;;
911 ;; Verify the state at that place 953 ;; Found a real string start.
912 ;; so we don't get fooled by \" or \;. 954 (setq here (point) beg (match-beginning 0))
913 (setq state (parse-partial-sexp prev (point) 955 (condition-case nil
914 nil nil state)))) 956 (save-restriction
915 (let ((here (point))) 957 (narrow-to-region (point-min) end)
916 (if (or (nth 4 state) (nth 7 state)) 958 (goto-char (scan-sexps beg 1)))
917 ;; 959 (error (goto-char end)))
918 ;; We found a real comment start. 960 (put-text-property beg (point) 'face font-lock-string-face)
919 (let ((beg (or (match-end 1) (match-beginning 0)))) 961 (setq state (parse-partial-sexp here (point) nil nil state)))
920 (goto-char beg) 962 ((or (nth 4 state) (nth 7 state))
921 (save-restriction 963 ;;
922 (narrow-to-region (point-min) end) 964 ;; Found a real comment start.
923 (condition-case nil 965 (setq here (point) beg (or (match-end 1) (match-beginning 0)))
924 (progn 966 (goto-char beg)
925 (forward-comment 1) 967 (condition-case nil
926 ;; forward-comment skips all whitespace, 968 (save-restriction
927 ;; so go back to the real end of the comment. 969 (narrow-to-region (point-min) end)
928 (skip-chars-backward " \t")) 970 (forward-comment 1)
929 (error (goto-char end)))) 971 (skip-chars-backward " \t"))
930 (put-text-property beg (point) 'face font-lock-comment-face) 972 (error (goto-char end)))
931 (setq state (parse-partial-sexp here (point) nil nil state))) 973 (put-text-property beg (point) 'face font-lock-comment-face)
932 (if (nth 3 state) 974 (setq state (parse-partial-sexp here (point) nil nil state)))))))
933 ;;
934 ;; We found a real string start.
935 (let ((beg (or (match-end 1) (match-beginning 0))))
936 (while (and (re-search-forward "\\s\"" end 'move)
937 (nth 3 (parse-partial-sexp here (point)
938 nil nil state))))
939 (put-text-property beg (point) 'face font-lock-string-face)
940 (setq state (parse-partial-sexp here (point)
941 nil nil state))))))
942 ;;
943 ;; Make sure `prev' is non-nil after the loop
944 ;; only if it was set on the very last iteration.
945 (setq prev nil))
946 ;;
947 ;; Clean up.
948 (and prev (remove-text-properties prev end '(face nil)))))
949 975
950;;; Additional text property functions. 976;;; Additional text property functions.
951 977
@@ -1089,7 +1115,7 @@ START should be at the beginning of a line."
1089 ;; Fontify each item in `font-lock-keywords' from `start' to `end'. 1115 ;; Fontify each item in `font-lock-keywords' from `start' to `end'.
1090 (while keywords 1116 (while keywords
1091 (if loudly (message "Fontifying %s... (regexps..%s)" bufname 1117 (if loudly (message "Fontifying %s... (regexps..%s)" bufname
1092 (make-string (setq count (1+ count)) ?.))) 1118 (make-string (incf count) ?.)))
1093 ;; 1119 ;;
1094 ;; Find an occurrence of `matcher' from `start' to `end'. 1120 ;; Find an occurrence of `matcher' from `start' to `end'.
1095 (setq keyword (car keywords) matcher (car keyword)) 1121 (setq keyword (car keywords) matcher (car keyword))
@@ -1134,7 +1160,7 @@ START should be at the beginning of a line."
1134 1160
1135(defun font-lock-value-in-major-mode (alist) 1161(defun font-lock-value-in-major-mode (alist)
1136 ;; Return value in ALIST for `major-mode', or ALIST if it is not an alist. 1162 ;; Return value in ALIST for `major-mode', or ALIST if it is not an alist.
1137 ;; Alist structure is ((MAJOR-MODE . VALUE)) where MAJOR-MODE may be t. 1163 ;; Structure is ((MAJOR-MODE . VALUE) ...) where MAJOR-MODE may be t.
1138 (if (consp alist) 1164 (if (consp alist)
1139 (cdr (or (assq major-mode alist) (assq t alist))) 1165 (cdr (or (assq major-mode alist) (assq t alist)))
1140 alist)) 1166 alist))
@@ -1151,6 +1177,8 @@ START should be at the beginning of a line."
1151 (t 1177 (t
1152 (car keywords)))) 1178 (car keywords))))
1153 1179
1180(defvar font-lock-set-defaults nil) ; Whether we have set up defaults.
1181
1154(defun font-lock-set-defaults () 1182(defun font-lock-set-defaults ()
1155 "Set fontification defaults appropriately for this mode. 1183 "Set fontification defaults appropriately for this mode.
1156Sets various variables using `font-lock-defaults' (or, if nil, using 1184Sets various variables using `font-lock-defaults' (or, if nil, using
@@ -1159,51 +1187,56 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
1159 (font-lock-make-faces) 1187 (font-lock-make-faces)
1160 ;; Set fontification defaults. 1188 ;; Set fontification defaults.
1161 (make-local-variable 'font-lock-fontified) 1189 (make-local-variable 'font-lock-fontified)
1162 (if (member font-lock-keywords '(nil (t))) 1190 ;; Set iff not previously set.
1163 (let* ((defaults (or font-lock-defaults 1191 (unless font-lock-set-defaults
1164 (cdr (assq major-mode font-lock-defaults-alist)))) 1192 (set (make-local-variable 'font-lock-set-defaults) t)
1165 (keywords 1193 (set (make-local-variable 'font-lock-cache-state) nil)
1166 (font-lock-choose-keywords (nth 0 defaults) 1194 (set (make-local-variable 'font-lock-cache-position) (make-marker))
1167 (font-lock-value-in-major-mode font-lock-maximum-decoration)))) 1195 (let* ((defaults (or font-lock-defaults
1168 ;; Regexp fontification? 1196 (cdr (assq major-mode font-lock-defaults-alist))))
1169 (setq font-lock-keywords (if (fboundp keywords) 1197 (keywords
1170 (funcall keywords) 1198 (font-lock-choose-keywords (nth 0 defaults)
1171 (eval keywords))) 1199 (font-lock-value-in-major-mode font-lock-maximum-decoration))))
1172 ;; Syntactic fontification? 1200 ;; Regexp fontification?
1173 (if (nth 1 defaults) 1201 (setq font-lock-keywords (if (fboundp keywords)
1174 (set (make-local-variable 'font-lock-keywords-only) t)) 1202 (funcall keywords)
1175 ;; Case fold during regexp fontification? 1203 (eval keywords)))
1176 (if (nth 2 defaults) 1204 ;; Syntactic fontification?
1177 (set (make-local-variable 'font-lock-keywords-case-fold-search) t)) 1205 (when (nth 1 defaults)
1178 ;; Syntax table for regexp and syntactic fontification? 1206 (set (make-local-variable 'font-lock-keywords-only) t))
1179 (if (nth 3 defaults) 1207 ;; Case fold during regexp fontification?
1180 (let ((slist (nth 3 defaults))) 1208 (when (nth 2 defaults)
1181 (set (make-local-variable 'font-lock-syntax-table) 1209 (set (make-local-variable 'font-lock-keywords-case-fold-search) t))
1182 (copy-syntax-table (syntax-table))) 1210 ;; Syntax table for regexp and syntactic fontification?
1183 (while slist 1211 (when (nth 3 defaults)
1184 ;; The character to modify may be a single CHAR or a STRING. 1212 (let ((slist (nth 3 defaults)))
1185 (let ((chars (if (numberp (car (car slist))) 1213 (set (make-local-variable 'font-lock-syntax-table)
1186 (list (car (car slist))) 1214 (copy-syntax-table (syntax-table)))
1187 (mapcar 'identity (car (car slist))))) 1215 (while slist
1188 (syntax (cdr (car slist)))) 1216 ;; The character to modify may be a single CHAR or a STRING.
1189 (while chars 1217 (let ((chars (if (numberp (car (car slist)))
1190 (modify-syntax-entry (car chars) syntax 1218 (list (car (car slist)))
1191 font-lock-syntax-table) 1219 (mapcar 'identity (car (car slist)))))
1192 (setq chars (cdr chars))) 1220 (syntax (cdr (car slist))))
1193 (setq slist (cdr slist)))))) 1221 (while chars
1194 ;; Syntax function for syntactic fontification? 1222 (modify-syntax-entry (car chars) syntax
1195 (if (nth 4 defaults) 1223 font-lock-syntax-table)
1196 (set (make-local-variable 'font-lock-beginning-of-syntax-function) 1224 (setq chars (cdr chars)))
1197 (nth 4 defaults))) 1225 (setq slist (cdr slist))))))
1198 ;; Variable alist? 1226 ;; Syntax function for syntactic fontification?
1199 (let ((alist (nthcdr 5 defaults))) 1227 (when (nth 4 defaults)
1200 (while alist 1228 (set (make-local-variable 'font-lock-beginning-of-syntax-function)
1201 (set (make-local-variable (car (car alist))) (cdr (car alist))) 1229 (nth 4 defaults)))
1202 (setq alist (cdr alist))))))) 1230 ;; Variable alist?
1231 (let ((alist (nthcdr 5 defaults)))
1232 (while alist
1233 (set (make-local-variable (car (car alist))) (cdr (car alist)))
1234 (setq alist (cdr alist)))))))
1203 1235
1204(defun font-lock-unset-defaults () 1236(defun font-lock-unset-defaults ()
1205 "Unset fontification defaults. See `font-lock-set-defaults'." 1237 "Unset fontification defaults. See `font-lock-set-defaults'."
1206 (setq font-lock-keywords nil 1238 (setq font-lock-set-defaults nil
1239 font-lock-keywords nil
1207 font-lock-keywords-only nil 1240 font-lock-keywords-only nil
1208 font-lock-keywords-case-fold-search nil 1241 font-lock-keywords-case-fold-search nil
1209 font-lock-syntax-table nil 1242 font-lock-syntax-table nil
@@ -1309,6 +1342,7 @@ See `font-lock-make-face' and `list-faces-display'."
1309 (list '(font-lock-comment-face nil nil t t nil) 1342 (list '(font-lock-comment-face nil nil t t nil)
1310 '(font-lock-string-face nil nil nil t nil) 1343 '(font-lock-string-face nil nil nil t nil)
1311 '(font-lock-keyword-face nil nil t nil nil) 1344 '(font-lock-keyword-face nil nil t nil nil)
1345 '(font-lock-builtin-face nil nil t nil nil)
1312 (list 1346 (list
1313 'font-lock-function-name-face 1347 'font-lock-function-name-face
1314 (cdr (assq 'background-color (frame-parameters))) 1348 (cdr (assq 'background-color (frame-parameters)))
@@ -1316,16 +1350,23 @@ See `font-lock-make-face' and `list-faces-display'."
1316 t nil nil) 1350 t nil nil)
1317 '(font-lock-variable-name-face nil nil t t nil) 1351 '(font-lock-variable-name-face nil nil t t nil)
1318 '(font-lock-type-face nil nil t nil t) 1352 '(font-lock-type-face nil nil t nil t)
1319 '(font-lock-reference-face nil nil t nil t))) 1353 '(font-lock-reference-face nil nil t nil t)
1354 (list
1355 'font-lock-warning-face
1356 (cdr (assq 'background-color (frame-parameters)))
1357 (cdr (assq 'foreground-color (frame-parameters)))
1358 t nil nil)))
1320 ((memq font-lock-display-type '(grayscale greyscale 1359 ((memq font-lock-display-type '(grayscale greyscale
1321 grayshade greyshade)) 1360 grayshade greyshade))
1322 (list 1361 (list
1323 (list 'font-lock-comment-face 1362 (list 'font-lock-comment-face
1324 nil (if light-bg "Gray80" "DimGray") t t nil) 1363 (if light-bg "DimGray" "LightGray") nil t t nil)
1325 (list 'font-lock-string-face 1364 (list 'font-lock-string-face
1326 nil (if light-bg "Gray50" "LightGray") nil t nil) 1365 (if light-bg "DimGray" "LightGray") nil nil t nil)
1327 (list 'font-lock-keyword-face 1366 (list 'font-lock-keyword-face
1328 nil (if light-bg "Gray90" "DimGray") t nil nil) 1367 nil (if light-bg "LightGray" "DimGray") t nil nil)
1368 (list 'font-lock-builtin-face
1369 nil (if light-bg "LightGray" "DimGray") t nil nil)
1329 (list 'font-lock-function-name-face 1370 (list 'font-lock-function-name-face
1330 (cdr (assq 'background-color (frame-parameters))) 1371 (cdr (assq 'background-color (frame-parameters)))
1331 (cdr (assq 'foreground-color (frame-parameters))) 1372 (cdr (assq 'foreground-color (frame-parameters)))
@@ -1333,25 +1374,33 @@ See `font-lock-make-face' and `list-faces-display'."
1333 (list 'font-lock-variable-name-face 1374 (list 'font-lock-variable-name-face
1334 nil (if light-bg "Gray90" "DimGray") t t nil) 1375 nil (if light-bg "Gray90" "DimGray") t t nil)
1335 (list 'font-lock-type-face 1376 (list 'font-lock-type-face
1336 nil (if light-bg "Gray80" "DimGray") t nil t) 1377 nil (if light-bg "Gray80" "DimGray") t nil nil)
1337 (list 'font-lock-reference-face 1378 (list 'font-lock-reference-face
1338 nil (if light-bg "LightGray" "Gray50") t nil t))) 1379 nil (if light-bg "LightGray" "Gray50") t nil t)
1380 (list 'font-lock-warning-face
1381 (cdr (assq 'background-color (frame-parameters)))
1382 (cdr (assq 'foreground-color (frame-parameters)))
1383 t nil nil)))
1339 (light-bg ; light colour background 1384 (light-bg ; light colour background
1340 '((font-lock-comment-face "Firebrick") 1385 '((font-lock-comment-face "Firebrick")
1341 (font-lock-string-face "RosyBrown") 1386 (font-lock-string-face "RosyBrown")
1342 (font-lock-keyword-face "Purple") 1387 (font-lock-keyword-face "Purple")
1388 (font-lock-builtin-face "Orchid")
1343 (font-lock-function-name-face "Blue") 1389 (font-lock-function-name-face "Blue")
1344 (font-lock-variable-name-face "DarkGoldenrod") 1390 (font-lock-variable-name-face "DarkGoldenrod")
1345 (font-lock-type-face "DarkOliveGreen") 1391 (font-lock-type-face "DarkOliveGreen")
1346 (font-lock-reference-face "CadetBlue"))) 1392 (font-lock-reference-face "CadetBlue")
1393 (font-lock-warning-face "Red" nil t nil nil)))
1347 (t ; dark colour background 1394 (t ; dark colour background
1348 '((font-lock-comment-face "OrangeRed") 1395 '((font-lock-comment-face "OrangeRed")
1349 (font-lock-string-face "LightSalmon") 1396 (font-lock-string-face "LightSalmon")
1350 (font-lock-keyword-face "LightSteelBlue") 1397 (font-lock-keyword-face "Cyan")
1398 (font-lock-builtin-face "LightSteelBlue")
1351 (font-lock-function-name-face "LightSkyBlue") 1399 (font-lock-function-name-face "LightSkyBlue")
1352 (font-lock-variable-name-face "LightGoldenrod") 1400 (font-lock-variable-name-face "LightGoldenrod")
1353 (font-lock-type-face "PaleGreen") 1401 (font-lock-type-face "PaleGreen")
1354 (font-lock-reference-face "Aquamarine"))))))) 1402 (font-lock-reference-face "Aquamarine")
1403 (font-lock-warning-face "Pink" nil t nil nil)))))))
1355 ;; Now make the faces if we have to. 1404 ;; Now make the faces if we have to.
1356 (mapcar (function 1405 (mapcar (function
1357 (lambda (face-attributes) 1406 (lambda (face-attributes)
@@ -1407,73 +1456,116 @@ the face is also set; its value is the face name."
1407;;; Various regexp information shared by several modes. 1456;;; Various regexp information shared by several modes.
1408;;; Information specific to a single mode should go in its load library. 1457;;; Information specific to a single mode should go in its load library.
1409 1458
1459;; The C/C++/Objective-C/Java support is in cc-font.el loaded by cc-mode.el.
1460;; The below function should stay in font-lock.el, since it is used by many
1461;; other libraries.
1462
1463(defun font-lock-match-c++-style-declaration-item-and-skip-to-next (limit)
1464 "Match, and move over, any declaration/definition item after point.
1465Matches after point, but ignores leading whitespace, `*' and `&' characters.
1466Does not move further than LIMIT. This generic function is intended to be used
1467as a MATCHER in a MATCH-ANCHORED `font-lock-keywords' item.
1468
1469The expected syntax of a declaration/definition item is `word' or `word::word',
1470possibly ending with optional whitespace and a `('. Everything following the
1471item (but belonging to it) is expected to by skip-able by `scan-sexps', and
1472items are expected to be separated with a `,' and to be terminated with a `;'.
1473
1474Thus the regexp matches after point: word::word (
1475 ^^^^ ^^^^ ^
1476Where the match subexpressions are: 1 3 4
1477
1478So, the item is delimited by (match-beginning 1) and (match-end 1).
1479If (match-beginning 3) is non-nil, that part of the item follows a `::'.
1480If (match-beginning 4) is non-nil, the item is followed by a `('."
1481 (when (looking-at "[ \t*&]*\\(\\sw+\\)\\(::\\(\\sw+\\)\\)?[ \t]*\\((\\)?")
1482 (save-match-data
1483 (condition-case nil
1484 (save-restriction
1485 ;; Restrict to the end of line, currently guaranteed to be LIMIT.
1486 (narrow-to-region (point-min) limit)
1487 (goto-char (match-end 1))
1488 ;; Move over any item value, etc., to the next item.
1489 (while (not (looking-at "[ \t]*\\(\\(,\\)\\|;\\|$\\)"))
1490 (goto-char (or (scan-sexps (point) 1) (point-max))))
1491 (goto-char (match-end 2)))
1492 (error t)))))
1493
1494
1410(defconst lisp-font-lock-keywords-1 1495(defconst lisp-font-lock-keywords-1
1411 (list 1496 (eval-when-compile
1412 ;; Anything not a variable or type declaration is fontified as a function. 1497 (list
1413 ;; It would be cleaner to allow preceding whitespace, but it would also be 1498 ;; Anything not a variable or type declaration is fontified as a function.
1414 ;; about five times slower. 1499 ;; It would be cleaner to allow preceding whitespace, but it would also be
1415 (list (concat "^(\\(def\\(" 1500 ;; about five times slower.
1416 ;; Variable declarations. 1501 (list (concat "^(\\(def\\("
1417 "\\(const\\(\\|ant\\)\\|ine-key\\(\\|-after\\)\\|var\\)\\|" 1502 ;; Variable declarations.
1418 ;; Structure declarations. 1503 "\\(const\\|custom\\|var\\)\\|"
1419 "\\(class\\|struct\\|type\\)\\|" 1504 ;; Structure declarations.
1420 ;; Everything else is a function declaration. 1505 "\\(class\\|struct\\|type\\)\\|"
1421 "\\([^ \t\n\(\)]+\\)" 1506 ;; Everything else is a function declaration.
1422 "\\)\\)\\>" 1507 "\\sw+"
1423 ;; Any whitespace and declared object. 1508 "\\)\\)\\>"
1424 "[ \t'\(]*" 1509 ;; Any whitespace and declared object.
1425 "\\(\\sw+\\)?") 1510 "[ \t'\(]*"
1426 '(1 font-lock-keyword-face) 1511 "\\(\\sw+\\)?")
1427 '(8 (cond ((match-beginning 3) font-lock-variable-name-face) 1512 '(1 font-lock-keyword-face)
1428 ((match-beginning 6) font-lock-type-face) 1513 '(5 (cond ((match-beginning 3) font-lock-variable-name-face)
1429 (t font-lock-function-name-face)) 1514 ((match-beginning 4) font-lock-type-face)
1430 nil t)) 1515 (t font-lock-function-name-face))
1431 ) 1516 nil t))
1517 ))
1432 "Subdued level highlighting for Lisp modes.") 1518 "Subdued level highlighting for Lisp modes.")
1433 1519
1434(defconst lisp-font-lock-keywords-2 1520(defconst lisp-font-lock-keywords-2
1435 (append lisp-font-lock-keywords-1 1521 (append lisp-font-lock-keywords-1
1436 (list 1522 (eval-when-compile
1437 ;; 1523 (list
1438 ;; Control structures. ELisp and CLisp combined. 1524 ;;
1525 ;; Control structures. Common ELisp and CLisp forms combined.
1439; (make-regexp 1526; (make-regexp
1440; '("cond" "if" "while" "let\\*?" "prog[nv12*]?" "inline" "catch" "throw" 1527; '("cond" "if" "while" "let\\*?" "prog[nv12*]?" "inline" "catch" "throw"
1441; "save-restriction" "save-excursion" "save-window-excursion" 1528; "save-restriction" "save-excursion" "save-window-excursion"
1442; "save-selected-window" "save-match-data" "unwind-protect" 1529; "save-selected-window" "save-match-data" "save-current-buffer"
1443; "condition-case" "track-mouse" 1530; "unwind-protect" "condition-case" "track-mouse"
1444; "eval-after-load" "eval-and-compile" "eval-when-compile" 1531; "eval-after-load" "eval-and-compile" "eval-when-compile"
1445; "when" "unless" "do" "flet" "labels" "return" "return-from" 1532; "when" "unless" "do" "flet" "labels" "return" "return-from"
1446; "with-output-to-temp-buffer" "with-timeout")) 1533; "with-output-to-temp-buffer" "with-timeout" "with-current-buffer"
1447 (cons 1534; "with-temp-buffer" "with-temp-file"))
1448 (concat 1535 (cons (concat "(\\("
1449 "(\\(" 1536 "c\\(atch\\|ond\\(\\|ition-case\\)\\)\\|do\\|"
1450 "c\\(atch\\|ond\\(\\|ition-case\\)\\)\\|do\\|" 1537 "eval-\\(a\\(fter-load\\|nd-compile\\)\\|"
1451 "eval-\\(a\\(fter-load\\|nd-compile\\)\\|when-compile\\)\\|flet\\|" 1538 "when-compile\\)\\|flet\\|i\\(f\\|nline\\)\\|"
1452 "i\\(f\\|nline\\)\\|l\\(abels\\|et\\*?\\)\\|prog[nv12*]?\\|" 1539 "l\\(abels\\|et\\*?\\)\\|prog[nv12*]?\\|"
1453 "return\\(\\|-from\\)\\|save-\\(excursion\\|match-data\\|restriction\\|" 1540 "return\\(\\|-from\\)\\|"
1454 "selected-window\\|window-excursion\\)\\|t\\(hrow\\|rack-mouse\\)\\|" 1541 "save-\\(current-buffer\\|excursion\\|match-data\\|"
1455 "un\\(less\\|wind-protect\\)\\|" 1542 "restriction\\|selected-window\\|window-excursion\\)\\|"
1456 "w\\(h\\(en\\|ile\\)\\|ith-\\(output-to-temp-buffer\\|timeout\\)\\)" 1543 "t\\(hrow\\|rack-mouse\\)\\|un\\(less\\|wind-protect\\)\\|"
1457 "\\)\\>") 1) 1544 "w\\(h\\(en\\|ile\\)\\|ith-\\(current-buffer\\|"
1458 ;; 1545 "output-to-temp-buffer\\|"
1459 ;; Feature symbols as references. 1546 "t\\(emp-\\(buffer\\|file\\)\\|imeout\\)\\)\\)"
1460 '("(\\(featurep\\|provide\\|require\\)\\>[ \t']*\\(\\sw+\\)?" 1547 "\\)\\>")
1461 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) 1548 1)
1462 ;; 1549 ;;
1463 ;; Words inside \\[] tend to be for `substitute-command-keys'. 1550 ;; Feature symbols as references.
1464 '("\\\\\\\\\\[\\(\\sw+\\)]" 1 font-lock-reference-face prepend) 1551 '("(\\(featurep\\|provide\\|require\\)\\>[ \t']*\\(\\sw+\\)?"
1465 ;; 1552 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
1466 ;; Words inside `' tend to be symbol names. 1553 ;;
1467 '("`\\(\\sw\\sw+\\)'" 1 font-lock-reference-face prepend) 1554 ;; Words inside \\[] tend to be for `substitute-command-keys'.
1468 ;; 1555 '("\\\\\\\\\\[\\(\\sw+\\)]" 1 font-lock-reference-face prepend)
1469 ;; CLisp `:' keywords as references. 1556 ;;
1470 '("\\<:\\sw+\\>" 0 font-lock-reference-face prepend) 1557 ;; Words inside `' tend to be symbol names.
1471 ;; 1558 '("`\\(\\sw\\sw+\\)'" 1 font-lock-reference-face prepend)
1472 ;; ELisp and CLisp `&' keywords as types. 1559 ;;
1473 '("\\<\\&\\sw+\\>" . font-lock-type-face) 1560 ;; CLisp `:' keywords as references.
1474 )) 1561 '("\\<:\\sw\\sw+\\>" 0 font-lock-reference-face prepend)
1562 ;;
1563 ;; ELisp and CLisp `&' keywords as types.
1564 '("\\<\\&\\sw+\\>" . font-lock-type-face)
1565 )))
1475 "Gaudy level highlighting for Lisp modes.") 1566 "Gaudy level highlighting for Lisp modes.")
1476 1567
1568
1477(defvar lisp-font-lock-keywords lisp-font-lock-keywords-1 1569(defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
1478 "Default expressions to highlight in Lisp modes.") 1570 "Default expressions to highlight in Lisp modes.")
1479 1571
@@ -1490,13 +1582,13 @@ the face is also set; its value is the face name."
1490 ;; Macro names, as variable names. A bit dubious, this. 1582 ;; Macro names, as variable names. A bit dubious, this.
1491 "\\(-syntax\\)\\|" 1583 "\\(-syntax\\)\\|"
1492 ;; Class names. 1584 ;; Class names.
1493 "\\(-class\\)" 1585 "-class"
1494 "\\)\\)\\>" 1586 "\\)\\)\\>"
1495 ;; Any whitespace and declared object. 1587 ;; Any whitespace and declared object.
1496 "[ \t]*(?" 1588 "[ \t]*(?"
1497 "\\(\\sw+\\)?") 1589 "\\(\\sw+\\)?")
1498 '(1 font-lock-keyword-face) 1590 '(1 font-lock-keyword-face)
1499 '(8 (cond ((match-beginning 3) font-lock-function-name-face) 1591 '(7 (cond ((match-beginning 3) font-lock-function-name-face)
1500 ((match-beginning 6) font-lock-variable-name-face) 1592 ((match-beginning 6) font-lock-variable-name-face)
1501 (t font-lock-type-face)) 1593 (t font-lock-type-face))
1502 nil t)) 1594 nil t))
@@ -1526,53 +1618,69 @@ the face is also set; its value is the face name."
1526 ;; Scheme `:' keywords as references. 1618 ;; Scheme `:' keywords as references.
1527 '("\\<:\\sw+\\>" . font-lock-reference-face) 1619 '("\\<:\\sw+\\>" . font-lock-reference-face)
1528 )) 1620 ))
1529"Default expressions to highlight in Scheme modes.") 1621 "Default expressions to highlight in Scheme modes.")
1530 1622
1531 1623
1532(defconst c-font-lock-keywords-1 nil 1624(defvar tex-font-lock-keywords
1533 "Subdued level highlighting for C modes.") 1625; ;; Regexps updated with help from Ulrik Dickow <dickow@nbi.dk>.
1626; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
1627; 2 font-lock-function-name-face)
1628; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
1629; 2 font-lock-reference-face)
1630; ;; It seems a bit dubious to use `bold' and `italic' faces since we might
1631; ;; not be able to display those fonts.
1632; ("{\\\\bf\\([^}]+\\)}" 1 'bold keep)
1633; ("{\\\\\\(em\\|it\\|sl\\)\\([^}]+\\)}" 2 'italic keep)
1634; ("\\\\\\([a-zA-Z@]+\\|.\\)" . font-lock-keyword-face)
1635; ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face keep))
1636 ;; Rewritten and extended for LaTeX2e by Ulrik Dickow <dickow@nbi.dk>.
1637 '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
1638 2 font-lock-function-name-face)
1639 ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
1640 2 font-lock-reference-face)
1641 ("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face)
1642 "\\\\\\([a-zA-Z@]+\\|.\\)"
1643 ;; It seems a bit dubious to use `bold' and `italic' faces since we might
1644 ;; not be able to display those fonts.
1645 ;; LaTeX2e: \emph{This is emphasized}.
1646 ("\\\\emph{\\([^}]+\\)}" 1 'italic keep)
1647 ;; LaTeX2e: \textbf{This is bold}, \textit{...}, \textsl{...}
1648 ("\\\\text\\(\\(bf\\)\\|it\\|sl\\){\\([^}]+\\)}"
1649 3 (if (match-beginning 2) 'bold 'italic) keep)
1650 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for good tables.
1651 ("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)"
1652 3 (if (match-beginning 2) 'bold 'italic) keep))
1653 "Default expressions to highlight in TeX modes.")
1654
1655;;; User choices.
1534 1656
1535(defconst c-font-lock-keywords-2 nil 1657(defvar c-font-lock-extra-types '("FILE" "\\sw+_t")
1536 "Medium level highlighting for C modes.") 1658 "*List of extra types to fontify in C mode.
1659Each list item should be a regexp without word-delimiters or parentheses.")
1537 1660
1538(defconst c-font-lock-keywords-3 nil 1661(defvar c++-font-lock-extra-types nil
1539 "Gaudy level highlighting for C modes.") 1662 "*List of extra types to fontify in C++ mode.
1663Each list item should be a regexp without word-delimiters or parentheses.")
1540 1664
1541(defconst c++-font-lock-keywords-1 nil 1665(defvar objc-font-lock-extra-types '("Class" "BOOL" "IMP" "SEL")
1542 "Subdued level highlighting for C++ modes.") 1666 "*List of extra types to fontify in Objective-C mode.
1667Each list item should be a regexp without word-delimiters or parentheses.")
1543 1668
1544(defconst c++-font-lock-keywords-2 nil 1669(defvar java-font-lock-extra-types '("[A-Z\300-\326\330-\337]\\sw+")
1545 "Medium level highlighting for C++ modes.") 1670 "*List of extra types to fontify in Java mode.
1671Each list item should be a regexp without word-delimiters or parentheses.")
1672
1673;;; C.
1674(defconst c-font-lock-keywords-1 nil
1675 "Subdued level highlighting for C mode.")
1546 1676
1547(defconst c++-font-lock-keywords-3 nil 1677(defconst c-font-lock-keywords-2 nil
1548 "Gaudy level highlighting for C++ modes.") 1678 "Medium level highlighting for C mode.
1679See also `c-font-lock-extra-types'.")
1549 1680
1550(defun font-lock-match-c++-style-declaration-item-and-skip-to-next (limit) 1681(defconst c-font-lock-keywords-3 nil
1551 ;; Match, and move over, any declaration/definition item after point. 1682 "Gaudy level highlighting for C mode.
1552 ;; The expect syntax of an item is "word" or "word::word", possibly ending 1683See also `c-font-lock-extra-types'.")
1553 ;; with optional whitespace and a "(". Everything following the item (but
1554 ;; belonging to it) is expected to by skip-able by `forward-sexp', and items
1555 ;; are expected to be separated with a ",".
1556 ;;
1557 ;; The regexp matches: word::word (
1558 ;; ^^^^ ^^^^ ^
1559 ;; Match subexps are: 1 3 4
1560 ;;
1561 ;; So, the item is delimited by (match-beginning 1) and (match-end 1).
1562 ;; If (match-beginning 3) is non-nil, that part of the item follows a ":".
1563 ;; If (match-beginning 4) is non-nil, the item is followed by a "(".
1564 (if (looking-at "[ \t*&]*\\(\\sw+\\)\\(::\\(\\sw+\\)\\)?[ \t]*\\((\\)?")
1565 (save-match-data
1566 (condition-case nil
1567 (save-restriction
1568 ;; Restrict to the end of line, currently guaranteed to be LIMIT.
1569 (narrow-to-region (point-min) limit)
1570 (goto-char (match-end 1))
1571 ;; Move over any item value, etc., to the next item.
1572 (while (not (looking-at "[ \t]*\\(\\(,\\)\\|;\\|$\\)"))
1573 (goto-char (or (scan-sexps (point) 1) (point-max))))
1574 (goto-char (match-end 2)))
1575 (error t)))))
1576 1684
1577(let ((c-keywords 1685(let ((c-keywords
1578; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while") 1686; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while")
@@ -1581,40 +1689,27 @@ the face is also set; its value is the face name."
1581; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum" 1689; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum"
1582; "signed" "unsigned" "short" "long" "int" "char" "float" "double" 1690; "signed" "unsigned" "short" "long" "int" "char" "float" "double"
1583; "void" "volatile" "const") 1691; "void" "volatile" "const")
1584 (concat "auto\\|c\\(har\\|onst\\)\\|double\\|e\\(num\\|xtern\\)\\|" 1692 (mapconcat 'identity
1585 "float\\|int\\|long\\|register\\|" 1693 (cons
1586 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|typedef\\|" 1694 (concat "auto\\|c\\(har\\|onst\\)\\|double\\|e\\(num\\|xtern\\)\\|"
1587 "un\\(ion\\|signed\\)\\|vo\\(id\\|latile\\)")) ; 6 ()s deep. 1695 "float\\|int\\|long\\|register\\|"
1588 (c++-keywords 1696 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|typedef\\|"
1589; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while" 1697 "un\\(ion\\|signed\\)\\|vo\\(id\\|latile\\)") ; 6 ()s deep.
1590; "asm" "catch" "delete" "new" "operator" "sizeof" "this" "throw" "try" 1698 c-font-lock-extra-types)
1591; "protected" "private" "public") 1699 "\\|"))
1592 (concat "asm\\|break\\|c\\(atch\\|ontinue\\)\\|d\\(elete\\|o\\)\\|"
1593 "else\\|for\\|if\\|new\\|"
1594 "p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|return\\|"
1595 "s\\(izeof\\|witch\\)\\|t\\(h\\(is\\|row\\)\\|ry\\)\\|while"))
1596 (c++-type-types
1597; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum"
1598; "signed" "unsigned" "short" "long" "int" "char" "float" "double"
1599; "void" "volatile" "const" "class" "inline" "friend" "bool"
1600; "virtual" "complex" "template")
1601 (concat "auto\\|bool\\|c\\(har\\|lass\\|o\\(mplex\\|nst\\)\\)\\|"
1602 "double\\|e\\(num\\|xtern\\)\\|f\\(loat\\|riend\\)\\|"
1603 "in\\(line\\|t\\)\\|long\\|register\\|"
1604 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|"
1605 "t\\(emplate\\|ypedef\\)\\|un\\(ion\\|signed\\)\\|"
1606 "v\\(irtual\\|o\\(id\\|latile\\)\\)")) ; 11 ()s deep.
1607 ) 1700 )
1608 (setq c-font-lock-keywords-1 1701 (setq c-font-lock-keywords-1
1609 (list 1702 (list
1610 ;; 1703 ;;
1611 ;; These are all anchored at the beginning of line for speed. 1704 ;; These are all anchored at the beginning of line for speed.
1705 ;; Note that `c++-font-lock-keywords-1' depends on `c-font-lock-keywords-1'.
1612 ;; 1706 ;;
1613 ;; Fontify function name definitions (GNU style; without type on line). 1707 ;; Fontify function name definitions (GNU style; without type on line).
1614 (list (concat "^\\(\\sw+\\)[ \t]*(") 1 'font-lock-function-name-face) 1708 (list (concat "^\\(\\sw+\\)[ \t]*(") 1 'font-lock-function-name-face)
1615 ;; 1709 ;;
1616 ;; Fontify filenames in #include <...> preprocessor directives as strings. 1710 ;; Fontify filenames in #include <...> preprocessor directives as strings.
1617 '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face) 1711 '("^#[ \t]*\\(import\\|include\\)[ \t]+\\(<[^>\"\n]+>?\\)"
1712 2 font-lock-string-face)
1618 ;; 1713 ;;
1619 ;; Fontify function macro names. 1714 ;; Fontify function macro names.
1620 '("^#[ \t]*define[ \t]+\\(\\sw+\\)(" 1 font-lock-function-name-face) 1715 '("^#[ \t]*define[ \t]+\\(\\sw+\\)(" 1 font-lock-function-name-face)
@@ -1639,12 +1734,16 @@ the face is also set; its value is the face name."
1639 (cons (concat "\\<\\(" c-type-types "\\)\\>") 'font-lock-type-face) 1734 (cons (concat "\\<\\(" c-type-types "\\)\\>") 'font-lock-type-face)
1640 ;; 1735 ;;
1641 ;; Fontify all builtin keywords (except case, default and goto; see below). 1736 ;; Fontify all builtin keywords (except case, default and goto; see below).
1642 (cons (concat "\\<\\(" c-keywords "\\)\\>") 'font-lock-keyword-face) 1737 (concat "\\<\\(" c-keywords "\\)\\>")
1643 ;; 1738 ;;
1644 ;; Fontify case/goto keywords and targets, and case default/goto tags. 1739 ;; Fontify case/goto keywords and targets, and case default/goto tags.
1645 '("\\<\\(case\\|goto\\)\\>[ \t]*\\(\\sw+\\)?" 1740 '("\\<\\(case\\|goto\\)\\>[ \t]*\\(\\sw+\\)?"
1646 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) 1741 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
1647 '("^[ \t]*\\(\\sw+\\)[ \t]*:" 1 font-lock-reference-face) 1742 ;; Anders Lindgren <andersl@csd.uu.se> points out that it is quicker to use
1743 ;; MATCH-ANCHORED to effectively anchor the regexp on the left.
1744 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:"
1745 (beginning-of-line) (end-of-line)
1746 (1 font-lock-reference-face)))
1648 ))) 1747 )))
1649 1748
1650 (setq c-font-lock-keywords-3 1749 (setq c-font-lock-keywords-3
@@ -1685,15 +1784,63 @@ the face is also set; its value is the face name."
1685 font-lock-function-name-face 1784 font-lock-function-name-face
1686 font-lock-variable-name-face)))) 1785 font-lock-variable-name-face))))
1687 ))) 1786 )))
1787 )
1788
1789(defvar c-font-lock-keywords c-font-lock-keywords-1
1790 "Default expressions to highlight in C mode.
1791See also `c-font-lock-extra-types'.")
1792
1793;;; C++.
1794
1795(defconst c++-font-lock-keywords-1 nil
1796 "Subdued level highlighting for C++ mode.")
1797
1798(defconst c++-font-lock-keywords-2 nil
1799 "Medium level highlighting for C++ mode.
1800See also `c++-font-lock-extra-types'.")
1801
1802(defconst c++-font-lock-keywords-3 nil
1803 "Gaudy level highlighting for C++ mode.
1804See also `c++-font-lock-extra-types'.")
1688 1805
1806(let ((c++-keywords
1807; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while"
1808; "asm" "catch" "delete" "new" "operator" "sizeof" "this" "throw" "try"
1809; "protected" "private" "public"
1810; ;; Eric Hopper <hopper@omnifarious.mn.org> says these are new.
1811; "static_cast" "dynamic_cast" "const_cast" "reinterpret_cast")
1812 (concat "asm\\|break\\|c\\(atch\\|on\\(st_cast\\|tinue\\)\\)\\|"
1813 "d\\(elete\\|o\\|ynamic_cast\\)\\|else\\|for\\|if\\|new\\|"
1814 "operator\\|p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|"
1815 "re\\(interpret_cast\\|turn\\)\\|s\\(izeof\\|tatic_cast\\|"
1816 "witch\\)\\|t\\(h\\(is\\|row\\)\\|ry\\)\\|while"))
1817 (c++-type-types
1818; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum"
1819; "signed" "unsigned" "short" "long" "int" "char" "float" "double"
1820; "void" "volatile" "const" "class" "inline" "friend" "bool"
1821; "virtual" "complex" "template"
1822; ;; Eric Hopper <hopper@omnifarious.mn.org> says these are new.
1823; "namespace" "using")
1824 (mapconcat 'identity
1825 (cons
1826 (concat "auto\\|bool\\|c\\(har\\|lass\\|o\\(mplex\\|nst\\)\\)\\|"
1827 "double\\|e\\(num\\|xtern\\)\\|f\\(loat\\|riend\\)\\|"
1828 "in\\(line\\|t\\)\\|long\\|namespace\\|register\\|"
1829 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|"
1830 "t\\(emplate\\|ypedef\\)\\|"
1831 "u\\(n\\(ion\\|signed\\)\\|sing\\)\\|"
1832 "v\\(irtual\\|o\\(id\\|latile\\)\\)") ; 12 ()s deep.
1833 c++-font-lock-extra-types)
1834 "\\|"))
1835 )
1689 (setq c++-font-lock-keywords-1 1836 (setq c++-font-lock-keywords-1
1690 (append 1837 (append
1691 ;; 1838 ;;
1692 ;; The list `c-font-lock-keywords-1' less that for function names. 1839 ;; The list `c-font-lock-keywords-1' less that for function names.
1693 (cdr c-font-lock-keywords-1) 1840 (cdr c-font-lock-keywords-1)
1694 ;;
1695 ;; Fontify function name definitions, possibly incorporating class name.
1696 (list 1841 (list
1842 ;;
1843 ;; Fontify function name definitions, possibly incorporating class name.
1697 '("^\\(\\sw+\\)\\(::\\(\\sw+\\)\\)?[ \t]*(" 1844 '("^\\(\\sw+\\)\\(::\\(\\sw+\\)\\)?[ \t]*("
1698 (1 (if (match-beginning 2) 1845 (1 (if (match-beginning 2)
1699 font-lock-type-face 1846 font-lock-type-face
@@ -1715,10 +1862,15 @@ the face is also set; its value is the face name."
1715 ;; Fontify case/goto keywords and targets, and case default/goto tags. 1862 ;; Fontify case/goto keywords and targets, and case default/goto tags.
1716 '("\\<\\(case\\|goto\\)\\>[ \t]*\\(\\sw+\\)?" 1863 '("\\<\\(case\\|goto\\)\\>[ \t]*\\(\\sw+\\)?"
1717 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t)) 1864 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
1718 '("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-reference-face) 1865 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:\\($\\|[^:]\\)"
1866 (beginning-of-line) (end-of-line)
1867 (1 font-lock-reference-face)))
1719 ;; 1868 ;;
1720 ;; Fontify other builtin keywords. 1869 ;; Fontify other builtin keywords.
1721 (cons (concat "\\<\\(" c++-keywords "\\)\\>") 'font-lock-keyword-face) 1870 (cons (concat "\\<\\(" c++-keywords "\\)\\>") 'font-lock-keyword-face)
1871 ;;
1872 ;; Eric Hopper <hopper@omnifarious.mn.org> says `true' and `false' are new.
1873 '("\\<\\(false\\|true\\)\\>" . font-lock-reference-face)
1722 ))) 1874 )))
1723 1875
1724 (setq c++-font-lock-keywords-3 1876 (setq c++-font-lock-keywords-3
@@ -1733,7 +1885,7 @@ the face is also set; its value is the face name."
1733 ;; Fontify each declaration item. 1885 ;; Fontify each declaration item.
1734 '(font-lock-match-c++-style-declaration-item-and-skip-to-next 1886 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
1735 ;; Start with point after all type specifiers. 1887 ;; Start with point after all type specifiers.
1736 (goto-char (or (match-beginning 13) (match-end 1))) 1888 (goto-char (or (match-beginning 14) (match-end 1)))
1737 ;; Finish with point after first type specifier. 1889 ;; Finish with point after first type specifier.
1738 (goto-char (match-end 1)) 1890 (goto-char (match-end 1))
1739 ;; Fontify as a variable or function name. 1891 ;; Fontify as a variable or function name.
@@ -1766,48 +1918,316 @@ the face is also set; its value is the face name."
1766 ))) 1918 )))
1767 ) 1919 )
1768 1920
1769(defvar c-font-lock-keywords c-font-lock-keywords-1
1770 "Default expressions to highlight in C mode.")
1771
1772(defvar c++-font-lock-keywords c++-font-lock-keywords-1 1921(defvar c++-font-lock-keywords c++-font-lock-keywords-1
1773 "Default expressions to highlight in C++ mode.") 1922 "Default expressions to highlight in C++ mode.
1923See also `c++-font-lock-extra-types'.")
1924
1925;;; Objective-C.
1926
1927(defconst objc-font-lock-keywords-1 nil
1928 "Subdued level highlighting for Objective-C mode.")
1929
1930(defconst objc-font-lock-keywords-2 nil
1931 "Medium level highlighting for Objective-C mode.
1932See also `objc-font-lock-extra-types'.")
1933
1934(defconst objc-font-lock-keywords-3 nil
1935 "Gaudy level highlighting for Objective-C mode.
1936See also `objc-font-lock-extra-types'.")
1937
1938;; Regexps written with help from Stephen Peters <speters@us.oracle.com> and
1939;; Jacques Duthen Prestataire <duthen@cegelec-red.fr>.
1940(let ((objc-keywords
1941; (make-regexp
1942; '("break" "continue" "do" "else" "for" "if" "return" "switch" "while"
1943; "sizeof" "self" "super"))
1944 (concat "break\\|continue\\|do\\|else\\|for\\|if\\|return\\|"
1945 "s\\(elf\\|izeof\\|uper\\|witch\\)\\|while"))
1946 (objc-type-types
1947 (mapconcat 'identity
1948 (cons
1949; '("auto" "extern" "register" "static" "typedef" "struct" "union"
1950; "enum" "signed" "unsigned" "short" "long" "int" "char"
1951; "float" "double" "void" "volatile" "const"
1952; "id" "oneway" "in" "out" "inout" "bycopy" "byref")
1953 (concat "auto\\|by\\(copy\\|ref\\)\\|c\\(har\\|onst\\)\\|double\\|"
1954 "e\\(num\\|xtern\\)\\|float\\|i\\([dn]\\|n\\(out\\|t\\)\\)\\|"
1955 "long\\|o\\(neway\\|ut\\)\\|register\\|s\\(hort\\|igned\\|"
1956 "t\\(atic\\|ruct\\)\\)\\|typedef\\|un\\(ion\\|signed\\)\\|"
1957 "vo\\(id\\|latile\\)")
1958 objc-font-lock-extra-types)
1959 "\\|"))
1960 )
1961 (setq objc-font-lock-keywords-1
1962 (append
1963 ;;
1964 ;; The list `c-font-lock-keywords-1' less that for function names.
1965 (cdr c-font-lock-keywords-1)
1966 (list
1967 ;;
1968 ;; Fontify compiler directives.
1969 '("@\\(\\sw+\\)\\>[ \t]*\\(\\sw+\\)?[ \t:<(]*"
1970 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)
1971 (font-lock-match-c++-style-declaration-item-and-skip-to-next nil nil
1972 (1 font-lock-function-name-face)))
1973 ;;
1974 ;; Fontify method names and arguments. Oh Lordy!
1975 ;; First, on the same line as the function declaration.
1976 '("^[+-][ \t]*\\(PRIVATE\\)?[ \t]*\\((\\([^)\n]+\\))\\)?[ \t]*\\(\\sw+\\)"
1977 (1 font-lock-type-face nil t)
1978 (3 font-lock-type-face nil t)
1979 (4 font-lock-function-name-face)
1980 ("\\=[ \t]*\\(\\sw+\\)?:[ \t]*\\((\\([^)\n]+\\))\\)?[ \t]*\\(\\sw+\\)"
1981 nil nil
1982 (1 font-lock-function-name-face nil t)
1983 (3 font-lock-type-face nil t)
1984 (4 font-lock-variable-name-face)))
1985 ;; Second, on lines following the function declaration.
1986 '(":" ("^[ \t]*\\(\\sw+\\)?:[ \t]*\\((\\([^)\n]+\\))\\)?[ \t]*\\(\\sw+\\)"
1987 (beginning-of-line) (end-of-line)
1988 (1 font-lock-function-name-face nil t)
1989 (3 font-lock-type-face nil t)
1990 (4 font-lock-variable-name-face)))
1991 )))
1774 1992
1993 (setq objc-font-lock-keywords-2
1994 (append objc-font-lock-keywords-1
1995 (list
1996 ;;
1997 ;; Simple regexps for speed.
1998 ;;
1999 ;; Fontify all type specifiers.
2000 (cons (concat "\\<\\(" objc-type-types "\\)\\>") 'font-lock-type-face)
2001 ;;
2002 ;; Fontify all builtin keywords (except case, default and goto; see below).
2003 (concat "\\<\\(" objc-keywords "\\)\\>")
2004 ;;
2005 ;; Fontify case/goto keywords and targets, and case default/goto tags.
2006 '("\\<\\(case\\|goto\\)\\>[ \t]*\\(\\sw+\\)?"
2007 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
2008 ;; Fontify tags iff sole statement on line, otherwise we detect selectors.
2009 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*$"
2010 (beginning-of-line) (end-of-line)
2011 (1 font-lock-reference-face)))
2012 ;;
2013 ;; Fontify null object pointers.
2014 '("\\<\\(Nil\\|nil\\)\\>" 1 font-lock-reference-face)
2015 )))
1775 2016
1776(defvar tex-font-lock-keywords 2017 (setq objc-font-lock-keywords-3
1777; ;; Regexps updated with help from Ulrik Dickow <dickow@nbi.dk>. 2018 (append objc-font-lock-keywords-2
1778; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}" 2019 ;;
1779; 2 font-lock-function-name-face) 2020 ;; More complicated regexps for more complete highlighting for types.
1780; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}" 2021 ;; We still have to fontify type specifiers individually, as C is so hairy.
1781; 2 font-lock-reference-face) 2022 (list
1782; ;; It seems a bit dubious to use `bold' and `italic' faces since we might 2023 ;;
1783; ;; not be able to display those fonts. 2024 ;; Fontify all storage classes and type specifiers, plus their items.
1784; ("{\\\\bf\\([^}]+\\)}" 1 'bold keep) 2025 (list (concat "\\<\\(" objc-type-types "\\)\\>"
1785; ("{\\\\\\(em\\|it\\|sl\\)\\([^}]+\\)}" 2 'italic keep) 2026 "\\([ \t*&]+\\sw+\\>\\)*")
1786; ("\\\\\\([a-zA-Z@]+\\|.\\)" . font-lock-keyword-face) 2027 ;; Fontify each declaration item.
1787; ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face keep)) 2028 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
1788 ;; Rewritten and extended for LaTeX2e by Ulrik Dickow <dickow@nbi.dk>. 2029 ;; Start with point after all type specifiers.
1789 '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}" 2030 (goto-char (or (match-beginning 2) (match-end 1)))
1790 2 font-lock-function-name-face) 2031 ;; Finish with point after first type specifier.
1791 ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}" 2032 (goto-char (match-end 1))
1792 2 font-lock-reference-face) 2033 ;; Fontify as a variable or function name.
1793 ("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face) 2034 (1 (if (match-beginning 4)
1794 "\\\\\\([a-zA-Z@]+\\|.\\)" 2035 font-lock-function-name-face
1795 ;; It seems a bit dubious to use `bold' and `italic' faces since we might 2036 font-lock-variable-name-face))))
1796 ;; not be able to display those fonts. 2037 ;;
1797 ;; LaTeX2e: \emph{This is emphasized}. 2038 ;; Fontify structures, or typedef names, plus their items.
1798 ("\\\\emph{\\([^}]+\\)}" 1 'italic keep) 2039 '("\\(}\\)[ \t*]*\\sw"
1799 ;; LaTeX2e: \textbf{This is bold}, \textit{...}, \textsl{...} 2040 (font-lock-match-c++-style-declaration-item-and-skip-to-next
1800 ("\\\\text\\(\\(bf\\)\\|it\\|sl\\){\\([^}]+\\)}" 2041 (goto-char (match-end 1)) nil
1801 3 (if (match-beginning 2) 'bold 'italic) keep) 2042 (1 (if (match-beginning 4)
1802 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for good tables. 2043 font-lock-function-name-face
1803 ("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)" 2044 font-lock-variable-name-face))))
1804 3 (if (match-beginning 2) 'bold 'italic) keep)) 2045 ;;
1805 "Default expressions to highlight in TeX modes.") 2046 ;; Fontify anything at beginning of line as a declaration or definition.
2047 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
2048 (1 font-lock-type-face)
2049 (font-lock-match-c++-style-declaration-item-and-skip-to-next
2050 (goto-char (or (match-beginning 2) (match-end 1))) nil
2051 (1 (if (match-beginning 4)
2052 font-lock-function-name-face
2053 font-lock-variable-name-face))))
2054 )))
2055 )
2056
2057(defvar objc-font-lock-keywords objc-font-lock-keywords-1
2058 "Default expressions to highlight in Objective-C mode.
2059See also `objc-font-lock-extra-types'.")
2060
2061;;; Java.
2062
2063(defconst java-font-lock-keywords-1 nil
2064 "Subdued level highlighting for Java mode.")
2065
2066(defconst java-font-lock-keywords-2 nil
2067 "Medium level highlighting for Java mode.
2068See also `java-font-lock-extra-types'.")
2069
2070(defconst java-font-lock-keywords-3 nil
2071 "Gaudy level highlighting for Java mode.
2072See also `java-font-lock-extra-types'.")
2073
2074;; Regexps written with help from Fred White <fwhite@bbn.com> and
2075;; Anders Lindgren <andersl@csd.uu.se>.
2076(let ((java-keywords
2077 (concat "\\<\\("
2078; (make-regexp
2079; '("catch" "do" "else" "super" "this" "finally" "for" "if"
2080;; ;; Anders Lindgren <andersl@csd.uu.se> says these have gone.
2081;; "cast" "byvalue" "future" "generic" "operator" "var"
2082;; "inner" "outer" "rest"
2083; "interface" "return" "switch" "throw" "try" "while")
2084 "catch\\|do\\|else\\|f\\(inally\\|or\\)\\|"
2085 "i\\(f\\|nterface\\)\\|return\\|s\\(uper\\|witch\\)\\|"
2086 "t\\(h\\(is\\|row\\)\\|ry\\)\\|while"
2087 "\\)\\>"))
2088 ;;
2089 ;; These are immediately followed by an object name.
2090 (java-minor-types
2091 (mapconcat 'identity
2092 '("boolean" "char" "byte" "short" "int" "long" "float" "double" "void")
2093 "\\|"))
2094 ;;
2095 ;; These are eventually followed by an object name.
2096 (java-major-types
2097; (make-regexp
2098; '("abstract" "const" "final" "synchronized" "transient" "static"
2099;; ;; Anders Lindgren <andersl@csd.uu.se> says this has gone.
2100;; "threadsafe"
2101; "volatile" "public" "private" "protected" "native")
2102 (concat "abstract\\|const\\|final\\|native\\|"
2103 "p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|"
2104 "s\\(tatic\\|ynchronized\\)\\|transient\\|volatile"))
2105 ;;
2106 ;; Random types immediately followed by an object name.
2107 (java-other-types
2108 (mapconcat 'identity (cons "\\sw+\\.\\sw+" java-font-lock-extra-types)
2109 "\\|"))
2110 )
2111 (setq java-font-lock-keywords-1
2112 (list
2113 ;;
2114 ;; Fontify class names.
2115 '("\\<\\(class\\)\\>[ \t]*\\(\\sw+\\)?"
2116 (1 font-lock-type-face) (2 font-lock-function-name-face nil t))
2117 ;;
2118 ;; Fontify package names in import directives.
2119 '("\\<\\(import\\|package\\)\\>[ \t]*\\(\\sw+\\)?"
2120 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
2121 ))
2122
2123 (setq java-font-lock-keywords-2
2124 (append java-font-lock-keywords-1
2125 (list
2126 ;;
2127 ;; Fontify all builtin type specifiers.
2128 (cons (concat "\\<\\(" java-minor-types "\\|" java-major-types "\\)\\>")
2129 'font-lock-type-face)
2130 ;;
2131 ;; Fontify all builtin keywords (except below).
2132 (concat "\\<\\(" java-keywords "\\)\\>")
2133 ;;
2134 ;; Fontify keywords and targets, and case default/goto tags.
2135 (list "\\<\\(break\\|case\\|continue\\|goto\\)\\>[ \t]*\\(\\sw+\\)?"
2136 '(1 font-lock-keyword-face) '(2 font-lock-reference-face nil t))
2137 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:"
2138 (beginning-of-line) (end-of-line)
2139 (1 font-lock-reference-face)))
2140 ;;
2141 ;; Fontify keywords and types; the first can be followed by a type list.
2142 (list (concat "\\<\\("
2143 "implements\\|throws\\|"
2144 "\\(extends\\|instanceof\\|new\\)"
2145 "\\)\\>[ \t]*\\(\\sw+\\)?")
2146 '(1 font-lock-keyword-face) '(3 font-lock-type-face nil t)
2147 '("\\=[ \t]*,[ \t]*\\(\\sw+\\)"
2148 (if (match-beginning 2) (goto-char (match-end 2))) nil
2149 (1 font-lock-type-face)))
2150 ;;
2151 ;; Fontify all constants.
2152 '("\\<\\(false\\|null\\|true\\)\\>" . font-lock-reference-face)
2153 ;;
2154 ;; Javadoc tags within comments.
2155 '("@\\(author\\|exception\\|return\\|see\\|version\\)\\>"
2156 (1 font-lock-reference-face prepend))
2157 '("@\\(param\\)\\>[ \t]*\\(\\sw+\\)?"
2158 (1 font-lock-reference-face prepend)
2159 (2 font-lock-variable-name-face prepend t))
2160 )))
2161
2162 (setq java-font-lock-keywords-3
2163 (append java-font-lock-keywords-2
2164 ;;
2165 ;; More complicated regexps for more complete highlighting for types.
2166 ;; We still have to fontify type specifiers individually, as Java is hairy.
2167 (list
2168 ;;
2169 ;; Fontify random types in casts.
2170 (list (concat "(\\(" java-other-types "\\))"
2171 "[ \t]*\\(\\sw\\|[\"\(]\\)")
2172 ;; Fontify the type name.
2173 '(1 font-lock-type-face))
2174 ;;
2175 ;; Fontify random types immediately followed by an item or items.
2176 (list (concat "\\<\\(" java-other-types "\\)\\>"
2177 "\\([ \t]*\\[[ \t]*\\]\\)*"
2178 "[ \t]*\\sw")
2179 ;; Fontify the type name.
2180 '(1 font-lock-type-face))
2181 (list (concat "\\<\\(" java-other-types "\\)\\>"
2182 "\\([ \t]*\\[[ \t]*\\]\\)*"
2183 "\\([ \t]*\\sw\\)")
2184 ;; Fontify each declaration item.
2185 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
2186 ;; Start and finish with point after the type specifier.
2187 (goto-char (match-beginning 3)) (goto-char (match-beginning 3))
2188 ;; Fontify as a variable or function name.
2189 (1 (if (match-beginning 4)
2190 font-lock-function-name-face
2191 font-lock-variable-name-face))))
2192 ;;
2193 ;; Fontify those that are immediately followed by an item or items.
2194 (list (concat "\\<\\(" java-minor-types "\\)\\>"
2195 "\\([ \t]*\\[[ \t]*\\]\\)*")
2196 ;; Fontify each declaration item.
2197 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
2198 ;; Start and finish with point after the type specifier.
2199 nil (goto-char (match-end 0))
2200 ;; Fontify as a variable or function name.
2201 (1 (if (match-beginning 4)
2202 font-lock-function-name-face
2203 font-lock-variable-name-face))))
2204 ;;
2205 ;; Fontify those that are eventually followed by an item or items.
2206 (list (concat "\\<\\(" java-major-types "\\)\\>"
2207 "\\([ \t]+\\sw+\\>"
2208 "\\([ \t]*\\[[ \t]*\\]\\)*"
2209 "\\)*")
2210 ;; Fontify each declaration item.
2211 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
2212 ;; Start with point after all type specifiers.
2213 (goto-char (or (match-beginning 2) (match-end 1)))
2214 ;; Finish with point after first type specifier.
2215 (goto-char (match-end 1))
2216 ;; Fontify as a variable or function name.
2217 (1 (if (match-beginning 4)
2218 font-lock-function-name-face
2219 font-lock-variable-name-face))))
2220 )))
2221 )
2222
2223(defvar java-font-lock-keywords java-font-lock-keywords-1
2224 "Default expressions to highlight in Java mode.
2225See also `java-font-lock-extra-types'.")
1806 2226
1807;; Install ourselves: 2227;; Install ourselves:
1808 2228
1809(unless (assq 'font-lock-mode minor-mode-alist) 2229(unless (assq 'font-lock-mode minor-mode-alist)
1810 (setq minor-mode-alist (cons '(font-lock-mode " Font") minor-mode-alist))) 2230 (push '(font-lock-mode " Font") minor-mode-alist))
1811 2231
1812;; Provide ourselves: 2232;; Provide ourselves:
1813 2233