tidy.vim 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. "============================================================================
  2. "File: xhtml.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
  5. "License: This program is free software. It comes without any warranty,
  6. " to the extent permitted by applicable law. You can redistribute
  7. " it and/or modify it under the terms of the Do What The Fuck You
  8. " Want To Public License, Version 2, as published by Sam Hocevar.
  9. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  10. "
  11. "============================================================================
  12. if exists('g:loaded_syntastic_xhtml_tidy_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_xhtml_tidy_checker = 1
  16. let s:save_cpo = &cpo
  17. set cpo&vim
  18. if !exists('g:syntastic_xhtml_tidy_ignore_errors')
  19. let g:syntastic_xhtml_tidy_ignore_errors = []
  20. endif
  21. " Constants {{{1
  22. " TODO: join this with html.vim DRY's sake?
  23. function! s:TidyEncOptByFenc()
  24. let TIDY_OPTS = {
  25. \ 'utf-8': '-utf8',
  26. \ 'ascii': '-ascii',
  27. \ 'latin1': '-latin1',
  28. \ 'iso-2022-jp': '-iso-2022',
  29. \ 'cp1252': '-win1252',
  30. \ 'macroman': '-mac',
  31. \ 'utf-16le': '-utf16le',
  32. \ 'utf-16': '-utf16',
  33. \ 'big5': '-big5',
  34. \ 'cp932': '-shiftjis',
  35. \ 'sjis': '-shiftjis',
  36. \ 'cp850': '-ibm858',
  37. \ }
  38. return get(TIDY_OPTS, &fileencoding, '-utf8')
  39. endfunction
  40. " }}}1
  41. function! SyntaxCheckers_xhtml_tidy_GetLocList() dict " {{{1
  42. let encopt = s:TidyEncOptByFenc()
  43. let makeprg = self.makeprgBuild({ 'args_after': encopt . ' -xml -e' })
  44. let errorformat=
  45. \ '%Wline %l column %v - Warning: %m,' .
  46. \ '%Eline %l column %v - Error: %m,' .
  47. \ '%-G%.%#'
  48. let loclist = SyntasticMake({
  49. \ 'makeprg': makeprg,
  50. \ 'errorformat': errorformat,
  51. \ 'defaults': {'bufnr': bufnr('')},
  52. \ 'returns': [0, 1, 2] })
  53. for e in loclist
  54. if e['valid'] && s:IgnoreError(e['text']) == 1
  55. let e['valid'] = 0
  56. endif
  57. endfor
  58. return loclist
  59. endfunction " }}}1
  60. " Utilities {{{1
  61. function! s:IgnoreError(text) " {{{2
  62. for item in g:syntastic_xhtml_tidy_ignore_errors
  63. if stridx(a:text, item) != -1
  64. return 1
  65. endif
  66. endfor
  67. return 0
  68. endfunction " }}}2
  69. " }}}1
  70. call g:SyntasticRegistry.CreateAndRegisterChecker({
  71. \ 'filetype': 'xhtml',
  72. \ 'name': 'tidy'})
  73. let &cpo = s:save_cpo
  74. unlet s:save_cpo
  75. " vim: set sw=4 sts=4 et fdm=marker: