Do not use a dummy sign to keep the sign column open.

This removes the g:gitgutter_sign_column_always option.

Vim 7.4.2201 introduced the |signcolumn| option to configure when the
signcolumn is visible, building in behaviour which the plugin provided
manually.

Although it would be good to maintain this feature for older Vims, the
complexity added by the code outweighs the benefit of backward
compatibility.
This commit is contained in:
Andy Stewart
2019-08-16 12:06:28 +01:00
parent f6f425e4cf
commit afe94ede1b
6 changed files with 18 additions and 71 deletions

View File

@@ -159,7 +159,7 @@ With Neovim 0.3.2 or higher, you can turn line number highlighting on and off (d
Note that if you have line highlighting on and signs off, you will have an empty sign column more accurately, a sign column with invisible signs. This is because line highlighting requires signs and Vim always shows the sign column even if the signs are invisible. Note that if you have line highlighting on and signs off, you will have an empty sign column more accurately, a sign column with invisible signs. This is because line highlighting requires signs and Vim always shows the sign column even if the signs are invisible.
If you switch off both line highlighting and signs, you won't see the sign column. That is unless you configure the sign column always to be there (see Sign Column section). If you switch off both line highlighting and signs, you won't see the sign column.
To keep your Vim snappy, vim-gitgutter will suppress the signs when a file has more than 500 changes. As soon as the number of changes falls below the limit vim-gitgutter will show the signs again. You can configure the threshold with: To keep your Vim snappy, vim-gitgutter will suppress the signs when a file has more than 500 changes. As soon as the number of changes falls below the limit vim-gitgutter will show the signs again. You can configure the threshold with:
@@ -293,11 +293,8 @@ highlight SignColumn guibg=whatever " gVim/MacVim
By default the sign column will appear when there are signs to show and disappear when there aren't. To always have the sign column, add to your vimrc: By default the sign column will appear when there are signs to show and disappear when there aren't. To always have the sign column, add to your vimrc:
```viml ```viml
if exists('&signcolumn') " Vim 7.4.2201 " Vim 7.4.2201
set signcolumn=yes set signcolumn=yes
else
let g:gitgutter_sign_column_always = 1
endif
``` ```
GitGutter can preserve or ignore non-gitgutter signs. On Vim and Neovim < 0.4.0, gitgutter will default to preserving other signs; on Neovim >= 0.4.0 gitgutter defaults to ignoring them. You can control this with: GitGutter can preserve or ignore non-gitgutter signs. On Vim and Neovim < 0.4.0, gitgutter will default to preserving other signs; on Neovim >= 0.4.0 gitgutter defaults to ignoring them. You can control this with:

View File

@@ -175,7 +175,6 @@ endfunction
function! s:clear(bufnr) function! s:clear(bufnr)
call gitgutter#sign#clear_signs(a:bufnr) call gitgutter#sign#clear_signs(a:bufnr)
call gitgutter#sign#remove_dummy_sign(a:bufnr, 1)
call gitgutter#hunk#reset(a:bufnr) call gitgutter#hunk#reset(a:bufnr)
call s:reset_tick(a:bufnr) call s:reset_tick(a:bufnr)
call gitgutter#utility#setbufvar(a:bufnr, 'path', '') call gitgutter#utility#setbufvar(a:bufnr, 'path', '')

View File

@@ -4,7 +4,6 @@ function! gitgutter#highlight#line_disable() abort
if !g:gitgutter_signs if !g:gitgutter_signs
call gitgutter#sign#clear_signs(bufnr('')) call gitgutter#sign#clear_signs(bufnr(''))
call gitgutter#sign#remove_dummy_sign(bufnr(''), 0)
endif endif
redraw! redraw!
@@ -37,7 +36,6 @@ function! gitgutter#highlight#linenr_disable() abort
if !g:gitgutter_signs if !g:gitgutter_signs
call gitgutter#sign#clear_signs(bufnr('')) call gitgutter#sign#clear_signs(bufnr(''))
call gitgutter#sign#remove_dummy_sign(bufnr(''), 0)
endif endif
redraw! redraw!
@@ -113,7 +111,6 @@ function! gitgutter#highlight#define_signs() abort
sign define GitGutterLineRemovedFirstLine sign define GitGutterLineRemovedFirstLine
sign define GitGutterLineRemovedAboveAndBelow sign define GitGutterLineRemovedAboveAndBelow
sign define GitGutterLineModifiedRemoved sign define GitGutterLineModifiedRemoved
sign define GitGutterDummy
call s:define_sign_text() call s:define_sign_text()
call gitgutter#highlight#define_sign_text_highlights() call gitgutter#highlight#define_sign_text_highlights()

View File

@@ -5,7 +5,6 @@
" Note also we currently never reset s:next_sign_id. " Note also we currently never reset s:next_sign_id.
let s:first_sign_id = 3000 let s:first_sign_id = 3000
let s:next_sign_id = s:first_sign_id let s:next_sign_id = s:first_sign_id
let s:dummy_sign_id = s:first_sign_id - 1
" Remove-all-signs optimisation requires Vim 7.3.596+. " Remove-all-signs optimisation requires Vim 7.3.596+.
let s:supports_star = v:version > 703 || (v:version == 703 && has("patch596")) let s:supports_star = v:version > 703 || (v:version == 703 && has("patch596"))
@@ -27,7 +26,6 @@ function! gitgutter#sign#disable() abort
if !g:gitgutter_highlight_lines if !g:gitgutter_highlight_lines
call gitgutter#sign#clear_signs(bufnr('')) call gitgutter#sign#clear_signs(bufnr(''))
call gitgutter#sign#remove_dummy_sign(bufnr(''), 0)
endif endif
endfunction endfunction
@@ -40,7 +38,7 @@ function! gitgutter#sign#toggle() abort
endfunction endfunction
" Removes gitgutter's signs (excluding dummy sign) from the buffer being processed. " Removes gitgutter's signs from the buffer being processed.
function! gitgutter#sign#clear_signs(bufnr) abort function! gitgutter#sign#clear_signs(bufnr) abort
call s:find_current_signs(a:bufnr) call s:find_current_signs(a:bufnr)
@@ -65,21 +63,6 @@ function! gitgutter#sign#update_signs(bufnr, modified_lines) abort
endfunction endfunction
function! s:add_dummy_sign(bufnr) abort
if !gitgutter#utility#getbufvar(a:bufnr, 'dummy_sign')
execute "sign place" s:dummy_sign_id "line=" . 9999 "name=GitGutterDummy buffer=" . a:bufnr
call gitgutter#utility#setbufvar(a:bufnr, 'dummy_sign', 1)
endif
endfunction
function! gitgutter#sign#remove_dummy_sign(bufnr, force) abort
if gitgutter#utility#getbufvar(a:bufnr, 'dummy_sign') && (a:force || !g:gitgutter_sign_column_always)
execute "sign unplace" s:dummy_sign_id "buffer=" . a:bufnr
call gitgutter#utility#setbufvar(a:bufnr, 'dummy_sign', 0)
endif
endfunction
" "
" Internal functions " Internal functions
" "
@@ -90,7 +73,6 @@ function! s:find_current_signs(bufnr) abort
if !g:gitgutter_sign_allow_clobber if !g:gitgutter_sign_allow_clobber
let other_signs = [] " [<line_number (number),...] let other_signs = [] " [<line_number (number),...]
endif endif
let dummy_sign_placed = 0
redir => signs redir => signs
silent execute "sign place buffer=" . a:bufnr silent execute "sign place buffer=" . a:bufnr
@@ -101,28 +83,23 @@ function! s:find_current_signs(bufnr) abort
" We assume splitting is faster than a regexp. " We assume splitting is faster than a regexp.
let components = split(sign_line) let components = split(sign_line)
let name = split(components[2], '=')[1] let name = split(components[2], '=')[1]
if name =~# 'GitGutterDummy' let line_number = str2nr(split(components[0], '=')[1])
let dummy_sign_placed = 1 if name =~# 'GitGutter'
else let id = str2nr(split(components[1], '=')[1])
let line_number = str2nr(split(components[0], '=')[1]) " Remove orphaned signs (signs placed on lines which have been deleted).
if name =~# 'GitGutter' " (When a line is deleted its sign lingers. Subsequent lines' signs'
let id = str2nr(split(components[1], '=')[1]) " line numbers are decremented appropriately.)
" Remove orphaned signs (signs placed on lines which have been deleted). if has_key(gitgutter_signs, line_number)
" (When a line is deleted its sign lingers. Subsequent lines' signs' execute "sign unplace" gitgutter_signs[line_number].id
" line numbers are decremented appropriately.)
if has_key(gitgutter_signs, line_number)
execute "sign unplace" gitgutter_signs[line_number].id
endif
let gitgutter_signs[line_number] = {'id': id, 'name': name}
else
if !g:gitgutter_sign_allow_clobber
call add(other_signs, line_number)
endif
endif endif
end let gitgutter_signs[line_number] = {'id': id, 'name': name}
else
if !g:gitgutter_sign_allow_clobber
call add(other_signs, line_number)
endif
endif
endfor 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, 'gitgutter_signs', gitgutter_signs)
if !g:gitgutter_sign_allow_clobber if !g:gitgutter_sign_allow_clobber
call gitgutter#utility#setbufvar(a:bufnr, 'other_signs', other_signs) call gitgutter#utility#setbufvar(a:bufnr, 'other_signs', other_signs)
@@ -150,11 +127,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 && (g:gitgutter_sign_allow_clobber || 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 execute "sign unplace * buffer=" . a:bufnr
if dummy_sign_present
execute "sign place" s:dummy_sign_id "line=" . 9999 "name=GitGutterDummy buffer=" . a:bufnr
endif
else else
for id in a:sign_ids for id in a:sign_ids
execute "sign unplace" id execute "sign unplace" id

View File

@@ -292,7 +292,6 @@ Signs:~
|g:gitgutter_sign_removed| |g:gitgutter_sign_removed|
|g:gitgutter_sign_removed_first_line| |g:gitgutter_sign_removed_first_line|
|g:gitgutter_sign_modified_removed| |g:gitgutter_sign_modified_removed|
|g:gitgutter_sign_column_always|
|g:gitgutter_override_sign_column_highlight| |g:gitgutter_override_sign_column_highlight|
Terminal:~ Terminal:~
@@ -409,17 +408,6 @@ Defaults:
You can use unicode characters but not images. Signs must not take up more than You can use unicode characters but not images. Signs must not take up more than
2 columns. 2 columns.
*g:gitgutter_sign_column_always*
Default: 0
This legacy option controls whether the sign column should always be shown, even
if there are no signs to display.
From Vim 7.4.2201, use 'signcolumn' instead:
>
set signcolumn=yes
<
*g:gitgutter_override_sign_column_highlight* *g:gitgutter_override_sign_column_highlight*
Default: 1 Default: 1

View File

@@ -32,13 +32,6 @@ if has('nvim-0.4.0') && !exists('g:gitgutter_sign_allow_clobber')
let g:gitgutter_sign_allow_clobber = 1 let g:gitgutter_sign_allow_clobber = 1
endif endif
call s:set('g:gitgutter_sign_allow_clobber', 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.
set signcolumn=yes
let g:gitgutter_sign_column_always = 0
call gitgutter#utility#warn('please replace "let g:gitgutter_sign_column_always=1" with "set signcolumn=yes"')
endif
call s:set('g:gitgutter_override_sign_column_highlight', 1) call s:set('g:gitgutter_override_sign_column_highlight', 1)
call s:set('g:gitgutter_sign_added', '+') call s:set('g:gitgutter_sign_added', '+')
call s:set('g:gitgutter_sign_modified', '~') call s:set('g:gitgutter_sign_modified', '~')