diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-07-22 21:50:18 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-07-22 21:50:18 +0200 |
commit | df48fb456fb6bf63d94cad9b302ff01d8ee8d311 (patch) | |
tree | e40ac7facad1b205bf5990a535c8c1686fbeb05b /src/userfunc.c | |
parent | 36edf0685c8b55ee3ce709058d83ada8027fec1e (diff) | |
download | vim-git-df48fb456fb6bf63d94cad9b302ff01d8ee8d311.tar.gz |
patch 7.4.2090v7.4.2090
Problem: Using submatch() in a lambda passed to substitute() is verbose.
Solution: Use a static list and pass it as an optional argument to the
function. Fix memory leak.
Diffstat (limited to 'src/userfunc.c')
-rw-r--r-- | src/userfunc.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/userfunc.c b/src/userfunc.c index ffbbc2d21..af1863f32 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -480,7 +480,7 @@ get_func_tv( &argvars[i]; } - ret = call_func(name, len, rettv, argcount, argvars, + ret = call_func(name, len, rettv, argcount, argvars, NULL, firstline, lastline, doesrange, evaluate, partial, selfdict); funcargs.ga_len -= i; @@ -1139,7 +1139,7 @@ func_call( } if (item == NULL) - r = call_func(name, (int)STRLEN(name), rettv, argc, argv, + r = call_func(name, (int)STRLEN(name), rettv, argc, argv, NULL, curwin->w_cursor.lnum, curwin->w_cursor.lnum, &dummy, TRUE, partial, selfdict); @@ -1152,6 +1152,11 @@ func_call( /* * Call a function with its resolved parameters + * + * "argv_func", when not NULL, can be used to fill in arguments only when the + * invoked function uses them. It is called like this: + * new_argcount = argv_func(current_argcount, argv, called_func_argcount) + * * Return FAIL when the function can't be called, OK otherwise. * Also returns OK when an error was encountered while executing the function. */ @@ -1163,6 +1168,8 @@ call_func( int argcount_in, /* number of "argvars" */ typval_T *argvars_in, /* vars for arguments, must have "argcount" PLUS ONE elements! */ + int (* argv_func)(int, typval_T *, int), + /* function to fill in argvars */ linenr_T firstline, /* first line of range */ linenr_T lastline, /* last line of range */ int *doesrange, /* return: function handled range */ @@ -1254,6 +1261,9 @@ call_func( if (fp != NULL) { + if (argv_func != NULL) + argcount = argv_func(argcount, argvars, fp->uf_args.ga_len); + if (fp->uf_flags & FC_RANGE) *doesrange = TRUE; if (argcount < fp->uf_args.ga_len) |