To: vim_dev@googlegroups.com Subject: Patch 7.4.2164 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.2164 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. Files: src/main.c, src/vim.h, src/ex_cmds2.c, src/testdir/Makefile, src/testdir/shared.vim, src/testdir/test_startup.vim, src/testdir/setup.vim, runtime/doc/starting.txt *** ../vim-7.4.2163/src/main.c 2016-07-29 18:13:29.132175672 +0200 --- src/main.c 2016-08-06 18:33:09.070425126 +0200 *************** *** 439,444 **** --- 439,449 ---- #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(¶ms); *************** *** 453,466 **** if (p_lpl) { # ifdef VMS /* Somehow VMS doesn't handle the "**". */ ! source_runtime((char_u *)"plugin/*.vim", DIP_ALL); # else ! source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL); # endif TIME_MSG("loading plugins"); ex_packloadall(NULL); TIME_MSG("loading packages"); } #endif --- 458,479 ---- if (p_lpl) { # ifdef VMS /* Somehow VMS doesn't handle the "**". */ ! source_runtime((char_u *)"plugin/*.vim", DIP_ALL | DIP_NOAFTER); # else ! 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,2952 **** 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 { --- 2958,2963 ---- *** ../vim-7.4.2163/src/vim.h 2016-08-03 22:08:41.747652107 +0200 --- src/vim.h 2016-08-06 16:09:42.169225902 +0200 *************** *** 2451,2456 **** --- 2451,2458 ---- #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 *** ../vim-7.4.2163/src/ex_cmds2.c 2016-07-30 22:47:44.322520729 +0200 --- src/ex_cmds2.c 2016-08-06 16:17:35.793222539 +0200 *************** *** 3240,3254 **** rtp = rtp_copy; while (*rtp != NUL && ((flags & DIP_ALL) || !did_one)) { /* Copy the path from 'runtimepath' to buf[]. */ copy_option_part(&rtp, buf, MAXPATHL, ","); if (name == NULL) { (*callback)(buf, (void *) &cookie); if (!did_one) did_one = (cookie == NULL); } ! else if (STRLEN(buf) + STRLEN(name) + 2 < MAXPATHL) { add_pathsep(buf); tail = buf + STRLEN(buf); --- 3240,3269 ---- 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 (buflen + STRLEN(name) + 2 < MAXPATHL) { add_pathsep(buf); tail = buf + STRLEN(buf); *************** *** 3512,3517 **** --- 3527,3533 ---- /* * ":packloadall" * Find plugins in the package directories and source them. + * "eap" is NULL when invoked during startup. */ void ex_packloadall(exarg_T *eap) *** ../vim-7.4.2163/src/testdir/Makefile 2016-07-31 14:17:22.907502194 +0200 --- src/testdir/Makefile 2016-08-06 19:00:18.097455512 +0200 *************** *** 127,130 **** .vim.res: ! $(RUN_VIMTEST) -u NONE -U NONE -S runtest.vim $*.vim --- 127,132 ---- .vim.res: ! @echo "$(RUN_VIMTEST)" > vimcmd ! $(RUN_VIMTEST) -U NONE -S runtest.vim $*.vim ! @rm vimcmd *** ../vim-7.4.2163/src/testdir/shared.vim 2016-07-15 17:08:45.662711053 +0200 --- src/testdir/shared.vim 2016-08-06 18:32:20.470816770 +0200 *************** *** 120,122 **** --- 120,143 ---- 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 *** ../vim-7.4.2163/src/testdir/test_startup.vim 2016-07-29 18:13:29.136175634 +0200 --- src/testdir/test_startup.vim 2016-08-06 18:38:54.259641823 +0200 *************** *** 1,8 **** ! " Check that loading startup.vim works. func Test_startup_script() set compatible source $VIMRUNTIME/defaults.vim call assert_equal(0, &compatible) endfunc --- 1,56 ---- ! " 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 *** ../vim-7.4.2163/src/testdir/setup.vim 2016-07-12 22:51:04.997428046 +0200 --- src/testdir/setup.vim 2016-08-06 18:38:00.992071500 +0200 *************** *** 1,7 **** " Common preparations for running tests. ! " Make sure 'runtimepath' does not include $HOME. set rtp=$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after " Only when the +eval feature is present. if 1 --- 1,8 ---- " Common preparations for running tests. ! " 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 *** ../vim-7.4.2163/runtime/doc/starting.txt 2016-07-28 22:22:39.982236402 +0200 --- runtime/doc/starting.txt 2016-08-06 18:56:35.359211711 +0200 *************** *** 851,856 **** --- 858,865 ---- 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. *************** *** 858,870 **** - 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|. 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|. 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. --- 867,884 ---- - 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'" 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. *** ../vim-7.4.2163/src/version.c 2016-08-06 15:29:07.241549789 +0200 --- src/version.c 2016-08-06 17:24:50.631559668 +0200 *************** *** 765,766 **** --- 765,768 ---- { /* Add new patch number below this line */ + /**/ + 2164, /**/ -- | Ceci n'est pas une pipe. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///