mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-09 12:03:48 -05:00
Extract utility functions.
This commit is contained in:
@@ -28,6 +28,14 @@ function! utility#has_unsaved_changes(file)
|
|||||||
return getbufvar(a:file, "&mod")
|
return getbufvar(a:file, "&mod")
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! utility#has_fresh_changes(file)
|
||||||
|
return getbufvar(a:file, 'changedtick') != getbufvar(a:file, 'gitgutter_last_tick', -1)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! utility#save_last_seen_change(file)
|
||||||
|
call setbufvar(a:file, 'gitgutter_last_tick', getbufvar(a:file, 'changedtick'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
" https://github.com/tpope/vim-dispatch/blob/9cdd05a87f8a47120335be03dfcd8358544221cd/autoload/dispatch/windows.vim#L8-L17
|
" https://github.com/tpope/vim-dispatch/blob/9cdd05a87f8a47120335be03dfcd8358544221cd/autoload/dispatch/windows.vim#L8-L17
|
||||||
function! utility#escape(str)
|
function! utility#escape(str)
|
||||||
if &shellxquote ==# '"'
|
if &shellxquote ==# '"'
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ command GitGutterAll call GitGutterAll()
|
|||||||
function! GitGutter(file, realtime)
|
function! GitGutter(file, realtime)
|
||||||
call utility#set_file(a:file)
|
call utility#set_file(a:file)
|
||||||
if utility#is_active()
|
if utility#is_active()
|
||||||
if !a:realtime || getbufvar(a:file, 'changedtick') != getbufvar(a:file, 'gitgutter_last_tick', -1)
|
if !a:realtime || utility#has_fresh_changes(a:file)
|
||||||
let diff = diff#run_diff(a:realtime || utility#has_unsaved_changes(a:file))
|
let diff = diff#run_diff(a:realtime || utility#has_unsaved_changes(a:file))
|
||||||
let s:hunks = diff#parse_diff(diff)
|
let s:hunks = diff#parse_diff(diff)
|
||||||
let modified_lines = diff#process_hunks(s:hunks)
|
let modified_lines = diff#process_hunks(s:hunks)
|
||||||
@@ -68,7 +68,7 @@ function! GitGutter(file, realtime)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
call sign#update_signs(a:file, modified_lines)
|
call sign#update_signs(a:file, modified_lines)
|
||||||
call setbufvar(a:file, 'gitgutter_last_tick', getbufvar(a:file, 'changedtick'))
|
call utility#save_last_seen_change(a:file)
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
call hunk#reset()
|
call hunk#reset()
|
||||||
|
|||||||
Reference in New Issue
Block a user