aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_getln.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2016-07-09 06:58:27 -0400
committerGitHub <noreply@github.com>2016-07-09 06:58:27 -0400
commitadaacdd71a70b76bc686113eaece47a6264701a5 (patch)
tree4be6079a8571316cbd89e3f310981b080f2815a4 /src/nvim/ex_getln.c
parent6cee9d1a17177f4ccdf34283c6ed3ffaa98b32cc (diff)
parent059e9785dc2fea0a15344162de4a5a7c8da6f491 (diff)
downloadrneovim-adaacdd71a70b76bc686113eaece47a6264701a5.tar.gz
rneovim-adaacdd71a70b76bc686113eaece47a6264701a5.tar.bz2
rneovim-adaacdd71a70b76bc686113eaece47a6264701a5.zip
Merge #4648 from jamessan/packages
packages (vim-patch:7.4.{1384,1388,1396,1478,1479,1480,1486,1492,1499,1528,1550,1551,1552,1553,1554,1596,1649,1712,1840,1973,1986})
Diffstat (limited to 'src/nvim/ex_getln.c')
-rw-r--r--src/nvim/ex_getln.c96
1 files changed, 81 insertions, 15 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 65144dace8..cd28554970 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -3440,6 +3440,7 @@ addstar (
|| context == EXPAND_COMPILER
|| context == EXPAND_OWNSYNTAX
|| context == EXPAND_FILETYPE
+ || context == EXPAND_PACKADD
|| (context == EXPAND_TAGS && fname[0] == '/'))
retval = vim_strnsave(fname, len);
else {
@@ -3794,23 +3795,27 @@ ExpandFromContext (
|| xp->xp_context == EXPAND_TAGS_LISTFILES)
return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file);
if (xp->xp_context == EXPAND_COLORS) {
- char *directories[] = {"colors", NULL};
- return ExpandRTDir(pat, num_file, file, directories);
+ char *directories[] = { "colors", NULL };
+ return ExpandRTDir(pat, DIP_START + DIP_OPT, num_file, file, directories);
}
if (xp->xp_context == EXPAND_COMPILER) {
- char *directories[] = {"compiler", NULL};
- return ExpandRTDir(pat, num_file, file, directories);
+ char *directories[] = { "compiler", NULL };
+ return ExpandRTDir(pat, 0, num_file, file, directories);
}
if (xp->xp_context == EXPAND_OWNSYNTAX) {
- char *directories[] = {"syntax", NULL};
- return ExpandRTDir(pat, num_file, file, directories);
+ char *directories[] = { "syntax", NULL };
+ return ExpandRTDir(pat, 0, num_file, file, directories);
}
if (xp->xp_context == EXPAND_FILETYPE) {
- char *directories[] = {"syntax", "indent", "ftplugin", NULL};
- return ExpandRTDir(pat, num_file, file, directories);
+ char *directories[] = { "syntax", "indent", "ftplugin", NULL };
+ return ExpandRTDir(pat, 0, num_file, file, directories);
}
- if (xp->xp_context == EXPAND_USER_LIST)
+ if (xp->xp_context == EXPAND_USER_LIST) {
return ExpandUserList(xp, num_file, file);
+ }
+ if (xp->xp_context == EXPAND_PACKADD) {
+ return ExpandPackAddDir(pat, num_file, file);
+ }
regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
if (regmatch.regprog == NULL)
@@ -4190,12 +4195,16 @@ static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file)
return OK;
}
-/*
- * Expand color scheme, compiler or filetype names:
- * 'runtimepath'/{dirnames}/{pat}.vim
- * "dirnames" is an array with one or more directory names.
- */
-static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirnames[])
+/// Expand color scheme, compiler or filetype names.
+/// Search from 'runtimepath':
+/// 'runtimepath'/{dirnames}/{pat}.vim
+/// When "flags" has DIP_START: search also from 'start' of 'packpath':
+/// 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim
+/// When "flags" has DIP_OPT: search also from 'opt' of 'packpath':
+/// 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim
+/// "dirnames" is an array with one or more directory names.
+static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file,
+ char *dirnames[])
{
*num_file = 0;
*file = NULL;
@@ -4212,6 +4221,26 @@ static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname
xfree(s);
}
+ if (flags & DIP_START) {
+ 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, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT
+ globpath(p_pp, s, &ga, 0);
+ xfree(s);
+ }
+ }
+
+ if (flags & DIP_OPT) {
+ 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, "pack/*/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++) {
char_u *match = ((char_u **)ga.ga_data)[i];
char_u *s = match;
@@ -4241,6 +4270,43 @@ static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname
return OK;
}
+/// Expand loadplugin names:
+/// 'packpath'/pack/ * /opt/{pat}
+static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file)
+{
+ garray_T ga;
+
+ *num_file = 0;
+ *file = NULL;
+ size_t pat_len = STRLEN(pat);
+ ga_init(&ga, (int)sizeof(char *), 10);
+
+ size_t buflen = pat_len + 26;
+ char_u *s = xmalloc(buflen);
+ snprintf((char *)s, buflen, "pack/*/opt/%s*", pat); // NOLINT
+ globpath(p_pp, s, &ga, 0);
+ xfree(s);
+
+ for (int i = 0; i < ga.ga_len; i++) {
+ char_u *match = ((char_u **)ga.ga_data)[i];
+ s = path_tail(match);
+ char_u *e = s + STRLEN(s);
+ memmove(match, s, e - s + 1);
+ }
+
+ if (GA_EMPTY(&ga)) {
+ return FAIL;
+ }
+
+ // Sort and remove duplicates which can happen when specifying multiple
+ // directories in dirnames.
+ ga_remove_duplicate_strings(&ga);
+
+ *file = ga.ga_data;
+ *num_file = ga.ga_len;
+ return OK;
+}
+
/// Expand `file` for all comma-separated directories in `path`.
/// Adds matches to `ga`.