ruby.vim 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "============================================================================
  2. "File: ruby.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: Martin Grenfell <martin.grenfell 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_eruby_ruby_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_eruby_ruby_checker = 1
  16. let s:save_cpo = &cpo
  17. set cpo&vim
  18. function! SyntaxCheckers_eruby_ruby_IsAvailable() dict
  19. if !exists('g:syntastic_eruby_ruby_exec') && exists('g:syntastic_ruby_exec')
  20. let g:syntastic_eruby_ruby_exec = g:syntastic_ruby_exec
  21. call self.log('g:syntastic_eruby_ruby_exec =', g:syntastic_eruby_ruby_exec)
  22. endif
  23. return executable(self.getExec())
  24. endfunction
  25. function! SyntaxCheckers_eruby_ruby_GetLocList() dict
  26. if !exists('s:ruby_new')
  27. let s:ruby_new = syntastic#util#versionIsAtLeast(self.getVersion(), [1, 9])
  28. endif
  29. let fname = "'" . escape(expand('%', 1), "\\'") . "'"
  30. " TODO: encodings became useful in ruby 1.9 :)
  31. if s:ruby_new
  32. let enc = &fileencoding !=# '' ? &fileencoding : &encoding
  33. let encoding_spec = ', :encoding => "' . (enc ==? 'utf-8' ? 'UTF-8' : 'BINARY') . '"'
  34. else
  35. let encoding_spec = ''
  36. endif
  37. "gsub fixes issue #7, rails has it's own eruby syntax
  38. let makeprg =
  39. \ self.getExecEscaped() . ' -rerb -e ' .
  40. \ syntastic#util#shescape('puts ERB.new(File.read(' .
  41. \ fname . encoding_spec .
  42. \ ').gsub(''<%='',''<%''), nil, ''-'').src') .
  43. \ ' | ' . self.getExecEscaped() . ' -w -c'
  44. let errorformat = '%-G%\m%.%#warning: %\%%(possibly %\)%\?useless use of a literal in void context,'
  45. " filter out lines starting with ...
  46. " long lines are truncated and wrapped in ... %p then returns the wrong
  47. " column offset
  48. let errorformat .= '%-G%\%.%\%.%\%.%.%#,'
  49. let errorformat .=
  50. \ '%-GSyntax OK,'.
  51. \ '%E-:%l: syntax error\, %m,%Z%p^,'.
  52. \ '%W-:%l: warning: %m,'.
  53. \ '%Z%p^,'.
  54. \ '%-C%.%#'
  55. let env = syntastic#util#isRunningWindows() ? {} : { 'RUBYOPT': '' }
  56. return SyntasticMake({
  57. \ 'makeprg': makeprg,
  58. \ 'errorformat': errorformat,
  59. \ 'env': env,
  60. \ 'defaults': { 'bufnr': bufnr(''), 'vcol': 1 } })
  61. endfunction
  62. call g:SyntasticRegistry.CreateAndRegisterChecker({
  63. \ 'filetype': 'eruby',
  64. \ 'name': 'ruby'})
  65. let &cpo = s:save_cpo
  66. unlet s:save_cpo
  67. " vim: set sw=4 sts=4 et fdm=marker: