mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
16
README.mkd
16
README.mkd
@@ -17,6 +17,7 @@ Features:
|
|||||||
* Provides a hunk text object.
|
* Provides a hunk text object.
|
||||||
* Diffs against index (default) or any commit.
|
* Diffs against index (default) or any commit.
|
||||||
* Allows folding all unchanged text.
|
* Allows folding all unchanged text.
|
||||||
|
* Provides fold text showing whether folded lines have been changed.
|
||||||
* Can load all hunk locations into quickfix list.
|
* Can load all hunk locations into quickfix list.
|
||||||
* Handles line endings correctly, even with repos that do CRLF conversion.
|
* Handles line endings correctly, even with repos that do CRLF conversion.
|
||||||
* Optional line highlighting.
|
* Optional line highlighting.
|
||||||
@@ -256,6 +257,21 @@ Use the `GitGutterFold` command to fold all unchanged lines, leaving just the hu
|
|||||||
|
|
||||||
Execute `GitGutterFold` a second time to restore the previous view.
|
Execute `GitGutterFold` a second time to restore the previous view.
|
||||||
|
|
||||||
|
Use `gitgutter#fold#foldtext()` to augment the default `foldtext()` with an indicator of whether the folded lines have been changed.
|
||||||
|
|
||||||
|
```viml
|
||||||
|
set foldtext=gitgutter#fold#foldtext()
|
||||||
|
```
|
||||||
|
|
||||||
|
For a closed fold with changed lines:
|
||||||
|
|
||||||
|
```
|
||||||
|
Default foldtext(): +-- 45 lines: abcdef
|
||||||
|
gitgutter#fold#foldtext(): +-- 45 lines (*): abcdef
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use `gitgutter#fold#is_changed()` in your own `foldtext` expression to find out whether the folded lines have been changed.
|
||||||
|
|
||||||
|
|
||||||
### Customisation
|
### Customisation
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,37 @@ function! gitgutter#fold#level(lnum)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function! gitgutter#fold#foldtext()
|
||||||
|
if !gitgutter#fold#is_changed()
|
||||||
|
return foldtext()
|
||||||
|
endif
|
||||||
|
|
||||||
|
return substitute(foldtext(), ':', ' (*):', '')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
" Returns 1 if any of the folded lines have been changed
|
||||||
|
" (added, removed, or modified), 0 otherwise.
|
||||||
|
function! gitgutter#fold#is_changed()
|
||||||
|
for hunk in gitgutter#hunk#hunks(bufnr(''))
|
||||||
|
let hunk_begin = hunk[2]
|
||||||
|
let hunk_end = hunk[2] + (hunk[3] == 0 ? 1 : hunk[3])
|
||||||
|
|
||||||
|
if hunk_end < v:foldstart
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
|
if hunk_begin > v:foldend
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
|
||||||
|
return 1
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
" A line in a hunk has a fold level of 0.
|
" A line in a hunk has a fold level of 0.
|
||||||
" A line within 3 lines of a hunk has a fold level of 1.
|
" A line within 3 lines of a hunk has a fold level of 1.
|
||||||
" All other lines have a fold level of 2.
|
" All other lines have a fold level of 2.
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ function SetUp()
|
|||||||
|
|
||||||
" FIXME why won't vim autoload the file?
|
" FIXME why won't vim autoload the file?
|
||||||
execute 'source' '../../autoload/gitgutter/diff_highlight.vim'
|
execute 'source' '../../autoload/gitgutter/diff_highlight.vim'
|
||||||
|
execute 'source' '../../autoload/gitgutter/fold.vim'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function TearDown()
|
function TearDown()
|
||||||
@@ -1050,3 +1051,20 @@ function Test_split()
|
|||||||
call assert_equal(['foobar', ''], gitgutter#diff_highlight#split('foobarbaz', 'baz'))
|
call assert_equal(['foobar', ''], gitgutter#diff_highlight#split('foobarbaz', 'baz'))
|
||||||
call assert_equal(['1', '2'], gitgutter#diff_highlight#split('1~2', '~'))
|
call assert_equal(['1', '2'], gitgutter#diff_highlight#split('1~2', '~'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function Test_foldtext()
|
||||||
|
8d
|
||||||
|
call s:trigger_gitgutter()
|
||||||
|
call assert_equal(0, gitgutter#fold#is_changed())
|
||||||
|
|
||||||
|
let v:foldstart = 5
|
||||||
|
let v:foldend = 9
|
||||||
|
call assert_equal(1, gitgutter#fold#is_changed())
|
||||||
|
call assert_equal('+- 5 lines (*): e', gitgutter#fold#foldtext())
|
||||||
|
|
||||||
|
let v:foldstart = 1
|
||||||
|
let v:foldend = 3
|
||||||
|
call assert_equal(0, gitgutter#fold#is_changed())
|
||||||
|
call assert_equal('+- 3 lines: a', gitgutter#fold#foldtext())
|
||||||
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user