add include directory functionality to cpp

This commit is contained in:
kongo2002 2012-03-04 19:59:26 +01:00
parent 630a57dfef
commit 8e2634ae7e
3 changed files with 40 additions and 31 deletions

View File

@ -38,6 +38,40 @@ function! s:Init()
call s:RegHandler('php\.h', 'syntastic#c#CheckPhp', [])
endfunction
" default include directories
let s:default_includes = [ '.', '..', 'include', 'includes',
\ '../include', '../includes' ]
" uniquify the input list
function! s:Unique(list)
let l = []
for elem in a:list
if index(l, elem) == -1
let l = add(l, elem)
endif
endfor
return l
endfunction
" get the gcc include directory argument depending on the default
" includes and the optional user-defined 'g:syntastic_c_include_dirs'
function! syntastic#c#GetIncludeDirs(cpp)
let include_dirs = copy(s:default_includes)
if a:cpp == 1
if exists('g:syntastic_cpp_include_dirs')
call extend(include_dirs, g:syntastic_cpp_include_dirs)
endif
else
if exists('g:syntastic_c_include_dirs')
call extend(include_dirs, g:syntastic_c_include_dirs)
endif
endif
return join(map(s:Unique(include_dirs), '"-I" . v:val'), ' ')
endfunction
" search the first 100 lines for include statements that are
" given in the handlers dictionary
function! syntastic#c#SearchHeaders()

View File

@ -64,36 +64,9 @@ endif
let s:save_cpo = &cpo
set cpo&vim
" default include directories
let s:default_includes = [ '.', '..', 'include', 'includes',
\ '../include', '../includes' ]
" uniquify the input list
function! s:Unique(list)
let l = []
for elem in a:list
if index(l, elem) == -1
let l = add(l, elem)
endif
endfor
return l
endfunction
" get the gcc include directory argument depending on the default
" includes and the optional user-defined 'g:syntastic_c_include_dirs'
function! s:GetIncludeDirs()
let include_dirs = s:default_includes
if exists('g:syntastic_c_include_dirs')
call extend(include_dirs, g:syntastic_c_include_dirs)
endif
return join(map(s:Unique(include_dirs), '"-I" . v:val'), ' ')
endfunction
function! SyntaxCheckers_c_GetLocList()
let makeprg = 'gcc -fsyntax-only -std=gnu99 '.shellescape(expand('%')).
\ ' '.s:GetIncludeDirs()
\ ' '.syntastic#c#GetIncludeDirs(0)
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%.%#,'.
@ -103,7 +76,7 @@ function! SyntaxCheckers_c_GetLocList()
if expand('%') =~? '.h$'
if exists('g:syntastic_c_check_header')
let makeprg = 'gcc -c '.shellescape(expand('%')).
\ ' '.s:GetIncludeDirs()
\ ' '.syntastic#c#GetIncludeDirs(0)
else
return []
endif

View File

@ -53,12 +53,14 @@ let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_cpp_GetLocList()
let makeprg = 'g++ -fsyntax-only '.shellescape(expand('%'))
let makeprg = 'g++ -fsyntax-only '.shellescape(expand('%')).
\ ' ' . syntastic#c#GetIncludeDirs(1)
let errorformat = '%-G%f:%s:,%f:%l:%c: %m,%f:%l: %m'
if expand('%') =~? '\%(.h\|.hpp\|.hh\)$'
if exists('g:syntastic_cpp_check_header')
let makeprg = 'g++ -c '.shellescape(expand('%'))
let makeprg = 'g++ -c '.shellescape(expand('%')).
\ ' ' . syntastic#c#GetIncludeDirs(1)
else
return []
endif