Minor refactoring

This commit is contained in:
Junegunn Choi 2014-07-10 00:44:09 +09:00
parent 42a42e7e71
commit 9ceb9caa09

View File

@ -179,13 +179,32 @@ function! plug#end()
syntax on syntax on
endfunction endfunction
function! s:rtp(spec) if s:is_win
let rtp = s:dirpath(a:spec.dir . get(a:spec, 'rtp', '')) function! s:rtp(spec)
if s:is_win let rtp = s:dirpath(a:spec.dir . get(a:spec, 'rtp', ''))
let rtp = substitute(rtp, '\\*$', '', '') return substitute(rtp, '\\*$', '', '')
endif endfunction
return rtp
endfunction function! s:path(path)
return substitute(substitute(a:path, '/', '\', 'g'), '[/\\]*$', '', '')
endfunction
function! s:dirpath(path)
return s:path(a:path) . '\'
endfunction
else
function! s:rtp(spec)
return s:dirpath(a:spec.dir . get(a:spec, 'rtp', ''))
endfunction
function! s:path(path)
return substitute(a:path, '[/\\]*$', '', '')
endfunction
function! s:dirpath(path)
return s:path(a:path) . '/'
endfunction
endif
function! s:esc(path) function! s:esc(path)
return substitute(a:path, ' ', '\\ ', 'g') return substitute(a:path, ' ', '\\ ', 'g')
@ -258,6 +277,9 @@ function! s:add(...)
return return
endif endif
let name = substitute(split(plugin, '/')[-1], '\.git$', '', '')
if !force && has_key(g:plugs, name) | return | endif
if plugin =~ ':' if plugin =~ ':'
let uri = plugin let uri = plugin
else else
@ -267,9 +289,6 @@ function! s:add(...)
let uri = 'https://git:@github.com/' . plugin . '.git' let uri = 'https://git:@github.com/' . plugin . '.git'
endif endif
let name = substitute(split(plugin, '/')[-1], '\.git$', '', '')
if !force && has_key(g:plugs, name) | return | endif
let dir = s:dirpath( fnamemodify(join([g:plug_home, name], '/'), ':p') ) let dir = s:dirpath( fnamemodify(join([g:plug_home, name], '/'), ':p') )
let spec = extend(opts, { 'dir': dir, 'uri': uri }) let spec = extend(opts, { 'dir': dir, 'uri': uri })
let g:plugs[name] = spec let g:plugs[name] = spec
@ -648,20 +667,6 @@ function! s:update_parallel(pull, todo, threads)
EOF EOF
endfunction endfunction
function! s:path(path)
return substitute(s:is_win ? substitute(a:path, '/', '\', 'g') : a:path,
\ '[/\\]*$', '', '')
endfunction
function! s:dirpath(path)
let path = s:path(a:path)
if s:is_win
return path !~ '\\$' ? path.'\' : path
else
return path !~ '/$' ? path.'/' : path
endif
endfunction
function! s:shellesc(arg) function! s:shellesc(arg)
return '"'.substitute(a:arg, '"', '\\"', 'g').'"' return '"'.substitute(a:arg, '"', '\\"', 'g').'"'
endfunction endfunction