Problem: No cmdline completion for :runtime.
Solution: Add completion for :runtime. (closes #11853, closes #11447)
Improve the resulting matches.
&& 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
// 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
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;
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};
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);
}
}
- if (flags & DIP_OPT) {
+ if (flags & DIP_OPT)
+ {
for (i = 0; dirnames[i] != NULL; ++i)
{
s = alloc(STRLEN(dirnames[i]) + pat_len + 20);
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;
}
}
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 =~ "\\./"'))
#endif
{EXPAND_SETTINGS, "option"},
{EXPAND_PACKADD, "packadd"},
+ {EXPAND_RUNTIME, "runtime"},
{EXPAND_SHELLCMD, "shellcmd"},
#if defined(FEAT_SIGNS)
{EXPAND_SIGN, "sign"},
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1227,
/**/
1226,
/**/
#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
#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