1
0
mirror of https://github.com/amix/vimrc synced 2025-06-16 01:25:00 +08:00

Updated plugins

This commit is contained in:
amix
2014-04-18 13:58:02 +01:00
parent ac3ef260c8
commit 6a16a9393c
91 changed files with 2554 additions and 708 deletions

View File

@ -29,7 +29,7 @@ endfunction
function! s:shellesc(arg) abort
if a:arg =~ '^[A-Za-z0-9_/.-]\+$'
return a:arg
elseif &shell =~# 'cmd'
elseif &shell =~# 'cmd' || &shell =~# 'power'
return '"'.s:gsub(s:gsub(a:arg, '"', '""'), '\%', '"%"').'"'
else
return shellescape(a:arg)
@ -49,14 +49,14 @@ function! s:throw(string) abort
throw v:errmsg
endfunction
function! s:warn(str)
function! s:warn(str) abort
echohl WarningMsg
echomsg a:str
echohl None
let v:warningmsg = a:str
endfunction
function! s:shellslash(path)
function! s:shellslash(path) abort
if exists('+shellslash') && !&shellslash
return s:gsub(a:path,'\\','/')
else
@ -73,7 +73,7 @@ function! fugitive#git_version(...) abort
return s:git_versions[g:fugitive_git_executable]
endfunction
function! s:recall()
function! s:recall() abort
let rev = s:sub(s:buffer().rev(), '^/', '')
if rev ==# ':'
return matchstr(getline('.'),'^#\t\%([[:alpha:] ]\+: *\)\=\zs.\{-\}\ze\%( ([^()[:digit:]]\+)\)\=$\|^\d\{6} \x\{40\} \d\t\zs.*')
@ -102,7 +102,7 @@ function! s:command(definition) abort
let s:commands += [a:definition]
endfunction
function! s:define_commands()
function! s:define_commands() abort
for command in s:commands
exe 'command! -buffer '.command
endfor
@ -164,7 +164,7 @@ function! fugitive#extract_git_dir(path) abort
return ''
endfunction
function! fugitive#detect(path)
function! fugitive#detect(path) abort
if exists('b:git_dir') && (b:git_dir ==# '' || b:git_dir =~# '/$')
unlet b:git_dir
endif
@ -198,6 +198,7 @@ augroup fugitive
autocmd FileType netrw call fugitive#detect(expand('%:p'))
autocmd User NERDTreeInit,NERDTreeNewRoot call fugitive#detect(b:NERDTreeRoot.path.str())
autocmd VimEnter * if expand('<amatch>')==''|call fugitive#detect(getcwd())|endif
autocmd CmdWinEnter * call fugitive#detect(expand('#:p'))
autocmd BufWinLeave * execute getwinvar(+bufwinnr(+expand('<abuf>')), 'fugitive_leave')
augroup END
@ -221,7 +222,7 @@ function! s:repo(...) abort
call s:throw('not a git repository: '.expand('%:p'))
endfunction
function! fugitive#repo(...)
function! fugitive#repo(...) abort
return call('s:repo', a:000)
endfunction
@ -322,6 +323,8 @@ function! s:repo_head(...) dict abort
" truncate hash to a:1 characters if we're in detached head mode
let len = a:0 ? a:1 : 0
let branch = len ? head[0:len-1] : ''
else
return ''
endif
return branch
@ -466,7 +469,7 @@ function! s:buffer_setvar(var,value) dict abort
endfunction
function! s:buffer_getline(lnum) dict abort
return getbufline(self['#'],a:lnum)[0]
return get(getbufline(self['#'], a:lnum), 0, '')
endfunction
function! s:buffer_repo() dict abort
@ -752,15 +755,15 @@ function! s:stage_info(lnum) abort
endif
endfunction
function! s:StageNext(count)
function! s:StageNext(count) abort
for i in range(a:count)
call search('^#\t.*','W')
endfor
return '.'
endfunction
function! s:StagePrevious(count)
if line('.') == 1 && exists(':CtrlP')
function! s:StagePrevious(count) abort
if line('.') == 1 && exists(':CtrlP') && get(g:, 'ctrl_p_map') =~? '^<c-p>$'
return 'CtrlP '.fnameescape(s:repo().tree())
else
for i in range(a:count)
@ -770,7 +773,7 @@ function! s:StagePrevious(count)
endif
endfunction
function! s:StageReloadSeek(target,lnum1,lnum2)
function! s:StageReloadSeek(target,lnum1,lnum2) abort
let jump = a:target
let f = matchstr(getline(a:lnum1-1),'^#\t\%([[:alpha:] ]\+: *\|.*\%uff1a *\)\=\zs.*')
if f !=# '' | let jump = f | endif
@ -949,7 +952,7 @@ function! s:Commit(args) abort
try
try
execute cd.s:fnameescape(s:repo().tree())
if &shell =~# 'cmd'
if &shell =~# 'cmd' || &shell =~# 'power'
let command = ''
let old_editor = $GIT_EDITOR
let $GIT_EDITOR = 'false'
@ -959,7 +962,7 @@ function! s:Commit(args) abort
let command .= s:repo().git_command('commit').' '.a:args
if &shell =~# 'csh'
noautocmd silent execute '!('.command.' > '.outfile.') >& '.errorfile
elseif a:args =~# '\%(^\| \)--interactive\>'
elseif a:args =~# '\%(^\| \)-\%(-interactive\|p\|-patch\)\>'
noautocmd execute '!'.command.' 2> '.errorfile
else
noautocmd silent execute '!'.command.' > '.outfile.' 2> '.errorfile
@ -982,7 +985,7 @@ function! s:Commit(args) abort
let error = get(errors,-2,get(errors,-1,'!'))
if error =~# 'false''\=\.$'
let args = a:args
let args = s:gsub(args,'%(%(^| )-- )@<!%(^| )@<=%(-[es]|--edit|--interactive|--signoff)%($| )','')
let args = s:gsub(args,'%(%(^| )-- )@<!%(^| )@<=%(-[esp]|--edit|--interactive|patch|--signoff)%($| )','')
let args = s:gsub(args,'%(%(^| )-- )@<!%(^| )@<=%(-F|--file|-m|--message)%(\s+|\=)%(''[^'']*''|"%(\\.|[^"])*"|\\.|\S)*','')
let args = s:gsub(args,'%(^| )@<=[%#]%(:\w)*','\=expand(submatch(0))')
let args = '-F '.s:shellesc(msgfile).' '.args
@ -1028,7 +1031,7 @@ function! s:CommitComplete(A,L,P) abort
endif
endfunction
function! s:FinishCommit()
function! s:FinishCommit() abort
let args = getbufvar(+expand('<abuf>'),'fugitive_commit_arguments')
if !empty(args)
call setbufvar(+expand('<abuf>'),'fugitive_commit_arguments','')
@ -1091,7 +1094,7 @@ function! s:Grep(cmd,bang,arg) abort
endtry
endfunction
function! s:Log(cmd,...)
function! s:Log(cmd,...) abort
let path = s:buffer().path('/')
if path =~# '^/\.git\%(/\|$\)' || index(a:000,'--') != -1
let path = ''
@ -1389,11 +1392,11 @@ call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gsdiff :execut
augroup fugitive_diff
autocmd!
autocmd BufWinLeave * if s:diff_window_count() == 2 && &diff && getbufvar(+expand('<abuf>'), 'git_dir') !=# '' | call s:diffoff_all(getbufvar(+expand('<abuf>'), 'git_dir')) | endif
autocmd BufWinEnter * if s:diff_window_count() == 1 && &diff && getbufvar(+expand('<abuf>'), 'git_dir') !=# '' | call s:diffoff() | endif
autocmd BufWinLeave * if &diff && s:diff_window_count() == 2 && getbufvar(+expand('<abuf>'), 'git_dir') !=# '' | call s:diffoff_all(getbufvar(+expand('<abuf>'), 'git_dir')) | endif
autocmd BufWinEnter * if &diff && s:diff_window_count() == 1 && getbufvar(+expand('<abuf>'), 'git_dir') !=# '' | call s:diffoff() | endif
augroup END
function! s:diff_window_count()
function! s:diff_window_count() abort
let c = 0
for nr in range(1,winnr('$'))
let c += getwinvar(nr,'&diff')
@ -1401,7 +1404,7 @@ function! s:diff_window_count()
return c
endfunction
function! s:diff_restore()
function! s:diff_restore() abort
let restore = 'setlocal nodiff noscrollbind'
\ . ' scrollopt=' . &l:scrollopt
\ . (&l:wrap ? ' wrap' : ' nowrap')
@ -1415,14 +1418,14 @@ function! s:diff_restore()
return restore
endfunction
function! s:diffthis()
function! s:diffthis() abort
if !&diff
let w:fugitive_diff_restore = s:diff_restore()
diffthis
endif
endfunction
function! s:diffoff()
function! s:diffoff() abort
if exists('w:fugitive_diff_restore')
execute w:fugitive_diff_restore
unlet w:fugitive_diff_restore
@ -1431,7 +1434,7 @@ function! s:diffoff()
endif
endfunction
function! s:diffoff_all(dir)
function! s:diffoff_all(dir) abort
for nr in range(1,winnr('$'))
if getwinvar(nr,'&diff')
if nr != winnr()
@ -1467,7 +1470,7 @@ endfunction
call s:add_methods('buffer',['compare_age'])
function! s:Diff(bang,...)
function! s:Diff(bang,...) abort
let vert = a:bang ? '' : 'vertical '
if exists(':DiffGitCached')
return 'DiffGitCached'
@ -1510,6 +1513,9 @@ function! s:Diff(bang,...)
let spec = s:repo().translate(file)
let commit = matchstr(spec,'\C[^:/]//\zs\x\+')
let restore = s:diff_restore()
if exists('+cursorbind')
setlocal cursorbind
endif
let w:fugitive_diff_restore = restore
if s:buffer().compare_age(commit) < 0
execute 'rightbelow '.vert.'diffsplit '.s:fnameescape(spec)
@ -1517,6 +1523,11 @@ function! s:Diff(bang,...)
execute 'leftabove '.vert.'diffsplit '.s:fnameescape(spec)
endif
let w:fugitive_diff_restore = restore
let winnr = winnr()
if getwinvar('#', '&diff')
wincmd p
call feedkeys("\<C-W>p", 'n')
endif
return ''
catch /^fugitive:/
return 'echoerr v:errmsg'
@ -1526,7 +1537,7 @@ endfunction
" }}}1
" Gmove, Gremove {{{1
function! s:Move(force,destination)
function! s:Move(force,destination) abort
if a:destination =~# '^/'
let destination = a:destination[1:-1]
else
@ -1560,7 +1571,7 @@ function! s:Move(force,destination)
endif
endfunction
function! s:MoveComplete(A,L,P)
function! s:MoveComplete(A,L,P) abort
if a:A =~ '^/'
return s:repo().superglob(a:A)
else
@ -1570,7 +1581,7 @@ function! s:MoveComplete(A,L,P)
endif
endfunction
function! s:Remove(force)
function! s:Remove(force) abort
if s:buffer().commit() ==# ''
let cmd = ['rm']
elseif s:buffer().commit() ==# '0'
@ -1611,7 +1622,7 @@ augroup fugitive_blame
autocmd User Fugitive if s:buffer().type('file', 'blob') | exe "command! -buffer -bar -bang -range=0 -nargs=* Gblame :execute s:Blame(<bang>0,<line1>,<line2>,<count>,[<f-args>])" | endif
augroup END
function! s:linechars(pattern)
function! s:linechars(pattern) abort
let chars = strlen(s:gsub(matchstr(getline('.'), a:pattern), '.', '.'))
if exists('*synconcealed') && &conceallevel > 1
for col in range(1, chars)
@ -1686,7 +1697,7 @@ function! s:Blame(bang,line1,line2,count,args) abort
execute top
normal! zt
execute current
setlocal nomodified nomodifiable nonumber scrollbind nowrap foldcolumn=0 nofoldenable filetype=fugitiveblame
setlocal nomodified nomodifiable nonumber scrollbind nowrap foldcolumn=0 nofoldenable winfixwidth filetype=fugitiveblame
if exists('+concealcursor')
setlocal concealcursor=nc conceallevel=2
endif
@ -1694,6 +1705,8 @@ function! s:Blame(bang,line1,line2,count,args) abort
setlocal norelativenumber
endif
execute "vertical resize ".(s:linechars('.\{-\}\ze\s\+\d\+)')+1)
nnoremap <buffer> <silent> <F1> :help fugitive-:Gblame<CR>
nnoremap <buffer> <silent> g? :help fugitive-:Gblame<CR>
nnoremap <buffer> <silent> q :exe substitute(bufwinnr(b:fugitive_blamed_bufnr).' wincmd w<Bar>'.bufnr('').'bdelete','^-1','','')<CR>
nnoremap <buffer> <silent> gq :exe substitute(bufwinnr(b:fugitive_blamed_bufnr).' wincmd w<Bar>'.bufnr('').'bdelete<Bar>if expand("%:p") =~# "^fugitive:[\\/][\\/]"<Bar>Gedit<Bar>endif','^-1','','')<CR>
nnoremap <buffer> <silent> <CR> :<C-U>exe <SID>BlameCommit("exe 'norm q'<Bar>edit")<CR>
@ -1933,7 +1946,7 @@ function! s:github_url(repo,url,rev,commit,path,type,line1,line2) abort
for domain in domains
let domain_pattern .= '\|' . escape(split(domain, '://')[-1], '.')
endfor
let repo = matchstr(a:url,'^\%(https\=://\|git://\|git@\)\zs\('.domain_pattern.'\)[/:].\{-\}\ze\%(\.git\)\=$')
let repo = matchstr(a:url,'^\%(https\=://\|git://\|git@\)\=\zs\('.domain_pattern.'\)[/:].\{-\}\ze\%(\.git\)\=$')
if repo ==# ''
return ''
endif
@ -2035,14 +2048,14 @@ function! s:ReplaceCmd(cmd,...) abort
let prefix = ''
try
if a:0 && a:1 != ''
if &shell =~# 'cmd'
if &shell =~# 'cmd' || &shell =~# 'power'
let old_index = $GIT_INDEX_FILE
let $GIT_INDEX_FILE = a:1
else
let prefix = 'env GIT_INDEX_FILE='.s:shellesc(a:1).' '
endif
endif
if &shell =~# 'cmd'
if &shell =~# 'cmd' || &shell =~# 'power'
let cmd_escape_char = &shellxquote == '(' ? '^' : '^^^'
call system('cmd /c "'.prefix.s:gsub(a:cmd,'[<>]', cmd_escape_char.'&').' > '.tmp.'"')
else
@ -2066,7 +2079,7 @@ function! s:ReplaceCmd(cmd,...) abort
endtry
endfunction
function! s:BufReadIndex()
function! s:BufReadIndex() abort
if !exists('b:fugitive_display_format')
let b:fugitive_display_format = filereadable(expand('%').'.lock')
endif
@ -2086,7 +2099,7 @@ function! s:BufReadIndex()
else
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
if fugitive#git_version() =~# '^0\|1\.[1-7]\.'
if fugitive#git_version() =~# '^0\|^1\.[1-7]\.'
let cmd = s:repo().git_command('status')
else
let cmd = s:repo().git_command(
@ -2132,12 +2145,14 @@ function! s:BufReadIndex()
xnoremap <buffer> <silent> p :<C-U>execute <SID>StagePatch(line("'<"),line("'>"))<CR>
nnoremap <buffer> <silent> q :<C-U>if bufnr('$') == 1<Bar>quit<Bar>else<Bar>bdelete<Bar>endif<CR>
nnoremap <buffer> <silent> R :<C-U>edit<CR>
nnoremap <buffer> <silent> g? :help fugitive-:Gstatus<CR>
nnoremap <buffer> <silent> <F1> :help fugitive-:Gstatus<CR>
catch /^fugitive:/
return 'echoerr v:errmsg'
endtry
endfunction
function! s:FileRead()
function! s:FileRead() abort
try
let repo = s:repo(fugitive#extract_git_dir(expand('<amatch>')))
let path = s:sub(s:sub(matchstr(expand('<amatch>'),'fugitive://.\{-\}//\zs.*'),'/',':'),'^\d:',':&')
@ -2154,7 +2169,7 @@ function! s:FileRead()
endtry
endfunction
function! s:BufReadIndexFile()
function! s:BufReadIndexFile() abort
try
let b:fugitive_type = 'blob'
let b:git_dir = s:repo().dir()
@ -2164,6 +2179,7 @@ function! s:BufReadIndexFile()
if &bufhidden ==# ''
setlocal bufhidden=delete
endif
setlocal noswapfile
endtry
return ''
catch /^fugitive: rev-parse/
@ -2174,7 +2190,7 @@ function! s:BufReadIndexFile()
endtry
endfunction
function! s:BufWriteIndexFile()
function! s:BufWriteIndexFile() abort
let tmp = tempname()
try
let path = matchstr(expand('<amatch>'),'//\d/\zs.*')
@ -2187,7 +2203,7 @@ function! s:BufWriteIndexFile()
endif
let info = old_mode.' '.sha1.' '.stage."\t".path
call writefile([info],tmp)
if &shell =~# 'cmd'
if &shell =~# 'cmd' || &shell =~# 'power'
let error = system('type '.s:gsub(tmp,'/','\\').'|'.s:repo().git_command('update-index','--index-info'))
else
let error = system(s:repo().git_command('update-index','--index-info').' < '.tmp)
@ -2205,7 +2221,7 @@ function! s:BufWriteIndexFile()
endtry
endfunction
function! s:BufReadObject()
function! s:BufReadObject() abort
try
setlocal noro ma
let b:git_dir = s:repo().dir()
@ -2226,7 +2242,7 @@ function! s:BufReadObject()
endif
let pos = getpos('.')
silent %delete
silent keepjumps %delete_
setlocal endofline
try
@ -2250,23 +2266,25 @@ function! s:BufReadObject()
call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash))
else
call s:ReplaceCmd(s:repo().git_command('show','--no-color','--pretty=format:tree %T%nparent %P%nauthor %an <%ae> %ad%ncommitter %cn <%ce> %cd%nencoding %e%n%n%s%n%n%b',hash))
call search('^parent ')
keepjumps call search('^parent ')
if getline('.') ==# 'parent '
silent delete_
silent keepjumps delete_
else
silent s/\%(^parent\)\@<! /\rparent /ge
silent keepjumps s/\%(^parent\)\@<! /\rparent /ge
endif
if search('^encoding \%(<unknown>\)\=$','W',line('.')+3)
silent delete_
keepjumps let lnum = search('^encoding \%(<unknown>\)\=$','W',line('.')+3)
if lnum
silent keepjumps delete_
end
1
keepjumps 1
endif
elseif b:fugitive_type ==# 'blob'
call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash))
setlocal nomodeline
endif
finally
call setpos('.',pos)
setlocal ro noma nomod
keepjumps call setpos('.',pos)
setlocal ro noma nomod noswapfile
if &bufhidden ==# ''
setlocal bufhidden=delete
endif
@ -2331,9 +2349,6 @@ augroup END
function! s:JumpInit() abort
nnoremap <buffer> <silent> <CR> :<C-U>exe <SID>GF("edit")<CR>
if !&modifiable
if exists(':CtrlP')
nnoremap <buffer> <silent> <C-P> :<C-U>exe 'CtrlP '.fnameescape(<SID>repo().tree())<CR>
endif
nnoremap <buffer> <silent> o :<C-U>exe <SID>GF("split")<CR>
nnoremap <buffer> <silent> S :<C-U>exe <SID>GF("vsplit")<CR>
nnoremap <buffer> <silent> O :<C-U>exe <SID>GF("tabedit")<CR>
@ -2522,12 +2537,15 @@ endfunction
" Statusline {{{1
function! s:repo_head_ref() dict abort
if !filereadable(self.dir('HEAD'))
return ''
endif
return readfile(self.dir('HEAD'))[0]
endfunction
call s:add_methods('repo',['head_ref'])
function! fugitive#statusline(...)
function! fugitive#statusline(...) abort
if !exists('b:git_dir')
return ''
endif
@ -2543,7 +2561,7 @@ function! fugitive#statusline(...)
endif
endfunction
function! fugitive#head(...)
function! fugitive#head(...) abort
if !exists('b:git_dir')
return ''
endif