]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.0.0612: pack dirs are added to 'runtimepath' too late v8.0.0612
authorBram Moolenaar <Bram@vim.org>
Sun, 4 Jun 2017 15:47:42 +0000 (17:47 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 4 Jun 2017 15:47:42 +0000 (17:47 +0200)
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)

src/ex_cmds2.c
src/globals.h
src/main.c
src/proto/ex_cmds2.pro
src/testdir/test_startup.vim
src/version.c

index 36ee57e8ec4afac2c546acb1117ec0275ac65368..225225a78c0206df453f111af18159ef46930cf5 100644 (file)
@@ -3633,27 +3633,41 @@ theend:
     vim_free(ffname);
 }
 
-static int did_source_packages = FALSE;
+/*
+ * Add all packages in the "start" directory to 'runtimepath'.
+ */
+    void
+add_pack_start_dirs(void)
+{
+    do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
+                                              add_pack_plugin, &APP_ADD_DIR);
+}
+
+/*
+ * Load plugins from all packages in the "start" directory.
+ */
+    void
+load_start_packages(void)
+{
+    did_source_packages = TRUE;
+    do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
+                                                 add_pack_plugin, &APP_LOAD);
+}
 
 /*
  * ":packloadall"
  * Find plugins in the package directories and source them.
- * "eap" is NULL when invoked during startup.
  */
     void
 ex_packloadall(exarg_T *eap)
 {
-    if (!did_source_packages || (eap != NULL && eap->forceit))
+    if (!did_source_packages || eap->forceit)
     {
-       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,
-                                              add_pack_plugin, &APP_ADD_DIR);
-       do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
-                                                 add_pack_plugin, &APP_LOAD);
+       add_pack_start_dirs();
+       load_start_packages();
     }
 }
 
index 7bc5471769adb01b972beb7e8e2c7b08459f039c..56df6d5083775c5f2a3d283a5dd8bc1b00c23109 100644 (file)
@@ -326,6 +326,8 @@ EXTERN int  garbage_collect_at_exit INIT(= FALSE);
 EXTERN scid_T  current_SID INIT(= 0);
 #endif
 
+EXTERN int     did_source_packages INIT(= FALSE);
+
 /* Magic number used for hashitem "hi_key" value indicating a deleted item.
  * Only the address is used. */
 EXTERN char_u  hash_removed;
index ebd1ec3333e45374b7635d1e21a7ebae354e3aa6..0c7aa98462eb8b541af9b438333d32afb176290f 100644 (file)
@@ -449,6 +449,12 @@ vim_main2(void)
      */
     if (p_lpl)
     {
+       /* First add all package directories to 'runtimepath', so that their
+        * autoload directories can be found.  Only if not done already with a
+        * :packloadall command. */
+       if (!did_source_packages)
+           add_pack_start_dirs();
+
 # ifdef VMS    /* Somehow VMS doesn't handle the "**". */
        source_runtime((char_u *)"plugin/*.vim", DIP_ALL | DIP_NOAFTER);
 # else
@@ -456,7 +462,10 @@ vim_main2(void)
 # endif
        TIME_MSG("loading plugins");
 
-       ex_packloadall(NULL);
+       /* Only source "start" packages if not done already with a :packloadall
+        * command. */
+       if (!did_source_packages)
+           load_start_packages();
        TIME_MSG("loading packages");
 
 # ifdef VMS    /* Somehow VMS doesn't handle the "**". */
index 4a40f0a767f58a24fbdf522cb2c5250d164165c8..e8d2814089a108dd53967b2233431a43bc303085 100644 (file)
@@ -72,6 +72,8 @@ void ex_runtime(exarg_T *eap);
 int source_runtime(char_u *name, int flags);
 int do_in_path(char_u *path, char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie);
 int do_in_runtimepath(char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie);
+void add_pack_start_dirs(void);
+void load_start_packages(void);
 void ex_packloadall(exarg_T *eap);
 void ex_packadd(exarg_T *eap);
 void ex_options(exarg_T *eap);
index bce431f7ddc21f2bb4bc7a3302d6a129e2fbf37b..08a107e8157fee4f14c7fa5cf63642754393c3ac 100644 (file)
@@ -61,6 +61,38 @@ func Test_after_comes_later()
   call delete('Xafter', 'rf')
 endfunc
 
+func Test_pack_in_rtp_when_plugins_run()
+  if !has('packages')
+    return
+  endif
+  let before = [
+       \ 'set nocp viminfo+=nviminfo',
+       \ 'set guioptions+=M',
+       \ 'let $HOME = "/does/not/exist"',
+       \ 'set loadplugins',
+       \ 'set rtp=Xhere',
+       \ 'set packpath=Xhere',
+       \ 'set nomore',
+       \ ]
+  let after = [
+       \ 'quit',
+       \ ]
+  call mkdir('Xhere/plugin', 'p')
+  call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim')
+  call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p')
+  call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim')
+
+  if RunVim(before, after, '')
+
+    let lines = filter(readfile('Xtestout'), '!empty(v:val)')
+    call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0))
+    call assert_match('autoloaded foo', get(lines, 1))
+  endif
+
+  call delete('Xtestout')
+  call delete('Xhere', 'rf')
+endfunc
+
 func Test_help_arg()
   if !has('unix') && has('gui')
     " this doesn't work with gvim on MS-Windows
index 2d91a72598b61ed8dee9e4adceaf09172cf03da4..91cd500526e6d5fd5bf75618ebe7db7e8a4b4d7a 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    612,
 /**/
     611,
 /**/