Skip to content

Commit 6df2133

Browse files
committed
Add User event "SignifyHunk"
By hooking into that event, you can show "Hunk [3/15]" (third hunk from a total of 15) in the command-line, when jumping between hunks with [c, ]c and friends. See `:h signify-mappings`. Closes #363
1 parent f658976 commit 6df2133

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

autoload/sy/jump.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ function! sy#jump#next_hunk(count)
1313
if !empty(hunk)
1414
execute 'sign jump '. hunk.ids[0] .' buffer='. b:sy.buffer
1515
endif
16+
17+
if exists('#User#SignifyHunk')
18+
doautocmd <nomodeline> User SignifyHunk
19+
endif
1620
endfunction
1721

1822
" #prev_hunk {{{1
@@ -26,4 +30,8 @@ function! sy#jump#prev_hunk(count)
2630
if !empty(hunk)
2731
execute 'sign jump '. hunk.ids[0] .' buffer='. b:sy.buffer
2832
endif
33+
34+
if exists('#User#SignifyHunk')
35+
doautocmd <nomodeline> User SignifyHunk
36+
endif
2937
endfunction

autoload/sy/util.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ endfunction
115115

116116
let s:popup_window = 0
117117

118+
" #get_hunk_stats {{{1
119+
function! sy#util#get_hunk_stats() abort
120+
execute sy#util#return_if_no_changes()
121+
122+
let curline = line('.')
123+
let total_hunks = len(b:sy.hunks)
124+
125+
for i in range(total_hunks)
126+
if b:sy.hunks[i].start <= curline && b:sy.hunks[i].end >= curline
127+
return { 'total_hunks': total_hunks, 'current_hunk': i + 1 }
128+
endif
129+
endfor
130+
131+
return {}
132+
endfunction
133+
118134
" #popup_close {{{1
119135
function! sy#util#popup_close() abort
120136
if s:popup_window

doc/signify.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,17 @@ Mapping other keys:
520520
nmap <leader>gJ 9999<leader>gj
521521
nmap <leader>gK 9999<leader>gk
522522
<
523+
When you jump to a hunk, show "[Hunk 2/15]" by putting this in your vimrc:
524+
>
525+
autocmd User SignifyHunk call s:show_current_hunk()
526+
527+
function! s:show_current_hunk() abort
528+
let h = sy#util#get_hunk_stats()
529+
if !empty(h)
530+
echo printf('[Hunk %d/%d]', h.current_hunk, h.total_hunks)
531+
endif
532+
endfunction
533+
<
523534
------------------------------------------------------------------------------
524535
Hunk text object:~
525536
>

0 commit comments

Comments
 (0)