Permalink
Browse files

Added optional argument to allow name of CoffeeScript file to be spec…

…ified.
  • Loading branch information...
1 parent 7aa8669 commit 11581b9ff8b40dcc015960578441edcdce307be2 @zeekay committed Jun 16, 2012
Showing with 19 additions and 9 deletions.
  1. +1 −1 README.md
  2. +18 −8 ftplugin/javascript/js2coffee.vim
View
@@ -1,4 +1,4 @@
vim-js2coffee
=============
-Adds `Js2Coffee` command to vim, which converts current buffer to CoffeeScript. Utilizes the excellent [js2coffee](http://js2coffee.org/) (so make sure to `npm install -g js2coffee` first)!
+Adds `Js2Coffee` command which converts the current JavaScript buffer to CoffeeScript. Utilizes the excellent [js2coffee](http://js2coffee.org/) (so make sure to `npm install -g js2coffee` first).
@@ -1,10 +1,20 @@
-function! s:Js2Coffee()
- let l:fn = expand('%:p')
- let l:coffee = fnamemodify(l:fn, ':r').'.coffee'
- exe 'vnew '.l:coffee
- let l:result = system('cat '.l:fn.' | js2coffee')
- 0put=l:result
- normal Gdd
+if !exists("g:js2coffee_loaded")
+ let g:js2coffee_loaded = 1
+else
+ finish
+endif
+
+function! s:Js2Coffee(...)
+ if a:0 == 1
+ let coffeefile = a:1
+ else
+ let filename = expand('%:p')
+ let coffeefile = fnamemodify(filename, ':r').'.coffee'
+ endif
+ exe 'vnew '.coffeefile
+ normal Gdgg
+ exe '0read '.filename
+ silent exe '%!js2coffee'
endfunction
-au FileType javascript command! Js2Coffee call s:Js2Coffee()
+command! -nargs=? Js2Coffee call s:Js2Coffee(<f-args>)

0 comments on commit 11581b9

Please sign in to comment.