/
ls.vim
67 lines (66 loc) · 1.7 KB
/
ls.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
" default check
if exists('current_compiler')
finish
endif
let current_compiler = 'ls'
" set defaults
" {{{
if !exists('livescript_compiler')
let livescript_compiler = 'lsc'
endif
if !exists('livescript_extra_compiler')
let livescript_extra_compiler = ''
endif
if !exists('livescript_compile_auto')
let livescript_compile_auto = 1
endif
" }}}
" create helpers
function! s:LiveScriptMake()
" {{{
" after some fiddling with "make",
" i've decided to put everything straight into vimscript,
" make sux and this is a much cleaner way:
" compile livescript code and get the output
let o = system(g:livescript_compiler . ' -cb ' . shellescape(expand('%')))
" check for error
if strlen(o)
" simply dump everything
echo "\n"
echohl ErrorMsg
echo o . "\n"
echohl None
" finish
return
endif
" check for extra compiler
if strlen(g:livescript_extra_compiler) && expand('%:e') ==# 'lsx'
" compile generated javascript with extra compiler
let f = expand('%:r') . '.js'
let o = system(g:livescript_extra_compiler . ' ' . shellescape(f))
" save the output
let o = ["// lsx: " . g:livescript_extra_compiler] + split(o, "\n", 1)
call writefile(o, f, 's')
endif
" }}}
endfunction
function! s:LiveScriptAutoMake()
" {{{
if g:livescript_compile_auto
call s:LiveScriptMake()
endif
" }}}
endfunction
" set autocommands
augroup LiveScriptMakeAuto
" {{{
" cleanup
autocmd!
" compile livescript file on save
"autocmd BufWritePost <buffer> call s:LiveScriptAutoMake()
autocmd BufWritePost *.ls call s:LiveScriptAutoMake()
autocmd BufWritePost *.lsx call s:LiveScriptAutoMake()
" }}}
augroup END
" editor settings
" vim: fdm=marker ts=2 sw=2 sts=2 nu: