2011-09-09 15:36:36 -04:00
|
|
|
if exists("g:loaded_syntastic_autoload")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_syntastic_autoload = 1
|
|
|
|
|
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
2011-05-02 19:21:16 -04:00
|
|
|
|
|
|
|
function! syntastic#ErrorBalloonExpr()
|
|
|
|
if !exists('b:syntastic_balloons') | return '' | endif
|
|
|
|
return get(b:syntastic_balloons, v:beval_lnum, '')
|
|
|
|
endfunction
|
2011-05-03 08:35:50 -04:00
|
|
|
|
2011-07-10 08:42:09 -04:00
|
|
|
function! syntastic#HighlightErrors(errors, termfunc, ...)
|
2011-11-27 10:35:56 -05:00
|
|
|
call syntastic#ClearErrorHighlights()
|
|
|
|
|
2011-07-10 08:42:09 -04:00
|
|
|
let forcecb = a:0 && a:1
|
2011-05-03 08:35:50 -04:00
|
|
|
for item in a:errors
|
2011-07-10 08:42:09 -04:00
|
|
|
let group = item['type'] == 'E' ? 'SpellBad' : 'SpellCap'
|
|
|
|
if item['col'] && !forcecb
|
2011-05-24 21:50:12 -04:00
|
|
|
let lastcol = col([item['lnum'], '$'])
|
|
|
|
let lcol = min([lastcol, item['col']])
|
2011-11-27 10:35:56 -05:00
|
|
|
call syntastic#HighlightError(group, '\%'.item['lnum'].'l\%'.lcol.'c')
|
2011-05-03 08:35:50 -04:00
|
|
|
else
|
|
|
|
let term = a:termfunc(item)
|
|
|
|
if len(term) > 0
|
2011-11-27 10:35:56 -05:00
|
|
|
call syntastic#HighlightError(group, '\%' . item['lnum'] . 'l' . term)
|
2011-05-03 08:35:50 -04:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2011-11-27 10:35:56 -05:00
|
|
|
function! syntastic#ClearErrorHighlights()
|
|
|
|
for i in syntastic#ErrorHighlightIds()
|
|
|
|
call matchdelete(i)
|
|
|
|
endfor
|
|
|
|
let b:syntastic_error_highlight_ids = []
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! syntastic#HighlightError(group, pattern)
|
|
|
|
call add(syntastic#ErrorHighlightIds(), matchadd(a:group, a:pattern))
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! syntastic#ErrorHighlightIds()
|
|
|
|
if !exists("b:syntastic_error_highlight_ids")
|
|
|
|
let b:syntastic_error_highlight_ids = []
|
|
|
|
endif
|
|
|
|
return b:syntastic_error_highlight_ids
|
|
|
|
endfunction
|
|
|
|
|
2011-09-09 15:31:45 -04:00
|
|
|
" initialize c/cpp syntax checker handlers
|
|
|
|
function! s:Init()
|
|
|
|
let s:handlers = []
|
|
|
|
let s:cflags = {}
|
|
|
|
|
2011-09-09 15:36:36 -04:00
|
|
|
call s:RegHandler('gtk', 'syntastic#CheckPKG',
|
2011-09-09 15:31:45 -04:00
|
|
|
\ ['gtk', 'gtk+-2.0', 'gtk+', 'glib-2.0', 'glib'])
|
2011-09-09 15:36:36 -04:00
|
|
|
call s:RegHandler('glib', 'syntastic#CheckPKG',
|
2011-09-09 15:31:45 -04:00
|
|
|
\ ['glib', 'glib-2.0', 'glib'])
|
2011-09-09 15:36:36 -04:00
|
|
|
call s:RegHandler('glade', 'syntastic#CheckPKG',
|
2011-09-09 15:31:45 -04:00
|
|
|
\ ['glade', 'libglade-2.0', 'libglade'])
|
2011-09-09 15:36:36 -04:00
|
|
|
call s:RegHandler('libsoup', 'syntastic#CheckPKG',
|
2011-09-09 15:31:45 -04:00
|
|
|
\ ['libsoup', 'libsoup-2.4', 'libsoup-2.2'])
|
2011-09-09 15:36:36 -04:00
|
|
|
call s:RegHandler('webkit', 'syntastic#CheckPKG',
|
2011-09-09 15:31:45 -04:00
|
|
|
\ ['webkit', 'webkit-1.0'])
|
2011-09-09 15:36:36 -04:00
|
|
|
call s:RegHandler('cairo', 'syntastic#CheckPKG',
|
2011-09-09 15:31:45 -04:00
|
|
|
\ ['cairo', 'cairo'])
|
2011-09-09 15:36:36 -04:00
|
|
|
call s:RegHandler('pango', 'syntastic#CheckPKG',
|
2011-09-09 15:31:45 -04:00
|
|
|
\ ['pango', 'pango'])
|
2011-09-09 15:36:36 -04:00
|
|
|
call s:RegHandler('libxml', 'syntastic#CheckPKG',
|
2011-09-09 15:31:45 -04:00
|
|
|
\ ['libxml', 'libxml-2.0', 'libxml'])
|
2011-09-09 15:36:36 -04:00
|
|
|
call s:RegHandler('freetype', 'syntastic#CheckPKG',
|
2011-09-09 15:31:45 -04:00
|
|
|
\ ['freetype', 'freetype2', 'freetype'])
|
2011-09-09 15:36:36 -04:00
|
|
|
call s:RegHandler('SDL', 'syntastic#CheckPKG',
|
2011-09-09 15:31:45 -04:00
|
|
|
\ ['sdl', 'sdl'])
|
2011-09-09 15:36:36 -04:00
|
|
|
call s:RegHandler('opengl', 'syntastic#CheckPKG',
|
2011-09-09 15:31:45 -04:00
|
|
|
\ ['opengl', 'gl'])
|
2011-09-09 15:36:36 -04:00
|
|
|
call s:RegHandler('ruby', 'syntastic#CheckRuby', [])
|
|
|
|
call s:RegHandler('Python\.h', 'syntastic#CheckPython', [])
|
|
|
|
call s:RegHandler('php\.h', 'syntastic#CheckPhp', [])
|
2011-09-09 15:31:45 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" search the first 100 lines for include statements that are
|
|
|
|
" given in the handlers dictionary
|
|
|
|
function! syntastic#SearchHeaders()
|
|
|
|
let includes = ''
|
|
|
|
let files = []
|
|
|
|
let found = []
|
|
|
|
let lines = filter(getline(1, 100), 'v:val =~# "#\s*include"')
|
|
|
|
|
|
|
|
" search current buffer
|
|
|
|
for line in lines
|
|
|
|
let file = matchstr(line, '"\zs\S\+\ze"')
|
|
|
|
if file != ''
|
|
|
|
call add(files, file)
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
for handler in s:handlers
|
|
|
|
if line =~# handler["regex"]
|
|
|
|
let includes .= call(handler["func"], handler["args"])
|
|
|
|
call add(found, handler["regex"])
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
|
|
|
|
" search included headers
|
|
|
|
for hfile in files
|
|
|
|
if hfile != ''
|
|
|
|
let filename = expand('%:p:h') . ((has('win32') || has('win64')) ?
|
|
|
|
\ '\' : '/') . hfile
|
|
|
|
try
|
|
|
|
let lines = readfile(filename, '', 100)
|
|
|
|
catch /E484/
|
|
|
|
continue
|
|
|
|
endtry
|
|
|
|
let lines = filter(lines, 'v:val =~# "#\s*include"')
|
|
|
|
for handler in s:handlers
|
|
|
|
if index(found, handler["regex"]) != -1
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
for line in lines
|
|
|
|
if line =~# handler["regex"]
|
|
|
|
let includes .= call(handler["func"], handler["args"])
|
|
|
|
call add(found, handler["regex"])
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return includes
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" try to find library with 'pkg-config'
|
|
|
|
" search possible libraries from first to last given
|
|
|
|
" argument until one is found
|
|
|
|
function! syntastic#CheckPKG(name, ...)
|
|
|
|
if executable('pkg-config')
|
|
|
|
if !has_key(s:cflags, a:name)
|
|
|
|
for i in range(a:0)
|
|
|
|
let l:cflags = system('pkg-config --cflags '.a:000[i])
|
|
|
|
" since we cannot necessarily trust the pkg-config exit code
|
|
|
|
" we have to check for an error output as well
|
|
|
|
if v:shell_error == 0 && l:cflags !~? 'not found'
|
|
|
|
let l:cflags = ' '.substitute(l:cflags, "\n", '', '')
|
|
|
|
let s:cflags[a:name] = l:cflags
|
|
|
|
return l:cflags
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
else
|
|
|
|
return s:cflags[a:name]
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" try to find PHP includes with 'php-config'
|
|
|
|
function! syntastic#CheckPhp()
|
|
|
|
if executable('php-config')
|
|
|
|
if !exists('s:php_flags')
|
|
|
|
let s:php_flags = system('php-config --includes')
|
|
|
|
let s:php_flags = ' ' . substitute(s:php_flags, "\n", '', '')
|
|
|
|
endif
|
|
|
|
return s:php_flags
|
|
|
|
endif
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" try to find the ruby headers with 'rbconfig'
|
|
|
|
function! syntastic#CheckRuby()
|
|
|
|
if executable('ruby')
|
|
|
|
if !exists('s:ruby_flags')
|
|
|
|
let s:ruby_flags = system('ruby -r rbconfig -e '
|
|
|
|
\ . '''puts Config::CONFIG["archdir"]''')
|
|
|
|
let s:ruby_flags = substitute(s:ruby_flags, "\n", '', '')
|
|
|
|
let s:ruby_flags = ' -I' . s:ruby_flags
|
|
|
|
endif
|
|
|
|
return s:ruby_flags
|
|
|
|
endif
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" try to find the python headers with distutils
|
|
|
|
function! syntastic#CheckPython()
|
|
|
|
if executable('python')
|
|
|
|
if !exists('s:python_flags')
|
|
|
|
let s:python_flags = system('python -c ''from distutils import '
|
|
|
|
\ . 'sysconfig; print sysconfig.get_python_inc()''')
|
|
|
|
let s:python_flags = substitute(s:python_flags, "\n", '', '')
|
|
|
|
let s:python_flags = ' -I' . s:python_flags
|
|
|
|
endif
|
|
|
|
return s:python_flags
|
|
|
|
endif
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" return a handler dictionary object
|
2011-09-09 15:36:36 -04:00
|
|
|
function! s:RegHandler(regex, function, args)
|
2011-09-09 15:31:45 -04:00
|
|
|
let handler = {}
|
|
|
|
let handler["regex"] = a:regex
|
|
|
|
let handler["func"] = function(a:function)
|
|
|
|
let handler["args"] = a:args
|
|
|
|
call add(s:handlers, handler)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call s:Init()
|
2011-09-09 15:36:36 -04:00
|
|
|
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|
|
|
|
|
|
|
|
" vim: set et sts=4 sw=4:
|