Skip to content

Commit ce876aa

Browse files
committed
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Problem: Package directories are added to 'runtimepath' only after loading non-package plugins. Solution: Split off the code to add package directories to 'runtimepath'. (Ingo Karkat, closes #1680)
1 parent 976787d commit ce876aa

6 files changed

Lines changed: 71 additions & 10 deletions

File tree

src/ex_cmds2.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3633,27 +3633,41 @@ add_pack_plugin(char_u *fname, void *cookie)
36333633
vim_free(ffname);
36343634
}
36353635

3636-
static int did_source_packages = FALSE;
3636+
/*
3637+
* Add all packages in the "start" directory to 'runtimepath'.
3638+
*/
3639+
void
3640+
add_pack_start_dirs(void)
3641+
{
3642+
do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
3643+
add_pack_plugin, &APP_ADD_DIR);
3644+
}
3645+
3646+
/*
3647+
* Load plugins from all packages in the "start" directory.
3648+
*/
3649+
void
3650+
load_start_packages(void)
3651+
{
3652+
did_source_packages = TRUE;
3653+
do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
3654+
add_pack_plugin, &APP_LOAD);
3655+
}
36373656

36383657
/*
36393658
* ":packloadall"
36403659
* Find plugins in the package directories and source them.
3641-
* "eap" is NULL when invoked during startup.
36423660
*/
36433661
void
36443662
ex_packloadall(exarg_T *eap)
36453663
{
3646-
if (!did_source_packages || (eap != NULL && eap->forceit))
3664+
if (!did_source_packages || eap->forceit)
36473665
{
3648-
did_source_packages = TRUE;
3649-
36503666
/* First do a round to add all directories to 'runtimepath', then load
36513667
* the plugins. This allows for plugins to use an autoload directory
36523668
* of another plugin. */
3653-
do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
3654-
add_pack_plugin, &APP_ADD_DIR);
3655-
do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
3656-
add_pack_plugin, &APP_LOAD);
3669+
add_pack_start_dirs();
3670+
load_start_packages();
36573671
}
36583672
}
36593673

src/globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ EXTERN int garbage_collect_at_exit INIT(= FALSE);
326326
EXTERN scid_T current_SID INIT(= 0);
327327
#endif
328328

329+
EXTERN int did_source_packages INIT(= FALSE);
330+
329331
/* Magic number used for hashitem "hi_key" value indicating a deleted item.
330332
* Only the address is used. */
331333
EXTERN char_u hash_removed;

src/main.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,23 @@ vim_main2(void)
449449
*/
450450
if (p_lpl)
451451
{
452+
/* First add all package directories to 'runtimepath', so that their
453+
* autoload directories can be found. Only if not done already with a
454+
* :packloadall command. */
455+
if (!did_source_packages)
456+
add_pack_start_dirs();
457+
452458
# ifdef VMS /* Somehow VMS doesn't handle the "**". */
453459
source_runtime((char_u *)"plugin/*.vim", DIP_ALL | DIP_NOAFTER);
454460
# else
455461
source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL | DIP_NOAFTER);
456462
# endif
457463
TIME_MSG("loading plugins");
458464

459-
ex_packloadall(NULL);
465+
/* Only source "start" packages if not done already with a :packloadall
466+
* command. */
467+
if (!did_source_packages)
468+
load_start_packages();
460469
TIME_MSG("loading packages");
461470

462471
# ifdef VMS /* Somehow VMS doesn't handle the "**". */

src/proto/ex_cmds2.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ void ex_runtime(exarg_T *eap);
7272
int source_runtime(char_u *name, int flags);
7373
int do_in_path(char_u *path, char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie);
7474
int do_in_runtimepath(char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie);
75+
void add_pack_start_dirs(void);
76+
void load_start_packages(void);
7577
void ex_packloadall(exarg_T *eap);
7678
void ex_packadd(exarg_T *eap);
7779
void ex_options(exarg_T *eap);

src/testdir/test_startup.vim

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,38 @@ func Test_after_comes_later()
6161
call delete('Xafter', 'rf')
6262
endfunc
6363

64+
func Test_pack_in_rtp_when_plugins_run()
65+
if !has('packages')
66+
return
67+
endif
68+
let before = [
69+
\ 'set nocp viminfo+=nviminfo',
70+
\ 'set guioptions+=M',
71+
\ 'let $HOME = "/does/not/exist"',
72+
\ 'set loadplugins',
73+
\ 'set rtp=Xhere',
74+
\ 'set packpath=Xhere',
75+
\ 'set nomore',
76+
\ ]
77+
let after = [
78+
\ 'quit',
79+
\ ]
80+
call mkdir('Xhere/plugin', 'p')
81+
call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim')
82+
call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p')
83+
call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim')
84+
85+
if RunVim(before, after, '')
86+
87+
let lines = filter(readfile('Xtestout'), '!empty(v:val)')
88+
call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0))
89+
call assert_match('autoloaded foo', get(lines, 1))
90+
endif
91+
92+
call delete('Xtestout')
93+
call delete('Xhere', 'rf')
94+
endfunc
95+
6496
func Test_help_arg()
6597
if !has('unix') && has('gui')
6698
" this doesn't work with gvim on MS-Windows

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
612,
767769
/**/
768770
611,
769771
/**/

0 commit comments

Comments
 (0)