]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.0902: using searchcount() in 'statusline' causes an error v8.2.0902
authorBram Moolenaar <Bram@vim.org>
Thu, 4 Jun 2020 18:56:09 +0000 (20:56 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 4 Jun 2020 18:56:09 +0000 (20:56 +0200)
Problem:    Using searchcount() in 'statusline' causes an error.
Solution:   Avoid saving/restoring the search patten recursively.
            (closes #6194)

src/search.c
src/testdir/dumps/Test_searchstat_4.dump [new file with mode: 0644]
src/testdir/test_search_stat.vim
src/version.c

index 7346383fc5c4e2f43d41fc18bbde129fd684eac6..7a4cdb7b6c39ba1ec09bb4b4676a16f47d3d2e1d 100644 (file)
@@ -356,10 +356,9 @@ static int     saved_no_hlsearch = 0;
     void
 save_last_search_pattern(void)
 {
-    if (did_save_last_search_spat != 0)
-       iemsg("did_save_last_search_spat is not zero");
-    else
-       ++did_save_last_search_spat;
+    if (++did_save_last_search_spat != 1)
+       // nested call, nothing to do
+       return;
 
     saved_last_search_spat = spats[RE_SEARCH];
     if (spats[RE_SEARCH].pat != NULL)
@@ -371,12 +370,14 @@ save_last_search_pattern(void)
     void
 restore_last_search_pattern(void)
 {
-    if (did_save_last_search_spat != 1)
+    if (--did_save_last_search_spat > 0)
+       // nested call, nothing to do
+       return;
+    if (did_save_last_search_spat != 0)
     {
-       iemsg("did_save_last_search_spat is not one");
+       iemsg("restore_last_search_pattern() called more often than save_last_search_pattern()");
        return;
     }
-    --did_save_last_search_spat;
 
     vim_free(spats[RE_SEARCH].pat);
     spats[RE_SEARCH] = saved_last_search_spat;
diff --git a/src/testdir/dumps/Test_searchstat_4.dump b/src/testdir/dumps/Test_searchstat_4.dump
new file mode 100644 (file)
index 0000000..899c8fb
--- /dev/null
@@ -0,0 +1,10 @@
+|t+0&#ffffff0|h|i|s| |i|s| |s+1&&|o|m|e|t|h|i|n|g| +0&&@57
+@75
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|[+3#0000000&|1|/|1|]| @69
+|/+0&&|s|o|m|e|t|h|i|n|g> @64
index 85e4f866ef358470930cae39a871c2de8cdbee92..7c4e13f4825a6fbf581fa46e96ec55f3b524d3f9 100644 (file)
@@ -263,6 +263,34 @@ func Test_searchcount_fails()
   call assert_fails('echo searchcount("boo!")', 'E715:')
 endfunc
 
+func Test_searchcount_in_statusline()
+  CheckScreendump
+
+  let lines =<< trim END
+    set shortmess-=S
+    call append(0, 'this is something')
+    function TestSearchCount() abort
+      let search_count = searchcount()
+      if !empty(search_count)
+       return '[' . search_count.current . '/' . search_count.total . ']'
+      else
+       return ''
+      endif
+    endfunction
+    set hlsearch
+    set laststatus=2 statusline+=%{TestSearchCount()}
+  END
+  call writefile(lines, 'Xsearchstatusline')
+  let buf = RunVimInTerminal('-S Xsearchstatusline', #{rows: 10})
+  call TermWait(buf)
+  call term_sendkeys(buf, "/something")
+  call VerifyScreenDump(buf, 'Test_searchstat_4', {})
+
+  call term_sendkeys(buf, "\<Esc>")
+  call StopVimInTerminal(buf)
+  call delete('Xsearchstatusline')
+endfunc
+
 func Test_search_stat_foldopen()
   CheckScreendump
 
index 291744e4e62d3c163e7c8db03f5d5f5a4f30feb6..bb183674f4830bb2f469c480712301b3a69acaa5 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    902,
 /**/
     901,
 /**/