author | Luke Hoersten <Luke@Hoersten.org> |
Mon, 16 May 2011 19:58:15 -0500 | |
changeset 36 | d915699fbc26 |
parent 35 | 4a9c440b6764 |
permissions | -rw-r--r-- |
22 | 1 |
;;; vala-mode.el --- Vala mode derived mode |
2 |
||
3 |
;; Author: 2005 Dylan R. E. Moonfire |
|
4 |
;; 2008 Étienne BERSAC |
|
5 |
;; Maintainer: Étienne BERSAC <[email protected]> |
|
6 |
;; Created: 2008 May the 4th |
|
7 |
;; Modified: May 2008 |
|
8 |
;; Version: 0.1 |
|
9 |
;; Keywords: vala languages oop |
|
10 |
||
11 |
;; This program is free software; you can redistribute it and/or modify |
|
12 |
;; it under the terms of the GNU General Public License as published by |
|
13 |
;; the Free Software Foundation; either version 2 of the License, or |
|
14 |
;; (at your option) any later version. |
|
15 |
;; |
|
16 |
;; This program is distributed in the hope that it will be useful, |
|
17 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
;; GNU General Public License for more details. |
|
20 |
;; |
|
21 |
;; You should have received a copy of the GNU General Public License |
|
22 |
;; along with this program; see the file COPYING. If not, write to |
|
23 |
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
24 |
;; Boston, MA 02111-1307, USA. |
|
25 |
||
26 |
;;; Commentary: |
|
27 |
;; |
|
28 |
;; See http://live.gnome.org/Vala for details about Vala language. |
|
29 |
;; |
|
30 |
;; This is a separate mode to implement the Vala constructs and |
|
31 |
;; font-locking. It is mostly the csharp-mode from |
|
32 |
;; http://mfgames.com/linux/csharp-mode with vala specific keywords |
|
33 |
;; and filename suffixes. |
|
34 |
;; |
|
35 |
;; Note: The interface used in this file requires CC Mode 5.30 or |
|
36 |
;; later. |
|
37 |
||
38 |
;;; .emacs (don't put in (require 'vala-mode)) |
|
39 |
;; (autoload 'vala-mode "vala-mode" "Major mode for editing Vala code." t) |
|
40 |
;; (setq auto-mode-alist |
|
41 |
;; (append '(("\\.vala$" . vala-mode)) auto-mode-alist)) |
|
42 |
||
43 |
;;; Versions: |
|
44 |
;; |
|
45 |
;; 0.1 : Initial version based on csharp-mode |
|
46 |
;; |
|
47 |
||
48 |
;; This is a copy of the function in cc-mode which is used to handle |
|
49 |
;; the eval-when-compile which is needed during other times. |
|
50 |
(defun c-filter-ops (ops opgroup-filter op-filter &optional xlate) |
|
51 |
;; See cc-langs.el, a direct copy. |
|
52 |
(unless (listp (car-safe ops)) |
|
53 |
(setq ops (list ops))) |
|
54 |
(cond ((eq opgroup-filter t) |
|
55 |
(setq opgroup-filter (lambda (opgroup) t))) |
|
56 |
((not (functionp opgroup-filter)) |
|
57 |
(setq opgroup-filter `(lambda (opgroup) |
|
58 |
(memq opgroup ',opgroup-filter))))) |
|
59 |
(cond ((eq op-filter t) |
|
60 |
(setq op-filter (lambda (op) t))) |
|
61 |
((stringp op-filter) |
|
62 |
(setq op-filter `(lambda (op) |
|
63 |
(string-match ,op-filter op))))) |
|
64 |
(unless xlate |
|
65 |
(setq xlate 'identity)) |
|
66 |
(c-with-syntax-table (c-lang-const c-mode-syntax-table) |
|
67 |
(delete-duplicates |
|
68 |
(mapcan (lambda (opgroup) |
|
69 |
(when (if (symbolp (car opgroup)) |
|
70 |
(when (funcall opgroup-filter (car opgroup)) |
|
71 |
(setq opgroup (cdr opgroup)) |
|
72 |
t) |
|
73 |
t) |
|
74 |
(mapcan (lambda (op) |
|
75 |
(when (funcall op-filter op) |
|
76 |
(let ((res (funcall xlate op))) |
|
77 |
(if (listp res) res (list res))))) |
|
78 |
opgroup))) |
|
79 |
ops) |
|
80 |
:test 'equal))) |
|
81 |
||
82 |
;; This inserts the bulk of the code. |
|
83 |
(require 'cc-mode) |
|
84 |
||
85 |
;; These are only required at compile time to get the sources for the |
|
86 |
;; language constants. (The cc-fonts require and the font-lock |
|
87 |
;; related constants could additionally be put inside an |
|
88 |
;; (eval-after-load "font-lock" ...) but then some trickery is |
|
89 |
;; necessary to get them compiled.) |
|
90 |
(eval-when-compile |
|
91 |
(let ((load-path |
|
92 |
(if (and (boundp 'byte-compile-dest-file) |
|
93 |
(stringp byte-compile-dest-file)) |
|
94 |
(cons (file-name-directory byte-compile-dest-file) load-path) |
|
95 |
load-path))) |
|
96 |
(load "cc-mode" nil t) |
|
97 |
(load "cc-fonts" nil t) |
|
98 |
(load "cc-langs" nil t))) |
|
99 |
||
100 |
(eval-and-compile |
|
101 |
;; Make our mode known to the language constant system. Use Java |
|
102 |
;; mode as the fallback for the constants we don't change here. |
|
103 |
;; This needs to be done also at compile time since the language |
|
104 |
;; constants are evaluated then. |
|
105 |
(c-add-language 'vala-mode 'java-mode)) |
|
106 |
||
107 |
;; Java uses a series of regexes to change the font-lock for class |
|
108 |
;; references. The problem comes in because Java uses Pascal (leading |
|
109 |
;; space in names, SomeClass) for class and package names, but |
|
110 |
;; Camel-casing (initial lowercase, upper case in words, |
|
111 |
;; i.e. someVariable) for variables. |
|
112 |
;;(error (byte-compile-dest-file)) |
|
113 |
;;(error (c-get-current-file)) |
|
114 |
(c-lang-defconst c-opt-after-id-concat-key |
|
115 |
vala (if (c-lang-const c-opt-identifier-concat-key) |
|
116 |
(c-lang-const c-symbol-start))) |
|
117 |
||
118 |
(c-lang-defconst c-basic-matchers-before |
|
119 |
vala `( |
|
120 |
;;;; Font-lock the attributes by searching for the |
|
121 |
;;;; appropriate regex and marking it as TODO. |
|
122 |
;;,`(,(concat "\\(" vala-attribute-regex "\\)") |
|
123 |
;; 0 font-lock-function-name-face) |
|
124 |
||
125 |
;; Put a warning face on the opener of unclosed strings that |
|
126 |
;; can't span lines. Later font |
|
127 |
;; lock packages have a `font-lock-syntactic-face-function' for |
|
128 |
;; this, but it doesn't give the control we want since any |
|
129 |
;; fontification done inside the function will be |
|
130 |
;; unconditionally overridden. |
|
131 |
,(c-make-font-lock-search-function |
|
132 |
;; Match a char before the string starter to make |
|
133 |
;; `c-skip-comments-and-strings' work correctly. |
|
134 |
(concat ".\\(" c-string-limit-regexp "\\)") |
|
135 |
'((c-font-lock-invalid-string))) |
|
136 |
|
|
137 |
;; Fontify keyword constants. |
|
138 |
,@(when (c-lang-const c-constant-kwds) |
|
139 |
(let ((re (c-make-keywords-re nil |
|
140 |
(c-lang-const c-constant-kwds)))) |
|
141 |
`((eval . (list ,(concat "\\<\\(" re "\\)\\>") |
|
142 |
1 c-constant-face-name))))) |
|
143 |
|
|
144 |
;; Fontify all keywords except the primitive types. |
|
145 |
,`(,(concat "\\<" (c-lang-const c-regular-keywords-regexp)) |
|
a7906973ceb5
Added some old files.
Luke Hoersten <Luke@Hoersten.org> |