wok-next diff emacs-pkg-vala-mode/stuff/vala-mode.el @ rev 9954
elink: fix receipt path and build
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed May 18 14:56:30 2011 +0200 (2011-05-18) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/emacs-pkg-vala-mode/stuff/vala-mode.el Wed May 18 14:56:30 2011 +0200 1.3 @@ -0,0 +1,395 @@ 1.4 +;;; vala-mode.el --- Vala mode derived mode 1.5 + 1.6 +;; Author: 2005 Dylan R. E. Moonfire 1.7 +;; 2008 Étienne BERSAC 1.8 +;; Maintainer: Étienne BERSAC <bersace03@laposte.net> 1.9 +;; Created: 2008 May the 4th 1.10 +;; Modified: May 2008 1.11 +;; Version: 0.1 1.12 +;; Keywords: vala languages oop 1.13 + 1.14 +;; This program is free software; you can redistribute it and/or modify 1.15 +;; it under the terms of the GNU General Public License as published by 1.16 +;; the Free Software Foundation; either version 2 of the License, or 1.17 +;; (at your option) any later version. 1.18 +;; 1.19 +;; This program is distributed in the hope that it will be useful, 1.20 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of 1.21 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.22 +;; GNU General Public License for more details. 1.23 +;; 1.24 +;; You should have received a copy of the GNU General Public License 1.25 +;; along with this program; see the file COPYING. If not, write to 1.26 +;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 1.27 +;; Boston, MA 02111-1307, USA. 1.28 + 1.29 +;;; Commentary: 1.30 +;; 1.31 +;; See http://live.gnome.org/Vala for details about Vala language. 1.32 +;; 1.33 +;; This is a separate mode to implement the Vala constructs and 1.34 +;; font-locking. It is mostly the csharp-mode from 1.35 +;; http://mfgames.com/linux/csharp-mode with vala specific keywords 1.36 +;; and filename suffixes. 1.37 +;; 1.38 +;; Note: The interface used in this file requires CC Mode 5.30 or 1.39 +;; later. 1.40 + 1.41 +;;; .emacs (don't put in (require 'vala-mode)) 1.42 +;; (autoload 'vala-mode "vala-mode" "Major mode for editing Vala code." t) 1.43 +;; (setq auto-mode-alist 1.44 +;; (append '(("\\.vala$" . vala-mode)) auto-mode-alist)) 1.45 + 1.46 +;;; Versions: 1.47 +;; 1.48 +;; 0.1 : Initial version based on csharp-mode 1.49 +;; 1.50 + 1.51 +;; This is a copy of the function in cc-mode which is used to handle 1.52 +;; the eval-when-compile which is needed during other times. 1.53 +(defun c-filter-ops (ops opgroup-filter op-filter &optional xlate) 1.54 + ;; See cc-langs.el, a direct copy. 1.55 + (unless (listp (car-safe ops)) 1.56 + (setq ops (list ops))) 1.57 + (cond ((eq opgroup-filter t) 1.58 + (setq opgroup-filter (lambda (opgroup) t))) 1.59 + ((not (functionp opgroup-filter)) 1.60 + (setq opgroup-filter `(lambda (opgroup) 1.61 + (memq opgroup ',opgroup-filter))))) 1.62 + (cond ((eq op-filter t) 1.63 + (setq op-filter (lambda (op) t))) 1.64 + ((stringp op-filter) 1.65 + (setq op-filter `(lambda (op) 1.66 + (string-match ,op-filter op))))) 1.67 + (unless xlate 1.68 + (setq xlate 'identity)) 1.69 + (c-with-syntax-table (c-lang-const c-mode-syntax-table) 1.70 + (delete-duplicates 1.71 + (mapcan (lambda (opgroup) 1.72 + (when (if (symbolp (car opgroup)) 1.73 + (when (funcall opgroup-filter (car opgroup)) 1.74 + (setq opgroup (cdr opgroup)) 1.75 + t) 1.76 + t) 1.77 + (mapcan (lambda (op) 1.78 + (when (funcall op-filter op) 1.79 + (let ((res (funcall xlate op))) 1.80 + (if (listp res) res (list res))))) 1.81 + opgroup))) 1.82 + ops) 1.83 + :test 'equal))) 1.84 + 1.85 +;; This inserts the bulk of the code. 1.86 +(require 'cc-mode) 1.87 + 1.88 +;; These are only required at compile time to get the sources for the 1.89 +;; language constants. (The cc-fonts require and the font-lock 1.90 +;; related constants could additionally be put inside an 1.91 +;; (eval-after-load "font-lock" ...) but then some trickery is 1.92 +;; necessary to get them compiled.) 1.93 +(eval-when-compile 1.94 + (let ((load-path 1.95 + (if (and (boundp 'byte-compile-dest-file) 1.96 + (stringp byte-compile-dest-file)) 1.97 + (cons (file-name-directory byte-compile-dest-file) load-path) 1.98 + load-path))) 1.99 + (load "cc-mode" nil t) 1.100 + (load "cc-fonts" nil t) 1.101 + (load "cc-langs" nil t))) 1.102 + 1.103 +(eval-and-compile 1.104 + ;; Make our mode known to the language constant system. Use Java 1.105 + ;; mode as the fallback for the constants we don't change here. 1.106 + ;; This needs to be done also at compile time since the language 1.107 + ;; constants are evaluated then. 1.108 + (c-add-language 'vala-mode 'java-mode)) 1.109 + 1.110 +;; Java uses a series of regexes to change the font-lock for class 1.111 +;; references. The problem comes in because Java uses Pascal (leading 1.112 +;; space in names, SomeClass) for class and package names, but 1.113 +;; Camel-casing (initial lowercase, upper case in words, 1.114 +;; i.e. someVariable) for variables. 1.115 +;;(error (byte-compile-dest-file)) 1.116 +;;(error (c-get-current-file)) 1.117 +(c-lang-defconst c-opt-after-id-concat-key 1.118 + vala (if (c-lang-const c-opt-identifier-concat-key) 1.119 + (c-lang-const c-symbol-start))) 1.120 + 1.121 +(c-lang-defconst c-basic-matchers-before 1.122 + vala `( 1.123 +;;;; Font-lock the attributes by searching for the 1.124 +;;;; appropriate regex and marking it as TODO. 1.125 + ;;,`(,(concat "\\(" vala-attribute-regex "\\)") 1.126 + ;; 0 font-lock-function-name-face) 1.127 + 1.128 + ;; Put a warning face on the opener of unclosed strings that 1.129 + ;; can't span lines. Later font 1.130 + ;; lock packages have a `font-lock-syntactic-face-function' for 1.131 + ;; this, but it doesn't give the control we want since any 1.132 + ;; fontification done inside the function will be 1.133 + ;; unconditionally overridden. 1.134 + ,(c-make-font-lock-search-function 1.135 + ;; Match a char before the string starter to make 1.136 + ;; `c-skip-comments-and-strings' work correctly. 1.137 + (concat ".\\(" c-string-limit-regexp "\\)") 1.138 + '((c-font-lock-invalid-string))) 1.139 + 1.140 + ;; Fontify keyword constants. 1.141 + ,@(when (c-lang-const c-constant-kwds) 1.142 + (let ((re (c-make-keywords-re nil 1.143 + (c-lang-const c-constant-kwds)))) 1.144 + `((eval . (list ,(concat "\\<\\(" re "\\)\\>") 1.145 + 1 c-constant-face-name))))) 1.146 + 1.147 + ;; Fontify all keywords except the primitive types. 1.148 + ,`(,(concat "\\<" (c-lang-const c-regular-keywords-regexp)) 1.149 + 1 font-lock-keyword-face) 1.150 + 1.151 + ;; Fontify leading identifiers in fully 1.152 + ;; qualified names like "Foo.Bar". 1.153 + ,@(when (c-lang-const c-opt-identifier-concat-key) 1.154 + `((,(byte-compile 1.155 + `(lambda (limit) 1.156 + (while (re-search-forward 1.157 + ,(concat "\\(\\<" ; 1 1.158 + "\\(" (c-lang-const c-symbol-key) 1.159 + "\\)" ; 2 1.160 + "[ \t\n\r\f\v]*" 1.161 + (c-lang-const 1.162 + c-opt-identifier-concat-key) 1.163 + "[ \t\n\r\f\v]*" 1.164 + "\\)" 1.165 + "\\(" 1.166 + (c-lang-const 1.167 + c-opt-after-id-concat-key) 1.168 + "\\)") 1.169 + limit t) 1.170 + (unless (progn 1.171 + (goto-char (match-beginning 0)) 1.172 + (c-skip-comments-and-strings limit)) 1.173 + (or (get-text-property (match-beginning 2) 'face) 1.174 + (c-put-font-lock-face (match-beginning 2) 1.175 + (match-end 2) 1.176 + c-reference-face-name)) 1.177 + (goto-char (match-end 1))))))))) 1.178 + )) 1.179 + 1.180 +;; Vala does not allow a leading qualifier operator. It also doesn't 1.181 +;; allow the ".*" construct of Java. So, we redo this regex without 1.182 +;; the "\\|\\*" regex. 1.183 +(c-lang-defconst c-identifier-key 1.184 + vala (concat "\\(" (c-lang-const c-symbol-key) "\\)" ; 1 1.185 + (concat "\\(" 1.186 + "[ \t\n\r\f\v]*" 1.187 + (c-lang-const c-opt-identifier-concat-key) 1.188 + "[ \t\n\r\f\v]*" 1.189 + (concat "\\(" 1.190 + "\\(" (c-lang-const c-symbol-key) "\\)" 1.191 + "\\)") 1.192 + "\\)*"))) 1.193 + 1.194 +;; Vala has a few rules that are slightly different than Java for 1.195 +;; operators. This also removed the Java's "super" and replaces it 1.196 +;; with the Vala's "base". 1.197 +(c-lang-defconst c-operators 1.198 + vala `((prefix "base"))) 1.199 + 1.200 +;; Vala directives ? 1.201 +;; (c-lang-defconst c-opt-cpp-prefix 1.202 +;; csharp "^\\s *#.*") 1.203 + 1.204 + 1.205 +;; Vala uses the following assignment operators 1.206 +(c-lang-defconst c-assignment-operators 1.207 + vala '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" 1.208 + "&=" "^=" "|=" "++" "--")) 1.209 + 1.210 +;; This defines the primative types for Vala 1.211 +(c-lang-defconst c-primitive-type-kwds 1.212 + vala '("void" "char" "int" "float" "double" "string")) 1.213 + 1.214 +;; The keywords that define that the following is a type, such as a 1.215 +;; class definition. 1.216 +(c-lang-defconst c-type-prefix-kwds 1.217 + vala '("class" "interface" "struct" "enum" "signal")) 1.218 + 1.219 +;; Type modifier keywords. They appear anywhere in types, but modifiy 1.220 +;; instead create one. 1.221 +(c-lang-defconst c-type-modifier-kwds 1.222 + vala '("const")) 1.223 + 1.224 +;; Structures that are similiar to classes. 1.225 +(c-lang-defconst c-class-decl-kwds 1.226 + vala '("class" "interface")) 1.227 + 1.228 +;; The various modifiers used for class and method descriptions. 1.229 +(c-lang-defconst c-modifier-kwds 1.230 + vala '("public" "partial" "private" "const" "abstract" 1.231 + "protected" "ref" "in" "out" "static" "virtual" 1.232 + "override" "params" "internal" "weak" "owned" 1.233 + "unowned")) 1.234 + 1.235 +;; We don't use the protection level stuff because it breaks the 1.236 +;; method indenting. Not sure why, though. 1.237 +(c-lang-defconst c-protection-kwds 1.238 + vala nil) 1.239 + 1.240 +;; Define the keywords that can have something following after them. 1.241 +(c-lang-defconst c-type-list-kwds 1.242 + vala '("struct" "class" "interface" "is" "as" 1.243 + "delegate" "event" "set" "get" "add" "remove" 1.244 + "callback" "signal" "var" "default")) 1.245 + 1.246 +;; This allows the classes after the : in the class declartion to be 1.247 +;; fontified. 1.248 +(c-lang-defconst c-typeless-decl-kwds 1.249 + vala '(":")) 1.250 + 1.251 +;; Sets up the enum to handle the list properly 1.252 +(c-lang-defconst c-brace-list-decl-kwds 1.253 + vala '("enum" "errordomain")) 1.254 + 1.255 +;; We need to remove Java's package keyword 1.256 +(c-lang-defconst c-ref-list-kwds 1.257 + vala '("using" "namespace" "construct")) 1.258 + 1.259 +;; Follow-on blocks that don't require a brace 1.260 +(c-lang-defconst c-block-stmt-2-kwds 1.261 + vala '("for" "if" "switch" "while" "catch" "foreach" "lock")) 1.262 + 1.263 +;; Statements that break out of braces 1.264 +(c-lang-defconst c-simple-stmt-kwds 1.265 + vala '("return" "continue" "break" "throw")) 1.266 + 1.267 +;; Statements that allow a label 1.268 +;; TODO? 1.269 +(c-lang-defconst c-before-label-kwds 1.270 + vala nil) 1.271 + 1.272 +;; Constant keywords 1.273 +(c-lang-defconst c-constant-kwds 1.274 + vala '("true" "false" "null")) 1.275 + 1.276 +;; Keywords that start "primary expressions." 1.277 +(c-lang-defconst c-primary-expr-kwds 1.278 + vala '("this" "base")) 1.279 + 1.280 +;; We need to treat namespace as an outer block to class indenting 1.281 +;; works properly. 1.282 +(c-lang-defconst c-other-block-decl-kwds 1.283 + vala '("namespace")) 1.284 + 1.285 +;; We need to include the "in" for the foreach 1.286 +(c-lang-defconst c-other-kwds 1.287 + vala '("in" "sizeof" "typeof")) 1.288 + 1.289 +(require 'cc-awk) 1.290 + 1.291 +(c-lang-defconst c-at-vsemi-p-fn 1.292 + vala 'c-awk-at-vsemi-p) 1.293 + 1.294 + 1.295 +(defcustom vala-font-lock-extra-types nil 1.296 + "*List of extra types (aside from the type keywords) to recognize in Vala mode. 1.297 +Each list item should be a regexp matching a single identifier.") 1.298 + 1.299 +(defconst vala-font-lock-keywords-1 (c-lang-const c-matchers-1 vala) 1.300 + "Minimal highlighting for Vala mode.") 1.301 + 1.302 +(defconst vala-font-lock-keywords-2 (c-lang-const c-matchers-2 vala) 1.303 + "Fast normal highlighting for Vala mode.") 1.304 + 1.305 +(defconst vala-font-lock-keywords-3 (c-lang-const c-matchers-3 vala) 1.306 + "Accurate normal highlighting for Vala mode.") 1.307 + 1.308 +(defvar vala-font-lock-keywords vala-font-lock-keywords-3 1.309 + "Default expressions to highlight in Vala mode.") 1.310 + 1.311 +(defvar vala-mode-syntax-table 1.312 + nil 1.313 + "Syntax table used in vala-mode buffers.") 1.314 +(or vala-mode-syntax-table 1.315 + (setq vala-mode-syntax-table 1.316 + (funcall (c-lang-const c-make-mode-syntax-table vala)))) 1.317 + 1.318 +(defvar vala-mode-abbrev-table nil 1.319 + "Abbreviation table used in vala-mode buffers.") 1.320 +(c-define-abbrev-table 'vala-mode-abbrev-table 1.321 + ;; Keywords that if they occur first on a line 1.322 + ;; might alter the syntactic context, and which 1.323 + ;; therefore should trig reindentation when 1.324 + ;; they are completed. 1.325 + '(("else" "else" c-electric-continued-statement 0) 1.326 + ("while" "while" c-electric-continued-statement 0) 1.327 + ("catch" "catch" c-electric-continued-statement 0) 1.328 + ("finally" "finally" c-electric-continued-statement 0))) 1.329 + 1.330 +(defvar vala-mode-map (let ((map (c-make-inherited-keymap))) 1.331 + ;; Add bindings which are only useful for Vala 1.332 + map) 1.333 + "Keymap used in vala-mode buffers.") 1.334 + 1.335 +;;(easy-menu-define vala-menu vala-mode-map "Vala Mode Commands" 1.336 +;; ;; Can use `vala' as the language for `c-mode-menu' 1.337 +;; ;; since its definition covers any language. In 1.338 +;; ;; this case the language is used to adapt to the 1.339 +;; ;; nonexistence of a cpp pass and thus removing some 1.340 +;; ;; irrelevant menu alternatives. 1.341 +;; (cons "Vala" (c-lang-const c-mode-menu vala))) 1.342 + 1.343 +;;; Autoload mode trigger 1.344 +(add-to-list 'auto-mode-alist '("\\.vala$" . vala-mode)) 1.345 +(add-to-list 'auto-mode-alist '("\\.vapi$" . vala-mode)) 1.346 + 1.347 +;; Custom variables 1.348 +(defcustom vala-mode-hook nil 1.349 + "*Hook called by `vala-mode'." 1.350 + :type 'hook 1.351 + :group 'c) 1.352 + 1.353 +;;; The entry point into the mode 1.354 +;;;###autoload 1.355 +(defun vala-mode () 1.356 + "Major mode for editing Vala code. 1.357 +This is a simple example of a separate mode derived from CC Mode 1.358 +to support a language with syntax similar to 1.359 +C#/C/C++/ObjC/Java/IDL/Pike. 1.360 + 1.361 +The hook `c-mode-common-hook' is run with no args at mode 1.362 +initialization, then `vala-mode-hook'. 1.363 + 1.364 +Key bindings: 1.365 +\\{vala-mode-map}" 1.366 + (interactive) 1.367 + (kill-all-local-variables) 1.368 + (c-initialize-cc-mode t) 1.369 + (set-syntax-table vala-mode-syntax-table) 1.370 + (setq major-mode 'vala-mode 1.371 + mode-name "Vala" 1.372 + local-abbrev-table vala-mode-abbrev-table 1.373 + abbrev-mode t) 1.374 + (use-local-map c-mode-map) 1.375 + ;; `c-init-language-vars' is a macro that is expanded at compile 1.376 + ;; time to a large `setq' with all the language variables and their 1.377 + ;; customized values for our language. 1.378 + (c-init-language-vars vala-mode) 1.379 + ;; `c-common-init' initializes most of the components of a CC Mode 1.380 + ;; buffer, including setup of the mode menu, font-lock, etc. 1.381 + ;; There's also a lower level routine `c-basic-common-init' that 1.382 + ;; only makes the necessary initialization to get the syntactic 1.383 + ;; analysis and similar things working. 1.384 + (c-common-init 'vala-mode) 1.385 + ;;(easy-menu-add vala-menu) 1.386 + (c-set-style "linux") 1.387 + (setq indent-tabs-mode t) 1.388 + (setq c-basic-offset 4) 1.389 + (setq tab-width 4) 1.390 + (c-toggle-auto-newline -1) 1.391 + (c-toggle-hungry-state -1) 1.392 + (run-hooks 'c-mode-common-hook) 1.393 + (run-hooks 'vala-mode-hook) 1.394 + (c-update-modeline)) 1.395 + 1.396 +(provide 'vala-mode) 1.397 + 1.398 +;;; vala-mode.el ends here