wok rev 8443

Add: emacs-pkg-vala-mode
author Dominique Corbex <domcox@slitaz.org>
date Sun Feb 06 21:13:45 2011 +0100 (2011-02-06)
parents f033d8c1c9f1
children 6d9995754b73
files emacs-pkg-vala-mode/receipt emacs-pkg-vala-mode/stuff/vala-init.el emacs-pkg-vala-mode/stuff/vala-mode.el
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/emacs-pkg-vala-mode/receipt	Sun Feb 06 21:13:45 2011 +0100
     1.3 @@ -0,0 +1,37 @@
     1.4 +# SliTaz package receipt.
     1.5 +
     1.6 +PACKAGE="emacs-pkg-vala-mode"
     1.7 +VERSION="0.1"
     1.8 +CATEGORY="development"
     1.9 +SHORT_DESC="An Emacs major mode for editing Vala code."
    1.10 +MAINTAINER="domcox@slitaz.org"
    1.11 +DEPENDS="emacs"
    1.12 +SOURCE="vala-mode"
    1.13 +TARBALL="$SOURCE-$VERSION.tar.gz"
    1.14 +WEB_SITE="http://live.gnome.org/Vala/Emacs"
    1.15 +TAGS="emacs vala"
    1.16 +
    1.17 +
    1.18 +# Rules to gen a SliTaz package suitable for Tazpkg.
    1.19 +genpkg_rules()
    1.20 +{
    1.21 +	echo -n "Installing vala-mode"
    1.22 +	mkdir -p $fs/usr/share/emacs/site-lisp/vala-mode && \
    1.23 +	cp stuff/vala-mode.el $fs/usr/share/emacs/site-lisp/vala-mode
    1.24 +	status
    1.25 +
    1.26 +	echo -n "Installing start file"
    1.27 +	mkdir -p $fs/usr/share/emacs/site-lisp/site-start.d && \
    1.28 +	cp stuff/vala-init.el $fs/usr/share/emacs/site-lisp/site-start.d
    1.29 +	status
    1.30 +}
    1.31 +
    1.32 +post_install()
    1.33 +{
    1.34 +	tazpkg reconfigure emacs
    1.35 +}
    1.36 +
    1.37 +post_remove()
    1.38 +{
    1.39 +	tazpkg reconfigure emacs
    1.40 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/emacs-pkg-vala-mode/stuff/vala-init.el	Sun Feb 06 21:13:45 2011 +0100
     2.3 @@ -0,0 +1,5 @@
     2.4 +;; Register vala-mode
     2.5 +
     2.6 +(autoload 'vala-mode "vala-mode" "Major mode for editing Vala code." t)
     2.7 +(add-to-list 'auto-mode-alist '("\\.vala$" . vala-mode))
     2.8 +(add-to-list 'auto-mode-alist '("\\.vapi$" . vala-mode))
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/emacs-pkg-vala-mode/stuff/vala-mode.el	Sun Feb 06 21:13:45 2011 +0100
     3.3 @@ -0,0 +1,395 @@
     3.4 +;;; vala-mode.el --- Vala mode derived mode
     3.5 +
     3.6 +;; Author:     2005 Dylan R. E. Moonfire
     3.7 +;;	       2008 Étienne BERSAC
     3.8 +;; Maintainer: Étienne BERSAC <bersace03@laposte.net>
     3.9 +;; Created:    2008 May the 4th
    3.10 +;; Modified:   May 2008
    3.11 +;; Version:    0.1
    3.12 +;; Keywords:   vala languages oop
    3.13 +
    3.14 +;; This program is free software; you can redistribute it and/or modify
    3.15 +;; it under the terms of the GNU General Public License as published by
    3.16 +;; the Free Software Foundation; either version 2 of the License, or
    3.17 +;; (at your option) any later version.
    3.18 +;; 
    3.19 +;; This program is distributed in the hope that it will be useful,
    3.20 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.21 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.22 +;; GNU General Public License for more details.
    3.23 +;; 
    3.24 +;; You should have received a copy of the GNU General Public License
    3.25 +;; along with this program; see the file COPYING.  If not, write to
    3.26 +;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    3.27 +;; Boston, MA 02111-1307, USA.
    3.28 +
    3.29 +;;; Commentary:
    3.30 +;;
    3.31 +;;    See http://live.gnome.org/Vala for details about Vala language.
    3.32 +;;
    3.33 +;;    This is a separate mode to implement the Vala constructs and
    3.34 +;;    font-locking. It is mostly the csharp-mode from
    3.35 +;;    http://mfgames.com/linux/csharp-mode with vala specific keywords
    3.36 +;;    and filename suffixes.
    3.37 +;;
    3.38 +;;    Note: The interface used in this file requires CC Mode 5.30 or
    3.39 +;;    later.
    3.40 +
    3.41 +;;; .emacs (don't put in (require 'vala-mode))
    3.42 +;; (autoload 'vala-mode "vala-mode" "Major mode for editing Vala code." t)
    3.43 +;; (setq auto-mode-alist
    3.44 +;;    (append '(("\\.vala$" . vala-mode)) auto-mode-alist))
    3.45 +
    3.46 +;;; Versions:
    3.47 +;;
    3.48 +;;	0.1	: Initial version based on csharp-mode
    3.49 +;;
    3.50 +
    3.51 +;; This is a copy of the function in cc-mode which is used to handle
    3.52 +;; the eval-when-compile which is needed during other times.
    3.53 +(defun c-filter-ops (ops opgroup-filter op-filter &optional xlate)
    3.54 +  ;; See cc-langs.el, a direct copy.
    3.55 +  (unless (listp (car-safe ops))
    3.56 +    (setq ops (list ops)))
    3.57 +  (cond ((eq opgroup-filter t)
    3.58 +	 (setq opgroup-filter (lambda (opgroup) t)))
    3.59 +	((not (functionp opgroup-filter))
    3.60 +	 (setq opgroup-filter `(lambda (opgroup)
    3.61 +				 (memq opgroup ',opgroup-filter)))))
    3.62 +  (cond ((eq op-filter t)
    3.63 +	 (setq op-filter (lambda (op) t)))
    3.64 +	((stringp op-filter)
    3.65 +	 (setq op-filter `(lambda (op)
    3.66 +			    (string-match ,op-filter op)))))
    3.67 +  (unless xlate
    3.68 +    (setq xlate 'identity))
    3.69 +  (c-with-syntax-table (c-lang-const c-mode-syntax-table)
    3.70 +    (delete-duplicates
    3.71 +     (mapcan (lambda (opgroup)
    3.72 +	       (when (if (symbolp (car opgroup))
    3.73 +			 (when (funcall opgroup-filter (car opgroup))
    3.74 +			   (setq opgroup (cdr opgroup))
    3.75 +			   t)
    3.76 +		       t)
    3.77 +		 (mapcan (lambda (op)
    3.78 +			   (when (funcall op-filter op)
    3.79 +			     (let ((res (funcall xlate op)))
    3.80 +			       (if (listp res) res (list res)))))
    3.81 +			 opgroup)))
    3.82 +	     ops)
    3.83 +     :test 'equal)))
    3.84 +
    3.85 +;; This inserts the bulk of the code.
    3.86 +(require 'cc-mode)
    3.87 +
    3.88 +;; These are only required at compile time to get the sources for the
    3.89 +;; language constants.  (The cc-fonts require and the font-lock
    3.90 +;; related constants could additionally be put inside an
    3.91 +;; (eval-after-load "font-lock" ...) but then some trickery is
    3.92 +;; necessary to get them compiled.)
    3.93 +(eval-when-compile
    3.94 +  (let ((load-path
    3.95 +	 (if (and (boundp 'byte-compile-dest-file)
    3.96 +		  (stringp byte-compile-dest-file))
    3.97 +	     (cons (file-name-directory byte-compile-dest-file) load-path)
    3.98 +	   load-path)))
    3.99 +    (load "cc-mode" nil t)
   3.100 +    (load "cc-fonts" nil t)
   3.101 +    (load "cc-langs" nil t)))
   3.102 +
   3.103 +(eval-and-compile
   3.104 +  ;; Make our mode known to the language constant system.  Use Java
   3.105 +  ;; mode as the fallback for the constants we don't change here.
   3.106 +  ;; This needs to be done also at compile time since the language
   3.107 +  ;; constants are evaluated then.
   3.108 +  (c-add-language 'vala-mode 'java-mode))
   3.109 +
   3.110 +;; Java uses a series of regexes to change the font-lock for class
   3.111 +;; references. The problem comes in because Java uses Pascal (leading
   3.112 +;; space in names, SomeClass) for class and package names, but
   3.113 +;; Camel-casing (initial lowercase, upper case in words,
   3.114 +;; i.e. someVariable) for variables.
   3.115 +;;(error (byte-compile-dest-file))
   3.116 +;;(error (c-get-current-file))
   3.117 +(c-lang-defconst c-opt-after-id-concat-key
   3.118 +  vala (if (c-lang-const c-opt-identifier-concat-key)
   3.119 +	   (c-lang-const c-symbol-start)))
   3.120 +
   3.121 +(c-lang-defconst c-basic-matchers-before
   3.122 +  vala `(
   3.123 +;;;; Font-lock the attributes by searching for the
   3.124 +;;;; appropriate regex and marking it as TODO.
   3.125 +	 ;;,`(,(concat "\\(" vala-attribute-regex "\\)")
   3.126 +	 ;;   0 font-lock-function-name-face)	   
   3.127 +
   3.128 +	 ;; Put a warning face on the opener of unclosed strings that
   3.129 +	 ;; can't span lines.  Later font
   3.130 +	 ;; lock packages have a `font-lock-syntactic-face-function' for
   3.131 +	 ;; this, but it doesn't give the control we want since any
   3.132 +	 ;; fontification done inside the function will be
   3.133 +	 ;; unconditionally overridden.
   3.134 +	 ,(c-make-font-lock-search-function
   3.135 +	   ;; Match a char before the string starter to make
   3.136 +	   ;; `c-skip-comments-and-strings' work correctly.
   3.137 +	   (concat ".\\(" c-string-limit-regexp "\\)")
   3.138 +	   '((c-font-lock-invalid-string)))
   3.139 +	   
   3.140 +	 ;; Fontify keyword constants.
   3.141 +	 ,@(when (c-lang-const c-constant-kwds)
   3.142 +	     (let ((re (c-make-keywords-re nil
   3.143 +			 (c-lang-const c-constant-kwds))))
   3.144 +	       `((eval . (list ,(concat "\\<\\(" re "\\)\\>")
   3.145 +			       1 c-constant-face-name)))))
   3.146 +	   
   3.147 +	 ;; Fontify all keywords except the primitive types.
   3.148 +	 ,`(,(concat "\\<" (c-lang-const c-regular-keywords-regexp))
   3.149 +	    1 font-lock-keyword-face)
   3.150 +
   3.151 +	 ;; Fontify leading identifiers in fully
   3.152 +	 ;; qualified names like "Foo.Bar".
   3.153 +	 ,@(when (c-lang-const c-opt-identifier-concat-key)
   3.154 +	     `((,(byte-compile
   3.155 +		  `(lambda (limit)
   3.156 +		     (while (re-search-forward
   3.157 +			     ,(concat "\\(\\<" ; 1
   3.158 +				      "\\(" (c-lang-const c-symbol-key)
   3.159 +				      "\\)" ; 2
   3.160 +				      "[ \t\n\r\f\v]*"
   3.161 +				      (c-lang-const
   3.162 +				       c-opt-identifier-concat-key)
   3.163 +				      "[ \t\n\r\f\v]*"
   3.164 +				      "\\)"
   3.165 +				      "\\("
   3.166 +				      (c-lang-const
   3.167 +				       c-opt-after-id-concat-key)
   3.168 +				      "\\)")
   3.169 +			     limit t)
   3.170 +		       (unless (progn
   3.171 +				 (goto-char (match-beginning 0))
   3.172 +				 (c-skip-comments-and-strings limit))
   3.173 +			 (or (get-text-property (match-beginning 2) 'face)
   3.174 +			     (c-put-font-lock-face (match-beginning 2)
   3.175 +						   (match-end 2)
   3.176 +						   c-reference-face-name))
   3.177 +			 (goto-char (match-end 1)))))))))
   3.178 +	 ))
   3.179 +
   3.180 +;; Vala does not allow a leading qualifier operator. It also doesn't
   3.181 +;; allow the ".*" construct of Java. So, we redo this regex without
   3.182 +;; the "\\|\\*" regex.
   3.183 +(c-lang-defconst c-identifier-key
   3.184 +  vala (concat "\\(" (c-lang-const c-symbol-key) "\\)" ; 1
   3.185 +	       (concat "\\("
   3.186 +		       "[ \t\n\r\f\v]*"
   3.187 +		       (c-lang-const c-opt-identifier-concat-key)
   3.188 +		       "[ \t\n\r\f\v]*"
   3.189 +		       (concat "\\("
   3.190 +			       "\\(" (c-lang-const c-symbol-key) "\\)"
   3.191 +			       "\\)")
   3.192 +		       "\\)*")))
   3.193 +
   3.194 +;; Vala has a few rules that are slightly different than Java for
   3.195 +;; operators. This also removed the Java's "super" and replaces it
   3.196 +;; with the Vala's "base".
   3.197 +(c-lang-defconst c-operators
   3.198 +  vala `((prefix "base")))
   3.199 +
   3.200 +;; Vala directives ?
   3.201 +;; (c-lang-defconst c-opt-cpp-prefix
   3.202 +;;   csharp "^\\s *#.*")
   3.203 +
   3.204 +
   3.205 +;; Vala uses the following assignment operators
   3.206 +(c-lang-defconst c-assignment-operators
   3.207 +  vala '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<="
   3.208 +	 "&=" "^=" "|=" "++" "--"))
   3.209 +
   3.210 +;; This defines the primative types for Vala
   3.211 +(c-lang-defconst c-primitive-type-kwds
   3.212 +  vala '("void" "char" "int" "float" "double" "string"))
   3.213 +
   3.214 +;; The keywords that define that the following is a type, such as a
   3.215 +;; class definition.
   3.216 +(c-lang-defconst c-type-prefix-kwds
   3.217 +  vala '("class" "interface" "struct" "enum" "signal"))
   3.218 +
   3.219 +;; Type modifier keywords. They appear anywhere in types, but modifiy
   3.220 +;; instead create one.
   3.221 +(c-lang-defconst c-type-modifier-kwds
   3.222 +  vala '("const"))
   3.223 +
   3.224 +;; Structures that are similiar to classes.
   3.225 +(c-lang-defconst c-class-decl-kwds
   3.226 +  vala '("class" "interface"))
   3.227 +
   3.228 +;; The various modifiers used for class and method descriptions.
   3.229 +(c-lang-defconst c-modifier-kwds
   3.230 +  vala '("public" "partial" "private" "const" "abstract"
   3.231 +	 "protected" "ref" "in" "out" "static" "virtual"
   3.232 +	 "override" "params" "internal" "weak" "owned"
   3.233 +	 "unowned"))
   3.234 +
   3.235 +;; We don't use the protection level stuff because it breaks the
   3.236 +;; method indenting. Not sure why, though.
   3.237 +(c-lang-defconst c-protection-kwds
   3.238 +  vala nil)
   3.239 +
   3.240 +;; Define the keywords that can have something following after them.
   3.241 +(c-lang-defconst c-type-list-kwds
   3.242 +  vala '("struct" "class" "interface" "is" "as"
   3.243 +	 "delegate" "event" "set" "get" "add" "remove"
   3.244 +	 "callback" "signal" "var" "default"))
   3.245 +
   3.246 +;; This allows the classes after the : in the class declartion to be
   3.247 +;; fontified. 
   3.248 +(c-lang-defconst c-typeless-decl-kwds
   3.249 +  vala '(":"))
   3.250 +
   3.251 +;; Sets up the enum to handle the list properly
   3.252 +(c-lang-defconst c-brace-list-decl-kwds
   3.253 +  vala '("enum" "errordomain"))
   3.254 +
   3.255 +;; We need to remove Java's package keyword
   3.256 +(c-lang-defconst c-ref-list-kwds
   3.257 +  vala '("using" "namespace" "construct"))
   3.258 +
   3.259 +;; Follow-on blocks that don't require a brace
   3.260 +(c-lang-defconst c-block-stmt-2-kwds
   3.261 +  vala '("for" "if" "switch" "while" "catch" "foreach" "lock"))
   3.262 +
   3.263 +;; Statements that break out of braces
   3.264 +(c-lang-defconst c-simple-stmt-kwds
   3.265 +  vala '("return" "continue" "break" "throw"))
   3.266 +
   3.267 +;; Statements that allow a label
   3.268 +;; TODO?
   3.269 +(c-lang-defconst c-before-label-kwds
   3.270 +  vala nil)
   3.271 +
   3.272 +;; Constant keywords
   3.273 +(c-lang-defconst c-constant-kwds
   3.274 +  vala '("true" "false" "null"))
   3.275 +
   3.276 +;; Keywords that start "primary expressions."
   3.277 +(c-lang-defconst c-primary-expr-kwds
   3.278 +  vala '("this" "base"))
   3.279 +
   3.280 +;; We need to treat namespace as an outer block to class indenting
   3.281 +;; works properly.
   3.282 +(c-lang-defconst c-other-block-decl-kwds
   3.283 +  vala '("namespace"))
   3.284 +
   3.285 +;; We need to include the "in" for the foreach
   3.286 +(c-lang-defconst c-other-kwds
   3.287 +  vala '("in" "sizeof" "typeof"))
   3.288 +
   3.289 +(require 'cc-awk)
   3.290 +
   3.291 +(c-lang-defconst c-at-vsemi-p-fn
   3.292 +  vala 'c-awk-at-vsemi-p)
   3.293 +
   3.294 +
   3.295 +(defcustom vala-font-lock-extra-types nil
   3.296 +  "*List of extra types (aside from the type keywords) to recognize in Vala mode.
   3.297 +Each list item should be a regexp matching a single identifier.")
   3.298 +
   3.299 +(defconst vala-font-lock-keywords-1 (c-lang-const c-matchers-1 vala)
   3.300 +  "Minimal highlighting for Vala mode.")
   3.301 +
   3.302 +(defconst vala-font-lock-keywords-2 (c-lang-const c-matchers-2 vala)
   3.303 +  "Fast normal highlighting for Vala mode.")
   3.304 +
   3.305 +(defconst vala-font-lock-keywords-3 (c-lang-const c-matchers-3 vala)
   3.306 +  "Accurate normal highlighting for Vala mode.")
   3.307 +
   3.308 +(defvar vala-font-lock-keywords vala-font-lock-keywords-3
   3.309 +  "Default expressions to highlight in Vala mode.")
   3.310 +
   3.311 +(defvar vala-mode-syntax-table
   3.312 +  nil
   3.313 +  "Syntax table used in vala-mode buffers.")
   3.314 +(or vala-mode-syntax-table
   3.315 +    (setq vala-mode-syntax-table
   3.316 +	  (funcall (c-lang-const c-make-mode-syntax-table vala))))
   3.317 +
   3.318 +(defvar vala-mode-abbrev-table nil
   3.319 +  "Abbreviation table used in vala-mode buffers.")
   3.320 +(c-define-abbrev-table 'vala-mode-abbrev-table
   3.321 +  ;; Keywords that if they occur first on a line
   3.322 +  ;; might alter the syntactic context, and which
   3.323 +  ;; therefore should trig reindentation when
   3.324 +  ;; they are completed.
   3.325 +  '(("else" "else" c-electric-continued-statement 0)
   3.326 +    ("while" "while" c-electric-continued-statement 0)
   3.327 +    ("catch" "catch" c-electric-continued-statement 0)
   3.328 +    ("finally" "finally" c-electric-continued-statement 0)))
   3.329 +
   3.330 +(defvar vala-mode-map (let ((map (c-make-inherited-keymap)))
   3.331 +			;; Add bindings which are only useful for Vala
   3.332 +			map)
   3.333 +  "Keymap used in vala-mode buffers.")
   3.334 +
   3.335 +;;(easy-menu-define vala-menu vala-mode-map "Vala Mode Commands"
   3.336 +;;		  ;; Can use `vala' as the language for `c-mode-menu'
   3.337 +;;		  ;; since its definition covers any language.  In
   3.338 +;;		  ;; this case the language is used to adapt to the
   3.339 +;;		  ;; nonexistence of a cpp pass and thus removing some
   3.340 +;;		  ;; irrelevant menu alternatives.
   3.341 +;;		  (cons "Vala" (c-lang-const c-mode-menu vala)))
   3.342 +
   3.343 +;;; Autoload mode trigger
   3.344 +(add-to-list 'auto-mode-alist '("\\.vala$" . vala-mode))
   3.345 +(add-to-list 'auto-mode-alist '("\\.vapi$" . vala-mode))
   3.346 +
   3.347 +;; Custom variables
   3.348 +(defcustom vala-mode-hook nil
   3.349 +  "*Hook called by `vala-mode'."
   3.350 +  :type 'hook
   3.351 +  :group 'c)
   3.352 +
   3.353 +;;; The entry point into the mode
   3.354 +;;;###autoload
   3.355 +(defun vala-mode ()
   3.356 +  "Major mode for editing Vala code.
   3.357 +This is a simple example of a separate mode derived from CC Mode
   3.358 +to support a language with syntax similar to
   3.359 +C#/C/C++/ObjC/Java/IDL/Pike.
   3.360 +
   3.361 +The hook `c-mode-common-hook' is run with no args at mode
   3.362 +initialization, then `vala-mode-hook'.
   3.363 +
   3.364 +Key bindings:
   3.365 +\\{vala-mode-map}"
   3.366 +  (interactive)
   3.367 +  (kill-all-local-variables)
   3.368 +  (c-initialize-cc-mode t)
   3.369 +  (set-syntax-table vala-mode-syntax-table)
   3.370 +  (setq major-mode 'vala-mode
   3.371 +	mode-name "Vala"
   3.372 +	local-abbrev-table vala-mode-abbrev-table
   3.373 +	abbrev-mode t)
   3.374 +  (use-local-map c-mode-map)
   3.375 +  ;; `c-init-language-vars' is a macro that is expanded at compile
   3.376 +  ;; time to a large `setq' with all the language variables and their
   3.377 +  ;; customized values for our language.
   3.378 +  (c-init-language-vars vala-mode)
   3.379 +  ;; `c-common-init' initializes most of the components of a CC Mode
   3.380 +  ;; buffer, including setup of the mode menu, font-lock, etc.
   3.381 +  ;; There's also a lower level routine `c-basic-common-init' that
   3.382 +  ;; only makes the necessary initialization to get the syntactic
   3.383 +  ;; analysis and similar things working.
   3.384 +  (c-common-init 'vala-mode)
   3.385 +  ;;(easy-menu-add vala-menu)
   3.386 +  (c-set-style "linux")
   3.387 +  (setq indent-tabs-mode t)
   3.388 +  (setq c-basic-offset 4)
   3.389 +  (setq tab-width 4)
   3.390 +  (c-toggle-auto-newline -1)
   3.391 +  (c-toggle-hungry-state -1)
   3.392 +  (run-hooks 'c-mode-common-hook)
   3.393 +  (run-hooks 'vala-mode-hook)
   3.394 +  (c-update-modeline))
   3.395 +
   3.396 +(provide 'vala-mode)
   3.397 +
   3.398 +;;; vala-mode.el ends here