0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 9.0.0320: command line type of CmdlineChange differs from getcmdtype()

Problem:    Command line type of CmdlineChange differs from getcmdtype().
Solution:   Use the same type. (closes #11005)
This commit is contained in:
zeertzjq
2022-08-29 16:21:25 +01:00
committed by Bram Moolenaar
parent d5c8f11905
commit 54acb90d9e
4 changed files with 61 additions and 65 deletions

View File

@@ -4114,6 +4114,30 @@ get_ccline_ptr(void)
}
#endif
#if defined(FEAT_EVAL) || defined(FEAT_CMDWIN)
/*
* Get the current command-line type.
* Returns ':' or '/' or '?' or '@' or '>' or '-'
* Only works when the command line is being edited.
* Returns NUL when something is wrong.
*/
static int
get_cmdline_type(void)
{
cmdline_info_T *p = get_ccline_ptr();
if (p == NULL)
return NUL;
if (p->cmdfirstc == NUL)
return
# ifdef FEAT_EVAL
(p->input_fn) ? '@' :
# endif
'-';
return p->cmdfirstc;
}
#endif
#if defined(FEAT_EVAL) || defined(PROTO)
/*
* Get the current command line in allocated memory.
@@ -4187,22 +4211,7 @@ f_getcmdpos(typval_T *argvars UNUSED, typval_T *rettv)
{
cmdline_info_T *p = get_ccline_ptr();
rettv->vval.v_number = 0;
if (p != NULL)
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;
rettv->vval.v_number = p != NULL ? p->cmdpos + 1 : 0;
}
/*
@@ -4211,16 +4220,32 @@ get_cmdline_screen_pos(void)
void
f_getcmdscreenpos(typval_T *argvars UNUSED, typval_T *rettv)
{
rettv->vval.v_number = get_cmdline_screen_pos() + 1;
cmdline_info_T *p = get_ccline_ptr();
rettv->vval.v_number = p != NULL ? p->cmdspos + 1 : 0;
}
/*
* "getcmdtype()" function
*/
void
f_getcmdtype(typval_T *argvars UNUSED, typval_T *rettv)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = alloc(2);
if (rettv->vval.v_string != NULL)
{
rettv->vval.v_string[0] = get_cmdline_type();
rettv->vval.v_string[1] = NUL;
}
}
// Set the command line str to "str".
// Returns 1 when failed, 0 when OK.
int
static int
set_cmdline_str(char_u *str, int pos)
{
cmdline_info_T *p = get_ccline_ptr();
int cmdline_type;
int len;
if (p == NULL)
@@ -4237,8 +4262,7 @@ set_cmdline_str(char_u *str, int pos)
redrawcmd();
// Trigger CmdlineChanged autocommands.
cmdline_type = ccline.cmdfirstc == NUL ? '-' : ccline.cmdfirstc;
trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED);
trigger_cmd_autocmd(get_cmdline_type(), EVENT_CMDLINECHANGED);
return 0;
}
@@ -4310,48 +4334,6 @@ f_setcmdpos(typval_T *argvars, typval_T *rettv)
}
#endif
#if defined(FEAT_EVAL) || defined(FEAT_CMDWIN)
/*
* Get the current command-line type.
* Returns ':' or '/' or '?' or '@' or '>' or '-'
* Only works when the command line is being edited.
* Returns NUL when something is wrong.
*/
static int
get_cmdline_type(void)
{
cmdline_info_T *p = get_ccline_ptr();
if (p == NULL)
return NUL;
if (p->cmdfirstc == NUL)
return
# ifdef FEAT_EVAL
(p->input_fn) ? '@' :
# endif
'-';
return p->cmdfirstc;
}
#endif
#if defined(FEAT_EVAL) || defined(PROTO)
/*
* "getcmdtype()" function
*/
void
f_getcmdtype(typval_T *argvars UNUSED, typval_T *rettv)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = alloc(2);
if (rettv->vval.v_string != NULL)
{
rettv->vval.v_string[0] = get_cmdline_type();
rettv->vval.v_string[1] = NUL;
}
}
#endif
/*
* Return the first character of the current command line.
*/