348
351
{VV_NAME("mouse_col", VAR_NUMBER), 0},
349
352
{VV_NAME("operator", VAR_STRING), VV_RO},
350
353
{VV_NAME("searchforward", VAR_NUMBER), 0},
354
{VV_NAME("oldfiles", VAR_LIST), 0},
426
431
static long list_idx_of_item __ARGS((list_T *l, listitem_T *item));
427
432
static void list_append __ARGS((list_T *l, listitem_T *item));
428
433
static int list_append_tv __ARGS((list_T *l, typval_T *tv));
429
static int list_append_string __ARGS((list_T *l, char_u *str, int len));
430
434
static int list_append_number __ARGS((list_T *l, varnumber_T n));
431
435
static int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item));
432
436
static int list_extend __ARGS((list_T *l1, list_T *l2, listitem_T *bef));
788
792
static void func_unref __ARGS((char_u *name));
789
793
static void func_ref __ARGS((char_u *name));
790
794
static void call_user_func __ARGS((ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict));
795
static int can_free_funccal __ARGS((funccall_T *fc, int copyID)) ;
796
static void free_funccal __ARGS((funccall_T *fc, int free_val));
791
797
static void add_nr_var __ARGS((dict_T *dp, dictitem_T *v, char *name, varnumber_T nr));
792
798
static win_T *find_win_by_nr __ARGS((typval_T *vp, tabpage_T *tp));
793
799
static void getwinvar __ARGS((typval_T *argvars, typval_T *rettv, int off));
846
852
if (p->vv_di.di_tv.v_type == VAR_STRING)
848
vim_free(p->vv_di.di_tv.vval.v_string);
849
p->vv_di.di_tv.vval.v_string = NULL;
857
else if (p->vv_di.di_tv.v_type == VAR_LIST)
859
list_unref(p->vv_list);
852
863
hash_clear(&vimvarht);
864
hash_init(&vimvarht); /* garbage_collect() will access it */
853
865
hash_clear(&compat_hashtab);
855
867
/* script-local variables */
916
928
/* pointer to funccal for currently active function */
917
929
funccall_T *current_funccal = NULL;
931
/* pointer to list of previously used funccal, still around because some
932
* item in it is still being used. */
933
funccall_T *previous_funccal = NULL;
920
936
* Return TRUE when a function was ended by a ":return" command.
6076
* Get list item "l[idx - 1]" as a string. Returns NULL for failure.
6079
list_find_str(l, idx)
6085
li = list_find(l, idx - 1);
6088
EMSGN(_(e_listidx), idx);
6091
return get_tv_string(&li->li_tv);
6060
6095
* Locate "item" list "l" and return its index.
6061
6096
* Returns -1 when "item" is not in the list.
7535
7587
{"getwinposx", 0, 0, f_getwinposx},
7536
7588
{"getwinposy", 0, 0, f_getwinposy},
7537
7589
{"getwinvar", 2, 2, f_getwinvar},
7538
{"glob", 1, 1, f_glob},
7539
{"globpath", 2, 2, f_globpath},
7590
{"glob", 1, 2, f_glob},
7591
{"globpath", 2, 3, f_globpath},
7540
7592
{"has", 1, 1, f_has},
7541
7593
{"has_key", 2, 2, f_has_key},
7542
7594
{"haslocaldir", 0, 0, f_haslocaldir},
9530
9582
/* When the optional second argument is non-zero, don't remove matches
9531
* for 'suffixes' and 'wildignore' */
9583
* for 'wildignore' and don't put matches for 'suffixes' at the end. */
9532
9584
if (argvars[1].v_type != VAR_UNKNOWN
9533
9585
&& get_tv_number_chk(&argvars[1], &error))
9534
9586
flags |= WILD_KEEP_ALL;
10310
10362
s = get_tv_string(&argvars[0]);
10311
10363
if (s == NULL || *s == NUL || VIM_ISDIGIT(*s))
10312
10364
EMSG2(_(e_invarg2), s);
10313
else if (!function_exists(s))
10365
/* Don't check an autoload name for existence here. */
10366
else if (vim_strchr(s, AUTOLOAD_CHAR) == NULL && !function_exists(s))
10314
10367
EMSG2(_("E700: Unknown function: %s"), s);
10622
10675
(void)mouse_comp_pos(win, &row, &col, &lnum);
10623
10676
# ifdef FEAT_WINDOWS
10624
10677
for (wp = firstwin; wp != win; wp = wp->w_next)
10627
vimvars[VV_MOUSE_WIN].vv_nr = n;
10680
vimvars[VV_MOUSE_WIN].vv_nr = winnr;
10628
10681
vimvars[VV_MOUSE_LNUM].vv_nr = lnum;
10629
10682
vimvars[VV_MOUSE_COL].vv_nr = col + 1;
11294
11347
typval_T *argvars;
11295
11348
typval_T *rettv;
11350
int flags = WILD_SILENT|WILD_USE_NL;
11297
11351
expand_T xpc;
11300
xpc.xp_context = EXPAND_FILES;
11354
/* When the optional second argument is non-zero, don't remove matches
11355
* for 'wildignore' and don't put matches for 'suffixes' at the end. */
11356
if (argvars[1].v_type != VAR_UNKNOWN
11357
&& get_tv_number_chk(&argvars[1], &error))
11358
flags |= WILD_KEEP_ALL;
11301
11359
rettv->v_type = VAR_STRING;
11302
rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]),
11303
NULL, WILD_USE_NL|WILD_SILENT, WILD_ALL);
11363
xpc.xp_context = EXPAND_FILES;
11364
rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]),
11365
NULL, flags, WILD_ALL);
11368
rettv->vval.v_string = NULL;
11311
11376
typval_T *argvars;
11312
11377
typval_T *rettv;
11314
11380
char_u buf1[NUMBUFLEN];
11315
11381
char_u *file = get_tv_string_buf_chk(&argvars[1], buf1);
11384
/* When the optional second argument is non-zero, don't remove matches
11385
* for 'wildignore' and don't put matches for 'suffixes' at the end. */
11386
if (argvars[2].v_type != VAR_UNKNOWN
11387
&& get_tv_number_chk(&argvars[2], &error))
11388
flags |= WILD_KEEP_ALL;
11317
11389
rettv->v_type = VAR_STRING;
11390
if (file == NULL || error)
11319
11391
rettv->vval.v_string = NULL;
11321
rettv->vval.v_string = globpath(get_tv_string(&argvars[0]), file);
11393
rettv->vval.v_string = globpath(get_tv_string(&argvars[0]), file,
11792
11865
n = has_patch(atoi((char *)name + 5));
11793
11866
else if (STRICMP(name, "vim_starting") == 0)
11794
11867
n = (starting != 0);
11869
else if (STRICMP(name, "multi_byte_encoding") == 0)
11795
11872
#if defined(FEAT_BEVAL) && defined(FEAT_GUI_W32)
11796
11873
else if (STRICMP(name, "balloon_multiline") == 0)
11797
11874
n = multiline_balloon_available();
16599
16676
p = highlight_has_attr(id, HL_INVERSE, modec);
16602
case 's': /* standout */
16603
p = highlight_has_attr(id, HL_STANDOUT, modec);
16680
if (TOLOWER_ASC(what[1]) == 'p') /* sp[#] */
16681
p = highlight_color(id, what, modec);
16682
else /* standout */
16683
p = highlight_has_attr(id, HL_STANDOUT, modec);
18109
* Set v:count, v:count1 and v:prevcount.
18189
* Get List v: variable value. Caller must take care of reference count when
18193
get_vim_var_list(idx)
18196
return vimvars[idx].vv_list;
18200
* Set v:count to "count" and v:count1 to "count1".
18201
* When "set_prevcount" is TRUE first set v:prevcount from v:count.
18112
set_vcount(count, count1)
18204
set_vcount(count, count1, set_prevcount)
18116
vimvars[VV_PREVCOUNT].vv_nr = vimvars[VV_COUNT].vv_nr;
18210
vimvars[VV_PREVCOUNT].vv_nr = vimvars[VV_COUNT].vv_nr;
18117
18211
vimvars[VV_COUNT].vv_nr = count;
18118
18212
vimvars[VV_COUNT1].vv_nr = count1;
18877
18985
dictitem_T *dict_var;
18879
18987
hash_init(&dict->dv_hashtab);
18880
dict->dv_refcount = 99999;
18988
dict->dv_refcount = DO_NOT_FREE_CNT;
18881
18989
dict_var->di_tv.vval.v_dict = dict;
18882
18990
dict_var->di_tv.v_type = VAR_DICT;
18883
18991
dict_var->di_tv.v_lock = VAR_FIXED;
21053
21163
line_breakcheck(); /* check for CTRL-C hit */
21055
fc.caller = current_funccal;
21056
current_funccal = &fc;
21165
fc = (funccall_T *)alloc(sizeof(funccall_T));
21166
fc->caller = current_funccal;
21167
current_funccal = fc;
21059
21170
rettv->vval.v_number = 0;
21061
fc.returned = FALSE;
21062
fc.level = ex_nesting_level;
21172
fc->returned = FALSE;
21173
fc->level = ex_nesting_level;
21063
21174
/* Check if this function has a breakpoint. */
21064
fc.breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, (linenr_T)0);
21065
fc.dbg_tick = debug_tick;
21175
fc->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, (linenr_T)0);
21176
fc->dbg_tick = debug_tick;
21068
* Note about using fc.fixvar[]: This is an array of FIXVAR_CNT variables
21179
* Note about using fc->fixvar[]: This is an array of FIXVAR_CNT variables
21069
21180
* with names up to VAR_SHORT_LEN long. This avoids having to alloc/free
21070
21181
* each argument variable and saves a lot of time.
21073
21184
* Init l: variables.
21075
init_var_dict(&fc.l_vars, &fc.l_vars_var);
21186
init_var_dict(&fc->l_vars, &fc->l_vars_var);
21076
21187
if (selfdict != NULL)
21078
21189
/* Set l:self to "selfdict". Use "name" to avoid a warning from
21079
21190
* some compiler that checks the destination size. */
21080
v = &fc.fixvar[fixvar_idx++].var;
21191
v = &fc->fixvar[fixvar_idx++].var;
21081
21192
name = v->di_key;
21082
21193
STRCPY(name, "self");
21083
21194
v->di_flags = DI_FLAGS_RO + DI_FLAGS_FIX;
21084
hash_add(&fc.l_vars.dv_hashtab, DI2HIKEY(v));
21195
hash_add(&fc->l_vars.dv_hashtab, DI2HIKEY(v));
21085
21196
v->di_tv.v_type = VAR_DICT;
21086
21197
v->di_tv.v_lock = 0;
21087
21198
v->di_tv.vval.v_dict = selfdict;
21093
21204
* Set a:0 to "argcount".
21094
21205
* Set a:000 to a list with room for the "..." arguments.
21096
init_var_dict(&fc.l_avars, &fc.l_avars_var);
21097
add_nr_var(&fc.l_avars, &fc.fixvar[fixvar_idx++].var, "0",
21207
init_var_dict(&fc->l_avars, &fc->l_avars_var);
21208
add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "0",
21098
21209
(varnumber_T)(argcount - fp->uf_args.ga_len));
21099
v = &fc.fixvar[fixvar_idx++].var;
21100
STRCPY(v->di_key, "000");
21210
/* Use "name" to avoid a warning from some compiler that checks the
21211
* destination size. */
21212
v = &fc->fixvar[fixvar_idx++].var;
21214
STRCPY(name, "000");
21101
21215
v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
21102
hash_add(&fc.l_avars.dv_hashtab, DI2HIKEY(v));
21216
hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v));
21103
21217
v->di_tv.v_type = VAR_LIST;
21104
21218
v->di_tv.v_lock = VAR_FIXED;
21105
v->di_tv.vval.v_list = &fc.l_varlist;
21106
vim_memset(&fc.l_varlist, 0, sizeof(list_T));
21107
fc.l_varlist.lv_refcount = 99999;
21108
fc.l_varlist.lv_lock = VAR_FIXED;
21219
v->di_tv.vval.v_list = &fc->l_varlist;
21220
vim_memset(&fc->l_varlist, 0, sizeof(list_T));
21221
fc->l_varlist.lv_refcount = DO_NOT_FREE_CNT;
21222
fc->l_varlist.lv_lock = VAR_FIXED;
21111
21225
* Set a:firstline to "firstline" and a:lastline to "lastline".
21112
21226
* Set a:name to named arguments.
21113
21227
* Set a:N to the "..." arguments.
21115
add_nr_var(&fc.l_avars, &fc.fixvar[fixvar_idx++].var, "firstline",
21229
add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "firstline",
21116
21230
(varnumber_T)firstline);
21117
add_nr_var(&fc.l_avars, &fc.fixvar[fixvar_idx++].var, "lastline",
21231
add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "lastline",
21118
21232
(varnumber_T)lastline);
21119
21233
for (i = 0; i < argcount; ++i)
21142
21256
v->di_flags = DI_FLAGS_RO;
21144
21258
STRCPY(v->di_key, name);
21145
hash_add(&fc.l_avars.dv_hashtab, DI2HIKEY(v));
21259
hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v));
21147
21261
/* Note: the values are copied directly to avoid alloc/free.
21148
21262
* "argvars" must have VAR_FIXED for v_lock. */
21152
21266
if (ai >= 0 && ai < MAX_FUNC_ARGS)
21154
list_append(&fc.l_varlist, &fc.l_listitems[ai]);
21155
fc.l_listitems[ai].li_tv = argvars[i];
21156
fc.l_listitems[ai].li_tv.v_lock = VAR_FIXED;
21268
list_append(&fc->l_varlist, &fc->l_listitems[ai]);
21269
fc->l_listitems[ai].li_tv = argvars[i];
21270
fc->l_listitems[ai].li_tv.v_lock = VAR_FIXED;
21234
21348
did_emsg = FALSE;
21236
21350
/* call do_cmdline() to execute the lines */
21237
do_cmdline(NULL, get_func_line, (void *)&fc,
21351
do_cmdline(NULL, get_func_line, (void *)fc,
21238
21352
DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
21240
21354
--RedrawingDisabled;
21250
21364
#ifdef FEAT_PROFILE
21251
21365
if (do_profiling == PROF_YES && (fp->uf_profiling
21252
|| (fc.caller != NULL && fc.caller->func->uf_profiling)))
21366
|| (fc->caller != NULL && fc->caller->func->uf_profiling)))
21254
21368
profile_end(&call_start);
21255
21369
profile_sub_wait(&wait_start, &call_start);
21256
21370
profile_add(&fp->uf_tm_total, &call_start);
21257
21371
profile_self(&fp->uf_tm_self, &call_start, &fp->uf_tm_children);
21258
if (fc.caller != NULL && fc.caller->func->uf_profiling)
21372
if (fc->caller != NULL && fc->caller->func->uf_profiling)
21260
profile_add(&fc.caller->func->uf_tm_children, &call_start);
21261
profile_add(&fc.caller->func->uf_tml_children, &call_start);
21374
profile_add(&fc->caller->func->uf_tm_children, &call_start);
21375
profile_add(&fc->caller->func->uf_tml_children, &call_start);
21272
21386
if (aborting())
21273
21387
smsg((char_u *)_("%s aborted"), sourcing_name);
21274
else if (fc.rettv->v_type == VAR_NUMBER)
21388
else if (fc->rettv->v_type == VAR_NUMBER)
21275
21389
smsg((char_u *)_("%s returning #%ld"), sourcing_name,
21276
(long)fc.rettv->vval.v_number);
21390
(long)fc->rettv->vval.v_number);
21279
21393
char_u buf[MSG_BUF_LEN];
21284
21398
/* The value may be very long. Skip the middle part, so that we
21285
21399
* have some idea how it starts and ends. smsg() would always
21286
21400
* truncate it at the end. */
21287
s = tv2string(fc.rettv, &tofree, numbuf2, 0);
21401
s = tv2string(fc->rettv, &tofree, numbuf2, 0);
21288
21402
if (s != NULL)
21290
21404
trunc_string(s, buf, MSG_BUF_CLEN);
21322
21436
did_emsg |= save_did_emsg;
21323
current_funccal = fc.caller;
21325
/* The a: variables typevals were not allocated, only free the allocated
21327
vars_clear_ext(&fc.l_avars.dv_hashtab, FALSE);
21329
vars_clear(&fc.l_vars.dv_hashtab); /* free all l: variables */
21437
current_funccal = fc->caller;
21440
/* if the a:000 list and the a: dict are not referenced we can free the
21441
* funccall_T and what's in it. */
21442
if (fc->l_varlist.lv_refcount == DO_NOT_FREE_CNT
21443
&& fc->l_vars.dv_refcount == DO_NOT_FREE_CNT
21444
&& fc->l_avars.dv_refcount == DO_NOT_FREE_CNT)
21446
free_funccal(fc, FALSE);
21454
/* "fc" is still in use. This can happen when returning "a:000" or
21455
* assigning "l:" to a global variable.
21456
* Link "fc" in the list for garbage collection later. */
21457
fc->caller = previous_funccal;
21458
previous_funccal = fc;
21460
/* Make a copy of the a: variables, since we didn't do that above. */
21461
todo = (int)fc->l_avars.dv_hashtab.ht_used;
21462
for (hi = fc->l_avars.dv_hashtab.ht_array; todo > 0; ++hi)
21464
if (!HASHITEM_EMPTY(hi))
21468
copy_tv(&v->di_tv, &v->di_tv);
21472
/* Make a copy of the a:000 items, since we didn't do that above. */
21473
for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
21474
copy_tv(&li->li_tv, &li->li_tv);
21479
* Return TRUE if items in "fc" do not have "copyID". That means they are not
21480
* referenced from anywyere.
21483
can_free_funccal(fc, copyID)
21487
return (fc->l_varlist.lv_copyID != copyID
21488
&& fc->l_vars.dv_copyID != copyID
21489
&& fc->l_avars.dv_copyID != copyID);
21493
* Free "fc" and what it contains.
21496
free_funccal(fc, free_val)
21498
int free_val; /* a: vars were allocated */
21502
/* The a: variables typevals may not have been allocated, only free the
21503
* allocated variables. */
21504
vars_clear_ext(&fc->l_avars.dv_hashtab, free_val);
21506
/* free all l: variables */
21507
vars_clear(&fc->l_vars.dv_hashtab);
21509
/* Free the a:000 variables if they were allocated. */
21511
for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
21512
clear_tv(&li->li_tv);
22088
* List v:oldfiles in a nice way.
22095
list_T *l = vimvars[VV_OLDFILES].vv_list;
22100
msg((char_u *)_("No old files"));
22105
for (li = l->lv_first; li != NULL && !got_int; li = li->li_next)
22107
msg_outnum((long)++nr);
22109
msg_outtrans(get_tv_string(&li->li_tv));
22111
out_flush(); /* output one line at a time */
22114
/* Assume "got_int" was set to truncate the listing. */
22117
#ifdef FEAT_BROWSE_CMD
22121
nr = prompt_for_number(FALSE);
22125
char_u *p = list_find_str(get_vim_var_list(VV_OLDFILES),
22130
p = expand_env_save(p);
22132
eap->cmdidx = CMD_edit;
22133
cmdmod.browse = FALSE;
22134
do_exedit(eap, NULL);
21903
22143
#endif /* FEAT_EVAL */