Add g:gitgutter_sign_allow_clobber to control clobbering.

I.e. how gitgutter handles non-gitgutter signs.

See #565, #627.

Co-authored-by: Andy Stewart <boss@airbladesoftware.com>
This commit is contained in:
Dan Aloni
2019-08-10 07:27:13 +01:00
committed by Andy Stewart
parent de200ffdd4
commit 9bf988bd1d
4 changed files with 28 additions and 6 deletions

View File

@@ -242,6 +242,7 @@ You can customise:
* The sign column's colours * The sign column's colours
* Whether or not the sign column is shown when there aren't any signs (defaults to no) * Whether or not the sign column is shown when there aren't any signs (defaults to no)
* How to handle non-gitgutter signs
* The signs' colours and symbols * The signs' colours and symbols
* Line highlights * Line highlights
* The base of the diff * The base of the diff
@@ -286,6 +287,12 @@ else
endif endif
``` ```
GitGutter will preserve non-gitgutter signs by default. If you don't want gitgutter to worry about this (e.g. if you use a NeoVim with an expanding sign column):
```viml
let g:gitgutter_sign_allow_clobber = 1
```
#### Signs' colours and symbols #### Signs' colours and symbols

View File

@@ -96,7 +96,9 @@ endfunction
function! s:find_current_signs(bufnr) abort function! s:find_current_signs(bufnr) abort
let gitgutter_signs = {} " <line_number (string)>: {'id': <id (number)>, 'name': <name (string)>} let gitgutter_signs = {} " <line_number (string)>: {'id': <id (number)>, 'name': <name (string)>}
let other_signs = [] " [<line_number (number),...] if !g:gitgutter_sign_allow_clobber
let other_signs = [] " [<line_number (number),...]
endif
let dummy_sign_placed = 0 let dummy_sign_placed = 0
redir => signs redir => signs
@@ -122,14 +124,18 @@ function! s:find_current_signs(bufnr) abort
endif endif
let gitgutter_signs[line_number] = {'id': id, 'name': name} let gitgutter_signs[line_number] = {'id': id, 'name': name}
else else
call add(other_signs, line_number) if !g:gitgutter_sign_allow_clobber
call add(other_signs, line_number)
endif
endif endif
end end
endfor endfor
call gitgutter#utility#setbufvar(a:bufnr, 'dummy_sign', dummy_sign_placed) call gitgutter#utility#setbufvar(a:bufnr, 'dummy_sign', dummy_sign_placed)
call gitgutter#utility#setbufvar(a:bufnr, 'gitgutter_signs', gitgutter_signs) call gitgutter#utility#setbufvar(a:bufnr, 'gitgutter_signs', gitgutter_signs)
call gitgutter#utility#setbufvar(a:bufnr, 'other_signs', other_signs) if !g:gitgutter_sign_allow_clobber
call gitgutter#utility#setbufvar(a:bufnr, 'other_signs', other_signs)
endif
endfunction endfunction
@@ -152,7 +158,7 @@ endfunction
function! s:remove_signs(bufnr, sign_ids, all_signs) abort function! s:remove_signs(bufnr, sign_ids, all_signs) abort
if a:all_signs && s:supports_star && empty(gitgutter#utility#getbufvar(a:bufnr, 'other_signs')) if a:all_signs && s:supports_star && (g:gitgutter_sign_allow_clobber || empty(gitgutter#utility#getbufvar(a:bufnr, 'other_signs')))
let dummy_sign_present = gitgutter#utility#getbufvar(a:bufnr, 'dummy_sign') let dummy_sign_present = gitgutter#utility#getbufvar(a:bufnr, 'dummy_sign')
execute "sign unplace * buffer=" . a:bufnr execute "sign unplace * buffer=" . a:bufnr
if dummy_sign_present if dummy_sign_present
@@ -167,7 +173,9 @@ endfunction
function! s:upsert_new_gitgutter_signs(bufnr, modified_lines) abort function! s:upsert_new_gitgutter_signs(bufnr, modified_lines) abort
let other_signs = gitgutter#utility#getbufvar(a:bufnr, 'other_signs') if !g:gitgutter_sign_allow_clobber
let other_signs = gitgutter#utility#getbufvar(a:bufnr, 'other_signs')
endif
let old_gitgutter_signs = gitgutter#utility#getbufvar(a:bufnr, 'gitgutter_signs') let old_gitgutter_signs = gitgutter#utility#getbufvar(a:bufnr, 'gitgutter_signs')
" Handle special case where the first line is the site of two hunks: " Handle special case where the first line is the site of two hunks:
@@ -181,7 +189,7 @@ function! s:upsert_new_gitgutter_signs(bufnr, modified_lines) abort
for line in modified_lines for line in modified_lines
let line_number = line[0] " <number> let line_number = line[0] " <number>
if index(other_signs, line_number) == -1 " don't clobber others' signs if g:gitgutter_sign_allow_clobber || index(other_signs, line_number) == -1 " don't clobber others' signs
let name = s:highlight_name_for_change(line[1]) let name = s:highlight_name_for_change(line[1])
if !has_key(old_gitgutter_signs, line_number) " insert if !has_key(old_gitgutter_signs, line_number) " insert
let id = s:next_sign_id() let id = s:next_sign_id()

View File

@@ -376,6 +376,12 @@ signs, so to avoid slowing down the GUI the number of signs is capped. When
the number of changed lines exceeds this value, the plugin removes all signs the number of changed lines exceeds this value, the plugin removes all signs
and displays a warning message. and displays a warning message.
*g:gitgutter_sign_allow_clobber*
Default: 0
Determines whether gitgutter preserves non-gitgutter signs (the default). When
1, gitgutter will not preserve non-gitgutter signs.
*g:gitgutter_sign_added* *g:gitgutter_sign_added*
*g:gitgutter_sign_modified* *g:gitgutter_sign_modified*
*g:gitgutter_sign_removed* *g:gitgutter_sign_removed*

View File

@@ -28,6 +28,7 @@ call s:set('g:gitgutter_max_signs', 500)
call s:set('g:gitgutter_signs', 1) call s:set('g:gitgutter_signs', 1)
call s:set('g:gitgutter_highlight_lines', 0) call s:set('g:gitgutter_highlight_lines', 0)
call s:set('g:gitgutter_highlight_linenrs', 0) call s:set('g:gitgutter_highlight_linenrs', 0)
call s:set('g:gitgutter_sign_allow_clobber', 0)
call s:set('g:gitgutter_sign_column_always', 0) call s:set('g:gitgutter_sign_column_always', 0)
if g:gitgutter_sign_column_always && exists('&signcolumn') if g:gitgutter_sign_column_always && exists('&signcolumn')
" Vim 7.4.2201. " Vim 7.4.2201.