improve gitgutter integration and algorithm

This commit is contained in:
Bailey Ling 2013-08-18 21:18:21 +00:00
parent aa4c9977df
commit da4d0730d3
2 changed files with 20 additions and 16 deletions

View File

@ -2,30 +2,34 @@
" vim: et ts=2 sts=2 sw=2 " vim: et ts=2 sts=2 sw=2
function! airline#extensions#hunks#get_hunks() function! airline#extensions#hunks#get_hunks()
try if get(g:, 'gitgutter_initialised', 0) && get(g:, 'gitgutter_enabled', 0)
" throws an error when first entering a buffer, so we gotta swallow it
silent! let hunks = GitGutterGetHunks()
let added = 0 let added = 0
let removed = 0 let removed = 0
let changed = 0 let changed = 0
let hunks = GitGutterGetHunks()
for hunk in hunks for hunk in hunks
let diff = hunk[3] - hunk[1] if hunk[1] == 0 && hunk[3] > 0
if diff > 0 let added += hunk[3]
let added += diff elseif hunk[1] > 0 && hunk[3] == 0
elseif diff < 0 let removed += hunk[1]
let removed -= diff elseif hunk[1] > 0 && hunk[3] > 0
else if hunk[1] == hunk[3]
let changed += 1 let changed += hunk[3]
elseif hunk[1] < hunk[3]
let changed += hunk[1]
let added += (hunk[3] - hunk[1])
elseif hunk[1] > hunk[3]
let changed += hunk[3]
let removed += (hunk[1] - hunk[3])
endif
endif endif
endfor endfor
return printf('+%s ~%s -%s', added, changed, removed) return printf('+%s ~%s -%s ', added, changed, removed)
catch endif
return ''
endtry
return '' return ''
endfunction endfunction
function! airline#extensions#hunks#init(ext) function! airline#extensions#hunks#init(ext)
let g:airline_section_b .= '%{airline#extensions#hunks#get_hunks()} ' let g:airline_section_b .= '%{airline#extensions#hunks#get_hunks()}'
endfunction endfunction

View File

@ -21,7 +21,7 @@ call s:check_defined('g:airline_enable_branch', 1)
call s:check_defined('g:airline_enable_syntastic', 1) call s:check_defined('g:airline_enable_syntastic', 1)
call s:check_defined('g:airline_enable_tagbar', 1) call s:check_defined('g:airline_enable_tagbar', 1)
call s:check_defined('g:airline_enable_csv', 1) call s:check_defined('g:airline_enable_csv', 1)
call s:check_defined('g:airline_enable_hunks', 0) call s:check_defined('g:airline_enable_hunks', 1)
call s:check_defined('g:airline_detect_iminsert', 0) call s:check_defined('g:airline_detect_iminsert', 0)
call s:check_defined('g:airline_detect_modified', 1) call s:check_defined('g:airline_detect_modified', 1)
call s:check_defined('g:airline_detect_paste', 1) call s:check_defined('g:airline_detect_paste', 1)