]> granicus.if.org Git - vim/commitdiff
patch 8.0.1398: :packadd does not load packages from the "start" directory v8.0.1398
authorBram Moolenaar <Bram@vim.org>
Sun, 17 Dec 2017 13:26:46 +0000 (14:26 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 17 Dec 2017 13:26:46 +0000 (14:26 +0100)
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.

src/ex_cmds2.c
src/testdir/test_packadd.vim
src/version.c

index 7b00ac265069be577976d94cc12f6924d3afb1f5..1475ef25dbb5688feb787d0bfae043b47fefbb0c 100644 (file)
@@ -3747,18 +3747,31 @@ ex_packloadall(exarg_T *eap)
     void
 ex_packadd(exarg_T *eap)
 {
-    static char *plugpat = "pack/*/opt/%s";
+    static char *plugpat = "pack/*/%s/%s";
     int                len;
     char       *pat;
+    int                round;
+    int                res = OK;
 
-    len = (int)STRLEN(plugpat) + (int)STRLEN(eap->arg);
-    pat = (char *)alloc(len);
-    if (pat == NULL)
-       return;
-    vim_snprintf(pat, len, plugpat, eap->arg);
-    do_in_path(p_pp, (char_u *)pat, DIP_ALL + DIP_DIR + DIP_ERR,
-                   add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH);
-    vim_free(pat);
+    /* Round 1: use "start", round 2: use "opt". */
+    for (round = 1; round <= 2; ++round)
+    {
+       /* Only look under "start" when loading packages wasn't done yet. */
+       if (round == 1 && did_source_packages)
+           continue;
+
+       len = (int)STRLEN(plugpat) + (int)STRLEN(eap->arg) + 5;
+       pat = (char *)alloc(len);
+       if (pat == NULL)
+           return;
+       vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg);
+       /* The first round don't give a "not found" error, in the second round
+        * only when nothing was found in the first round. */
+       res = do_in_path(p_pp, (char_u *)pat,
+               DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0),
+               add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH);
+       vim_free(pat);
+    }
 }
 
 #if defined(FEAT_EVAL) && defined(FEAT_AUTOCMD)
index c83d4a876ae50e26595ecef25471cbe8880305c8..09b9b82f5511c682cc0a81092c7ba30f68db4188 100644 (file)
@@ -45,6 +45,24 @@ func Test_packadd()
   call assert_fails("packadd", 'E471:')
 endfunc
 
+func Test_packadd_start()
+  let plugdir = s:topdir . '/pack/mine/start/other'
+  call mkdir(plugdir . '/plugin', 'p')
+  set rtp&
+  let rtp = &rtp
+  filetype on
+
+  exe 'split ' . plugdir . '/plugin/test.vim'
+  call setline(1, 'let g:plugin_works = 24')
+  wq
+
+  packadd other
+
+  call assert_equal(24, g:plugin_works)
+  call assert_true(len(&rtp) > len(rtp))
+  call assert_true(&rtp =~ '/testdir/Xdir/pack/mine/start/other\($\|,\)')
+endfunc
+
 func Test_packadd_noload()
   call mkdir(s:plugdir . '/plugin', 'p')
   call mkdir(s:plugdir . '/syntax', 'p')
index 096d21c9931742e36779b2b590a3a7e935457f9c..2580b9ecc24befbc0f248a300d9b4f38751e4a43 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1398,
 /**/
     1397,
 /**/