summaryrefslogtreecommitdiffstats
path: root/src/evalfunc.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-10-30 21:48:41 +0100
committerBram Moolenaar <Bram@vim.org>2017-10-30 21:48:41 +0100
commit48570488f17e397183ea7d5c7ca67d6e4ffb013d (patch)
treef9bbc935f2f0d999e16d047056c747168791cb3e /src/evalfunc.c
parent2e51d9a0972080b087d566608472928d5b7b35d7 (diff)
patch 8.0.1239: cannot use a lambda for the skip argument to searchpair()v8.0.1239
Problem: Cannot use a lambda for the skip argument to searchpair(). Solution: Evaluate a partial, funcref and lambda. (LemonBoy, closes #1454, closes #2265)
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r--src/evalfunc.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 2f294ca1ff..25536af2e0 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -9531,13 +9531,12 @@ f_searchdecl(typval_T *argvars, typval_T *rettv)
searchpair_cmn(typval_T *argvars, pos_T *match_pos)
{
char_u *spat, *mpat, *epat;
- char_u *skip;
+ typval_T *skip;
int save_p_ws = p_ws;
int dir;
int flags = 0;
char_u nbuf1[NUMBUFLEN];
char_u nbuf2[NUMBUFLEN];
- char_u nbuf3[NUMBUFLEN];
int retval = 0; /* default: FAIL */
long lnum_stop = 0;
long time_limit = 0;
@@ -9571,10 +9570,16 @@ searchpair_cmn(typval_T *argvars, pos_T *match_pos)
/* Optional fifth argument: skip expression */
if (argvars[3].v_type == VAR_UNKNOWN
|| argvars[4].v_type == VAR_UNKNOWN)
- skip = (char_u *)"";
+ skip = NULL;
else
{
- skip = get_tv_string_buf_chk(&argvars[4], nbuf3);
+ skip = &argvars[4];
+ if (skip->v_type != VAR_FUNC && skip->v_type != VAR_PARTIAL
+ && skip->v_type != VAR_STRING)
+ {
+ /* Type error */
+ goto theend;
+ }
if (argvars[5].v_type != VAR_UNKNOWN)
{
lnum_stop = (long)get_tv_number_chk(&argvars[5], NULL);
@@ -9590,8 +9595,6 @@ searchpair_cmn(typval_T *argvars, pos_T *match_pos)
#endif
}
}
- if (skip == NULL)
- goto theend; /* type error */
retval = do_searchpair(spat, mpat, epat, dir, skip, flags,
match_pos, lnum_stop, time_limit);
@@ -9645,7 +9648,7 @@ do_searchpair(
char_u *mpat, /* middle pattern */
char_u *epat, /* end pattern */
int dir, /* BACKWARD or FORWARD */
- char_u *skip, /* skip expression */
+ typval_T *skip, /* skip expression */
int flags, /* SP_SETPCMARK and other SP_ values */
pos_T *match_pos,
linenr_T lnum_stop, /* stop at this line if not zero */
@@ -9662,6 +9665,7 @@ do_searchpair(
int n;
int r;
int nest = 1;
+ int use_skip = FALSE;
int err;
int options = SEARCH_KEEP;
proftime_T tm;
@@ -9690,6 +9694,14 @@ do_searchpair(
if (flags & SP_START)
options |= SEARCH_START;
+ if (skip != NULL)
+ {
+ /* Empty string means to not use the skip expression. */
+ if (skip->v_type == VAR_STRING || skip->v_type == VAR_FUNC)
+ use_skip = skip->vval.v_string != NULL
+ && *skip->vval.v_string != NUL;
+ }
+
save_cursor = curwin->w_cursor;
pos = curwin->w_cursor;
CLEAR_POS(&firstpos);
@@ -9721,11 +9733,12 @@ do_searchpair(
options &= ~SEARCH_START;
/* If the skip pattern matches, ignore this match. */
- if (*skip != NUL)
+ if (use_skip)
{
save_pos = curwin->w_cursor;
curwin->w_cursor = pos;
- r = eval_to_bool(skip, &err, NULL, FALSE);
+ err = FALSE;
+ r = eval_expr_to_bool(skip, &err);
curwin->w_cursor = save_pos;
if (err)
{