svtools.vim 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "============================================================================
  2. "File: svtools.vim
  3. "Description: Syntax checking plugin for syntastic
  4. "Maintainer: LCD 47 <lcd047 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. "
  13. " Security:
  14. "
  15. " This checker runs the code in your file. This is probably fine if you
  16. " wrote the file yourself, but it can be a problem if you're trying to
  17. " check third party files. If you are 100% willing to let Vim run the
  18. " code in your file, set g:syntastic_enable_r_svtools_checker to 1 in
  19. " your vimrc to enable this checker:
  20. "
  21. " let g:syntastic_enable_r_svtools_checker = 1
  22. if exists('g:loaded_syntastic_r_svtools_checker')
  23. finish
  24. endif
  25. let g:loaded_syntastic_r_svtools_checker = 1
  26. if !exists('g:syntastic_r_svtools_styles')
  27. let g:syntastic_r_svtools_styles = 'lint.style'
  28. endif
  29. let s:save_cpo = &cpo
  30. set cpo&vim
  31. function! SyntaxCheckers_r_svtools_GetHighlightRegex(item)
  32. let term = matchstr(a:item['text'], "\\m'\\zs[^']\\+\\ze'")
  33. return term !=# '' ? '\V' . escape(term, '\') : ''
  34. endfunction
  35. function! SyntaxCheckers_r_svtools_IsAvailable() dict
  36. if !executable(self.getExec())
  37. return 0
  38. endif
  39. call syntastic#util#system(self.getExecEscaped() . ' --slave --restore --no-save -e ' . syntastic#util#shescape('library(svTools)'))
  40. return v:shell_error == 0
  41. endfunction
  42. function! SyntaxCheckers_r_svtools_GetLocList() dict
  43. let buf = bufnr('')
  44. let setwd = syntastic#util#isRunningWindows() ? 'setwd("' . escape(getcwd(), '"\') . '"); ' : ''
  45. let makeprg = self.getExecEscaped() . ' --slave --restore --no-save' .
  46. \ ' -e ' . syntastic#util#shescape(setwd . 'library(svTools); ' .
  47. \ 'try(lint(commandArgs(TRUE), filename = commandArgs(TRUE), type = "flat", sep = ":"))') .
  48. \ ' --args ' . syntastic#util#shescape(bufname(buf))
  49. let errorformat =
  50. \ '%trror:%f:%\s%#%l:%\s%#%v:%m,' .
  51. \ '%tarning:%f:%\s%#%l:%\s%#%v:%m'
  52. return SyntasticMake({
  53. \ 'makeprg': makeprg,
  54. \ 'errorformat': errorformat,
  55. \ 'returns': [0] })
  56. endfunction
  57. call g:SyntasticRegistry.CreateAndRegisterChecker({
  58. \ 'filetype': 'r',
  59. \ 'name': 'svtools',
  60. \ 'exec': 'R',
  61. \ 'enable': 'enable_r_svtools_checker'})
  62. let &cpo = s:save_cpo
  63. unlet s:save_cpo
  64. " vim: set sw=4 sts=4 et fdm=marker: