Show sign on first line when line(s) deleted at start of file.

This time with silly mistake fixed.
This commit is contained in:
Andy Stewart
2014-06-02 09:20:51 +02:00
parent d1e66b71f9
commit c6e5cf49f2
7 changed files with 22 additions and 12 deletions

View File

@@ -204,6 +204,7 @@ To customise the symbols, add the following to your `~/.vimrc`:
let g:gitgutter_sign_added = 'xx'
let g:gitgutter_sign_modified = 'yy'
let g:gitgutter_sign_removed = 'zz'
let g:gitgutter_sign_removed_first_line = '^^'
let g:gitgutter_sign_modified_removed = 'ww'
```
@@ -276,10 +277,6 @@ let g:gitgutter_realtime = 0
let g:gitgutter_eager = 0
```
> Why is no sign shown if I delete the first line(s) in a file?
vim-gitgutter shows removed lines with a sign on the line above. In this case there isn't a line above so vim-gitgutter can't show the sign. In due course I'll fix this with an overline character on the first line.
> What happens if I also use another plugin which uses signs (e.g. Syntastic)?
Vim only allows one sign per line. Before adding a sign to a line, vim-gitgutter checks whether a sign has already been added by somebody else. If so it doesn't do anything. In other words vim-gitgutter won't overwrite another plugin's signs. It also won't remove another plugin's signs.

View File

@@ -142,7 +142,11 @@ function! diff#process_added(modifications, from_count, to_count, to_line)
endfunction
function! diff#process_removed(modifications, from_count, to_count, to_line)
call add(a:modifications, [a:to_line, 'removed'])
if a:to_line == 0
call add(a:modifications, [1, 'removed_first_line'])
else
call add(a:modifications, [a:to_line, 'removed'])
endif
endfunction
function! diff#process_modified(modifications, from_count, to_count, to_line)

View File

@@ -34,6 +34,7 @@ function! highlight#define_signs()
sign define GitGutterLineAdded
sign define GitGutterLineModified
sign define GitGutterLineRemoved
sign define GitGutterLineRemovedFirstLine
sign define GitGutterLineModifiedRemoved
sign define GitGutterDummy
@@ -46,6 +47,7 @@ function! highlight#define_sign_text()
execute "sign define GitGutterLineAdded text=" . g:gitgutter_sign_added
execute "sign define GitGutterLineModified text=" . g:gitgutter_sign_modified
execute "sign define GitGutterLineRemoved text=" . g:gitgutter_sign_removed
execute "sign define GitGutterLineRemovedFirstLine text=" . g:gitgutter_sign_removed_first_line
execute "sign define GitGutterLineModifiedRemoved text=" . g:gitgutter_sign_modified_removed
endfunction
@@ -68,6 +70,7 @@ function! highlight#define_sign_text_highlights()
sign define GitGutterLineAdded texthl=GitGutterAdd
sign define GitGutterLineModified texthl=GitGutterChange
sign define GitGutterLineRemoved texthl=GitGutterDelete
sign define GitGutterLineRemovedFirstLine texthl=GitGutterDelete
sign define GitGutterLineModifiedRemoved texthl=GitGutterChangeDelete
endfunction
@@ -76,11 +79,13 @@ function! highlight#define_sign_line_highlights()
sign define GitGutterLineAdded linehl=GitGutterAddLine
sign define GitGutterLineModified linehl=GitGutterChangeLine
sign define GitGutterLineRemoved linehl=GitGutterDeleteLine
sign define GitGutterLineRemovedFirstLine linehl=GitGutterDeleteLine
sign define GitGutterLineModifiedRemoved linehl=GitGutterChangeDeleteLine
else
sign define GitGutterLineAdded linehl=
sign define GitGutterLineModified linehl=
sign define GitGutterLineRemoved linehl=
sign define GitGutterLineRemovedFirstLine linehl=
sign define GitGutterLineModifiedRemoved linehl=
endif
endfunction

View File

@@ -54,7 +54,8 @@ function! hunk#prev_hunk(count)
if hunk[2] < current_line
let hunk_count += 1
if hunk_count == a:count
execute 'normal!' hunk[2] . 'G'
let target = hunk[2] == 0 ? 1 : hunk[2]
execute 'normal!' target . 'G'
break
endif
endif
@@ -69,6 +70,11 @@ function! hunk#current_hunk()
let current_line = line('.')
for hunk in s:hunks
if current_line == 1 && hunk[2] == 0
let current_hunk = hunk
break
endif
if current_line >= hunk[2] && current_line < hunk[2] + (hunk[3] == 0 ? 1 : hunk[3])
let current_hunk = hunk
break

View File

@@ -88,6 +88,8 @@ function! utility#highlight_name_for_change(text)
return 'GitGutterLineAdded'
elseif a:text ==# 'removed'
return 'GitGutterLineRemoved'
elseif a:text ==# 'removed_first_line'
return 'GitGutterLineRemovedFirstLine'
elseif a:text ==# 'modified'
return 'GitGutterLineModified'
elseif a:text ==# 'modified_removed'

View File

@@ -270,12 +270,7 @@ a. Why are the colours in the sign column weird?
Your colorscheme is configuring the |hl-SignColumn| highlight group weirdly.
Please see |GitGutterCustomisation| on customising the sign column.
b. Why is no sign shown if I delete the first line(s) in a file?
vim-gitgutter shows removed lines with a sign on the line above. In this
case there isn't a line above so vim-gitgutter can't show the sign.
c. What happens if I also use another plugin which uses signs (e.g. Syntastic)?
b. What happens if I also use another plugin which uses signs (e.g. Syntastic)?
Vim only allows one sign per line. Before adding a sign to a line,
vim-gitgutter checks whether a sign has already been added by somebody else.

View File

@@ -34,6 +34,7 @@ call s:set('g:gitgutter_eager', 1)
call s:set('g:gitgutter_sign_added', '+')
call s:set('g:gitgutter_sign_modified', '~')
call s:set('g:gitgutter_sign_removed', '_')
call s:set('g:gitgutter_sign_removed_first_line', '‾')
call s:set('g:gitgutter_sign_modified_removed', '~_')
call s:set('g:gitgutter_diff_args', '')
call s:set('g:gitgutter_escape_grep', 0)