From 98bd8428b57a3dc794c158a0822be4f7b94ce7da Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 19 Aug 2021 11:09:47 -0400 Subject: [PATCH] Add optional callback to FugitiveConfig() Obvious next step is to make this asynchronous, but let's settle for getting the API in place for now. --- autoload/fugitive.vim | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 888a386..1c3664b 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -902,7 +902,18 @@ let s:config = {} function! fugitive#Config(...) abort let name = '' let default = get(a:, 3, '') - if a:0 >= 2 && type(a:2) == type({}) && has_key(a:2, 'GetAll') + if a:0 && type(a:1) == type(function('tr')) + let dir = s:Dir() + let callback = a:000 + elseif a:0 > 1 && type(a:2) == type(function('tr')) + if type(a:1) == type({}) && has_key(a:1, 'GetAll') + call call(a:2, [a:1] + a:000[2:-1]) + return a:1 + else + let dir = s:Dir(a:1) + let callback = a:000[1:-1] + endif + elseif a:0 >= 2 && type(a:2) == type({}) && has_key(a:2, 'GetAll') return get(fugitive#ConfigGetAll(a:1, a:2), 0, default) elseif a:0 >= 2 let dir = s:Dir(a:2) @@ -942,6 +953,9 @@ function! fugitive#Config(...) abort let s:config[dir_key] = [s:ConfigTimestamps(dir, dict), dict] lockvar! dict endif + if exists('callback') + call call(callback[0], [dict] + callback[1:-1]) + endif return len(name) ? get(get(dict, name, []), 0, default) : dict endfunction