From 0095241a6fb3aa9aa59a60003903d28b41176ac7 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sun, 19 Jan 2014 17:56:32 -0500 Subject: [PATCH] :Piggieback --- README.markdown | 4 +++- doc/fireplace.txt | 14 ++++++++++++++ plugin/fireplace.vim | 37 +++++++++++++++++++++++++++++++++---- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index 0318572..4817f8a 100644 --- a/README.markdown +++ b/README.markdown @@ -34,7 +34,8 @@ This list isn't exhaustive; see the `:help` for details. Fireplace.vim talks to nREPL. With Leiningen, it connects automatically based on `target/repl-port`, otherwise it's just a `:Connect` away. You can connect to multiple instances of nREPL for different projects, and it will use the -right one automatically. +right one automatically. ClojureScript support is just as seamless with +[Piggieback][]. The only external dependency is that you have either a Vim with Python support compiled in, or `python` in your path. @@ -45,6 +46,7 @@ your Leiningen or Maven config. It's a bit slow, but a two-second delay is vastly preferable to being forced out of my flow for a single command, in my book. +[Piggieback]: https://github.com/cemerick/piggieback [classpath.vim]: https://github.com/tpope/vim-classpath ### Not quite a REPL diff --git a/doc/fireplace.txt b/doc/fireplace.txt index 60b1a9e..7eb6978 100644 --- a/doc/fireplace.txt +++ b/doc/fireplace.txt @@ -28,6 +28,20 @@ directly, which can be quite slow depending on your setup. The only adapter shipped with fireplace.vim is for nREPL. You need either |if_pyth| or the python command in your PATH. + *fireplace-piggieback* *fireplace-clojurescript* +ClojureScript is can be evaled with Piggieback if the appropriate nREPL +middleware is loaded. https://github.com/cemerick/piggieback + + *fireplace-:Piggieback* +:Piggieback [{env}] Create a new nREPL session and invoke + cemerick.piggieback/cljs-repl with the given or + default (Rhino) environment. This will also happen + automatically on first eval in a ClojureScript buffer + if not invoked explicitly. + +:Piggieback! Terminate the most recently created piggieback + session. + LEININGEN *fireplace-leiningen* In addition to automatic repl connection, Clojure buffers in a Leiningen diff --git a/plugin/fireplace.vim b/plugin/fireplace.vim index 92780c9..9d7595e 100644 --- a/plugin/fireplace.vim +++ b/plugin/fireplace.vim @@ -190,6 +190,29 @@ endfunction let s:piggieback = copy(s:repl) +function! s:repl.piggieback(arg, ...) abort + if a:0 && a:1 + if len(self.piggiebacks) + call remove(self.piggiebacks, 0) + endif + return {} + endif + if empty(a:arg) + let arg = '' + else + let arg = ' :repl-env ' . a:arg + endif + let connection = s:conn_try(self.connection, 'clone') + let response = connection.eval('(cemerick.piggieback/cljs-repl'.arg.')') + + if empty(get(response, 'ex')) + call insert(self.piggiebacks, extend({'connection': connection}, deepcopy(s:piggieback))) + return {} + endif + call connection.close() + return response +endfunction + function! s:piggieback.user_ns() abort return 'cljs.user' endfunction @@ -294,9 +317,15 @@ function! s:Connect(...) abort return '' endfunction +function! s:piggieback(arg, remove) abort + let response = fireplace#platform().piggieback(a:arg, a:remove) + call s:output_response(response) +endfunction + augroup fireplace_connect autocmd! autocmd FileType clojure command! -bar -complete=customlist,s:connect_complete -nargs=* Connect :FireplaceConnect + autocmd FileType clojure command! -bar -complete=customlist,fireplace#eval_complete -bang -nargs=* Piggieback :call s:piggieback(, 0) augroup END " }}}1 @@ -367,10 +396,12 @@ function! s:oneoff.eval(expr, options) dict abort return s:spawning_eval(self.classpath, a:expr, get(a:options, 'ns', self.user_ns())) endfunction -function! s:oneoff.message(symbol) abort +function! s:oneoff.message(...) abort throw 'No live REPL connection' endfunction +let s:oneoff.piggieback = s:oneoff.message + " }}}1 " Client {{{1 @@ -439,12 +470,10 @@ function! fireplace#client(...) abort throw ':Connect to a REPL to evaluate code' endif if empty(client.piggiebacks) - let connection = s:conn_try(client.connection, 'clone') - let result = connection.eval('(cemerick.piggieback/cljs-repl)') + let result = client.piggieback('') if has_key(result, 'ex') return result endif - call insert(client.piggiebacks, extend({'connection': connection}, deepcopy(s:piggieback))) endif return client.piggiebacks[0] endif