From 5db64d670907d86e27fca28487876c2edc11ad87 Mon Sep 17 00:00:00 2001 From: gmarik Date: Wed, 8 Dec 2010 22:31:11 -0600 Subject: [PATCH] autoload/vundle.vim extracted into smaller files - vundle.vim - entrypoing and loader - config.vim - configuration and runtimepath management - installer.vim - installation and docs --- autoload/vundle.vim | 114 ++-------------------------------- autoload/vundle/config.vim | 58 +++++++++++++++++ autoload/vundle/installer.vim | 47 ++++++++++++++ 3 files changed, 109 insertions(+), 110 deletions(-) create mode 100644 autoload/vundle/config.vim create mode 100644 autoload/vundle/installer.vim diff --git a/autoload/vundle.vim b/autoload/vundle.vim index f36d65e..b07632c 100644 --- a/autoload/vundle.vim +++ b/autoload/vundle.vim @@ -1,11 +1,11 @@ " vundle.vim - is a shortcut for Vim Bundle and Is a simple plugin manager for Vim " Maintainer: http://github.com/gmarik -" Version: 0.4 +" Version: 0.5 " Readme: http://github.com/gmarik/vundle/blob/master/README.md -com! -nargs=+ Bundle call vundle#add_bundle() -com! -nargs=? -bang BundleInstall call vundle#install_bundles("") -com! -nargs=0 BundleDocs call vundle#helptags() +com! -nargs=+ Bundle call vundle#config#bundle() +com! -nargs=? -bang BundleInstall call vundle#installer#install("") +com! -nargs=0 BundleDocs call vundle#installer#helptags() com! -nargs=+ -bang BundleSearch silent call vundle#scripts#search("", ) @@ -16,109 +16,3 @@ func! vundle#rc() call filter(g:bundles, 's:rtp_rm(v:val.rtpath())') let g:bundles = [] endf - -func! vundle#add_bundle(arg, ...) - let bundle = extend(s:parse_options(a:000), s:parse_name(a:arg)) - call extend(bundle, copy(s:bundle)) - call add(g:bundles, bundle) - call s:rtp_add(bundle.rtpath()) - call s:require(bundle) -endf - -func! vundle#install_bundles(bang) - silent source ~/.vimrc - if !isdirectory(g:bundle_dir) | call mkdir(g:bundle_dir, 'p') | endif - for bundle in g:bundles | call s:install('!' == a:bang, bundle) | endfor -endf - -func! vundle#helptags() - let c = 0 - for bundle in g:bundles | let c += s:helptags(bundle.rtpath()) | endfor - call s:log('Done. '.c.' bundles processed') -endf - -func! s:parse_options(opts) - " TODO: improve this - if len(a:opts) != 1 | return {} | endif - - if type(a:opts[0]) == type({}) - return a:opts[0] - else - return {'rev': a:opts[0]} - endif -endf - -func! s:parse_name(arg) - let arg = a:arg - if arg =~ '^\s*\(git@\|git://\)\S\+' || arg =~ 'https\?://' || arg =~ '\.git\*$' - let uri = arg - let name = substitute(split(uri,'\/')[-1], '\.git\s*$','','i') - else - let name = arg - let uri = 'http://github.com/vim-scripts/'.name.'.git' - endif - return {'name': name, 'uri': uri } -endf - -func! s:require(bundle) - call s:rtp_add(g:bundle_dir) - exec 'runtime! '.a:bundle.name.'/plugin/*.vim' - exec 'runtime! '.a:bundle.name.'/after/*.vim' - call s:rtp_rm(g:bundle_dir) -endf - -func! s:helptags(rtp) - if !(isdirectory(a:rtp.'/doc') && (!filereadable(a:rtp.'/doc/tags') || filewritable(a:rtp.'/doc/tags'))) - return 0 - endif - helptags `=a:rtp.'/doc'` - return 1 -endf - -func! s:sync(bang, bundle) - let git_dir = a:bundle.path().'/.git' - if isdirectory(git_dir) - if !(a:bang) | return 0 | endif - silent exec '!cd '.a:bundle.path().'; git pull >/dev/null 2>&1' - else - silent exec '!git clone '.a:bundle.uri.' '.a:bundle.path().' >/dev/null 2>&1' - endif - return 1 -endf - -func! s:install(bang, bundle) - let synced = s:sync(a:bang, a:bundle) - call s:helptags(a:bundle.rtpath()) - call s:log(a:bundle.name.' '.(synced ? ' ': ' already').' installed') -endf - -func! s:rtp_rm(dir) - exec 'set rtp-='.a:dir - exec 'set rtp-='.expand(a:dir.'/after') -endf - -func! s:rtp_add(dir) - exec 'set rtp^='.a:dir - exec 'set rtp+='.expand(a:dir.'/after') -endf - -func! s:log(msg) - if has('gui_running') - echo a:msg - else - " console vim requires to hit ENTER after each !cmd with stdout output - " workaround - silent exec '! echo '.a:msg.' >&2| cat >/dev/null' - endif -endf - -let s:bundle = {} - -func! s:bundle.path() - return join([g:bundle_dir, self.name], '/') -endf - -func! s:bundle.rtpath() - return has_key(self, 'rtp') ? join([self.path(), self.rtp], '/') : self.path() -endf - diff --git a/autoload/vundle/config.vim b/autoload/vundle/config.vim new file mode 100644 index 0000000..3bdb7cb --- /dev/null +++ b/autoload/vundle/config.vim @@ -0,0 +1,58 @@ +func! vundle#config#bundle(arg, ...) + let bundle = extend(s:parse_options(a:000), s:parse_name(a:arg)) + call extend(bundle, copy(s:bundle)) + call add(g:bundles, bundle) + call s:rtp_add(bundle.rtpath()) + call s:require(bundle) +endf + +func! s:parse_options(opts) + " TODO: improve this + if len(a:opts) != 1 | return {} | endif + + if type(a:opts[0]) == type({}) + return a:opts[0] + else + return {'rev': a:opts[0]} + endif +endf + +func! s:parse_name(arg) + let arg = a:arg + if arg =~ '^\s*\(git@\|git://\)\S\+' || arg =~ 'https\?://' || arg =~ '\.git\*$' + let uri = arg + let name = substitute(split(uri,'\/')[-1], '\.git\s*$','','i') + else + let name = arg + let uri = 'http://github.com/vim-scripts/'.name.'.git' + endif + return {'name': name, 'uri': uri } +endf + +func! s:require(bundle) + call s:rtp_add(g:bundle_dir) + " TODO: it has to be relative rtpath, not bundle, name + exec 'runtime! '.a:bundle.name.'/plugin/*.vim' + exec 'runtime! '.a:bundle.name.'/after/*.vim' + call s:rtp_rm(g:bundle_dir) +endf + +func! s:rtp_rm(dir) + exec 'set rtp-='.a:dir + exec 'set rtp-='.expand(a:dir.'/after') +endf + +func! s:rtp_add(dir) + exec 'set rtp^='.a:dir + exec 'set rtp+='.expand(a:dir.'/after') +endf + +let s:bundle = {} + +func! s:bundle.path() + return join([g:bundle_dir, self.name], '/') +endf + +func! s:bundle.rtpath() + return has_key(self, 'rtp') ? join([self.path(), self.rtp], '/') : self.path() +endf diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim new file mode 100644 index 0000000..1a6034e --- /dev/null +++ b/autoload/vundle/installer.vim @@ -0,0 +1,47 @@ +func! vundle#installer#install(bang) + " TODO: this sucks + silent source ~/.vimrc + if !isdirectory(g:bundle_dir) | call mkdir(g:bundle_dir, 'p') | endif + for bundle in g:bundles | call s:install('!' == a:bang, bundle) | endfor +endf + +func! vundle#installer#helptags() + let c = 0 + for bundle in g:bundles | let c += s:helptags(bundle.rtpath()) | endfor + call s:log('Done. '.c.' bundles processed') +endf + +func! s:helptags(rtp) + if !(isdirectory(a:rtp.'/doc') && (!filereadable(a:rtp.'/doc/tags') || filewritable(a:rtp.'/doc/tags'))) + return 0 + endif + helptags `=a:rtp.'/doc'` + return 1 +endf + +func! s:sync(bang, bundle) + let git_dir = a:bundle.path().'/.git' + if isdirectory(git_dir) + if !(a:bang) | return 0 | endif + silent exec '!cd '.a:bundle.path().'; git pull >/dev/null 2>&1' + else + silent exec '!git clone '.a:bundle.uri.' '.a:bundle.path().' >/dev/null 2>&1' + endif + return 1 +endf + +func! s:install(bang, bundle) + let synced = s:sync(a:bang, a:bundle) + call s:helptags(a:bundle.rtpath()) + call s:log(a:bundle.name.' '.(synced ? ' ': ' already').' installed') +endf + +func! s:log(msg) + if has('gui_running') + echo a:msg + else + " console vim requires to hit ENTER after each !cmd with stdout output + " workaround + silent exec '! echo '.a:msg.' >&2| cat >/dev/null' + endif +endf