Centralize output/throw from eval

Supports #7.
This commit is contained in:
Tim Pope 2012-12-15 01:32:08 -05:00
parent 5b42ed5c65
commit 1aa3a32fbe
2 changed files with 32 additions and 35 deletions

View File

@ -157,23 +157,10 @@ function! s:nrepl_eval(expr, ...) dict abort
let self.ns = response.ns let self.ns = response.ns
endif endif
if has_key(response, 'err') if has_key(response, 'value')
echohl ErrorMSG let response.value = response.value[-1]
echo substitute(response.err, '\n$', '', '')
echohl NONE
endif endif
if has_key(response, 'out') return response
echo substitute(response.out, '\n$', '', '')
endif
if has_key(response, 'ex')
let err = 'Clojure: '.response.ex
elseif has_key(response, 'value')
return response.value[-1]
else
let err = 'nREPL: Unrecognized response '.string(response)
endif
throw err
endfunction endfunction
function! s:nrepl_call(payload) dict abort function! s:nrepl_call(payload) dict abort

View File

@ -288,26 +288,16 @@ function! s:oneoff.eval(expr, ns) dict abort
\ ' (spit "'.s:oneoff_ex.'" (class e))))' . \ ' (spit "'.s:oneoff_ex.'" (class e))))' .
\ ' nil)') \ ' nil)')
let wtf = system(command) let wtf = system(command)
let pr = join(readfile(s:oneoff_pr, 'b'), "\n") let result = {}
let out = join(readfile(s:oneoff_out, 'b'), "\n") let result.value = join(readfile(s:oneoff_pr, 'b'), "\n")
let err = join(readfile(s:oneoff_err, 'b'), "\n") let result.out = join(readfile(s:oneoff_out, 'b'), "\n")
let ex = join(readfile(s:oneoff_err, 'b'), "\n") let result.err = join(readfile(s:oneoff_err, 'b'), "\n")
if v:shell_error && ex ==# '' let result.ex = join(readfile(s:oneoff_err, 'b'), "\n")
call filter(result, 'v:val !=# ""')
if v:shell_error && result.ex ==# ''
throw 'Error running Clojure: '.wtf throw 'Error running Clojure: '.wtf
else else
if err !=# '' return result
echohl ErrorMSG
echo substitute(err, '\n$', '', '')
echohl None
endif
if out !=# ''
echo substitute(out, "\n$", '', '')
endif
if v:shell_error
throw 'Clojure: '.ex
else
return pr
endif
endif endif
endfunction endfunction
@ -353,10 +343,30 @@ endfunction
function! foreplay#eval(expr, ...) abort function! foreplay#eval(expr, ...) abort
let c = s:client() let c = s:client()
if !a:0 && foreplay#ns() !~# '^\%(user\)$' if !a:0 && foreplay#ns() !~# '^\%(user\)$'
call c.require(foreplay#ns()) call c.require(foreplay#ns())
endif endif
return c.eval(a:expr, a:0 ? a:1 : foreplay#ns())
let result = c.eval(a:expr, a:0 ? a:1 : foreplay#ns())
if get(result, 'err', '') !=# ''
echohl ErrorMSG
echo substitute(result.err, '\n$', '', '')
echohl NONE
endif
if get(result, 'out', '') !=# ''
echo substitute(result.out, '\n$', '', '')
endif
if get(result, 'ex', '') !=# ''
let err = 'Clojure: '.result.ex
elseif has_key(result, 'value')
return result.value
else
let err = 'foreplay.vim: Something went wrong: '.string(result)
endif
throw err
endfunction endfunction
function! foreplay#evalparse(expr) abort function! foreplay#evalparse(expr) abort