syntastic/syntax_checkers/c.vim

61 lines
2.0 KiB
VimL
Raw Normal View History

"============================================================================
"File: c.vim
"Description: Syntax checking plugin for syntastic.vim
"Maintainer: Gregor Uhlenheuer <kongo2002 at gmail dot com>
"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.
"
"============================================================================
" in order to also check header files add this to your .vimrc:
" (this usually creates a .gch file in your source directory)
"
" let g:syntastic_c_check_header = 1
2009-12-20 14:08:31 -05:00
if exists('loaded_c_syntax_checker')
finish
endif
let loaded_c_syntax_checker = 1
2009-12-20 14:08:31 -05:00
if !executable('gcc')
finish
endif
function! SyntaxCheckers_c_GetLocList()
2009-12-20 13:02:08 -05:00
let makeprg = 'gcc -fsyntax-only %'
let errorformat = '%-G%f:%s:,%f:%l: %m'
2009-12-20 14:08:31 -05:00
if expand('%') =~? '.h$'
if exists('g:syntastic_c_check_header')
let makeprg = 'gcc -c %'
else
return []
endif
endif
2010-02-08 10:44:31 -05:00
let makeprg .= s:CheckGtk()
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
endfunction
2010-02-08 10:44:31 -05:00
" search for a gtk include statement in the first 50 lines
" if true, try to find the gtk headers with 'pkg-config'
function! s:CheckGtk()
if executable('pkg-config')
for i in range(50)
2010-02-08 11:02:33 -05:00
if getline(i) =~? '^#include.*\%(gtk\|glib\)'
2010-02-08 10:44:31 -05:00
if !exists('s:gtk_flags')
let s:gtk_flags = system('pkg-config --cflags gtk+-2.0')
2010-03-25 18:18:45 -04:00
let s:gtk_flags = substitute(s:gtk_flags, "\n", '', '')
2010-02-08 10:44:31 -05:00
let s:gtk_flags = ' '.s:gtk_flags
endif
return s:gtk_flags
endif
endfor
endif
return ''
endfunction