Skip to content

Commit 8bb6902

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 0e351c1 + bc7ce67 commit 8bb6902

24 files changed

Lines changed: 702 additions & 355 deletions

runtime/doc/eval.txt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 7.4. Last change: 2016 Jul 29
1+
*eval.txt* For Vim version 7.4. Last change: 2016 Jul 31
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1240,7 +1240,9 @@ function returns: >
12401240
:let Bar = Foo(4)
12411241
:echo Bar(6)
12421242
< 5
1243-
See also |:func-closure|.
1243+
1244+
See also |:func-closure|. Lambda and closure support can be checked with: >
1245+
if has('lambda')
12441246
12451247
Examples for using a lambda expression with |sort()|, |map()| and |filter()|: >
12461248
:echo map([1, 2, 3], {idx, val -> val + 1})
@@ -2071,8 +2073,10 @@ foldlevel({lnum}) Number fold level at {lnum}
20712073
foldtext() String line displayed for closed fold
20722074
foldtextresult({lnum}) String text for closed fold at {lnum}
20732075
foreground() Number bring the Vim window to the foreground
2074-
function({name} [, {arglist}] [, {dict}])
2076+
funcref({name} [, {arglist}] [, {dict}])
20752077
Funcref reference to function {name}
2078+
function({name} [, {arglist}] [, {dict}])
2079+
Funcref named reference to function {name}
20762080
garbagecollect([{atexit}]) none free memory, breaking cyclic references
20772081
get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
20782082
get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
@@ -3850,19 +3854,32 @@ foreground() Move the Vim window to the foreground. Useful when sent from
38503854
{only in the Win32, Athena, Motif and GTK GUI versions and the
38513855
Win32 console version}
38523856

3857+
*funcref()*
3858+
funcref({name} [, {arglist}] [, {dict}])
3859+
Just like |function()|, but the returned Funcref will lookup
3860+
the function by reference, not by name. This matters when the
3861+
function {name} is redefined later.
3862+
3863+
Unlike |function()|, {name} must be an existing user function.
3864+
Also for autoloaded functions. {name} cannot be a builtin
3865+
function.
38533866

38543867
*function()* *E700* *E922* *E923*
38553868
function({name} [, {arglist}] [, {dict}])
38563869
Return a |Funcref| variable that refers to function {name}.
38573870
{name} can be the name of a user defined function or an
38583871
internal function.
38593872

3860-
{name} can also be a Funcref, also a partial. When it is a
3873+
{name} can also be a Funcref or a partial. When it is a
38613874
partial the dict stored in it will be used and the {dict}
38623875
argument is not allowed. E.g.: >
38633876
let FuncWithArg = function(dict.Func, [arg])
38643877
let Broken = function(dict.Func, [arg], dict)
38653878
<
3879+
When using the Funcref the function will be found by {name},
3880+
also when it was redefined later. Use |funcref()| to keep the
3881+
same function.
3882+
38663883
When {arglist} or {dict} is present this creates a partial.
38673884
That means the argument list and/or the dictionary is stored in
38683885
the Funcref and will be used when the Funcref is called.
@@ -6191,6 +6208,7 @@ screenrow() *screenrow()*
61916208
The result is a Number, which is the current screen row of the
61926209
cursor. The top line has number one.
61936210
This function is mainly used for testing.
6211+
Alternatively you can use |winline()|.
61946212

61956213
Note: Same restrictions as with |screencol()|.
61966214

@@ -8041,6 +8059,7 @@ insert_expand Compiled with support for CTRL-X expansion commands in
80418059
Insert mode.
80428060
jumplist Compiled with |jumplist| support.
80438061
keymap Compiled with 'keymap' support.
8062+
lambda Compiled with |lambda| support.
80448063
langmap Compiled with 'langmap' support.
80458064
libcall Compiled with |libcall()| support.
80468065
linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
@@ -8298,7 +8317,7 @@ See |:verbose-cmd| for more information.
82988317
:endf[unction] The end of a function definition. Must be on a line
82998318
by its own, without other commands.
83008319

8301-
*:delf* *:delfunction* *E130* *E131*
8320+
*:delf* *:delfunction* *E130* *E131* *E933*
83028321
:delf[unction] {name} Delete function {name}.
83038322
{name} can also be a |Dictionary| entry that is a
83048323
|Funcref|: >

runtime/menu.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" You can also use this as a start for your own set of menus.
33
"
44
" Maintainer: Bram Moolenaar <[email protected]>
5-
" Last Change: 2014 May 22
5+
" Last Change: 2016 Jul 27
66

77
" Note that ":an" (short for ":anoremenu") is often used to make a menu work
88
" in all modes and avoid side effects from mappings defined by the user.

src/INSTALLpc.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Building with Visual Studio (VS 98, VS .NET, VS .NET 2003, VS 2005, VS 2008,
4949
VS2010, VS2012, VS2013 and VS2015) is straightforward. (These instructions
5050
should also work for VS 4 and VS 5.)
5151

