mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 9.0.1227: no cmdline completion for :runtime
Problem: No cmdline completion for :runtime. Solution: Add completion for :runtime. (closes #11853, closes #11447) Improve the resulting matches.
This commit is contained in:
@@ -56,6 +56,7 @@ cmdline_fuzzy_completion_supported(expand_T *xp)
|
|||||||
&& xp->xp_context != EXPAND_OLD_SETTING
|
&& xp->xp_context != EXPAND_OLD_SETTING
|
||||||
&& xp->xp_context != EXPAND_OWNSYNTAX
|
&& xp->xp_context != EXPAND_OWNSYNTAX
|
||||||
&& xp->xp_context != EXPAND_PACKADD
|
&& xp->xp_context != EXPAND_PACKADD
|
||||||
|
&& xp->xp_context != EXPAND_RUNTIME
|
||||||
&& xp->xp_context != EXPAND_SHELLCMD
|
&& xp->xp_context != EXPAND_SHELLCMD
|
||||||
&& xp->xp_context != EXPAND_TAGS
|
&& xp->xp_context != EXPAND_TAGS
|
||||||
&& xp->xp_context != EXPAND_TAGS_LISTFILES
|
&& xp->xp_context != EXPAND_TAGS_LISTFILES
|
||||||
@@ -1362,6 +1363,7 @@ addstar(
|
|||||||
// For a tag pattern starting with "/" no translation is needed.
|
// For a tag pattern starting with "/" no translation is needed.
|
||||||
if (context == EXPAND_HELP
|
if (context == EXPAND_HELP
|
||||||
|| context == EXPAND_COLORS
|
|| context == EXPAND_COLORS
|
||||||
|
|| context == EXPAND_RUNTIME
|
||||||
|| context == EXPAND_COMPILER
|
|| context == EXPAND_COMPILER
|
||||||
|| context == EXPAND_OWNSYNTAX
|
|| context == EXPAND_OWNSYNTAX
|
||||||
|| context == EXPAND_FILETYPE
|
|| context == EXPAND_FILETYPE
|
||||||
@@ -2312,6 +2314,11 @@ set_context_by_cmdname(
|
|||||||
xp->xp_pattern = arg;
|
xp->xp_pattern = arg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CMD_runtime:
|
||||||
|
xp->xp_context = EXPAND_RUNTIME;
|
||||||
|
xp->xp_pattern = arg;
|
||||||
|
break;
|
||||||
|
|
||||||
case CMD_compiler:
|
case CMD_compiler:
|
||||||
xp->xp_context = EXPAND_COMPILER;
|
xp->xp_context = EXPAND_COMPILER;
|
||||||
xp->xp_pattern = arg;
|
xp->xp_pattern = arg;
|
||||||
@@ -3019,6 +3026,12 @@ ExpandFromContext(
|
|||||||
return ExpandRTDir(pat, DIP_START + DIP_OPT, numMatches, matches,
|
return ExpandRTDir(pat, DIP_START + DIP_OPT, numMatches, matches,
|
||||||
directories);
|
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)
|
if (xp->xp_context == EXPAND_COMPILER)
|
||||||
{
|
{
|
||||||
char *directories[] = {"compiler", NULL};
|
char *directories[] = {"compiler", NULL};
|
||||||
|
@@ -990,18 +990,34 @@ ExpandRTDir(
|
|||||||
|
|
||||||
for (i = 0; dirnames[i] != NULL; ++i)
|
for (i = 0; dirnames[i] != NULL; ++i)
|
||||||
{
|
{
|
||||||
s = alloc(STRLEN(dirnames[i]) + pat_len + 7);
|
size_t buflen = STRLEN(dirnames[i]) + pat_len * 2 + 17;
|
||||||
if (s == NULL)
|
char_u *buf = alloc(buflen);
|
||||||
|
if (buf == NULL)
|
||||||
{
|
{
|
||||||
ga_clear_strings(&ga);
|
ga_clear_strings(&ga);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat);
|
if (*(dirnames[i]) == NUL)
|
||||||
globpath(p_rtp, s, &ga, 0);
|
{
|
||||||
vim_free(s);
|
// 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)
|
for (i = 0; dirnames[i] != NULL; ++i)
|
||||||
{
|
{
|
||||||
s = alloc(STRLEN(dirnames[i]) + pat_len + 22);
|
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)
|
for (i = 0; dirnames[i] != NULL; ++i)
|
||||||
{
|
{
|
||||||
s = alloc(STRLEN(dirnames[i]) + pat_len + 20);
|
s = alloc(STRLEN(dirnames[i]) + pat_len + 20);
|
||||||
@@ -1036,15 +1053,52 @@ ExpandRTDir(
|
|||||||
match = ((char_u **)ga.ga_data)[i];
|
match = ((char_u **)ga.ga_data)[i];
|
||||||
s = match;
|
s = match;
|
||||||
e = s + STRLEN(s);
|
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)
|
if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0)
|
||||||
{
|
{
|
||||||
e -= 4;
|
if (res_start == s)
|
||||||
for (s = e; s > match; MB_PTR_BACK(match, s))
|
{
|
||||||
if (s < match || vim_ispathsep(*s))
|
// Only keep the file name.
|
||||||
break;
|
// Remove file ext only if flag DIP_PRNEXT is not present.
|
||||||
++s;
|
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;
|
*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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -552,6 +552,15 @@ func Test_getcompletion()
|
|||||||
call assert_true(index(l, '<buffer>') >= 0)
|
call assert_true(index(l, '<buffer>') >= 0)
|
||||||
let l = getcompletion('not', 'mapclear')
|
let l = getcompletion('not', 'mapclear')
|
||||||
call assert_equal([], l)
|
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')
|
let l = getcompletion('.', 'shellcmd')
|
||||||
call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
|
call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
|
||||||
|
@@ -86,6 +86,7 @@ static struct
|
|||||||
#endif
|
#endif
|
||||||
{EXPAND_SETTINGS, "option"},
|
{EXPAND_SETTINGS, "option"},
|
||||||
{EXPAND_PACKADD, "packadd"},
|
{EXPAND_PACKADD, "packadd"},
|
||||||
|
{EXPAND_RUNTIME, "runtime"},
|
||||||
{EXPAND_SHELLCMD, "shellcmd"},
|
{EXPAND_SHELLCMD, "shellcmd"},
|
||||||
#if defined(FEAT_SIGNS)
|
#if defined(FEAT_SIGNS)
|
||||||
{EXPAND_SIGN, "sign"},
|
{EXPAND_SIGN, "sign"},
|
||||||
|
@@ -695,6 +695,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1227,
|
||||||
/**/
|
/**/
|
||||||
1226,
|
1226,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -811,6 +811,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
|
|||||||
#define EXPAND_DISASSEMBLE 50
|
#define EXPAND_DISASSEMBLE 50
|
||||||
#define EXPAND_BREAKPOINT 51
|
#define EXPAND_BREAKPOINT 51
|
||||||
#define EXPAND_SCRIPTNAMES 52
|
#define EXPAND_SCRIPTNAMES 52
|
||||||
|
#define EXPAND_RUNTIME 53
|
||||||
|
|
||||||
// Values for exmode_active (0 is no exmode)
|
// Values for exmode_active (0 is no exmode)
|
||||||
#define EXMODE_NORMAL 1
|
#define EXMODE_NORMAL 1
|
||||||
@@ -2661,6 +2662,7 @@ typedef enum {
|
|||||||
#define DIP_NORTP 0x20 // do not use 'runtimepath'
|
#define DIP_NORTP 0x20 // do not use 'runtimepath'
|
||||||
#define DIP_NOAFTER 0x40 // skip "after" directories
|
#define DIP_NOAFTER 0x40 // skip "after" directories
|
||||||
#define DIP_AFTER 0x80 // only use "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.
|
// Lowest number used for window ID. Cannot have this many windows.
|
||||||
#define LOWEST_WIN_ID 1000
|
#define LOWEST_WIN_ID 1000
|
||||||
|
Reference in New Issue
Block a user