├── .gitignore ├── plugin └── jack_in.vim ├── README.adoc ├── doc └── jack_in.txt └── autoload └── jack_in.vim /.gitignore: -------------------------------------------------------------------------------- 1 | doc/tags 2 | -------------------------------------------------------------------------------- /plugin/jack_in.vim: -------------------------------------------------------------------------------- 1 | if exists("g:loaded_jack_in") 2 | finish 3 | endif 4 | let g:loaded_jack_in = 1 5 | 6 | let g:default_lein_task = 'repl' 7 | let g:default_boot_task = 'repl' 8 | 9 | let g:jack_in_injections = 10 | \ {'cider/cider-nrepl': 11 | \ {'version': '0.52.0', 12 | \ 'middleware': 'cider.nrepl/cider-middleware', 13 | \ 'lein_plugin': 1}, 14 | \ 'refactor-nrepl/refactor-nrepl': 15 | \ {'version': '3.10.0', 16 | \ 'middleware': 'refactor-nrepl.middleware/wrap-refactor'}} 17 | 18 | command! -bang -nargs=* Boot call jack_in#boot(0,) 19 | command! -bang -nargs=* Lein call jack_in#lein(0,) 20 | command! -bang -nargs=* Clj call jack_in#clj(0,) 21 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = vim-jack-in 2 | 3 | Jack in to Boot, Clj & Leiningen from Vim. Inspired by the feature in CIDER.el. 4 | 5 | Depends on https://github.com/tpope/vim-dispatch[vim-dispatch] to run commands in background. If you're using Neovim I can recommend https://github.com/radenling/vim-dispatch-neovim[vim-dispatch-neovim] 6 | 7 | [source,vim] 8 | ---- 9 | Plug 'tpope/vim-dispatch' 10 | Plug 'clojure-vim/vim-jack-in' 11 | " Only in Neovim: 12 | Plug 'radenling/vim-dispatch-neovim' 13 | ---- 14 | 15 | Provides a couple of helper commands for "jacking" in to a Clojure REPL by 16 | auto-starting it. Highly inspired by CIDER.el's feature by the same name. 17 | 18 | == Commands 19 | 20 | These run inside the directory vim is currently in. In the future it would be 21 | nice to run relative to the current file. 22 | To run boot & lein, `dispatch-:Start` is used with the bang option. 23 | 24 | === Boot 25 | [source] 26 | ---- 27 | :Boot [args] 28 | ---- 29 | Start boot with CIDER-nrepl and Refactor-nrepl automatically injected. 30 | [args] is a list of tasks to run in boot. If not provided, 31 | `g:default_boot_task` is used instead. 32 | 33 | === Clj 34 | [source] 35 | ---- 36 | :Clj [args] 37 | ---- 38 | Start clj with CIDER-nrepl and Refactor-nrepl automatically injected. 39 | [args] is a list of options to run in clj. If not provided, 40 | no aditional options will be used. 41 | 42 | === Lein 43 | [source] 44 | ---- 45 | :Lein [args] 46 | ---- 47 | Start lein with CIDER-nrepl and Refactor-nrepl automatically injected. 48 | [args] is a list of tasks to run in lein. If not provided, 49 | `g:default_lein_task` is used instead. 50 | 51 | == Variables 52 | 53 | `g:default_boot_task` 54 | Control the default task to start boot with. Defaults to "repl" 55 | 56 | `g:default_lein_task` 57 | Control the default task to start lein with. Defaults to "repl" 58 | -------------------------------------------------------------------------------- /doc/jack_in.txt: -------------------------------------------------------------------------------- 1 | *jack_in.txt* Automatic REPL starting for Vim 2 | 3 | INTRODUCTION *jack_in* 4 | 5 | Provides a couple of helper commands for "jacking" in to a Clojure REPL by 6 | auto-starting it. Highly inspired by CIDER.el's feature by the same name. 7 | 8 | COMMANDS *jack_in-commands* 9 | 10 | These run inside the directory vim is currently in. In the future it would be 11 | nice to run relative to the current file. To run boot & lein, 12 | |dispatch-:Start| is used with the bang option. 13 | 14 | *jack_in-:Boot* 15 | :Boot [args] Start boot with CIDER-nrepl and Refactor-nrepl 16 | automatically injected. [args] is a list of tasks to 17 | run in boot. If not provided, |g:default_boot_task| is 18 | used instead. 19 | 20 | *jack_in-:Clj* 21 | :Clj [args] Start clj with CIDER-nrepl and Refactor-nrepl 22 | automatically injected. [args] is a list of options to 23 | run in clj. If not provided, no aditional options will 24 | be used. 25 | 26 | *jack_in-:Lein* 27 | :Lein [args] Start lein with CIDER-nrepl and Refactor-nrepl 28 | automatically injected. [args] is a list of tasks to 29 | run in lein. If not provided, |g:default_lein_task| is 30 | used instead. 31 | 32 | VARIABLES *jack_in-variables* 33 | 34 | *g:default_boot_task* Control the default task to start boot with. Defaults 35 | to "repl" 36 | 37 | *g:default_lein_task* Control the default task to start lein with. Defaults 38 | to "repl" 39 | 40 | vim:tw=78:ts=8:ft=help:norl: 41 | -------------------------------------------------------------------------------- /autoload/jack_in.vim: -------------------------------------------------------------------------------- 1 | function! s:warn(str) abort 2 | echohl WarningMsg 3 | echomsg a:str 4 | echohl None 5 | let v:warningmsg = a:str 6 | endfunction 7 | 8 | function! s:RunRepl(cmd, is_bg) abort 9 | if exists(':Start') == 2 10 | execute 'Start' . (a:is_bg ? '!' : '') a:cmd 11 | else 12 | call s:warn('dispatch.vim not installed, please install it.') 13 | if has('nvim') 14 | call s:warn('neovim detected, falling back on termopen()') 15 | tabnew 16 | call termopen(a:cmd) 17 | tabprevious 18 | endif 19 | endif 20 | endfunction 21 | 22 | function! jack_in#boot_cmd(...) 23 | let l:boot_string = 'boot -x -i "(require ''cider.tasks)"' 24 | for [dep, inj] in items(g:jack_in_injections) 25 | let l:boot_string .= printf(' -d %s:%s', dep, inj['version']) 26 | endfor 27 | let l:boot_string .= ' cider.tasks/add-middleware' 28 | for inj in values(g:jack_in_injections) 29 | let l:boot_string .= ' -m '.inj['middleware'] 30 | endfor 31 | if a:0 > 0 && a:1 != '' 32 | let l:boot_task = join(a:000, ' ') 33 | else 34 | let l:boot_task = g:default_boot_task 35 | endif 36 | return l:boot_string.' '.l:boot_task 37 | endfunction 38 | 39 | function! jack_in#boot(is_bg,...) 40 | call s:RunRepl(call(function('jack_in#boot_cmd'), a:000), a:is_bg) 41 | endfunction 42 | 43 | function! jack_in#lein_cmd(...) 44 | let l:lein_string = 'lein' 45 | for [dep, inj] in items(g:jack_in_injections) 46 | let l:dep_vector = printf('''[%s "%s"]''', dep, inj['version']) 47 | if !get(inj, 'lein_plugin') 48 | let l:lein_string .= ' update-in :dependencies conj '.l:dep_vector.' --' 49 | let l:lein_string .= ' update-in :repl-options:nrepl-middleware conj '.inj['middleware'].' --' 50 | else 51 | let l:lein_string .= ' update-in :plugins conj '.l:dep_vector.' --' 52 | endif 53 | endfor 54 | if a:0 > 0 && a:1 != '' 55 | let l:lein_task = join(a:000, ' ') 56 | else 57 | let l:lein_task = g:default_lein_task 58 | endif 59 | 60 | return l:lein_string.' '.l:lein_task 61 | endfunction 62 | 63 | function! jack_in#lein(is_bg, ...) 64 | call s:RunRepl(call(function('jack_in#lein_cmd'), a:000), a:is_bg) 65 | endfunction 66 | 67 | function! jack_in#clj_cmd(...) 68 | let l:clj_string = 'clj' 69 | let l:deps_map = '{:deps {nrepl/nrepl {:mvn/version "1.3.0"} ' 70 | let l:cider_opts = '-e "(require ''nrepl.cmdline) (nrepl.cmdline/-main \"--interactive\" \"--middleware\" \"[' 71 | 72 | for [dep, inj] in items(g:jack_in_injections) 73 | if has_key(inj, 'version') 74 | let l:deps_map .= dep . ' {:mvn/version "' . inj['version'] . '"} ' 75 | endif 76 | let l:cider_opts .= ' '.inj['middleware'] 77 | endfor 78 | 79 | let l:deps_map .= '}}' 80 | let l:cider_opts .= ']\")"' 81 | let l:m = '-M ' 82 | 83 | for arg in a:000 84 | if arg =~ '^-M:' 85 | let l:m = '' 86 | break 87 | endif 88 | endfor 89 | 90 | return l:clj_string . ' -Sdeps ''' . l:deps_map . ''' ' . join(a:000, ' ') . ' ' . l:m . l:cider_opts . ' ' 91 | endfunction 92 | 93 | function! jack_in#clj(is_bg, ...) 94 | call s:RunRepl(call(function('jack_in#clj_cmd'), a:000), a:is_bg) 95 | endfunction 96 | --------------------------------------------------------------------------------