52-
Using VS C++ 2008 Express is recommended, the binaries build with that run on
52+
Using VS C++ 2008 Express is recommended, the binaries built with that run on
5353
nearly all platforms. Binaries from later versions may not run on Windows 95
5454
or XP.
5555

src/channel.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,15 +1145,18 @@ set_callback(
11451145
if (callback != NULL && *callback != NUL)
11461146
{
11471147
if (partial != NULL)
1148-
*cbp = partial->pt_name;
1148+
*cbp = partial_name(partial);
11491149
else
1150+
{
11501151
*cbp = vim_strsave(callback);
1152+
func_ref(*cbp);
1153+
}
11511154
}
11521155
else
11531156
*cbp = NULL;
11541157
*pp = partial;
1155-
if (*pp != NULL)
1156-
++(*pp)->pt_refcount;
1158+
if (partial != NULL)
1159+
++partial->pt_refcount;
11571160
}
11581161

11591162
/*
@@ -1300,7 +1303,10 @@ channel_set_req_callback(
13001303
item->cq_callback = callback;
13011304
}
13021305
else
1306+
{
13031307
item->cq_callback = vim_strsave(callback);
1308+
func_ref(item->cq_callback);
1309+
}
13041310
item->cq_seq_nr = id;
13051311
item->cq_prev = head->cq_prev;
13061312
head->cq_prev = item;
@@ -3948,14 +3954,24 @@ free_job_options(jobopt_T *opt)
39483954
{
39493955
if (opt->jo_partial != NULL)
39503956
partial_unref(opt->jo_partial);
3957+
else if (opt->jo_callback != NULL)
3958+
func_unref(opt->jo_callback);
39513959
if (opt->jo_out_partial != NULL)
39523960
partial_unref(opt->jo_out_partial);
3961+
else if (opt->jo_out_cb != NULL)
3962+
func_unref(opt->jo_out_cb);
39533963
if (opt->jo_err_partial != NULL)
39543964
partial_unref(opt->jo_err_partial);
3965+
else if (opt->jo_err_cb != NULL)
3966+
func_unref(opt->jo_err_cb);
39553967
if (opt->jo_close_partial != NULL)
39563968
partial_unref(opt->jo_close_partial);
3969+
else if (opt->jo_close_cb != NULL)
3970+
func_unref(opt->jo_close_cb);
39573971
if (opt->jo_exit_partial != NULL)
39583972
partial_unref(opt->jo_exit_partial);
3973+
else if (opt->jo_exit_cb != NULL)
3974+
func_unref(opt->jo_exit_cb);
39593975
}
39603976

39613977
/*
@@ -4501,7 +4517,10 @@ job_set_options(job_T *job, jobopt_T *opt)
45014517
++job->jv_exit_partial->pt_refcount;
45024518
}
45034519
else
4520+
{
45044521
job->jv_exit_cb = vim_strsave(opt->jo_exit_cb);
4522+
func_ref(job->jv_exit_cb);
4523+
}
45054524
}
45064525
}
45074526
}

src/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ diff_buf_add(buf_T *buf)
135135
return;
136136
}
137137

138-
EMSGN(_("E96: Can not diff more than %ld buffers"), DB_COUNT);
138+
EMSGN(_("E96: Cannot diff more than %ld buffers"), DB_COUNT);
139139
}
140140

141141
/*

src/digraph.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2460,4 +2460,3 @@ keymap_unload(void)
24602460
}
24612461

24622462
#endif /* FEAT_KEYMAP */
2463-

src/eval.c

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,7 +2838,7 @@ do_unlet(char_u *name, int forceit)
28382838
}
28392839
hi = hash_find(ht, varname);
28402840
if (HASHITEM_EMPTY(hi))
2841-
hi = find_hi_in_scoped_ht(name, &varname, &ht);
2841+
hi = find_hi_in_scoped_ht(name, &ht);
28422842
if (hi != NULL && !HASHITEM_EMPTY(hi))
28432843
{
28442844
di = HI2DI(hi);
@@ -5011,6 +5011,17 @@ get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate)
50115011
return OK;
50125012
}
50135013

5014+
/*
5015+
* Return the function name of the partial.
5016+
*/
5017+
char_u *
5018+
partial_name(partial_T *pt)
5019+
{
5020+
if (pt->pt_name != NULL)
5021+
return pt->pt_name;
5022+
return pt->pt_func->uf_name;
5023+
}
5024+
50145025
static void
50155026
partial_free(partial_T *pt)
50165027
{
@@ -5020,8 +5031,13 @@ partial_free(partial_T *pt)
50205031
clear_tv(&pt->pt_argv[i]);
50215032
vim_free(pt->pt_argv);
50225033
dict_unref(pt->pt_dict);
5023-
func_unref(pt->pt_name);
5024-
vim_free(pt->pt_name);
5034+
if (pt->pt_name != NULL)
5035+
{
5036+
func_unref(pt->pt_name);
5037+
vim_free(pt->pt_name);
5038+
}
5039+
else
5040+
func_ptr_unref(pt->pt_func);
50255041
vim_free(pt);
50265042
}
50275043

