mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 14:08:32 +00:00
window: Fix matchaddpos() and enhance error reporting
This commit is contained in:
@@ -12440,56 +12440,56 @@ static void f_matchadd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
|
||||
static void f_matchaddpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
rettv->vval.v_number = -1;
|
||||
rettv->vval.v_number = -1;
|
||||
|
||||
char buf[NUMBUFLEN];
|
||||
const char *const group = tv_get_string_buf_chk(&argvars[0], buf);
|
||||
if (group == NULL) {
|
||||
return;
|
||||
}
|
||||
char buf[NUMBUFLEN];
|
||||
const char *const group = tv_get_string_buf_chk(&argvars[0], buf);
|
||||
if (group == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (argvars[1].v_type != VAR_LIST) {
|
||||
EMSG2(_(e_listarg), "matchaddpos()");
|
||||
return;
|
||||
}
|
||||
if (argvars[1].v_type != VAR_LIST) {
|
||||
EMSG2(_(e_listarg), "matchaddpos()");
|
||||
return;
|
||||
}
|
||||
|
||||
list_T *l;
|
||||
l = argvars[1].vval.v_list;
|
||||
if (l == NULL) {
|
||||
return;
|
||||
}
|
||||
list_T *l;
|
||||
l = argvars[1].vval.v_list;
|
||||
if (l == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool error = false;
|
||||
int prio = 10;
|
||||
int id = -1;
|
||||
const char *conceal_char = NULL;
|
||||
bool error = false;
|
||||
int prio = 10;
|
||||
int id = -1;
|
||||
const char *conceal_char = NULL;
|
||||
|
||||
if (argvars[2].v_type != VAR_UNKNOWN) {
|
||||
prio = tv_get_number_chk(&argvars[2], &error);
|
||||
if (argvars[3].v_type != VAR_UNKNOWN) {
|
||||
id = tv_get_number_chk(&argvars[3], &error);
|
||||
if (argvars[4].v_type != VAR_UNKNOWN) {
|
||||
if (argvars[4].v_type != VAR_DICT) {
|
||||
EMSG(_(e_dictreq));
|
||||
return;
|
||||
}
|
||||
dictitem_T *di;
|
||||
if ((di = tv_dict_find(argvars[4].vval.v_dict, S_LEN("conceal")))
|
||||
!= NULL) {
|
||||
conceal_char = tv_get_string(&di->di_tv);
|
||||
}
|
||||
if (argvars[2].v_type != VAR_UNKNOWN) {
|
||||
prio = tv_get_number_chk(&argvars[2], &error);
|
||||
if (argvars[3].v_type != VAR_UNKNOWN) {
|
||||
id = tv_get_number_chk(&argvars[3], &error);
|
||||
if (argvars[4].v_type != VAR_UNKNOWN) {
|
||||
if (argvars[4].v_type != VAR_DICT) {
|
||||
EMSG(_(e_dictreq));
|
||||
return;
|
||||
}
|
||||
dictitem_T *di;
|
||||
if ((di = tv_dict_find(argvars[4].vval.v_dict, S_LEN("conceal")))
|
||||
!= NULL) {
|
||||
conceal_char = tv_get_string(&di->di_tv);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (error == true) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (error == true) {
|
||||
return;
|
||||
}
|
||||
|
||||
// id == 3 is ok because matchaddpos() is supposed to substitute :3match
|
||||
if (id == 1 || id == 2) {
|
||||
EMSGN(_("E798: ID is reserved for \"match\": %" PRId64), id);
|
||||
return;
|
||||
}
|
||||
// id == 3 is ok because matchaddpos() is supposed to substitute :3match
|
||||
if (id == 1 || id == 2) {
|
||||
EMSGN(_("E798: ID is reserved for \"match\": %" PRId64), id);
|
||||
return;
|
||||
}
|
||||
|
||||
rettv->vval.v_number = match_add(curwin, group, NULL, prio, id, l,
|
||||
conceal_char);
|
||||
|
@@ -5619,19 +5619,17 @@ int match_add(win_T *wp, const char *const grp, const char *const pat,
|
||||
|
||||
if (TV_LIST_ITEM_TV(li)->v_type == VAR_LIST) {
|
||||
const list_T *const subl = TV_LIST_ITEM_TV(li)->vval.v_list;
|
||||
if (subl == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
const listitem_T *subli = tv_list_first(subl);
|
||||
if (subli == NULL) {
|
||||
emsgf(_("E5030: Empty list at position %d"),
|
||||
(int)tv_list_idx_of_item(pos_list, li));
|
||||
goto fail;
|
||||
}
|
||||
lnum = tv_get_number_chk(TV_LIST_ITEM_TV(subli), &error);
|
||||
if (error) {
|
||||
goto fail;
|
||||
}
|
||||
if (lnum == 0) {
|
||||
--i;
|
||||
if (lnum <= 0) {
|
||||
continue;
|
||||
}
|
||||
m->pos.pos[i].lnum = lnum;
|
||||
@@ -5641,9 +5639,15 @@ int match_add(win_T *wp, const char *const grp, const char *const pat,
|
||||
if (error) {
|
||||
goto fail;
|
||||
}
|
||||
if (col < 0) {
|
||||
continue;
|
||||
}
|
||||
subli = TV_LIST_ITEM_NEXT(subl, subli);
|
||||
if (subli != NULL) {
|
||||
len = tv_get_number_chk(TV_LIST_ITEM_TV(subli), &error);
|
||||
if (len < 0) {
|
||||
continue;
|
||||
}
|
||||
if (error) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -5652,15 +5656,15 @@ int match_add(win_T *wp, const char *const grp, const char *const pat,
|
||||
m->pos.pos[i].col = col;
|
||||
m->pos.pos[i].len = len;
|
||||
} else if (TV_LIST_ITEM_TV(li)->v_type == VAR_NUMBER) {
|
||||
if (TV_LIST_ITEM_TV(li)->vval.v_number == 0) {
|
||||
i--;
|
||||
if (TV_LIST_ITEM_TV(li)->vval.v_number <= 0) {
|
||||
continue;
|
||||
}
|
||||
m->pos.pos[i].lnum = TV_LIST_ITEM_TV(li)->vval.v_number;
|
||||
m->pos.pos[i].col = 0;
|
||||
m->pos.pos[i].len = 0;
|
||||
} else {
|
||||
EMSG(_("List or number required"));
|
||||
emsgf(_("E5031: List or number required at position %d"),
|
||||
(int)tv_list_idx_of_item(pos_list, li));
|
||||
goto fail;
|
||||
}
|
||||
if (toplnum == 0 || lnum < toplnum) {
|
||||
|
Reference in New Issue
Block a user