ruby.vim 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. "============================================================================
  2. "File: ruby.vim
  3. "Description: Syntax checking plugin for syntastic
  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 buf = bufnr('')
  30. let fname = "'" . escape(bufname(buf), "\\'") . "'"
  31. " TODO: encodings became useful in ruby 1.9 :)
  32. if s:ruby_new
  33. let enc = &fileencoding !=# '' ? &fileencoding : &encoding
  34. let encoding_spec = ', :encoding => "' . (enc ==? 'utf-8' ? 'UTF-8' : 'BINARY') . '"'
  35. else
  36. let encoding_spec = ''
  37. endif
  38. "gsub fixes issue #7, rails has it's own eruby syntax
  39. let makeprg =
  40. \ self.getExecEscaped() . ' -rerb -e ' .
  41. \ syntastic#util#shescape('puts ERB.new(File.read(' .
  42. \ fname . encoding_spec .
  43. \ ').gsub(''<%='',''<%''), nil, ''-'').src') .
  44. \ ' | ' . self.getExecEscaped() . ' -w -c'
  45. let errorformat =
  46. \ '%-G%\m%.%#warning: %\%%(possibly %\)%\?useless use of a literal in void context,' .
  47. \ '%-G%\m%.%#warning: possibly useless use of a variable in void context,'
  48. " filter out lines starting with ...
  49. " long lines are truncated and wrapped in ... %p then returns the wrong
  50. " column offset
  51. let errorformat .= '%-G%\%.%\%.%\%.%.%#,'
  52. let errorformat .=
  53. \ '%-GSyntax OK,'.
  54. \ '%E-:%l: syntax error\, %m,%Z%p^,'.
  55. \ '%W-:%l: warning: %m,'.
  56. \ '%Z%p^,'.
  57. \ '%-C%.%#'
  58. let env = syntastic#util#isRunningWindows() ? {} : { 'RUBYOPT': '' }
  59. return SyntasticMake({
  60. \ 'makeprg': makeprg,
  61. \ 'errorformat': errorformat,
  62. \ 'env': env,
  63. \ 'defaults': { 'bufnr': buf, 'vcol': 1 } })
  64. endfunction
  65. call g:SyntasticRegistry.CreateAndRegisterChecker({
  66. \ 'filetype': 'eruby',
  67. \ 'name': 'ruby'})
  68. let &cpo = s:save_cpo
  69. unlet s:save_cpo
  70. " vim: set sw=4 sts=4 et fdm=marker: