vim-patch:7.4.1712

Problem:    For plugins in packages, plugin authors need to take care of all
            dependencies.
Solution:   When loading "start" packages and for :packloadall, first add all
            directories to 'runtimepath' before sourcing plugins.

49b2732644
This commit is contained in:
James McCoy
2016-07-07 23:12:33 -04:00
parent 3f689ed327
commit 23b2ee0771
3 changed files with 46 additions and 9 deletions

View File

@@ -2452,18 +2452,22 @@ static void source_all_matches(char_u *pat)
} }
} }
// used for "cookie" of add_pack_plugin()
static int APP_ADD_DIR;
static int APP_LOAD;
static int APP_BOTH;
static void add_pack_plugin(char_u *fname, void *cookie) static void add_pack_plugin(char_u *fname, void *cookie)
{ {
char_u *p4, *p3, *p2, *p1, *p; char_u *p4, *p3, *p2, *p1, *p;
char_u *new_rtp; char_u *new_rtp;
char_u *ffname = (char_u *)fix_fname((char *)fname); char_u *ffname = (char_u *)fix_fname((char *)fname);
bool load_files = cookie != NULL;
if (ffname == NULL) { if (ffname == NULL) {
return; return;
} }
if (strstr((char *)p_rtp, (char *)ffname) == NULL) { if (cookie != &APP_LOAD && strstr((char *)p_rtp, (char *)ffname) == NULL) {
// directory not in 'runtimepath', add it // directory not in 'runtimepath', add it
p4 = p3 = p2 = p1 = get_past_head(ffname); p4 = p3 = p2 = p1 = get_past_head(ffname);
for (p = p1; *p; mb_ptr_adv(p)) { for (p = p1; *p; mb_ptr_adv(p)) {
@@ -2510,7 +2514,7 @@ static void add_pack_plugin(char_u *fname, void *cookie)
xfree(new_rtp); xfree(new_rtp);
} }
if (load_files) { if (cookie != &APP_ADD_DIR) {
static const char *plugpat = "%s/plugin/*.vim"; static const char *plugpat = "%s/plugin/*.vim";
static const char *ftpat = "%s/ftdetect/*.vim"; static const char *ftpat = "%s/ftdetect/*.vim";
@@ -2548,8 +2552,14 @@ void ex_packloadall(exarg_T *eap)
{ {
if (!did_source_packages || (eap != NULL && eap->forceit)) { if (!did_source_packages || (eap != NULL && eap->forceit)) {
did_source_packages = true; did_source_packages = true;
// First do a round to add all directories to 'runtimepath', then load
// the plugins. This allows for plugins to use an autoload directory
// of another plugin.
do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
add_pack_plugin, p_pp); add_pack_plugin, &APP_ADD_DIR);
do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
add_pack_plugin, &APP_LOAD);
} }
} }
@@ -2562,7 +2572,7 @@ void ex_packadd(exarg_T *eap)
char *pat = (char *)xmallocz(len); char *pat = (char *)xmallocz(len);
vim_snprintf(pat, len, plugpat, eap->arg); vim_snprintf(pat, len, plugpat, eap->arg);
do_in_path(p_pp, (char_u *)pat, DIP_ALL + DIP_DIR + DIP_ERR, add_pack_plugin, do_in_path(p_pp, (char_u *)pat, DIP_ALL + DIP_DIR + DIP_ERR, add_pack_plugin,
eap->forceit ? NULL : p_pp); eap->forceit ? &APP_ADD_DIR : &APP_BOTH);
xfree(pat); xfree(pat);
} }

View File

@@ -87,6 +87,7 @@ static int included_patches[] = {
1753, 1753,
1728, 1728,
1716, 1716,
1712,
1695, 1695,
1654, 1654,
1652, 1652,

View File

@@ -75,14 +75,40 @@ describe('packadd', function()
endfunc endfunc
func Test_packloadall() func Test_packloadall()
let plugindir = &packpath . '/pack/mine/start/foo/plugin' " plugin foo with an autoload directory
call mkdir(plugindir, 'p') let fooplugindir = &packpath . '/pack/mine/start/foo/plugin'
call writefile(['let g:plugin_foo_number = 1234'], plugindir . '/bar.vim') call mkdir(fooplugindir, 'p')
call writefile(['let g:plugin_foo_number = 1234',
\ 'let g:plugin_foo_auto = bbb#value',
\ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim')
let fooautodir = &packpath . '/pack/mine/start/foo/autoload'
call mkdir(fooautodir, 'p')
call writefile(['let bar#value = 77'], fooautodir . '/bar.vim')
" plugin aaa with an autoload directory
let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin'
call mkdir(aaaplugindir, 'p')
call writefile(['let g:plugin_aaa_number = 333',
\ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim')
let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload'
call mkdir(aaaautodir, 'p')
call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim')
" plugin extra with only an autoload directory
let extraautodir = &packpath . '/pack/mine/start/extra/autoload'
call mkdir(extraautodir, 'p')
call writefile(['let extra#value = 99'], extraautodir . '/extra.vim')
packloadall packloadall
call assert_equal(1234, g:plugin_foo_number) call assert_equal(1234, g:plugin_foo_number)
call assert_equal(55, g:plugin_foo_auto)
call assert_equal(99, g:plugin_extra_auto)
call assert_equal(333, g:plugin_aaa_number)
call assert_equal(77, g:plugin_aaa_auto)
" only works once " only works once
call writefile(['let g:plugin_bar_number = 4321'], plugindir . '/bar2.vim') call writefile(['let g:plugin_bar_number = 4321'],
\ fooplugindir . '/bar2.vim')
packloadall packloadall
call assert_false(exists('g:plugin_bar_number')) call assert_false(exists('g:plugin_bar_number'))