Add filename expansions to defer commands
This commit is contained in:
parent
9744203353
commit
c2fb46bcee
1 changed files with 20 additions and 16 deletions
|
@ -1,30 +1,34 @@
|
||||||
function s:jobstart(command, options)
|
function s:jobstart(command, options)
|
||||||
if has("nvim")
|
if has("nvim")
|
||||||
let a:options["on_exit"] = a:options["close_cb"]
|
let a:options["on_exit"] = a:options["close_cb"]
|
||||||
return jobstart(a:command, a:options)
|
return jobstart(a:command, a:options)
|
||||||
else
|
else
|
||||||
return job_start(a:command, a:options)
|
return job_start(a:command, a:options)
|
||||||
end
|
end
|
||||||
endfun
|
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 s:jobstart(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")}) }
|
||||||
\ })
|
\ })
|
||||||
|
endfun
|
||||||
|
|
||||||
|
function s:expand(string)
|
||||||
|
return substitute(a:string, '%[:a-z]*', '\=expand(submatch(0))', 'g')
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
function s:echo(message)
|
function s:echo(message)
|
||||||
echom a:message
|
echom a:message
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
function s:notify(message)
|
function s:notify(message)
|
||||||
call Defer('notify-send "Vim" "'.a:message.'"', { b -> 0 })
|
call Defer('notify-send "Vim" "'.a:message.'"', { b -> 0 })
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
comm -complete=shellcmd -nargs=* Defer call Defer(<q-args>, { r -> 0 })
|
comm -complete=shellcmd -nargs=* Defer call Defer(s:expand(<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=* DeferEcho call Defer(s:expand(<q-args>), { result -> <SID>echo("Deferred job completed (".(result['tend']-result['tstart'])."s): ".s:expand(<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>) })
|
comm -complete=shellcmd -nargs=* DeferNotify call Defer(s:expand(<q-args>), { result -> <SID>notify("Deferred job completed (".(result['tend']-result['tstart'])."s):\n$ ".s:expand(<q-args>)) })
|
||||||
|
|
Loading…
Reference in a new issue