Use nrepl load-file for :[range]Eval

Closes #83.
This commit is contained in:
Tim Pope 2013-12-30 14:19:11 -05:00
parent d3f7f2cf26
commit cd3bf333bf
2 changed files with 27 additions and 8 deletions

View File

@ -164,6 +164,17 @@ function! s:nrepl_eval(expr, ...) dict abort
echo "nREPL: server has bug preventing session support" echo "nREPL: server has bug preventing session support"
echohl None echohl None
endif endif
elseif has_key(options, 'file_path')
let payload.op = 'load-file'
let payload['file-path'] = options.file_path
let payload['file-name'] = fnamemodify(options.file_path, ':t')
if has_key(payload, 'ns')
let payload.file = "(in-ns '".payload.ns.") ".payload.code
call remove(payload, 'ns')
else
let payload.file = payload.code
endif
call remove(payload, 'code')
endif endif
let response = self.process(payload) let response = self.process(payload)
if has_key(response, 'ns') && !a:0 if has_key(response, 'ns') && !a:0

View File

@ -494,8 +494,8 @@ function! s:qfhistory() abort
return list return list
endfunction endfunction
function! fireplace#session_eval(expr) abort function! fireplace#eval(expr, ...) abort
let response = s:eval(a:expr, {'session': 1}) let response = s:eval(a:expr, a:0 ? a:1 : {})
if !empty(get(response, 'value', '')) || !empty(get(response, 'err', '')) if !empty(get(response, 'value', '')) || !empty(get(response, 'err', ''))
call insert(s:history, {'buffer': bufnr(''), 'code': a:expr, 'ns': fireplace#ns(), 'response': response}) call insert(s:history, {'buffer': bufnr(''), 'code': a:expr, 'ns': fireplace#ns(), 'response': response})
@ -526,13 +526,17 @@ function! fireplace#session_eval(expr) abort
throw err throw err
endfunction endfunction
function! fireplace#eval(expr) abort function! fireplace#session_eval(expr) abort
return fireplace#session_eval(a:expr) return fireplace#eval(a:expr, {'session': 1})
endfunction endfunction
function! fireplace#echo_session_eval(expr) abort function! fireplace#echo_session_eval(expr) abort
return fireplace#echo_eval(a:expr, {'session': 1})
endfunction
function! fireplace#echo_eval(expr, options) abort
try try
echo fireplace#session_eval(a:expr) echo fireplace#eval(a:expr, a:options)
catch /^Clojure:/ catch /^Clojure:/
endtry endtry
return '' return ''
@ -657,8 +661,10 @@ function! s:editop(type) abort
endfunction endfunction
function! s:Eval(bang, line1, line2, count, args) abort function! s:Eval(bang, line1, line2, count, args) abort
let options = {}
if a:args !=# '' if a:args !=# ''
let expr = a:args let expr = a:args
let options.session = 1
else else
if a:count ==# 0 if a:count ==# 0
normal! ^ normal! ^
@ -671,14 +677,16 @@ function! s:Eval(bang, line1, line2, count, args) abort
if !line1 || !line2 if !line1 || !line2
return '' return ''
endif endif
let expr = join(getline(line1, line2), "\n") let options.session = 0
let options.file_path = s:buffer_path()
let expr = repeat("\n", line1-1).join(getline(line1, line2), "\n")
if a:bang if a:bang
exe line1.','.line2.'delete _' exe line1.','.line2.'delete _'
endif endif
endif endif
if a:bang if a:bang
try try
let result = fireplace#session_eval(expr) let result = fireplace#eval(expr, options)
if a:args !=# '' if a:args !=# ''
call append(a:line1, result) call append(a:line1, result)
exe a:line1 exe a:line1
@ -689,7 +697,7 @@ function! s:Eval(bang, line1, line2, count, args) abort
catch /^Clojure:/ catch /^Clojure:/
endtry endtry
else else
call fireplace#echo_session_eval(expr) call fireplace#echo_eval(expr, options)
endif endif
return '' return ''
endfunction endfunction