Introduce hunk text object
This commit is contained in:
parent
8cef26186e
commit
ecd0bb0dbc
@ -33,6 +33,7 @@ TOC *signify-contents*
|
||||
OPTIONS ........................ |signify-options|
|
||||
COMMANDS ....................... |signify-commands|
|
||||
MAPPINGS ....................... |signify-mappings|
|
||||
OBJECTS ........................ |signify-objects|
|
||||
COLORS ......................... |signify-colors|
|
||||
|
||||
==============================================================================
|
||||
@ -279,6 +280,21 @@ Default mapping: <leader>gt
|
||||
Toggle line highlighting for lines containing changes.
|
||||
Default mapping: <leader>gh
|
||||
|
||||
==============================================================================
|
||||
OBJECTS *signify-objects*
|
||||
|
||||
Sy also provides text objects that operate on the current hunk:
|
||||
>
|
||||
ic
|
||||
>
|
||||
Operate on all the lines of the current hunk.
|
||||
>
|
||||
ac
|
||||
<
|
||||
Does the same as ic and also removes all trailing empty lines.
|
||||
|
||||
NOTE: Don't be surprised that this also works with "deleted lines".
|
||||
|
||||
==============================================================================
|
||||
COLORS *signify-colors*
|
||||
|
||||
|
@ -89,3 +89,35 @@ function! s:save()
|
||||
write
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Text object: ac / ic {{{1
|
||||
function! s:hunk_text_object(emptylines) abort
|
||||
if !exists('b:sy')
|
||||
return
|
||||
endif
|
||||
|
||||
let lnum = line('.')
|
||||
let hunks = filter(copy(b:sy.hunks), 'v:val.start <= lnum && v:val.end >= lnum')
|
||||
|
||||
if empty(hunks)
|
||||
return
|
||||
endif
|
||||
|
||||
execute hunks[0].start
|
||||
normal! V
|
||||
|
||||
if a:emptylines
|
||||
let lnum = hunks[0].end
|
||||
while getline(lnum+1) =~ '^$'
|
||||
let lnum += 1
|
||||
endwhile
|
||||
execute lnum
|
||||
else
|
||||
execute hunks[0].end
|
||||
endif
|
||||
endfunction
|
||||
|
||||
onoremap <silent> ac :<c-u>call <sid>hunk_text_object(1)<cr>
|
||||
xnoremap <silent> ac :<c-u>call <sid>hunk_text_object(1)<cr>
|
||||
onoremap <silent> ic :<c-u>call <sid>hunk_text_object(0)<cr>
|
||||
xnoremap <silent> ic :<c-u>call <sid>hunk_text_object(0)<cr>
|
||||
|
Loading…
Reference in New Issue
Block a user