svtools.vim 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "============================================================================
  2. "File: svtools.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  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. if !exists('g:syntastic_enable_r_svtools_checker') || !g:syntastic_enable_r_svtools_checker
  44. call syntastic#log#error('checker r/svtools: checks disabled for security reasons; set g:syntastic_enable_r_svtools_checker to 1 to override')
  45. return []
  46. endif
  47. let setwd = syntastic#util#isRunningWindows() ? 'setwd("' . escape(getcwd(), '"\') . '"); ' : ''
  48. let makeprg = self.getExecEscaped() . ' --slave --restore --no-save' .
  49. \ ' -e ' . syntastic#util#shescape(setwd . 'library(svTools); ' .
  50. \ 'try(lint(commandArgs(TRUE), filename = commandArgs(TRUE), type = "flat", sep = ":"))') .
  51. \ ' --args ' . syntastic#util#shexpand('%')
  52. let errorformat =
  53. \ '%trror:%f:%\s%#%l:%\s%#%v:%m,' .
  54. \ '%tarning:%f:%\s%#%l:%\s%#%v:%m'
  55. return SyntasticMake({
  56. \ 'makeprg': makeprg,
  57. \ 'errorformat': errorformat,
  58. \ 'returns': [0] })
  59. endfunction
  60. call g:SyntasticRegistry.CreateAndRegisterChecker({
  61. \ 'filetype': 'r',
  62. \ 'name': 'svtools',
  63. \ 'exec': 'R' })
  64. let &cpo = s:save_cpo
  65. unlet s:save_cpo
  66. " vim: set sw=4 sts=4 et fdm=marker: