syntastic/syntax_checkers/c.vim

120 lines
4.3 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.
"
"============================================================================
2010-07-01 15:13:45 -04:00
" 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
"
2010-07-01 15:13:45 -04:00
" To disable the search of included header files after special
" libraries like gtk and glib add this line to your .vimrc:
"
" let g:syntastic_c_no_include_search = 1
"
2010-07-01 15:13:45 -04:00
" To enable header files being re-checked on every file write add the
" following line to your .vimrc. Otherwise the header files are checked only
" one time on initially loading the file.
" In order to force syntastic to refresh the header includes simply
" unlet b:syntastic_c_includes. Then the header files are being re-checked on
" the next file write.
"
2010-07-01 15:21:29 -04:00
" let g:syntastic_c_auto_refresh_includes = 1
"
2010-07-01 15:13:45 -04:00
" Alternatively you can set the buffer local variable b:syntastic_c_cflags.
" If this variable is set for the current buffer no search for additional
" libraries is done. I.e. set the variable like this:
"
" let b:syntastic_c_cflags = ' -I/usr/include/libsoup-2.4'
2011-08-07 08:25:42 -04:00
"
" In order to add some custom include directories that should be added to the
" gcc command line you can add those to the global variable
" g:syntastic_c_include_dirs. This list can be used like this:
"
" let g:syntastic_c_include_dirs = [ 'includes', 'headers' ]
" Moreover it is possible to add additional compiler options to the syntax
" checking execution via the variable 'g:syntastic_c_compiler_options':
"
" let g:syntastic_c_compiler_options = ' -ansi'
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
let s:save_cpo = &cpo
set cpo&vim
2011-08-07 08:38:55 -04:00
let s:default_includes = [ '.', '..', 'include', 'includes',
\ '../include', '../includes' ]
function! s:GetIncludeDirs()
let include_dirs = s:default_includes
if exists('g:syntastic_c_include_dirs')
2011-08-07 08:37:34 -04:00
" TODO: check for duplicates
call extend(include_dirs, g:syntastic_c_include_dirs)
endif
return join(map(copy(include_dirs), '"-I" . v:val'), ' ')
endfunction
function! SyntaxCheckers_c_GetLocList()
let makeprg = 'gcc -fsyntax-only '.shellescape(expand('%')).
\ ' '.s:GetIncludeDirs()
2010-09-24 12:48:17 -04:00
let errorformat = '%-G%f:%s:,%-G%f:%l: %#error: %#(Each undeclared '.
\ 'identifier is reported only%.%#,%-G%f:%l: %#error: %#for '.
\ 'each function it appears%.%#,%-GIn file included%.%#,'.
\ '%-G %#from %f:%l\,,%f:%l:%c: %m,%f:%l: %trror: %m,%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 '.shellescape(expand('%')).
\ ' '.s:GetIncludeDirs()
else
return []
endif
endif
if exists('g:syntastic_c_compiler_options')
let makeprg .= g:syntastic_c_compiler_options
endif
if !exists('b:syntastic_c_cflags')
if !exists('g:syntastic_c_no_include_search') ||
\ g:syntastic_c_no_include_search != 1
2010-07-01 15:21:29 -04:00
if exists('g:syntastic_c_auto_refresh_includes') &&
\ g:syntastic_c_auto_refresh_includes != 0
let makeprg .= syntastic#SearchHeaders()
else
2010-07-01 15:13:45 -04:00
if !exists('b:syntastic_c_includes')
let b:syntastic_c_includes = syntastic#SearchHeaders()
endif
2010-07-01 15:13:45 -04:00
let makeprg .= b:syntastic_c_includes
endif
endif
else
let makeprg .= b:syntastic_c_cflags
endif
2010-02-08 10:44:31 -05:00
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
endfunction
2010-02-08 10:44:31 -05:00
let &cpo = s:save_cpo
unlet s:save_cpo
2011-09-09 15:36:36 -04:00
" vim: set et sts=4 sw=4: