Skip to content

Commit 6e450a5

Browse files
committed
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)
1 parent 2872665 commit 6e450a5

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/evalfunc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9509,15 +9509,15 @@ do_searchpair(
95099509

95109510
/* Make two search patterns: start/end (pat2, for in nested pairs) and
95119511
* start/middle/end (pat3, for the top pair). */
9512-
pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 15));
9513-
pat3 = alloc((unsigned)(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 23));
9512+
pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 17));
9513+
pat3 = alloc((unsigned)(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 25));
95149514
if (pat2 == NULL || pat3 == NULL)
95159515
goto theend;
9516-
sprintf((char *)pat2, "\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat);
9516+
sprintf((char *)pat2, "\\m\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat);
95179517
if (*mpat == NUL)
95189518
STRCPY(pat3, pat2);
95199519
else
9520-
sprintf((char *)pat3, "\\(%s\\m\\)\\|\\(%s\\m\\)\\|\\(%s\\m\\)",
9520+
sprintf((char *)pat3, "\\m\\(%s\\m\\)\\|\\(%s\\m\\)\\|\\(%s\\m\\)",
95219521
spat, epat, mpat);
95229522
if (flags & SP_START)
95239523
options |= SEARCH_START;

src/testdir/test_search.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,18 @@ func Test_use_sub_pat()
279279
call X()
280280
bwipe!
281281
endfunc
282+
283+
func Test_searchpair()
284+
new
285+
call setline(1, ['other code here', '', '[', '" cursor here', ']'])
286+
4
287+
let a=searchpair('\[','',']','bW')
288+
call assert_equal(3, a)
289+
set nomagic
290+
4
291+
let a=searchpair('\[','',']','bW')
292+
call assert_equal(3, a)
293+
set magic
294+
q!
295+
endfunc
296+

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
147,
767769
/**/
768770
146,
769771
/**/

0 commit comments

Comments
 (0)