mirror of
https://github.com/amix/vimrc
synced 2025-06-16 09:35:01 +08:00
Updated plugins
This commit is contained in:
@ -1,11 +1,6 @@
|
||||
" Vim doesn't namespace sign ids so every plugin shares the same
|
||||
" namespace. Sign ids are simply integers so to avoid clashes with other
|
||||
" signs we guess at a clear run.
|
||||
"
|
||||
" Note also we currently never reset s:next_sign_id.
|
||||
" For older Vims without sign_place() the plugin has to manaage the sign ids.
|
||||
let s:first_sign_id = 3000
|
||||
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+.
|
||||
let s:supports_star = v:version > 703 || (v:version == 703 && has("patch596"))
|
||||
|
||||
@ -27,7 +22,6 @@ function! gitgutter#sign#disable() abort
|
||||
|
||||
if !g:gitgutter_highlight_lines
|
||||
call gitgutter#sign#clear_signs(bufnr(''))
|
||||
call gitgutter#sign#remove_dummy_sign(bufnr(''), 0)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@ -40,8 +34,14 @@ function! gitgutter#sign#toggle() abort
|
||||
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
|
||||
if exists('*sign_unplace')
|
||||
call sign_unplace('gitgutter', {'buffer': a:bufnr})
|
||||
return
|
||||
endif
|
||||
|
||||
|
||||
call s:find_current_signs(a:bufnr)
|
||||
|
||||
let sign_ids = map(values(gitgutter#utility#getbufvar(a:bufnr, 'gitgutter_signs')), 'v:val.id')
|
||||
@ -55,37 +55,42 @@ endfunction
|
||||
" modified_lines: list of [<line_number (number)>, <name (string)>]
|
||||
" where name = 'added|removed|modified|modified_removed'
|
||||
function! gitgutter#sign#update_signs(bufnr, modified_lines) abort
|
||||
if exists('*sign_unplace')
|
||||
" Vim is (hopefully) now quick enough to remove all signs then place new ones.
|
||||
call sign_unplace('gitgutter', {'buffer': a:bufnr})
|
||||
|
||||
let modified_lines = s:handle_double_hunk(a:modified_lines)
|
||||
let signs = map(copy(modified_lines), '{'.
|
||||
\ '"buffer": a:bufnr,'.
|
||||
\ '"group": "gitgutter",'.
|
||||
\ '"name": s:highlight_name_for_change(v:val[1]),'.
|
||||
\ '"lnum": v:val[0],'.
|
||||
\ '"priority": g:gitgutter_sign_priority'.
|
||||
\ '}')
|
||||
|
||||
if exists('*sign_placelist')
|
||||
call sign_placelist(signs)
|
||||
return
|
||||
endif
|
||||
|
||||
for sign in signs
|
||||
call sign_place(0, sign.group, sign.name, sign.buffer, {'lnum': sign.lnum, 'priority': sign.priority})
|
||||
endfor
|
||||
return
|
||||
endif
|
||||
|
||||
|
||||
" Derive a delta between the current signs and the ones we want.
|
||||
" Remove signs from lines that no longer need a sign.
|
||||
" Upsert the remaining signs.
|
||||
|
||||
call s:find_current_signs(a:bufnr)
|
||||
|
||||
let new_gitgutter_signs_line_numbers = map(copy(a:modified_lines), 'v:val[0]')
|
||||
let obsolete_signs = s:obsolete_gitgutter_signs_to_remove(a:bufnr, new_gitgutter_signs_line_numbers)
|
||||
|
||||
let flicker_possible = s:remove_all_old_signs && !empty(a:modified_lines)
|
||||
if flicker_possible
|
||||
call s:add_dummy_sign(a:bufnr)
|
||||
endif
|
||||
|
||||
call s:remove_signs(a:bufnr, obsolete_signs, s:remove_all_old_signs)
|
||||
call s:upsert_new_gitgutter_signs(a:bufnr, a:modified_lines)
|
||||
|
||||
if flicker_possible
|
||||
call gitgutter#sign#remove_dummy_sign(a:bufnr, 0)
|
||||
endif
|
||||
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
|
||||
|
||||
|
||||
@ -96,40 +101,52 @@ endfunction
|
||||
|
||||
function! s:find_current_signs(bufnr) abort
|
||||
let gitgutter_signs = {} " <line_number (string)>: {'id': <id (number)>, 'name': <name (string)>}
|
||||
let other_signs = [] " [<line_number (number),...]
|
||||
let dummy_sign_placed = 0
|
||||
if !g:gitgutter_sign_allow_clobber
|
||||
let other_signs = [] " [<line_number (number),...]
|
||||
endif
|
||||
|
||||
redir => signs
|
||||
silent execute "sign place buffer=" . a:bufnr
|
||||
redir END
|
||||
if exists('*getbufinfo')
|
||||
let bufinfo = getbufinfo(a:bufnr)[0]
|
||||
let signs = has_key(bufinfo, 'signs') ? bufinfo.signs : []
|
||||
else
|
||||
let signs = []
|
||||
|
||||
for sign_line in filter(split(signs, '\n')[2:], 'v:val =~# "="')
|
||||
" Typical sign line: line=88 id=1234 name=GitGutterLineAdded
|
||||
" We assume splitting is faster than a regexp.
|
||||
let components = split(sign_line)
|
||||
let name = split(components[2], '=')[1]
|
||||
if name =~# 'GitGutterDummy'
|
||||
let dummy_sign_placed = 1
|
||||
else
|
||||
let line_number = str2nr(split(components[0], '=')[1])
|
||||
if name =~# 'GitGutter'
|
||||
let id = str2nr(split(components[1], '=')[1])
|
||||
" Remove orphaned signs (signs placed on lines which have been deleted).
|
||||
" (When a line is deleted its sign lingers. Subsequent lines' signs'
|
||||
" 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
|
||||
call add(other_signs, line_number)
|
||||
redir => signlines
|
||||
silent execute "sign place buffer=" . a:bufnr
|
||||
redir END
|
||||
|
||||
for signline in filter(split(signlines, '\n')[2:], 'v:val =~# "="')
|
||||
" Typical sign line before v8.1.0614: line=88 id=1234 name=GitGutterLineAdded
|
||||
" We assume splitting is faster than a regexp.
|
||||
let components = split(signline)
|
||||
call add(signs, {
|
||||
\ 'lnum': str2nr(split(components[0], '=')[1]),
|
||||
\ 'id': str2nr(split(components[1], '=')[1]),
|
||||
\ 'name': split(components[2], '=')[1]
|
||||
\ })
|
||||
endfor
|
||||
endif
|
||||
|
||||
for sign in signs
|
||||
if sign.name =~# 'GitGutter'
|
||||
" Remove orphaned signs (signs placed on lines which have been deleted).
|
||||
" (When a line is deleted its sign lingers. Subsequent lines' signs'
|
||||
" line numbers are decremented appropriately.)
|
||||
if has_key(gitgutter_signs, sign.lnum)
|
||||
execute "sign unplace" gitgutter_signs[sign.lnum].id
|
||||
endif
|
||||
end
|
||||
let gitgutter_signs[sign.lnum] = {'id': sign.id, 'name': sign.name}
|
||||
else
|
||||
if !g:gitgutter_sign_allow_clobber
|
||||
call add(other_signs, sign.lnum)
|
||||
endif
|
||||
endif
|
||||
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,12 +169,8 @@ 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'))
|
||||
let dummy_sign_present = gitgutter#utility#getbufvar(a:bufnr, 'dummy_sign')
|
||||
if a:all_signs && s:supports_star && (g:gitgutter_sign_allow_clobber || empty(gitgutter#utility#getbufvar(a:bufnr, 'other_signs')))
|
||||
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
|
||||
for id in a:sign_ids
|
||||
execute "sign unplace" id
|
||||
@ -167,21 +180,16 @@ 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:
|
||||
" lines deleted above at the start of the file, and lines deleted
|
||||
" immediately below.
|
||||
if a:modified_lines[0:1] == [[1, 'removed_first_line'], [1, 'removed']]
|
||||
let modified_lines = [[1, 'removed_above_and_below']] + a:modified_lines[2:]
|
||||
else
|
||||
let modified_lines = a:modified_lines
|
||||
endif
|
||||
let modified_lines = s:handle_double_hunk(a:modified_lines)
|
||||
|
||||
for line in modified_lines
|
||||
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])
|
||||
if !has_key(old_gitgutter_signs, line_number) " insert
|
||||
let id = s:next_sign_id()
|
||||
@ -198,6 +206,18 @@ function! s:upsert_new_gitgutter_signs(bufnr, modified_lines) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Handle special case where the first line is the site of two hunks:
|
||||
" lines deleted above at the start of the file, and lines deleted
|
||||
" immediately below.
|
||||
function! s:handle_double_hunk(modified_lines)
|
||||
if a:modified_lines[0:1] == [[1, 'removed_first_line'], [1, 'removed']]
|
||||
return [[1, 'removed_above_and_below']] + a:modified_lines[2:]
|
||||
endif
|
||||
|
||||
return a:modified_lines
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:next_sign_id() abort
|
||||
let next_id = s:next_sign_id
|
||||
let s:next_sign_id += 1
|
||||
|
Reference in New Issue
Block a user