@@ -5051,11 +5067,11 @@ func_equal(
50515067

50525068
/* empty and NULL function name considered the same */
50535069
s1 = tv1->v_type == VAR_FUNC ? tv1->vval.v_string
5054-
: tv1->vval.v_partial->pt_name;
5070+
: partial_name(tv1->vval.v_partial);
50555071
if (s1 != NULL && *s1 == NUL)
50565072
s1 = NULL;
50575073
s2 = tv2->v_type == VAR_FUNC ? tv2->vval.v_string
5058-
: tv2->vval.v_partial->pt_name;
5074+
: partial_name(tv2->vval.v_partial);
50595075
if (s2 != NULL && *s2 == NUL)
50605076
s2 = NULL;
50615077
if (s1 == NULL || s2 == NULL)
@@ -5288,6 +5304,9 @@ garbage_collect(int testing)
52885304
/* function-local variables */
52895305
abort = abort || set_ref_in_call_stack(copyID);
52905306

5307+
/* named functions (matters for closures) */
5308+
abort = abort || set_ref_in_functions(copyID);
5309+
52915310
/* function call arguments, if v:testing is set. */
52925311
abort = abort || set_ref_in_func_args(copyID);
52935312

@@ -5550,7 +5569,7 @@ set_ref_in_item(
55505569
}
55515570
else if (tv->v_type == VAR_FUNC)
55525571
{
5553-
abort = set_ref_in_func(tv->vval.v_string, copyID);
5572+
abort = set_ref_in_func(tv->vval.v_string, NULL, copyID);
55545573
}
55555574
else if (tv->v_type == VAR_PARTIAL)
55565575
{
@@ -5561,7 +5580,7 @@ set_ref_in_item(
55615580
*/
55625581
if (pt != NULL)
55635582
{
5564-
abort = set_ref_in_func(pt->pt_name, copyID);
5583+
abort = set_ref_in_func(pt->pt_name, pt->pt_func, copyID);
55655584

55665585
if (pt->pt_dict != NULL)
55675586
{
@@ -5735,7 +5754,7 @@ echo_string_core(
57355754
{
57365755
partial_T *pt = tv->vval.v_partial;
57375756
char_u *fname = string_quote(pt == NULL ? NULL
5738-
: pt->pt_name, FALSE);
5757+
: partial_name(pt), FALSE);
57395758
garray_T ga;
57405759
int i;
57415760
char_u *tf;
@@ -6871,7 +6890,7 @@ handle_subscript(
68716890
if (functv.v_type == VAR_PARTIAL)
68726891
{
68736892
pt = functv.vval.v_partial;
6874-
s = pt->pt_name;
6893+
s = partial_name(pt);
68756894
}
68766895
else
68776896
s = functv.vval.v_string;
@@ -7328,8 +7347,7 @@ find_var(char_u *name, hashtab_T **htp, int no_autoload)
73287347
return ret;
73297348

73307349
/* Search in parent scope for lambda */
7331-
return find_var_in_scoped_ht(name, varname ? &varname : NULL,
7332-
no_autoload || htp != NULL);
7350+
return find_var_in_scoped_ht(name, no_autoload || htp != NULL);
73337351
}
73347352

73357353
/*
@@ -7668,7 +7686,7 @@ set_var(
76687686

76697687
/* Search in parent scope which is possible to reference from lambda */
76707688
if (v == NULL)
7671-
v = find_var_in_scoped_ht(name, varname ? &varname : NULL, TRUE);
7689+
v = find_var_in_scoped_ht(name, TRUE);
76727690

76737691
if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL)
76747692
&& var_check_func_name(name, v == NULL))
@@ -7813,7 +7831,7 @@ var_check_func_name(
78137831
/* Don't allow hiding a function. When "v" is not NULL we might be
78147832
* assigning another function to the same var, the type is checked
78157833
* below. */
7816-
if (new_var && function_exists(name))
7834+
if (new_var && function_exists(name, FALSE))
78177835
{
78187836
EMSG2(_("E705: Variable name conflicts with existing function: %s"),
78197837
name);
@@ -10025,7 +10043,7 @@ filter_map_one(typval_T *tv, typval_T *expr, int map, int *remp)
1002510043
{
1002610044
partial_T *partial = expr->vval.v_partial;
1002710045

10028-
s = partial->pt_name;
10046+
s = partial_name(partial);
1002910047
if (call_func(s, (int)STRLEN(s), &rettv, 2, argv, NULL,
1003010048
0L, 0L, &dummy, TRUE, partial, NULL) == FAIL)
1003110049
goto theend;

0 commit comments

Comments
 (0)