summaryrefslogtreecommitdiffstats
path: root/compiler/coffee.vim
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2013-09-12 16:17:03 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2013-09-12 16:17:03 +0200
commit01fe1500df97577452f755b526c09d8ed0c802ea (patch)
tree9e2e038630cc9e82abcd17da6dd3407a9b3bc62a /compiler/coffee.vim
parentdce12af91b404835938e95de9e6d839d52487ed5 (diff)
downloadvim-polyglot-01fe1500df97577452f755b526c09d8ed0c802ea.tar.gz
vim-polyglot-01fe1500df97577452f755b526c09d8ed0c802ea.zip
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript, json, less, nginx, ocaml, ruby, sass, scss, slim, stylus, textile, tmux
Diffstat (limited to 'compiler/coffee.vim')
-rw-r--r--compiler/coffee.vim82
1 files changed, 82 insertions, 0 deletions
diff --git a/compiler/coffee.vim b/compiler/coffee.vim
new file mode 100644
index 00000000..f521ca9e
--- /dev/null
+++ b/compiler/coffee.vim
@@ -0,0 +1,82 @@
+" Language: CoffeeScript
+" Maintainer: Mick Koch <kchmck@gmail.com>
+" URL: http://github.com/kchmck/vim-coffee-script
+" License: WTFPL
+
+" 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.
+
+if exists('current_compiler')
+ finish
+endif
+
+let current_compiler = 'coffee'
+call coffee#CoffeeSetUpVariables()
+
+" Pattern to check if coffee is the compiler
+let s:pat = '^' . current_compiler
+
+" Get a `makeprg` for the current filename.
+function! s:GetMakePrg()
+ return g:coffee_compiler .
+ \ ' -c' .
+ \ ' ' . b:coffee_litcoffee .
+ \ ' ' . g:coffee_make_options .
+ \ ' ' . fnameescape(expand('%')) .
+ \ ' $*'
+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.
+exec 'CompilerSet makeprg=' . current_compiler
+" Then actually set the compiler.
+call s:SetMakePrg()
+call coffee#CoffeeSetUpErrorFormat()
+
+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
+
+" Compile the current file.
+command! -bang -bar -nargs=* CoffeeMake
+\ call s:CoffeeMakeDeprecated(<q-bang>, <q-args>)
+
+" 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
+ autocmd BufFilePost,BufWritePost <buffer> call s:UpdateMakePrg()
+ else
+ autocmd BufFilePost,BufWritePost call s:UpdateMakePrg()
+ endif
+augroup END