Files
vim-gitgutter/autoload/gitgutter.vim
Andy Stewart 5bfe5b9209 Big refactor.
- Hunk stage/undo/preview no longer saves the buffer.
- Hunk undo no longer makes locations go out of sync.
- Grep can be opted out of (grep output with ansi escapes is number one cause
  of issues).
- Replaced g:gitgutter_grep_command with g:gitgutter_grep.
- Always runs git-diff the same way instead of in two possible ways.
- Separated detection of git tracking from diffing.
- Simplified path handling.
- Removed support for xolox shell: Windows taskbar does not flash with async
  jobs.
- Removed g:gitgutter_{eager,realtime}.
- Simplified implementation generally.
2018-02-12 14:25:11 +00:00

86 lines
2.1 KiB
VimL

" Primary functions {{{
function! gitgutter#all(force) abort
for bufnr in tabpagebuflist()
let file = expand('#'.bufnr.':p')
if !empty(file)
call gitgutter#init_buffer(bufnr)
call gitgutter#process_buffer(bufnr, a:force)
endif
endfor
endfunction
" Finds the file's path relative to the repo root.
function! gitgutter#init_buffer(bufnr)
let p = gitgutter#utility#repo_path(a:bufnr, 0)
if type(p) != v:t_string || empty(p)
call gitgutter#utility#set_repo_path(a:bufnr)
endif
endfunction
function! gitgutter#process_buffer(bufnr, force) abort
" NOTE a:bufnr is not necessarily the current buffer.
if gitgutter#utility#is_active(a:bufnr)
if a:force || s:has_fresh_changes(a:bufnr)
let diff = ''
try
let diff = gitgutter#diff#run_diff(a:bufnr, 0)
catch /gitgutter not tracked/
call gitgutter#debug#log('Not tracked: '.gitgutter#utility#file(a:bufnr))
catch /gitgutter diff failed/
call gitgutter#debug#log('Diff failed: '.gitgutter#utility#file(a:bufnr))
call gitgutter#hunk#reset(a:bufnr)
endtry
if diff != 'async'
call gitgutter#diff#handler(a:bufnr, diff)
endif
endif
endif
endfunction
function! gitgutter#disable() abort
" get list of all buffers (across all tabs)
let buflist = []
for i in range(tabpagenr('$'))
call extend(buflist, tabpagebuflist(i + 1))
endfor
for bufnr in buflist
let file = expand('#'.bufnr.':p')
if !empty(file)
call gitgutter#sign#clear_signs(bufnr)
call gitgutter#sign#remove_dummy_sign(bufnr, 1)
call gitgutter#hunk#reset(bufnr)
endif
endfor
let g:gitgutter_enabled = 0
endfunction
function! gitgutter#enable() abort
let g:gitgutter_enabled = 1
call gitgutter#all(1)
endfunction
function! gitgutter#toggle() abort
if g:gitgutter_enabled
call gitgutter#disable()
else
call gitgutter#enable()
endif
endfunction
" }}}
function! s:has_fresh_changes(bufnr) abort
return getbufvar(a:bufnr, 'changedtick') != gitgutter#utility#getbufvar(a:bufnr, 'tick')
endfunction