1 ;(***********************************************************************)
5 ;(* Jacques Garrigue and Ian T Zimmerman *)
7 ;(* Copyright 1997 Institut National de Recherche en Informatique et *)
8 ;(* en Automatique. All rights reserved. This file is distributed *)
9 ;(* under the terms of the GNU General Public License. *)
11 ;(***********************************************************************)
13 ;(* $Id: caml-font.el,v 1.18.2.1 2004/08/09 16:09:33 doligez Exp $ *)
21 ((not (boundp 'font-lock-type-face
))
22 ; make the necessary faces
23 (make-face 'Firebrick
)
24 (set-face-foreground 'Firebrick
"Firebrick")
25 (make-face 'RosyBrown
)
26 (set-face-foreground 'RosyBrown
"RosyBrown")
28 (set-face-foreground 'Purple
"Purple")
29 (make-face 'MidnightBlue
)
30 (set-face-foreground 'MidnightBlue
"MidnightBlue")
31 (make-face 'DarkGoldenRod
)
32 (set-face-foreground 'DarkGoldenRod
"DarkGoldenRod")
33 (make-face 'DarkOliveGreen
)
34 (set-face-foreground 'DarkOliveGreen
"DarkOliveGreen4")
35 (make-face 'CadetBlue
)
36 (set-face-foreground 'CadetBlue
"CadetBlue")
37 ; assign them as standard faces
38 (setq font-lock-comment-face
'Firebrick
)
39 (setq font-lock-string-face
'RosyBrown
)
40 (setq font-lock-keyword-face
'Purple
)
41 (setq font-lock-function-name-face
'MidnightBlue
)
42 (setq font-lock-variable-name-face
'DarkGoldenRod
)
43 (setq font-lock-type-face
'DarkOliveGreen
)
44 (setq font-lock-reference-face
'CadetBlue
)))
45 ; extra faces for documention
47 (set-face-foreground 'Stop
"White")
48 (set-face-background 'Stop
"Red")
50 (set-face-foreground 'Doc
"Red")
51 (setq font-lock-stop-face
'Stop
)
52 (setq font-lock-doccomment-face
'Doc
)
55 ; The same definition is in caml.el:
56 ; we don't know in which order they will be loaded.
57 (defvar caml-quote-char
"'"
58 "*Quote for character constants. \"'\" for Objective Caml, \"`\" for Caml-Light.")
60 (defconst caml-font-lock-keywords
62 ;stop special comments
63 '("\\(^\\|[^\"]\\)\\((\\*\\*/\\*\\*)\\)"
64 2 font-lock-stop-face
)
66 '("\\(^\\|[^\"]\\)\\((\\*\\*[^*]*\\([^)*][^*]*\\*+\\)*)\\)"
67 2 font-lock-doccomment-face
)
69 '("\\(^\\|[^\"]\\)\\((\\*[^*]*\\*+\\([^)*][^*]*\\*+\\)*)\\)"
70 2 font-lock-comment-face
)
72 (cons (concat caml-quote-char
"\\(\\\\\\([ntbr" caml-quote-char
"\\]\\|"
73 "[0-9][0-9][0-9]\\)\\|.\\)" caml-quote-char
74 "\\|\"[^\"\\]*\\(\\\\\\(.\\|\n\\)[^\"\\]*\\)*\"")
75 'font-lock-string-face
)
76 ;modules and constructors
77 '("`?\\<[A-Z][A-Za-z0-9_']*\\>" . font-lock-function-name-face
)
80 "\\<\\(a\\(nd\\|s\\)\\|c\\(onstraint\\|lass\\)"
81 "\\|ex\\(ception\\|ternal\\)\\|fun\\(ct\\(ion\\|or\\)\\)?"
82 "\\|in\\(herit\\|itializer\\)?\\|let"
83 "\\|m\\(ethod\\|utable\\|odule\\)"
84 "\\|of\\|p\\(arser\\|rivate\\)\\|rec\\|type"
85 "\\|v\\(al\\|irtual\\)\\)\\>")
88 '("\\<\\(begin\\|end\\|object\\|s\\(ig\\|truct\\)\\)\\>"
89 . font-lock-keyword-face
)
92 "\\<\\(do\\(ne\\|wnto\\)?\\|else\\|for\\|i\\(f\\|gnore\\)"
93 "\\|lazy\\|match\\|new\\|or\\|t\\(hen\\|o\\|ry\\)"
94 "\\|w\\(h\\(en\\|ile\\)\\|ith\\)\\)\\>"
96 'font-lock-reference-face
)
97 '("\\<raise\\>" . font-lock-comment-face
)
99 '("\\(\\([~?]\\|\\<\\)[a-z][a-zA-Z0-9_']*:\\)[^:=]" 1
100 font-lock-variable-name-face
)
101 '("\\<\\(assert\\|open\\|include\\)\\>\\|[~?][ (]*[a-z][a-zA-Z0-9_']*"
102 . font-lock-variable-name-face
)))
104 (defconst inferior-caml-font-lock-keywords
108 '("^[#-]" . font-lock-comment-face
))
109 caml-font-lock-keywords
))
111 ;; font-lock commands are similar for caml-mode and inferior-caml-mode
112 (add-hook 'caml-mode-hook
115 ((fboundp 'global-font-lock-mode
)
116 (make-local-variable 'font-lock-defaults
)
117 (setq font-lock-defaults
118 '(caml-font-lock-keywords nil nil
((?
' .
"w") (?_ .
"w")))))
120 (setq font-lock-keywords caml-font-lock-keywords
)))
121 (make-local-variable 'font-lock-keywords-only
)
122 (setq font-lock-keywords-only t
)
125 (defun inferior-caml-mode-font-hook ()
127 ((fboundp 'global-font-lock-mode
)
128 (make-local-variable 'font-lock-defaults
)
129 (setq font-lock-defaults
130 '(inferior-caml-font-lock-keywords
131 nil nil
((?
' .
"w") (?_ .
"w")))))
133 (setq font-lock-keywords inferior-caml-font-lock-keywords
)))
134 (make-local-variable 'font-lock-keywords-only
)
135 (setq font-lock-keywords-only t
)
138 (add-hook 'inferior-caml-mode-hooks
'inferior-caml-mode-font-hook
)