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
2017-05-02 14:42:08 +02:00
parent c4fbfe8aa8
commit 85e105159e
63 changed files with 1389 additions and 737 deletions

View File

@ -70,6 +70,10 @@ endfunction
let s:git_versions = {}
function! s:git_command() abort
return get(g:, 'fugitive_git_command', g:fugitive_git_executable)
endfunction
function! fugitive#git_version(...) abort
if !has_key(s:git_versions, g:fugitive_git_executable)
let s:git_versions[g:fugitive_git_executable] = matchstr(system(g:fugitive_git_executable.' --version'), "\\S\\+\n")
@ -127,7 +131,12 @@ function! fugitive#extract_git_dir(path) abort
if s:shellslash(a:path) =~# '^fugitive://.*//'
return matchstr(s:shellslash(a:path), '\C^fugitive://\zs.\{-\}\ze//')
endif
let root = s:shellslash(simplify(fnamemodify(a:path, ':p:s?[\/]$??')))
if isdirectory(a:path)
let path = fnamemodify(a:path, ':p:s?[\/]$??')
else
let path = fnamemodify(a:path, ':p:h:s?[\/]$??')
endif
let root = s:shellslash(resolve(path))
let previous = ""
while root !=# previous
if root =~# '\v^//%([^/]+/?)?$'
@ -179,6 +188,9 @@ function! fugitive#detect(path) abort
let dir = fugitive#extract_git_dir(a:path)
if dir !=# ''
let b:git_dir = dir
if empty(fugitive#buffer().path())
silent! exe haslocaldir() ? 'lcd .' : 'cd .'
endif
endif
endif
if exists('b:git_dir')
@ -374,12 +386,14 @@ endfunction
call s:add_methods('repo',['dir','tree','bare','translate','head'])
function! s:repo_git_command(...) dict abort
let git = g:fugitive_git_executable . ' --git-dir='.s:shellesc(self.git_dir)
let git = s:git_command() . ' --git-dir='.s:shellesc(self.git_dir)
return git.join(map(copy(a:000),'" ".s:shellesc(v:val)'),'')
endfunction
function! s:repo_git_chomp(...) dict abort
return s:sub(system(call(self.git_command,a:000,self)),'\n$','')
let git = g:fugitive_git_executable . ' --git-dir='.s:shellesc(self.git_dir)
let output = git.join(map(copy(a:000),'" ".s:shellesc(v:val)'),'')
return s:sub(system(output),'\n$','')
endfunction
function! s:repo_git_chomp_in_tree(...) dict abort
@ -456,7 +470,7 @@ endfunction
call s:add_methods('repo',['dirglob','superglob'])
function! s:repo_config(conf) dict abort
return matchstr(system(s:repo().git_command('config').' '.a:conf),"[^\r\n]*")
return matchstr(s:repo().git_chomp('config',a:conf),"[^\r\n]*")
endfun
function! s:repo_user() dict abort
@ -480,9 +494,9 @@ call s:add_methods('repo',['config', 'user', 'aliases'])
function! s:repo_keywordprg() dict abort
let args = ' --git-dir='.escape(self.dir(),"\\\"' ")
if has('gui_running') && !has('win32')
return g:fugitive_git_executable . ' --no-pager' . args . ' log -1'
return s:git_command() . ' --no-pager' . args . ' log -1'
else
return g:fugitive_git_executable . args . ' show'
return s:git_command() . args . ' show'
endif
endfunction
@ -693,7 +707,7 @@ function! s:Git(bang, args) abort
if a:bang
return s:Edit('edit', 1, a:args)
endif
let git = g:fugitive_git_executable
let git = s:git_command()
if has('gui_running') && !has('win32')
let git .= ' --no-pager'
endif
@ -1211,7 +1225,7 @@ function! s:Merge(cmd, bang, args) abort
\ !empty(s:repo().git_chomp('diff-files', '--diff-filter=U')))
let &l:makeprg = g:fugitive_git_executable.' diff-files --name-status --diff-filter=U'
else
let &l:makeprg = s:sub(g:fugitive_git_executable . ' ' . a:cmd .
let &l:makeprg = s:sub(s:git_command() . ' ' . a:cmd .
\ (a:args =~# ' \%(--no-edit\|--abort\|-m\)\>' ? '' : ' --edit') .
\ ' ' . a:args, ' *$', '')
endif
@ -1390,6 +1404,9 @@ function! s:Edit(cmd,bang,...) abort
return 'redraw|echo '.string(':!'.git.' '.args)
else
let temp = resolve(tempname())
if has('win32')
let temp = fnamemodify(fnamemodify(temp, ':h'), ':p').fnamemodify(temp, ':t')
endif
let s:temp_files[s:cpath(temp)] = { 'dir': buffer.repo().dir(), 'args': arglist }
silent execute a:cmd.' '.temp
if a:cmd =~# 'pedit'
@ -1632,7 +1649,7 @@ function! s:Dispatch(bang, args)
try
let b:current_compiler = 'git'
let &l:errorformat = s:common_efm
let &l:makeprg = g:fugitive_git_executable . ' ' . a:args
let &l:makeprg = substitute(s:git_command() . ' ' . a:args, '\s\+$', '', '')
execute cd fnameescape(s:repo().tree())
if exists(':Make') == 2
noautocmd Make
@ -2011,6 +2028,9 @@ function! s:Blame(bang,line1,line2,count,args) abort
endif
let top = line('w0') + &scrolloff
let current = line('.')
if has('win32')
let temp = fnamemodify(fnamemodify(temp, ':h'), ':p').fnamemodify(temp, ':t')
endif
let s:temp_files[s:cpath(temp)] = { 'dir': s:repo().dir(), 'args': cmd }
exe 'keepalt leftabove vsplit '.temp
let b:fugitive_blamed_bufnr = bufnr
@ -2188,7 +2208,7 @@ endfunction
function! s:RehighlightBlame() abort
for [hash, cterm] in items(s:hash_colors)
if !empty(cterm) || has('gui_running')
if !empty(cterm) || has('gui_running') || has('termguicolors') && &termguicolors
exe 'hi FugitiveblameHash'.hash.' guifg=#'.hash.get(s:hash_colors, hash, '')
else
exe 'hi link FugitiveblameHash'.hash.' Identifier'
@ -2260,10 +2280,11 @@ function! s:Browse(bang,line1,count,...) abort
if path =~# '^\.git/refs/remotes/.'
if empty(remote)
let remote = matchstr(path, '^\.git/refs/remotes/\zs[^/]\+')
let branch = matchstr(path, '^\.git/refs/remotes/[^/]\+/\zs.\+')
else
let merge = matchstr(path, '^\.git/refs/remotes/[^/]\+/\zs.\+')
let path = '.git/refs/heads/'.merge
endif
let merge = matchstr(path, '^\.git/refs/remotes/[^/]\+/\zs.\+')
let branch = ''
let path = '.git/refs/heads/'.merge
elseif path =~# '^\.git/refs/heads/.'
let branch = path[16:-1]
elseif !exists('branch')
@ -2300,9 +2321,14 @@ function! s:Browse(bang,line1,count,...) abort
if empty(remote)
let remote = '.'
let raw = s:repo().git_chomp('remote','get-url','origin')
let remote_for_url = 'origin'
else
let raw = s:repo().git_chomp('remote','get-url',remote)
let remote_for_url = remote
endif
if fugitive#git_version() =~# '^[01]\.|^2\.[0-6]\.'
let raw = s:repo().git_chomp('config','remote.'.remote_for_url.'.url')
else
let raw = s:repo().git_chomp('remote','get-url',remote_for_url)
endif
if raw ==# ''
let raw = remote
@ -2365,46 +2391,8 @@ function! s:github_url(opts, ...) abort
if repo ==# ''
return ''
endif
let path = substitute(a:opts.path, '^/', '', '')
if index(domains, 'http://' . matchstr(repo, '^[^:/]*')) >= 0
let root = 'http://' . s:sub(repo,':','/')
else
let root = 'https://' . s:sub(repo,':','/')
endif
if path =~# '^\.git/refs/heads/'
let branch = a:opts.repo.git_chomp('config','branch.'.path[16:-1].'.merge')[11:-1]
if branch ==# ''
return root . '/commits/' . path[16:-1]
else
return root . '/commits/' . branch
endif
elseif path =~# '^\.git/refs/tags/'
return root . '/releases/tag/' . path[15:-1]
elseif path =~# '^\.git/refs/remotes/[^/]\+/.'
return root . '/commits/' . matchstr(path,'remotes/[^/]\+/\zs.*')
elseif path =~# '.git/\%(config$\|hooks\>\)'
return root . '/admin'
elseif path =~# '^\.git\>'
return root
endif
if a:opts.commit =~# '^\d\=$'
let commit = a:opts.repo.rev_parse('HEAD')
else
let commit = a:opts.commit
endif
if get(a:opts, 'type', '') ==# 'tree' || a:opts.path =~# '/$'
let url = substitute(root . '/tree/' . commit . '/' . path, '/$', '', 'g')
elseif get(a:opts, 'type', '') ==# 'blob' || a:opts.path =~# '[^/]$'
let url = root . '/blob/' . commit . '/' . path
if get(a:opts, 'line2') && a:opts.line1 == a:opts.line2
let url .= '#L' . a:opts.line1
elseif get(a:opts, 'line2')
let url .= '#L' . a:opts.line1 . '-L' . a:opts.line2
endif
else
let url = root . '/commit/' . commit
endif
return url
call s:warn('Install rhubarb.vim for GitHub support')
return 'https://github.com/tpope/vim-rhubarb'
endfunction
function! s:instaweb_url(opts) abort
@ -2662,7 +2650,7 @@ function! s:BufReadObject() abort
let b:fugitive_type = s:repo().git_chomp('cat-file','-t',hash)
endif
if b:fugitive_type !~# '^\%(tag\|commit\|tree\|blob\)$'
return "echoerr 'fugitive: unrecognized git type'"
return "echoerr ".string("fugitive: unrecognized git type '".b:fugitive_type."'")
endif
let firstline = getline('.')
if !exists('b:fugitive_display_format') && b:fugitive_type != 'blob'
@ -2906,7 +2894,7 @@ function! s:cfile() abort
let ref = matchstr(getline('.'),'\x\{40\}')
echoerr "warning: unknown context ".matchstr(getline('.'),'^\l*')
elseif getline('.') =~# '^[+-]\{3\} [ab/]'
elseif getline('.') =~# '^[+-]\{3\} [abciwo12]\=/'
let ref = getline('.')[4:]
elseif getline('.') =~# '^[+-]' && search('^@@ -\d\+,\d\+ +\d\+,','bnW')
@ -2920,7 +2908,7 @@ function! s:cfile() abort
let lnum -= 1
endwhile
let offset += matchstr(getline(lnum), type.'\zs\d\+')
let ref = getline(search('^'.type.'\{3\} [ab]/','bnW'))[4:-1]
let ref = getline(search('^'.type.'\{3\} [abciwo12]/','bnW'))[4:-1]
let dcmds = [offset, 'normal!zv']
elseif getline('.') =~# '^rename from '
@ -2929,22 +2917,22 @@ function! s:cfile() abort
let ref = 'b/'.getline('.')[10:]
elseif getline('.') =~# '^@@ -\d\+,\d\+ +\d\+,'
let diff = getline(search('^diff --git \%(a/.*\|/dev/null\) \%(b/.*\|/dev/null\)', 'bcnW'))
let diff = getline(search('^diff --git \%([abciwo12]/.*\|/dev/null\) \%([abciwo12]/.*\|/dev/null\)', 'bcnW'))
let offset = matchstr(getline('.'), '+\zs\d\+')
let dref = matchstr(diff, '\Cdiff --git \zs\%(a/.*\|/dev/null\)\ze \%(b/.*\|/dev/null\)')
let ref = matchstr(diff, '\Cdiff --git \%(a/.*\|/dev/null\) \zs\%(b/.*\|/dev/null\)')
let dref = matchstr(diff, '\Cdiff --git \zs\%([abciwo12]/.*\|/dev/null\)\ze \%([abciwo12]/.*\|/dev/null\)')
let ref = matchstr(diff, '\Cdiff --git \%([abciwo12]/.*\|/dev/null\) \zs\%([abciwo12]/.*\|/dev/null\)')
let dcmd = 'Gdiff! +'.offset
elseif getline('.') =~# '^diff --git \%(a/.*\|/dev/null\) \%(b/.*\|/dev/null\)'
let dref = matchstr(getline('.'),'\Cdiff --git \zs\%(a/.*\|/dev/null\)\ze \%(b/.*\|/dev/null\)')
let ref = matchstr(getline('.'),'\Cdiff --git \%(a/.*\|/dev/null\) \zs\%(b/.*\|/dev/null\)')
elseif getline('.') =~# '^diff --git \%([abciwo12]/.*\|/dev/null\) \%([abciwo12]/.*\|/dev/null\)'
let dref = matchstr(getline('.'),'\Cdiff --git \zs\%([abciwo12]/.*\|/dev/null\)\ze \%([abciwo12]/.*\|/dev/null\)')
let ref = matchstr(getline('.'),'\Cdiff --git \%([abciwo12]/.*\|/dev/null\) \zs\%([abciwo12]/.*\|/dev/null\)')
let dcmd = 'Gdiff!'
elseif getline('.') =~# '^index ' && getline(line('.')-1) =~# '^diff --git \%(a/.*\|/dev/null\) \%(b/.*\|/dev/null\)'
elseif getline('.') =~# '^index ' && getline(line('.')-1) =~# '^diff --git \%([abciwo12]/.*\|/dev/null\) \%([abciwo12]/.*\|/dev/null\)'
let line = getline(line('.')-1)
let dref = matchstr(line,'\Cdiff --git \zs\%(a/.*\|/dev/null\)\ze \%(b/.*\|/dev/null\)')
let ref = matchstr(line,'\Cdiff --git \%(a/.*\|/dev/null\) \zs\%(b/.*\|/dev/null\)')
let dref = matchstr(line,'\Cdiff --git \zs\%([abciwo12]/.*\|/dev/null\)\ze \%([abciwo12]/.*\|/dev/null\)')
let ref = matchstr(line,'\Cdiff --git \%([abciwo12]/.*\|/dev/null\) \zs\%([abciwo12]/.*\|/dev/null\)')
let dcmd = 'Gdiff!'
elseif line('$') == 1 && getline('.') =~ '^\x\{40\}$'
@ -2957,18 +2945,21 @@ function! s:cfile() abort
let ref = ''
endif
if myhash ==# ''
let ref = s:sub(ref,'^a/','HEAD:')
let ref = s:sub(ref,'^b/',':0:')
if exists('dref')
let dref = s:sub(dref,'^a/','HEAD:')
endif
else
let ref = s:sub(ref,'^a/',myhash.'^:')
let ref = s:sub(ref,'^b/',myhash.':')
if exists('dref')
let dref = s:sub(dref,'^a/',myhash.'^:')
endif
let prefixes = {
\ '1': '',
\ '2': '',
\ 'b': ':0:',
\ 'i': ':0:',
\ 'o': '',
\ 'w': ''}
if len(myhash)
let prefixes.a = myhash.'^:'
let prefixes.b = myhash.':'
endif
let ref = s:sub(ref, '^\(\w\)/', 'get(prefixes, submatch(1), "HEAD:")')
if exists('dref')
let dref = s:sub(dref, '^\(\w\)/', 'get(prefixes, submatch(1), "HEAD:")')
endif
if ref ==# '/dev/null'
@ -3076,7 +3067,7 @@ function! fugitive#foldtext() abort
endif
endfor
if filename ==# ''
let filename = matchstr(getline(v:foldstart), '^diff .\{-\} a/\zs.*\ze b/')
let filename = matchstr(getline(v:foldstart), '^diff .\{-\} [abciow12]/\zs.*\ze [abciow12]/')
endif
if filename ==# ''
let filename = getline(v:foldstart)[5:-1]