Simple image host.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

coffee.vim 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. " Language: CoffeeScript
  2. " Maintainer: Mick Koch <mick@kochm.co>
  3. " URL: http://github.com/kchmck/vim-coffee-script
  4. " License: WTFPL
  5. " All this is needed to support compiling filenames with spaces, quotes, and
  6. " such. The filename is escaped and embedded into the `makeprg` setting.
  7. "
  8. " Because of this, `makeprg` must be updated on every file rename. And because
  9. " of that, `CompilerSet` can't be used because it doesn't exist when the
  10. " rename autocmd is ran. So, we have to do some checks to see whether `compiler`
  11. " was called locally or globally, and respect that in the rest of the script.
  12. if exists('current_compiler')
  13. finish
  14. endif
  15. let current_compiler = 'coffee'
  16. call coffee#CoffeeSetUpVariables()
  17. " Pattern to check if coffee is the compiler
  18. let s:pat = '^' . current_compiler
  19. " Get a `makeprg` for the current filename.
  20. function! s:GetMakePrg()
  21. return g:coffee_compiler .
  22. \ ' -c' .
  23. \ ' ' . b:coffee_litcoffee .
  24. \ ' ' . g:coffee_make_options .
  25. \ ' $*' .
  26. \ ' ' . fnameescape(expand('%'))
  27. endfunction
  28. " Set `makeprg` and return 1 if coffee is still the compiler, else return 0.
  29. function! s:SetMakePrg()
  30. if &l:makeprg =~ s:pat
  31. let &l:makeprg = s:GetMakePrg()
  32. elseif &g:makeprg =~ s:pat
  33. let &g:makeprg = s:GetMakePrg()
  34. else
  35. return 0
  36. endif
  37. return 1
  38. endfunction
  39. " Set a dummy compiler so we can check whether to set locally or globally.
  40. exec 'CompilerSet makeprg=' . current_compiler
  41. " Then actually set the compiler.
  42. call s:SetMakePrg()
  43. call coffee#CoffeeSetUpErrorFormat()
  44. function! s:CoffeeMakeDeprecated(bang, args)
  45. echoerr 'CoffeeMake is deprecated! Please use :make instead, its behavior ' .
  46. \ 'is identical.'
  47. sleep 5
  48. exec 'make' . a:bang a:args
  49. endfunction
  50. " Compile the current file.
  51. command! -bang -bar -nargs=* CoffeeMake
  52. \ call s:CoffeeMakeDeprecated(<q-bang>, <q-args>)
  53. " Set `makeprg` on rename since we embed the filename in the setting.
  54. augroup CoffeeUpdateMakePrg
  55. autocmd!
  56. " Update `makeprg` if coffee is still the compiler, else stop running this
  57. " function.
  58. function! s:UpdateMakePrg()
  59. if !s:SetMakePrg()
  60. autocmd! CoffeeUpdateMakePrg
  61. endif
  62. endfunction
  63. " Set autocmd locally if compiler was set locally.
  64. if &l:makeprg =~ s:pat
  65. autocmd BufWritePre,BufFilePost <buffer> call s:UpdateMakePrg()
  66. else
  67. autocmd BufWritePre,BufFilePost call s:UpdateMakePrg()
  68. endif
  69. augroup END