From f72ca2e6c11a9802978c3ffe11080741596e4ca1 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Mon, 30 Sep 2019 20:43:16 -0400 Subject: [PATCH] Improve ++opt +cmd handling for :Gedit/:Gread --- autoload/fugitive.vim | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index e9663a6..3835a60 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -3956,11 +3956,18 @@ function! s:UsableWin(nr) abort \ index(['nofile','help','quickfix'], getbufvar(winbufnr(a:nr), '&buftype')) < 0 endfunction -function! s:OpenParse(args) abort - let pre = [] +function! s:OpenParse(args, wants_cmd) abort + let opts = [] + let cmds = [] let args = copy(a:args) - while !empty(args) && args[0] =~# '^+' - call add(pre, ' ' . escape(remove(args, 0), ' |"')) + while !empty(args) + if args[0] =~# '^++' + call add(opts, ' ' . escape(remove(args, 0), ' |"')) + elseif a:wants_cmd && args[0] =~# '^+' + call add(cmds, remove(args, 0)[1:-1]) + else + break + endif endwhile if len(args) let file = join(args) @@ -3971,7 +3978,13 @@ function! s:OpenParse(args) abort else let file = '>' endif - return [s:Expand(file), join(pre)] + let pre = join(opts, '') + if len(cmds) > 1 + let pre .= ' +' . escape(join(map(cmds, '"exe ".string(v:val)'), '|'), ' |"') + elseif len(cmds) + let pre .= ' +' . escape(cmds[0], ' |"') + endif + return [s:Generate(s:Expand(file)), pre] endfunction function! s:DiffClose() abort @@ -4039,8 +4052,7 @@ function! fugitive#Open(cmd, bang, mods, arg, args) abort let mods = s:Mods(a:mods) try - let [file, pre] = s:OpenParse(a:args) - let file = s:Generate(file) + let [file, pre] = s:OpenParse(a:args, 1) catch /^fugitive:/ return 'echoerr ' . string(v:exception) endtry @@ -4073,8 +4085,7 @@ function! fugitive#ReadCommand(line1, count, range, bang, mods, arg, args) abort return 'redraw|echo '.string(':!'.s:UserCommand(dir, args)) endif try - let [file, pre] = s:OpenParse(a:args) - let file = s:Generate(file) + let [file, pre] = s:OpenParse(a:args, 0) catch /^fugitive:/ return 'echoerr ' . string(v:exception) endtry