Skip to content

Commit

Permalink
Enable iced#nrepl#eval#code to inject callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed May 12, 2019
1 parent a223ddb commit 7c6ec86
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
11 changes: 8 additions & 3 deletions autoload/iced/nrepl/eval.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions test/nrepl_eval.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7c6ec86

Please sign in to comment.