motiejus/dotfiles

Unnamed repository; edit this file 'description' to name the repository.
git clone https://git.jakstys.lt/motiejus/dotfiles.git
Log | Tree | Refs | README | LICENSE

commit cd8bd3956702025aad8bdcc033f27b17fc793ca7 (tree)
parent d4d2b9c6b237d2cba256e33c0755a46be2071447
Author: Tim Pope <code@tpope.net>
Date:   Wed,  7 Apr 2021 00:11:33 -0400

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.

Diffstat:
Mautoload/fugitive.vim | 28++++++++++++++++++++++------
Mdoc/fugitive.txt | 3++-
2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim @@ -1159,7 +1159,7 @@ function! fugitive#Object(...) abort endif 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:expand = '\%(\(' . s:var . '\)\(' . s:flag . '*\)\(:S\)\=\)' @@ -1195,27 +1195,43 @@ function! s:ExpandVar(other, var, flags, esc, ...) abort let owner = s:Owner(buffer) return len(owner) ? owner : '@' elseif a:var ==# '<cfile>' - let cfile = expand('<cfile>') + let bufname = expand('<cfile>') if v:version >= 704 && get(maparg('<Plug><cfile>', 'c', 0, 1), 'expr') 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 endtry endif - return cfile + elseif a:var =~# '^<' + let bufname = s:BufName(a:var) + else + let bufname = fugitive#Real(s:BufName(a:var)) endif let flags = a:flags - let file = s:DotRelative(fugitive#Real(s:BufName(a:var)), cwd) + let file = s:DotRelative(bufname, cwd) while len(flags) let flag = matchstr(flags, s:flag) let flags = strpart(flags, len(flag)) if flag ==# ':.' - let file = s:DotRelative(file, cwd) + 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 return (len(a:esc) ? shellescape(file) : file) endfunction diff --git a/doc/fugitive.txt b/doc/fugitive.txt @@ -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 !3^2 The second parent of the commit owning buffer #3 .git/config The repo config file -: The |fugitive-summary| buffer. +: The |fugitive-summary| buffer - A temp file containing the last |:Git| invocation's output +<cfile> The file or commit under the cursor STATUSLINE *fugitive-statusline*