Skip to content

Commit 34a3077

Browse files
committed
Merge pull request #450 from lucc/autoload-vars
Refactor global variables to autoload variables
2 parents 7d9b108 + 16237bb commit 34a3077

4 files changed

Lines changed: 60 additions & 50 deletions

File tree

autoload/vundle.vim

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ com! -nargs=? -bang PluginClean
2121
\ call vundle#installer#clean('!' == '<bang>')
2222

2323
com! -nargs=0 PluginDocs
24-
\ call vundle#installer#helptags(g:bundles)
24+
\ call vundle#installer#helptags(g:vundle#bundles)
2525

2626
" Aliases
2727
com! -nargs=* -complete=custom,vundle#scripts#complete PluginUpdate PluginInstall! <args>
@@ -61,24 +61,30 @@ endif
6161
" :Plugin command in the vimrc. It is not possible to do this automatically
6262
" because when loading the vimrc file no plugins where loaded yet.
6363
func! vundle#rc(...) abort
64-
let g:bundle_dir = len(a:000) > 0 ? expand(a:1, 1) : expand('$HOME/.vim/bundle', 1)
65-
let g:updated_bundles = []
66-
let g:vundle_log = []
67-
let g:vundle_changelog = ['Updated Plugins:']
64+
if a:0 > 0
65+
let g:vundle#bundle_dir = expand(a:1, 1)
66+
endif
6867
call vundle#config#init()
6968
endf
7069

7170
" Alternative to vundle#rc, offers speed up by modifying rtp only when end()
7271
" called later.
7372
func! vundle#begin(...) abort
74-
let g:vundle_lazy_load = 1
73+
let g:vundle#lazy_load = 1
7574
call call('vundle#rc', a:000)
7675
endf
7776

7877
" Finishes putting plugins on the rtp.
7978
func! vundle#end(...) abort
80-
unlet g:vundle_lazy_load
79+
unlet g:vundle#lazy_load
8180
call vundle#config#activate_bundles()
8281
endf
8382

83+
" Initialize some global variables used by Vundle.
84+
let vundle#bundle_dir = expand('$HOME/.vim/bundle', 1)
85+
let vundle#bundles = []
86+
let vundle#lazy_load = 0
87+
let vundle#log = []
88+
let vundle#updated_bundles = []
89+
8490
" vim: set expandtab sts=2 ts=2 sw=2 tw=78 norl:

