Merge pull request #19962 from zeertzjq/vim-9.0.0278

vim-patch:9.0.{0278,0279,0283,0284}: cmdline completion patches
This commit is contained in:
zeertzjq 2022-08-27 07:33:29 +08:00 committed by GitHub
commit 58b29e344c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 21 deletions

View File

@ -6940,12 +6940,15 @@ A jump table for the options with a short description can be found at |Q_op|.
*'wildmenu'* *'wmnu'* *'nowildmenu'* *'nowmnu'*
'wildmenu' 'wmnu' boolean (default on)
global
Enables "enhanced mode" of command-line completion. When user hits
<Tab> (or 'wildchar') to invoke completion, the possible matches are
shown in a menu just above the command-line (see 'wildoptions'), with
the first match highlighted (overwriting the statusline). Keys that
show the previous/next match (<Tab>/CTRL-P/CTRL-N) highlight the
match.
When 'wildmenu' is on, command-line completion operates in an enhanced
mode. On pressing 'wildchar' (usually <Tab>) to invoke completion,
the possible matches are shown.
When 'wildoptions' contains "pum", then the completion matches are
shown in a popup menu. Otherwise they are displayed just above the
command line, with the first match highlighted (overwriting the status
line, if there is one).
Keys that show the previous/next match, such as <Tab> or
CTRL-P/CTRL-N, cause the highlight to move to the appropriate match.
'wildmode' must specify "full": "longest" and "list" do not start
'wildmenu' mode. You can check the current mode with |wildmenumode()|.
The menu is canceled when a key is hit that is not used for selecting

View File

@ -90,14 +90,14 @@ static char *(history_names[]) = {
/// arguments of the ":history command.
char *get_history_arg(expand_T *xp, int idx)
{
static char_u compl[2] = { NUL, NUL };
char *short_names = ":=@>?/";
int short_names_count = (int)STRLEN(short_names);
int history_name_count = ARRAY_SIZE(history_names) - 1;
const char *short_names = ":=@>?/";
const int short_names_count = (int)STRLEN(short_names);
const int history_name_count = ARRAY_SIZE(history_names) - 1;
if (idx < short_names_count) {
compl[0] = (char_u)short_names[idx];
return (char *)compl;
xp->xp_buf[0] = short_names[idx];
xp->xp_buf[1] = NUL;
return xp->xp_buf;
}
if (idx < short_names_count + history_name_count) {
return history_names[idx - short_names_count];

View File

@ -237,6 +237,8 @@ struct expand {
int xp_col; // cursor position in line
char **xp_files; // list of files
char *xp_line; // text being completed
#define EXPAND_BUF_LEN 256
char xp_buf[EXPAND_BUF_LEN]; // buffer for returned match
};
// values for xp_backslash

View File

@ -1808,6 +1808,7 @@ static int command_line_handle_key(CommandLineState *s)
// menu (if present)
cmdline_pum_cleanup(&ccline);
}
if (nextwild(&s->xpc, WILD_ALL, 0, s->firstc != '@') == FAIL) {
break;
}

View File

@ -337,7 +337,9 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip,
curbuf->b_op_start = orig_start;
if (flags & READ_NOFILE) {
return NOTDONE; // so that BufEnter can be triggered
// Return NOTDONE instead of FAIL so that BufEnter can be triggered
// and other operations don't fail.
return NOTDONE;
}
}

View File

@ -1156,15 +1156,12 @@ char *home_replace_save(buf_T *buf, const char *src)
/// Function given to ExpandGeneric() to obtain an environment variable name.
char *get_env_name(expand_T *xp, int idx)
{
#define ENVNAMELEN 100
// this static buffer is needed to avoid a memory leak in ExpandGeneric
static char_u name[ENVNAMELEN];
assert(idx >= 0);
char *envname = os_getenvname_at_index((size_t)idx);
if (envname) {
STRLCPY(name, envname, ENVNAMELEN);
STRLCPY(xp->xp_buf, envname, EXPAND_BUF_LEN);
xfree(envname);
return (char *)name;
return xp->xp_buf;
}
return NULL;
}

View File

@ -5664,7 +5664,8 @@ static enum {
EXP_SUBCMD, // expand ":syn" sub-commands
EXP_CASE, // expand ":syn case" arguments
EXP_SPELL, // expand ":syn spell" arguments
EXP_SYNC, // expand ":syn sync" arguments
EXP_SYNC, // expand ":syn sync" arguments
EXP_CLUSTER, // expand ":syn list @cluster" arguments
} expand_what;
/*
@ -5712,10 +5713,16 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg)
expand_what = EXP_SPELL;
} else if (STRNICMP(arg, "sync", p - arg) == 0) {
expand_what = EXP_SYNC;
} else if (STRNICMP(arg, "list", p - arg) == 0) {
p = skipwhite(p);
if (*p == '@') {
expand_what = EXP_CLUSTER;
} else {
xp->xp_context = EXPAND_HIGHLIGHT;
}
} else if (STRNICMP(arg, "keyword", p - arg) == 0
|| STRNICMP(arg, "region", p - arg) == 0
|| STRNICMP(arg, "match", p - arg) == 0
|| STRNICMP(arg, "list", p - arg) == 0) {
|| STRNICMP(arg, "match", p - arg) == 0) {
xp->xp_context = EXPAND_HIGHLIGHT;
} else {
xp->xp_context = EXPAND_NOTHING;
@ -5749,6 +5756,14 @@ char *get_syntax_name(expand_T *xp, int idx)
"maxlines=", "minlines=", "region", NULL };
return sync_args[idx];
}
case EXP_CLUSTER:
if (idx < curwin->w_s->b_syn_clusters.ga_len) {
vim_snprintf(xp->xp_buf, EXPAND_BUF_LEN, "@%s",
SYN_CLSTR(curwin->w_s)[idx].scl_name);
return xp->xp_buf;
} else {
return NULL;
}
}
return NULL;
}

View File

@ -198,6 +198,10 @@ func Test_syntax_completion()
call feedkeys(":syn match \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_match('^"syn match @boolean @character ', @:)
syn cluster Aax contains=Aap
call feedkeys(":syn list @A\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_match('^"syn list @Aax', @:)
endfunc
func Test_echohl_completion()