From 48b934b8aad36b9309095e853834df6e846ed1ea Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Fri, 31 May 2013 10:19:52 +0300 Subject: [PATCH 1/2] Adds filetype aliases. This allows checking of files with non-standard filetypes. --- doc/syntastic.txt | 9 ++++++ plugin/syntastic.vim | 19 ++++++++---- plugin/syntastic/makeprg_builder.vim | 2 +- plugin/syntastic/registry.vim | 44 ++++++++++++++++------------ 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/doc/syntastic.txt b/doc/syntastic.txt index 6e005a71..5a43f6bf 100644 --- a/doc/syntastic.txt +++ b/doc/syntastic.txt @@ -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": [], diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index a03a5aed..3e7aba55 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -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, ) 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: diff --git a/plugin/syntastic/makeprg_builder.vim b/plugin/syntastic/makeprg_builder.vim index 9f6a90f1..cc861e76 100644 --- a/plugin/syntastic/makeprg_builder.vim +++ b/plugin/syntastic/makeprg_builder.vim @@ -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 diff --git a/plugin/syntastic/registry.vim b/plugin/syntastic/registry.vim index 07495f08..b026fc33 100644 --- a/plugin/syntastic/registry.vim +++ b/plugin/syntastic/registry.vim @@ -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 From e6bb7bd4c6111bfbab5faa53b33364ff86501cf5 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Fri, 31 May 2013 19:06:33 +0300 Subject: [PATCH 2/2] Bug fix: :SyntasticInfo didn't return information for composite filetypes. --- plugin/syntastic.vim | 2 +- plugin/syntastic/checker.vim | 2 ++ plugin/syntastic/registry.vim | 20 ++++++++++---------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index 3e7aba55..a4ece2da 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -73,7 +73,7 @@ endfunction command! SyntasticToggleMode call s:ToggleMode() command! -nargs=? -complete=custom,s:CompleteCheckerName SyntasticCheck call s:UpdateErrors(0, ) call s:Redraw() command! Errors call s:ShowLocList() -command! SyntasticInfo call s:registry.echoInfoFor(&filetype) +command! SyntasticInfo call s:registry.echoInfoFor(s:CurrentFiletypes()) highlight link SyntasticError SpellBad highlight link SyntasticWarning SpellCap diff --git a/plugin/syntastic/checker.vim b/plugin/syntastic/checker.vim index 51dc0c80..5f4e8fd3 100644 --- a/plugin/syntastic/checker.vim +++ b/plugin/syntastic/checker.vim @@ -53,6 +53,8 @@ function! g:SyntasticChecker.isAvailable() return self._isAvailableFunc() endfunction +" Private methods {{{1 + function! g:SyntasticChecker._populateHighlightRegexes(list) let list = a:list if !empty(self._highlightRegexFunc) diff --git a/plugin/syntastic/registry.vim b/plugin/syntastic/registry.vim index b026fc33..43197c34 100644 --- a/plugin/syntastic/registry.vim +++ b/plugin/syntastic/registry.vim @@ -78,11 +78,6 @@ function! g:SyntasticRegistry.getActiveCheckers(ftalias) return [] endfunction -function! g:SyntasticRegistry.getActiveCheckerNames(ftalias) - let checkers = self.getActiveCheckers(a:ftalias) - return join(map(checkers, 'v:val.name()')) -endfunction - function! g:SyntasticRegistry.getChecker(ftalias, name) for checker in self.availableCheckersFor(a:ftalias) if checker.name() == a:name @@ -99,13 +94,18 @@ function! g:SyntasticRegistry.availableCheckersFor(ftalias) return self._filterCheckersByAvailability(checkers) endfunction -function! g:SyntasticRegistry.echoInfoFor(ftalias) - echomsg "Syntastic info for filetype: " . a:ftalias +function! g:SyntasticRegistry.echoInfoFor(ftalias_list) + echomsg "Syntastic info for filetype: " . join(a:ftalias_list, '.') - let available = self.availableCheckersFor(a:ftalias) - echomsg "Available checkers: " . join(map(available, "v:val.name()")) + let available = [] + let active = [] + for ftalias in a:ftalias_list + call extend(available, self.availableCheckersFor(ftalias)) + call extend(active, self.getActiveCheckers(ftalias)) + endfor - echomsg "Currently active checker(s): " . self.getActiveCheckerNames(a:ftalias) + echomsg "Available checkers: " . join(syntastic#util#unique(map(available, "v:val.name()"))) + echomsg "Currently active checker(s): " . join(syntastic#util#unique(map(active, "v:val.name()"))) endfunction " Private methods {{{1