summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@acermirko.emind.lan>2023-01-21 21:56:06 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-21 21:56:06 +0000
commita6759381a590b2d395e05b109ca9ccfc356be5a8 (patch)
tree10c853b311f065148c4b707f052e569677e3e818
parent51b2fc2ef5183487dc1acd9f526e904e5bda7814 (diff)
patch 9.0.1227: no cmdline completion for :runtimev9.0.1227
Problem: No cmdline completion for :runtime. Solution: Add completion for :runtime. (closes #11853, closes #11447) Improve the resulting matches.
-rw-r--r--src/cmdexpand.c13
-rw-r--r--src/scriptfile.c80
-rw-r--r--src/testdir/test_cmdline.vim9
-rw-r--r--src/usercmd.c1
-rw-r--r--src/version.c2
-rw-r--r--src/vim.h2
6 files changed, 94 insertions, 13 deletions
diff --git a/src/cmdexpand.c b/src/cmdexpand.c
index 5a47f6a24a..4fe9bd35bc 100644
--- a/src/cmdexpand.c
+++ b/src/cmdexpand.c
@@ -56,6 +56,7 @@ cmdline_fuzzy_completion_supported(expand_T *xp)
&& xp->xp_context != EXPAND_OLD_SETTING
&& xp->xp_context != EXPAND_OWNSYNTAX
&& xp->xp_context != EXPAND_PACKADD
+ && xp->xp_context != EXPAND_RUNTIME
&& xp->xp_context != EXPAND_SHELLCMD
&& xp->xp_context != EXPAND_TAGS
&& xp->xp_context != EXPAND_TAGS_LISTFILES
@@ -1362,6 +1363,7 @@ addstar(
// For a tag pattern starting with "/" no translation is needed.
if (context == EXPAND_HELP
|| context == EXPAND_COLORS
+ || context == EXPAND_RUNTIME
|| context == EXPAND_COMPILER
|| context == EXPAND_OWNSYNTAX
|| context == EXPAND_FILETYPE
@@ -2312,6 +2314,11 @@ set_context_by_cmdname(
xp->xp_pattern = arg;
break;
+ case CMD_runtime:
+ xp->xp_context = EXPAND_RUNTIME;
+ xp->xp_pattern = arg;
+ break;
+
case CMD_compiler:
xp->xp_context = EXPAND_COMPILER;
xp->xp_pattern = arg;
@@ -3019,6 +3026,12 @@ ExpandFromContext(
return ExpandRTDir(pat, DIP_START + DIP_OPT, numMatches, matches,
directories);
}
+ if (xp->xp_context == EXPAND_RUNTIME)
+ {
+ char *directories[] = {"", NULL};
+ return ExpandRTDir(pat, DIP_START + DIP_OPT + DIP_PRNEXT, numMatches,
+ matches, directories);
+ }
if (xp->xp_context == EXPAND_COMPILER)
{
char *directories[] = {"compiler", NULL};
diff --git a/src/scriptfile.c b/src/scriptfile.c
index b5a381cff3..3404c22d1a 100644
--- a/src/scriptfile.c
+++ b/src/scriptfile.c
@@ -990,18 +990,34 @@ ExpandRTDir(
for (i = 0; dirnames[i] != NULL; ++i)
{
- s = alloc(STRLEN(dirnames[i]) + pat_len + 7);
- if (s == NULL)
+ size_t buflen = STRLEN(dirnames[i]) + pat_len * 2 + 17;
+ char_u *buf = alloc(buflen);
+ if (buf == NULL)
{
ga_clear_strings(&ga);
return FAIL;
}
- sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat);
- globpath(p_rtp, s, &ga, 0);
- vim_free(s);
+ if (*(dirnames[i]) == NUL)
+ {
+ // empty dir used for :runtime
+ if (gettail(pat) == pat)
+ // no path separator, match dir names and script files
+ vim_snprintf((char *)buf, buflen, "\\(%s*.vim\\)\\|\\(%s*\\)",
+ pat, pat);
+ else
+ // has path separator, match script files
+ vim_snprintf((char *)buf, buflen, "%s*.vim", pat);
+ }
+ else
+ {
+ vim_snprintf((char *)buf, buflen, "%s/%s*.vim", dirnames[i], pat);
+ }
+ globpath(p_rtp, buf, &ga, 0);
+ vim_free(buf);
}
- if (flags & DIP_START) {
+ if (flags & DIP_START)
+ {
for (i = 0; dirnames[i] != NULL; ++i)
{
s = alloc(STRLEN(dirnames[i]) + pat_len + 22);
@@ -1016,7 +1032,8 @@ ExpandRTDir(
}
}
- if (flags & DIP_OPT) {
+ if (flags & DIP_OPT)
+ {
for (i = 0; dirnames[i] != NULL; ++i)
{
s = alloc(STRLEN(dirnames[i]) + pat_len + 20);
@@ -1036,15 +1053,52 @@ ExpandRTDir(
match = ((char_u **)ga.ga_data)[i];
s = match;
e = s + STRLEN(s);
+ char_u *res_start = s;
+ if ((flags & DIP_PRNEXT) != 0)
+ {
+ char_u *p = (char_u *)strstr((char *)match, (char *)pat);
+ if (p != NULL)
+ // Drop what comes before "pat" in the match, so that for
+ // match "/long/path/syntax/cpp.vim" with pattern
+ // "syntax/cp" we only keep "syntax/cpp.vim".
+ res_start = p;
+ }
+
if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0)
{
- e -= 4;
- for (s = e; s > match; MB_PTR_BACK(match, s))
- if (s < match || vim_ispathsep(*s))
- break;
- ++s;
+ if (res_start == s)
+ {
+ // Only keep the file name.
+ // Remove file ext only if flag DIP_PRNEXT is not present.
+ if ((flags & DIP_PRNEXT) == 0)
+ e -= 4;
+ for (s = e; s > match; MB_PTR_BACK(match, s))
+ {
+ if (s < match)
+ break;
+ if (vim_ispathsep(*s))
+ {
+ res_start = s + 1;
+ break;
+ }
+ }
+ }
+
*e = NUL;
- mch_memmove(match, s, e - s + 1);
+ }
+
+ if (res_start > match)
+ mch_memmove(match, res_start, e - res_start + 1);
+
+ // remove entries that look like backup files
+ if (e > s && e[-1] == '~')
+ {
+ vim_free(match);
+ char_u **fnames = (char_u **)ga.ga_data;
+ for (int j = i + 1; j < ga.ga_len; ++j)
+ fnames[j - 1] = fnames[j];
+ --ga.ga_len;
+ --i;
}
}
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index 9eca9186fa..9406a7eac4 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -552,6 +552,15 @@ func Test_getcompletion()
call assert_true(index(l, '<buffer>') >= 0)
let l = getcompletion('not', 'mapclear')
call assert_equal([], l)
+
+ let l = getcompletion('', 'runtime')
+ call assert_true(index(l, 'defaults.vim') >= 0)
+ let l = getcompletion('synt', 'runtime')
+ call assert_true(index(l, 'syntax') >= 0)
+ let l = getcompletion('syntax/vi', 'runtime')
+ call assert_true(index(l, 'syntax/vim.vim') >= 0)
+ let l = getcompletion('notexitsts', 'runtime')
+ call assert_equal([], l)
let l = getcompletion('.', 'shellcmd')
call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
diff --git a/src/usercmd.c b/src/usercmd.c
index 3bd6fd536f..9dcc20e7f4 100644
--- a/src/usercmd.c
+++ b/src/usercmd.c
@@ -86,6 +86,7 @@ static struct
#endif
{EXPAND_SETTINGS, "option"},
{EXPAND_PACKADD, "packadd"},
+ {EXPAND_RUNTIME, "runtime"},
{EXPAND_SHELLCMD, "shellcmd"},
#if defined(FEAT_SIGNS)
{EXPAND_SIGN, "sign"},
diff --git a/src/version.c b/src/version.c
index 73211b6a5a..ebcd70ff35 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1227,
+/**/
1226,
/**/
1225,
diff --git a/src/vim.h b/src/vim.h
index 7d58b06a36..930b17b104 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -811,6 +811,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
#define EXPAND_DISASSEMBLE 50
#define EXPAND_BREAKPOINT 51
#define EXPAND_SCRIPTNAMES 52
+#define EXPAND_RUNTIME 53
// Values for exmode_active (0 is no exmode)
#define EXMODE_NORMAL 1
@@ -2661,6 +2662,7 @@ typedef enum {
#define DIP_NORTP 0x20 // do not use 'runtimepath'
#define DIP_NOAFTER 0x40 // skip "after" directories
#define DIP_AFTER 0x80 // only use "after" directories
+#define DIP_PRNEXT 0x100 // for print also file extension
// Lowest number used for window ID. Cannot have this many windows.
#define LOWEST_WIN_ID 1000