]> granicus.if.org Git - vim/commitdiff
patch 8.0.0147: searchpair() fails when 'magic' is off v8.0.0147
authorBram Moolenaar <Bram@vim.org>
Fri, 6 Jan 2017 19:03:58 +0000 (20:03 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 6 Jan 2017 19:03:58 +0000 (20:03 +0100)
Problem:    searchpair() does not work when 'magic' is off. (Chris Paul)
Solution:   Add \m in the pattern. (Christian Brabandt, closes #1341)

src/evalfunc.c
src/testdir/test_search.vim
src/version.c

index f1fa7401e1528facae1eb99fdbb25b85baee1f33..10f6b182e7f18d45c3e8582f6231c0348611af73 100644 (file)
@@ -9509,15 +9509,15 @@ do_searchpair(
 
     /* Make two search patterns: start/end (pat2, for in nested pairs) and
      * start/middle/end (pat3, for the top pair). */
-    pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 15));
-    pat3 = alloc((unsigned)(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 23));
+    pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 17));
+    pat3 = alloc((unsigned)(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 25));
     if (pat2 == NULL || pat3 == NULL)
        goto theend;
-    sprintf((char *)pat2, "\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat);
+    sprintf((char *)pat2, "\\m\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat);
     if (*mpat == NUL)
        STRCPY(pat3, pat2);
     else
-       sprintf((char *)pat3, "\\(%s\\m\\)\\|\\(%s\\m\\)\\|\\(%s\\m\\)",
+       sprintf((char *)pat3, "\\m\\(%s\\m\\)\\|\\(%s\\m\\)\\|\\(%s\\m\\)",
                                                            spat, epat, mpat);
     if (flags & SP_START)
        options |= SEARCH_START;
index 3b9aff4e7daf03fe29887d2fbedcc38dba4ae237..040a8098a87c78fafb132c051e038e6d3e27fafd 100644 (file)
@@ -279,3 +279,18 @@ func Test_use_sub_pat()
   call X()
   bwipe!
 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
+
index 775f7df21846b8a2b986215229442e12c3f1ff85..bd0220ff61880e21d41d42fd9a8dd8813a06284d 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    147,
 /**/
     146,
 /**/