diff options
Diffstat (limited to 'src/nvim/regexp.c')
-rw-r--r-- | src/nvim/regexp.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index e0cc25421a..c2ef217638 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -692,6 +692,7 @@ static char_u *regparse; ///< Input-scan pointer. static int prevchr_len; ///< byte length of previous char static int num_complex_braces; ///< Complex \{...} count static int regnpar; ///< () count. +static bool wants_nfa; ///< regex should use NFA engine static int regnzpar; ///< \z() count. static int re_has_z; ///< \z item detected static char_u *regcode; ///< Code-emit pointer, or JUST_CALC_SIZE @@ -2911,7 +2912,7 @@ static int peekchr(void) at_start = false; // be able to say "/\*ptr" regparse++; after_slash++; - peekchr(); + (void)peekchr(); regparse--; after_slash--; curchr = toggle_Magic(curchr); @@ -3754,6 +3755,7 @@ static bool reg_match_visual(void) int mode; colnr_T start, end; colnr_T start2, end2; + colnr_T curswant; // Check if the buffer is the current buffer. if (rex.reg_buf != curbuf || VIsual.lnum == 0) { @@ -3769,6 +3771,7 @@ static bool reg_match_visual(void) bot = VIsual; } mode = VIsual_mode; + curswant = wp->w_curswant; } else { if (lt(curbuf->b_visual.vi_start, curbuf->b_visual.vi_end)) { top = curbuf->b_visual.vi_start; @@ -3778,6 +3781,7 @@ static bool reg_match_visual(void) bot = curbuf->b_visual.vi_start; } mode = curbuf->b_visual.vi_mode; + curswant = curbuf->b_visual.vi_curswant; } lnum = rex.lnum + rex.reg_firstlnum; if (lnum < top.lnum || lnum > bot.lnum) { @@ -3797,8 +3801,9 @@ static bool reg_match_visual(void) start = start2; if (end2 > end) end = end2; - if (top.col == MAXCOL || bot.col == MAXCOL) + if (top.col == MAXCOL || bot.col == MAXCOL || curswant == MAXCOL) { end = MAXCOL; + } unsigned int cols_u = win_linetabsize(wp, rex.line, (colnr_T)(rex.input - rex.line)); assert(cols_u <= MAXCOL); @@ -3974,17 +3979,25 @@ static bool regmatch( pos = getmark_buf(rex.reg_buf, mark, false); if (pos == NULL // mark doesn't exist - || pos->lnum <= 0 // mark isn't set in reg_buf - || (pos->lnum == rex.lnum + rex.reg_firstlnum - ? (pos->col == (colnr_T)(rex.input - rex.line) - ? (cmp == '<' || cmp == '>') - : (pos->col < (colnr_T)(rex.input - rex.line) - ? cmp != '>' - : cmp != '<')) - : (pos->lnum < rex.lnum + rex.reg_firstlnum - ? cmp != '>' - : cmp != '<'))) { + || pos->lnum <= 0) { // mark isn't set in reg_buf status = RA_NOMATCH; + } else { + const colnr_T pos_col = pos->lnum == rex.lnum + rex.reg_firstlnum + && pos->col == MAXCOL + ? (colnr_T)STRLEN(reg_getline(pos->lnum - rex.reg_firstlnum)) + : pos->col; + + if (pos->lnum == rex.lnum + rex.reg_firstlnum + ? (pos_col == (colnr_T)(rex.input - rex.line) + ? (cmp == '<' || cmp == '>') + : (pos_col < (colnr_T)(rex.input - rex.line) + ? cmp != '>' + : cmp != '<')) + : (pos->lnum < rex.lnum + rex.reg_firstlnum + ? cmp != '>' + : cmp != '<')) { + status = RA_NOMATCH; + } } } break; @@ -7240,7 +7253,7 @@ regprog_T *vim_regcomp(char_u *expr_arg, int re_flags) // Check for error compiling regexp with initial engine. if (prog == NULL) { #ifdef BT_REGEXP_DEBUG_LOG - // Debugging log for NFA. + // Debugging log for BT engine. if (regexp_engine != BACKTRACKING_ENGINE) { FILE *f = fopen(BT_REGEXP_DEBUG_LOG_NAME, "a"); if (f) { @@ -7257,6 +7270,7 @@ regprog_T *vim_regcomp(char_u *expr_arg, int re_flags) // But don't try if an error message was given. if (regexp_engine == AUTOMATIC_ENGINE && !called_emsg) { regexp_engine = BACKTRACKING_ENGINE; + report_re_switch(expr); prog = bt_regengine.regcomp(expr, re_flags); } } |