From f72a8c83bb73cf9c2812ec4d9a617663c2218082 Mon Sep 17 00:00:00 2001 From: "C.D. Clark III" Date: Sun, 10 Jun 2012 21:53:44 -0500 Subject: [PATCH] added support for options to the Bundle command Wrote body for s:parse_options to allow users to specify config options to the Bundle command. The most common use for this would be to set the path to a plugins runtime files directory. If a plugin repo stores it's runtime files in a subdirectory, you need to be able to specify the path to this directory in order to laod the plugin. For exmaple, " exvim stores runtime files in subdir of repo root Bundle 'jwu/exvim' 'rtpath=./vimfiles' The parser will read arbitary options, but currently only rtpath is used. --- autoload/vundle.vim | 2 +- autoload/vundle/config.vim | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/autoload/vundle.vim b/autoload/vundle.vim index 1ac74e1..0f817d8 100644 --- a/autoload/vundle.vim +++ b/autoload/vundle.vim @@ -5,7 +5,7 @@ " Version: 0.9 com! -nargs=+ Bundle -\ call vundle#config#bundle() +\ call vundle#config#bundle() com! -nargs=? -bang -complete=custom,vundle#scripts#complete BundleInstall \ call vundle#installer#new('!' == '', ) diff --git a/autoload/vundle/config.vim b/autoload/vundle/config.vim index 55c7d7d..474cac1 100644 --- a/autoload/vundle/config.vim +++ b/autoload/vundle/config.vim @@ -24,7 +24,7 @@ func! vundle#config#require(bundles) abort endf func! vundle#config#init_bundle(name, opts) - let opts = extend(s:parse_options(a:opts), s:parse_name(substitute(a:name,"['".'"]\+','','g'))) + let opts = extend(s:parse_options(split( substitute( join(a:opts),"['".'"]\+','','g') )), s:parse_name(substitute(a:name,"['".'"]\+','','g'))) let b = extend(opts, copy(s:bundle)) let b.rtpath = s:rtpath(opts) return b @@ -32,13 +32,25 @@ 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 + let parsed_opts = {} + for opt in a:opts + if type(opt) == type({}) + " already a dict + call extend( parsed_opts, opt ) + elseif type(opt) == type("") + " a string. detect delimiter + if opt =~? '\S\+=\S\+' " is it a '=' + let [key,val] = split( opt, '=' ) + elseif opt =~? '\S\+:\S\+' " is it a ':' + let [key,val] = split( opt, ':' ) + else + let key = 'could_not_parse' + let val = opt + endif + let parsed_opts[key] = val + endif + endfor + return parsed_opts endf func! s:parse_name(arg) @@ -95,7 +107,14 @@ func! s:expand_path(path) abort endf func! s:rtpath(opts) - return has_key(a:opts, 'rtp') ? s:expand_path(a:opts.path().'/'.a:opts.rtp) : a:opts.path() + if has_key(a:opts, 'rtp') " check if user set rtp + return s:expand_path(a:opts.path().'/'.a:opts.rtp) + elseif has_key(a:opts, 'rtpath') " check if user set rtpath + return s:expand_path(a:opts.path().'/'.a:opts.rtpath) + else + " default to the bundles path + return has_key(a:opts, 'rtp') ? s:expand_path(a:opts.path().'/'.a:opts.rtp) : a:opts.path() + endif endf let s:bundle = {}