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:
parent
bbf9e51eb2
commit
1da788a1b0
@ -1092,7 +1092,7 @@ function! s:Edit(cmd,bang,...) abort
|
||||
endif
|
||||
|
||||
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'
|
||||
let git = buffer.repo().git_command()
|
||||
let last = line('$')
|
||||
@ -1127,7 +1127,7 @@ function! s:Edit(cmd,bang,...) abort
|
||||
if a:0 && a:1 == ''
|
||||
return ''
|
||||
elseif a:0
|
||||
let file = buffer.expand(a:1)
|
||||
let file = buffer.expand(join(a:000, ' '))
|
||||
elseif expand('%') ==# ''
|
||||
let file = ':'
|
||||
elseif buffer.commit() ==# '' && buffer.path('/') !~# '^/.git\>'
|
||||
@ -1148,7 +1148,7 @@ function! s:Edit(cmd,bang,...) abort
|
||||
endfunction
|
||||
|
||||
function! s:EditComplete(A,L,P) abort
|
||||
return s:repo().superglob(a:A)
|
||||
return map(s:repo().superglob(a:A), 'fnameescape(v:val)')
|
||||
endfunction
|
||||
|
||||
function! s:EditRunComplete(A,L,P) abort
|
||||
@ -1159,20 +1159,20 @@ function! s:EditRunComplete(A,L,P) abort
|
||||
endif
|
||||
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 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 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 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=* -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: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 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=* -count -complete=customlist,s:EditRunComplete Gread :execute s:Edit((!<count> && <line1> ? '' : <count>).'read',<bang>0,<f-args>)")
|
||||
|
||||
" }}}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 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 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 Gwq :execute s:Wq(<bang>0,<f-args>)")
|
||||
|
||||
function! s:Write(force,...) abort
|
||||
if exists('b:fugitive_commit_arguments')
|
||||
@ -1202,7 +1202,7 @@ function! s:Write(force,...) abort
|
||||
endif
|
||||
let mytab = tabpagenr()
|
||||
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\>'
|
||||
return 'write'.(a:force ? '! ' : ' ').s:fnameescape(s:repo().translate(s:buffer().expand(path)))
|
||||
endif
|
||||
@ -1327,9 +1327,9 @@ endfunction
|
||||
" }}}1
|
||||
" Gdiff {{{1
|
||||
|
||||
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 Gsdiff :execute s:Diff(1,<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 Gsdiff :execute s:Diff(1,<f-args>)")
|
||||
|
||||
augroup fugitive_diff
|
||||
autocmd!
|
||||
@ -1421,20 +1421,21 @@ function! s:Diff(bang,...)
|
||||
call s:diffthis()
|
||||
return ''
|
||||
elseif a:0
|
||||
if a:1 ==# ''
|
||||
let arg = join(a:000, ' ')
|
||||
if arg ==# ''
|
||||
return ''
|
||||
elseif a:1 ==# '/'
|
||||
elseif arg ==# '/'
|
||||
let file = s:buffer().path('/')
|
||||
elseif a:1 ==# ':'
|
||||
elseif arg ==# ':'
|
||||
let file = s:buffer().path(':0:')
|
||||
elseif a:1 =~# '^:/.'
|
||||
elseif arg =~# '^:/.'
|
||||
try
|
||||
let file = s:repo().rev_parse(a:1).s:buffer().path(':')
|
||||
let file = s:repo().rev_parse(arg).s:buffer().path(':')
|
||||
catch /^fugitive:/
|
||||
return 'echoerr v:errmsg'
|
||||
endtry
|
||||
else
|
||||
let file = s:buffer().expand(a:1)
|
||||
let file = s:buffer().expand(arg)
|
||||
endif
|
||||
if file !~# ':' && file !~# '^/' && s:repo().git_chomp('cat-file','-t',file) =~# '^\%(tag\|commit\)$'
|
||||
let file = file.s:buffer().path(':')
|
||||
@ -1761,11 +1762,11 @@ endfunction
|
||||
" }}}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
|
||||
try
|
||||
let rev = a:0 ? substitute(a:1,'@[[:alnum:]_-]*\%(://.\{-\}\)\=$','','') : ''
|
||||
let rev = a:0 ? substitute(join(a:000, ' '),'@[[:alnum:]_-]*\%(://.\{-\}\)\=$','','') : ''
|
||||
if rev ==# ''
|
||||
let expanded = s:buffer().rev()
|
||||
elseif rev ==# ':'
|
||||
@ -1808,8 +1809,8 @@ function! s:Browse(bang,line1,count,...) abort
|
||||
endif
|
||||
endif
|
||||
|
||||
if a:0 && a:1 =~# '@[[:alnum:]_-]*\%(://.\{-\}\)\=$'
|
||||
let remote = matchstr(a:1,'@\zs[[:alnum:]_-]\+\%(://.\{-\}\)\=$')
|
||||
if a:0 && join(a:000, ' ') =~# '@[[:alnum:]_-]*\%(://.\{-\}\)\=$'
|
||||
let remote = matchstr(join(a:000, ' '),'@\zs[[:alnum:]_-]\+\%(://.\{-\}\)\=$')
|
||||
elseif path =~# '^\.git/refs/remotes/.'
|
||||
let remote = matchstr(path,'^\.git/refs/remotes/\zs[^/]\+')
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user