Adds filetype aliases.

This allows checking of files with non-standard filetypes.
This commit is contained in:
LCD 47 2013-05-31 10:19:52 +03:00
parent dfb8b4a0ad
commit 48b934b8aa
4 changed files with 49 additions and 25 deletions

View File

@ -264,6 +264,15 @@ patterns. >
let g:syntastic_ignore_files=['^/usr/include/', '\c\.h$'] 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'* *'syntastic_mode_map'*
Default: { "mode": "active", Default: { "mode": "active",
"active_filetypes": [], "active_filetypes": [],

View File

@ -52,6 +52,10 @@ if !exists("g:syntastic_ignore_files")
let g:syntastic_ignore_files = [] let g:syntastic_ignore_files = []
endif endif
if !exists("g:syntastic_filetype_map")
let g:syntastic_filetype_map = {}
endif
let s:registry = g:SyntasticRegistry.Instance() let s:registry = g:SyntasticRegistry.Instance()
let s:notifiers = g:SyntasticNotifiers.New() let s:notifiers = g:SyntasticNotifiers.New()
let s:modemap = g:SyntasticModeMap.Instance() let s:modemap = g:SyntasticModeMap.Instance()
@ -69,7 +73,7 @@ endfunction
command! SyntasticToggleMode call s:ToggleMode() command! SyntasticToggleMode call s:ToggleMode()
command! -nargs=? -complete=custom,s:CompleteCheckerName SyntasticCheck call s:UpdateErrors(0, <f-args>) <bar> call s:Redraw() command! -nargs=? -complete=custom,s:CompleteCheckerName SyntasticCheck call s:UpdateErrors(0, <f-args>) <bar> call s:Redraw()
command! Errors call s:ShowLocList() 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 SyntasticError SpellBad
highlight link SyntasticWarning SpellCap highlight link SyntasticWarning SpellCap
@ -148,10 +152,7 @@ function! s:ClearCache()
endfunction endfunction
function! s:CurrentFiletypes() function! s:CurrentFiletypes()
"sub - for _ in filetypes otherwise we cant name syntax checker return split(&filetype, '\.')
"functions legally for filetypes like "gentoo-metadata"
let fts = substitute(&ft, '-', '_', 'g')
return split(fts, '\.')
endfunction endfunction
"detect and cache all syntax errors in this buffer "detect and cache all syntax errors in this buffer
@ -386,4 +387,12 @@ function! SyntasticAddToErrors(errors, options)
return a:errors return a:errors
endfunction 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: " vim: set et sts=4 sw=4:

View File

@ -57,7 +57,7 @@ function! g:SyntasticMakeprgBuilder._optExists(name)
endfunction endfunction
function! g:SyntasticMakeprgBuilder._optName(name) function! g:SyntasticMakeprgBuilder._optName(name)
let setting = "g:syntastic_" . &ft let setting = "g:syntastic_" . SyntasticNormalizeFiletype(&filetype)
if !empty(self._subchecker) if !empty(self._subchecker)
let setting .= '_' . self._subchecker let setting .= '_' . self._subchecker
endif endif

View File

@ -20,6 +20,10 @@ let s:defaultCheckers = {
let g:SyntasticRegistry = {} 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 " Public methods {{{1
function! g:SyntasticRegistry.Instance() function! g:SyntasticRegistry.Instance()
@ -49,22 +53,23 @@ function! g:SyntasticRegistry.registerChecker(checker) abort
call add(self._checkerMap[ft], a:checker) call add(self._checkerMap[ft], a:checker)
endfunction endfunction
function! g:SyntasticRegistry.checkable(filetype) function! g:SyntasticRegistry.checkable(ftalias)
return !empty(self.getActiveCheckers(a:filetype)) return !empty(self.getActiveCheckers(a:ftalias))
endfunction endfunction
function! g:SyntasticRegistry.getActiveCheckers(filetype) function! g:SyntasticRegistry.getActiveCheckers(ftalias)
let checkers = self.availableCheckersFor(a:filetype) let filetype = SyntasticNormalizeFiletype(a:ftalias)
let checkers = self.availableCheckersFor(filetype)
if self._userHasFiletypeSettings(a:filetype) if self._userHasFiletypeSettings(filetype)
return self._filterCheckersByUserSettings(checkers, a:filetype) return self._filterCheckersByUserSettings(checkers, filetype)
endif endif
if has_key(s:defaultCheckers, a:filetype) if has_key(s:defaultCheckers, filetype)
return self._filterCheckersByDefaultSettings(checkers, a:filetype) return self._filterCheckersByDefaultSettings(checkers, filetype)
endif endif
let checkers = self.availableCheckersFor(a:filetype) let checkers = self.availableCheckersFor(filetype)
if !empty(checkers) if !empty(checkers)
return [checkers[0]] return [checkers[0]]
@ -73,13 +78,13 @@ function! g:SyntasticRegistry.getActiveCheckers(filetype)
return [] return []
endfunction endfunction
function! g:SyntasticRegistry.getActiveCheckerNames(filetype) function! g:SyntasticRegistry.getActiveCheckerNames(ftalias)
let checkers = self.getActiveCheckers(a:filetype) let checkers = self.getActiveCheckers(a:ftalias)
return join(map(checkers, 'v:val.name()')) return join(map(checkers, 'v:val.name()'))
endfunction endfunction
function! g:SyntasticRegistry.getChecker(filetype, name) function! g:SyntasticRegistry.getChecker(ftalias, name)
for checker in self.availableCheckersFor(a:filetype) for checker in self.availableCheckersFor(a:ftalias)
if checker.name() == a:name if checker.name() == a:name
return checker return checker
endif endif
@ -88,18 +93,19 @@ function! g:SyntasticRegistry.getChecker(filetype, name)
return {} return {}
endfunction endfunction
function! g:SyntasticRegistry.availableCheckersFor(filetype) function! g:SyntasticRegistry.availableCheckersFor(ftalias)
let checkers = copy(self._allCheckersFor(a:filetype)) let filetype = SyntasticNormalizeFiletype(a:ftalias)
let checkers = copy(self._allCheckersFor(filetype))
return self._filterCheckersByAvailability(checkers) return self._filterCheckersByAvailability(checkers)
endfunction endfunction
function! g:SyntasticRegistry.echoInfoFor(filetype) function! g:SyntasticRegistry.echoInfoFor(ftalias)
echomsg "Syntastic info for filetype: " . a:filetype 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 "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 endfunction
" Private methods {{{1 " Private methods {{{1