Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cljs command #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 76 additions & 55 deletions autoload/jack_in.vim
Original file line number Diff line number Diff line change
@@ -1,85 +1,106 @@
" Append a window to the right if there is only one window currently,
" and add it to the bottom right if there are 2 or more.
function! s:AppendWin()
let l:window_count winnr('$')
if l:window_count == 1
vsplit
wincmd l
else
wincmd l
split
endif
enew
endfunction

function! s:warn(str) abort
echohl WarningMsg
echomsg a:str
echohl None
let v:warningmsg = a:str
endfunction

function! s:RunRepl(cmd, is_bg) abort
if exists(':Start') == 2
execute 'Start' . (a:is_bg ? '!' : '') a:cmd
function! s:FindBufName(name, num)
let l:buf_name = a:name . '_' . a:num
if bufexists(l:buf_name)
let l:num = a:num + 1
return s:FindBufName(a:name, l:num)
else
call s:warn('dispatch.vim not installed, please install it.')
if has('nvim')
call s:warn('neovim detected, falling back on termopen()')
tabnew
call termopen(a:cmd)
tabprevious
endif
return l:buf_name
endif
endfunction

function! jack_in#boot_cmd(...)
let l:boot_string = 'boot -x -i "(require ''cider.tasks)"'
function! s:RunRepl(name, cmd, is_bg) abort
call AppendWin()
Rooter
call termopen(a:cmd)
let l:buf_name = s:FindBufName(a:name, 0)
execute "file" l:buf_name
endfunction

function! jack_in#clj_cmd(...)
let l:clj_string = 'clojure -X:dev'
let l:main_fn = ''
let l:interactive = ''

let l:deps = '-Sdeps '' {:deps {nrepl/nrepl {:mvn/version "0.8.3"} '
let l:cider_opts = '--middleware ''['

for [dep, inj] in items(g:jack_in_injections)
let l:boot_string .= printf(' -d %s:%s', dep, inj['version'])
endfor
let l:boot_string .= ' cider.tasks/add-middleware'
for inj in values(g:jack_in_injections)
let l:boot_string .= ' -m '.inj['middleware']
let l:deps .= dep . ' {:mvn/version "' . inj['version'] . '"} '
let l:cider_opts .= ' "'.inj['middleware'] . '"'
endfor
if a:0 > 0 && a:1 != ''
let l:boot_task = join(a:000, ' ')
else
let l:boot_task = g:default_boot_task
endif
return l:boot_string.' '.l:boot_task

let l:deps .= '}}'''
let l:cider_opts .= ']'''

"let l:cmd = l:clj_string . ' ' . l:deps . ' ' . l:main_fn . ' ' . l:cider_opts . ' ' . l:interactive
let l:cmd = l:clj_string
return l:cmd
endfunction

function! jack_in#boot(is_bg,...)
call s:RunRepl(call(function('jack_in#boot_cmd'), a:000), a:is_bg)
function! jack_in#clj(is_bg, ...)
call s:RunRepl("clj", call(function('jack_in#clj_cmd'), a:000), a:is_bg)
endfunction

function! jack_in#lein_cmd(...)
let l:lein_string = 'lein'
for [dep, inj] in items(g:jack_in_injections)
let l:dep_vector = printf('''[%s "%s"]''', dep, inj['version'])
if !get(inj, 'lein_plugin')
let l:lein_string .= ' update-in :dependencies conj '.l:dep_vector.' --'
let l:lein_string .= ' update-in :repl-options:nrepl-middleware conj '.inj['middleware'].' --'
else
let l:lein_string .= ' update-in :plugins conj '.l:dep_vector.' --'
endif
endfor
if a:0 > 0 && a:1 != ''
let l:lein_task = join(a:000, ' ')
else
let l:lein_task = g:default_lein_task
endif

return l:lein_string.' '.l:lein_task
function! jack_in#shadow_cmd(...)
let l:shadow_string = 'npx shadow-cljs watch app'

return l:shadow_string
endfunction

function! jack_in#lein(is_bg, ...)
call s:RunRepl(call(function('jack_in#lein_cmd'), a:000), a:is_bg)
function! jack_in#shadow(is_bg, ...)
call s:RunRepl("shadow", call(function('jack_in#shadow_cmd'), a:000), a:is_bg)
endfunction

function! jack_in#clj_cmd(...)
let l:clj_string = 'clj'
let l:deps_map = '{:deps {nrepl/nrepl {:mvn/version "0.7.0"} '
let l:cider_opts = '-e "(require ''nrepl.cmdline) (nrepl.cmdline/-main \"--middleware\" \"['

function! jack_in#cljs_cmd(...)
let l:clj_string = "clojure -M:cljs:dev "
let l:main_fn = ''
let l:interactive = ''

let l:deps = '-Sdeps '' {:deps {nrepl/nrepl {:mvn/version "0.8.3"} '
let l:cider_opts = '--middleware ''['

for [dep, inj] in items(g:jack_in_injections)
let l:deps_map .= dep . ' {:mvn/version "' . inj['version'] . '"} '
let l:cider_opts .= ' '.inj['middleware']
let l:deps .= dep . ' {:mvn/version "' . inj['version'] . '"} '
let l:cider_opts .= ' "'.inj['middleware'] . '"'
endfor

let l:deps_map .= '}}'
let l:cider_opts .= ']\")"'
let l:deps .= '}}'''
let l:cider_opts .= ']'''

let l:eval = "--eval \"(require \'shadow-repl)(shadow-repl/start\!)\""

let l:cmd = l:clj_string . ' ' . l:eval

return l:cmd

return l:clj_string . ' -Sdeps ''' . l:deps_map . ''' ' . join(a:000, ' ') . ' ' . l:cider_opts . ' '
endfunction

function! jack_in#clj(is_bg, ...)
call s:RunRepl(call(function('jack_in#clj_cmd'), a:000), a:is_bg)

function! jack_in#cljs(is_bg, ...)
call s:RunRepl("cljs", call(function('jack_in#cljs_cmd'), a:000), a:is_bg)
endfunction


12 changes: 9 additions & 3 deletions plugin/jack_in.vim
Original file line number Diff line number Diff line change
@@ -6,15 +6,21 @@ let g:loaded_jack_in = 1
let g:default_lein_task = 'repl'
let g:default_boot_task = 'repl'

let g:jack_in_injections =
\ {'cider/cider-nrepl':
let g:jack_in_injections = {'cider/cider-nrepl':
\ {'version': '0.25.2',
\ 'middleware': 'cider.nrepl/cider-middleware',
\ 'lein_plugin': 1},
\ 'thheller/shadow-cljs':
\ {'version': '2.15.1',
\ 'middleware': 'shadow.cljs.devtools.server.nrepl/middleware'},
\ 'refactor-nrepl/refactor-nrepl':
\ {'version': '2.5.0',
\ 'middleware': 'refactor-nrepl.middleware/wrap-refactor'}}
\ 'middleware': 'refactor-nrepl.middleware/wrap-refactor'}
\}

command! -bang -nargs=* Boot call jack_in#boot(<bang>0,<q-args>)
command! -bang -nargs=* Lein call jack_in#lein(<bang>0,<q-args>)
command! -bang -nargs=* Clj call jack_in#clj(<bang>0,<q-args>)
command! -bang -nargs=* Shadow call jack_in#shadow(<bang>0,<q-args>)
command! -bang -nargs=* Cljs call jack_in#cljs(<bang>0,<q-args>)