svtools.vim 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. let setwd = syntastic#util#isRunningWindows() ? 'setwd("' . escape(getcwd(), '"\') . '"); ' : ''
  44. let makeprg = self.getExecEscaped() . ' --slave --restore --no-save' .
  45. \ ' -e ' . syntastic#util#shescape(setwd . 'library(svTools); ' .
  46. \ 'try(lint(commandArgs(TRUE), filename = commandArgs(TRUE), type = "flat", sep = ":"))') .
  47. \ ' --args ' . syntastic#util#shexpand('%')
  48. let errorformat =
  49. \ '%trror:%f:%\s%#%l:%\s%#%v:%m,' .
  50. \ '%tarning:%f:%\s%#%l:%\s%#%v:%m'
  51. return SyntasticMake({
  52. \ 'makeprg': makeprg,
  53. \ 'errorformat': errorformat,
  54. \ 'returns': [0] })
  55. endfunction
  56. call g:SyntasticRegistry.CreateAndRegisterChecker({
  57. \ 'filetype': 'r',
  58. \ 'name': 'svtools',
  59. \ 'exec': 'R',
  60. \ 'enable': 'enable_r_svtools_checker'})
  61. let &cpo = s:save_cpo
  62. unlet s:save_cpo
  63. " vim: set sw=4 sts=4 et fdm=marker: