]> granicus.if.org Git - vim/commitdiff
patch 7.4.2164 v7.4.2164
authorBram Moolenaar <Bram@vim.org>
Sat, 6 Aug 2016 17:01:55 +0000 (19:01 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 6 Aug 2016 17:01:55 +0000 (19:01 +0200)
Problem:    It is not possible to use plugins in an "after" directory to tune
            the behavior of a package.
Solution:   First load plugins from non-after directories, then packages and
            finally plugins in after directories.
            Reset 'loadplugins' before executing --cmd arguments.

runtime/doc/starting.txt
src/ex_cmds2.c
src/main.c
src/testdir/Makefile
src/testdir/setup.vim
src/testdir/shared.vim
src/testdir/test_startup.vim
src/version.c
src/vim.h

index bcd1eadfe76767e7d96a45371a73502a1f6ef379..a4847c2e292cd3dd6c6ba599b66a9e8a83f5769e 100644 (file)
@@ -1,4 +1,4 @@
-*starting.txt*  For Vim version 7.4.  Last change: 2016 Jul 29
+*starting.txt*  For Vim version 7.4.  Last change: 2016 Aug 06
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -858,6 +858,8 @@ accordingly.  Vim proceeds in this order:
        searched for the "plugin" sub-directory and all files ending in ".vim"
        will be sourced (in alphabetical order per directory), also in
        subdirectories.
+       However, directories in 'runtimepath' ending in "after" are skipped
+       here and only loaded after packages, see below.
        Loading plugins won't be done when:
        - The 'loadplugins' option was reset in a vimrc file.
        - The |--noplugin| command line argument is used.
@@ -865,13 +867,18 @@ accordingly.  Vim proceeds in this order:
        - When Vim was compiled without the |+eval| feature.
        Note that using "-c 'set noloadplugins'" doesn't work, because the
        commands from the command line have not been executed yet.  You can
-       use "--cmd 'set noloadplugins'" |--cmd|.
+       use "--cmd 'set noloadplugins'" or "--cmd 'set loadplugins'" |--cmd|.
 
        Packages are loaded.  These are plugins, as above, but found in the
        "start" directory of each entry in 'packpath'.  Every plugin directory
        found is added in 'runtimepath' and then the plugins are sourced.  See
        |packages|.
 
+       The plugins scripts are loaded, as above, but now only the directories
+       ending in "after" are used.  Note that 'runtimepath' will have changed
+       if packages have been found, but that should not add a directory
+       ending in "after".
+
 5. Set 'shellpipe' and 'shellredir'
        The 'shellpipe' and 'shellredir' options are set according to the
        value of the 'shell' option, unless they have been set before.
index 2cebbebca880727ddf66461a3fd03208fbabd909..0e332dd421e833cc608289d57162cfa98fa00cc6 100644 (file)
@@ -3240,15 +3240,30 @@ do_in_path(
        rtp = rtp_copy;
        while (*rtp != NUL && ((flags & DIP_ALL) || !did_one))
        {
+           size_t buflen;
+
            /* Copy the path from 'runtimepath' to buf[]. */
            copy_option_part(&rtp, buf, MAXPATHL, ",");
+           buflen = STRLEN(buf);
+
+           /* Skip after or non-after directories. */
+           if (flags & (DIP_NOAFTER | DIP_AFTER))
+           {
+               int is_after = buflen >= 5
+                                    && STRCMP(buf + buflen - 5, "after") == 0;
+
+               if ((is_after && (flags & DIP_NOAFTER))
+                       || (!is_after && (flags & DIP_AFTER)))
+                   continue;
+           }
+
            if (name == NULL)
            {
                (*callback)(buf, (void *) &cookie);
                if (!did_one)
                    did_one = (cookie == NULL);
            }
-           else if (STRLEN(buf) + STRLEN(name) + 2 < MAXPATHL)
+           else if (buflen + STRLEN(name) + 2 < MAXPATHL)
            {
                add_pathsep(buf);
                tail = buf + STRLEN(buf);
@@ -3512,6 +3527,7 @@ static int did_source_packages = FALSE;
 /*
  * ":packloadall"
  * Find plugins in the package directories and source them.
+ * "eap" is NULL when invoked during startup.
  */
     void
 ex_packloadall(exarg_T *eap)
index 51e4483e3e7f243e9ac86605476b468316a0add4..48e90c27ffe05590143a4599d81ce7aedaef789a 100644 (file)
@@ -439,6 +439,11 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
 #endif
 
 #ifndef NO_VIM_MAIN
+    /* Reset 'loadplugins' for "-u NONE" before "--cmd" arguments.
+     * Allows for setting 'loadplugins' there. */
+    if (params.use_vimrc != NULL && STRCMP(params.use_vimrc, "NONE") == 0)
+       p_lpl = FALSE;
+
     /* Execute --cmd arguments. */
     exe_pre_commands(&params);
 
@@ -453,14 +458,22 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
     if (p_lpl)
     {
 # ifdef VMS    /* Somehow VMS doesn't handle the "**". */
-       source_runtime((char_u *)"plugin/*.vim", DIP_ALL);
+       source_runtime((char_u *)"plugin/*.vim", DIP_ALL | DIP_NOAFTER);
 # else
-       source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL);
+       source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL | DIP_NOAFTER);
 # endif
        TIME_MSG("loading plugins");
 
        ex_packloadall(NULL);
        TIME_MSG("loading packages");
+
+# ifdef VMS    /* Somehow VMS doesn't handle the "**". */
+       source_runtime((char_u *)"plugin/*.vim", DIP_ALL | DIP_AFTER);
+# else
+       source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL | DIP_AFTER);
+# endif
+       TIME_MSG("loading after plugins");
+
     }
 #endif
 
@@ -2945,8 +2958,6 @@ source_startup_scripts(mparm_T *parmp)
            if (use_gvimrc == NULL)         /* don't load gvimrc either */
                use_gvimrc = parmp->use_vimrc;
 #endif
-           if (parmp->use_vimrc[2] == 'N')
-               p_lpl = FALSE;              /* don't load plugins either */
        }
        else
        {
index 5c629ed3f7f702c3a882ea53e8c825f8efd4e6a2..2153039d567fe7be05766762aa96da064d695396 100644 (file)
@@ -127,4 +127,6 @@ newtestssilent: $(NEW_TESTS)
 
 
 .vim.res:
-       $(RUN_VIMTEST) -u NONE -U NONE -S runtest.vim $*.vim
+       @echo "$(RUN_VIMTEST)" > vimcmd
+       $(RUN_VIMTEST) -U NONE -S runtest.vim $*.vim
+       @rm vimcmd
index f7e475a81ae3232e5a8070d89decf7889d7d468e..dee3de21208d452772ead0435ea3d66867e2d5ea 100644 (file)
@@ -1,7 +1,8 @@
 " Common preparations for running tests.
 
-" Make sure 'runtimepath' does not include $HOME.
+" Make sure 'runtimepath' and 'packpath' does not include $HOME.
 set rtp=$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after
+let &packpath = &rtp
 
 " Only when the +eval feature is present. 
 if 1
index b28a26c0ba62f2ce443f32343bcd6ab5de2f78e3..d0be24166a8ad3cfcdbe9fb1619d0cf78c553662 100644 (file)
@@ -120,3 +120,24 @@ func WaitFor(expr)
     sleep 10m
   endfor
 endfunc
+
+" Run Vim, using the "vimcmd" file and "-u NORC".
+" "before" is a list of commands to be executed before loading plugins.
+" "after" is a list of commands to be executed after loading plugins.
+" Plugins are not loaded, unless 'loadplugins' is set in "before".
+" Return 1 if Vim could be executed.
+func RunVim(before, after)
+  if !filereadable('vimcmd')
+    return 0
+  endif
+  call writefile(a:before, 'Xbefore.vim')
+  call writefile(a:after, 'Xafter.vim')
+
+  let cmd = readfile('vimcmd')[0]
+  let cmd = substitute(cmd, '-u \f\+', '-u NONE', '')
+  exe "silent !" . cmd . " --cmd 'so Xbefore.vim' -S Xafter.vim"
+
+  call delete('Xbefore.vim')
+  call delete('Xafter.vim')
+  return 1
+endfunc
index 0630b2a8419b19430dd6c9cd56d0dd823a3fb425..26e7b9f8eec2e6f0192967ae5e4a45f89f241a74 100644 (file)
@@ -1,8 +1,56 @@
-" Check that loading startup.vim works.
+" Tests for startup.
+
+source shared.vim
 
+" Check that loading startup.vim works.
 func Test_startup_script()
   set compatible
   source $VIMRUNTIME/defaults.vim
 
   call assert_equal(0, &compatible)
 endfunc
+
+" Verify the order in which plugins are loaded:
+" 1. plugins in non-after directories
+" 2. packages
+" 3. plugins in after directories
+func Test_after_comes_later()
+  let before = [
+       \ 'let $HOME = "/does/not/exist"',
+       \ 'set loadplugins',
+       \ 'set rtp=Xhere,Xafter',
+       \ 'set packpath=Xhere,Xafter',
+       \ 'set nomore',
+       \ ]
+  let after = [
+       \ 'redir! > Xtestout',
+       \ 'scriptnames',
+       \ 'redir END',
+       \ 'quit',
+       \ ]
+  call mkdir('Xhere/plugin', 'p')
+  call writefile(['let done = 1'], 'Xhere/plugin/here.vim')
+  call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p')
+  call writefile(['let done = 1'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim')
+
+  call mkdir('Xafter/plugin', 'p')
+  call writefile(['let done = 1'], 'Xafter/plugin/later.vim')
+
+  call RunVim(before, after)
+
+  let lines = readfile('Xtestout')
+  let expected = ['Xbefore.vim', 'here.vim', 'foo.vim', 'later.vim', 'Xafter.vim']
+  let found = []
+  for line in lines
+    for one in expected
+      if line =~ one
+       call add(found, one)
+      endif
+    endfor
+  endfor
+  call assert_equal(expected, found)
+
+  call delete('Xtestout')
+  call delete('Xhere', 'rf')
+  call delete('Xafter', 'rf')
+endfunc
index e6488620a78ce0c5ed9c90e548952dbca9258190..142801db42bb45f698b8cd4f2e1506dcdd524403 100644 (file)
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2164,
 /**/
     2163,
 /**/
index 398fcc548f9124f7242a4917d912ed0fafae7d82..928a558fba08006500c3ba4a80c0a5e8f46a6f7a 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -2451,6 +2451,8 @@ int vim_main2(int argc, char **argv);
 #define DIP_START   0x08       /* also use "start" directory in 'packpath' */
 #define DIP_OPT            0x10        /* also use "opt" directory in 'packpath' */
 #define DIP_NORTP   0x20       /* do not use 'runtimepath' */
+#define DIP_NOAFTER 0x40       /* skip "after" directories */
+#define DIP_AFTER   0x80       /* only use "after" directories */
 
 /* Lowest number used for window ID. Cannot have this many windows. */
 #define LOWEST_WIN_ID 1000