Skip to content

Commit 9e1d399

Browse files
committed
patch 8.0.1398: :packadd does not load packages from the "start" directory
Problem: :packadd does not load packages from the "start" directory. (Alejandro Hernandez) Solution: Make :packadd look in the "start" directory if those packages were not loaded on startup.
1 parent 890dd05 commit 9e1d399

3 files changed

Lines changed: 42 additions & 9 deletions

File tree

src/ex_cmds2.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3747,18 +3747,31 @@ ex_packloadall(exarg_T *eap)
37473747
void
37483748
ex_packadd(exarg_T *eap)
37493749
{
3750-
static char *plugpat = "pack/*/opt/%s";
3750+
static char *plugpat = "pack/*/%s/%s";
37513751
int len;
37523752
char *pat;
3753+
int round;
3754+
int res = OK;
37533755

3754-
len = (int)STRLEN(plugpat) + (int)STRLEN(eap->arg);
3755-
pat = (char *)alloc(len);
3756-
if (pat == NULL)
3757-
return;
3758-
vim_snprintf(pat, len, plugpat, eap->arg);
3759-
do_in_path(p_pp, (char_u *)pat, DIP_ALL + DIP_DIR + DIP_ERR,
3760-
add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH);
3761-
vim_free(pat);
3756+
/* Round 1: use "start", round 2: use "opt". */
3757+
for (round = 1; round <= 2; ++round)
3758+
{
3759+
/* Only look under "start" when loading packages wasn't done yet. */
3760+
if (round == 1 && did_source_packages)
3761+
continue;
3762+
3763+
len = (int)STRLEN(plugpat) + (int)STRLEN(eap->arg) + 5;
3764+
pat = (char *)alloc(len);
3765+
if (pat == NULL)
3766+
return;
3767+
vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg);
3768+
/* The first round don't give a "not found" error, in the second round
3769+
* only when nothing was found in the first round. */
3770+
res = do_in_path(p_pp, (char_u *)pat,
3771+
DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0),
3772+
add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH);
3773+
vim_free(pat);
3774+
}
37623775
}
37633776

37643777
#if defined(FEAT_EVAL) && defined(FEAT_AUTOCMD)

src/testdir/test_packadd.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ func Test_packadd()
4545
call assert_fails("packadd", 'E471:')
4646
endfunc
4747

48+
func Test_packadd_start()
49+
let plugdir = s:topdir . '/pack/mine/start/other'
50+
call mkdir(plugdir . '/plugin', 'p')
51+
set rtp&
52+
let rtp = &rtp
53+
filetype on
54+
55+
exe 'split ' . plugdir . '/plugin/test.vim'
56+
call setline(1, 'let g:plugin_works = 24')
57+
wq
58+
59+
packadd other
60+
61+
call assert_equal(24, g:plugin_works)
62+
call assert_true(len(&rtp) > len(rtp))
63+
call assert_true(&rtp =~ '/testdir/Xdir/pack/mine/start/other\($\|,\)')
64+
endfunc
65+
4866
func Test_packadd_noload()
4967
call mkdir(s:plugdir . '/plugin', 'p')
5068
call mkdir(s:plugdir . '/syntax', 'p')

src/version.c

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

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1398,
774776
/**/
775777
1397,
776778
/**/

0 commit comments

Comments
 (0)