diff --git a/README.mkd b/README.mkd index 54234ba..0a151cc 100644 --- a/README.mkd +++ b/README.mkd @@ -242,6 +242,7 @@ You can customise: * The sign column's colours * 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 * Line highlights * The base of the diff @@ -286,6 +287,12 @@ else 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 diff --git a/autoload/gitgutter/sign.vim b/autoload/gitgutter/sign.vim index 4c23dbe..80d21eb 100644 --- a/autoload/gitgutter/sign.vim +++ b/autoload/gitgutter/sign.vim @@ -96,7 +96,9 @@ endfunction function! s:find_current_signs(bufnr) abort let gitgutter_signs = {} " : {'id': , 'name': } - let other_signs = [] " [ signs @@ -122,14 +124,18 @@ function! s:find_current_signs(bufnr) abort endif let gitgutter_signs[line_number] = {'id': id, 'name': name} else - call add(other_signs, line_number) + if !g:gitgutter_sign_allow_clobber + call add(other_signs, line_number) + endif endif end endfor 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, 'other_signs', other_signs) + if !g:gitgutter_sign_allow_clobber + call gitgutter#utility#setbufvar(a:bufnr, 'other_signs', other_signs) + endif endfunction @@ -152,7 +158,7 @@ endfunction 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') execute "sign unplace * buffer=" . a:bufnr if dummy_sign_present @@ -167,7 +173,9 @@ endfunction 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') " 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 let line_number = line[0] " - 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]) if !has_key(old_gitgutter_signs, line_number) " insert let id = s:next_sign_id() diff --git a/doc/gitgutter.txt b/doc/gitgutter.txt index 1141722..bab6188 100644 --- a/doc/gitgutter.txt +++ b/doc/gitgutter.txt @@ -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 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_modified* *g:gitgutter_sign_removed* diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index f5a212a..5251145 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -28,6 +28,7 @@ call s:set('g:gitgutter_max_signs', 500) call s:set('g:gitgutter_signs', 1) call s:set('g:gitgutter_highlight_lines', 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) if g:gitgutter_sign_column_always && exists('&signcolumn') " Vim 7.4.2201.