commit 8ce49ebea0a11c5c91d8ff38f10b9d5cfcf01a3f (tree)
parent 6cf850dd001d24f458f119f8f22502e408d8a7b4
Author: Tim Pope <code@tpope.net>
Date: Sat, 1 Oct 2011 17:25:18 -0400
Jump from blame to commit focuses relevant diff
Diffstat:
1 file changed, 44 insertions(+), 3 deletions(-)
diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim
@@ -1488,9 +1488,9 @@ function! s:Blame(bang,line1,line2,count,args) abort
nnoremap <buffer> <silent> <CR> :<C-U>exe <SID>BlameJump('')<CR>
nnoremap <buffer> <silent> P :<C-U>exe <SID>BlameJump('^'.v:count1)<CR>
nnoremap <buffer> <silent> ~ :<C-U>exe <SID>BlameJump('~'.v:count1)<CR>
- nnoremap <buffer> <silent> i :<C-U>exe "exe 'norm q'<Bar>".<SID>Edit("edit", 0, matchstr(getline('.'),'\x\+'))<CR>
- nnoremap <buffer> <silent> o :<C-U>exe <SID>Edit((&splitbelow ? "botright" : "topleft")." split", 0, matchstr(getline('.'),'\x\+'))<CR>
- nnoremap <buffer> <silent> O :<C-U>exe <SID>Edit("tabedit", 0, matchstr(getline('.'),'\x\+'))<CR>
+ nnoremap <buffer> <silent> i :<C-U>exe <SID>BlameCommit("exe 'norm q'<Bar>edit")<CR>
+ nnoremap <buffer> <silent> o :<C-U>exe <SID>BlameCommit((&splitbelow ? "botright" : "topleft")." split")<CR>
+ nnoremap <buffer> <silent> O :<C-U>exe <SID>BlameCommit("tabedit")<CR>
redraw
syncbind
endif
@@ -1505,6 +1505,47 @@ function! s:Blame(bang,line1,line2,count,args) abort
endtry
endfunction
+function! s:BlameCommit(cmd) abort
+ let cmd = s:Edit(a:cmd, 0, matchstr(getline('.'),'\x\+'))
+ if cmd =~# '^echoerr'
+ return cmd
+ endif
+ let lnum = matchstr(getline('.'),' \zs\d\+\ze\s\+[([:digit:]]')
+ let path = matchstr(getline('.'),'^\^\=\x\+\s\+\zs.\{-\}\ze\s*\d\+ ')
+ if path ==# ''
+ let path = s:buffer(b:fugitive_blamed_bufnr).path()
+ endif
+ execute cmd
+ if search('^diff .* b/\M'.escape(path,'\').'$','W')
+ call search('^+++')
+ let head = line('.')
+ while search('^@@ \|^diff ') && getline('.') =~# '^@@ '
+ let top = +matchstr(getline('.'),' +\zs\d\+')
+ let len = +matchstr(getline('.'),' +\d\+,\zs\d\+')
+ if lnum >= top && lnum <= top + len
+ let offset = lnum - top
+ if &scrolloff
+ +
+ normal! zt
+ else
+ normal! zt
+ +
+ endif
+ while offset > 0 && line('.') < line('$')
+ +
+ if getline('.') =~# '^[ +]'
+ let offset -= 1
+ endif
+ endwhile
+ return ''
+ endif
+ endwhile
+ execute head
+ normal! zt
+ endif
+ return ''
+endfunction
+
function! s:BlameJump(suffix) abort
let commit = matchstr(getline('.'),'^\^\=\zs\x\+')
if commit =~# '^0\+$'