Problem: Using searchcount() in 'statusline' causes an error.
Solution: Avoid saving/restoring the search patten recursively.
(closes #6194)
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)
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;
--- /dev/null
+|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
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
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 902,
/**/
901,
/**/