aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/cmdhist.c12
-rw-r--r--src/nvim/ex_cmds_defs.h2
-rw-r--r--src/nvim/ex_getln.c1
-rw-r--r--src/nvim/fileio.c4
-rw-r--r--src/nvim/os/env.c7
-rw-r--r--src/nvim/syntax.c21
-rw-r--r--src/nvim/testdir/test_syntax.vim4
7 files changed, 36 insertions, 15 deletions
diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c
index b078fc6570..1426054d0b 100644
--- a/src/nvim/cmdhist.c
+++ b/src/nvim/cmdhist.c
@@ -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];
diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h
index 5d8ed64c60..71956b2246 100644
--- a/src/nvim/ex_cmds_defs.h
+++ b/src/nvim/ex_cmds_defs.h
@@ -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
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index d73a57ad75..081aa80778 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -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;
}
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 0b66878103..39b4eb4376 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -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;
}
}
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index d46d51882e..ea9a803a86 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -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;
}
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index fe37a79a5b..20287089f7 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -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;
}
diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim
index 85f27dd043..ccff01486e 100644
--- a/src/nvim/testdir/test_syntax.vim
+++ b/src/nvim/testdir/test_syntax.vim
@@ -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()