summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-07-29 01:05:17 -0300
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-07-29 01:07:57 -0300
commitc9f24bb5587b9c0862bed35e262f32b4e088adac (patch)
treed48c5472bc05ec7da924273ef79525f8e80ac61c
parent3a9d43ff3131147b43af5c2ff7f6436cefe31bdc (diff)
eo-mode.el for emacs.
This major mode provides colored output, that helps a lot to view and edit ".eo" and ".eot" files. It's the first version, I still see some indenting issues with toplevel blocks such as struct and enums. Nonetheless it's much more useful than fundamental-mode (pure text).
-rw-r--r--data/eo/eo-mode.el396
1 files changed, 396 insertions, 0 deletions
diff --git a/data/eo/eo-mode.el b/data/eo/eo-mode.el
new file mode 100644
index 0000000000..5f53aeccc5
--- /dev/null
+++ b/data/eo/eo-mode.el
@@ -0,0 +1,396 @@
1;;; eo-mode-el -- Major mode for editing Eo (eolian) files
2
3;; Author: Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
4;; Created: 2016-07-29
5;; Keywords: EFL Eo major-mode
6
7;; Copyright (C) 2016 Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
8
9;; This program is free software; you can redistribute it and/or
10;; modify it under the terms of the GNU General Public License as
11;; published by the Free Software Foundation; either version 2 of
12;; the License, or (at your option) any later version.
13
14;; This program is distributed in the hope that it will be
15;; useful, but WITHOUT ANY WARRANTY; without even the implied
16;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17;; PURPOSE. See the GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public
20;; License along with this program; if not, write to the Free
21;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22;; MA 02111-1307 USA
23
24;; To enable for *.eo and *.eot files, add to ~/.emacs:
25;;
26;; (add-to-list 'load-path "SOMEPATH/.emacs.d/site-packages/eo-mode.el")
27;; (add-to-list 'auto-mode-alist '("\\.eo$\\|\\.eot$" . eo-mode))
28;; (autoload 'eo-mode "eo-mode")
29
30
31(defvar eo-mode-hook nil)
32
33(defconst eo-font-lock-units
34 (eval-when-compile
35 (list
36 (list (concat
37 "^\\<"
38 (regexp-opt
39 '(
40 "abstract"
41 "class"
42 "mixin"
43 "interface"
44 "type"
45 "const"
46 "var"
47 "struct"
48 "enum"
49 "import"
50 ) t) "\\>\\(\\(\\s-+@"
51 "\\(extern\\|free([^)]+)\\)"
52 "\\)+\\|\\)\\s-+\\<\\([a-zA-Z_][a-zA-Z0-9_.]*\\)\\>")
53 '(1 font-lock-keyword-face)
54 '(2 font-lock-type-face)
55 '(5 font-lock-function-name-face)
56 )))
57 "Toplevel Units")
58
59(defconst eo-font-lock-blocks
60 (eval-when-compile
61 (append eo-font-lock-units
62 (list
63 (list (concat
64 "^\\s-+"
65 (regexp-opt
66 '(
67 "methods"
68 "events"
69 "implements"
70 "constructors"
71 "params"
72 "keys"
73 "values"
74 ) t) "\\s-*{")
75 '(1 font-lock-builtin-face)
76 ))))
77 "blocks")
78
79(defconst eo-font-lock-blocks-with-modifiers
80 (eval-when-compile
81 (append eo-font-lock-blocks
82 (list
83 (list (concat
84 "^\\s-+"
85 (regexp-opt
86 '(
87 "get"
88 "set"
89 ) t)
90 "\\(\\s-+@"
91 (regexp-opt
92 '(
93 "virtual_pure"
94 ) t)
95 "\\|\\)\\s-*{")
96 '(1 font-lock-builtin-face)
97 '(2 font-lock-type-face)
98 ))))
99 "blocks")
100
101(defconst eo-font-lock-constants
102 (eval-when-compile
103 (append eo-font-lock-blocks-with-modifiers
104 (list
105 (list (concat
106 "\\<"
107 (regexp-opt
108 '(
109 "null"
110 "true"
111 "false"
112 ) t) "\\>")
113 '(1 font-lock-constant-face)
114 ))))
115 "Constants")
116
117(defconst eo-font-lock-event
118 (eval-when-compile
119 (append eo-font-lock-constants
120 (list
121 (list (concat
122 "^\\s-+\\([a-zA-Z][a-zA-Z0-9_,]*\\)\\(\\s-+@"
123 (regexp-opt
124 '(
125 "private"
126 "protected"
127 "beta"
128 "hot"
129 ) t) "\\|\\)\\s-*\\(:\\|;\\)")
130 '(1 font-lock-variable-name-face)
131 '(2 font-lock-type-face)
132 ))))
133 "event")
134
135(defconst eo-font-lock-param
136 (eval-when-compile
137 (append eo-font-lock-event
138 (list
139 (list (concat
140 "^\\s-+\\(@"
141 (regexp-opt
142 '(
143 "in"
144 "out"
145 "inout"
146 ) t)
147 "\\s-+\\|\\)\\([a-zA-Z][a-zA-Z0-9_]*\\)"
148 "\\s-*:[^@]+*\\(\\(\\s-+@"
149 (regexp-opt
150 '(
151 "nullable"
152 "optional"
153 ) t)
154 "\\)+\\|\\)\\s-*;"
155 )
156 '(1 font-lock-type-face)
157 '(3 font-lock-variable-name-face)
158 '(4 font-lock-type-face)
159 ))))
160 "parameters")
161
162
163(defconst eo-font-lock-return
164 (eval-when-compile
165 (append eo-font-lock-param
166 (list
167 (list (concat
168 "^\\s-+return\\s-*:[^@]+*\\(\\(\\s-+@"
169 (regexp-opt
170 '(
171 "warn_unused"
172 ) t)
173 "\\)+\\|\\)\\s-*;"
174 )
175 '(1 font-lock-type-face)
176 ))))
177 "return")
178
179(defconst eo-font-lock-default-implementation
180 (eval-when-compile
181 (append eo-font-lock-return
182 (list
183 (list (concat
184 "^\\s-+"
185 (regexp-opt
186 '(
187 "class.constructor"
188 "class.destructor"
189 ) t)
190 "\\s-*;"
191 )
192 '(1 font-lock-builtin-face)
193 ))))
194 "Default Implementation")
195
196(defconst eo-font-lock-implementation
197 (eval-when-compile
198 (append eo-font-lock-default-implementation
199 (list
200 (list (concat
201 "^\\s-+"
202 "\\(@\\(auto\\|empty\\)\\s-+\\|\\)"
203 "\\([a-zA-Z.][a-zA-Z0-9_.]*\\)"
204 "\\s-*;"
205 )
206 '(1 font-lock-type-face)
207 '(3 font-lock-variable-name-face)
208 ))))
209 "Implementation")
210
211(defconst eo-font-lock-property
212 (eval-when-compile
213 (append eo-font-lock-implementation
214 (list
215 (list (concat
216 "^\\s-+\\(@property\\)\\s-+"
217 "\\([a-zA-Z][a-zA-Z0-9_]*\\)\\(\\(\\s-+@"
218 (regexp-opt
219 '(
220 "protected"
221 "class"
222 "virtual_pure"
223 "part"
224 ) t)
225 "\\)+\\|\\)\\s-*{"
226 )
227 '(1 font-lock-type-face)
228 '(2 font-lock-variable-name-face)
229 '(3 font-lock-type-face)
230 ))))
231 "Property method")
232
233(defconst eo-font-lock-method
234 (eval-when-compile
235 (append eo-font-lock-property
236 (list
237 (list (concat
238 "^\\s-+\\([a-zA-Z][a-zA-Z0-9_]*\\)\\(\\(\\s-+@"
239 (regexp-opt
240 '(
241 "protected"
242 "const"
243 "class"
244 "virtual_pure"
245 ) t)
246 "\\)+\\|\\)\\s-*{"
247 )
248 '(1 font-lock-variable-name-face)
249 '(2 font-lock-type-face)
250 ))))
251 "Method")
252
253
254(defconst eo-font-lock-fields
255 (eval-when-compile
256 (append eo-font-lock-method
257 (list
258 (list "^\\s-+\\<\\([a-zA-Z0-9][a-zA-Z0-9_,]*\\)\\>:"
259 '(1 font-lock-variable-name-face)
260 ))))
261 "Fields & Events without modifiers")
262
263(defconst eo-font-lock-complex-type
264 (eval-when-compile
265 (append eo-font-lock-fields
266 (list
267 (list (concat
268 "\\<"
269 (regexp-opt
270 '(
271 "accessor"
272 "array"
273 "iterator"
274 "hash"
275 "list"
276 ) t)
277 "\\>\\s-*<"
278 )
279 '(1 font-lock-builtin-face)
280 ))))
281 "Complex types, C++ template style.")
282
283(defconst eo-font-lock-expression-functions
284 (eval-when-compile
285 (append eo-font-lock-complex-type
286 (list
287 (list (concat
288 "\\<"
289 (regexp-opt
290 '(
291 "own"
292 "const"
293 "free"
294 ) t)
295 "\\>\\s-*("
296 )
297 '(1 font-lock-builtin-face)
298 ))))
299 "Expression Functions")
300
301(defconst eo-font-lock-known-types
302 (eval-when-compile
303 (append eo-font-lock-expression-functions
304 (list
305 (list (concat
306 "\\<"
307 (regexp-opt
308 '(
309 "byte"
310 "ubyte"
311 "char"
312 "short"
313 "ushort"
314 "int"
315 "uint"
316 "long"
317 "ulong"
318 "llong"
319 "ullong"
320 "int8"
321 "uint8"
322 "int16"
323 "uint16"
324 "int32"
325 "uint32"
326 "int64"
327 "uint64"
328 "int128"
329 "uint128"
330 "size"
331 "ssize"
332 "intptr"
333 "uintptr"
334 "ptrdiff"
335 "time"
336 "float"
337 "double"
338 "bool"
339 "void"
340 ) t)
341 "\\>"
342 )
343 '(1 font-lock-builtin-face)
344 ))))
345 "Expression Functions")
346
347(defgroup eo nil
348 "EFL's Eo formatting."
349 :prefix "eo-"
350 :group 'faces)
351
352(defface eo-docstring-face
353 '((t :inherit font-lock-string-face))
354 "Face used to highlight documentation strings."
355 :group 'eo)
356
357(defconst eo-font-lock-docstring
358 (eval-when-compile
359 (append eo-font-lock-known-types
360 (list
361 (list "\\(\\[\\[.*\\]\\]\\)"
362 '(1 'eo-docstring-face t) ;; t = overrides comment existing formatting
363 ))))
364 "Documentation")
365
366(defvar eo-font-lock eo-font-lock-docstring)
367
368(defvar eo-mode-syntax-table
369 (let ((eo-mode-syntax-table (make-syntax-table)))
370 ;; [ is open and matches ], but [[ is a docstring starter
371 (modify-syntax-entry ?[ "(]12c" eo-mode-syntax-table)
372 (modify-syntax-entry ?] ")[34c" eo-mode-syntax-table)
373 eo-mode-syntax-table)
374 "Syntax table for eo-mode")
375
376(c-add-style
377 "eo"
378 '("gnu"
379 (indent-tabs-mode . nil)
380 (tab-width . 8)
381 (c-basic-offset . 4)
382 (c-backslash-column . 72)
383 ))
384
385(define-derived-mode eo-mode c-mode "Eo"
386 "Major mode for editing Eo files"
387 (interactive)
388 (use-local-map eo-mode-map)
389 (set-syntax-table eo-mode-syntax-table)
390 (set (make-local-variable 'font-lock-defaults) '(eo-font-lock))
391 (set (make-local-variable 'require-final-newline) t)
392 (c-set-style "eo")
393 (run-hooks 'eo-mode-hook)
394 )
395
396(provide 'eo-mode)