mirror of
https://github.com/vim/vim.git
synced 2025-10-13 06:54:15 -04:00
patch 8.1.1943: more code can be moved to evalvars.c
Problem: More code can be moved to evalvars.c. Solution: Move it, clean up comments. Also move some window related functions to window.c. (Yegappan Lakshmanan, closes #4874)
This commit is contained in:
128
src/evalfunc.c
128
src/evalfunc.c
@@ -21,7 +21,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef MACOS_X
|
||||
# include <time.h> /* for time_t */
|
||||
# include <time.h> // for time_t
|
||||
#endif
|
||||
|
||||
static char *e_listblobarg = N_("E899: Argument of %s must be a List or Blob");
|
||||
@@ -129,7 +129,6 @@ static void f_garbagecollect(typval_T *argvars, typval_T *rettv);
|
||||
static void f_get(typval_T *argvars, typval_T *rettv);
|
||||
static void f_getbufinfo(typval_T *argvars, typval_T *rettv);
|
||||
static void f_getbufline(typval_T *argvars, typval_T *rettv);
|
||||
static void f_getbufvar(typval_T *argvars, typval_T *rettv);
|
||||
static void f_getchangelist(typval_T *argvars, typval_T *rettv);
|
||||
static void f_getchar(typval_T *argvars, typval_T *rettv);
|
||||
static void f_getcharmod(typval_T *argvars, typval_T *rettv);
|
||||
@@ -280,7 +279,6 @@ static void f_searchpos(typval_T *argvars, typval_T *rettv);
|
||||
static void f_server2client(typval_T *argvars, typval_T *rettv);
|
||||
static void f_serverlist(typval_T *argvars, typval_T *rettv);
|
||||
static void f_setbufline(typval_T *argvars, typval_T *rettv);
|
||||
static void f_setbufvar(typval_T *argvars, typval_T *rettv);
|
||||
static void f_setcharsearch(typval_T *argvars, typval_T *rettv);
|
||||
static void f_setcmdpos(typval_T *argvars, typval_T *rettv);
|
||||
static void f_setenv(typval_T *argvars, typval_T *rettv);
|
||||
@@ -4393,73 +4391,6 @@ f_getbufline(typval_T *argvars, typval_T *rettv)
|
||||
get_buffer_lines(buf, lnum, end, TRUE, rettv);
|
||||
}
|
||||
|
||||
/*
|
||||
* "getbufvar()" function
|
||||
*/
|
||||
static void
|
||||
f_getbufvar(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
buf_T *buf;
|
||||
buf_T *save_curbuf;
|
||||
char_u *varname;
|
||||
dictitem_T *v;
|
||||
int done = FALSE;
|
||||
|
||||
(void)tv_get_number(&argvars[0]); /* issue errmsg if type error */
|
||||
varname = tv_get_string_chk(&argvars[1]);
|
||||
++emsg_off;
|
||||
buf = tv_get_buf(&argvars[0], FALSE);
|
||||
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = NULL;
|
||||
|
||||
if (buf != NULL && varname != NULL)
|
||||
{
|
||||
/* set curbuf to be our buf, temporarily */
|
||||
save_curbuf = curbuf;
|
||||
curbuf = buf;
|
||||
|
||||
if (*varname == '&')
|
||||
{
|
||||
if (varname[1] == NUL)
|
||||
{
|
||||
/* get all buffer-local options in a dict */
|
||||
dict_T *opts = get_winbuf_options(TRUE);
|
||||
|
||||
if (opts != NULL)
|
||||
{
|
||||
rettv_dict_set(rettv, opts);
|
||||
done = TRUE;
|
||||
}
|
||||
}
|
||||
else if (get_option_tv(&varname, rettv, TRUE) == OK)
|
||||
/* buffer-local-option */
|
||||
done = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Look up the variable. */
|
||||
/* Let getbufvar({nr}, "") return the "b:" dictionary. */
|
||||
v = find_var_in_ht(&curbuf->b_vars->dv_hashtab,
|
||||
'b', varname, FALSE);
|
||||
if (v != NULL)
|
||||
{
|
||||
copy_tv(&v->di_tv, rettv);
|
||||
done = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* restore previous notion of curbuf */
|
||||
curbuf = save_curbuf;
|
||||
}
|
||||
|
||||
if (!done && argvars[2].v_type != VAR_UNKNOWN)
|
||||
/* use the default value */
|
||||
copy_tv(&argvars[2], rettv);
|
||||
|
||||
--emsg_off;
|
||||
}
|
||||
|
||||
/*
|
||||
* "getchangelist()" function
|
||||
*/
|
||||
@@ -9749,63 +9680,6 @@ f_setbufline(typval_T *argvars, typval_T *rettv)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* "setbufvar()" function
|
||||
*/
|
||||
static void
|
||||
f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED)
|
||||
{
|
||||
buf_T *buf;
|
||||
char_u *varname, *bufvarname;
|
||||
typval_T *varp;
|
||||
char_u nbuf[NUMBUFLEN];
|
||||
|
||||
if (check_secure())
|
||||
return;
|
||||
(void)tv_get_number(&argvars[0]); /* issue errmsg if type error */
|
||||
varname = tv_get_string_chk(&argvars[1]);
|
||||
buf = tv_get_buf(&argvars[0], FALSE);
|
||||
varp = &argvars[2];
|
||||
|
||||
if (buf != NULL && varname != NULL && varp != NULL)
|
||||
{
|
||||
if (*varname == '&')
|
||||
{
|
||||
long numval;
|
||||
char_u *strval;
|
||||
int error = FALSE;
|
||||
aco_save_T aco;
|
||||
|
||||
/* set curbuf to be our buf, temporarily */
|
||||
aucmd_prepbuf(&aco, buf);
|
||||
|
||||
++varname;
|
||||
numval = (long)tv_get_number_chk(varp, &error);
|
||||
strval = tv_get_string_buf_chk(varp, nbuf);
|
||||
if (!error && strval != NULL)
|
||||
set_option_value(varname, numval, strval, OPT_LOCAL);
|
||||
|
||||
/* reset notion of buffer */
|
||||
aucmd_restbuf(&aco);
|
||||
}
|
||||
else
|
||||
{
|
||||
buf_T *save_curbuf = curbuf;
|
||||
|
||||
bufvarname = alloc(STRLEN(varname) + 3);
|
||||
if (bufvarname != NULL)
|
||||
{
|
||||
curbuf = buf;
|
||||
STRCPY(bufvarname, "b:");
|
||||
STRCPY(bufvarname + 2, varname);
|
||||
set_var(bufvarname, varp, TRUE);
|
||||
vim_free(bufvarname);
|
||||
curbuf = save_curbuf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
f_setcharsearch(typval_T *argvars, typval_T *rettv UNUSED)
|
||||
{
|
||||
|
Reference in New Issue
Block a user