sphinx.vim 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 srcdir = syntastic#util#var('rst_sphinx_source_dir')
  25. call self.log('g:syntastic_rst_sphinx_source_dir =', srcdir)
  26. if srcdir ==# ''
  27. let config = syntastic#util#findFileInParent('conf.py', expand('%:p:h', 1))
  28. if config ==# '' || !filereadable(config)
  29. call self.log('conf.py file not found')
  30. return []
  31. endif
  32. let srcdir = fnamemodify(config, ':p:h')
  33. endif
  34. let confdir = syntastic#util#var('rst_sphinx_config_dir')
  35. call self.log('g:syntastic_rst_sphinx_config_dir =', confdir)
  36. if confdir ==# ''
  37. let config = syntastic#util#findFileInParent('conf.py', expand('%:p:h', 1))
  38. let confdir = (config !=# '' && filereadable(config)) ? fnamemodify(config, ':p:h') : srcdir
  39. endif
  40. let makeprg = self.makeprgBuild({
  41. \ 'args': '-n -E',
  42. \ 'args_after': '-q -N -b pseudoxml -c ' . syntastic#util#shescape(confdir),
  43. \ 'fname': syntastic#util#shescape(srcdir),
  44. \ 'fname_after': syntastic#util#shescape(s:sphinx_cache_location) })
  45. let errorformat =
  46. \ '%E%f:%l: SEVER%t: %m,' .
  47. \ '%f:%l: %tRROR: %m,' .
  48. \ '%f:%l: %tARNING: %m,' .
  49. \ '%E%f:: SEVER%t: %m,' .
  50. \ '%f:: %tRROR: %m,' .
  51. \ '%f:: %tARNING: %m,' .
  52. \ '%trror: %m,' .
  53. \ '%+C%.%#'
  54. let loclist = SyntasticMake({
  55. \ 'makeprg': makeprg,
  56. \ 'errorformat': errorformat,
  57. \ 'returns': [0] })
  58. return loclist
  59. endfunction
  60. call g:SyntasticRegistry.CreateAndRegisterChecker({
  61. \ 'filetype': 'rst',
  62. \ 'name': 'sphinx',
  63. \ 'exec': 'sphinx-build' })
  64. let &cpo = s:save_cpo
  65. unlet s:save_cpo
  66. " vim: set sw=4 sts=4 et fdm=marker: