diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2020-11-18 20:02:44 +0100 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2020-11-19 14:31:07 +0100 |
commit | a119fe15da28b166ffef6bf34067e5a7f75bbca9 (patch) | |
tree | dfbaad7525ebd9cb6e8ca9317efa2ce09d4e9a2a | |
parent | 569e5c86bfd7e7729229030fc2045c624e5f33c4 (diff) | |
download | rneovim-a119fe15da28b166ffef6bf34067e5a7f75bbca9.tar.gz rneovim-a119fe15da28b166ffef6bf34067e5a7f75bbca9.tar.bz2 rneovim-a119fe15da28b166ffef6bf34067e5a7f75bbca9.zip |
startup: load files from &packpath . '/start/{pluginname}'
Quoting the existing docs:
Packages are loaded. These are plugins, as above [&runtimepath], 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.
Also tj didn't think I could do it.
-rw-r--r-- | src/nvim/ex_cmds2.c | 26 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 19 | ||||
-rw-r--r-- | test/functional/core/startup_spec.lua | 25 | ||||
-rw-r--r-- | test/functional/fixtures/start/nvim-leftpad/autoload/leftpad.vim | 3 | ||||
-rw-r--r-- | test/functional/fixtures/start/nvim-leftpad/lua/leftpad.lua | 1 |
5 files changed, 71 insertions, 3 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 713d18b44d..42454b7c9a 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2551,6 +2551,17 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags, done = do_in_path(p_pp, s, flags, callback, cookie); xfree(s); + + if (done == FAIL|| (flags & DIP_ALL)) { + start_dir = "start/*/%s"; // NOLINT + len = STRLEN(start_dir) + STRLEN(name); + s = xmallocz(len); + + vim_snprintf((char *)s, len, start_dir, name); + done = do_in_path(p_pp, s, flags, callback, cookie); + + xfree(s); + } } if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_OPT)) { @@ -2562,6 +2573,17 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags, done = do_in_path(p_pp, s, flags, callback, cookie); xfree(s); + + if (done == FAIL || (flags & DIP_ALL)) { + opt_dir = "opt/*/%s"; // NOLINT + len = STRLEN(opt_dir) + STRLEN(name); + s = xmallocz(len); + + vim_snprintf((char *)s, len, opt_dir, name); + done = do_in_path(p_pp, s, flags, callback, cookie); + + xfree(s); + } } return done; @@ -2822,6 +2844,8 @@ void add_pack_start_dirs(void) { do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, // NOLINT add_pack_plugin, &APP_ADD_DIR); + do_in_path(p_pp, (char_u *)"start/*", DIP_ALL + DIP_DIR, // NOLINT + add_pack_plugin, &APP_ADD_DIR); } /// Load plugins from all packages in the "start" directory. @@ -2830,6 +2854,8 @@ void load_start_packages(void) did_source_packages = true; do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, // NOLINT add_pack_plugin, &APP_LOAD); + do_in_path(p_pp, (char_u *)"start/*", DIP_ALL + DIP_DIR, // NOLINT + add_pack_plugin, &APP_LOAD); } // ":packloadall" diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 9edb826ea6..0100be15bc 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -5533,6 +5533,7 @@ static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, garray_T ga; ga_init(&ga, (int)sizeof(char *), 10); + // TODO(bfredl): this is bullshit, exandpath should not reinvent path logic. for (int i = 0; dirnames[i] != NULL; i++) { size_t size = STRLEN(dirnames[i]) + pat_len + 7; char_u *s = xmalloc(size); @@ -5549,6 +5550,14 @@ static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, globpath(p_pp, s, &ga, 0); xfree(s); } + + for (int i = 0; dirnames[i] != NULL; i++) { + size_t size = STRLEN(dirnames[i]) + pat_len + 22; + char_u *s = xmalloc(size); + snprintf((char *)s, size, "start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT + globpath(p_pp, s, &ga, 0); + xfree(s); + } } if (flags & DIP_OPT) { @@ -5559,6 +5568,14 @@ static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, globpath(p_pp, s, &ga, 0); xfree(s); } + + for (int i = 0; dirnames[i] != NULL; i++) { + size_t size = STRLEN(dirnames[i]) + pat_len + 20; + char_u *s = xmalloc(size); + snprintf((char *)s, size, "opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT + globpath(p_pp, s, &ga, 0); + xfree(s); + } } for (int i = 0; i < ga.ga_len; i++) { @@ -5606,6 +5623,8 @@ static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file) char_u *s = xmalloc(buflen); snprintf((char *)s, buflen, "pack/*/opt/%s*", pat); // NOLINT globpath(p_pp, s, &ga, 0); + snprintf((char *)s, buflen, "opt/%s*", pat); // NOLINT + globpath(p_pp, s, &ga, 0); xfree(s); for (int i = 0; i < ga.ga_len; i++) { diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 3bfae5f3d7..27793ab936 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -313,14 +313,33 @@ describe('startup', function() it("handles &packpath during startup", function() - pack_clear [[ let g:x = bar#test() ]] + pack_clear [[ + let g:x = bar#test() + let g:y = leftpad#pad("heyya") + ]] eq(-3, eval 'g:x') + eq(" heyya", eval 'g:y') - pack_clear [[ lua _G.y = require'bar'.doit() ]] - eq(9003, exec_lua [[ return _G.y ]]) + pack_clear [[ lua _G.y = require'bar'.doit() _G.z = require'leftpad''howdy' ]] + eq({9003, '\thowdy'}, exec_lua [[ return { _G.y, _G.z } ]]) end) it("handles :packadd during startup", function() + -- control group: opt/bonus is not availabe by default + pack_clear [[ + try + let g:x = bonus#secret() + catch + let g:err = v:exception + endtry + ]] + eq('Vim(let):E117: Unknown function: bonus#secret', eval 'g:err') + + pack_clear [[ lua _G.test = {pcall(function() require'bonus'.launch() end)} ]] + eq({false, [[[string ":lua"]:1: module 'bonus' not found:]]}, + exec_lua [[ _G.test[2] = string.gsub(_G.test[2], '[\r\n].*', '') return _G.test ]]) + + -- ok, time to launch the nukes: pack_clear [[ packadd! bonus | let g:x = bonus#secret() ]] eq('halloj', eval 'g:x') diff --git a/test/functional/fixtures/start/nvim-leftpad/autoload/leftpad.vim b/test/functional/fixtures/start/nvim-leftpad/autoload/leftpad.vim new file mode 100644 index 0000000000..2f428f59e0 --- /dev/null +++ b/test/functional/fixtures/start/nvim-leftpad/autoload/leftpad.vim @@ -0,0 +1,3 @@ +function! leftpad#pad(str) + return ' '.a:str +endfunction diff --git a/test/functional/fixtures/start/nvim-leftpad/lua/leftpad.lua b/test/functional/fixtures/start/nvim-leftpad/lua/leftpad.lua new file mode 100644 index 0000000000..866ed2fd30 --- /dev/null +++ b/test/functional/fixtures/start/nvim-leftpad/lua/leftpad.lua @@ -0,0 +1 @@ +return function (str) return '\t' .. str end |