From f32bdf1a7ba0bf5c2bea5965d765e3a03af9e00c Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 21 Jun 2014 13:44:44 -0400 Subject: [PATCH] Only :diffoff our own diffs Closes #395. --- plugin/fugitive.vim | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 34e7b68..891bbe6 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -1408,19 +1408,25 @@ call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gsdiff :execut augroup fugitive_diff autocmd! autocmd BufWinLeave * - \ if getwinvar(bufwinnr(+expand('')), '&diff') && - \ s:diff_window_count() == 2 && - \ !empty(getbufvar(+expand(''), 'git_dir')) | + \ if s:can_diffoff(+expand('')) && s:diff_window_count() == 2 | \ call s:diffoff_all(getbufvar(+expand(''), 'git_dir')) | \ endif autocmd BufWinEnter * - \ if getwinvar(bufwinnr(+expand('')), '&diff') && - \ s:diff_window_count() == 1 && - \ !empty(getbufvar(+expand(''), 'git_dir')) | + \ if s:can_diffoff(+expand('')) && s:diff_window_count() == 1 | \ call s:diffoff() | \ endif augroup END +function! s:can_diffoff(buf) abort + return getwinvar(bufwinnr(a:buf), '&diff') && + \ !empty(getbufvar(a:buf, 'git_dir')) && + \ !empty(getwinvar(bufwinnr(a:buf), 'fugitive_diff_restore')) +endfunction + +function! fugitive#can_diffoff(buf) abort + return s:can_diffoff(a:buf) +endfunction + function! s:diff_horizontal(count) abort let fdc = matchstr(&diffopt, 'foldcolumn:\zs\d\+') if &diffopt =~# 'horizontal' && &diffopt !~# 'vertical'