autoload/vundle/config.vim

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ func! vundle#config#bundle(arg, ...)
1010
if !s:check_bundle_name(bundle)
1111
return
1212
endif
13-
if exists('g:vundle_lazy_load') && g:vundle_lazy_load
14-
call add(g:bundles, bundle)
13+
if exists('g:vundle#lazy_load') && g:vundle#lazy_load
14+
call add(g:vundle#bundles, bundle)
1515
else
1616
call s:rtp_rm_a()
17-
call add(g:bundles, bundle)
17+
call add(g:vundle#bundles, bundle)
1818
call s:rtp_add_a()
1919
call s:rtp_add_defaults()
2020
endif
@@ -40,10 +40,10 @@ endf
4040
" once.
4141
" ---------------------------------------------------------------------------
4242
func! vundle#config#init()
43-
if !exists('g:bundles') | let g:bundles = [] | endif
43+
if !exists('g:vundle#bundles') | let g:vundle#bundles = [] | endif
4444
call s:rtp_rm_a()
45-
let g:bundles = []
46-
let g:bundle_names = {}
45+
let g:vundle#bundles = []
46+
let s:bundle_names = {}
4747
endf
4848

4949

@@ -55,11 +55,11 @@ endf
5555
func! vundle#config#require(bundles) abort
5656
for b in a:bundles
5757
call s:rtp_add(b.rtpath)
58-
call s:rtp_add(g:bundle_dir)
58+
call s:rtp_add(g:vundle#bundle_dir)
5959
" TODO: it has to be relative rtpath, not bundle.name
6060
exec 'runtime! '.b.name.'/plugin/*.vim'
6161
exec 'runtime! '.b.name.'/after/*.vim'
62-
call s:rtp_rm(g:bundle_dir)
62+
call s:rtp_rm(g:vundle#bundle_dir)
6363
endfor
6464
call s:rtp_add_defaults()
6565
endf
@@ -91,14 +91,14 @@ endf
9191
" return -- 0 if the bundle's name has been seen before, 1 otherwise
9292
" ---------------------------------------------------------------------------
9393
funct! s:check_bundle_name(bundle)
94-
if has_key(g:bundle_names, a:bundle.name)
94+
if has_key(s:bundle_names, a:bundle.name)
9595
echoerr 'Vundle error: Name collision for Plugin ' . a:bundle.name_spec .
96-
\ '. Plugin ' . g:bundle_names[a:bundle.name] .
96+
\ '. Plugin ' . s:bundle_names[a:bundle.name] .
9797
\ ' previously used the name "' . a:bundle.name . '"' .
9898
\ '. Skipping Plugin ' . a:bundle.name_spec . '.'
9999
return 0
100100
endif
101-
let g:bundle_names[a:bundle.name] = a:bundle.name_spec
101+
let s:bundle_names[a:bundle.name] = a:bundle.name_spec
102102
return 1
103103
endf
104104

@@ -180,7 +180,7 @@ endf
180180
" runtimepath.
181181
" ---------------------------------------------------------------------------
182182
func! s:rtp_rm_a()
183-
let paths = map(copy(g:bundles), 'v:val.rtpath')
183+
let paths = map(copy(g:vundle#bundles), 'v:val.rtpath')
184184
let prepends = join(paths, ',')
185185
let appends = join(paths, '/after,').'/after'
186186
exec 'set rtp-='.fnameescape(prepends)
@@ -193,7 +193,7 @@ endf
193193
" runtimepath.
194194
" ---------------------------------------------------------------------------
195195
func! s:rtp_add_a()
196-
let paths = map(copy(g:bundles), 'v:val.rtpath')
196+
let paths = map(copy(g:vundle#bundles), 'v:val.rtpath')
197197
let prepends = join(paths, ',')
198198
let appends = join(paths, '/after,').'/after'
199199
exec 'set rtp^='.fnameescape(prepends)
@@ -262,7 +262,7 @@ let s:bundle = {}
262262
" return -- the target location to clone this bundle to
263263
" ---------------------------------------------------------------------------
264264
func! s:bundle.path()
265-
return s:expand_path(g:bundle_dir.'/'.self.name)
265+
return s:expand_path(g:vundle#bundle_dir.'/'.self.name)
266266
endf
267267

268268

autoload/vundle/installer.vim

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
" ---------------------------------------------------------------------------
2-
" Try to clone all new bundles given (or all bundles in g:bundles by default)
3-
" to g:bundle_dir. If a:bang is 1 it will also update all plugins (git pull).
2+
" Try to clone all new bundles given (or all bundles in g:vundle#bundles by
3+
" default) to g:vundle#bundle_dir. If a:bang is 1 it will also update all
4+
" plugins (git pull).
45
"
56
" bang -- 1 or 0
67
" ... -- any number of bundle specifications (separate arguments)
78
" ---------------------------------------------------------------------------
89
func! vundle#installer#new(bang, ...) abort
910
" No specific plugins are specified. Operate on all plugins.
1011
if a:0 == 0
11-
let bundles = g:bundles
12+
let bundles = g:vundle#bundles
1213
" Specific plugins are specified for update. Update them.
1314
elseif (a:bang)
14-
let bundles = filter(copy(g:bundles), 'index(a:000, v:val.name) > -1')
15+
let bundles = filter(copy(g:vundle#bundles), 'index(a:000, v:val.name) > -1')
1516
" Specific plugins are specified for installation. Install them.
1617
else
1718
let bundles = map(copy(a:000), 'vundle#config#bundle(v:val, {})')
@@ -23,7 +24,7 @@ func! vundle#installer#new(bang, ...) abort
2324
endif
2425

2526
let names = vundle#scripts#bundle_names(map(copy(bundles), 'v:val.name_spec'))
26-
call vundle#scripts#view('Installer',['" Installing plugins to '.expand(g:bundle_dir, 1)], names + ['Helptags'])
27+
call vundle#scripts#view('Installer',['" Installing plugins to '.expand(g:vundle#bundle_dir, 1)], names + ['Helptags'])
2728

2829
" This calls 'add' as a normal mode command. This is a buffer local mapping
2930
" defined in vundle#scripts#view(). The mapping will call a buffer local
@@ -55,11 +56,11 @@ func! s:process(bang, cmd)
5556

5657
exec ':norm '.a:cmd
5758

58-
if 'error' == g:vundle_last_status
59+
if 'error' == s:last_status
5960
let msg = 'With errors; press l to view log'
6061
endif
6162

62-
if 'updated' == g:vundle_last_status && empty(msg)
63+
if 'updated' == s:last_status && empty(msg)
6364
let msg = 'Plugins updated; press u to view changelog'
6465
endif
6566

@@ -118,7 +119,7 @@ func! vundle#installer#run(func_name, name, ...) abort
118119
throw 'whoops, unknown status:'.status
119120
endif
120121

121-
let g:vundle_last_status = status
122+
let s:last_status = status
122123

123124
return status
124125
endf
@@ -163,10 +164,10 @@ endf
163164
" return -- the return value from s:sync()
164165
" ---------------------------------------------------------------------------
165166
func! vundle#installer#install(bang, name) abort
166-
if !isdirectory(g:bundle_dir) | call mkdir(g:bundle_dir, 'p') | endif
167+
if !isdirectory(g:vundle#bundle_dir) | call mkdir(g:vundle#bundle_dir, 'p') | endif
167168

168169
let n = substitute(a:name,"['".'"]\+','','g')
169-
let matched = filter(copy(g:bundles), 'v:val.name_spec == n')
170+
let matched = filter(copy(g:vundle#bundles), 'v:val.name_spec == n')
170171

171172
if len(matched) > 0
172173
let b = matched[0]
@@ -179,12 +180,12 @@ endf
179180

180181

181182
" ---------------------------------------------------------------------------
182-
" Call :helptags for all bundles in g:bundles.
183+
" Call :helptags for all bundles in g:vundle#bundles.
183184
"
184185
" return -- 'error' if an error occurred, else return 'helptags'
185186
" ---------------------------------------------------------------------------
186187
func! vundle#installer#docs() abort
187-
let error_count = vundle#installer#helptags(g:bundles)
188+
let error_count = vundle#installer#helptags(g:vundle#bundles)
188189
if error_count > 0
189190
return 'error'
190191
endif
@@ -222,10 +223,10 @@ endf
222223
" bang -- not used
223224
" ---------------------------------------------------------------------------
224225
func! vundle#installer#list(bang) abort
225-
let bundles = vundle#scripts#bundle_names(map(copy(g:bundles), 'v:val.name_spec'))
226+
let bundles = vundle#scripts#bundle_names(map(copy(g:vundle#bundles), 'v:val.name_spec'))
226227
call vundle#scripts#view('list', ['" My Plugins'], bundles)
227228
redraw
228-
echo len(g:bundles).' plugins configured'
229+
echo len(g:vundle#bundles).' plugins configured'
229230
endf
230231

231232

@@ -237,10 +238,10 @@ endf
237238
" should be removed unconditionally
238239
" ---------------------------------------------------------------------------
239240
func! vundle#installer#clean(bang) abort
240-
let bundle_dirs = map(copy(g:bundles), 'v:val.path()')
241+
let bundle_dirs = map(copy(g:vundle#bundles), 'v:val.path()')
241242
let all_dirs = (v:version > 702 || (v:version == 702 && has("patch51")))
242-
\ ? split(globpath(g:bundle_dir, '*', 1), "\n")
243-
\ : split(globpath(g:bundle_dir, '*'), "\n")
243+
\ ? split(globpath(g:vundle#bundle_dir, '*', 1), "\n")
244+
\ : split(globpath(g:vundle#bundle_dir, '*'), "\n")
244245
let x_dirs = filter(all_dirs, '0 > index(bundle_dirs, v:val)')
245246

246247
if empty(x_dirs)
@@ -465,7 +466,7 @@ func! s:sync(bang, bundle) abort
465466
return 'todate'
466467
endif
467468

468-
call add(g:updated_bundles, [initial_sha, updated_sha, a:bundle])
469+
call add(g:vundle#updated_bundles, [initial_sha, updated_sha, a:bundle])
469470
return 'updated'
470471
endf
471472

@@ -527,7 +528,7 @@ func! s:log(str, ...) abort
527528
let lines = split(a:str, '\n', 1)
528529
let time = strftime(fmt)
529530
for line in lines
530-
call add(g:vundle_log, '['. time .'] '. prefix . line)
531+
call add(g:vundle#log, '['. time .'] '. prefix . line)
531532
endfor
532533
return a:str
533534
endf

autoload/vundle/scripts.vim

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ endf
4242
func! vundle#scripts#complete(a,c,d)
4343
if match(a:c, '\v^%(Plugin|Vundle)%(Install!|Update)') == 0
4444
" Only installed plugins if updating
45-
return join(map(copy(g:bundles), 'v:val.name'), "\n")
45+
return join(map(copy(g:vundle#bundles), 'v:val.name'), "\n")
4646
else
4747
" Or all known plugins otherwise
4848
return join(s:load_scripts(0),"\n")
@@ -54,12 +54,15 @@ endf
5454
" View the logfile after an update or installation.
5555
" ---------------------------------------------------------------------------
5656
func! s:view_log()
57-
if !exists('g:vundle_log_file')
58-
let g:vundle_log_file = tempname()
57+
if !exists('s:log_file')
58+
let s:log_file = tempname()
5959
endif
6060

61-
call writefile(g:vundle_log, g:vundle_log_file)
62-
execute 'silent pedit ' . g:vundle_log_file
61+
if bufloaded(s:log_file)
62+
execute 'silent bdelete' s:log_file
63+
endif
64+
call writefile(g:vundle#log, s:log_file)
65+
execute 'silent pedit ' . s:log_file
6366

6467
wincmd P | wincmd H
6568
endf
@@ -71,7 +74,7 @@ endf
7174
" ---------------------------------------------------------------------------
7275
func! s:create_changelog() abort
7376
let changelog = ['Updated Plugins:']
74-
for bundle_data in g:updated_bundles
77+
for bundle_data in g:vundle#updated_bundles
7578
let initial_sha = bundle_data[0]
7679
let updated_sha = bundle_data[1]
7780
let bundle = bundle_data[2]
@@ -139,15 +142,15 @@ endf
139142
" strings)
140143
" ---------------------------------------------------------------------------
141144
func! vundle#scripts#view(title, headers, results)
142-
if exists('g:vundle_view') && bufloaded(g:vundle_view)
143-
exec g:vundle_view.'bd!'
145+
if exists('s:view') && bufloaded(s:view)
146+
exec s:view.'bd!'
144147
endif
145148

146149
exec 'silent pedit [Vundle] '.a:title
147150

148151
wincmd P | wincmd H
149152

150-
let g:vundle_view = bufnr('%')
153+
let s:view = bufnr('%')
151154
"
152155
" make buffer modifiable
153156
" to append without errors
@@ -255,7 +258,7 @@ endf
255258
" specifications) of all plugins from vim-scripts.org
256259
" ---------------------------------------------------------------------------
257260
func! s:load_scripts(bang)
258-
let f = expand(g:bundle_dir.'/.vundle/script-names.vim-scripts.org.json', 1)
261+
let f = expand(g:vundle#bundle_dir.'/.vundle/script-names.vim-scripts.org.json', 1)
259262
if a:bang || !filereadable(f)
260263
if 0 != s:fetch_scripts(f)
261264
return []

0 commit comments

Comments
 (0)