Extract disconnection cleanup for general use

This commit is contained in:
Tim Pope 2014-01-17 17:51:14 -05:00
parent a568535bcd
commit 0520e4fa32

View File

@ -144,11 +144,11 @@ function! s:repl.path() dict abort
return self.connection.path() return self.connection.path()
endfunction endfunction
function! s:repl.try(function, ...) dict abort function! s:conn_try(connection, function, ...) abort
try try
return call(self.connection[a:function], a:000, self.connection) return call(a:connection[a:function], a:000, a:connection)
catch /^\w\+ Connection Error:/ catch /^\w\+ Connection Error:/
call s:unregister_connection(self.connection) call s:unregister_connection(a:connection)
throw v:exception throw v:exception
endtry endtry
endfunction endfunction
@ -160,7 +160,7 @@ function! s:repl.eval(expr, options) dict abort
return error return error
endif endif
endif endif
return self.try('eval', a:expr, a:options) return s:conn_try(self.connection, 'eval', a:expr, a:options)
endfunction endfunction
function! s:repl.message(payload, ...) dict abort function! s:repl.message(payload, ...) dict abort
@ -170,14 +170,14 @@ function! s:repl.message(payload, ...) dict abort
return error return error
endif endif
endif endif
return call(self.try, ['message', a:payload] + a:000, self) return call('s:conn_try', [self.connection, 'message', a:payload] + a:000, self)
endfunction endfunction
function! s:repl.preload(lib) dict abort function! s:repl.preload(lib) dict abort
if !empty(a:lib) && a:lib !=# self.user_ns() && !get(self.requires, a:lib) if !empty(a:lib) && a:lib !=# self.user_ns() && !get(self.requires, a:lib)
let reload = has_key(self.requires, a:lib) ? ' :reload' : '' let reload = has_key(self.requires, a:lib) ? ' :reload' : ''
let self.requires[a:lib] = 0 let self.requires[a:lib] = 0
let clone = self.try('clone') let clone = s:conn_try(self.connection, 'clone')
try try
let result = clone.eval('(ns '.a:lib.' (:require '.a:lib.reload.'))', {'ns': self.user_ns()}) let result = clone.eval('(ns '.a:lib.' (:require '.a:lib.reload.'))', {'ns': self.user_ns()})
finally finally