mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-09 20:13:46 -05:00
Support all <cword> style expansions
The previous implementation for <cfile> didn't handle <cfile>:h correctly. May as well support the rest of the gang while fixing this. Note that unlike for % and #, these can return a commit in addition to a file name. Use a ":." expansion, as in "<cfile>:.", to get the corresponding work tree file.
This commit is contained in:
@@ -1159,7 +1159,7 @@ function! fugitive#Object(...) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:var = '\%(%\|#<\=\d\+\|##\=\|<cfile>\)'
|
let s:var = '\%(<\%(cword\|cWORD\|cexpr\|cfile\|sfile\|slnum\|afile\|abuf\|amatch' . (has('clientserver') ? '\|client' : '') . '\)>\|%\|#<\=\d\+\|##\=\)'
|
||||||
let s:flag = '\%(:[p8~.htre]\|:g\=s\(.\).\{-\}\1.\{-\}\1\)'
|
let s:flag = '\%(:[p8~.htre]\|:g\=s\(.\).\{-\}\1.\{-\}\1\)'
|
||||||
let s:expand = '\%(\(' . s:var . '\)\(' . s:flag . '*\)\(:S\)\=\)'
|
let s:expand = '\%(\(' . s:var . '\)\(' . s:flag . '*\)\(:S\)\=\)'
|
||||||
|
|
||||||
@@ -1195,27 +1195,43 @@ 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 cfile = expand('<cfile>')
|
let bufname = 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 cfile = eval(maparg('<Plug><cfile>', 'c'))
|
let bufname = eval(maparg('<Plug><cfile>', 'c'))
|
||||||
|
if bufname ==# "\<C-R>\<C-F>"
|
||||||
|
let bufname = expand('<cfile>')
|
||||||
|
endif
|
||||||
catch
|
catch
|
||||||
endtry
|
endtry
|
||||||
endif
|
endif
|
||||||
return cfile
|
elseif a:var =~# '^<'
|
||||||
|
let bufname = s:BufName(a:var)
|
||||||
|
else
|
||||||
|
let bufname = fugitive#Real(s:BufName(a:var))
|
||||||
endif
|
endif
|
||||||
let flags = a:flags
|
let flags = a:flags
|
||||||
let file = s:DotRelative(fugitive#Real(s:BufName(a:var)), cwd)
|
let file = s:DotRelative(bufname, cwd)
|
||||||
while len(flags)
|
while len(flags)
|
||||||
let flag = matchstr(flags, s:flag)
|
let flag = matchstr(flags, s:flag)
|
||||||
let flags = strpart(flags, len(flag))
|
let flags = strpart(flags, len(flag))
|
||||||
if flag ==# ':.'
|
if flag ==# ':.'
|
||||||
let file = s:DotRelative(file, cwd)
|
let file = s:DotRelative(fugitive#Real(file), cwd)
|
||||||
else
|
else
|
||||||
let file = fnamemodify(file, flag)
|
let file = fnamemodify(file, flag)
|
||||||
endif
|
endif
|
||||||
endwhile
|
endwhile
|
||||||
let file = s:Slash(file)
|
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
|
||||||
return (len(a:esc) ? shellescape(file) : file)
|
return (len(a:esc) ? shellescape(file) : file)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -588,8 +588,9 @@ Makefile The file named Makefile in the work tree
|
|||||||
!:Makefile The file named Makefile in the commit owning the current file
|
!:Makefile The file named Makefile in the commit owning the current file
|
||||||
!3^2 The second parent of the commit owning buffer #3
|
!3^2 The second parent of the commit owning buffer #3
|
||||||
.git/config The repo config file
|
.git/config The repo config file
|
||||||
: The |fugitive-summary| buffer.
|
: The |fugitive-summary| buffer
|
||||||
- A temp file containing the last |:Git| invocation's output
|
- A temp file containing the last |:Git| invocation's output
|
||||||
|
<cfile> The file or commit under the cursor
|
||||||
|
|
||||||
STATUSLINE *fugitive-statusline*
|
STATUSLINE *fugitive-statusline*
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user