]> git.r.bdr.sh - rbdr/dotfiles/blob - vim/syntax_checkers/lua.vim
03acb0889be832f1f685b365c8ee9a95ead2df84
[rbdr/dotfiles] / vim / syntax_checkers / lua.vim
1 "============================================================================
2 "File: lua.vim
3 "Description: Syntax checking plugin for syntastic.vim
4 "Maintainer: Gregor Uhlenheuer <kongo2002 at gmail dot com>
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 "============================================================================
12
13 if exists('loaded_lua_syntax_checker')
14 finish
15 endif
16 let loaded_lua_syntax_checker = 1
17
18 " check if the lua compiler is installed
19 if !executable('luac')
20 finish
21 endif
22
23 function! SyntaxCheckers_lua_Term(pos)
24 let near = matchstr(a:pos['text'], "near '[^']\\+'")
25 let result = ''
26 if len(near) > 0
27 let near = split(near, "'")[1]
28 if near == '<eof>'
29 let p = getpos('$')
30 let a:pos['lnum'] = p[1]
31 let a:pos['col'] = p[2]
32 let result = '\%'.p[2].'c'
33 else
34 let result = '\V'.near
35 endif
36 let open = matchstr(a:pos['text'], "(to close '[^']\\+' at line [0-9]\\+)")
37 if len(open) > 0
38 let oline = split(open, "'")[1:2]
39 let line = 0+strpart(oline[1], 9)
40 call matchadd('SpellCap', '\%'.line.'l\V'.oline[0])
41 endif
42 endif
43 return result
44 endfunction
45
46 function! SyntaxCheckers_lua_GetLocList()
47 let makeprg = 'luac -p ' . shellescape(expand('%'))
48 let errorformat = 'luac: %#%f:%l: %m'
49
50 let loclist = SyntasticMake({ 'makeprg': makeprg,
51 \ 'errorformat': errorformat,
52 \ 'defaults': { 'bufnr': bufnr(''), 'type': 'E' } })
53
54 call SyntasticHighlightErrors(loclist, function("SyntaxCheckers_lua_Term"))
55
56 return loclist
57 endfunction
58