mirror of
https://github.com/neovim/neovim.git
synced 2025-12-15 19:05:40 +00:00
vim-patch:8.1.1734: the evalfunc.c file is too big
Problem: The evalfunc.c file is too big.
Solution: Move some functions to other files.
29b7d7a9aa
This commit is contained in:
@@ -1124,7 +1124,7 @@ static void f_cindent(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
}
|
||||
}
|
||||
|
||||
static win_T *get_optional_window(typval_T *argvars, int idx)
|
||||
win_T *get_optional_window(typval_T *argvars, int idx)
|
||||
{
|
||||
win_T *win = curwin;
|
||||
|
||||
@@ -3669,61 +3669,6 @@ static void f_getmarklist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
get_buf_local_marks(buf, rettv->vval.v_list);
|
||||
}
|
||||
|
||||
/// "getmatches()" function
|
||||
static void f_getmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
matchitem_T *cur;
|
||||
int i;
|
||||
win_T *win = get_optional_window(argvars, 0);
|
||||
|
||||
if (win == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
tv_list_alloc_ret(rettv, kListLenMayKnow);
|
||||
cur = win->w_match_head;
|
||||
while (cur != NULL) {
|
||||
dict_T *dict = tv_dict_alloc();
|
||||
if (cur->match.regprog == NULL) {
|
||||
// match added with matchaddpos()
|
||||
for (i = 0; i < MAXPOSMATCH; i++) {
|
||||
llpos_T *llpos;
|
||||
char buf[30]; // use 30 to avoid compiler warning
|
||||
|
||||
llpos = &cur->pos.pos[i];
|
||||
if (llpos->lnum == 0) {
|
||||
break;
|
||||
}
|
||||
list_T *const l = tv_list_alloc(1 + (llpos->col > 0 ? 2 : 0));
|
||||
tv_list_append_number(l, (varnumber_T)llpos->lnum);
|
||||
if (llpos->col > 0) {
|
||||
tv_list_append_number(l, (varnumber_T)llpos->col);
|
||||
tv_list_append_number(l, (varnumber_T)llpos->len);
|
||||
}
|
||||
int len = snprintf(buf, sizeof(buf), "pos%d", i + 1);
|
||||
assert((size_t)len < sizeof(buf));
|
||||
tv_dict_add_list(dict, buf, (size_t)len, l);
|
||||
}
|
||||
} else {
|
||||
tv_dict_add_str(dict, S_LEN("pattern"), (const char *)cur->pattern);
|
||||
}
|
||||
tv_dict_add_str(dict, S_LEN("group"),
|
||||
(const char *)syn_id2name(cur->hlg_id));
|
||||
tv_dict_add_nr(dict, S_LEN("priority"), (varnumber_T)cur->priority);
|
||||
tv_dict_add_nr(dict, S_LEN("id"), (varnumber_T)cur->id);
|
||||
|
||||
if (cur->conceal_char) {
|
||||
char buf[MB_MAXBYTES + 1];
|
||||
|
||||
buf[utf_char2bytes(cur->conceal_char, (char_u *)buf)] = NUL;
|
||||
tv_dict_add_str(dict, S_LEN("conceal"), buf);
|
||||
}
|
||||
|
||||
tv_list_append_dict(rettv->vval.v_list, dict);
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
|
||||
/// "getmousepos()" function
|
||||
static void f_getmousepos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
@@ -6108,133 +6053,6 @@ static void f_match(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
find_some_match(argvars, rettv, kSomeMatch);
|
||||
}
|
||||
|
||||
/// "matchadd()" function
|
||||
static void f_matchadd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
char grpbuf[NUMBUFLEN];
|
||||
char patbuf[NUMBUFLEN];
|
||||
// group
|
||||
const char *const grp = tv_get_string_buf_chk(&argvars[0], grpbuf);
|
||||
// pattern
|
||||
const char *const pat = tv_get_string_buf_chk(&argvars[1], patbuf);
|
||||
// default priority
|
||||
int prio = 10;
|
||||
int id = -1;
|
||||
bool error = false;
|
||||
const char *conceal_char = NULL;
|
||||
win_T *win = curwin;
|
||||
|
||||
rettv->vval.v_number = -1;
|
||||
|
||||
if (grp == NULL || pat == NULL) {
|
||||
return;
|
||||
}
|
||||
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
|
||||
&& matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
if (id >= 1 && id <= 3) {
|
||||
semsg(_("E798: ID is reserved for \":match\": %" PRId64), (int64_t)id);
|
||||
return;
|
||||
}
|
||||
|
||||
rettv->vval.v_number = match_add(win, grp, pat, prio, id, NULL, conceal_char);
|
||||
}
|
||||
|
||||
static void f_matchaddpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
rettv->vval.v_number = -1;
|
||||
|
||||
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) {
|
||||
semsg(_(e_listarg), "matchaddpos()");
|
||||
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;
|
||||
win_T *win = curwin;
|
||||
|
||||
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
|
||||
&& matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (error == true) {
|
||||
return;
|
||||
}
|
||||
|
||||
// id == 3 is ok because matchaddpos() is supposed to substitute :3match
|
||||
if (id == 1 || id == 2) {
|
||||
semsg(_("E798: ID is reserved for \"match\": %" PRId64), (int64_t)id);
|
||||
return;
|
||||
}
|
||||
|
||||
rettv->vval.v_number = match_add(win, group, NULL, prio, id, l, conceal_char);
|
||||
}
|
||||
|
||||
/// "matcharg()" function
|
||||
static void f_matcharg(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
const int id = tv_get_number(&argvars[0]);
|
||||
|
||||
tv_list_alloc_ret(rettv, (id >= 1 && id <= 3
|
||||
? 2
|
||||
: 0));
|
||||
|
||||
if (id >= 1 && id <= 3) {
|
||||
matchitem_T *const m = get_match(curwin, id);
|
||||
|
||||
if (m != NULL) {
|
||||
tv_list_append_string(rettv->vval.v_list,
|
||||
(const char *)syn_id2name(m->hlg_id), -1);
|
||||
tv_list_append_string(rettv->vval.v_list, (const char *)m->pattern, -1);
|
||||
} else {
|
||||
tv_list_append_string(rettv->vval.v_list, NULL, 0);
|
||||
tv_list_append_string(rettv->vval.v_list, NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// "matchdelete()" function
|
||||
static void f_matchdelete(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
win_T *win = get_optional_window(argvars, 1);
|
||||
if (win == NULL) {
|
||||
rettv->vval.v_number = -1;
|
||||
} else {
|
||||
rettv->vval.v_number = match_delete(win,
|
||||
(int)tv_get_number(&argvars[0]), true);
|
||||
}
|
||||
}
|
||||
|
||||
/// "matchend()" function
|
||||
static void f_matchend(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user