mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-10 12:33:46 -05:00
Encapsulate restore options for diff
This should make it easier to experiment with solutions for issues such as #257.
This commit is contained in:
@@ -1373,17 +1373,22 @@ function! s:diff_window_count()
|
|||||||
return c
|
return c
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:diff_restore()
|
||||||
|
let restore = 'setlocal nodiff noscrollbind'
|
||||||
|
\ . ' scrollopt=' . &l:scrollopt
|
||||||
|
\ . (&l:wrap ? ' wrap' : ' nowrap')
|
||||||
|
\ . ' foldmethod=' . &l:foldmethod
|
||||||
|
\ . ' foldcolumn=' . &l:foldcolumn
|
||||||
|
\ . ' foldlevel=' . &l:foldlevel
|
||||||
|
if has('cursorbind')
|
||||||
|
let restore .= (&l:cursorbind ? ' ' : ' no') . 'cursorbind'
|
||||||
|
endif
|
||||||
|
return restore
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:diffthis()
|
function! s:diffthis()
|
||||||
if !&diff
|
if !&diff
|
||||||
let w:fugitive_diff_restore = 'setlocal nodiff noscrollbind'
|
let w:fugitive_diff_restore = s:diff_restore()
|
||||||
let w:fugitive_diff_restore .= ' scrollopt=' . &l:scrollopt
|
|
||||||
let w:fugitive_diff_restore .= &l:wrap ? ' wrap' : ' nowrap'
|
|
||||||
let w:fugitive_diff_restore .= ' foldmethod=' . &l:foldmethod
|
|
||||||
let w:fugitive_diff_restore .= ' foldcolumn=' . &l:foldcolumn
|
|
||||||
let w:fugitive_diff_restore .= ' foldlevel=' . &l:foldlevel
|
|
||||||
if has('cursorbind')
|
|
||||||
let w:fugitive_diff_restore .= (&l:cursorbind ? ' ' : ' no') . 'cursorbind'
|
|
||||||
endif
|
|
||||||
diffthis
|
diffthis
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
@@ -1434,16 +1439,16 @@ endfunction
|
|||||||
call s:add_methods('buffer',['compare_age'])
|
call s:add_methods('buffer',['compare_age'])
|
||||||
|
|
||||||
function! s:Diff(bang,...)
|
function! s:Diff(bang,...)
|
||||||
let split = a:bang ? 'split' : 'vsplit'
|
let vert = a:bang ? '' : 'vertical '
|
||||||
if exists(':DiffGitCached')
|
if exists(':DiffGitCached')
|
||||||
return 'DiffGitCached'
|
return 'DiffGitCached'
|
||||||
elseif (!a:0 || a:1 == ':') && s:buffer().commit() =~# '^[0-1]\=$' && s:repo().git_chomp_in_tree('ls-files', '--unmerged', '--', s:buffer().path()) !=# ''
|
elseif (!a:0 || a:1 == ':') && s:buffer().commit() =~# '^[0-1]\=$' && s:repo().git_chomp_in_tree('ls-files', '--unmerged', '--', s:buffer().path()) !=# ''
|
||||||
let nr = bufnr('')
|
let nr = bufnr('')
|
||||||
execute 'leftabove '.split.' `=fugitive#buffer().repo().translate(s:buffer().expand('':2''))`'
|
execute 'leftabove '.vert.'split `=fugitive#buffer().repo().translate(s:buffer().expand('':2''))`'
|
||||||
execute 'nnoremap <buffer> <silent> dp :diffput '.nr.'<Bar>diffupdate<CR>'
|
execute 'nnoremap <buffer> <silent> dp :diffput '.nr.'<Bar>diffupdate<CR>'
|
||||||
call s:diffthis()
|
call s:diffthis()
|
||||||
wincmd p
|
wincmd p
|
||||||
execute 'rightbelow '.split.' `=fugitive#buffer().repo().translate(s:buffer().expand('':3''))`'
|
execute 'rightbelow '.vert.'split `=fugitive#buffer().repo().translate(s:buffer().expand('':3''))`'
|
||||||
execute 'nnoremap <buffer> <silent> dp :diffput '.nr.'<Bar>diffupdate<CR>'
|
execute 'nnoremap <buffer> <silent> dp :diffput '.nr.'<Bar>diffupdate<CR>'
|
||||||
call s:diffthis()
|
call s:diffthis()
|
||||||
wincmd p
|
wincmd p
|
||||||
@@ -1476,9 +1481,9 @@ function! s:Diff(bang,...)
|
|||||||
let spec = s:repo().translate(file)
|
let spec = s:repo().translate(file)
|
||||||
let commit = matchstr(spec,'\C[^:/]//\zs\x\+')
|
let commit = matchstr(spec,'\C[^:/]//\zs\x\+')
|
||||||
if s:buffer().compare_age(commit) < 0
|
if s:buffer().compare_age(commit) < 0
|
||||||
execute 'rightbelow '.split.' '.s:fnameescape(spec)
|
execute 'rightbelow '.vert.'split '.s:fnameescape(spec)
|
||||||
else
|
else
|
||||||
execute 'leftabove '.split.' '.s:fnameescape(spec)
|
execute 'leftabove '.vert.'split '.s:fnameescape(spec)
|
||||||
endif
|
endif
|
||||||
call s:diffthis()
|
call s:diffthis()
|
||||||
wincmd p
|
wincmd p
|
||||||
|
|||||||
Reference in New Issue
Block a user