Fall back to "commit" line for file hunk jump maps

This enables jumping from commit to commit in :Git log.
This commit is contained in:
Tim Pope 2019-08-02 16:02:19 -04:00
parent e5a6a8c525
commit 9ac6a258d6
2 changed files with 27 additions and 16 deletions

View File

@ -2236,7 +2236,7 @@ function! s:StageJump(offset, section, ...) abort
let line = search('^' . a:section, 'nw') let line = search('^' . a:section, 'nw')
if line if line
exe line exe line
return s:NextFileHunk(a:offset ? a:offset : 1) return s:NextItem(a:offset ? a:offset : 1)
endif endif
return '' return ''
endfunction endfunction
@ -2622,23 +2622,36 @@ function! s:StageReveal(...) abort
while getline(end) =~# '^[ \+-]' while getline(end) =~# '^[ \+-]'
let end += 1 let end += 1
endwhile endwhile
elseif getline(begin) =~# '^commit '
let end = begin
while end < line('$') && getline(end + 1) !~# '^commit '
let end += 1
endwhile
endif
if exists('end')
while line('w$') < line('$') && end > line('w$') && line('.') > line('w0') + &scrolloff while line('w$') < line('$') && end > line('w$') && line('.') > line('w0') + &scrolloff
execute "normal! \<C-E>" execute "normal! \<C-E>"
endwhile endwhile
endif endif
endfunction endfunction
function! s:NextFileHunk(count) abort let s:item_pattern = '^[A-Z?] .\|^diff --\|^\%(\l\{3,\} \)\=[0-9a-f]\{4,\} \|^@'
function! s:NextItem(count) abort
for i in range(a:count) for i in range(a:count)
call search('^[A-Z?] .\|^diff --\|^\%(\l\{3,\} \)\=[0-9a-f]\{4,\} \|^@','W') if !search(s:item_pattern, 'W') && getline('.') !~# s:item_pattern
call search('^commit ', 'W')
endif
endfor endfor
call s:StageReveal() call s:StageReveal()
return '.' return '.'
endfunction endfunction
function! s:PreviousFileHunk(count) abort function! s:PreviousItem(count) abort
for i in range(a:count) for i in range(a:count)
call search('^[A-Z?] .\|^diff --\|^[0-9a-f]\{4,\} \|^@','Wbe') if !search(s:item_pattern, 'Wbe') && getline('.') !~# s:item_pattern
call search('^commit ', 'Wbe')
endif
endfor endfor
call s:StageReveal() call s:StageReveal()
return '.' return '.'
@ -4935,15 +4948,15 @@ function! fugitive#MapJumps(...) abort
nnoremap <buffer> <silent> p :<C-U>exe <SID>GF("pedit")<CR> nnoremap <buffer> <silent> p :<C-U>exe <SID>GF("pedit")<CR>
if exists(':CtrlP') && get(g:, 'ctrl_p_map') =~? '^<c-p>$' if exists(':CtrlP') && get(g:, 'ctrl_p_map') =~? '^<c-p>$'
nnoremap <buffer> <silent> <C-P> :<C-U>execute line('.') == 1 ? 'CtrlP ' . fnameescape(<SID>Tree()) : <SID>PreviousFileHunk(v:count1)<CR> nnoremap <buffer> <silent> <C-P> :<C-U>execute line('.') == 1 ? 'CtrlP ' . fnameescape(<SID>Tree()) : <SID>PreviousItem(v:count1)<CR>
else else
nnoremap <buffer> <silent> <C-P> :<C-U>execute <SID>PreviousFileHunk(v:count1)<CR> nnoremap <buffer> <silent> <C-P> :<C-U>execute <SID>PreviousItem(v:count1)<CR>
endif endif
nnoremap <buffer> <silent> <C-N> :<C-U>execute <SID>NextFileHunk(v:count1)<CR> nnoremap <buffer> <silent> <C-N> :<C-U>execute <SID>NextItem(v:count1)<CR>
call s:MapEx('(', 'exe <SID>PreviousFileHunk(v:count1)') call s:MapEx('(', 'exe <SID>PreviousItem(v:count1)')
call s:MapEx(')', 'exe <SID>NextFileHunk(v:count1)') call s:MapEx(')', 'exe <SID>NextItem(v:count1)')
call s:MapEx('K', 'exe <SID>PreviousFileHunk(v:count1)') call s:MapEx('K', 'exe <SID>PreviousItem(v:count1)')
call s:MapEx('J', 'exe <SID>NextFileHunk(v:count1)') call s:MapEx('J', 'exe <SID>NextItem(v:count1)')
call s:MapEx('[[', 'exe <SID>PreviousSection(v:count1)') call s:MapEx('[[', 'exe <SID>PreviousSection(v:count1)')
call s:MapEx(']]', 'exe <SID>NextSection(v:count1)') call s:MapEx(']]', 'exe <SID>NextSection(v:count1)')
endif endif

View File

@ -333,12 +333,10 @@ P Open the current file in the [count]th parent.
C Open the commit containing the current file. C Open the commit containing the current file.
*fugitive_CTRL-P* *fugitive_(* *fugitive_CTRL-P* *fugitive_(*
( Jump to the previous file or hunk. ( Jump to the previous file, hunk, or revision.
<C-P>
*fugitive_CTRL-N* *fugitive_)* *fugitive_CTRL-N* *fugitive_)*
) Jump to the next file or hunk. ) Jump to the next file, hunk, or revision.
<C-N>
*fugitive_i* *fugitive_i*
i Jump to the next file or hunk, expanding inline diffs i Jump to the next file or hunk, expanding inline diffs