Skip to content

Instantly share code, notes, and snippets.

@lmarburger
Last active August 29, 2015 13:56
Show Gist options
  • Save lmarburger/9002034 to your computer and use it in GitHub Desktop.
Save lmarburger/9002034 to your computer and use it in GitHub Desktop.
Pipe the selection to the CoffeeScript compile and print the result.

No more wondering, "How does this compile?"

Image 2014-02-14 at 9.42.51 AM.png

Image 2014-02-14 at 9.43.08 AM.png

function! CompileCoffee() range
let code = shellescape(join(getline(a:firstline, a:lastline), "\n"))
" shellescape() escapes newlines and encloses in single quotes. Code needs
" to be wrapped in double quotes and use real newlines in order to be
" processed correctly.
let code = substitute(code, "\\\\\n", "\n", "g")
echo system("echo " . code . "| coffee -scb")
endfunction
vmap <leader>c :call CompileCoffee()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment