Unify escaping rules for :Gedit with :edit

In particular, this makes `:Gedit file\ with\ spaces` work, and updates
the tab complete to match.

Closes #305.
This commit is contained in:
Tim Pope 2013-02-10 12:57:37 -05:00
parent bbf9e51eb2
commit 1da788a1b0

View File

@ -1092,7 +1092,7 @@ function! s:Edit(cmd,bang,...) abort
endif endif
if a:bang if a:bang
let args = s:gsub(a:0 ? a:1 : '', '\\@<!%(\\\\)*\zs[%#]', '\=s:buffer().expand(submatch(0))') let args = s:gsub(join(a:000, ' '), '\\@<!%(\\\\)*\zs[%#]', '\=s:buffer().expand(submatch(0))')
if a:cmd =~# 'read' if a:cmd =~# 'read'
let git = buffer.repo().git_command() let git = buffer.repo().git_command()
let last = line('$') let last = line('$')
@ -1127,7 +1127,7 @@ function! s:Edit(cmd,bang,...) abort
if a:0 && a:1 == '' if a:0 && a:1 == ''
return '' return ''
elseif a:0 elseif a:0
let file = buffer.expand(a:1) let file = buffer.expand(join(a:000, ' '))
elseif expand('%') ==# '' elseif expand('%') ==# ''
let file = ':' let file = ':'
elseif buffer.commit() ==# '' && buffer.path('/') !~# '^/.git\>' elseif buffer.commit() ==# '' && buffer.path('/') !~# '^/.git\>'
@ -1148,7 +1148,7 @@ function! s:Edit(cmd,bang,...) abort
endfunction endfunction
function! s:EditComplete(A,L,P) abort function! s:EditComplete(A,L,P) abort
return s:repo().superglob(a:A) return map(s:repo().superglob(a:A), 'fnameescape(v:val)')
endfunction endfunction
function! s:EditRunComplete(A,L,P) abort function! s:EditRunComplete(A,L,P) abort
@ -1159,20 +1159,20 @@ function! s:EditRunComplete(A,L,P) abort
endif endif
endfunction endfunction
call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Ge :execute s:Edit('edit<bang>',0,<f-args>)") call s:command("-bar -bang -nargs=* -complete=customlist,s:EditComplete Ge :execute s:Edit('edit<bang>',0,<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Gedit :execute s:Edit('edit<bang>',0,<f-args>)") call s:command("-bar -bang -nargs=* -complete=customlist,s:EditComplete Gedit :execute s:Edit('edit<bang>',0,<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:EditRunComplete Gpedit :execute s:Edit('pedit',<bang>0,<f-args>)") call s:command("-bar -bang -nargs=* -complete=customlist,s:EditRunComplete Gpedit :execute s:Edit('pedit',<bang>0,<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:EditRunComplete Gsplit :execute s:Edit('split',<bang>0,<f-args>)") call s:command("-bar -bang -nargs=* -complete=customlist,s:EditRunComplete Gsplit :execute s:Edit('split',<bang>0,<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:EditRunComplete Gvsplit :execute s:Edit('vsplit',<bang>0,<f-args>)") call s:command("-bar -bang -nargs=* -complete=customlist,s:EditRunComplete Gvsplit :execute s:Edit('vsplit',<bang>0,<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:EditRunComplete Gtabedit :execute s:Edit('tabedit',<bang>0,<f-args>)") call s:command("-bar -bang -nargs=* -complete=customlist,s:EditRunComplete Gtabedit :execute s:Edit('tabedit',<bang>0,<f-args>)")
call s:command("-bar -bang -nargs=? -count -complete=customlist,s:EditRunComplete Gread :execute s:Edit((!<count> && <line1> ? '' : <count>).'read',<bang>0,<f-args>)") call s:command("-bar -bang -nargs=* -count -complete=customlist,s:EditRunComplete Gread :execute s:Edit((!<count> && <line1> ? '' : <count>).'read',<bang>0,<f-args>)")
" }}}1 " }}}1
" Gwrite, Gwq {{{1 " Gwrite, Gwq {{{1
call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Gwrite :execute s:Write(<bang>0,<f-args>)") call s:command("-bar -bang -nargs=* -complete=customlist,s:EditComplete Gwrite :execute s:Write(<bang>0,<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Gw :execute s:Write(<bang>0,<f-args>)") call s:command("-bar -bang -nargs=* -complete=customlist,s:EditComplete Gw :execute s:Write(<bang>0,<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Gwq :execute s:Wq(<bang>0,<f-args>)") call s:command("-bar -bang -nargs=* -complete=customlist,s:EditComplete Gwq :execute s:Wq(<bang>0,<f-args>)")
function! s:Write(force,...) abort function! s:Write(force,...) abort
if exists('b:fugitive_commit_arguments') if exists('b:fugitive_commit_arguments')
@ -1202,7 +1202,7 @@ function! s:Write(force,...) abort
endif endif
let mytab = tabpagenr() let mytab = tabpagenr()
let mybufnr = bufnr('') let mybufnr = bufnr('')
let path = a:0 ? a:1 : s:buffer().path() let path = a:0 ? join(a:000, ' ') : s:buffer().path()
if path =~# '^:\d\>' if path =~# '^:\d\>'
return 'write'.(a:force ? '! ' : ' ').s:fnameescape(s:repo().translate(s:buffer().expand(path))) return 'write'.(a:force ? '! ' : ' ').s:fnameescape(s:repo().translate(s:buffer().expand(path)))
endif endif
@ -1327,9 +1327,9 @@ endfunction
" }}}1 " }}}1
" Gdiff {{{1 " Gdiff {{{1
call s:command("-bang -bar -nargs=? -complete=customlist,s:EditComplete Gdiff :execute s:Diff(<bang>0,<f-args>)") call s:command("-bang -bar -nargs=* -complete=customlist,s:EditComplete Gdiff :execute s:Diff(<bang>0,<f-args>)")
call s:command("-bar -nargs=? -complete=customlist,s:EditComplete Gvdiff :execute s:Diff(0,<f-args>)") call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gvdiff :execute s:Diff(0,<f-args>)")
call s:command("-bar -nargs=? -complete=customlist,s:EditComplete Gsdiff :execute s:Diff(1,<f-args>)") call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gsdiff :execute s:Diff(1,<f-args>)")
augroup fugitive_diff augroup fugitive_diff
autocmd! autocmd!
@ -1421,20 +1421,21 @@ function! s:Diff(bang,...)
call s:diffthis() call s:diffthis()
return '' return ''
elseif a:0 elseif a:0
if a:1 ==# '' let arg = join(a:000, ' ')
if arg ==# ''
return '' return ''
elseif a:1 ==# '/' elseif arg ==# '/'
let file = s:buffer().path('/') let file = s:buffer().path('/')
elseif a:1 ==# ':' elseif arg ==# ':'
let file = s:buffer().path(':0:') let file = s:buffer().path(':0:')
elseif a:1 =~# '^:/.' elseif arg =~# '^:/.'
try try
let file = s:repo().rev_parse(a:1).s:buffer().path(':') let file = s:repo().rev_parse(arg).s:buffer().path(':')
catch /^fugitive:/ catch /^fugitive:/
return 'echoerr v:errmsg' return 'echoerr v:errmsg'
endtry endtry
else else
let file = s:buffer().expand(a:1) let file = s:buffer().expand(arg)
endif endif
if file !~# ':' && file !~# '^/' && s:repo().git_chomp('cat-file','-t',file) =~# '^\%(tag\|commit\)$' if file !~# ':' && file !~# '^/' && s:repo().git_chomp('cat-file','-t',file) =~# '^\%(tag\|commit\)$'
let file = file.s:buffer().path(':') let file = file.s:buffer().path(':')
@ -1761,11 +1762,11 @@ endfunction
" }}}1 " }}}1
" Gbrowse {{{1 " Gbrowse {{{1
call s:command("-bar -bang -range -nargs=? -complete=customlist,s:EditComplete Gbrowse :execute s:Browse(<bang>0,<line1>,<count>,<f-args>)") call s:command("-bar -bang -range -nargs=* -complete=customlist,s:EditComplete Gbrowse :execute s:Browse(<bang>0,<line1>,<count>,<f-args>)")
function! s:Browse(bang,line1,count,...) abort function! s:Browse(bang,line1,count,...) abort
try try
let rev = a:0 ? substitute(a:1,'@[[:alnum:]_-]*\%(://.\{-\}\)\=$','','') : '' let rev = a:0 ? substitute(join(a:000, ' '),'@[[:alnum:]_-]*\%(://.\{-\}\)\=$','','') : ''
if rev ==# '' if rev ==# ''
let expanded = s:buffer().rev() let expanded = s:buffer().rev()
elseif rev ==# ':' elseif rev ==# ':'
@ -1808,8 +1809,8 @@ function! s:Browse(bang,line1,count,...) abort
endif endif
endif endif
if a:0 && a:1 =~# '@[[:alnum:]_-]*\%(://.\{-\}\)\=$' if a:0 && join(a:000, ' ') =~# '@[[:alnum:]_-]*\%(://.\{-\}\)\=$'
let remote = matchstr(a:1,'@\zs[[:alnum:]_-]\+\%(://.\{-\}\)\=$') let remote = matchstr(join(a:000, ' '),'@\zs[[:alnum:]_-]\+\%(://.\{-\}\)\=$')
elseif path =~# '^\.git/refs/remotes/.' elseif path =~# '^\.git/refs/remotes/.'
let remote = matchstr(path,'^\.git/refs/remotes/\zs[^/]\+') let remote = matchstr(path,'^\.git/refs/remotes/\zs[^/]\+')
else else