From 0f2d8b26e1b52403970950d25f85b06bf1a5d0b5 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Fri, 21 Aug 2020 14:02:53 +0200 Subject: [PATCH] Add timing information to vim deferred commands --- vim/plugin/defer.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vim/plugin/defer.vim b/vim/plugin/defer.vim index e505684..3a79a14 100644 --- a/vim/plugin/defer.vim +++ b/vim/plugin/defer.vim @@ -1,9 +1,10 @@ function Defer(command, callback) + let l:start = strftime("%s") let l:buffer = [] call job_start(a:command, { \ "out_io": "pipe", \ "out_cb": { pipe, text -> add(l:buffer, text) }, - \ "close_cb": { pipe -> a:callback(l:buffer) } + \ "close_cb": { pipe -> a:callback({"output": l:buffer, "tstart": l:start, "tend":strftime("%s")}) } \ }) endfun @@ -15,6 +16,6 @@ function s:notify(message) call Defer('notify-send "Vim" "'.a:message.'"', { b -> 0 }) endfun -comm -complete=shellcmd -nargs=* Defer call Defer(, { buffer -> 0 }) -comm -complete=shellcmd -nargs=* DeferEcho call Defer(, { buffer -> echo("Deferred job completed: ".) }) -comm -complete=shellcmd -nargs=* DeferNotify call Defer(, { buffer -> notify("Deferred job completed:\n$ ".) }) +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$ ".) })