summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-06-04 20:56:09 +0200
committerBram Moolenaar <Bram@vim.org>2020-06-04 20:56:09 +0200
commit442a85369f3eb9834dbab42add45f7c4106700f4 (patch)
tree4eb3d8f317235ee838653441c45e8bf3fcee8b16 /src
parente52702f00322c8a8861efd0bd6a3775e685e5685 (diff)
downloadvim-git-442a85369f3eb9834dbab42add45f7c4106700f4.tar.gz
patch 8.2.0902: using searchcount() in 'statusline' causes an errorv8.2.0902
Problem: Using searchcount() in 'statusline' causes an error. Solution: Avoid saving/restoring the search patten recursively. (closes #6194)
Diffstat (limited to 'src')
-rw-r--r--src/search.c15
-rw-r--r--src/testdir/dumps/Test_searchstat_4.dump10
-rw-r--r--src/testdir/test_search_stat.vim28
-rw-r--r--src/version.c2
4 files changed, 48 insertions, 7 deletions
diff --git a/src/search.c b/src/search.c
index 7346383fc..7a4cdb7b6 100644
--- a/src/search.c
+++ b/src/search.c
@@ -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
index 000000000..899c8fb90
--- /dev/null
+++ b/src/testdir/dumps/Test_searchstat_4.dump
@@ -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
diff --git a/src/testdir/test_search_stat.vim b/src/testdir/test_search_stat.vim
index 85e4f866e..7c4e13f48 100644
--- a/src/testdir/test_search_stat.vim
+++ b/src/testdir/test_search_stat.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index 291744e4e..bb183674f 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 902,
+/**/
901,
/**/
900,