postprocess.vim 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. if exists('g:loaded_syntastic_postprocess_autoload') || !exists('g:loaded_syntastic_plugin')
  2. finish
  3. endif
  4. let g:loaded_syntastic_postprocess_autoload = 1
  5. let s:save_cpo = &cpo
  6. set cpo&vim
  7. " Public functions {{{1
  8. " merge consecutive blanks
  9. function! syntastic#postprocess#compressWhitespace(errors) abort " {{{2
  10. for e in a:errors
  11. let e['text'] = substitute(e['text'], "\001", '', 'g')
  12. let e['text'] = substitute(e['text'], '\n', ' ', 'g')
  13. let e['text'] = substitute(e['text'], '\m\s\{2,}', ' ', 'g')
  14. let e['text'] = substitute(e['text'], '\m^\s\+', '', '')
  15. let e['text'] = substitute(e['text'], '\m\s\+$', '', '')
  16. endfor
  17. return a:errors
  18. endfunction " }}}2
  19. " remove spurious CR under Cygwin
  20. function! syntastic#postprocess#cygwinRemoveCR(errors) abort " {{{2
  21. if has('win32unix')
  22. for e in a:errors
  23. let e['text'] = substitute(e['text'], '\r', '', 'g')
  24. endfor
  25. endif
  26. return a:errors
  27. endfunction " }}}2
  28. " decode XML entities
  29. function! syntastic#postprocess#decodeXMLEntities(errors) abort " {{{2
  30. for e in a:errors
  31. let e['text'] = syntastic#util#decodeXMLEntities(e['text'])
  32. endfor
  33. return a:errors
  34. endfunction " }}}2
  35. " filter out errors referencing other files
  36. function! syntastic#postprocess#filterForeignErrors(errors) abort " {{{2
  37. return filter(copy(a:errors), 'get(v:val, "bufnr") == ' . bufnr(''))
  38. endfunction " }}}2
  39. " make sure line numbers are not past end of buffers
  40. " XXX: this loads all referenced buffers in memory
  41. function! syntastic#postprocess#guards(errors) abort " {{{2
  42. let buffers = syntastic#util#unique(map(filter(copy(a:errors), 'v:val["valid"]'), 'str2nr(v:val["bufnr"])'))
  43. let guards = {}
  44. for b in buffers
  45. let guards[b] = len(getbufline(b, 1, '$'))
  46. endfor
  47. for e in a:errors
  48. if e['valid'] && e['lnum'] > guards[e['bufnr']]
  49. let e['lnum'] = guards[e['bufnr']]
  50. endif
  51. endfor
  52. return a:errors
  53. endfunction " }}}2
  54. " }}}1
  55. let &cpo = s:save_cpo
  56. unlet s:save_cpo
  57. " vim: set sw=4 sts=4 et fdm=marker: