commit b9c47cec52d5fb5213ef101502dca34ae82ceaec (tree)
parent 21991bcbaf5de7fd145c6ccb83cc05e7d1351496
Author: Tim Pope <code@tpope.net>
Date: Fri, 2 Aug 2019 01:01:11 -0400
Add command dispatcher
This will enable cleaning up some of the repetition in argument and
exception handling
Diffstat:
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim
@@ -581,10 +581,18 @@ function! s:add_methods(namespace, method_names) abort
endfor
endfunction
+function! s:Command(command, line1, line2, range, bang, mods, arg, args) abort
+ try
+ return s:{a:command}Command(a:line1, a:line2, a:range, a:line2, a:bang, s:Mods(a:mods), '', a:arg, a:args)
+ catch /^fugitive:/
+ return 'echoerr ' . string(v:exception)
+ endtry
+endfunction
+
let s:commands = []
function! s:command(definition, ...) abort
if a:0
- call add(s:commands, a:definition . ' execute s:' . a:1 . "Command(<line1>, <line2>, +'<range>', <count>, <bang>0, '<mods>', <q-reg>, <q-args>, [<f-args>])")
+ call add(s:commands, a:definition . ' execute s:Command(' . string(a:1) . ", <line1>, <count>, +'<range>', <bang>0, '<mods>', <q-args>, [<f-args>])")
else
call add(s:commands, a:definition)
endif