0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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.
This commit is contained in:
Bram Moolenaar
2022-08-26 22:36:41 +01:00
parent af9a6002e0
commit 5ff595d9db
5 changed files with 21 additions and 24 deletions

View File

@@ -99,15 +99,15 @@ static char *(history_names[]) =
char_u * char_u *
get_history_arg(expand_T *xp UNUSED, int idx) get_history_arg(expand_T *xp UNUSED, int idx)
{ {
static char_u compl[2] = { NUL, NUL }; char *short_names = ":=@>?/";
char *short_names = ":=@>?/"; int short_names_count = (int)STRLEN(short_names);
int short_names_count = (int)STRLEN(short_names); int history_name_count = ARRAY_LENGTH(history_names) - 1;
int history_name_count = ARRAY_LENGTH(history_names) - 1;
if (idx < short_names_count) if (idx < short_names_count)
{ {
compl[0] = (char_u)short_names[idx]; xp->xp_buf[0] = (char_u)short_names[idx];
return compl; xp->xp_buf[1] = NUL;
return xp->xp_buf;
} }
if (idx < short_names_count + history_name_count) if (idx < short_names_count + history_name_count)
return (char_u *)history_names[idx - short_names_count]; return (char_u *)history_names[idx - short_names_count];

View File

@@ -2016,18 +2016,14 @@ get_env_name(
expand_T *xp UNUSED, expand_T *xp UNUSED,
int idx) int idx)
{ {
# if defined(AMIGA) #if defined(AMIGA)
/* // No environ[] on the Amiga.
* No environ[] on the Amiga.
*/
return NULL; return NULL;
# else #else
# ifndef __WIN32__ # ifndef __WIN32__
// Borland C++ 5.2 has this in a header file. // Borland C++ 5.2 has this in a header file.
extern char **environ; extern char **environ;
# endif # endif
# define ENVNAMELEN 100
static char_u name[ENVNAMELEN];
char_u *str; char_u *str;
int n; int n;
@@ -2035,15 +2031,15 @@ get_env_name(
if (str == NULL) if (str == NULL)
return NULL; return NULL;
for (n = 0; n < ENVNAMELEN - 1; ++n) for (n = 0; n < EXPAND_BUF_LEN - 1; ++n)
{ {
if (str[n] == '=' || str[n] == NUL) if (str[n] == '=' || str[n] == NUL)
break; break;
name[n] = str[n]; xp->xp_buf[n] = str[n];
} }
name[n] = NUL; xp->xp_buf[n] = NUL;
return name; return xp->xp_buf;
# endif #endif
} }
/* /*

View File

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

View File

@@ -6420,11 +6420,8 @@ set_context_in_syntax_cmd(expand_T *xp, char_u *arg)
* expansion. * expansion.
*/ */
char_u * char_u *
get_syntax_name(expand_T *xp UNUSED, int idx) get_syntax_name(expand_T *xp, int idx)
{ {
#define CBUFFER_LEN 256
static char_u cbuffer[CBUFFER_LEN]; // TODO: better solution
switch (expand_what) switch (expand_what)
{ {
case EXP_SUBCMD: case EXP_SUBCMD:
@@ -6452,9 +6449,9 @@ get_syntax_name(expand_T *xp UNUSED, int idx)
{ {
if (idx < curwin->w_s->b_syn_clusters.ga_len) if (idx < curwin->w_s->b_syn_clusters.ga_len)
{ {
vim_snprintf((char *)cbuffer, CBUFFER_LEN, "@%s", vim_snprintf((char *)xp->xp_buf, EXPAND_BUF_LEN, "@%s",
SYN_CLSTR(curwin->w_s)[idx].scl_name); SYN_CLSTR(curwin->w_s)[idx].scl_name);
return cbuffer; return xp->xp_buf;
} }
else else
return NULL; return NULL;

View File

@@ -707,6 +707,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 */
/**/
284,
/**/ /**/
283, 283,
/**/ /**/