coffee.vim 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. " Language: CoffeeScript
  2. " Maintainer: Mick Koch <kchmck@gmail.com>
  3. " URL: http://github.com/kchmck/vim-coffee-script
  4. " License: WTFPL
  5. if exists('current_compiler')
  6. finish
  7. endif
  8. let current_compiler = 'coffee'
  9. " Pattern to check if coffee is the compiler
  10. let s:pat = '^' . current_compiler
  11. " Extra options passed to CoffeeMake
  12. if !exists("coffee_make_options")
  13. let coffee_make_options = ""
  14. endif
  15. " Get a `makeprg` for the current filename. This is needed to support filenames
  16. " with spaces and quotes, but also not break generic `make`.
  17. function! s:GetMakePrg()
  18. return 'coffee -c ' . g:coffee_make_options . ' $* ' . fnameescape(expand('%'))
  19. endfunction
  20. " Set `makeprg` and return 1 if coffee is still the compiler, else return 0.
  21. function! s:SetMakePrg()
  22. if &l:makeprg =~ s:pat
  23. let &l:makeprg = s:GetMakePrg()
  24. elseif &g:makeprg =~ s:pat
  25. let &g:makeprg = s:GetMakePrg()
  26. else
  27. return 0
  28. endif
  29. return 1
  30. endfunction
  31. " Set a dummy compiler so we can check whether to set locally or globally.
  32. CompilerSet makeprg=coffee
  33. call s:SetMakePrg()
  34. CompilerSet errorformat=Error:\ In\ %f\\,\ %m\ on\ line\ %l,
  35. \Error:\ In\ %f\\,\ Parse\ error\ on\ line\ %l:\ %m,
  36. \SyntaxError:\ In\ %f\\,\ %m,
  37. \%-G%.%#
  38. " Compile the current file.
  39. command! -bang -bar -nargs=* CoffeeMake make<bang> <args>
  40. " Set `makeprg` on rename since we embed the filename in the setting.
  41. augroup CoffeeUpdateMakePrg
  42. autocmd!
  43. " Update `makeprg` if coffee is still the compiler, else stop running this
  44. " function.
  45. function! s:UpdateMakePrg()
  46. if !s:SetMakePrg()
  47. autocmd! CoffeeUpdateMakePrg
  48. endif
  49. endfunction
  50. " Set autocmd locally if compiler was set locally.
  51. if &l:makeprg =~ s:pat
  52. autocmd BufFilePost,BufWritePost <buffer> call s:UpdateMakePrg()
  53. else
  54. autocmd BufFilePost,BufWritePost call s:UpdateMakePrg()
  55. endif
  56. augroup END