2009-07-11 13:39:39 +12:00
|
|
|
"============================================================================
|
|
|
|
"File: syntastic.vim
|
2013-04-13 16:02:03 +01:00
|
|
|
"Description: Vim plugin for on the fly syntax checking.
|
|
|
|
"Version: 3.0.0
|
|
|
|
"Released On: 13 April, 2013
|
2009-07-11 13:39:39 +12: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-07-11 11:09:52 +12:00
|
|
|
if exists("g:loaded_syntastic_plugin")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_syntastic_plugin = 1
|
|
|
|
|
2013-03-28 23:00:08 +00:00
|
|
|
runtime! plugin/syntastic/*.vim
|
2013-01-24 00:01:30 +00:00
|
|
|
|
2012-05-08 20:31:20 +08:00
|
|
|
let s:running_windows = has("win16") || has("win32")
|
2009-07-11 11:09:52 +12:00
|
|
|
|
2013-03-21 17:44:19 +00:00
|
|
|
if !exists("g:syntastic_always_populate_loc_list")
|
|
|
|
let g:syntastic_always_populate_loc_list = 0
|
|
|
|
endif
|
|
|
|
|
2011-01-04 16:27:47 -06:00
|
|
|
if !exists("g:syntastic_auto_jump")
|
|
|
|
let syntastic_auto_jump=0
|
|
|
|
endif
|
|
|
|
|
2009-07-20 14:59:54 +12:00
|
|
|
if !exists("g:syntastic_quiet_warnings")
|
|
|
|
let g:syntastic_quiet_warnings = 0
|
|
|
|
endif
|
|
|
|
|
2011-02-19 20:10:20 +13:00
|
|
|
if !exists("g:syntastic_stl_format")
|
|
|
|
let g:syntastic_stl_format = '[Syntax: line:%F (%t)]'
|
|
|
|
endif
|
|
|
|
|
2011-12-24 09:44:01 +00:00
|
|
|
if !exists("g:syntastic_check_on_open")
|
|
|
|
let g:syntastic_check_on_open = 0
|
|
|
|
endif
|
|
|
|
|
2012-02-10 17:56:32 +00:00
|
|
|
if !exists("g:syntastic_loc_list_height")
|
|
|
|
let g:syntastic_loc_list_height = 10
|
|
|
|
endif
|
|
|
|
|
2013-01-24 00:01:30 +00:00
|
|
|
let s:registry = g:SyntasticRegistry.Instance()
|
2013-04-07 22:10:26 +03:00
|
|
|
let s:notifiers = g:SyntasticNotifiers.New()
|
2013-03-22 22:50:47 +00:00
|
|
|
let s:modemap = g:SyntasticModeMap.Instance()
|
2013-01-24 00:01:30 +00:00
|
|
|
|
2013-01-31 23:36:41 -08:00
|
|
|
function! s:CompleteCheckerName(argLead, cmdLine, cursorPos)
|
|
|
|
let checker_names = []
|
2013-02-01 14:38:53 +00:00
|
|
|
for ft in s:CurrentFiletypes()
|
2013-01-31 23:36:41 -08:00
|
|
|
for checker in s:registry.availableCheckersFor(ft)
|
2013-02-01 15:01:31 +00:00
|
|
|
call add(checker_names, checker.name())
|
2013-01-31 23:36:41 -08:00
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
return join(checker_names, "\n")
|
|
|
|
endfunction
|
|
|
|
|
2011-12-09 23:49:21 +00:00
|
|
|
command! SyntasticToggleMode call s:ToggleMode()
|
2013-01-31 23:36:41 -08:00
|
|
|
command! -nargs=? -complete=custom,s:CompleteCheckerName SyntasticCheck call s:UpdateErrors(0, <f-args>) <bar> call s:Redraw()
|
2011-12-02 09:36:11 +00:00
|
|
|
command! Errors call s:ShowLocList()
|
2011-11-28 23:44:40 +00:00
|
|
|
|
2011-12-10 00:18:28 +00:00
|
|
|
highlight link SyntasticError SpellBad
|
|
|
|
highlight link SyntasticWarning SpellCap
|
|
|
|
|
2011-12-10 01:15:24 +00:00
|
|
|
augroup syntastic
|
2011-12-24 09:44:01 +00:00
|
|
|
autocmd BufReadPost * if g:syntastic_check_on_open | call s:UpdateErrors(1) | endif
|
2011-12-24 01:33:07 +01:00
|
|
|
autocmd BufWritePost * call s:UpdateErrors(1)
|
2011-12-23 23:46:39 +00:00
|
|
|
|
2013-04-09 09:52:02 +01:00
|
|
|
autocmd BufWinEnter * if empty(&bt) | call g:SyntasticAutoloclistNotifier.AutoToggle(g:SyntasticLoclist.Current()) | endif
|
2013-04-07 23:02:31 +01:00
|
|
|
autocmd BufEnter * if &bt=='quickfix' && !empty(getloclist(0)) && !bufloaded(getloclist(0)[0].bufnr) | call g:SyntasticLoclist.Hide() | endif
|
2011-12-10 01:15:24 +00:00
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
2009-07-12 12:13:06 +12:00
|
|
|
"refresh and redraw all the error info for this buf when saving or reading
|
2013-01-31 23:20:24 -08:00
|
|
|
function! s:UpdateErrors(auto_invoked, ...)
|
2013-04-03 11:45:06 +03:00
|
|
|
if s:SkipFile()
|
2011-01-11 16:33:29 -06:00
|
|
|
return
|
|
|
|
endif
|
2011-11-28 23:44:40 +00:00
|
|
|
|
2013-03-22 22:50:47 +00:00
|
|
|
if !a:auto_invoked || s:modemap.allowsAutoChecking(&filetype)
|
2013-01-31 23:20:24 -08:00
|
|
|
if a:0 >= 1
|
|
|
|
call s:CacheErrors(a:1)
|
|
|
|
else
|
|
|
|
call s:CacheErrors()
|
|
|
|
endif
|
2011-11-28 23:44:40 +00:00
|
|
|
end
|
2009-07-11 13:47:17 +12:00
|
|
|
|
2013-04-09 09:52:02 +01:00
|
|
|
call s:notifiers.refresh(g:SyntasticLoclist.Current())
|
2012-03-02 10:05:15 +00:00
|
|
|
|
2013-04-09 09:52:02 +01:00
|
|
|
let loclist = g:SyntasticLoclist.Current()
|
2013-03-21 17:44:19 +00:00
|
|
|
if g:syntastic_always_populate_loc_list && loclist.hasErrorsOrWarningsToDisplay()
|
2013-04-03 21:53:56 +03:00
|
|
|
call setloclist(0, loclist.filteredRaw())
|
2013-03-21 17:44:19 +00:00
|
|
|
endif
|
|
|
|
|
2013-02-01 14:16:04 +00:00
|
|
|
if g:syntastic_auto_jump && loclist.hasErrorsOrWarningsToDisplay()
|
2013-04-03 21:53:56 +03:00
|
|
|
call setloclist(0, loclist.filteredRaw())
|
2011-12-23 13:56:49 +00:00
|
|
|
silent! ll
|
|
|
|
endif
|
2011-12-16 16:48:26 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
"clear the loc list for the buffer
|
2012-02-18 15:54:22 +00:00
|
|
|
function! s:ClearCache()
|
2013-04-09 09:52:02 +01:00
|
|
|
call s:notifiers.reset(g:SyntasticLoclist.Current())
|
2013-02-01 14:16:04 +00:00
|
|
|
unlet! b:syntastic_loclist
|
2011-12-16 16:48:26 +00:00
|
|
|
endfunction
|
2011-12-16 13:28:49 +00:00
|
|
|
|
2013-02-01 14:38:53 +00:00
|
|
|
function! s:CurrentFiletypes()
|
|
|
|
"sub - for _ in filetypes otherwise we cant name syntax checker
|
|
|
|
"functions legally for filetypes like "gentoo-metadata"
|
|
|
|
let fts = substitute(&ft, '-', '_', 'g')
|
|
|
|
return split(fts, '\.')
|
|
|
|
endfunction
|
|
|
|
|
2009-07-11 11:55:51 +12:00
|
|
|
"detect and cache all syntax errors in this buffer
|
2013-01-31 23:20:24 -08:00
|
|
|
function! s:CacheErrors(...)
|
2012-02-18 15:54:22 +00:00
|
|
|
call s:ClearCache()
|
2013-02-01 14:16:04 +00:00
|
|
|
let newLoclist = g:SyntasticLoclist.New([])
|
2009-07-11 11:09:52 +12:00
|
|
|
|
2013-04-02 15:30:58 +03:00
|
|
|
if !s:SkipFile()
|
2013-02-01 14:38:53 +00:00
|
|
|
for ft in s:CurrentFiletypes()
|
2011-12-13 23:28:11 +00:00
|
|
|
|
2013-02-01 14:38:53 +00:00
|
|
|
if a:0
|
|
|
|
let checker = s:registry.getChecker(ft, a:1)
|
|
|
|
if !empty(checker)
|
|
|
|
let checkers = [checker]
|
|
|
|
endif
|
2013-01-31 23:20:24 -08:00
|
|
|
else
|
|
|
|
let checkers = s:registry.getActiveCheckers(ft)
|
|
|
|
endif
|
2013-02-01 14:38:53 +00:00
|
|
|
|
2013-01-24 00:01:30 +00:00
|
|
|
for checker in checkers
|
2013-02-01 14:16:04 +00:00
|
|
|
let loclist = checker.getLocList()
|
2013-01-24 00:01:30 +00:00
|
|
|
|
2013-02-01 14:16:04 +00:00
|
|
|
if !loclist.isEmpty()
|
|
|
|
let newLoclist = newLoclist.extend(loclist)
|
2013-01-24 00:01:30 +00:00
|
|
|
|
|
|
|
"only get errors from one checker at a time
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
2011-12-21 23:52:58 +00:00
|
|
|
endfor
|
2009-09-20 22:45:06 +12:00
|
|
|
endif
|
2013-02-01 14:16:04 +00:00
|
|
|
|
|
|
|
let b:syntastic_loclist = newLoclist
|
2009-07-11 11:09:52 +12:00
|
|
|
endfunction
|
|
|
|
|
2011-11-28 23:44:40 +00:00
|
|
|
function! s:ToggleMode()
|
2013-03-22 22:50:47 +00:00
|
|
|
call s:modemap.toggleMode()
|
2012-02-18 15:54:22 +00:00
|
|
|
call s:ClearCache()
|
2011-12-15 13:42:42 +00:00
|
|
|
call s:UpdateErrors(1)
|
2013-03-22 22:50:47 +00:00
|
|
|
call s:modemap.echoMode()
|
2011-11-28 23:44:40 +00:00
|
|
|
endfunction
|
|
|
|
|
2009-07-13 23:12:18 +12:00
|
|
|
"display the cached errors for this buf in the location list
|
|
|
|
function! s:ShowLocList()
|
2013-04-09 09:52:02 +01:00
|
|
|
let loclist = g:SyntasticLoclist.Current()
|
2013-04-07 23:02:31 +01:00
|
|
|
call loclist.show()
|
2011-12-10 01:15:24 +00:00
|
|
|
endfunction
|
|
|
|
|
2012-07-01 22:48:54 +01:00
|
|
|
"the script changes &shellpipe and &shell to stop the screen flicking when
|
|
|
|
"shelling out to syntax checkers. Not all OSs support the hacks though
|
|
|
|
function! s:OSSupportsShellpipeHack()
|
2013-04-06 21:58:38 +03:00
|
|
|
return !s:running_windows && executable('/bin/bash') && (s:uname() !~ "FreeBSD") && (s:uname() !~ "OpenBSD")
|
2012-10-23 23:02:00 +01:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:IsRedrawRequiredAfterMake()
|
|
|
|
return !s:running_windows && (s:uname() =~ "FreeBSD" || s:uname() =~ "OpenBSD")
|
2012-07-01 22:48:54 +01:00
|
|
|
endfunction
|
|
|
|
|
2013-01-16 09:42:22 +00:00
|
|
|
"Redraw in a way that doesnt make the screen flicker or leave anomalies behind.
|
|
|
|
"
|
|
|
|
"Some terminal versions of vim require `redraw!` - otherwise there can be
|
|
|
|
"random anomalies left behind.
|
|
|
|
"
|
|
|
|
"However, on some versions of gvim using `redraw!` causes the screen to
|
|
|
|
"flicker - so use redraw.
|
|
|
|
function! s:Redraw()
|
2013-03-15 17:20:41 -07:00
|
|
|
if has('gui_running') || has('gui_macvim')
|
2013-01-16 09:42:22 +00:00
|
|
|
redraw
|
|
|
|
else
|
|
|
|
redraw!
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-04-02 15:30:58 +03:00
|
|
|
" Skip running in special buffers
|
|
|
|
function! s:SkipFile()
|
2013-04-03 11:45:06 +03:00
|
|
|
return !empty(&buftype) || !filereadable(expand('%')) || getwinvar(0, '&diff')
|
2013-04-02 15:30:58 +03:00
|
|
|
endfunction
|
|
|
|
|
2012-09-24 18:53:15 +01:00
|
|
|
function! s:uname()
|
|
|
|
if !exists('s:uname')
|
|
|
|
let s:uname = system('uname')
|
|
|
|
endif
|
|
|
|
return s:uname
|
|
|
|
endfunction
|
|
|
|
|
2011-02-19 20:10:20 +13:00
|
|
|
"return a string representing the state of buffer according to
|
|
|
|
"g:syntastic_stl_format
|
2009-07-11 11:55:51 +12:00
|
|
|
"
|
|
|
|
"return '' if no errors are cached for the buffer
|
|
|
|
function! SyntasticStatuslineFlag()
|
2013-04-09 09:52:02 +01:00
|
|
|
let loclist = g:SyntasticLoclist.Current()
|
2013-02-01 14:16:04 +00:00
|
|
|
if loclist.hasErrorsOrWarningsToDisplay()
|
|
|
|
let errors = loclist.errors()
|
|
|
|
let warnings = loclist.warnings()
|
2009-07-20 14:59:54 +12:00
|
|
|
|
2012-02-18 15:38:27 +00:00
|
|
|
let num_errors = len(errors)
|
|
|
|
let num_warnings = len(warnings)
|
|
|
|
|
2011-02-19 20:10:20 +13:00
|
|
|
let output = g:syntastic_stl_format
|
2009-07-20 14:59:54 +12:00
|
|
|
|
2011-02-19 20:10:20 +13:00
|
|
|
"hide stuff wrapped in %E(...) unless there are errors
|
2012-02-18 15:38:27 +00:00
|
|
|
let output = substitute(output, '\C%E{\([^}]*\)}', num_errors ? '\1' : '' , 'g')
|
2009-07-20 14:59:54 +12:00
|
|
|
|
2011-02-19 20:10:20 +13:00
|
|
|
"hide stuff wrapped in %W(...) unless there are warnings
|
2012-02-18 15:38:27 +00:00
|
|
|
let output = substitute(output, '\C%W{\([^}]*\)}', num_warnings ? '\1' : '' , 'g')
|
2009-07-20 14:59:54 +12:00
|
|
|
|
2011-02-19 20:10:20 +13:00
|
|
|
"hide stuff wrapped in %B(...) unless there are both errors and warnings
|
2012-02-18 15:38:27 +00:00
|
|
|
let output = substitute(output, '\C%B{\([^}]*\)}', (num_warnings && num_errors) ? '\1' : '' , 'g')
|
2011-02-19 20:10:20 +13:00
|
|
|
|
2013-02-01 14:16:04 +00:00
|
|
|
|
2011-02-19 20:10:20 +13:00
|
|
|
"sub in the total errors/warnings/both
|
2012-02-18 15:38:27 +00:00
|
|
|
let output = substitute(output, '\C%w', num_warnings, 'g')
|
|
|
|
let output = substitute(output, '\C%e', num_errors, 'g')
|
2013-02-01 14:16:04 +00:00
|
|
|
let output = substitute(output, '\C%t', loclist.length(), 'g')
|
2011-02-19 20:10:20 +13:00
|
|
|
|
|
|
|
"first error/warning line num
|
2013-04-03 21:53:56 +03:00
|
|
|
let output = substitute(output, '\C%F', loclist.filteredRaw()[0]['lnum'], 'g')
|
2011-02-19 20:10:20 +13:00
|
|
|
|
|
|
|
"first error line num
|
2012-02-18 15:38:27 +00:00
|
|
|
let output = substitute(output, '\C%fe', num_errors ? errors[0]['lnum'] : '', 'g')
|
2009-07-20 14:59:54 +12:00
|
|
|
|
2011-02-19 20:10:20 +13:00
|
|
|
"first warning line num
|
2012-02-18 15:38:27 +00:00
|
|
|
let output = substitute(output, '\C%fw', num_warnings ? warnings[0]['lnum'] : '', 'g')
|
2009-07-20 14:59:54 +12:00
|
|
|
|
2011-02-19 20:10:20 +13:00
|
|
|
return output
|
2009-07-11 11:09:52 +12:00
|
|
|
else
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
endfunction
|
2009-07-11 11:55:51 +12:00
|
|
|
|
2009-07-15 21:28:44 +12:00
|
|
|
"A wrapper for the :lmake command. Sets up the make environment according to
|
|
|
|
"the options given, runs make, resets the environment, returns the location
|
|
|
|
"list
|
|
|
|
"
|
|
|
|
"a:options can contain the following keys:
|
|
|
|
" 'makeprg'
|
|
|
|
" 'errorformat'
|
|
|
|
"
|
|
|
|
"The corresponding options are set for the duration of the function call. They
|
|
|
|
"are set with :let, so dont escape spaces.
|
2011-12-09 13:44:54 +00:00
|
|
|
"
|
|
|
|
"a:options may also contain:
|
|
|
|
" 'defaults' - a dict containing default values for the returned errors
|
2012-02-08 13:26:55 +00:00
|
|
|
" 'subtype' - all errors will be assigned the given subtype
|
2009-07-15 21:28:44 +12:00
|
|
|
function! SyntasticMake(options)
|
2009-07-29 16:07:04 +12:00
|
|
|
let old_loclist = getloclist(0)
|
2012-04-08 02:19:05 -04:00
|
|
|
let old_makeprg = &l:makeprg
|
2009-07-15 21:28:44 +12:00
|
|
|
let old_shellpipe = &shellpipe
|
2011-02-17 12:53:53 -08:00
|
|
|
let old_shell = &shell
|
2012-04-08 02:19:05 -04:00
|
|
|
let old_errorformat = &l:errorformat
|
2009-07-15 21:28:44 +12:00
|
|
|
|
2012-07-01 22:48:54 +01:00
|
|
|
if s:OSSupportsShellpipeHack()
|
2009-07-15 21:28:44 +12:00
|
|
|
"this is a hack to stop the screen needing to be ':redraw'n when
|
|
|
|
"when :lmake is run. Otherwise the screen flickers annoyingly
|
|
|
|
let &shellpipe='&>'
|
2011-02-17 12:53:53 -08:00
|
|
|
let &shell = '/bin/bash'
|
2009-07-15 21:28:44 +12:00
|
|
|
endif
|
|
|
|
|
|
|
|
if has_key(a:options, 'makeprg')
|
2012-04-08 02:19:05 -04:00
|
|
|
let &l:makeprg = a:options['makeprg']
|
2009-07-15 21:28:44 +12:00
|
|
|
endif
|
|
|
|
|
|
|
|
if has_key(a:options, 'errorformat')
|
2012-04-08 02:19:05 -04:00
|
|
|
let &l:errorformat = a:options['errorformat']
|
2009-07-15 21:28:44 +12:00
|
|
|
endif
|
|
|
|
|
|
|
|
silent lmake!
|
|
|
|
let errors = getloclist(0)
|
|
|
|
|
2009-07-29 16:07:04 +12:00
|
|
|
call setloclist(0, old_loclist)
|
2012-04-08 02:19:05 -04:00
|
|
|
let &l:makeprg = old_makeprg
|
|
|
|
let &l:errorformat = old_errorformat
|
2009-07-15 21:28:44 +12:00
|
|
|
let &shellpipe=old_shellpipe
|
2011-02-18 10:02:31 +13:00
|
|
|
let &shell=old_shell
|
2011-02-17 12:53:53 -08:00
|
|
|
|
2012-10-23 23:02:00 +01:00
|
|
|
if s:IsRedrawRequiredAfterMake()
|
2013-01-16 09:42:22 +00:00
|
|
|
call s:Redraw()
|
2011-09-19 13:10:53 -07:00
|
|
|
endif
|
|
|
|
|
2011-12-09 13:44:54 +00:00
|
|
|
if has_key(a:options, 'defaults')
|
2013-03-03 20:08:54 +02:00
|
|
|
call SyntasticAddToErrors(errors, a:options['defaults'])
|
2011-12-09 13:44:54 +00:00
|
|
|
endif
|
|
|
|
|
2012-02-08 13:25:11 +00:00
|
|
|
" Add subtype info if present.
|
|
|
|
if has_key(a:options, 'subtype')
|
2013-03-03 20:08:54 +02:00
|
|
|
call SyntasticAddToErrors(errors, {'subtype': a:options['subtype']})
|
2012-02-08 13:25:11 +00:00
|
|
|
endif
|
|
|
|
|
2009-07-15 21:28:44 +12:00
|
|
|
return errors
|
|
|
|
endfunction
|
|
|
|
|
2011-12-09 13:44:54 +00:00
|
|
|
"take a list of errors and add default values to them from a:options
|
2013-03-03 20:08:54 +02:00
|
|
|
function! SyntasticAddToErrors(errors, options)
|
2011-12-09 13:44:54 +00:00
|
|
|
for i in range(0, len(a:errors)-1)
|
|
|
|
for key in keys(a:options)
|
2012-01-27 13:43:48 -06:00
|
|
|
if !has_key(a:errors[i], key) || empty(a:errors[i][key])
|
2011-12-09 13:44:54 +00:00
|
|
|
let a:errors[i][key] = a:options[key]
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
return a:errors
|
|
|
|
endfunction
|
|
|
|
|
2009-07-11 11:55:51 +12:00
|
|
|
" vim: set et sts=4 sw=4:
|