Merge pull request #450 from lucc/autoload-vars
Refactor global variables to autoload variables
This commit is contained in:
commit
34a307786b
@ -21,7 +21,7 @@ com! -nargs=? -bang PluginClean
|
|||||||
\ call vundle#installer#clean('!' == '<bang>')
|
\ call vundle#installer#clean('!' == '<bang>')
|
||||||
|
|
||||||
com! -nargs=0 PluginDocs
|
com! -nargs=0 PluginDocs
|
||||||
\ call vundle#installer#helptags(g:bundles)
|
\ call vundle#installer#helptags(g:vundle#bundles)
|
||||||
|
|
||||||
" Aliases
|
" Aliases
|
||||||
com! -nargs=* -complete=custom,vundle#scripts#complete PluginUpdate PluginInstall! <args>
|
com! -nargs=* -complete=custom,vundle#scripts#complete PluginUpdate PluginInstall! <args>
|
||||||
@ -61,24 +61,30 @@ endif
|
|||||||
" :Plugin command in the vimrc. It is not possible to do this automatically
|
" :Plugin command in the vimrc. It is not possible to do this automatically
|
||||||
" because when loading the vimrc file no plugins where loaded yet.
|
" because when loading the vimrc file no plugins where loaded yet.
|
||||||
func! vundle#rc(...) abort
|
func! vundle#rc(...) abort
|
||||||
let g:bundle_dir = len(a:000) > 0 ? expand(a:1, 1) : expand('$HOME/.vim/bundle', 1)
|
if a:0 > 0
|
||||||
let g:updated_bundles = []
|
let g:vundle#bundle_dir = expand(a:1, 1)
|
||||||
let g:vundle_log = []
|
endif
|
||||||
let g:vundle_changelog = ['Updated Plugins:']
|
|
||||||
call vundle#config#init()
|
call vundle#config#init()
|
||||||
endf
|
endf
|
||||||
|
|
||||||
" Alternative to vundle#rc, offers speed up by modifying rtp only when end()
|
" Alternative to vundle#rc, offers speed up by modifying rtp only when end()
|
||||||
" called later.
|
" called later.
|
||||||
func! vundle#begin(...) abort
|
func! vundle#begin(...) abort
|
||||||
let g:vundle_lazy_load = 1
|
let g:vundle#lazy_load = 1
|
||||||
call call('vundle#rc', a:000)
|
call call('vundle#rc', a:000)
|
||||||
endf
|
endf
|
||||||
|
|
||||||
" Finishes putting plugins on the rtp.
|
" Finishes putting plugins on the rtp.
|
||||||
func! vundle#end(...) abort
|
func! vundle#end(...) abort
|
||||||
unlet g:vundle_lazy_load
|
unlet g:vundle#lazy_load
|
||||||
call vundle#config#activate_bundles()
|
call vundle#config#activate_bundles()
|
||||||
endf
|
endf
|
||||||
|
|
||||||
|
" Initialize some global variables used by Vundle.
|
||||||
|
let vundle#bundle_dir = expand('$HOME/.vim/bundle', 1)
|
||||||
|
let vundle#bundles = []
|
||||||
|
let vundle#lazy_load = 0
|
||||||
|
let vundle#log = []
|
||||||
|
let vundle#updated_bundles = []
|
||||||
|
|
||||||
" vim: set expandtab sts=2 ts=2 sw=2 tw=78 norl:
|
" vim: set expandtab sts=2 ts=2 sw=2 tw=78 norl:
|
||||||
|
@ -10,11 +10,11 @@ func! vundle#config#bundle(arg, ...)
|
|||||||
if !s:check_bundle_name(bundle)
|
if !s:check_bundle_name(bundle)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
if exists('g:vundle_lazy_load') && g:vundle_lazy_load
|
if exists('g:vundle#lazy_load') && g:vundle#lazy_load
|
||||||
call add(g:bundles, bundle)
|
call add(g:vundle#bundles, bundle)
|
||||||
else
|
else
|
||||||
call s:rtp_rm_a()
|
call s:rtp_rm_a()
|
||||||
call add(g:bundles, bundle)
|
call add(g:vundle#bundles, bundle)
|
||||||
call s:rtp_add_a()
|
call s:rtp_add_a()
|
||||||
call s:rtp_add_defaults()
|
call s:rtp_add_defaults()
|
||||||
endif
|
endif
|
||||||
@ -40,10 +40,10 @@ endf
|
|||||||
" once.
|
" once.
|
||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
func! vundle#config#init()
|
func! vundle#config#init()
|
||||||
if !exists('g:bundles') | let g:bundles = [] | endif
|
if !exists('g:vundle#bundles') | let g:vundle#bundles = [] | endif
|
||||||
call s:rtp_rm_a()
|
call s:rtp_rm_a()
|
||||||
let g:bundles = []
|
let g:vundle#bundles = []
|
||||||
let g:bundle_names = {}
|
let s:bundle_names = {}
|
||||||
endf
|
endf
|
||||||
|
|
||||||
|
|
||||||
@ -55,11 +55,11 @@ endf
|
|||||||
func! vundle#config#require(bundles) abort
|
func! vundle#config#require(bundles) abort
|
||||||
for b in a:bundles
|
for b in a:bundles
|
||||||
call s:rtp_add(b.rtpath)
|
call s:rtp_add(b.rtpath)
|
||||||
call s:rtp_add(g:bundle_dir)
|
call s:rtp_add(g:vundle#bundle_dir)
|
||||||
" TODO: it has to be relative rtpath, not bundle.name
|
" TODO: it has to be relative rtpath, not bundle.name
|
||||||
exec 'runtime! '.b.name.'/plugin/*.vim'
|
exec 'runtime! '.b.name.'/plugin/*.vim'
|
||||||
exec 'runtime! '.b.name.'/after/*.vim'
|
exec 'runtime! '.b.name.'/after/*.vim'
|
||||||
call s:rtp_rm(g:bundle_dir)
|
call s:rtp_rm(g:vundle#bundle_dir)
|
||||||
endfor
|
endfor
|
||||||
call s:rtp_add_defaults()
|
call s:rtp_add_defaults()
|
||||||
endf
|
endf
|
||||||
@ -91,14 +91,14 @@ endf
|
|||||||
" return -- 0 if the bundle's name has been seen before, 1 otherwise
|
" return -- 0 if the bundle's name has been seen before, 1 otherwise
|
||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
funct! s:check_bundle_name(bundle)
|
funct! s:check_bundle_name(bundle)
|
||||||
if has_key(g:bundle_names, a:bundle.name)
|
if has_key(s:bundle_names, a:bundle.name)
|
||||||
echoerr 'Vundle error: Name collision for Plugin ' . a:bundle.name_spec .
|
echoerr 'Vundle error: Name collision for Plugin ' . a:bundle.name_spec .
|
||||||
\ '. Plugin ' . g:bundle_names[a:bundle.name] .
|
\ '. Plugin ' . s:bundle_names[a:bundle.name] .
|
||||||
\ ' previously used the name "' . a:bundle.name . '"' .
|
\ ' previously used the name "' . a:bundle.name . '"' .
|
||||||
\ '. Skipping Plugin ' . a:bundle.name_spec . '.'
|
\ '. Skipping Plugin ' . a:bundle.name_spec . '.'
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
let g:bundle_names[a:bundle.name] = a:bundle.name_spec
|
let s:bundle_names[a:bundle.name] = a:bundle.name_spec
|
||||||
return 1
|
return 1
|
||||||
endf
|
endf
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ endf
|
|||||||
" runtimepath.
|
" runtimepath.
|
||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
func! s:rtp_rm_a()
|
func! s:rtp_rm_a()
|
||||||
let paths = map(copy(g:bundles), 'v:val.rtpath')
|
let paths = map(copy(g:vundle#bundles), 'v:val.rtpath')
|
||||||
let prepends = join(paths, ',')
|
let prepends = join(paths, ',')
|
||||||
let appends = join(paths, '/after,').'/after'
|
let appends = join(paths, '/after,').'/after'
|
||||||
exec 'set rtp-='.fnameescape(prepends)
|
exec 'set rtp-='.fnameescape(prepends)
|
||||||
@ -193,7 +193,7 @@ endf
|
|||||||
" runtimepath.
|
" runtimepath.
|
||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
func! s:rtp_add_a()
|
func! s:rtp_add_a()
|
||||||
let paths = map(copy(g:bundles), 'v:val.rtpath')
|
let paths = map(copy(g:vundle#bundles), 'v:val.rtpath')
|
||||||
let prepends = join(paths, ',')
|
let prepends = join(paths, ',')
|
||||||
let appends = join(paths, '/after,').'/after'
|
let appends = join(paths, '/after,').'/after'
|
||||||
exec 'set rtp^='.fnameescape(prepends)
|
exec 'set rtp^='.fnameescape(prepends)
|
||||||
@ -262,7 +262,7 @@ let s:bundle = {}
|
|||||||
" return -- the target location to clone this bundle to
|
" return -- the target location to clone this bundle to
|
||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
func! s:bundle.path()
|
func! s:bundle.path()
|
||||||
return s:expand_path(g:bundle_dir.'/'.self.name)
|
return s:expand_path(g:vundle#bundle_dir.'/'.self.name)
|
||||||
endf
|
endf
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
" Try to clone all new bundles given (or all bundles in g:bundles by default)
|
" Try to clone all new bundles given (or all bundles in g:vundle#bundles by
|
||||||
" to g:bundle_dir. If a:bang is 1 it will also update all plugins (git pull).
|
" default) to g:vundle#bundle_dir. If a:bang is 1 it will also update all
|
||||||
|
" plugins (git pull).
|
||||||
"
|
"
|
||||||
" bang -- 1 or 0
|
" bang -- 1 or 0
|
||||||
" ... -- any number of bundle specifications (separate arguments)
|
" ... -- any number of bundle specifications (separate arguments)
|
||||||
@ -8,10 +9,10 @@
|
|||||||
func! vundle#installer#new(bang, ...) abort
|
func! vundle#installer#new(bang, ...) abort
|
||||||
" No specific plugins are specified. Operate on all plugins.
|
" No specific plugins are specified. Operate on all plugins.
|
||||||
if a:0 == 0
|
if a:0 == 0
|
||||||
let bundles = g:bundles
|
let bundles = g:vundle#bundles
|
||||||
" Specific plugins are specified for update. Update them.
|
" Specific plugins are specified for update. Update them.
|
||||||
elseif (a:bang)
|
elseif (a:bang)
|
||||||
let bundles = filter(copy(g:bundles), 'index(a:000, v:val.name) > -1')
|
let bundles = filter(copy(g:vundle#bundles), 'index(a:000, v:val.name) > -1')
|
||||||
" Specific plugins are specified for installation. Install them.
|
" Specific plugins are specified for installation. Install them.
|
||||||
else
|
else
|
||||||
let bundles = map(copy(a:000), 'vundle#config#bundle(v:val, {})')
|
let bundles = map(copy(a:000), 'vundle#config#bundle(v:val, {})')
|
||||||
@ -23,7 +24,7 @@ func! vundle#installer#new(bang, ...) abort
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
let names = vundle#scripts#bundle_names(map(copy(bundles), 'v:val.name_spec'))
|
let names = vundle#scripts#bundle_names(map(copy(bundles), 'v:val.name_spec'))
|
||||||
call vundle#scripts#view('Installer',['" Installing plugins to '.expand(g:bundle_dir, 1)], names + ['Helptags'])
|
call vundle#scripts#view('Installer',['" Installing plugins to '.expand(g:vundle#bundle_dir, 1)], names + ['Helptags'])
|
||||||
|
|
||||||
" This calls 'add' as a normal mode command. This is a buffer local mapping
|
" This calls 'add' as a normal mode command. This is a buffer local mapping
|
||||||
" defined in vundle#scripts#view(). The mapping will call a buffer local
|
" defined in vundle#scripts#view(). The mapping will call a buffer local
|
||||||
@ -55,11 +56,11 @@ func! s:process(bang, cmd)
|
|||||||
|
|
||||||
exec ':norm '.a:cmd
|
exec ':norm '.a:cmd
|
||||||
|
|
||||||
if 'error' == g:vundle_last_status
|
if 'error' == s:last_status
|
||||||
let msg = 'With errors; press l to view log'
|
let msg = 'With errors; press l to view log'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if 'updated' == g:vundle_last_status && empty(msg)
|
if 'updated' == s:last_status && empty(msg)
|
||||||
let msg = 'Plugins updated; press u to view changelog'
|
let msg = 'Plugins updated; press u to view changelog'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -118,7 +119,7 @@ func! vundle#installer#run(func_name, name, ...) abort
|
|||||||
throw 'whoops, unknown status:'.status
|
throw 'whoops, unknown status:'.status
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let g:vundle_last_status = status
|
let s:last_status = status
|
||||||
|
|
||||||
return status
|
return status
|
||||||
endf
|
endf
|
||||||
@ -163,10 +164,10 @@ endf
|
|||||||
" return -- the return value from s:sync()
|
" return -- the return value from s:sync()
|
||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
func! vundle#installer#install(bang, name) abort
|
func! vundle#installer#install(bang, name) abort
|
||||||
if !isdirectory(g:bundle_dir) | call mkdir(g:bundle_dir, 'p') | endif
|
if !isdirectory(g:vundle#bundle_dir) | call mkdir(g:vundle#bundle_dir, 'p') | endif
|
||||||
|
|
||||||
let n = substitute(a:name,"['".'"]\+','','g')
|
let n = substitute(a:name,"['".'"]\+','','g')
|
||||||
let matched = filter(copy(g:bundles), 'v:val.name_spec == n')
|
let matched = filter(copy(g:vundle#bundles), 'v:val.name_spec == n')
|
||||||
|
|
||||||
if len(matched) > 0
|
if len(matched) > 0
|
||||||
let b = matched[0]
|
let b = matched[0]
|
||||||
@ -179,12 +180,12 @@ endf
|
|||||||
|
|
||||||
|
|
||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
" Call :helptags for all bundles in g:bundles.
|
" Call :helptags for all bundles in g:vundle#bundles.
|
||||||
"
|
"
|
||||||
" return -- 'error' if an error occurred, else return 'helptags'
|
" return -- 'error' if an error occurred, else return 'helptags'
|
||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
func! vundle#installer#docs() abort
|
func! vundle#installer#docs() abort
|
||||||
let error_count = vundle#installer#helptags(g:bundles)
|
let error_count = vundle#installer#helptags(g:vundle#bundles)
|
||||||
if error_count > 0
|
if error_count > 0
|
||||||
return 'error'
|
return 'error'
|
||||||
endif
|
endif
|
||||||
@ -222,10 +223,10 @@ endf
|
|||||||
" bang -- not used
|
" bang -- not used
|
||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
func! vundle#installer#list(bang) abort
|
func! vundle#installer#list(bang) abort
|
||||||
let bundles = vundle#scripts#bundle_names(map(copy(g:bundles), 'v:val.name_spec'))
|
let bundles = vundle#scripts#bundle_names(map(copy(g:vundle#bundles), 'v:val.name_spec'))
|
||||||
call vundle#scripts#view('list', ['" My Plugins'], bundles)
|
call vundle#scripts#view('list', ['" My Plugins'], bundles)
|
||||||
redraw
|
redraw
|
||||||
echo len(g:bundles).' plugins configured'
|
echo len(g:vundle#bundles).' plugins configured'
|
||||||
endf
|
endf
|
||||||
|
|
||||||
|
|
||||||
@ -237,10 +238,10 @@ endf
|
|||||||
" should be removed unconditionally
|
" should be removed unconditionally
|
||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
func! vundle#installer#clean(bang) abort
|
func! vundle#installer#clean(bang) abort
|
||||||
let bundle_dirs = map(copy(g:bundles), 'v:val.path()')
|
let bundle_dirs = map(copy(g:vundle#bundles), 'v:val.path()')
|
||||||
let all_dirs = (v:version > 702 || (v:version == 702 && has("patch51")))
|
let all_dirs = (v:version > 702 || (v:version == 702 && has("patch51")))
|
||||||
\ ? split(globpath(g:bundle_dir, '*', 1), "\n")
|
\ ? split(globpath(g:vundle#bundle_dir, '*', 1), "\n")
|
||||||
\ : split(globpath(g:bundle_dir, '*'), "\n")
|
\ : split(globpath(g:vundle#bundle_dir, '*'), "\n")
|
||||||
let x_dirs = filter(all_dirs, '0 > index(bundle_dirs, v:val)')
|
let x_dirs = filter(all_dirs, '0 > index(bundle_dirs, v:val)')
|
||||||
|
|
||||||
if empty(x_dirs)
|
if empty(x_dirs)
|
||||||
@ -465,7 +466,7 @@ func! s:sync(bang, bundle) abort
|
|||||||
return 'todate'
|
return 'todate'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call add(g:updated_bundles, [initial_sha, updated_sha, a:bundle])
|
call add(g:vundle#updated_bundles, [initial_sha, updated_sha, a:bundle])
|
||||||
return 'updated'
|
return 'updated'
|
||||||
endf
|
endf
|
||||||
|
|
||||||
@ -527,7 +528,7 @@ func! s:log(str, ...) abort
|
|||||||
let lines = split(a:str, '\n', 1)
|
let lines = split(a:str, '\n', 1)
|
||||||
let time = strftime(fmt)
|
let time = strftime(fmt)
|
||||||
for line in lines
|
for line in lines
|
||||||
call add(g:vundle_log, '['. time .'] '. prefix . line)
|
call add(g:vundle#log, '['. time .'] '. prefix . line)
|
||||||
endfor
|
endfor
|
||||||
return a:str
|
return a:str
|
||||||
endf
|
endf
|
||||||
|
@ -42,7 +42,7 @@ endf
|
|||||||
func! vundle#scripts#complete(a,c,d)
|
func! vundle#scripts#complete(a,c,d)
|
||||||
if match(a:c, '\v^%(Plugin|Vundle)%(Install!|Update)') == 0
|
if match(a:c, '\v^%(Plugin|Vundle)%(Install!|Update)') == 0
|
||||||
" Only installed plugins if updating
|
" Only installed plugins if updating
|
||||||
return join(map(copy(g:bundles), 'v:val.name'), "\n")
|
return join(map(copy(g:vundle#bundles), 'v:val.name'), "\n")
|
||||||
else
|
else
|
||||||
" Or all known plugins otherwise
|
" Or all known plugins otherwise
|
||||||
return join(s:load_scripts(0),"\n")
|
return join(s:load_scripts(0),"\n")
|
||||||
@ -54,12 +54,15 @@ endf
|
|||||||
" View the logfile after an update or installation.
|
" View the logfile after an update or installation.
|
||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
func! s:view_log()
|
func! s:view_log()
|
||||||
if !exists('g:vundle_log_file')
|
if !exists('s:log_file')
|
||||||
let g:vundle_log_file = tempname()
|
let s:log_file = tempname()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call writefile(g:vundle_log, g:vundle_log_file)
|
if bufloaded(s:log_file)
|
||||||
execute 'silent pedit ' . g:vundle_log_file
|
execute 'silent bdelete' s:log_file
|
||||||
|
endif
|
||||||
|
call writefile(g:vundle#log, s:log_file)
|
||||||
|
execute 'silent pedit ' . s:log_file
|
||||||
|
|
||||||
wincmd P | wincmd H
|
wincmd P | wincmd H
|
||||||
endf
|
endf
|
||||||
@ -71,7 +74,7 @@ endf
|
|||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
func! s:create_changelog() abort
|
func! s:create_changelog() abort
|
||||||
let changelog = ['Updated Plugins:']
|
let changelog = ['Updated Plugins:']
|
||||||
for bundle_data in g:updated_bundles
|
for bundle_data in g:vundle#updated_bundles
|
||||||
let initial_sha = bundle_data[0]
|
let initial_sha = bundle_data[0]
|
||||||
let updated_sha = bundle_data[1]
|
let updated_sha = bundle_data[1]
|
||||||
let bundle = bundle_data[2]
|
let bundle = bundle_data[2]
|
||||||
@ -139,15 +142,15 @@ endf
|
|||||||
" strings)
|
" strings)
|
||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
func! vundle#scripts#view(title, headers, results)
|
func! vundle#scripts#view(title, headers, results)
|
||||||
if exists('g:vundle_view') && bufloaded(g:vundle_view)
|
if exists('s:view') && bufloaded(s:view)
|
||||||
exec g:vundle_view.'bd!'
|
exec s:view.'bd!'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
exec 'silent pedit [Vundle] '.a:title
|
exec 'silent pedit [Vundle] '.a:title
|
||||||
|
|
||||||
wincmd P | wincmd H
|
wincmd P | wincmd H
|
||||||
|
|
||||||
let g:vundle_view = bufnr('%')
|
let s:view = bufnr('%')
|
||||||
"
|
"
|
||||||
" make buffer modifiable
|
" make buffer modifiable
|
||||||
" to append without errors
|
" to append without errors
|
||||||
@ -255,7 +258,7 @@ endf
|
|||||||
" specifications) of all plugins from vim-scripts.org
|
" specifications) of all plugins from vim-scripts.org
|
||||||
" ---------------------------------------------------------------------------
|
" ---------------------------------------------------------------------------
|
||||||
func! s:load_scripts(bang)
|
func! s:load_scripts(bang)
|
||||||
let f = expand(g:bundle_dir.'/.vundle/script-names.vim-scripts.org.json', 1)
|
let f = expand(g:vundle#bundle_dir.'/.vundle/script-names.vim-scripts.org.json', 1)
|
||||||
if a:bang || !filereadable(f)
|
if a:bang || !filereadable(f)
|
||||||
if 0 != s:fetch_scripts(f)
|
if 0 != s:fetch_scripts(f)
|
||||||
return []
|
return []
|
||||||
|
Loading…
Reference in New Issue
Block a user