diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 1 | ||||
-rw-r--r-- | src/nvim/ex_cmds.lua | 6 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 115 | ||||
-rw-r--r-- | src/nvim/main.c | 3 | ||||
-rw-r--r-- | src/nvim/option.c | 1 | ||||
-rw-r--r-- | src/nvim/option_defs.h | 1 | ||||
-rw-r--r-- | src/nvim/options.lua | 10 | ||||
-rw-r--r-- | src/nvim/version.c | 2 |
8 files changed, 119 insertions, 20 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 9a86c5765c..d2b9bf66e1 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10782,6 +10782,7 @@ static void f_has(typval_T *argvars, typval_T *rettv) "mouse", "multi_byte", "multi_lang", + "packages", "path_extra", "persistent_undo", "postscript", diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua index 6c58879d58..7bfb592ea7 100644 --- a/src/nvim/ex_cmds.lua +++ b/src/nvim/ex_cmds.lua @@ -1453,6 +1453,12 @@ 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 40074f726c..d5740e224b 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2284,21 +2284,9 @@ int source_runtime(char_u *name, int all) return do_in_runtimepath(name, all, source_callback, NULL); } -/// Find "name" in 'runtimepath'. When found, invoke the callback function for -/// it: callback(fname, "cookie") -/// When "all" is true repeat for all matches, otherwise only the first one is -/// used. -/// Returns OK when at least one match found, FAIL otherwise. -/// If "name" is NULL calls callback for each entry in runtimepath. Cookie is -/// passed by reference in this case, setting it to NULL indicates that callback -/// has done its job. -int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback, - void *cookie) +static int do_in_path(char_u *path, char_u *name, bool all, + DoInRuntimepathCB callback, void *cookie) { - char_u *rtp; - char_u *np; - char_u *buf; - char_u *rtp_copy; char_u *tail; int num_files; char_u **files; @@ -2307,18 +2295,18 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback, // Make a copy of 'runtimepath'. Invoking the callback may change the // value. - rtp_copy = vim_strsave(p_rtp); - buf = xmallocz(MAXPATHL); + char_u *rtp_copy = vim_strsave(path); + char_u *buf = xmallocz(MAXPATHL); { if (p_verbose > 1 && name != NULL) { verbose_enter(); smsg(_("Searching for \"%s\" in \"%s\""), - (char *)name, (char *)p_rtp); + (char *)name, (char *)path); verbose_leave(); } // Loop over all entries in 'runtimepath'. - rtp = rtp_copy; + char_u *rtp = rtp_copy; while (*rtp != NUL && (all || !did_one)) { // Copy the path from 'runtimepath' to buf[]. copy_option_part(&rtp, buf, MAXPATHL, ","); @@ -2332,7 +2320,7 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback, tail = buf + STRLEN(buf); // Loop over all patterns in "name" - np = name; + char_u *np = name; while (*np != NUL && (all || !did_one)) { // Append the pattern from "name" to buf[]. assert(MAXPATHL >= (tail - buf)); @@ -2373,6 +2361,95 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback, return did_one ? OK : FAIL; } +/// Find "name" in 'runtimepath'. When found, invoke the callback function for +/// it: callback(fname, "cookie") +/// When "all" is true repeat for all matches, otherwise only the first one is +/// used. +/// Returns OK when at least one match found, FAIL otherwise. +/// If "name" is NULL calls callback for each entry in runtimepath. Cookie is +/// passed by reference in this case, setting it to NULL indicates that callback +/// has done its job. +int do_in_runtimepath(char_u *name, bool all, DoInRuntimepathCB callback, + void *cookie) +{ + return do_in_path(p_rtp, name, all, callback, cookie); +} + +static void source_pack_plugin(char_u *fname, void *cookie) +{ + char_u *p6, *p5, *p4, *p3, *p2, *p1, *p; + char_u *new_rtp; + + p4 = p3 = p2 = p1 = get_past_head(fname); + 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: + // rtp/pack/name/ever/name/plugin/name.vim + // p6 p5 p4 p3 p2 p1 + + // find the part up to "pack" in 'runtimepath' + char_u c = *p6; + *p6 = NUL; + p = (char_u *)strstr((char *)p_rtp, (char *)fname); + if (p == NULL) { + // not found, append at the end + p = p_rtp + STRLEN(p_rtp); + } else { + // append after the matching directory. + p += STRLEN(fname); + } + *p6 = c; + + c = *p2; + *p2 = NUL; + if (strstr((char *)p_rtp, (char *)fname) == NULL) { + // directory not in 'runtimepath', add it + size_t oldlen = STRLEN(p_rtp); + size_t addlen = STRLEN(fname); + new_rtp = try_malloc(oldlen + addlen + 1); + if (new_rtp == NULL) { + *p2 = c; + return; + } + uintptr_t keep = (uintptr_t)(p - p_rtp); + memmove(new_rtp, p_rtp, keep); + new_rtp[keep] = ','; + memmove(new_rtp + keep + 1, fname, addlen + 1); + if (p_rtp[keep] != NUL) { + memmove(new_rtp + keep + 1 + addlen, p_rtp + keep, + oldlen - keep + 1); + } + free_string_option(p_rtp); + p_rtp = new_rtp; + } + *p2 = c; + + (void)do_source(fname, false, DOSO_NONE); +} + +// Source the plugins in the package directories. +void source_packages(void) +{ + do_in_path(p_pp, (char_u *)"pack/*/ever/*/plugin/*.vim", + true, source_pack_plugin, NULL); +} + +// ":loadplugin {name}" +void ex_loadplugin(exarg_T *eap) +{ + static const char *pattern = "pack/*/opt/%s/plugin/*.vim"; + + size_t len = STRLEN(pattern) + STRLEN(eap->arg); + char *pat = xmallocz(len); + vim_snprintf(pat, len, pattern, eap->arg); + do_in_path(p_pp, (char_u *)pat, true, source_pack_plugin, NULL); + xfree(pat); +} + /// ":options" void ex_options(exarg_T *eap) { diff --git a/src/nvim/main.c b/src/nvim/main.c index 5cd1dbb467..dcfd9b0fdf 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1243,6 +1243,9 @@ static void load_plugins(void) if (p_lpl) { source_runtime((char_u *)"plugin/**/*.vim", TRUE); TIME_MSG("loading plugins"); + + source_packages(); + TIME_MSG("loading packages"); } } diff --git a/src/nvim/option.c b/src/nvim/option.c index a844c4ed80..be3cb914b2 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5839,6 +5839,7 @@ set_context_in_set_cmd ( if (p == (char_u *)&p_bdir || p == (char_u *)&p_dir || p == (char_u *)&p_path + || p == (char_u *)&p_pp || p == (char_u *)&p_rtp || p == (char_u *)&p_cdpath || p == (char_u *)&p_vdir diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index b1a2b00bdb..833da7907c 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -521,6 +521,7 @@ EXTERN int p_ari; /* 'allowrevins' */ EXTERN int p_ri; /* 'revins' */ EXTERN int p_ru; /* 'ruler' */ EXTERN char_u *p_ruf; /* 'rulerformat' */ +EXTERN char_u *p_pp; /* 'packpath' */ EXTERN char_u *p_rtp; /* 'runtimepath' */ EXTERN long p_sj; /* 'scrolljump' */ EXTERN long p_so; /* 'scrolloff' */ diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 218e34f595..d19af4f73f 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -1640,6 +1640,16 @@ return { defaults={if_true={vi=""}} }, { + full_name='packpath', abbreviation='pp', + type='string', list='onecomma', scope={'global'}, + deny_duplicates=true, + secure=true, + vi_def=true, + expand=true, + varname='p_pp', + defaults={if_true={vi=''}} + }, + { full_name='paragraphs', abbreviation='para', type='string', scope={'global'}, vi_def=true, diff --git a/src/nvim/version.c b/src/nvim/version.c index 278255c904..95f924d6a1 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -311,7 +311,7 @@ static int included_patches[] = { // 1387 NA // 1386 NA // 1385 NA - // 1384, + 1384, // 1383 NA // 1382 NA // 1381 NA |