Make defer vim plugin neovim compatible

This commit is contained in:
Talia 2020-09-23 13:52:03 +02:00
parent b7dece6ec6
commit 9744203353

View file

@ -1,7 +1,16 @@
function s:jobstart(command, options)
if has("nvim")
let a:options["on_exit"] = a:options["close_cb"]
return jobstart(a:command, a:options)
else
return job_start(a:command, a:options)
end
endfun
function Defer(command, callback) function Defer(command, callback)
let l:start = strftime("%s") let l:start = strftime("%s")
let l:buffer = [] let l:buffer = []
call job_start(a:command, { call s:jobstart(a:command, {
\ "out_io": "pipe", \ "out_io": "pipe",
\ "out_cb": { pipe, text -> add(l:buffer, text) }, \ "out_cb": { pipe, text -> add(l:buffer, text) },
\ "close_cb": { pipe -> a:callback({"output": l:buffer, "tstart": l:start, "tend":strftime("%s")}) } \ "close_cb": { pipe -> a:callback({"output": l:buffer, "tstart": l:start, "tend":strftime("%s")}) }