mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-11 21:03:53 -05:00
Add <mods> helper function
This commit is contained in:
@@ -74,6 +74,14 @@ function! s:warn(str) abort
|
|||||||
let v:warningmsg = a:str
|
let v:warningmsg = a:str
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:Mods(mods, ...) abort
|
||||||
|
let mods = a:mods ==# '<mods>' || empty(a:mods) ? '' : a:mods . ' '
|
||||||
|
if a:0 && mods !~# 'aboveleft\|belowright\|leftabove\|rightbelow\|topleft\|botright\|tab'
|
||||||
|
let mods = a:1 . ' ' . mods
|
||||||
|
endif
|
||||||
|
return mods
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:Slash(path) abort
|
function! s:Slash(path) abort
|
||||||
if exists('+shellslash')
|
if exists('+shellslash')
|
||||||
return tr(a:path, '\', '/')
|
return tr(a:path, '\', '/')
|
||||||
@@ -1934,10 +1942,7 @@ call s:command("-bar -bang -range=-1 G", "Status")
|
|||||||
|
|
||||||
function! s:StatusCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort
|
function! s:StatusCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort
|
||||||
try
|
try
|
||||||
let mods = a:mods ==# '<mods>' || empty(a:mods) ? '' : a:mods . ' '
|
let mods = s:Mods(a:mods, &splitbelow ? 'botright' : 'topleft')
|
||||||
if mods !~# 'aboveleft\|belowright\|leftabove\|rightbelow\|topleft\|botright'
|
|
||||||
let mods = (&splitbelow ? 'botright ' : 'topleft ') . mods
|
|
||||||
endif
|
|
||||||
let file = fugitive#Find(':')
|
let file = fugitive#Find(':')
|
||||||
let arg = ' +setl\ foldmethod=syntax\ foldlevel=1\|let\ w:fugitive_status=FugitiveGitDir() ' .
|
let arg = ' +setl\ foldmethod=syntax\ foldlevel=1\|let\ w:fugitive_status=FugitiveGitDir() ' .
|
||||||
\ s:fnameescape(file)
|
\ s:fnameescape(file)
|
||||||
@@ -2657,7 +2662,7 @@ endfunction
|
|||||||
call s:command("-nargs=? -complete=customlist,s:CommitComplete Gcommit", "Commit")
|
call s:command("-nargs=? -complete=customlist,s:CommitComplete Gcommit", "Commit")
|
||||||
|
|
||||||
function! s:CommitCommand(line1, line2, range, count, bang, mods, reg, arg, args, ...) abort
|
function! s:CommitCommand(line1, line2, range, count, bang, mods, reg, arg, args, ...) abort
|
||||||
let mods = s:gsub(a:mods ==# '<mods>' ? '' : a:mods, '<tab>', '-tab')
|
let mods = substitute(s:Mods(a:mods), '\C\<tab\>', '-tab', 'g')
|
||||||
let dir = a:0 ? a:1 : s:Dir()
|
let dir = a:0 ? a:1 : s:Dir()
|
||||||
let tree = s:Tree(dir)
|
let tree = s:Tree(dir)
|
||||||
let msgfile = fugitive#Find('.git/COMMIT_EDITMSG', dir)
|
let msgfile = fugitive#Find('.git/COMMIT_EDITMSG', dir)
|
||||||
@@ -2713,12 +2718,12 @@ function! s:CommitCommand(line1, line2, range, count, bang, mods, reg, arg, args
|
|||||||
if args !~# '\%(^\| \)--cleanup\>'
|
if args !~# '\%(^\| \)--cleanup\>'
|
||||||
let args = '--cleanup=strip '.args
|
let args = '--cleanup=strip '.args
|
||||||
endif
|
endif
|
||||||
if bufname('%') == '' && line('$') == 1 && getline(1) == '' && !&mod
|
if bufname('%') == '' && line('$') == 1 && getline(1) == '' && !&modified
|
||||||
execute mods 'keepalt edit' s:fnameescape(msgfile)
|
execute mods . 'keepalt edit' s:fnameescape(msgfile)
|
||||||
elseif a:arg =~# '\%(^\| \)-\w*v' || mods =~# '\<tab\>'
|
elseif a:arg =~# '\%(^\| \)-\w*v' || mods =~# '\<tab\>'
|
||||||
execute mods 'keepalt -tabedit' s:fnameescape(msgfile)
|
execute mods . 'keepalt -tabedit' s:fnameescape(msgfile)
|
||||||
else
|
else
|
||||||
execute mods 'keepalt split' s:fnameescape(msgfile)
|
execute mods . 'keepalt split' s:fnameescape(msgfile)
|
||||||
endif
|
endif
|
||||||
let b:fugitive_commit_arguments = args
|
let b:fugitive_commit_arguments = args
|
||||||
setlocal bufhidden=wipe filetype=gitcommit
|
setlocal bufhidden=wipe filetype=gitcommit
|
||||||
@@ -2869,7 +2874,7 @@ endfunction
|
|||||||
|
|
||||||
function! s:Merge(cmd, bang, mods, args, ...) abort
|
function! s:Merge(cmd, bang, mods, args, ...) abort
|
||||||
let dir = a:0 ? a:1 : s:Dir()
|
let dir = a:0 ? a:1 : s:Dir()
|
||||||
let mods = substitute(a:mods, '\C<mods>', '', '') . ' '
|
let mods = s:Mods(a:mods)
|
||||||
if a:cmd =~# '^rebase' && ' '.a:args =~# ' -i\| --interactive'
|
if a:cmd =~# '^rebase' && ' '.a:args =~# ' -i\| --interactive'
|
||||||
let cmd = fugitive#Prepare(dir, '-c', 'sequence.editor=sh ' . s:RebaseSequenceAborter(), 'rebase') . ' ' . a:args
|
let cmd = fugitive#Prepare(dir, '-c', 'sequence.editor=sh ' . s:RebaseSequenceAborter(), 'rebase') . ' ' . a:args
|
||||||
let out = system(cmd)[0:-2]
|
let out = system(cmd)[0:-2]
|
||||||
@@ -3193,7 +3198,7 @@ function! s:BlurStatus() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:Open(cmd, bang, mods, arg, args) abort
|
function! s:Open(cmd, bang, mods, arg, args) abort
|
||||||
let mods = a:mods ==# '<mods>' ? '' : a:mods
|
let mods = s:Mods(a:mods)
|
||||||
|
|
||||||
if a:bang
|
if a:bang
|
||||||
let temp = tempname()
|
let temp = tempname()
|
||||||
@@ -3212,7 +3217,7 @@ function! s:Open(cmd, bang, mods, arg, args) abort
|
|||||||
if a:cmd ==# 'edit'
|
if a:cmd ==# 'edit'
|
||||||
call s:BlurStatus()
|
call s:BlurStatus()
|
||||||
endif
|
endif
|
||||||
silent execute mods a:cmd temp
|
silent execute mods . a:cmd temp
|
||||||
call fugitive#ReloadStatus()
|
call fugitive#ReloadStatus()
|
||||||
return 'echo ' . string(':!' . git . ' ' . args)
|
return 'echo ' . string(':!' . git . ' ' . args)
|
||||||
endif
|
endif
|
||||||
@@ -3229,11 +3234,11 @@ function! s:Open(cmd, bang, mods, arg, args) abort
|
|||||||
if a:cmd ==# 'edit'
|
if a:cmd ==# 'edit'
|
||||||
call s:BlurStatus()
|
call s:BlurStatus()
|
||||||
endif
|
endif
|
||||||
return mods . ' ' . a:cmd . pre . ' ' . s:fnameescape(file)
|
return mods . a:cmd . pre . ' ' . s:fnameescape(file)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ReadCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort
|
function! s:ReadCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort
|
||||||
let mods = a:mods ==# '<mods>' ? '' : a:mods
|
let mods = s:Mods(a:mods)
|
||||||
let after = a:line2
|
let after = a:line2
|
||||||
if a:count < 0
|
if a:count < 0
|
||||||
let delete = 'silent 1,' . line('$') . 'delete_|'
|
let delete = 'silent 1,' . line('$') . 'delete_|'
|
||||||
@@ -3248,7 +3253,7 @@ function! s:ReadCommand(line1, line2, range, count, bang, mods, reg, arg, args)
|
|||||||
let cdback = s:Cd(s:Tree())
|
let cdback = s:Cd(s:Tree())
|
||||||
let git = s:UserCommand()
|
let git = s:UserCommand()
|
||||||
let args = s:ShellExpand(a:arg)
|
let args = s:ShellExpand(a:arg)
|
||||||
silent execute mods after.'read!' escape(git . ' --no-pager ' . args, '!#%')
|
silent execute mods . after . 'read!' escape(git . ' --no-pager ' . args, '!#%')
|
||||||
finally
|
finally
|
||||||
execute cdback
|
execute cdback
|
||||||
endtry
|
endtry
|
||||||
@@ -3263,12 +3268,12 @@ function! s:ReadCommand(line1, line2, range, count, bang, mods, reg, arg, args)
|
|||||||
return 'echoerr v:errmsg'
|
return 'echoerr v:errmsg'
|
||||||
endtry
|
endtry
|
||||||
if file =~# '^fugitive:' && after is# 0
|
if file =~# '^fugitive:' && after is# 0
|
||||||
return 'exe ' .string(mods . ' ' . fugitive#FileReadCmd(file, 0, pre)) . '|diffupdate'
|
return 'exe ' .string(mods . fugitive#FileReadCmd(file, 0, pre)) . '|diffupdate'
|
||||||
endif
|
endif
|
||||||
if foldlevel(after)
|
if foldlevel(after)
|
||||||
exe after . 'foldopen!'
|
exe after . 'foldopen!'
|
||||||
endif
|
endif
|
||||||
return mods . ' ' . after . 'read' . pre . ' ' . s:fnameescape(file) . '|' . delete . 'diffupdate' . (a:count < 0 ? '|' . line('.') : '')
|
return mods . after . 'read' . pre . ' ' . s:fnameescape(file) . '|' . delete . 'diffupdate' . (a:count < 0 ? '|' . line('.') : '')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ReadComplete(A,L,P) abort
|
function! s:ReadComplete(A,L,P) abort
|
||||||
@@ -3846,7 +3851,7 @@ function! s:BlameCommand(line1, line2, range, count, bang, mods, reg, arg, args)
|
|||||||
call s:throw(join(readfile(error),"\n"))
|
call s:throw(join(readfile(error),"\n"))
|
||||||
endif
|
endif
|
||||||
if a:count
|
if a:count
|
||||||
let edit = substitute(a:mods, '^<mods>$', '', '') . get(['edit', 'split', 'pedit'], a:line2 - a:line1, ' split')
|
let edit = s:Mods(a:mods) . get(['edit', 'split', 'pedit'], a:line2 - a:line1, ' split')
|
||||||
return s:BlameCommit(edit, get(readfile(temp), 0, ''))
|
return s:BlameCommit(edit, get(readfile(temp), 0, ''))
|
||||||
else
|
else
|
||||||
for winnr in range(winnr('$'),1,-1)
|
for winnr in range(winnr('$'),1,-1)
|
||||||
|
|||||||
Reference in New Issue
Block a user