sphinx.vim 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. "============================================================================
  2. "File: sphinx.vim
  3. "Description: Syntax checking plugin for Sphinx reStructuredText files
  4. "Maintainer: Buck Evan <buck dot 2019 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_rst_sphinx_checker")
  13. finish
  14. endif
  15. let g:loaded_syntastic_rst_sphinx_checker = 1
  16. let s:save_cpo = &cpo
  17. set cpo&vim
  18. let s:sphinx_cache_location = syntastic#util#tmpdir()
  19. lockvar s:sphinx_cache_location
  20. augroup syntastic
  21. autocmd VimLeave * call syntastic#util#rmrf(s:sphinx_cache_location)
  22. augroup END
  23. function! SyntaxCheckers_rst_sphinx_GetLocList() dict
  24. let buf = bufnr('')
  25. let srcdir = syntastic#util#bufVar(buf, 'rst_sphinx_source_dir')
  26. call self.log('syntastic_rst_sphinx_source_dir =', srcdir)
  27. if srcdir ==# ''
  28. let config = syntastic#util#findFileInParent('conf.py', fnamemodify(bufname(buf), ':p:h'))
  29. if config ==# '' || !filereadable(config)
  30. call self.log('conf.py file not found')
  31. return []
  32. endif
  33. let srcdir = fnamemodify(config, ':p:h')
  34. endif
  35. let confdir = syntastic#util#bufVar(buf, 'rst_sphinx_config_dir')
  36. call self.log('syntastic_rst_sphinx_config_dir =', confdir)
  37. if confdir ==# ''
  38. let config = syntastic#util#findFileInParent('conf.py', fnamemodify(bufname(buf), ':p:h'))
  39. let confdir = (config !=# '' && filereadable(config)) ? fnamemodify(config, ':p:h') : srcdir
  40. endif
  41. let makeprg = self.makeprgBuild({
  42. \ 'args': '-n -E',
  43. \ 'args_after': '-q -N -b pseudoxml -c ' . syntastic#util#shescape(confdir),
  44. \ 'fname': syntastic#util#shescape(srcdir),
  45. \ 'fname_after': syntastic#util#shescape(s:sphinx_cache_location) })
  46. let errorformat =
  47. \ '%E%f:%l: SEVER%t: %m,' .
  48. \ '%f:%l: %tRROR: %m,' .
  49. \ '%f:%l: %tARNING: %m,' .
  50. \ '%E%f:: SEVER%t: %m,' .
  51. \ '%f:: %tRROR: %m,' .
  52. \ '%f:: %tARNING: %m,' .
  53. \ '%trror: %m,' .
  54. \ '%+C%.%#'
  55. let loclist = SyntasticMake({
  56. \ 'makeprg': makeprg,
  57. \ 'errorformat': errorformat,
  58. \ 'returns': [0] })
  59. return loclist
  60. endfunction
  61. call g:SyntasticRegistry.CreateAndRegisterChecker({
  62. \ 'filetype': 'rst',
  63. \ 'name': 'sphinx',
  64. \ 'exec': 'sphinx-build' })
  65. let &cpo = s:save_cpo
  66. unlet s:save_cpo
  67. " vim: set sw=4 sts=4 et fdm=marker: