mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.0284: using static buffer for multiple completion functions
Problem: Using static buffer for multiple completion functions.
Solution: Use one buffer in expand_T.
5ff595d9db
This commit is contained in:
parent
2676555b22
commit
608134794d
@ -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];
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -5737,9 +5737,6 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg)
|
||||
*/
|
||||
char *get_syntax_name(expand_T *xp, int idx)
|
||||
{
|
||||
#define CBUFFER_LEN 256
|
||||
static char cbuffer[CBUFFER_LEN]; // TODO: better solution
|
||||
|
||||
switch (expand_what) {
|
||||
case EXP_SUBCMD:
|
||||
return subcommands[idx].name;
|
||||
@ -5761,9 +5758,9 @@ char *get_syntax_name(expand_T *xp, int idx)
|
||||
}
|
||||
case EXP_CLUSTER:
|
||||
if (idx < curwin->w_s->b_syn_clusters.ga_len) {
|
||||
vim_snprintf(cbuffer, CBUFFER_LEN, "@%s",
|
||||
vim_snprintf(xp->xp_buf, EXPAND_BUF_LEN, "@%s",
|
||||
SYN_CLSTR(curwin->w_s)[idx].scl_name);
|
||||
return cbuffer;
|
||||
return xp->xp_buf;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user