diff --git a/autoload/syntastic/postprocess.vim b/autoload/syntastic/postprocess.vim new file mode 100644 index 00000000..d145a82a --- /dev/null +++ b/autoload/syntastic/postprocess.vim @@ -0,0 +1,39 @@ +if exists("g:loaded_syntastic_postprocess_autoload") + finish +endif +let g:loaded_syntastic_postprocess_autoload = 1 + +let s:save_cpo = &cpo +set cpo&vim + +function! s:compareErrorItems(a, b) + if a:a['bufnr'] != a:b['bufnr'] + return a:a['bufnr'] - a:b['bufnr'] + elseif a:a['lnum'] != a:b['lnum'] + return a:a['lnum'] - a:b['lnum'] + elseif a:a['type'] !=? a:b['type'] + " errors take precedence over warnings + return a:a['type'] ==? 'e' ? -1 : 1 + else + return a:a['col'] - a:b['col'] + endif +endfunction + +" natural sort +function! syntastic#postprocess#sort(errors) + return sort(a:errors, 's:compareErrorItems') +endfunction + +function syntastic#postprocess#compressWhitespace(errors) + let llist = [] + + for e in a:errors + call add(llist, substitute(e['text'], '\s\{2,}', ' ', 'g')) + endfor + + return llist +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo +" vim: set et sts=4 sw=4: diff --git a/autoload/syntastic/util.vim b/autoload/syntastic/util.vim index 8240188b..e68f6c95 100644 --- a/autoload/syntastic/util.vim +++ b/autoload/syntastic/util.vim @@ -117,18 +117,6 @@ function! syntastic#util#bufIsActive(buffer) return 0 endfunction -" Used to sort error lists -function! syntastic#util#compareErrorItems(a, b) - if a:a['lnum'] != a:b['lnum'] - return a:a['lnum'] - a:b['lnum'] - elseif a:a['type'] !=? a:b['type'] - " errors take precedence over warnings - return a:a['type'] ==? 'e' ? -1 : 1 - else - return a:a['col'] - a:b['col'] - endif -endfunction - " Returns unique elements in a list function! syntastic#util#unique(list) let seen = {} diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index e74d9d93..5c26db23 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -287,6 +287,7 @@ endfunction "a:options may also contain: " 'defaults' - a dict containing default values for the returned errors " 'subtype' - all errors will be assigned the given subtype +" 'postprocess' - a list of functions to be applied to the error list function! SyntasticMake(options) call syntastic#util#debug('SyntasticMake: called with options: '. string(a:options)) @@ -333,6 +334,12 @@ function! SyntasticMake(options) call SyntasticAddToErrors(errors, {'subtype': a:options['subtype']}) endif + if has_key(a:options, 'postprocess') && !empty(a:options['postprocess']) + for rule in a:options['postprocess'] + let errors = call('syntastic#postprocess#' . rule, [errors]) + endfor + endif + return errors endfunction diff --git a/syntax_checkers/css/prettycss.vim b/syntax_checkers/css/prettycss.vim index 764f9aee..204b5142 100644 --- a/syntax_checkers/css/prettycss.vim +++ b/syntax_checkers/css/prettycss.vim @@ -43,12 +43,17 @@ function! SyntaxCheckers_css_prettycss_GetLocList() \ '%WWarning: %m\, line %l\, char %c),' . \ '%-G%.%#' - let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr("")} }) + let loclist = SyntasticMake({ + \ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'defaults': {'bufnr': bufnr("")}, + \ 'postprocess': ['sort'] }) + for n in range(len(loclist)) let loclist[n]["text"] .= ')' endfor - return sort(loclist, 'syntastic#util#compareErrorItems') + return loclist endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ diff --git a/syntax_checkers/haskell/hdevtools.vim b/syntax_checkers/haskell/hdevtools.vim index f2ea0e91..fd43b349 100644 --- a/syntax_checkers/haskell/hdevtools.vim +++ b/syntax_checkers/haskell/hdevtools.vim @@ -21,19 +21,22 @@ endfunction function! SyntaxCheckers_haskell_hdevtools_GetLocList() let makeprg = syntastic#makeprg#build({ - \ 'exe': 'hdevtools check', - \ 'args': get(g:, 'hdevtools_options', ''), - \ 'subchecker': 'hdevtools' }) + \ 'exe': 'hdevtools check', + \ 'args': get(g:, 'hdevtools_options', ''), + \ 'subchecker': 'hdevtools' }) let errorformat= '\%-Z\ %#,'. - \ '%W%f:%l:%c:\ Warning:\ %m,'. - \ '%E%f:%l:%c:\ %m,'. - \ '%E%>%f:%l:%c:,'. - \ '%+C\ \ %#%m,'. - \ '%W%>%f:%l:%c:,'. - \ '%+C\ \ %#%tarning:\ %m,' + \ '%W%f:%l:%c:\ Warning:\ %m,'. + \ '%E%f:%l:%c:\ %m,'. + \ '%E%>%f:%l:%c:,'. + \ '%+C\ \ %#%m,'. + \ '%W%>%f:%l:%c:,'. + \ '%+C\ \ %#%tarning:\ %m,' - return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + return SyntasticMake({ + \ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'postprocess': ['compressWhitespace'] }) endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ diff --git a/syntax_checkers/python/pylint.vim b/syntax_checkers/python/pylint.vim index 37fc7bec..b7bfa122 100644 --- a/syntax_checkers/python/pylint.vim +++ b/syntax_checkers/python/pylint.vim @@ -15,22 +15,25 @@ endfunction function! SyntaxCheckers_python_pylint_GetLocList() let makeprg = syntastic#makeprg#build({ - \ 'exe': 'pylint', - \ 'args': ' -f parseable -r n -i y', - \ 'subchecker': 'pylint' }) + \ 'exe': 'pylint', + \ 'args': ' -f parseable -r n -i y', + \ 'subchecker': 'pylint' }) let errorformat = - \ '%A%f:%l:%m,' . - \ '%A%f:(%l):%m,' . - \ '%-Z%p^%.%#,' . - \ '%-G%.%#' + \ '%A%f:%l:%m,' . + \ '%A%f:(%l):%m,' . + \ '%-Z%p^%.%#,' . + \ '%-G%.%#' - let loclist=SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + let loclist=SyntasticMake({ + \ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'postprocess': ['sort'] }) for n in range(len(loclist)) let loclist[n]['type'] = match(['R', 'C', 'W'], loclist[n]['text'][2]) >= 0 ? 'W' : 'E' endfor - return sort(loclist, 'syntastic#util#compareErrorItems') + return loclist endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ diff --git a/syntax_checkers/tex/chktex.vim b/syntax_checkers/tex/chktex.vim index 67b6e432..d0fb30cb 100644 --- a/syntax_checkers/tex/chktex.vim +++ b/syntax_checkers/tex/chktex.vim @@ -38,14 +38,22 @@ endfunction function! SyntaxCheckers_tex_chktex_GetLocList() let makeprg = syntastic#makeprg#build({ - \ 'exe': 'chktex', - \ 'post_args': '-q -v1', - \ 'subchecker': 'chktex' }) - let errorformat = '%EError\ %\\d%\\+\ in\ %f\ line\ %l:\ %m,%WWarning\ %\\d%\\+\ in\ %f\ line\ %l:\ %m,' . - \ (g:syntastic_tex_chktex_showmsgs ? '%WMessage\ %\\d%\\+\ in\ %f\ line %l:\ %m,' : '') . - \ '%+Z%p^,%-G%.%#' - let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' }) - return sort(loclist, 'syntastic#util#compareErrorItems') + \ 'exe': 'chktex', + \ 'post_args': '-q -v1', + \ 'subchecker': 'chktex' }) + + let errorformat = + \ '%EError\ %\\d%\\+\ in\ %f\ line\ %l:\ %m,' . + \ '%WWarning\ %\\d%\\+\ in\ %f\ line\ %l:\ %m,' . + \ (g:syntastic_tex_chktex_showmsgs ? '%WMessage\ %\\d%\\+\ in\ %f\ line %l:\ %m,' : '') . + \ '%+Z%p^,' . + \ '%-G%.%#' + + return SyntasticMake({ + \ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'subtype': 'Style', + \ 'postprocess': ['sort'] }) endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({