add g:syntastic_mode_map option

This option will allow users to fine tune when automatic syntax checking
is done.

The option should be set to something like:

let g:syntastic_mode_map = { 'mode': 'active',
                           \ 'active_filetypes': [],
                           \ 'passive_filetypes': ['puppet'] }

g:syntastic_mode_map['mode'] can take one of 2 values - "active" or
"passive". When set to active, syntastic does automatic checking as
usual. When set to "passive" syntastic only checks when the user calls
:SyntasticCheck.

The exceptions to these rules are defined in "active_filetypes"
"passive_filetypes". In passive mode, automatic checks are still done
for all filetypes in the "active_filetypes" array. In active mode,
automatic checks are not done for any filetypes in the
"passive_filetypes" array.
This commit is contained in:
Martin Grenfell 2011-11-28 23:44:40 +00:00
parent e7b8375dec
commit 78fbd7fa13

View File

@ -51,14 +51,22 @@ if !exists("g:syntastic_stl_format")
let g:syntastic_stl_format = '[Syntax: line:%F (%t)]' let g:syntastic_stl_format = '[Syntax: line:%F (%t)]'
endif endif
if !exists("g:syntastic_mode_map")
let g:syntastic_mode_map = { 'mode': 'active', 'active_filetypes': [], 'passive_filetypes': [] }
endif
"refresh and redraw all the error info for this buf when saving or reading "refresh and redraw all the error info for this buf when saving or reading
command SyntasticCheck call s:UpdateErrors(1) command SyntasticCheck -nargs=0 call s:UpdateErrors(0) <bar> redraw!
autocmd bufreadpost,bufwritepost * call s:UpdateErrors(0) autocmd bufreadpost,bufwritepost * call s:UpdateErrors(1)
function! s:UpdateErrors(skip_disabled) function! s:UpdateErrors(auto_invoked)
if &buftype == 'quickfix' if &buftype == 'quickfix'
return return
endif endif
call s:CacheErrors(a:skip_disabled)
if !a:auto_invoked || s:ModeMapAllowsAutoChecking()
call s:CacheErrors()
end
if g:syntastic_enable_balloons && has('balloon_eval') if g:syntastic_enable_balloons && has('balloon_eval')
let b:syntastic_balloons = {} let b:syntastic_balloons = {}
@ -96,18 +104,55 @@ endfunction
" "
"depends on a function called SyntaxCheckers_{&ft}_GetLocList() existing "depends on a function called SyntaxCheckers_{&ft}_GetLocList() existing
"elsewhere "elsewhere
function! s:CacheErrors(skip_disabled) function! s:CacheErrors()
let b:syntastic_loclist = [] let b:syntastic_loclist = []
if filereadable(expand("%")) if filereadable(expand("%"))
for ft in split(&ft, '\.') for ft in split(&ft, '\.')
if s:Checkable(ft, a:skip_disabled) if s:Checkable(ft)
let b:syntastic_loclist = extend(b:syntastic_loclist, SyntaxCheckers_{ft}_GetLocList()) let b:syntastic_loclist = extend(b:syntastic_loclist, SyntaxCheckers_{ft}_GetLocList())
endif endif
endfor endfor
endif endif
endfunction endfunction
command! -nargs=0 SyntasticToggleMode call s:ToggleMode()
"toggle the g:syntastic_mode_map['mode']
function! s:ToggleMode()
if g:syntastic_mode_map['mode'] == "active"
let g:syntastic_mode_map['mode'] = "passive"
else
let g:syntastic_mode_map['mode'] = "active"
endif
echo "Syntastic: " . g:syntastic_mode_map['mode'] . " mode enabled"
endfunction
"check the current filetypes against g:syntastic_mode_map to determine whether
"active mode syntax checking should be done
function! s:ModeMapAllowsAutoChecking()
if g:syntastic_mode_map['mode'] == 'passive'
"check at least one filetype is active
for ft in split(&ft, '\.')
if index(g:syntastic_mode_map['active_filetypes'], ft) != -1
return 1
endif
return 0
endfor
else
"check no filetypes are passive
for ft in split(&ft, '\.')
if index(g:syntastic_mode_map['passive_filetypes'], ft) != -1
return 0
endif
return 1
endfor
endif
endfunction
"return true if there are cached errors/warnings for this buf "return true if there are cached errors/warnings for this buf
function! s:BufHasErrorsOrWarnings() function! s:BufHasErrorsOrWarnings()
return exists("b:syntastic_loclist") && !empty(b:syntastic_loclist) return exists("b:syntastic_loclist") && !empty(b:syntastic_loclist)
@ -294,15 +339,11 @@ function! SyntasticMake(options)
return errors return errors
endfunction endfunction
function! s:Checkable(ft, skip_disabled) function! s:Checkable(ft)
if !exists("g:loaded_" . a:ft . "_syntax_checker") if !exists("g:loaded_" . a:ft . "_syntax_checker")
exec "runtime syntax_checkers/" . a:ft . ".vim" exec "runtime syntax_checkers/" . a:ft . ".vim"
endif endif
if a:skip_disabled
return 1
endif
return exists("*SyntaxCheckers_". a:ft ."_GetLocList") && return exists("*SyntaxCheckers_". a:ft ."_GetLocList") &&
\ index(g:syntastic_disabled_filetypes, a:ft) == -1 \ index(g:syntastic_disabled_filetypes, a:ft) == -1
endfunction endfunction