From c2fb46bceeb42eee96bb962ad852d889c116ab6a Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Tue, 29 Sep 2020 13:19:24 +0200 Subject: [PATCH] Add filename expansions to defer commands --- vim/plugin/defer.vim | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/vim/plugin/defer.vim b/vim/plugin/defer.vim index 8f4a7ca..add017f 100644 --- a/vim/plugin/defer.vim +++ b/vim/plugin/defer.vim @@ -1,30 +1,34 @@ 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 + 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) - let l:start = strftime("%s") + let l:start = strftime("%s") let l:buffer = [] call s:jobstart(a:command, { - \ "out_io": "pipe", - \ "out_cb": { pipe, text -> add(l:buffer, text) }, - \ "close_cb": { pipe -> a:callback({"output": l:buffer, "tstart": l:start, "tend":strftime("%s")}) } - \ }) + \ "out_io": "pipe", + \ "out_cb": { pipe, text -> add(l:buffer, text) }, + \ "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 function s:echo(message) - echom a:message + echom a:message endfun function s:notify(message) - call Defer('notify-send "Vim" "'.a:message.'"', { b -> 0 }) + call Defer('notify-send "Vim" "'.a:message.'"', { b -> 0 }) endfun -comm -complete=shellcmd -nargs=* Defer call Defer(, { r -> 0 }) -comm -complete=shellcmd -nargs=* DeferEcho call Defer(, { result -> echo("Deferred job completed (".(result['tend']-result['tstart'])."s): ".) }) -comm -complete=shellcmd -nargs=* DeferNotify call Defer(, { result -> notify("Deferred job completed (".(result['tend']-result['tstart'])."s):\n$ ".) }) +comm -complete=shellcmd -nargs=* Defer call Defer(s:expand(), { r -> 0 }) +comm -complete=shellcmd -nargs=* DeferEcho call Defer(s:expand(), { result -> echo("Deferred job completed (".(result['tend']-result['tstart'])."s): ".s:expand()) }) +comm -complete=shellcmd -nargs=* DeferNotify call Defer(s:expand(), { result -> notify("Deferred job completed (".(result['tend']-result['tstart'])."s):\n$ ".s:expand()) })