From 7c6ec865c6d906c1b5eeb0729ff64eb090b205bc Mon Sep 17 00:00:00 2001 From: liquidz Date: Sun, 12 May 2019 10:07:32 +0900 Subject: [PATCH] Enable iced#nrepl#eval#code to inject callback function --- autoload/iced/nrepl/eval.vim | 11 ++++++++--- test/nrepl_eval.vim | 12 ++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/autoload/iced/nrepl/eval.vim b/autoload/iced/nrepl/eval.vim index 4dd8e0948..cecacf94c 100644 --- a/autoload/iced/nrepl/eval.vim +++ b/autoload/iced/nrepl/eval.vim @@ -42,7 +42,7 @@ function! iced#nrepl#eval#err(err) abort endif endfunction -function! s:out(resp) abort +function! iced#nrepl#eval#out(resp) abort if has_key(a:resp, 'value') echo iced#util#shorten(a:resp['value']) @@ -59,7 +59,7 @@ function! s:out(resp) abort endfunction function! s:repl_out(resp) abort - call s:out(a:resp) + call iced#nrepl#eval#out(a:resp) call iced#nrepl#cljs#check_switching_session(a:resp) endfunction @@ -87,8 +87,13 @@ function! iced#nrepl#eval#code(code, ...) abort let code = s:extract_inside_form(code) endif + let Callback = get(opt, 'callback', function('iced#nrepl#eval#out')) + if has_key(opt, 'callback') + unlet opt['callback'] + endif + try - call iced#nrepl#eval(code, funcref('s:out'), opt) + call iced#nrepl#eval(code, Callback, opt) finally let @@ = reg_save call winrestview(view) diff --git a/test/nrepl_eval.vim b/test/nrepl_eval.vim index 3c7d544b8..7bf54de9c 100644 --- a/test/nrepl_eval.vim +++ b/test/nrepl_eval.vim @@ -56,3 +56,15 @@ function! s:suite.code_test() abort call iced#nrepl#eval#code('(comment (+ 1 2 3))') call s:assert.equals(s:last_evaluated_code, '(+ 1 2 3)') endfunction + +function! s:suite.code_with_callback_test() abort + let test = {'resp': ''} + function! test.callback(resp) abort + let self.resp = a:resp + endfunction + + call s:ch.register_test_builder({'status_value': 'open', 'relay': funcref('s:code_relay')}) + call iced#nrepl#eval#code('(+ 1 2 3)', {'callback': {v -> test.callback(v)}}) + + call s:assert.equals(test.resp.status, ['done']) +endfunction