mirror of
https://github.com/vim/vim.git
synced 2025-10-01 04:54:07 -04:00
patch 9.0.2025: no cmdline completion for ++opt args
Problem: no cmdline completion for ++opt args Solution: Add cmdline completion for :e ++opt=arg and :terminal [++options] closes: #13319 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
This commit is contained in:
committed by
Christian Brabandt
parent
bd734c3bea
commit
989426be6e
111
src/ex_docmd.c
111
src/ex_docmd.c
@@ -5407,6 +5407,25 @@ get_bad_opt(char_u *p, exarg_T *eap)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function given to ExpandGeneric() to obtain the list of bad= names.
|
||||
*/
|
||||
static char_u *
|
||||
get_bad_name(expand_T *xp UNUSED, int idx)
|
||||
{
|
||||
// Note: Keep this in sync with getargopt.
|
||||
static char *(p_bad_values[]) =
|
||||
{
|
||||
"?",
|
||||
"keep",
|
||||
"drop",
|
||||
};
|
||||
|
||||
if (idx < (int)ARRAY_LENGTH(p_bad_values))
|
||||
return (char_u*)p_bad_values[idx];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get "++opt=arg" argument.
|
||||
* Return FAIL or OK.
|
||||
@@ -5419,6 +5438,8 @@ getargopt(exarg_T *eap)
|
||||
int bad_char_idx;
|
||||
char_u *p;
|
||||
|
||||
// Note: Keep this in sync with get_argopt_name.
|
||||
|
||||
// ":edit ++[no]bin[ary] file"
|
||||
if (STRNCMP(arg, "bin", 3) == 0 || STRNCMP(arg, "nobin", 5) == 0)
|
||||
{
|
||||
@@ -5499,6 +5520,96 @@ getargopt(exarg_T *eap)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function given to ExpandGeneric() to obtain the list of ++opt names.
|
||||
*/
|
||||
static char_u *
|
||||
get_argopt_name(expand_T *xp UNUSED, int idx)
|
||||
{
|
||||
// Note: Keep this in sync with getargopt.
|
||||
static char *(p_opt_values[]) =
|
||||
{
|
||||
"fileformat=",
|
||||
"encoding=",
|
||||
"binary",
|
||||
"nobinary",
|
||||
"bad=",
|
||||
"edit",
|
||||
};
|
||||
|
||||
if (idx < (int)ARRAY_LENGTH(p_opt_values))
|
||||
return (char_u*)p_opt_values[idx];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Command-line expansion for ++opt=name.
|
||||
*/
|
||||
int
|
||||
expand_argopt(
|
||||
char_u *pat,
|
||||
expand_T *xp,
|
||||
regmatch_T *rmp,
|
||||
char_u ***matches,
|
||||
int *numMatches)
|
||||
{
|
||||
if (xp->xp_pattern > xp->xp_line && *(xp->xp_pattern-1) == '=')
|
||||
{
|
||||
char_u *(*cb)(expand_T *, int) = NULL;
|
||||
|
||||
char_u *name_end = xp->xp_pattern - 1;
|
||||
if (name_end - xp->xp_line >= 2
|
||||
&& STRNCMP(name_end - 2, "ff", 2) == 0)
|
||||
cb = get_fileformat_name;
|
||||
else if (name_end - xp->xp_line >= 10
|
||||
&& STRNCMP(name_end - 10, "fileformat", 10) == 0)
|
||||
cb = get_fileformat_name;
|
||||
else if (name_end - xp->xp_line >= 3
|
||||
&& STRNCMP(name_end - 3, "enc", 3) == 0)
|
||||
cb = get_encoding_name;
|
||||
else if (name_end - xp->xp_line >= 8
|
||||
&& STRNCMP(name_end - 8, "encoding", 8) == 0)
|
||||
cb = get_encoding_name;
|
||||
else if (name_end - xp->xp_line >= 3
|
||||
&& STRNCMP(name_end - 3, "bad", 3) == 0)
|
||||
cb = get_bad_name;
|
||||
|
||||
if (cb != NULL)
|
||||
{
|
||||
return ExpandGeneric(
|
||||
pat,
|
||||
xp,
|
||||
rmp,
|
||||
matches,
|
||||
numMatches,
|
||||
cb,
|
||||
FALSE);
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// Special handling of "ff" which acts as a short form of
|
||||
// "fileformat", as "ff" is not a substring of it.
|
||||
if (STRCMP(xp->xp_pattern, "ff") == 0)
|
||||
{
|
||||
*matches = ALLOC_MULT(char_u *, 1);
|
||||
if (*matches == NULL)
|
||||
return FAIL;
|
||||
*numMatches = 1;
|
||||
(*matches)[0] = vim_strsave((char_u*)"fileformat=");
|
||||
return OK;
|
||||
}
|
||||
|
||||
return ExpandGeneric(
|
||||
pat,
|
||||
xp,
|
||||
rmp,
|
||||
matches,
|
||||
numMatches,
|
||||
get_argopt_name,
|
||||
FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
ex_autocmd(exarg_T *eap)
|
||||
{
|
||||
|
Reference in New Issue
Block a user