-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfsharp-font.el
More file actions
253 lines (227 loc) · 10.4 KB
/
fsharp-font.el
File metadata and controls
253 lines (227 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
;(***********************************************************************)
;(* *)
;(* Objective Caml *)
;(* *)
;(* Jacques Garrigue and Ian T Zimmerman *)
;(* *)
;(* Copyright 1997 Institut National de Recherche en Informatique et *)
;(* en Automatique. All rights reserved. This file is distributed *)
;(* under the terms of the GNU General Public License. *)
;(* *)
;(***********************************************************************)
;(* $Id: fsharp-font.el,v 1.19 2004/08/20 17:04:35 doligez Exp $ *)
;; useful colors
(cond
((x-display-color-p)
(require 'font-lock)
(cond
((not (boundp 'font-lock-type-face))
;; make the necessary faces
(make-face 'Firebrick)
(set-face-foreground 'Firebrick "firebrick")
(make-face 'RosyBrown)
(set-face-foreground 'RosyBrown "RosyBrown")
(make-face 'Purple)
(set-face-foreground 'Purple "Purple")
(make-face 'MidnightBlue)
(set-face-foreground 'MidnightBlue "MidnightBlue")
(make-face 'DarkGoldenRod)
(set-face-foreground 'DarkGoldenRod "DarkGoldenRod")
(make-face 'DarkOliveGreen)
(set-face-foreground 'DarkOliveGreen "DarkOliveGreen4")
(make-face 'CadetBlue)
(set-face-foreground 'CadetBlue "CadetBlue")
; assign them as standard faces
(setq font-lock-comment-face 'Firebrick)
(setq font-lock-string-face 'RosyBrown)
(setq font-lock-keyword-face 'Purple)
(setq font-lock-function-name-face 'MidnightBlue)
(setq font-lock-variable-name-face 'DarkGoldenRod)
(setq font-lock-type-face 'DarkOliveGreen)
(setq font-lock-constant-face 'CadetBlue)))
; extra faces for documention
(make-face 'Stop)
(set-face-foreground 'Stop "White")
(set-face-background 'Stop "Red")
(make-face 'Doc)
(set-face-foreground 'Doc "Red")
(setq font-lock-stop-face 'Stop)
(setq font-lock-doccomment-face 'Doc)
))
(defconst fsharp-access-control-regexp
"\\(?:private\\s-+\\|internal\\s-+\\|public\\s-+\\)*")
(defconst fsharp-function-def-regexp
"\\<\\(?:let\\|and\\|with\\)\\s-+\\(?:\\(?:inline\\|rec\\)\\s-+\\)?\\([A-Za-z0-9_']+\\)\\(?:\\s-+[A-Za-z_]\\|\\s-*(\\)")
(defconst fsharp-pattern-function-regexp
"\\<\\(?:let\\|and\\)\\s-+\\(?:\\(?:inline\\|rec\\)\\s-+\\)?\\([A-Za-z0-9_']+\\)\\s-*=\\s-*function")
(defconst fsharp-active-pattern-regexp
"\\<\\(?:let\\|and\\)\\s-+\\(?:\\(?:inline\\|rec\\)\\s-+\\)?(\\(|[A-Za-z0-9_'|]+|\\))\\(?:\\s-+[A-Za-z_]\\|\\s-*(\\)")
(defconst fsharp-member-function-regexp
"\\<\\(?:override\\|member\\|abstract\\)\\s-+\\(?:\\(?:inline\\|rec\\)\\s-+\\)?\\(?:[A-Za-z0-9_']+\\.\\)?\\([A-Za-z0-9_']+\\)")
(defconst fsharp-overload-operator-regexp
"\\<\\(?:override\\|member\\|abstract\\)\\s-+\\(?:\\(?:inline\\|rec\\)\\s-+\\)?\\(([!%&*+-./<=>?@^|~]+)\\)")
(defconst fsharp-constructor-regexp "^\\s-*\\<\\(new\\) *(.*)[^=]*=")
(defconst fsharp-type-def-regexp
(format "^\\s-*\\<\\(?:type\\|inherit\\)\\s-+%s\\([A-Za-z0-9_'.]+\\)"
fsharp-access-control-regexp))
(defconst fsharp-var-or-arg-regexp "\\<\\([A-Za-z_][A-Za-z0-9_']*\\)\\>")
(defconst fsharp-explicit-field-regexp
(format "^\\s-*\\(?:val\\|abstract\\)\\s-*\\(?:mutable\\s-+\\)?%s\\([A-Za-z_][A-Za-z0-9_']*\\)\\s-*:\\s-*\\([A-Za-z_][A-Za-z0-9_'<> \t]*\\)" fsharp-access-control-regexp))
(defvar fsharp-imenu-generic-expression
`((nil ,(concat "^\\s-*" fsharp-function-def-regexp) 1)
(nil ,(concat "^\\s-*" fsharp-pattern-function-regexp) 1)
(nil ,(concat "^\\s-*" fsharp-active-pattern-regexp) 1)
(nil ,(concat "^\\s-*" fsharp-member-function-regexp) 1)
(nil ,(concat "^\\s-*" fsharp-overload-operator-regexp) 1)
(nil ,fsharp-constructor-regexp 1)
(nil ,fsharp-type-def-regexp 1)
))
(defvar fsharp-var-pre-form
(lambda ()
(save-excursion
(re-search-forward "\\(:\\s-*\\w[^)]*\\)?=")
(match-beginning 0))))
(defvar fsharp-fun-pre-form
(lambda ()
(save-excursion
(search-forward "->"))))
(defconst fsharp-font-lock-keywords
(list
;stop special comments
'("\\(^\\|[^\"]\\)\\((\\*\\*/\\*\\*)\\)"
2 font-lock-stop-face)
;doccomments
'("\\(^\\|[^\"]\\)\\((\\*\\*[^*]*\\([^)*][^*]*\\*+\\)*)\\)"
2 font-lock-doccomment-face)
;comments
'("\\(^\\|[^\"]\\)\\((\\*[^*]*\\*+\\([^)*][^*]*\\*+\\)*)\\)"
2 font-lock-comment-face)
;; '("(\\*IF-OCAML\\([^)*][^*]*\\*+\\)+ENDIF-OCAML\\*)"
;; 2 font-lock-comment-face)
;; '("\\(^\\|[^\"]\\)\\((\\*[^F]\\([^)*][^*]*\\*+\\)+)\\)"
;; . font-lock-comment-face)
; '("(\\*.*\\*)\\|(\\*.*\n.*\\*)"
; . font-lock-comment-face)
;character literals
(cons (concat "'\\(\\\\\\([ntbr'\\]\\|"
"[0-9][0-9][0-9]\\)\\|.\\)'"
"\\|\"[^\"\\]*\\(\\\\\\(.\\|\n\\)[^\"\\]*\\)*\"")
'font-lock-string-face)
'("//.*" . font-lock-comment-face)
;modules and constructors
;; '("`?\\<[A-Z][A-Za-z0-9_']*\\>" . font-lock-function-name-face)
;definition
(cons (concat "\\(\\<"
(mapconcat 'identity
'(
;; F# keywords
"abstract" "and" "as" "assert" "base" "begin"
"class" "default" "delegate" "do" "done" "downcast"
"downto" "elif" "else" "end" "exception" "extern"
"false" "finally" "for" "fun" "function" "global"
"if" "in" "inherit" "inline" "interface" "internal"
"lazy" "let" "match" "member" "module" "mutable"
"namespace" "new" "null" "of" "open" "or" "override"
"private" "public" "rec" "return" "sig" "static"
"struct" "then" "to" "true" "try" "type" "upcast"
"use" "val" "void" "when" "while" "with" "yield"
;; F# reserved words for future use
"atomic" "break" "checked" "component" "const"
"constraint" "constructor" "continue" "eager"
"fixed" "fori" "functor" "include" "measure"
"method" "mixin" "object" "parallel" "params"
"process" "protected" "pure" "recursive" "sealed"
"tailcall" "trait" "virtual" "volatile"
)
"\\>\\|\\<")
"\\>\\)")
'font-lock-keyword-face)
;blocking
;; '("\\<\\(begin\\|end\\|module\\|namespace\\|object\\|sig\\|struct\\)\\>"
;; . font-lock-keyword-face)
;control
;; attributes
'("\\[<[A-Za-z0-9_]+>\\]" . font-lock-preprocessor-face)
;; type defines
`(,fsharp-type-def-regexp 1 font-lock-type-face)
`(,fsharp-function-def-regexp 1 font-lock-function-name-face)
`(,fsharp-pattern-function-regexp 1 font-lock-function-name-face)
`(,fsharp-active-pattern-regexp 1 font-lock-function-name-face)
`(,fsharp-member-function-regexp 1 font-lock-function-name-face)
`(,fsharp-overload-operator-regexp 1 font-lock-function-name-face)
;; `(,fsharp-constructor-regexp 1 font-lock-function-name-face)
`("[^:]:\\s-*\\(\\<[A-Za-z_'][^,)=<-]*\\)\\s-*\\(<[^>]*>\\)?"
(1 font-lock-type-face) ; type annotations
;; HACK: font-lock-negation-char-face is usually the same as
;; 'default'. use this to prevent generic type arguments from
;; being rendered in variable face
(2 font-lock-negation-char-face nil t))
`(,(format "^\\s-*\\<\\(let\\|use\\|override\\|member\\|and\\|\\(?:%snew\\)\\)\\>"
fsharp-access-control-regexp)
(0 font-lock-keyword-face) ; let binding and function arguments
(,fsharp-var-or-arg-regexp
(,fsharp-var-pre-form) nil
(1 font-lock-variable-name-face nil t)))
`("\\<fun\\>"
(0 font-lock-keyword-face) ; lambda function arguments
(,fsharp-var-or-arg-regexp
(,fsharp-fun-pre-form) nil
(1 font-lock-variable-name-face nil t)))
`(,fsharp-type-def-regexp
(0 font-lock-keyword-face) ; implicit constructor arguments
(,fsharp-var-or-arg-regexp
(,fsharp-var-pre-form) nil
(1 font-lock-variable-name-face nil t)))
`(,fsharp-explicit-field-regexp
(1 font-lock-variable-name-face)
(2 font-lock-type-face))
;; open namespace
'("\\<open\s\\([A-Za-z0-9_.]+\\)" 1 font-lock-type-face)
;; module/namespace
'("\\<\\(?:module\\|namespace\\)\s\\([A-Za-z0-9_.]+\\)" 1 font-lock-type-face)
;labels (and open)
'("\\<\\(assert\\|open\\|include\\|module\\|namespace\\|extern\\|void\\)\\>\\|[~?][ (]*[a-z][a-zA-Z0-9_']*"
. font-lock-variable-name-face)
;; (cons (concat
;; "\\<\\(asr\\|false\\|land\\|lor\\|lsl\\|lsr\\|lxor"
;; "\\|mod\\|new\\|null\\|object\\|or\\|sig\\|true\\)\\>"
;; "\\|\|\\|->\\|&\\|#")
;; 'font-lock-constant-face)
))
(defconst inferior-fsharp-font-lock-keywords
(append
(list
;inferior
'("^[#-]" . font-lock-comment-face)
'("^>" . font-lock-variable-name-face))
fsharp-font-lock-keywords))
;; font-lock commands are similar for fsharp-mode and inferior-fsharp-mode
(add-hook 'fsharp-mode-hook
'(lambda ()
(cond
((fboundp 'global-font-lock-mode)
(make-local-variable 'font-lock-defaults)
(setq font-lock-defaults
'(fsharp-font-lock-keywords nil nil ((?' . "w") (?_ . "w")))))
(t
(setq font-lock-keywords fsharp-font-lock-keywords)))
(make-local-variable 'font-lock-keywords-only)
(setq font-lock-keywords-only t)
(font-lock-mode 1)
(set (make-local-variable 'imenu-generic-expression)
fsharp-imenu-generic-expression)
))
(defun inferior-fsharp-mode-font-hook ()
(cond
((fboundp 'global-font-lock-mode)
(make-local-variable 'font-lock-defaults)
(setq font-lock-defaults
'(inferior-fsharp-font-lock-keywords
nil nil ((?' . "w") (?_ . "w")))))
(t
(setq font-lock-keywords inferior-fsharp-font-lock-keywords)))
(make-local-variable 'font-lock-keywords-only)
(setq font-lock-keywords-only t)
(font-lock-mode 1))
;; (add-hook 'inferior-fsharp-mode-hooks 'inferior-fsharp-mode-font-hook)
(provide 'fsharp-font)