2009-12-20 12:26:58 -05:00
|
|
|
"============================================================================
|
|
|
|
"File: c.vim
|
|
|
|
"Description: Syntax checking plugin for syntastic.vim
|
2009-12-22 06:54:24 -05:00
|
|
|
"Maintainer: Gregor Uhlenheuer <kongo2002 at gmail dot com>
|
2009-12-20 12:26:58 -05:00
|
|
|
"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.
|
|
|
|
"
|
|
|
|
"============================================================================
|
2009-12-21 06:50:47 -05:00
|
|
|
|
2010-07-01 15:13:45 -04:00
|
|
|
" In order to also check header files add this to your .vimrc:
|
2009-12-21 06:50:47 -05:00
|
|
|
" (this usually creates a .gch file in your source directory)
|
|
|
|
"
|
|
|
|
" let g:syntastic_c_check_header = 1
|
2010-03-25 20:09:10 -04:00
|
|
|
"
|
2010-07-01 15:13:45 -04:00
|
|
|
" To disable the search of included header files after special
|
2010-03-25 20:09:10 -04:00
|
|
|
" libraries like gtk and glib add this line to your .vimrc:
|
|
|
|
"
|
|
|
|
" let g:syntastic_c_no_include_search = 1
|
2010-03-26 18:26:47 -04:00
|
|
|
"
|
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:07:24 -04:00
|
|
|
"
|
2010-07-01 15:21:29 -04:00
|
|
|
" let g:syntastic_c_auto_refresh_includes = 1
|
2010-07-01 15:07:24 -04:00
|
|
|
"
|
2010-07-01 15:13:45 -04:00
|
|
|
" Alternatively you can set the buffer local variable b:syntastic_c_cflags.
|
2010-03-26 18:26:47 -04:00
|
|
|
" 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' ]
|
2011-12-18 12:59:24 -05:00
|
|
|
"
|
2011-09-09 15:55:04 -04:00
|
|
|
" 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'
|
2011-12-18 12:59:24 -05:00
|
|
|
"
|
2012-03-27 16:26:15 -04:00
|
|
|
" Additionally the setting 'g:syntastic_c_config_file' allows you to define a
|
|
|
|
" file that contains additional compiler arguments like include directories or
|
|
|
|
" CFLAGS. The file is expected to contain one option per line. If none is
|
|
|
|
" given the filename defaults to '.syntastic_c_config':
|
|
|
|
"
|
|
|
|
" let g:syntastic_c_config_file = '.config'
|
|
|
|
"
|
2011-12-18 12:59:24 -05:00
|
|
|
" Using the global variable 'g:syntastic_c_remove_include_errors' you can
|
|
|
|
" specify whether errors of files included via the g:syntastic_c_include_dirs'
|
|
|
|
" setting are removed from the result set:
|
|
|
|
"
|
|
|
|
" let g:syntastic_c_remove_include_errors = 1
|
2009-12-21 06:50:47 -05:00
|
|
|
|
2009-12-20 14:08:31 -05:00
|
|
|
if exists('loaded_c_syntax_checker')
|
2009-12-20 12:26:58 -05:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let loaded_c_syntax_checker = 1
|
|
|
|
|
2009-12-20 14:08:31 -05:00
|
|
|
if !executable('gcc')
|
2009-12-20 12:26:58 -05:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2010-04-01 10:42:30 -04:00
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2012-03-11 14:40:53 -04:00
|
|
|
if !exists('g:syntastic_c_compiler_options')
|
|
|
|
let g:syntastic_c_compiler_options = '-std=gnu99'
|
|
|
|
endif
|
|
|
|
|
2012-03-27 16:26:15 -04:00
|
|
|
if !exists('g:syntastic_c_config_file')
|
|
|
|
let g:syntastic_c_config_file = '.syntastic_c_config'
|
|
|
|
endif
|
|
|
|
|
2009-12-20 12:26:58 -05:00
|
|
|
function! SyntaxCheckers_c_GetLocList()
|
2012-03-11 14:40:53 -04:00
|
|
|
let makeprg = 'gcc -fsyntax-only '
|
2010-09-24 12:48:17 -04:00
|
|
|
let errorformat = '%-G%f:%s:,%-G%f:%l: %#error: %#(Each undeclared '.
|
2011-04-08 14:57:37 -04:00
|
|
|
\ '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 12:26:58 -05:00
|
|
|
|
2012-03-11 14:35:52 -04:00
|
|
|
" add optional user-defined compiler options
|
2012-03-11 14:40:53 -04:00
|
|
|
let makeprg .= g:syntastic_c_compiler_options
|
2012-03-11 14:35:52 -04:00
|
|
|
|
|
|
|
let makeprg .= ' '.shellescape(expand('%')).
|
2012-03-11 14:55:01 -04:00
|
|
|
\ ' '.syntastic#c#GetIncludeDirs('c')
|
2012-03-11 14:35:52 -04:00
|
|
|
|
2011-12-18 12:25:07 -05:00
|
|
|
" determine whether to parse header files as well
|
2009-12-20 14:08:31 -05:00
|
|
|
if expand('%') =~? '.h$'
|
2009-12-20 13:19:53 -05:00
|
|
|
if exists('g:syntastic_c_check_header')
|
2011-08-07 08:22:32 -04:00
|
|
|
let makeprg = 'gcc -c '.shellescape(expand('%')).
|
2012-03-11 14:55:01 -04:00
|
|
|
\ ' '.syntastic#c#GetIncludeDirs('c')
|
2009-12-20 13:19:53 -05:00
|
|
|
else
|
|
|
|
return []
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2011-12-18 12:59:24 -05:00
|
|
|
" check if the user manually set some cflags
|
2010-03-26 18:26:47 -04:00
|
|
|
if !exists('b:syntastic_c_cflags')
|
2011-12-18 12:59:24 -05:00
|
|
|
" check whether to search for include files at all
|
2010-03-26 18:26:47 -04:00
|
|
|
if !exists('g:syntastic_c_no_include_search') ||
|
|
|
|
\ g:syntastic_c_no_include_search != 1
|
2011-12-18 12:59:24 -05:00
|
|
|
" refresh the include file search if desired
|
2010-07-01 15:21:29 -04:00
|
|
|
if exists('g:syntastic_c_auto_refresh_includes') &&
|
|
|
|
\ g:syntastic_c_auto_refresh_includes != 0
|
2011-11-30 17:13:16 -05:00
|
|
|
let makeprg .= syntastic#c#SearchHeaders()
|
2010-07-01 15:07:24 -04:00
|
|
|
else
|
2011-12-18 12:59:24 -05:00
|
|
|
" search for header includes if not cached already
|
2010-07-01 15:13:45 -04:00
|
|
|
if !exists('b:syntastic_c_includes')
|
2011-11-30 17:13:16 -05:00
|
|
|
let b:syntastic_c_includes = syntastic#c#SearchHeaders()
|
2010-07-01 15:07:24 -04:00
|
|
|
endif
|
2010-07-01 15:13:45 -04:00
|
|
|
let makeprg .= b:syntastic_c_includes
|
2010-07-01 15:07:24 -04:00
|
|
|
endif
|
2010-03-26 18:26:47 -04:00
|
|
|
endif
|
|
|
|
else
|
2011-12-18 12:59:24 -05:00
|
|
|
" use the user-defined cflags
|
2010-03-26 18:26:47 -04:00
|
|
|
let makeprg .= b:syntastic_c_cflags
|
2010-03-25 20:09:10 -04:00
|
|
|
endif
|
2010-02-08 10:44:31 -05:00
|
|
|
|
2012-03-27 16:26:15 -04:00
|
|
|
" add optional config file parameters
|
2012-03-28 08:22:17 -04:00
|
|
|
let makeprg .= ' '.syntastic#c#ReadConfig(g:syntastic_c_config_file)
|
2012-03-27 16:26:15 -04:00
|
|
|
|
2011-12-18 12:59:24 -05:00
|
|
|
" process makeprg
|
|
|
|
let errors = SyntasticMake({ 'makeprg': makeprg,
|
|
|
|
\ 'errorformat': errorformat })
|
|
|
|
|
|
|
|
" filter the processed errors if desired
|
|
|
|
if exists('g:syntastic_c_remove_include_errors') &&
|
|
|
|
\ g:syntastic_c_remove_include_errors != 0
|
|
|
|
return filter(errors,
|
|
|
|
\ 'has_key(v:val, "bufnr") && v:val["bufnr"]=='.bufnr(''))
|
|
|
|
else
|
|
|
|
return errors
|
|
|
|
endif
|
2009-12-20 12:26:58 -05:00
|
|
|
endfunction
|
2010-02-08 10:44:31 -05:00
|
|
|
|
2010-04-01 10:42:30 -04: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:
|