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