diff options
author | James McCoy <jamessan@jamessan.com> | 2016-04-28 22:58:24 -0400 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2016-07-08 01:43:36 -0400 |
commit | 2f72f34f0407dcdf189bb4f3a4b79b51e96744bf (patch) | |
tree | b78d4294ec2c485f91df73db98365f675ba3496a | |
parent | 67d8e586318a3f2f13df22f9a3b25c6d8a109e6c (diff) | |
download | rneovim-2f72f34f0407dcdf189bb4f3a4b79b51e96744bf.tar.gz rneovim-2f72f34f0407dcdf189bb4f3a4b79b51e96744bf.tar.bz2 rneovim-2f72f34f0407dcdf189bb4f3a4b79b51e96744bf.zip |
vim-patch:7.4.1486
Problem: ":loadplugin" is not optimal, some people find it confusing.
Solution: Only use ":packadd" with an optional "!".
https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
-rw-r--r-- | runtime/doc/repeat.txt | 14 | ||||
-rw-r--r-- | src/nvim/ex_cmds.lua | 6 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 147 | ||||
-rw-r--r-- | src/nvim/version.c | 2 | ||||
-rw-r--r-- | test/functional/legacy/packadd_spec.lua (renamed from test/functional/legacy/loadplugin_spec.lua) | 33 |
5 files changed, 104 insertions, 98 deletions
diff --git a/runtime/doc/repeat.txt b/runtime/doc/repeat.txt index b9dee8d261..bee05d8efa 100644 --- a/runtime/doc/repeat.txt +++ b/runtime/doc/repeat.txt @@ -418,6 +418,12 @@ You would now have these files under ~/.local/share/nvim/site: pack/my/ever/always/syntax/always.vim pack/my/opt/mydebug/plugin/debugger.vim +If you don't have a package but a single plugin, you need to create the extra +directory level: + % mkdir -p ~/.local/share/nvim/site/pack/my/ever/always + % cd ~/.local/share/nvim/site/pack/my/ever/always + % unzip /tmp/myplugin.zip + When Vim starts up it scans all directories in 'packpath' for plugins under the "ever" directory and loads them. When found that directory is added to 'runtimepath'. @@ -428,11 +434,11 @@ In the example Vim will find "my/ever/always/plugin/always.vim" and adds If the "always" plugin kicks in and sets the 'filetype' to "always", Vim will find the syntax/always.vim file, because its directory is in 'runtimepath'. -Vim will also load ftdetect files, like with |:loadplugin|. +Vim will also load ftdetect files, like with |:packadd|. - *load-plugin* -To load an optional plugin from a pack use the `:loadplugin` command: > - :loadplugin mydebug + *pack-add* +To load an optional plugin from a pack use the `:packadd` command: > + :packadd mydebug This could be done inside always.vim, if some conditions are met. Or you could add this command to your |.vimrc|. diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua index de538ce733..81a0610a90 100644 --- a/src/nvim/ex_cmds.lua +++ b/src/nvim/ex_cmds.lua @@ -1453,12 +1453,6 @@ return { func='ex_loadkeymap', }, { - command='loadplugin', - flags=bit.bor(BANG, FILE1, TRLBAR, SBOXOK, CMDWIN), - addr_type=ADDR_LINES, - func='ex_loadplugin', - }, - { command='lockmarks', flags=bit.bor(NEEDARG, EXTRA, NOTRLCOM), addr_type=ADDR_LINES, diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 93da08a629..6bfa494094 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2381,76 +2381,67 @@ int do_in_runtimepath(char_u *name, bool all, DoInRuntimepathCB callback, return do_in_path(p_rtp, name, all ? DIP_ALL : 0, callback, cookie); } -// Source filetype detection scripts, if filetype.vim was already done. -static void may_do_filetypes(char_u *pat) +// Expand wildcards in "pat" and invoke do_source() for each match. +static void source_all_matches(char_u *pat) { - char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes"); + int num_files; + char_u **files; - // If runtime/filetype.vim wasn't loaded yet, the scripts will be found - // when it loads. - if (cmd != NULL && eval_to_number(cmd) > 0) { - do_cmdline_cmd("augroup filetypedetect"); - do_in_path(p_pp, pat, DIP_ALL, source_callback, NULL); - do_cmdline_cmd("augroup END"); + if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) == OK) { + for (int i = 0; i < num_files; i++) { + (void)do_source(files[i], false, DOSO_NONE); + } + FreeWild(num_files, files); } - xfree(cmd); } static void add_pack_plugin(char_u *fname, void *cookie) { - char_u *p6, *p5, *p4, *p3, *p2, *p1, *p; + char_u *p4, *p3, *p2, *p1, *p; char_u *new_rtp; char_u *ffname = (char_u *)fix_fname((char *)fname); - bool load_file = cookie != NULL; + bool load_files = cookie != NULL; if (ffname == NULL) { return; } - p6 = p5 = p4 = p3 = p2 = p1 = get_past_head(ffname); - for (p = p1; *p; mb_ptr_adv(p)) { - if (vim_ispathsep_nocolon(*p)) { - p6 = p5; p5 = p4; p4 = p3; p3 = p2; p2 = p1; p1 = p; - } - } - // now we have: load_file == true - // rtp/pack/name/ever/name/plugin/name.vim - // p6 p5 p4 p3 p2 p1 - // - // with load_file == false - // rtp/pack/name/ever/name - // p4 p3 p2 p1 - if (load_file) { - p4 = p6; - } - - // find the part up to "pack" in 'runtimepath' - char_u c = *p4; - *p4 = NUL; - p = (char_u *)strstr((char *)p_rtp, (char *)ffname); - if (p == NULL) { - // not found, append at the end - p = p_rtp + STRLEN(p_rtp); - } else { - // append after the matching directory. - p += STRLEN(ffname); - } - *p4 = c; - - if (load_file) { - c = *p2; - *p2 = NUL; - } if (strstr((char *)p_rtp, (char *)ffname) == NULL) { // directory not in 'runtimepath', add it + p4 = p3 = p2 = p1 = get_past_head(ffname); + for (p = p1; *p; mb_ptr_adv(p)) { + if (vim_ispathsep_nocolon(*p)) { + p4 = p3; p3 = p2; p2 = p1; p1 = p; + } + } + + // now we have: + // rtp/pack/name/ever/name + // p4 p3 p2 p1 + // + // find the part up to "pack" in 'runtimepath' + char_u c = *p4; + *p4 = NUL; + char_u *insp = (char_u *)strstr((char *)p_rtp, (char *)ffname); + if (insp == NULL) { + // not found, append at the end + insp = p_rtp + STRLEN(p_rtp); + } else { + // append after the matching directory. + insp += STRLEN(ffname); + while (*insp != NUL && *insp != ',') { + insp++; + } + } + *p4 = c; + size_t oldlen = STRLEN(p_rtp); size_t addlen = STRLEN(ffname); new_rtp = try_malloc(oldlen + addlen + 1); if (new_rtp == NULL) { - *p2 = c; - return; + goto theend; } - uintptr_t keep = (uintptr_t)(p - p_rtp); + uintptr_t keep = (uintptr_t)(insp - p_rtp); memmove(new_rtp, p_rtp, keep); new_rtp[keep] = ','; memmove(new_rtp + keep + 1, ffname, addlen + 1); @@ -2461,39 +2452,44 @@ static void add_pack_plugin(char_u *fname, void *cookie) set_option_value((char_u *)"rtp", 0L, new_rtp, 0); xfree(new_rtp); } - xfree(ffname); - if (load_file) { - (void)do_source(fname, false, DOSO_NONE); - } -} + if (load_files) { + static const char *plugpat = "%s/plugin/*.vim"; + static const char *ftpat = "%s/ftdetect/*.vim"; -// Source the plugins in the package directories. -void source_packages(void) -{ - do_in_path(p_pp, (char_u *)"pack/*/ever/*/plugin/*.vim", - DIP_ALL, add_pack_plugin, p_pp); - may_do_filetypes((char_u *)"pack/*/ever/*/ftdetect/*.vim"); -} + size_t len = STRLEN(ffname) + STRLEN(ftpat); + char_u *pat = try_malloc(len + 1); + if (pat == NULL) { + goto theend; + } + vim_snprintf((char *)pat, len, plugpat, ffname); + source_all_matches(pat); -// ":loadplugin {name}" -void ex_loadplugin(exarg_T *eap) -{ - static const char *plugpat = "pack/*/opt/%s/plugin/*.vim"; - static const char *ftpat = "pack/*/opt/%s/ftdetect/*.vim"; + char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes"); - size_t len = STRLEN(ftpat) + STRLEN(eap->arg); - char *pat = xmallocz(len); - vim_snprintf(pat, len, plugpat, eap->arg); - do_in_path(p_pp, (char_u *)pat, DIP_ALL, add_pack_plugin, p_pp); + // If runtime/filetype.vim wasn't loaded yet, the scripts will be + // found when it loads. + if (eval_to_number(cmd) > 0) { + do_cmdline_cmd("augroup filetypedetect"); + vim_snprintf((char *)pat, len, ftpat, ffname); + source_all_matches(pat); + do_cmdline_cmd("augroup END"); + } + xfree(cmd); + } - vim_snprintf(pat, len, ftpat, eap->arg); - may_do_filetypes((char_u *)pat); +theend: + xfree(ffname); +} - xfree(pat); +// Find plugins in the package directories and source them. +void source_packages(void) +{ + do_in_path(p_pp, (char_u *)"pack/*/ever/*", DIP_ALL + DIP_DIR, + add_pack_plugin, p_pp); } -/// ":packadd {name}" +/// ":packadd[!] {name}" void ex_packadd(exarg_T *eap) { static const char *plugpat = "pack/*/opt/%s"; @@ -2501,7 +2497,8 @@ void ex_packadd(exarg_T *eap) size_t len = STRLEN(plugpat) + STRLEN(eap->arg); char *pat = (char *)xmallocz(len); vim_snprintf(pat, len, plugpat, eap->arg); - do_in_path(p_pp, (char_u *)pat, DIP_ALL + DIP_DIR, add_pack_plugin, NULL); + do_in_path(p_pp, (char_u *)pat, DIP_ALL + DIP_DIR, add_pack_plugin, + eap->forceit ? NULL : p_pp); xfree(pat); } diff --git a/src/nvim/version.c b/src/nvim/version.c index 4320190592..569a755429 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -209,7 +209,7 @@ static int included_patches[] = { // 1489 NA // 1488 NA // 1487 NA - // 1486, + 1486, // 1485 NA // 1484 NA // 1483 NA diff --git a/test/functional/legacy/loadplugin_spec.lua b/test/functional/legacy/packadd_spec.lua index af97db3ae5..94b5336b9f 100644 --- a/test/functional/legacy/loadplugin_spec.lua +++ b/test/functional/legacy/packadd_spec.lua @@ -1,4 +1,4 @@ --- Tests for :loadplugin +-- Tests for 'packpath' and :packadd local helpers = require('test.functional.helpers')(after_each) local clear, source = helpers.clear, helpers.source @@ -8,8 +8,8 @@ local function expected_empty() eq({}, nvim.get_vvar('errors')) end -describe('loadplugin', function() - setup(function() +describe('packadd', function() + before_each(function() clear() source([=[ @@ -23,7 +23,7 @@ describe('loadplugin', function() call delete(s:topdir, 'rf') endfunc - func Test_loadplugin() + func Test_packadd() call mkdir(s:plugdir . '/plugin', 'p') call mkdir(s:plugdir . '/ftdetect', 'p') set rtp& @@ -38,7 +38,7 @@ describe('loadplugin', function() call setline(1, 'let g:ftdetect_works = 17') wq - loadplugin mytest + packadd mytest call assert_true(42, g:plugin_works) call assert_true(17, g:ftdetect_works) @@ -46,34 +46,43 @@ describe('loadplugin', function() call assert_true(&rtp =~ (s:plugdir . '\($\|,\)')) endfunc - func Test_packadd() + func Test_packadd_noload() + call mkdir(s:plugdir . '/plugin', 'p') call mkdir(s:plugdir . '/syntax', 'p') set rtp& let rtp = &rtp - packadd mytest + + exe 'split ' . s:plugdir . '/plugin/test.vim' + call setline(1, 'let g:plugin_works = 42') + wq + let g:plugin_works = 0 + + packadd! mytest + call assert_true(len(&rtp) > len(rtp)) call assert_true(&rtp =~ (s:plugdir . '\($\|,\)')) + call assert_equal(0, g:plugin_works) " check the path is not added twice let new_rtp = &rtp - packadd mytest + packadd! mytest call assert_equal(new_rtp, &rtp) endfunc ]=]) call('SetUp') end) - teardown(function() + after_each(function() call('TearDown') end) it('is working', function() - call('Test_loadplugin') + call('Test_packadd') expected_empty() end) - it('works with packadd', function() - call('Test_packadd') + it('works with packadd!', function() + call('Test_packadd_noload') expected_empty() end) end) |