2020-08-19 12:23:39 +00:00
|
|
|
function Defer(command, callback)
|
2020-08-21 12:02:53 +00:00
|
|
|
let l:start = strftime("%s")
|
2020-08-19 15:32:32 +00:00
|
|
|
let l:buffer = []
|
|
|
|
call job_start(a:command, {
|
|
|
|
\ "out_io": "pipe",
|
|
|
|
\ "out_cb": { pipe, text -> add(l:buffer, text) },
|
2020-08-21 12:02:53 +00:00
|
|
|
\ "close_cb": { pipe -> a:callback({"output": l:buffer, "tstart": l:start, "tend":strftime("%s")}) }
|
2020-08-19 15:32:32 +00:00
|
|
|
\ })
|
2020-08-19 12:23:39 +00:00
|
|
|
endfun
|
|
|
|
|
2020-08-21 11:00:07 +00:00
|
|
|
function s:echo(message)
|
|
|
|
echom a:message
|
|
|
|
endfun
|
|
|
|
|
|
|
|
function s:notify(message)
|
|
|
|
call Defer('notify-send "Vim" "'.a:message.'"', { b -> 0 })
|
|
|
|
endfun
|
|
|
|
|
2020-08-21 12:02:53 +00:00
|
|
|
comm -complete=shellcmd -nargs=* Defer call Defer(<q-args>, { r -> 0 })
|
|
|
|
comm -complete=shellcmd -nargs=* DeferEcho call Defer(<q-args>, { result -> <SID>echo("Deferred job completed (".(result['tend']-result['tstart'])."s): ".<q-args>) })
|
|
|
|
comm -complete=shellcmd -nargs=* DeferNotify call Defer(<q-args>, { result -> <SID>notify(""Deferred job completed (".(result['tend']-result['tstart'])."s):\n$ ".<q-args>) })
|