Adds filetype aliases.
This allows checking of files with non-standard filetypes.
This commit is contained in:
parent
dfb8b4a0ad
commit
48b934b8aa
@ -264,6 +264,15 @@ patterns. >
|
||||
let g:syntastic_ignore_files=['^/usr/include/', '\c\.h$']
|
||||
<
|
||||
|
||||
*'syntastic_filetype_map'*
|
||||
Default: {}
|
||||
Use this option to map non-standard filetypes to standard ones. Corresponding
|
||||
checkers are mapped accordingly, which allows syntastic to check files with
|
||||
non-standard filetypes: >
|
||||
let g:syntastic_filetype_map = { 'latex': 'tex',
|
||||
\ 'gentoo-metadata': 'xml' }
|
||||
<
|
||||
|
||||
*'syntastic_mode_map'*
|
||||
Default: { "mode": "active",
|
||||
"active_filetypes": [],
|
||||
|
@ -52,6 +52,10 @@ if !exists("g:syntastic_ignore_files")
|
||||
let g:syntastic_ignore_files = []
|
||||
endif
|
||||
|
||||
if !exists("g:syntastic_filetype_map")
|
||||
let g:syntastic_filetype_map = {}
|
||||
endif
|
||||
|
||||
let s:registry = g:SyntasticRegistry.Instance()
|
||||
let s:notifiers = g:SyntasticNotifiers.New()
|
||||
let s:modemap = g:SyntasticModeMap.Instance()
|
||||
@ -69,7 +73,7 @@ endfunction
|
||||
command! SyntasticToggleMode call s:ToggleMode()
|
||||
command! -nargs=? -complete=custom,s:CompleteCheckerName SyntasticCheck call s:UpdateErrors(0, <f-args>) <bar> call s:Redraw()
|
||||
command! Errors call s:ShowLocList()
|
||||
command! SyntasticInfo call s:registry.echoInfoFor(&ft)
|
||||
command! SyntasticInfo call s:registry.echoInfoFor(&filetype)
|
||||
|
||||
highlight link SyntasticError SpellBad
|
||||
highlight link SyntasticWarning SpellCap
|
||||
@ -148,10 +152,7 @@ function! s:ClearCache()
|
||||
endfunction
|
||||
|
||||
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, '\.')
|
||||
return split(&filetype, '\.')
|
||||
endfunction
|
||||
|
||||
"detect and cache all syntax errors in this buffer
|
||||
@ -386,4 +387,12 @@ function! SyntasticAddToErrors(errors, options)
|
||||
return a:errors
|
||||
endfunction
|
||||
|
||||
"resolve filetype aliases, and replace - with _ otherwise we cant name
|
||||
"syntax checker functions legally for filetypes like "gentoo-metadata"
|
||||
function! SyntasticNormalizeFiletype(ftalias)
|
||||
let ft = get(g:syntastic_filetype_map, a:ftalias, a:ftalias)
|
||||
let ft = substitute(ft, '-', '_', 'g')
|
||||
return ft
|
||||
endfunction
|
||||
|
||||
" vim: set et sts=4 sw=4:
|
||||
|
@ -57,7 +57,7 @@ function! g:SyntasticMakeprgBuilder._optExists(name)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticMakeprgBuilder._optName(name)
|
||||
let setting = "g:syntastic_" . &ft
|
||||
let setting = "g:syntastic_" . SyntasticNormalizeFiletype(&filetype)
|
||||
if !empty(self._subchecker)
|
||||
let setting .= '_' . self._subchecker
|
||||
endif
|
||||
|
@ -20,6 +20,10 @@ let s:defaultCheckers = {
|
||||
|
||||
let g:SyntasticRegistry = {}
|
||||
|
||||
" TODO: Handling of filetype aliases: all public methods take aliases as
|
||||
" parameters, all private methods take normalized filetypes. Public methods
|
||||
" are thus supposed to normalize filetypes before calling private methods.
|
||||
|
||||
" Public methods {{{1
|
||||
|
||||
function! g:SyntasticRegistry.Instance()
|
||||
@ -49,22 +53,23 @@ function! g:SyntasticRegistry.registerChecker(checker) abort
|
||||
call add(self._checkerMap[ft], a:checker)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry.checkable(filetype)
|
||||
return !empty(self.getActiveCheckers(a:filetype))
|
||||
function! g:SyntasticRegistry.checkable(ftalias)
|
||||
return !empty(self.getActiveCheckers(a:ftalias))
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry.getActiveCheckers(filetype)
|
||||
let checkers = self.availableCheckersFor(a:filetype)
|
||||
function! g:SyntasticRegistry.getActiveCheckers(ftalias)
|
||||
let filetype = SyntasticNormalizeFiletype(a:ftalias)
|
||||
let checkers = self.availableCheckersFor(filetype)
|
||||
|
||||
if self._userHasFiletypeSettings(a:filetype)
|
||||
return self._filterCheckersByUserSettings(checkers, a:filetype)
|
||||
if self._userHasFiletypeSettings(filetype)
|
||||
return self._filterCheckersByUserSettings(checkers, filetype)
|
||||
endif
|
||||
|
||||
if has_key(s:defaultCheckers, a:filetype)
|
||||
return self._filterCheckersByDefaultSettings(checkers, a:filetype)
|
||||
if has_key(s:defaultCheckers, filetype)
|
||||
return self._filterCheckersByDefaultSettings(checkers, filetype)
|
||||
endif
|
||||
|
||||
let checkers = self.availableCheckersFor(a:filetype)
|
||||
let checkers = self.availableCheckersFor(filetype)
|
||||
|
||||
if !empty(checkers)
|
||||
return [checkers[0]]
|
||||
@ -73,13 +78,13 @@ function! g:SyntasticRegistry.getActiveCheckers(filetype)
|
||||
return []
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry.getActiveCheckerNames(filetype)
|
||||
let checkers = self.getActiveCheckers(a:filetype)
|
||||
function! g:SyntasticRegistry.getActiveCheckerNames(ftalias)
|
||||
let checkers = self.getActiveCheckers(a:ftalias)
|
||||
return join(map(checkers, 'v:val.name()'))
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry.getChecker(filetype, name)
|
||||
for checker in self.availableCheckersFor(a:filetype)
|
||||
function! g:SyntasticRegistry.getChecker(ftalias, name)
|
||||
for checker in self.availableCheckersFor(a:ftalias)
|
||||
if checker.name() == a:name
|
||||
return checker
|
||||
endif
|
||||
@ -88,18 +93,19 @@ function! g:SyntasticRegistry.getChecker(filetype, name)
|
||||
return {}
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry.availableCheckersFor(filetype)
|
||||
let checkers = copy(self._allCheckersFor(a:filetype))
|
||||
function! g:SyntasticRegistry.availableCheckersFor(ftalias)
|
||||
let filetype = SyntasticNormalizeFiletype(a:ftalias)
|
||||
let checkers = copy(self._allCheckersFor(filetype))
|
||||
return self._filterCheckersByAvailability(checkers)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry.echoInfoFor(filetype)
|
||||
echomsg "Syntastic info for filetype: " . a:filetype
|
||||
function! g:SyntasticRegistry.echoInfoFor(ftalias)
|
||||
echomsg "Syntastic info for filetype: " . a:ftalias
|
||||
|
||||
let available = self.availableCheckersFor(a:filetype)
|
||||
let available = self.availableCheckersFor(a:ftalias)
|
||||
echomsg "Available checkers: " . join(map(available, "v:val.name()"))
|
||||
|
||||
echomsg "Currently active checker(s): " . self.getActiveCheckerNames(a:filetype)
|
||||
echomsg "Currently active checker(s): " . self.getActiveCheckerNames(a:ftalias)
|
||||
endfunction
|
||||
|
||||
" Private methods {{{1
|
||||
|
Loading…
Reference in New Issue
Block a user