From 31fffb0057fec7f650eec71806410e5fd3da8fa9 Mon Sep 17 00:00:00 2001 From: Leszek Swirski Date: Mon, 5 Aug 2013 13:47:53 +0100 Subject: [PATCH] Added custom callback for compile_command --- autoload/dispatch.vim | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/autoload/dispatch.vim b/autoload/dispatch.vim index 4de8a9d6..426b2001 100644 --- a/autoload/dispatch.vim +++ b/autoload/dispatch.vim @@ -253,7 +253,7 @@ if !exists('s:makes') let s:files = {} endif -function! dispatch#compile_command(bang, args) abort +function! dispatch#compile_command(bang, args, ...) abort if !empty(a:args) let args = a:args else @@ -297,6 +297,8 @@ function! dispatch#compile_command(bang, args) abort let request.command = args endif + let request.callback = a:0 >= 1 ? a:1 : "dispatch#default_callback" + if empty(request.compiler) unlet request.compiler endif @@ -395,6 +397,13 @@ function! dispatch#completed(request) abort return get(s:request(a:request), 'completed', 0) endfunction +function! dispatch#default_callback(request) abort + if !a:request.background + call s:cgetfile(a:request, 0, 0) + redraw + endif +endfunction + function! dispatch#complete(file, ...) abort if !dispatch#completed(a:file) let request = s:request(a:file) @@ -406,9 +415,8 @@ function! dispatch#complete(file, ...) abort echo 'Finished :Dispatch' request.command endif endif - if !request.background - call s:cgetfile(request, 0, 0) - redraw + if has_key(request, 'callback') && !empty(request.callback) + exec 'call '.request.callback.'(request)' endif endif return ''