1
0
forked from aniani/vim

patch 8.0.0147: searchpair() fails when 'magic' is off

Problem:    searchpair() does not work when 'magic' is off. (Chris Paul)
Solution:   Add \m in the pattern. (Christian Brabandt, closes #1341)
This commit is contained in:
Bram Moolenaar
2017-01-06 20:03:58 +01:00
parent 287266527a
commit 6e450a5754
3 changed files with 21 additions and 4 deletions

View File

@@ -9509,15 +9509,15 @@ do_searchpair(
/* Make two search patterns: start/end (pat2, for in nested pairs) and /* Make two search patterns: start/end (pat2, for in nested pairs) and
* start/middle/end (pat3, for the top pair). */ * start/middle/end (pat3, for the top pair). */
pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 15)); pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 17));
pat3 = alloc((unsigned)(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 23)); pat3 = alloc((unsigned)(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 25));
if (pat2 == NULL || pat3 == NULL) if (pat2 == NULL || pat3 == NULL)
goto theend; goto theend;
sprintf((char *)pat2, "\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat); sprintf((char *)pat2, "\\m\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat);
if (*mpat == NUL) if (*mpat == NUL)
STRCPY(pat3, pat2); STRCPY(pat3, pat2);
else else
sprintf((char *)pat3, "\\(%s\\m\\)\\|\\(%s\\m\\)\\|\\(%s\\m\\)", sprintf((char *)pat3, "\\m\\(%s\\m\\)\\|\\(%s\\m\\)\\|\\(%s\\m\\)",
spat, epat, mpat); spat, epat, mpat);
if (flags & SP_START) if (flags & SP_START)
options |= SEARCH_START; options |= SEARCH_START;

View File

@@ -279,3 +279,18 @@ func Test_use_sub_pat()
call X() call X()
bwipe! bwipe!
endfunc endfunc
func Test_searchpair()
new
call setline(1, ['other code here', '', '[', '" cursor here', ']'])
4
let a=searchpair('\[','',']','bW')
call assert_equal(3, a)
set nomagic
4
let a=searchpair('\[','',']','bW')
call assert_equal(3, a)
set magic
q!
endfunc

View File

@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
147,
/**/ /**/
146, 146,
/**/ /**/