Initial Commit
[packages] / xemacs-packages / ocaml / caml-font.el
1 ;; useful colors
2
3 (cond
4  ((x-display-color-p)
5   (cond
6    ((not (memq 'font-lock-type-face (face-list)))
7     ; make the necessary faces
8     (make-face 'Firebrick)
9     (set-face-foreground 'Firebrick "Firebrick")
10     (make-face 'RosyBrown)
11     (set-face-foreground 'RosyBrown "RosyBrown")
12     (make-face 'Purple)
13     (set-face-foreground 'Purple "Purple")
14     (make-face 'MidnightBlue)
15     (set-face-foreground 'MidnightBlue "MidnightBlue")
16     (make-face 'DarkGoldenRod)
17     (set-face-foreground 'DarkGoldenRod "DarkGoldenRod")
18     (make-face 'DarkOliveGreen)
19     (set-face-foreground 'DarkOliveGreen "DarkOliveGreen4")
20     (make-face 'CadetBlue)
21     (set-face-foreground 'CadetBlue "CadetBlue")
22     ; assign them as standard faces
23     (setq font-lock-comment-face 'Firebrick)
24     (setq font-lock-string-face 'RosyBrown)
25     (setq font-lock-keyword-face 'Purple)
26     (setq font-lock-function-name-face 'MidnightBlue)
27     (setq font-lock-variable-name-face 'DarkGoldenRod)
28     (setq font-lock-type-face 'DarkOliveGreen)
29     (setq font-lock-reference-face 'CadetBlue)))
30   ; extra faces for documention
31   (make-face 'font-lock-stop-face)
32   (set-face-foreground 'font-lock-stop-face "White")
33   (set-face-background 'font-lock-stop-face "Red")
34   (make-face 'font-lock-doccomment-face)
35   (set-face-foreground 'font-lock-doccomment-face "Red")
36 ))
37
38 ; The same definition is in caml.el:
39 ; we don't know in which order they will be loaded.
40 (defvar caml-quote-char "'"
41   "*Quote for character constants. \"'\" for Objective Caml, \"`\" for Caml-Light.")
42
43 (defconst caml-font-lock-keywords
44   (list
45 ;stop special comments
46    '("\\(^\\|[^\"]\\)\\((\\*\\*/\\*\\*)\\)"
47      2 font-lock-stop-face)
48 ;doccomments
49    '("\\(^\\|[^\"]\\)\\((\\*\\*[^*]*\\([^)*][^*]*\\*+\\)*)\\)"
50      2 font-lock-doccomment-face)
51 ;comments
52    '("\\(^\\|[^\"]\\)\\((\\*[^*]*\\*+\\([^)*][^*]*\\*+\\)*)\\)"
53      2 font-lock-comment-face)
54 ;character literals
55    (cons (concat caml-quote-char "\\(\\\\\\([ntbr" caml-quote-char "\\]\\|"
56                  "[0-9][0-9][0-9]\\)\\|.\\)" caml-quote-char
57                  "\\|\"[^\"\\]*\\(\\\\\\(.\\|\n\\)[^\"\\]*\\)*\"")
58          'font-lock-string-face)
59 ;modules and constructors
60    '("`?\\<[A-Z][A-Za-z0-9_']*\\>" . font-lock-function-name-face)
61 ;definition
62    (cons (concat
63           "\\<\\(a\\(nd\\|s\\)\\|c\\(onstraint\\|lass\\)"
64           "\\|ex\\(ception\\|ternal\\)\\|fun\\(ct\\(ion\\|or\\)\\)?"
65           "\\|in\\(herit\\|itializer\\)?\\|let"
66           "\\|m\\(ethod\\|utable\\|odule\\)"
67           "\\|of\\|p\\(arser\\|rivate\\)\\|rec\\|type"
68           "\\|v\\(al\\(ue\\)?\\|irtual\\)\\)\\>")
69          'font-lock-type-face)
70 ;blocking
71    '("\\<\\(begin\\|end\\|object\\|s\\(ig\\|truct\\)\\)\\>"
72      . font-lock-keyword-face)
73 ;control
74    (cons (concat
75           "\\<\\(do\\(ne\\|wnto\\)?\\|else\\|for\\|i\\(f\\|gnore\\)"
76           "\\|lazy\\|match\\|new\\|or\\|t\\(hen\\|o\\|ry\\)"
77           "\\|w\\(h\\(en\\|ile\\)\\|ith\\)\\)\\>"
78           "\\|\|\\|->\\|&\\|#")
79          'font-lock-reference-face)
80    '("\\<raise\\>" . font-lock-comment-face)
81 ;labels (and open)
82    '("\\(\\([~?]\\|\\<\\)[a-z][a-zA-Z0-9_']*:\\)[^:=]" 1
83      font-lock-variable-name-face)
84    '("\\<\\(assert\\|open\\|include\\)\\>\\|[~?][ (]*[a-z][a-zA-Z0-9_']*"
85      . font-lock-variable-name-face)))
86
87 (defconst inferior-caml-font-lock-keywords
88   (append
89    (list
90 ;inferior
91     '("^[#-]" . font-lock-comment-face))
92    caml-font-lock-keywords))
93
94 ;; font-lock commands are similar for caml-mode and inferior-caml-mode
95 (setq caml-mode-hook
96       '(lambda ()
97          (cond
98           ((fboundp 'global-font-lock-mode)
99            (make-local-variable 'font-lock-defaults)
100            (setq font-lock-defaults
101                  '(caml-font-lock-keywords nil nil ((?' . "w") (?_ . "w")))))
102           (t
103            (setq font-lock-keywords caml-font-lock-keywords)))
104          (make-local-variable 'font-lock-keywords-only)
105          (setq font-lock-keywords-only t)
106          (font-lock-mode 1)))
107
108 (defun inferior-caml-mode-font-hook ()
109   (cond
110    ((fboundp 'global-font-lock-mode)
111     (make-local-variable 'font-lock-defaults)
112     (setq font-lock-defaults
113           '(inferior-caml-font-lock-keywords
114             nil nil ((?' . "w") (?_ . "w")))))
115    (t
116     (setq font-lock-keywords inferior-caml-font-lock-keywords)))
117   (make-local-variable 'font-lock-keywords-only)
118   (setq font-lock-keywords-only t)
119   (font-lock-mode 1))
120
121 (add-hook 'inferior-caml-mode-hooks 'inferior-caml-mode-font-hook)
122
123 (provide 'caml-font)