mirror of
https://github.com/vim/vim.git
synced 2025-07-04 23:07:33 -04:00
Improve implementation
This commit is contained in:
parent
8e58fc0268
commit
1a5f9dc5a5
@ -4526,40 +4526,6 @@ f_cmdcomplete_info(typval_T *argvars UNUSED, typval_T *rettv)
|
||||
list_append_string(li, ccline->xpc->xp_files[idx], -1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* "getcompltype()" function
|
||||
*/
|
||||
void
|
||||
f_getcompltype(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
char_u *pat;
|
||||
char_u *cmd_compl;
|
||||
expand_T xpc;
|
||||
int cmdline_len;
|
||||
|
||||
if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
|
||||
return;
|
||||
|
||||
pat = tv_get_string(&argvars[0]);
|
||||
if (check_for_string_arg(argvars, 0) == FAIL)
|
||||
return;
|
||||
|
||||
ExpandInit(&xpc);
|
||||
|
||||
cmdline_len = (int)STRLEN(pat);
|
||||
set_cmd_context(&xpc, pat, cmdline_len, cmdline_len, FALSE);
|
||||
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
|
||||
xpc.xp_col = cmdline_len;
|
||||
|
||||
rettv->v_type = VAR_STRING;
|
||||
|
||||
cmd_compl = cmdcomplete_type_to_str(xpc.xp_context);
|
||||
if (cmd_compl != NULL)
|
||||
rettv->vval.v_string = vim_strsave(cmd_compl);
|
||||
|
||||
ExpandCleanup(&xpc);
|
||||
}
|
||||
#endif // FEAT_EVAL
|
||||
|
||||
/*
|
||||
|
@ -4306,25 +4306,16 @@ get_cmdline_completion_pattern(void)
|
||||
* Get the current command-line completion type.
|
||||
*/
|
||||
static char_u *
|
||||
get_cmdline_completion(void)
|
||||
get_cmdline_completion(expand_T *xpc)
|
||||
{
|
||||
cmdline_info_T *p;
|
||||
char_u *buffer;
|
||||
int xp_context;
|
||||
|
||||
if (cmdline_star > 0)
|
||||
return NULL;
|
||||
|
||||
p = get_ccline_ptr();
|
||||
if (p == NULL || p->xpc == NULL)
|
||||
return NULL;
|
||||
|
||||
xp_context = p->xpc->xp_context;
|
||||
xp_context = xpc->xp_context;
|
||||
if (xp_context == EXPAND_NOTHING)
|
||||
{
|
||||
set_expand_context(p->xpc);
|
||||
xp_context = p->xpc->xp_context;
|
||||
p->xpc->xp_context = EXPAND_NOTHING;
|
||||
set_expand_context(xpc);
|
||||
xp_context = xpc->xp_context;
|
||||
xpc->xp_context = EXPAND_NOTHING;
|
||||
}
|
||||
if (xp_context == EXPAND_UNSUCCESSFUL)
|
||||
return NULL;
|
||||
@ -4335,10 +4326,12 @@ get_cmdline_completion(void)
|
||||
|
||||
if (xp_context == EXPAND_USER_LIST || xp_context == EXPAND_USER_DEFINED)
|
||||
{
|
||||
buffer = alloc(STRLEN(cmd_compl) + STRLEN(p->xpc->xp_arg) + 2);
|
||||
char_u *buffer;
|
||||
|
||||
buffer = alloc(STRLEN(cmd_compl) + STRLEN(xpc->xp_arg) + 2);
|
||||
if (buffer == NULL)
|
||||
return NULL;
|
||||
sprintf((char *)buffer, "%s,%s", cmd_compl, p->xpc->xp_arg);
|
||||
sprintf((char *)buffer, "%s,%s", cmd_compl, xpc->xp_arg);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -4361,8 +4354,47 @@ f_getcmdcomplpat(typval_T *argvars UNUSED, typval_T *rettv)
|
||||
void
|
||||
f_getcmdcompltype(typval_T *argvars UNUSED, typval_T *rettv)
|
||||
{
|
||||
cmdline_info_T *p;
|
||||
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = get_cmdline_completion();
|
||||
|
||||
p = get_ccline_ptr();
|
||||
if (cmdline_star > 0 || p == NULL || p->xpc == NULL)
|
||||
return;
|
||||
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = get_cmdline_completion(p->xpc);
|
||||
}
|
||||
|
||||
/*
|
||||
* "getcompltype()" function
|
||||
*/
|
||||
void
|
||||
f_getcompltype(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
char_u *pat;
|
||||
char_u *cmd_compl;
|
||||
expand_T xpc;
|
||||
int cmdline_len;
|
||||
|
||||
if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
|
||||
return;
|
||||
|
||||
pat = tv_get_string(&argvars[0]);
|
||||
if (check_for_string_arg(argvars, 0) == FAIL)
|
||||
return;
|
||||
|
||||
ExpandInit(&xpc);
|
||||
|
||||
cmdline_len = (int)STRLEN(pat);
|
||||
set_cmd_context(&xpc, pat, cmdline_len, cmdline_len, FALSE);
|
||||
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
|
||||
xpc.xp_col = cmdline_len;
|
||||
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = get_cmdline_completion(&xpc);
|
||||
|
||||
ExpandCleanup(&xpc);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -25,5 +25,4 @@ int wildmenu_process_key(cmdline_info_T *cclp, int key, expand_T *xp);
|
||||
void wildmenu_cleanup(cmdline_info_T *cclp);
|
||||
void f_getcompletion(typval_T *argvars, typval_T *rettv);
|
||||
void f_cmdcomplete_info(typval_T *argvars UNUSED, typval_T *rettv);
|
||||
void f_getcompltype(typval_T *argvars, typval_T *rettv);
|
||||
/* vim: set ft=c : */
|
||||
|
@ -39,6 +39,7 @@ void f_getcmdscreenpos(typval_T *argvars, typval_T *rettv);
|
||||
void f_getcmdtype(typval_T *argvars, typval_T *rettv);
|
||||
void f_setcmdline(typval_T *argvars, typval_T *rettv);
|
||||
void f_setcmdpos(typval_T *argvars, typval_T *rettv);
|
||||
void f_getcompltype(typval_T *argvars, typval_T *rettv);
|
||||
int get_cmdline_firstc(void);
|
||||
int get_list_range(char_u **str, int *num1, int *num2);
|
||||
char *did_set_cedit(optset_T *args);
|
||||
|
Loading…
x
Reference in New Issue
Block a user