misc: update vim syntastic plugin to latest specification
[nit.git] / misc / vim / syntax_checkers / nit / nitc.vim
1 "============================================================================
2 "File:        nit.vim
3 "Description: Syntax checking plugin for syntastic.vim
4 "Maintainer:  Alexis Laferrière <alexis.laf@xymus.net>
5 "License:     This program is free software. It comes without any warranty,
6 "             to the extent permitted by applicable law. You can redistribute
7 "             it and/or modify it under the terms of the Do What The Fuck You
8 "             Want To Public License, Version 2, as published by Sam Hocevar.
9 "             See http://sam.zoy.org/wtfpl/COPYING for more details.
10 "
11 "       g:syntastic_nitc specifies custom path to compiler
12 "       g:syntastic_nit_dir specifies the NIT_DIR env variable
13 "       g:syntastic_nit_args specifies extra arguments to call nitc
14 "       g:syntastic_nit_include_dirs lists directories to include, must be a list
15 "============================================================================
16 if exists("loaded_syntastic_nit_nitc_checker")
17         finish
18 endif
19 let loaded_syntastic_nit_nitc_checker = 1
20
21 " check if nitc is accessible
22 if exists('g:syntastic_nitc')
23         let s:nitc = g:syntastic_nitc
24 else
25         let s:nitc = "nitc"
26 endif
27
28 if !executable(s:nitc)
29         if exists('g:syntastic_nitc')
30                 echo "Syntastic for Nit error: Custom nitc cannot be found at: " . g:syntastic_nitc
31         endif
32         finish
33 endif
34
35 function! SyntaxCheckers_nit_nitc_IsAvailable()
36     return executable(expand(s:nitc))
37 endfunction
38
39 function! SyntaxCheckers_nit_nitc_GetLocList()
40         let makeprg = s:nitc . " --no-color --only-metamodel 2>&1 " . shellescape(expand("%"))
41
42         " custom NIT_DIR
43         if exists('g:syntastic_nit_dir')
44                 let makeprg = "NIT_DIR=" . g:syntastic_nit_dir . " " . makeprg
45         endif
46
47         " custom options for nit compiler
48         if exists('g:syntastic_nit_options')
49                 let makeprg .= " " . g:syntastic_nit_options
50         endif
51
52         " custom dirs to include for compiler
53         if exists('g:syntastic_nit_include_dirs')
54                 for d in g:syntastic_nit_include_dirs
55                         let makeprg .= " -I " . d
56                 endfor
57         end
58
59         " possible combinations of error messages
60         let ef_start = [ '%f:%l\,%c--%*[0-9]:', '%f:%l\,%c--%*[0-9]\,%*[0-9]:', '%f:%l\,%c:' ]
61         let ef_type = [ ' %tarning: ', '' ]
62
63         " generate errorformat from combinations
64         let errorformat = ""
65         for s in ef_start
66                 for t in ef_type
67                         let errorformat .= s . t . '%m,'
68                 endfor
69         endfor
70
71         return SyntasticMake({ 'makeprg': makeprg, 'errorformat':errorformat })
72 endfunction
73
74 call g:SyntasticRegistry.CreateAndRegisterChecker({
75     \ 'filetype': 'nit',
76     \ 'name': 'nitc'})