forked from kmroz/rmoo
-
Notifications
You must be signed in to change notification settings - Fork 5
/
coldc-mode.el
238 lines (197 loc) · 6.02 KB
/
coldc-mode.el
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
;;; coldc-mode.el by Jeremy Weatherford, no rights reserved
;; basically stolen from php-mode.el by Turadg Aleahmad
;; with very minor mods
(defgroup coldc nil
"Major mode for editing ColdC code."
:prefix "coldc-"
:group 'languages)
(defcustom coldc-file-patterns (list "\\.coldc\\'" "textdump\\'" "\\.cdc\\'")
"*List of file patterns for which to automatically invoke coldc-mode."
:type '(repeat (regexp :tag "Pattern"))
:group 'coldc)
(defcustom coldc-mode-user-hook nil
"List of functions to be executed on entry to coldc-mode"
:type 'hook
:group 'coldc)
;; Note whether we're in XEmacs
(defconst xemacsp (string-match "Lucid\\|XEmacs" emacs-version)
"Non nil if using XEmacs.")
;; Keymap
(defvar coldc-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-j" 'newline-and-indent)
(define-key map (kbd "C-c c") 'rmoo-upload-and-destroy)
(define-key map (kbd "C-c s") 'rmoo-upload-buffer-directly)
(define-key map (kbd "<f7>") 'rmoo-upload-buffer-directly)
(define-key map (kbd "<f8>") 'rmoo-resize-editor-frame)
(define-key map (kbd "C-c ]") 'rmoo-destroy)
(define-key map (kbd "C-c C-c") 'rmoo-code-commentify)
(define-key map (kbd "C-c C-u") 'rmoo-code-uncommentify)
map)
"Keymap for ColdC major mode.")
;;;###autoload
(define-derived-mode coldc-mode c-mode "ColdC"
"Major mode for editing ColdC code.\n\n{coldc-mode-map}"
(use-local-map coldc-mode-map)
(setq comment-start "// "
comment-end "")
; comment-start-skip "// *")
(defvar coldc-mode-syntax-table coldc-mode-syntax-table)
;; single-quote considered part of word
(modify-syntax-entry ?' "w" coldc-mode-syntax-table)
(modify-syntax-entry ?_ "w" coldc-mode-syntax-table)
;; dollar-sign considered punctuation, not part of word
;(modify-syntax-entry ?$ "." coldc-mode-syntax-table)
(make-local-variable 'font-lock-defaults)
(setq font-lock-defaults
'((coldc-font-lock-keywords-1
coldc-font-lock-keywords-2
;; Comment-out the next line if the font-coloring is too
;; extreme/ugly for you.
coldc-font-lock-keywords-3
)
nil ; KEYWORDS-ONLY
T ; CASE-FOLD
nil ; SYNTAX-ALIST
nil ; SYNTAX-BEGIN
(font-lock-syntactic-keywords . coldc-font-lock-syntactic-keywords)))
(setq font-lock-maximum-decoration t
case-fold-search t) ; ColdC vars are case-sensitive
; imenu-generic-expression cc-imenu-coldc-generic-expression)
;; Do not force newline at end of file. Such newlines can cause
;; trouble if the ColdC file is included in another file before calls
;; to header() or cookie().
(set (make-local-variable 'require-final-newline) nil)
(set (make-local-variable 'next-line-add-newlines) nil)
;; personal preference
(set (make-local-variable 'tab-width) 4)
(set (make-local-variable 'c-basic-offset) 4)
(set (make-local-variable 'indent-tabs-mode) nil)
(run-hooks 'coldc-mode-user-hook)
)
;; Make coldc-mode the default mode for ColdC source code buffers.
;;;###autoload
(let ((coldc-file-patterns-temp coldc-file-patterns))
(while coldc-file-patterns-temp
(setq auto-mode-alist
(cons
(cons (car coldc-file-patterns-temp) 'coldc-mode)
auto-mode-alist)
)
(setq coldc-file-patterns-temp (cdr coldc-file-patterns-temp))))
(defconst coldc-constants
(eval-when-compile
(regexp-opt
'(;; core constants
; umm... none in ColdC?
) t))
"ColdC constants.")
(defconst coldc-keywords
(eval-when-compile
(regexp-opt
'(
; straight from token.c
"any"
"arg"
"break"
"case"
"catch"
"continue"
"default"
"disallow_overrides"
"else"
"filter"
"find"
"for"
"fork"
"handler"
"hash"
"if"
"in"
"map"
"pass"
"return"
"switch"
"to"
"var"
"where"
"while"
"with"
; hackish, but eh
"public method"
"protected method"
"private method"
"root method"
"driver method"
"frob method"
) t))
"ColdC keywords.")
(defconst coldc-identifier
(eval-when-compile
'"[a-zA-Z\_][a-zA-Z0-9\_]*")
"Characters in a ColdC identifier.")
; not sure what we'll do with these
(defconst coldc-types
(eval-when-compile
(regexp-opt '("integer" "float" "string" "objnum" "list" "symbol"
"error" "frob" "dictionary" "buffer")
t))
"ColdC types.")
;; Set up font locking
(defconst coldc-font-lock-keywords-1
(list
;; symbols
(cons
"'[a-zA-Z0-9\_]+"
'font-lock-type-face)
;; errors
(cons
"~[a-zA-Z0-9\_]+"
'font-lock-warning-face)
;; object refs
(cons
"\\$[a-zA-Z][a-zA-Z0-9\_]*"
'font-lock-constant-face)
;; Fontify constants
(cons
(concat "\\<\\(" coldc-constants "\\)\\>")
'font-lock-constant-face)
;; Fontify keywords
(cons
(concat "\\<\\(" coldc-keywords "\\)\\>")
'font-lock-keyword-face)
;; Fontify keywords and targets, and case default/goto tags.
(list "\\<\\(break\\|case\\|continue\\)\\>[ \t]*\\(-?\\sw+\\)?"
'(1 font-lock-keyword-face) '(2 font-lock-constant-face t t))
;; This must come after the one for keywords and targets.
'(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*$"
(beginning-of-line) (end-of-line)
(1 font-lock-constant-face))))
"Subdued level highlighting for ColdC mode.")
(defconst coldc-font-lock-keywords-2
(append
coldc-font-lock-keywords-1
(list
))
; could be expanded
"Medium level highlighting for ColdC mode.")
(defconst coldc-font-lock-keywords-3
(append
coldc-font-lock-keywords-2
(list
))
; could also use some expansion
"Gauchy level highlighting for ColdC mode.")
; todo?
(defconst coldc-font-lock-syntactic-keywords nil)
;; Create "default" symbol for GNU Emacs so that both Xemacs and GNU
;; emacs can refer to the default face by a variable named "default".
(unless (boundp 'default)
(defvar default 'default))
;; Create faces for XEmacs
(unless (boundp 'font-lock-keyword-face)
(copy-face 'bold 'font-lock-keyword-face))
(unless (boundp 'font-lock-constant-face)
(copy-face 'font-lock-keyword-face 'font-lock-constant-face))
(provide 'coldc-mode)
;;; coldc-mode.el ends here