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

patch 8.2.4903: cannot get the current cmdline completion type and position

Problem:    Cannot get the current cmdline completion type and position.
Solution:   Add getcmdcompltype() and getcmdscreenpos(). (Shougo Matsushita,
            closes #10344)
This commit is contained in:
Shougo Matsushita
2022-05-07 12:48:29 +01:00
committed by Bram Moolenaar
parent c27747e6dd
commit 79d599b877
11 changed files with 125 additions and 3 deletions

View File

@@ -4118,6 +4118,42 @@ get_cmdline_str(void)
return vim_strnsave(p->cmdbuff, p->cmdlen);
}
/*
* Get the current command-line completion type.
*/
static char_u *
get_cmdline_completion(void)
{
cmdline_info_T *p;
if (cmdline_star > 0)
return NULL;
p = get_ccline_ptr();
if (p && p->xpc != NULL)
{
char_u *cmd_compl;
set_expand_context(p->xpc);
cmd_compl = cmdcomplete_type_to_str(p->xpc->xp_context);
if (cmd_compl != NULL)
return vim_strnsave(cmd_compl, strlen((char *)cmd_compl));
}
return NULL;
}
/*
* "getcmdcompltype()" function
*/
void
f_getcmdcompltype(typval_T *argvars UNUSED, typval_T *rettv)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = get_cmdline_completion();
}
/*
* "getcmdline()" function
*/
@@ -4141,6 +4177,28 @@ f_getcmdpos(typval_T *argvars UNUSED, typval_T *rettv)
rettv->vval.v_number = p->cmdpos + 1;
}
/*
* Get the command line cursor screen position.
*/
static int
get_cmdline_screen_pos(void)
{
cmdline_info_T *p = get_ccline_ptr();
if (p == NULL)
return -1;
return p->cmdspos;
}
/*
* "getcmdscreenpos()" function
*/
void
f_getcmdscreenpos(typval_T *argvars UNUSED, typval_T *rettv)
{
rettv->vval.v_number = get_cmdline_screen_pos() + 1;
}
/*
* Set the command line byte position to "pos". Zero is the first position.
* Only works when the command line is being edited.