2012-08-16 23:41:25 -04:00
|
|
|
" Language: CoffeeScript
|
2014-10-14 09:30:33 -04:00
|
|
|
" Maintainer: Mick Koch <mick@kochm.co>
|
2012-08-16 23:41:25 -04:00
|
|
|
" URL: http://github.com/kchmck/vim-coffee-script
|
|
|
|
" License: WTFPL
|
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
" All this is needed to support compiling filenames with spaces, quotes, and
|
|
|
|
" such. The filename is escaped and embedded into the `makeprg` setting.
|
|
|
|
"
|
|
|
|
" Because of this, `makeprg` must be updated on every file rename. And because
|
|
|
|
" of that, `CompilerSet` can't be used because it doesn't exist when the
|
|
|
|
" rename autocmd is ran. So, we have to do some checks to see whether `compiler`
|
|
|
|
" was called locally or globally, and respect that in the rest of the script.
|
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
if exists('current_compiler')
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2013-11-16 14:45:48 -05:00
|
|
|
let current_compiler = 'coffee'
|
|
|
|
call coffee#CoffeeSetUpVariables()
|
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
" Pattern to check if coffee is the compiler
|
|
|
|
let s:pat = '^' . current_compiler
|
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
" Get a `makeprg` for the current filename.
|
2012-08-16 23:41:25 -04:00
|
|
|
function! s:GetMakePrg()
|
2013-11-16 14:45:48 -05:00
|
|
|
return g:coffee_compiler .
|
|
|
|
\ ' -c' .
|
|
|
|
\ ' ' . b:coffee_litcoffee .
|
|
|
|
\ ' ' . g:coffee_make_options .
|
|
|
|
\ ' $*' .
|
|
|
|
\ ' ' . fnameescape(expand('%'))
|
2012-08-16 23:41:25 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Set `makeprg` and return 1 if coffee is still the compiler, else return 0.
|
|
|
|
function! s:SetMakePrg()
|
|
|
|
if &l:makeprg =~ s:pat
|
|
|
|
let &l:makeprg = s:GetMakePrg()
|
|
|
|
elseif &g:makeprg =~ s:pat
|
|
|
|
let &g:makeprg = s:GetMakePrg()
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
return 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Set a dummy compiler so we can check whether to set locally or globally.
|
2013-11-16 14:45:48 -05:00
|
|
|
exec 'CompilerSet makeprg=' . current_compiler
|
|
|
|
" Then actually set the compiler.
|
2012-08-16 23:41:25 -04:00
|
|
|
call s:SetMakePrg()
|
2013-11-16 14:45:48 -05:00
|
|
|
call coffee#CoffeeSetUpErrorFormat()
|
2012-08-16 23:41:25 -04:00
|
|
|
|
2013-11-16 14:45:48 -05:00
|
|
|
function! s:CoffeeMakeDeprecated(bang, args)
|
|
|
|
echoerr 'CoffeeMake is deprecated! Please use :make instead, its behavior ' .
|
|
|
|
\ 'is identical.'
|
|
|
|
sleep 5
|
|
|
|
exec 'make' . a:bang a:args
|
|
|
|
endfunction
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
" Compile the current file.
|
2013-11-16 14:45:48 -05:00
|
|
|
command! -bang -bar -nargs=* CoffeeMake
|
|
|
|
\ call s:CoffeeMakeDeprecated(<q-bang>, <q-args>)
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
" Set `makeprg` on rename since we embed the filename in the setting.
|
|
|
|
augroup CoffeeUpdateMakePrg
|
|
|
|
autocmd!
|
|
|
|
|
|
|
|
" Update `makeprg` if coffee is still the compiler, else stop running this
|
|
|
|
" function.
|
|
|
|
function! s:UpdateMakePrg()
|
|
|
|
if !s:SetMakePrg()
|
|
|
|
autocmd! CoffeeUpdateMakePrg
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Set autocmd locally if compiler was set locally.
|
|
|
|
if &l:makeprg =~ s:pat
|
2013-12-28 13:23:13 -05:00
|
|
|
autocmd BufWritePre,BufFilePost <buffer> call s:UpdateMakePrg()
|
2012-08-16 23:41:25 -04:00
|
|
|
else
|
2013-12-28 13:23:13 -05:00
|
|
|
autocmd BufWritePre,BufFilePost call s:UpdateMakePrg()
|
2012-08-16 23:41:25 -04:00
|
|
|
endif
|
|
|
|
augroup END
|