Rewrite <C-R><C-G> and y<C-G>
This commit is contained in:
parent
236bd21b45
commit
40facfde5e
@ -259,24 +259,6 @@ function! fugitive#RemoteUrl(...) abort
|
|||||||
return v:shell_error ? '' : out
|
return v:shell_error ? '' : out
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:recall() abort
|
|
||||||
let rev = s:sub(fugitive#buffer().rev(), '^/', '')
|
|
||||||
if rev ==# ':'
|
|
||||||
return matchstr(getline('.'),'^.\=\t\%([[:alpha:] ]\+: *\)\=\zs.\{-\}\ze\%( ([^()[:digit:]]\+)\)\=$\|^\d\{6} \x\{40\} \d\t\zs.*')
|
|
||||||
elseif fugitive#buffer().type('tree')
|
|
||||||
let file = matchstr(getline('.'), '\t\zs.*')
|
|
||||||
if empty(file) && line('.') > 2
|
|
||||||
let file = s:sub(getline('.'), '/$', '')
|
|
||||||
endif
|
|
||||||
if !empty(file) && rev !~# ':$'
|
|
||||||
return rev . '/' . file
|
|
||||||
else
|
|
||||||
return rev . file
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
return rev
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:map(mode, lhs, rhs, ...) abort
|
function! s:map(mode, lhs, rhs, ...) abort
|
||||||
let flags = (a:0 ? a:1 : '') . (a:rhs =~# '<Plug>' ? '' : '<script>')
|
let flags = (a:0 ? a:1 : '') . (a:rhs =~# '<Plug>' ? '' : '<script>')
|
||||||
let head = a:lhs
|
let head = a:lhs
|
||||||
@ -567,6 +549,32 @@ function! s:RemoveDot(path, ...) abort
|
|||||||
return a:path[2:-1]
|
return a:path[2:-1]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! fugitive#Object(...) abort
|
||||||
|
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '')
|
||||||
|
let [fdir, rev] = s:DirRev(a:0 ? a:1 : @%)
|
||||||
|
if s:cpath(dir) !=# s:cpath(fdir)
|
||||||
|
let rev = ''
|
||||||
|
endif
|
||||||
|
let tree = s:Tree(dir)
|
||||||
|
if empty(rev) && empty(tree)
|
||||||
|
elseif empty(rev)
|
||||||
|
let rev = fugitive#Path(a:0 ? a:1 : @%, './', dir)
|
||||||
|
let cdir = fugitive#CommonDir(dir)
|
||||||
|
if rev =~# '^\./\.git/refs/\%(tags\|heads\|remotes\)/.\|^\./\.git/\w*HEAD$'
|
||||||
|
let rev = rev[7:-1]
|
||||||
|
elseif s:cpath(cdir . '/refs/', rev[0 : len(cdir)])
|
||||||
|
let rev = strpart(rev, len(cdir)+1)
|
||||||
|
elseif rev =~# '^\./.git\%(/\|$\)'
|
||||||
|
return fnamemodify(a:0 ? a:1 : @%, ':p')
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
if rev !~# '^\.\%(/\|$\)' || s:cpath(getcwd(), tree)
|
||||||
|
return rev
|
||||||
|
else
|
||||||
|
return tree . rev[1:-1]
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:Expand(rev) abort
|
function! s:Expand(rev) abort
|
||||||
if a:rev =~# '^:[0-3]$'
|
if a:rev =~# '^:[0-3]$'
|
||||||
let file = a:rev . s:Relative(':')
|
let file = a:rev . s:Relative(':')
|
||||||
@ -977,22 +985,7 @@ function! s:buffer_path(...) dict abort
|
|||||||
return self.relative()
|
return self.relative()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:buffer_rev() dict abort
|
call s:add_methods('buffer',['getvar','getline','repo','type','spec','name','commit','path','relative'])
|
||||||
let rev = matchstr(self.spec(),'^fugitive:\%(//\)\=.\{-\}\%(//\|::\)\zs.*')
|
|
||||||
if rev =~ '^\x/'
|
|
||||||
return ':'.rev[0].':'.rev[2:-1]
|
|
||||||
elseif rev =~ '.'
|
|
||||||
return s:sub(rev,'/',':')
|
|
||||||
elseif self.spec() =~ '\.git/index$'
|
|
||||||
return ':'
|
|
||||||
elseif self.spec() =~ '\.git/refs/\|\.git/.*HEAD$'
|
|
||||||
return self.spec()[strlen(self.repo().dir())+1 : -1]
|
|
||||||
else
|
|
||||||
return self.relative('/')
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
call s:add_methods('buffer',['getvar','getline','repo','type','spec','name','commit','path','relative','rev'])
|
|
||||||
|
|
||||||
" Section: Completion
|
" Section: Completion
|
||||||
|
|
||||||
@ -3657,8 +3650,8 @@ function! fugitive#Init() abort
|
|||||||
endtry
|
endtry
|
||||||
endif
|
endif
|
||||||
if !exists('g:fugitive_no_maps')
|
if !exists('g:fugitive_no_maps')
|
||||||
call s:map('c', '<C-R><C-G>', 'fnameescape(<SID>recall())', '<expr>')
|
call s:map('c', '<C-R><C-G>', '<SID>fnameescape(fugitive#Object(@%))', '<expr>')
|
||||||
call s:map('n', 'y<C-G>', ':call setreg(v:register, <SID>recall())<CR>', '<silent>')
|
call s:map('n', 'y<C-G>', ':<C-U>call setreg(v:register, fugitive#Object(@%))<CR>', '<silent>')
|
||||||
endif
|
endif
|
||||||
if expand('%:p') =~# ':[\/][\/]'
|
if expand('%:p') =~# ':[\/][\/]'
|
||||||
let &l:path = s:sub(&path, '^\.%(,|$)', '')
|
let &l:path = s:sub(&path, '^\.%(,|$)', '')
|
||||||
|
Loading…
Reference in New Issue
Block a user