Support expanding ## as argument list

Closes https://github.com/tpope/vim-fugitive/issues/1792
This commit is contained in:
Tim Pope
2021-07-16 18:38:00 -04:00
parent 1c2663f516
commit 58516a13c6

View File

@@ -1283,44 +1283,50 @@ function! s:ExpandVar(other, var, flags, esc, ...) abort
let owner = s:Owner(buffer) let owner = s:Owner(buffer)
return len(owner) ? owner : '@' return len(owner) ? owner : '@'
elseif a:var ==# '<cfile>' elseif a:var ==# '<cfile>'
let bufname = expand('<cfile>') let bufnames = [expand('<cfile>')]
if v:version >= 704 && get(maparg('<Plug><cfile>', 'c', 0, 1), 'expr') if v:version >= 704 && get(maparg('<Plug><cfile>', 'c', 0, 1), 'expr')
try try
let bufname = eval(maparg('<Plug><cfile>', 'c')) let bufnames = [eval(maparg('<Plug><cfile>', 'c'))]
if bufname ==# "\<C-R>\<C-F>" if bufnames[0] ==# "\<C-R>\<C-F>"
let bufname = expand('<cfile>') let bufnames = [expand('<cfile>')]
endif endif
catch catch
endtry endtry
endif endif
elseif a:var =~# '^<' elseif a:var =~# '^<'
let bufname = s:BufName(a:var) let bufnames = [s:BufName(a:var)]
elseif a:var ==# '##'
let bufnames = map(argv(), 'fugitive#Real(v:val)')
else else
let bufname = fugitive#Real(s:BufName(a:var)) let bufnames = [fugitive#Real(s:BufName(a:var))]
endif endif
let flags = a:flags let files = []
let file = s:DotRelative(bufname, cwd) for bufname in bufnames
while len(flags) let flags = a:flags
let flag = matchstr(flags, s:flag) let file = s:DotRelative(bufname, cwd)
let flags = strpart(flags, len(flag)) while len(flags)
if flag ==# ':.' let flag = matchstr(flags, s:flag)
let file = s:DotRelative(fugitive#Real(file), cwd) let flags = strpart(flags, len(flag))
else if flag ==# ':.'
let file = fnamemodify(file, flag) let file = s:DotRelative(fugitive#Real(file), cwd)
else
let file = fnamemodify(file, flag)
endif
endwhile
let file = s:Slash(file)
if file =~# '^fugitive://'
let [dir, commit, file_candidate] = s:DirCommitFile(file)
let tree = s:Tree(dir)
if len(tree) && len(file_candidate)
let file = (commit =~# '^.$' ? ':' : '') . commit . ':' .
\ s:DotRelative(tree . file_candidate)
elseif empty(file_candidate) && commit !~# '^.$'
let file = commit
endif
endif endif
endwhile call add(files, len(a:esc) ? shellescape(file) : file)
let file = s:Slash(file) endfor
if file =~# '^fugitive://' return join(files, "\1")
let [dir, commit, file_candidate] = s:DirCommitFile(file)
let tree = s:Tree(dir)
if len(tree) && len(file_candidate)
let file = (commit =~# '^.$' ? ':' : '') . commit . ':' .
\ s:DotRelative(tree . file_candidate)
elseif empty(file_candidate) && commit !~# '^.$'
let file = commit
endif
endif
return (len(a:esc) ? shellescape(file) : file)
endfunction endfunction
function! s:Expand(rev, ...) abort function! s:Expand(rev, ...) abort
@@ -1337,13 +1343,13 @@ function! s:Expand(rev, ...) abort
endif endif
return substitute(file, return substitute(file,
\ '\(\\[' . s:fnameescape . ']\|^\\[>+-]\|!\d*\)\|' . s:expand, \ '\(\\[' . s:fnameescape . ']\|^\\[>+-]\|!\d*\)\|' . s:expand,
\ '\=s:ExpandVar(submatch(1),submatch(2),submatch(3),"", a:0 ? a:1 : getcwd())', 'g') \ '\=tr(s:ExpandVar(submatch(1),submatch(2),submatch(3),"", a:0 ? a:1 : getcwd()), "\1", " ")', 'g')
endfunction endfunction
function! fugitive#Expand(object) abort function! fugitive#Expand(object) abort
return substitute(a:object, return substitute(a:object,
\ '\(\\[' . s:fnameescape . ']\|^\\[>+-]\|!\d*\)\|' . s:expand, \ '\(\\[' . s:fnameescape . ']\|^\\[>+-]\|!\d*\)\|' . s:expand,
\ '\=s:ExpandVar(submatch(1),submatch(2),submatch(3),submatch(5))', 'g') \ '\=tr(s:ExpandVar(submatch(1),submatch(2),submatch(3),submatch(5)), "\1", " ")', 'g')
endfunction endfunction
function! s:SplitExpandChain(string, ...) abort function! s:SplitExpandChain(string, ...) abort
@@ -1365,7 +1371,7 @@ function! s:SplitExpandChain(string, ...) abort
let arg = substitute(arg, let arg = substitute(arg,
\ '\(' . dquote . '''\%(''''\|[^'']\)*''\|\\[' . s:fnameescape . ']\|^\\[>+-]\|!\d*\)\|' . s:expand, \ '\(' . dquote . '''\%(''''\|[^'']\)*''\|\\[' . s:fnameescape . ']\|^\\[>+-]\|!\d*\)\|' . s:expand,
\ '\=s:ExpandVar(submatch(1),submatch(2),submatch(3),submatch(5), cwd)', 'g') \ '\=s:ExpandVar(submatch(1),submatch(2),submatch(3),submatch(5), cwd)', 'g')
call add(list, arg) call extend(list, split(arg, "\1", 1))
if arg ==# '--' if arg ==# '--'
let seen_separator = 1 let seen_separator = 1
endif endif