Merge branch 'syntastic' into wip
authorJean Privat <jean@pryen.org>
Wed, 30 May 2012 16:39:32 +0000 (12:39 -0400)
committerJean Privat <jean@pryen.org>
Wed, 30 May 2012 16:39:32 +0000 (12:39 -0400)
misc/README
misc/vim/indent/nit.vim
misc/vim/syntax_checkers/nit.vim [new file with mode: 0644]

index 377f9b7..5166943 100644 (file)
@@ -1,4 +1,30 @@
-* gtksourceview (gedit and other GTK editors)
-  To install in your home, just link (or copy) the language definition file in ~/.local/share/gtksourceview-2.0/language-specs
+# gtksourceview (gedit and other GTK editors)
+To install in your home, just link (or copy) the language definition file in ~/.local/share/gtksourceview-2.0/language-specs
 
+# vim
 
+vim is a powerful text editor.
+The misc/vim directory contains the support of nit files to vim.
+
+### Install
+
+The simpler way to install nit for vim is with [pathogen][1].
+
+    cd ~/.vim/bundle
+    ln -s /full/path/to/nit/misc/vim nit
+
+Ensure that your .vimrc contains
+
+    call pathogen#infect()
+    syntax on
+    filetype plugin indent on
+
+  [1]: https://github.com/tpope/vim-pathogen
+
+### Features
+
+ * syntax highlighting
+ * indentation
+ * syntax checker (require [Syntastic][2]).
+
+  [2]: https://github.com/scrooloose/syntastic
index 51c1d53..afaa93a 100644 (file)
@@ -33,6 +33,11 @@ setlocal comments=:#
 setlocal indentkeys+==end,=else,=do,=var,0!,=then,=loop,=special,=class,=interface,=universal
 setlocal sw=8
 
+" Only define the function once.
+if exists("*GetNITIndent")
+       finish
+endif
+
 " Indent after
 let s:relative_indent = '\<\(do\|loop\|then\|else\|if\)\s*\(#\|$\)\|^\s*\(\<\(redef\|private\)\>\s*\)\?\(\<abstract\>\s*\)\?\<\(class\|interface\|universal\|special\)\>'
 " Unindent on them
@@ -52,11 +57,6 @@ function s:Match(lnum, regex)
        return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0
 endfunction
 
-" Only define the function once.
-if exists("*GetNITIndent")
-       finish
-endif
-
 function GetNITIndent()
        " Find a non-blank line above the current line.
        let plnum = prevnonblank(v:lnum - 1)
diff --git a/misc/vim/syntax_checkers/nit.vim b/misc/vim/syntax_checkers/nit.vim
new file mode 100644 (file)
index 0000000..222c080
--- /dev/null
@@ -0,0 +1,68 @@
+"============================================================================
+"File:        nit.vim
+"Description: Syntax checking plugin for syntastic.vim
+"Maintainer:  Alexis Laferrière <alexis.laf@xymus.net>
+"License:     This program is free software. It comes without any warranty,
+"             to the extent permitted by applicable law. You can redistribute
+"             it and/or modify it under the terms of the Do What The Fuck You
+"             Want To Public License, Version 2, as published by Sam Hocevar.
+"             See http://sam.zoy.org/wtfpl/COPYING for more details.
+"
+"      g:syntastic_nitc specifies custom path to compiler
+"      g:syntastic_nit_dir specifies the NIT_DIR env variable
+"      g:syntastic_nit_args specifies extra arguments to call nitc
+"      g:syntastic_nit_include_dirs lists directories to include, must be a list
+"============================================================================
+if exists("loaded_nit_syntax_checker")
+       finish
+endif
+let loaded_nit_syntax_checker = 1
+
+" check if nitc is accessible
+if exists('g:syntastic_nitc')
+       let s:nitc = g:syntastic_nitc
+else
+       let s:nitc = "nitc"
+endif
+
+if !executable(s:nitc)
+       if exists('g:syntastic_nitc')
+               echo "Syntastic for Nit error: Custom nitc cannot be found at: " . g:syntastic_nitc
+       endif
+       finish
+endif
+
+function! SyntaxCheckers_nit_GetLocList()
+       let makeprg = s:nitc . " --no-color --only-metamodel 2>&1 " . shellescape(expand("%"))
+
+       " custom NIT_DIR
+       if exists('g:syntastic_nit_dir')
+               let makeprg = "NIT_DIR=" . g:syntastic_nit_dir . " " . makeprg
+       endif
+
+       " custom options for nit compiler
+       if exists('g:syntastic_nit_options')
+               let makeprg .= " " . g:syntastic_nit_options
+       endif
+
+       " custom dirs to include for compiler
+       if exists('g:syntastic_nit_include_dirs')
+               for d in g:syntastic_nit_include_dirs
+                       let makeprg .= " -I " . d
+               endfor
+       end
+
+       " possible combinations of error messages
+       let ef_start = [ '%f:%l\,%c--%*[0-9]:', '%f:%l\,%c--%*[0-9]\,%*[0-9]:', '%f:%l\,%c:' ]
+       let ef_type = [ ' %tarning: ', '' ]
+
+       " generate errorformat from combinations
+       let errorformat = ""
+       for s in ef_start
+               for t in ef_type
+                       let errorformat .= s . t . '%m,'
+               endfor
+       endfor
+
+       return SyntasticMake({ 'makeprg': makeprg, 'errorformat':errorformat })
+endfunction