Skip to content

Commit

Permalink
Show sign on first line when line(s) deleted at start of file.
Browse files Browse the repository at this point in the history
This time with silly mistake fixed.
  • Loading branch information
airblade committed Jun 2, 2014
1 parent d1e66b7 commit c6e5cf4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
5 changes: 1 addition & 4 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -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'
```

Expand Down Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion autoload/diff.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions autoload/highlight.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion autoload/hunk.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions autoload/utility.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 1 addition & 6 deletions doc/gitgutter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions plugin/gitgutter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c6e5cf4

Please sign in to comment.