Limit size based :Gdiffsplit orientation to no argument variant

I don't think anybody liked this except for me.  This brings :Gdiffsplit
one step closer to :diffsplit.  The no argument version will probably be
removed eventually as well, but let's take it one step at a time.
This commit is contained in:
Tim Pope
2021-08-28 08:12:50 -04:00
parent c9aaf78541
commit a6be4a301c
2 changed files with 12 additions and 8 deletions

View File

@@ -6046,12 +6046,14 @@ function! fugitive#CanDiffoff(buf) abort
return s:can_diffoff(bufnr(a:buf)) return s:can_diffoff(bufnr(a:buf))
endfunction endfunction
function! s:diff_modifier(count) abort function! s:DiffModifier(count, default) abort
let fdc = matchstr(&diffopt, 'foldcolumn:\zs\d\+') let fdc = matchstr(&diffopt, 'foldcolumn:\zs\d\+')
if &diffopt =~# 'horizontal' && &diffopt !~# 'vertical' if &diffopt =~# 'horizontal' && &diffopt !~# 'vertical'
return '' return ''
elseif &diffopt =~# 'vertical' elseif &diffopt =~# 'vertical'
return 'vertical ' return 'vertical '
elseif !get(g:, 'fugitive_diffsplit_directional_fit', a:default)
return ''
elseif winwidth(0) <= a:count * ((&tw ? &tw : 80) + (empty(fdc) ? 2 : fdc)) elseif winwidth(0) <= a:count * ((&tw ? &tw : 80) + (empty(fdc) ? 2 : fdc))
return '' return ''
else else
@@ -6164,7 +6166,7 @@ function! fugitive#Diffsplit(autodir, keepfocus, mods, arg, args) abort
try try
if exists('parents') && len(parents) > 1 if exists('parents') && len(parents) > 1
exe pre exe pre
let mods = (autodir ? s:diff_modifier(len(parents) + 1) : '') . s:Mods(mods, 'leftabove') let mods = (autodir ? s:DiffModifier(len(parents) + 1, empty(args)) : '') . s:Mods(mods, 'leftabove')
let nr = bufnr('') let nr = bufnr('')
if len(parents) > 1 && !&equalalways if len(parents) > 1 && !&equalalways
let equalalways = 0 let equalalways = 0
@@ -6238,7 +6240,7 @@ function! fugitive#Diffsplit(autodir, keepfocus, mods, arg, args) abort
exe pre exe pre
let restore = s:diff_restore() let restore = s:diff_restore()
let w:fugitive_diff_restore = restore let w:fugitive_diff_restore = restore
let mods = (autodir ? s:diff_modifier(2) : '') . mods let mods = (autodir ? s:DiffModifier(2, empty(args)) : '') . mods
if &diffopt =~# 'vertical' if &diffopt =~# 'vertical'
let diffopt = &diffopt let diffopt = &diffopt
set diffopt-=vertical set diffopt-=vertical

View File

@@ -185,10 +185,9 @@ that are part of Git repositories).
commit is given, the current file in that commit. commit is given, the current file in that commit.
With no argument, the version in the index or work With no argument, the version in the index or work
tree is used, and the work tree version is always tree is used, and the work tree version is always
placed to the right or bottom. A vertical split is placed to the right or bottom, depending on available
used if space permits, and if 'diffopt' does not width. Use Vim's |do| and |dp| to stage and unstage
otherwise specify. Use Vim's |do| and |dp| to stage changes.
and unstage changes.
*:Gdiffsplit!* *:Gdiffsplit!*
:Gdiffsplit! Diff against any and all direct ancestors, retaining :Gdiffsplit! Diff against any and all direct ancestors, retaining
@@ -205,7 +204,10 @@ that are part of Git repositories).
:Gvdiffsplit [object] Like |:Gdiffsplit|, but always split vertically. :Gvdiffsplit [object] Like |:Gdiffsplit|, but always split vertically.
*:Ghdiffsplit* *:Ghdiffsplit*
:Ghdiffsplit [object] Like |:Gdiffsplit|, but always split horizontally. :Gdiffsplit ++novertical [object]
:Ghdiffsplit [object] Like |:Gdiffsplit|, but with "vertical" removed from
'diffopt'. The split will still be vertical if
combined with |:vertical|.
*:GMove* *:GMove*
:GMove {destination} Wrapper around git-mv that renames the buffer :GMove {destination} Wrapper around git-mv that renames the buffer