diff options
Diffstat (limited to 'libraries/edje/data/edje-mode.el')
-rw-r--r-- | libraries/edje/data/edje-mode.el | 512 |
1 files changed, 512 insertions, 0 deletions
diff --git a/libraries/edje/data/edje-mode.el b/libraries/edje/data/edje-mode.el new file mode 100644 index 0000000..33c6fe6 --- /dev/null +++ b/libraries/edje/data/edje-mode.el | |||
@@ -0,0 +1,512 @@ | |||
1 | ;;; edje-mode-el -- Major mode for editing Edje files | ||
2 | |||
3 | ;; Author: Gustavo Sverzut Barbieri <barbieri@gmail.com> | ||
4 | ;; Created: 2007-07-23 | ||
5 | ;; Keywords: Edje major-mode | ||
6 | ;; Url: http://barbieri-playground.googlecode.com/svn/dot-files/edje-mode.el | ||
7 | ;; (if you find this file have problems, check that Url and request update) | ||
8 | |||
9 | ;; Copyright (C) 2007 Gustavo Sverzut Barbieri <barbieri@gmail.com> | ||
10 | |||
11 | ;; This program is free software; you can redistribute it and/or | ||
12 | ;; modify it under the terms of the GNU General Public License as | ||
13 | ;; published by the Free Software Foundation; either version 2 of | ||
14 | ;; the License, or (at your option) any later version. | ||
15 | |||
16 | ;; This program is distributed in the hope that it will be | ||
17 | ;; useful, but WITHOUT ANY WARRANTY; without even the implied | ||
18 | ;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
19 | ;; PURPOSE. See the GNU General Public License for more details. | ||
20 | |||
21 | ;; You should have received a copy of the GNU General Public | ||
22 | ;; License along with this program; if not, write to the Free | ||
23 | ;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
24 | ;; MA 02111-1307 USA | ||
25 | |||
26 | ;;; Commentary: | ||
27 | ;; | ||
28 | ;; This mode is based on tutorial from Scott Andrew Borton: | ||
29 | ;; http://two-wugs.net/emacs/mode-tutorial.html | ||
30 | |||
31 | |||
32 | (defvar edje-mode-hook nil) | ||
33 | |||
34 | (defun number-or-nil-to-string (v &optional default) | ||
35 | (cond ((numberp v) (number-to-string v)) | ||
36 | ((stringp v) (if (string= v "") (number-to-string default) v)) | ||
37 | (t (number-to-string default)))) | ||
38 | |||
39 | (defun non-empty-string (s) | ||
40 | (and (not (eq 'nil s)) | ||
41 | (not (string= "" s)))) | ||
42 | |||
43 | (defun edje-new-program-action-signal-emit (source emission) | ||
44 | "Insert new program SIGNAL_EMIT" | ||
45 | (interactive "ssource: \nsemission: ") | ||
46 | (insert | ||
47 | (concat | ||
48 | " action: SIGNAL_EMIT \"" source "\" \"" emission "\";\n" | ||
49 | ))) | ||
50 | |||
51 | (defun edje-new-program-action-state-set (state value target) | ||
52 | "Insert new program STATE_SET" | ||
53 | (interactive "sstate: \nsvalue (0.0): \nstarget: ") | ||
54 | (insert | ||
55 | (concat | ||
56 | " action: STATE_SET \"" state "\" " | ||
57 | (number-or-nil-to-string value 0.0) ";\n" | ||
58 | " target: \"" target "\";\n" | ||
59 | ))) | ||
60 | |||
61 | (defun edje-new-program-action (action) | ||
62 | "Insert new program action" | ||
63 | (interactive "saction: ") | ||
64 | (setq action (upcase action)) | ||
65 | (cond ((string= action "STATE_SET") | ||
66 | (edje-new-program-action-state-set "" 0.0 "")) | ||
67 | ((string= action "SIGNAL_EMIT") | ||
68 | (edje-new-program-action-signal-emit "" "")) | ||
69 | )) | ||
70 | |||
71 | (defun edje-new-program (name signal source action) | ||
72 | "Insert new program block" | ||
73 | (interactive "sname: \nssignal: \nssource: \nsaction: ") | ||
74 | (insert | ||
75 | (concat | ||
76 | "\n" | ||
77 | " program {\n" | ||
78 | " name: \"" name "\";\n" | ||
79 | |||
80 | (if (non-empty-string signal) | ||
81 | (concat " signal: \"" signal "\";\n")) | ||
82 | |||
83 | (if (non-empty-string source) | ||
84 | (concat " source: \"" source "\";\n")) | ||
85 | )) | ||
86 | |||
87 | (edje-new-program-action action) | ||
88 | |||
89 | (insert | ||
90 | (concat | ||
91 | " }\n" | ||
92 | "\n" | ||
93 | ))) | ||
94 | |||
95 | (defun edje-new-desc-relative (x y &optional defx defy) | ||
96 | "Insert new part description 'relative' line" | ||
97 | (interactive "sx: \nsy: ") | ||
98 | (insert | ||
99 | (concat | ||
100 | " relative: " | ||
101 | (number-or-nil-to-string x defx) " " | ||
102 | (number-or-nil-to-string y defy) ";\n" | ||
103 | ))) | ||
104 | |||
105 | (defun edje-new-desc-offset (x y &optional defx defy) | ||
106 | "Insert new part description 'offset' line" | ||
107 | (interactive "sx: \nsy: ") | ||
108 | (insert | ||
109 | (concat | ||
110 | " offset: " | ||
111 | (number-or-nil-to-string x defx) " " | ||
112 | (number-or-nil-to-string y defy) ";\n" | ||
113 | ))) | ||
114 | |||
115 | (defun edje-new-desc-inherit (name val) | ||
116 | "Insert new part description 'inherit' line" | ||
117 | (interactive "sname: \nsvalue: ") | ||
118 | (insert | ||
119 | (concat | ||
120 | " inherit: \"" name "\" " | ||
121 | (number-or-nil-to-string val 0.0) ";\n" | ||
122 | ))) | ||
123 | |||
124 | (defun edje-new-desc-text (font size text) | ||
125 | "Insert new part description 'text' block" | ||
126 | (interactive "sfont: \nssize: \nstext: ") | ||
127 | (insert | ||
128 | (concat | ||
129 | " text {\n" | ||
130 | " font: \"" font "\";\n" | ||
131 | " size: " (number-or-nil-to-string size) ";\n" | ||
132 | " text: \"" text "\";\n" | ||
133 | " }\n" | ||
134 | ))) | ||
135 | |||
136 | (defun edje-new-desc-image (name) | ||
137 | "Insert new part description 'image' block" | ||
138 | (interactive "sname: ") | ||
139 | (insert | ||
140 | (concat | ||
141 | " image {\n" | ||
142 | " normal: \"" name "\";\n" | ||
143 | " }\n" | ||
144 | ))) | ||
145 | |||
146 | (defun edje-new-desc-color (r g b a &optional defr defg defb defa) | ||
147 | "Insert new part description 'color' line" | ||
148 | (interactive "sred: \nsgreen: \nsblue: \nsalpha: ") | ||
149 | (insert | ||
150 | (concat | ||
151 | " color: " | ||
152 | (number-or-nil-to-string r defr) " " | ||
153 | (number-or-nil-to-string g defg) " " | ||
154 | (number-or-nil-to-string b defb) " " | ||
155 | (number-or-nil-to-string a defa) ";\n" | ||
156 | ))) | ||
157 | |||
158 | (defun edje-new-desc (name val &optional | ||
159 | r1_rx r1_ry | ||
160 | r2_rx r2_ry | ||
161 | r1_ox r1_oy | ||
162 | r2_ox r2_oy | ||
163 | part_type) | ||
164 | "Insert new part description block" | ||
165 | (interactive "sName: \nsValue: ") | ||
166 | (insert | ||
167 | (concat | ||
168 | " description {\n" | ||
169 | " state: \"" name "\" " (number-or-nil-to-string val 0.0) ";\n")) | ||
170 | (if (string= part_type "RECT") (edje-new-desc-color 255 255 255 255)) | ||
171 | (insert " rel1 {\n") | ||
172 | (edje-new-desc-relative r1_rx r1_ry 0.0 0.0) | ||
173 | (edje-new-desc-offset r1_ox r1_oy 0 0) | ||
174 | (insert | ||
175 | (concat | ||
176 | " }\n" | ||
177 | " rel2 {\n" | ||
178 | )) | ||
179 | (edje-new-desc-relative r2_rx r2_ry 1.0 1.0) | ||
180 | (edje-new-desc-offset r2_ox r2_oy -1 -1) | ||
181 | (insert " }\n") | ||
182 | (cond ((string= part_type "IMAGE") (edje-new-desc-image "")) | ||
183 | ((string= part_type "TEXT") (edje-new-desc-text "" 10 "contents")) | ||
184 | ) | ||
185 | (insert " }\n") | ||
186 | ) | ||
187 | |||
188 | (defun edje-new-part (name type &optional | ||
189 | r1_rx r1_ry | ||
190 | r2_rx r2_ry | ||
191 | r1_ox r1_oy | ||
192 | r2_ox r2_oy) | ||
193 | "Insert new part" | ||
194 | (interactive "sName: \nsType: ") | ||
195 | (setq type (upcase type)) | ||
196 | (insert | ||
197 | (concat | ||
198 | "\n" | ||
199 | " part {\n" | ||
200 | " name: \"" name "\";\n" | ||
201 | " type: " type ";\n" | ||
202 | " mouse_events: 0;\n" | ||
203 | )) | ||
204 | (edje-new-desc "default" 0.0 r1_rx r1_ry r2_rx r2_ry r1_ox r1_oy r2_ox r2_oy type) | ||
205 | (insert | ||
206 | (concat | ||
207 | " }\n" | ||
208 | ))) | ||
209 | |||
210 | (defun edje-setup-compile () | ||
211 | (set (make-local-variable 'compile-command) | ||
212 | (concat "edje_cc " (buffer-file-name)) | ||
213 | )) | ||
214 | |||
215 | (defun edje-cc () | ||
216 | "Runs edje_cc with current buffer." | ||
217 | (interactive) | ||
218 | (compile (edje-setup-compile))) | ||
219 | |||
220 | (defvar edje-mode-map | ||
221 | (let ((edje-mode-map (make-sparse-keymap))) | ||
222 | (define-key edje-mode-map "\C-j" 'newline-and-indent) | ||
223 | (define-key edje-mode-map "\C-cp" 'edje-new-part) | ||
224 | (define-key edje-mode-map "\C-cd" 'edje-new-desc) | ||
225 | (define-key edje-mode-map "\C-cr" 'edje-new-desc-relative) | ||
226 | (define-key edje-mode-map "\C-co" 'edje-new-desc-offset) | ||
227 | (define-key edje-mode-map "\C-ch" 'edje-new-desc-inherit) | ||
228 | (define-key edje-mode-map "\C-cc" 'edje-new-desc-color) | ||
229 | (define-key edje-mode-map "\C-ci" 'edje-new-desc-image) | ||
230 | (define-key edje-mode-map "\C-ct" 'edje-new-desc-text) | ||
231 | (define-key edje-mode-map "\C-cg" 'edje-new-program) | ||
232 | (define-key edje-mode-map "\C-ca" 'edje-new-program-action) | ||
233 | (define-key edje-mode-map "\C-cs" 'edje-new-program-action-state-set) | ||
234 | (define-key edje-mode-map "\C-ce" 'edje-new-program-action-signal-emit) | ||
235 | edje-mode-map) | ||
236 | "Keymap for Edje major mode") | ||
237 | |||
238 | (add-hook 'c-mode-hook 'edje-setup-compile) | ||
239 | (add-to-list 'auto-mode-alist '("\\.edc$" . edje-mode)) | ||
240 | |||
241 | (defconst edje-font-lock-keywords-1 | ||
242 | (eval-when-compile | ||
243 | (list | ||
244 | (list (concat "[ \t]*\\<" | ||
245 | (regexp-opt | ||
246 | '( | ||
247 | "collections" | ||
248 | "data" | ||
249 | "description" | ||
250 | "dragable" | ||
251 | "fill" | ||
252 | "fonts" | ||
253 | "group" | ||
254 | "image" | ||
255 | "images" | ||
256 | "origin" | ||
257 | "part" | ||
258 | "parts" | ||
259 | "program" | ||
260 | "programs" | ||
261 | "rel1" | ||
262 | "rel2" | ||
263 | "script" | ||
264 | "spectra" | ||
265 | "style" | ||
266 | "styles" | ||
267 | "text" | ||
268 | ) t) "\\>\\([ \t]*{\\|\\.\\)") | ||
269 | '(1 font-lock-function-name-face)) | ||
270 | |||
271 | )) | ||
272 | "Major keywords") | ||
273 | |||
274 | (defconst edje-font-lock-keywords-2 | ||
275 | (eval-when-compile | ||
276 | (append edje-font-lock-keywords-1 | ||
277 | (list | ||
278 | (list | ||
279 | (concat "^\\([ \t]*\\|[ \t]*[a-z]+\\.\\|\\)\\<" | ||
280 | (regexp-opt | ||
281 | '("action" | ||
282 | "after" | ||
283 | "alias" | ||
284 | "align" | ||
285 | "angle" | ||
286 | "aspect" | ||
287 | "aspect_preference" | ||
288 | "base" | ||
289 | "border" | ||
290 | "clip_to" | ||
291 | "collections" | ||
292 | "color" | ||
293 | "color2" | ||
294 | "color3" | ||
295 | "color_class" | ||
296 | "color_classes" | ||
297 | "confine" | ||
298 | "data" | ||
299 | "description" | ||
300 | "dragable" | ||
301 | "effect" | ||
302 | "elipsis" | ||
303 | "events" | ||
304 | "fill" | ||
305 | "fit" | ||
306 | "fixed" | ||
307 | "font" | ||
308 | "fonts" | ||
309 | "gradient" | ||
310 | "group" | ||
311 | "ignore_flags" | ||
312 | "image" | ||
313 | "images" | ||
314 | "in" | ||
315 | "inherit" | ||
316 | "item" | ||
317 | "max" | ||
318 | "middle" | ||
319 | "min" | ||
320 | "mouse_events" | ||
321 | "name" | ||
322 | "normal" | ||
323 | "offset" | ||
324 | "origin" | ||
325 | "part" | ||
326 | "parts" | ||
327 | "pointer_mode" | ||
328 | "precise_is_inside" | ||
329 | "program" | ||
330 | "programs" | ||
331 | "rel1" | ||
332 | "rel2" | ||
333 | "relative" | ||
334 | "repeat_events" | ||
335 | "signal" | ||
336 | "size" | ||
337 | "smooth" | ||
338 | "source" | ||
339 | "spectra" | ||
340 | "spectrum" | ||
341 | "spread" | ||
342 | "state" | ||
343 | "step" | ||
344 | "style" | ||
345 | "styles" | ||
346 | "tag" | ||
347 | "target" | ||
348 | "text" | ||
349 | "text_class" | ||
350 | "text_source" | ||
351 | "to" | ||
352 | "to_x" | ||
353 | "to_y" | ||
354 | "transition" | ||
355 | "tween" | ||
356 | "type" | ||
357 | "use_alternate_font_metrics" | ||
358 | "visible" | ||
359 | "x" | ||
360 | "y" | ||
361 | ) t) "\\>[ \t]*[:,]") | ||
362 | '(2 font-lock-keyword-face)) | ||
363 | ))) | ||
364 | "Minor keywords") | ||
365 | |||
366 | (defconst edje-font-lock-keywords-3 | ||
367 | (eval-when-compile | ||
368 | (append edje-font-lock-keywords-2 | ||
369 | (list | ||
370 | (list | ||
371 | (concat "\\<" | ||
372 | (regexp-opt | ||
373 | '(; image options (st_images_image) | ||
374 | "RAW" | ||
375 | "COMP" | ||
376 | "LOSSY" | ||
377 | "USER" | ||
378 | ; part types (st_collections_group_parts_part_type) | ||
379 | "NONE" | ||
380 | "RECT" | ||
381 | "TEXT" | ||
382 | "IMAGE" | ||
383 | "SWALLOW" | ||
384 | "TEXTBLOCK" | ||
385 | "GRADIENT" | ||
386 | "GROUP" | ||
387 | ; ignore flags (st_collections_group_parts_part_ignore_flags) | ||
388 | ;"NONE" | ||
389 | "ON_HOLD" | ||
390 | ; pointer mode (st_collections_group_parts_part_pointer_mode) | ||
391 | "AUTOGRAB" | ||
392 | "NOGRAB" | ||
393 | ; aspect (st_collections_group_parts_part_description_aspect_preference) | ||
394 | "NONE" | ||
395 | "VERTICAL" | ||
396 | "HORIZONTAL" | ||
397 | "BOTH" | ||
398 | ; text effect (st_collections_group_parts_part_effect) | ||
399 | "NONE" | ||
400 | "PLAIN" | ||
401 | "OUTLINE" | ||
402 | "SOFT_OUTLINE" | ||
403 | "SHADOW" | ||
404 | "SOFT_SHADOW" | ||
405 | "OUTLINE_SHADOW" | ||
406 | "OUTLINE_SOFT_SHADOW" | ||
407 | "FAR_SHADOW" | ||
408 | "FAR_SOFT_SHADOW" | ||
409 | "GLOW" | ||
410 | ; image fill (st_collections_group_parts_part_description_fill_type) | ||
411 | "SCALE" | ||
412 | "TILE" | ||
413 | ; program action (st_collections_group_programs_program_action) | ||
414 | "STATE_SET" | ||
415 | "ACTION_STOP" | ||
416 | "SIGNAL_EMIT" | ||
417 | "DRAG_VAL_SET" | ||
418 | "DRAG_VAL_STEP" | ||
419 | "DRAG_VAL_PAGE" | ||
420 | "SCRIPT" | ||
421 | ; program transition (st_collections_group_programs_program_transition) | ||
422 | "LINEAR" | ||
423 | "SINUSOIDAL" | ||
424 | "ACCELERATE" | ||
425 | "DECELERATE" | ||
426 | ) t) "\\>") | ||
427 | '(1 font-lock-builtin-face)) | ||
428 | ))) | ||
429 | "Enumerate values") | ||
430 | |||
431 | (defconst edje-font-lock-keywords-4 | ||
432 | (eval-when-compile | ||
433 | (append edje-font-lock-keywords-3 | ||
434 | (list | ||
435 | (list | ||
436 | (concat "[ \t]*#" | ||
437 | (regexp-opt | ||
438 | '("if" | ||
439 | "ifdef" | ||
440 | "ifndef" | ||
441 | "define" | ||
442 | "else" | ||
443 | "endif" | ||
444 | "include" | ||
445 | "undef") t) "[ \t]*") | ||
446 | '(1 font-lock-builtin-face)) | ||
447 | ))) | ||
448 | "CPP directives") | ||
449 | |||
450 | (defconst edje-font-lock-keywords-5 | ||
451 | (eval-when-compile | ||
452 | (append edje-font-lock-keywords-4 | ||
453 | (list | ||
454 | (list "[ \t]*#undef[ \t]+\\([a-zA-Z_][a-zA-Z0-9_]*\\)" | ||
455 | '(1 font-lock-variable-name-face)) | ||
456 | (list "[ \t]*#define[ \t]+\\([a-zA-Z_][a-zA-Z0-9_]*\\)(" | ||
457 | '(1 font-lock-function-name-face)) | ||
458 | (list "[ \t]*#define[ \t]+\\([a-zA-Z_][a-zA-Z0-9_]*\\)" | ||
459 | '(1 font-lock-variable-name-face)) | ||
460 | ))) | ||
461 | "CPP directives that define constants") | ||
462 | |||
463 | |||
464 | (defvar edje-font-lock-keywords edje-font-lock-keywords-5) | ||
465 | |||
466 | (defvar edje-mode-syntax-table | ||
467 | (let ((edje-mode-syntax-table (make-syntax-table))) | ||
468 | ; This is added so entity names with underscores can be more easily parsed | ||
469 | (modify-syntax-entry ?_ "w" edje-mode-syntax-table) | ||
470 | (modify-syntax-entry ?/ ". 124b" edje-mode-syntax-table) | ||
471 | (modify-syntax-entry ?* ". 23" edje-mode-syntax-table) | ||
472 | (modify-syntax-entry ?\n "> b" edje-mode-syntax-table) | ||
473 | |||
474 | edje-mode-syntax-table) | ||
475 | "Syntax table for edje-mode") | ||
476 | |||
477 | (c-add-style | ||
478 | "edje" | ||
479 | '("gnu" | ||
480 | (indent-tabs-mode . nil) | ||
481 | (tab-width . 8) | ||
482 | (c-basic-offset . 3) | ||
483 | (c-backslash-column . 72) | ||
484 | (c-hanging-braces-alist . | ||
485 | ((block-open after) | ||
486 | (brace-list-open after) | ||
487 | (substatement-open after)) | ||
488 | ) | ||
489 | (c-offsets-alist . | ||
490 | ((statement-block-intro . +) | ||
491 | (defun-open . 0) | ||
492 | (substatement-open . 0) | ||
493 | (defun-block-intro . +) | ||
494 | (block-open . 0) | ||
495 | (label . +) | ||
496 | )))) | ||
497 | |||
498 | |||
499 | (define-derived-mode edje-mode c-mode "Edje" | ||
500 | "Major mode for editing Edje files" | ||
501 | (interactive) | ||
502 | (use-local-map edje-mode-map) | ||
503 | (set-syntax-table edje-mode-syntax-table) | ||
504 | (set (make-local-variable 'font-lock-defaults) '(edje-font-lock-keywords)) | ||
505 | (set (make-local-variable 'require-final-newline) t) | ||
506 | (c-set-style "edje") | ||
507 | (run-hooks 'edje-mode-hook) | ||
508 | ) | ||
509 | |||
510 | (provide 'edje-mode) | ||
511 | |||
512 | ;;; edje-mode.el ends here | ||