mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 13:15:09 -07:00
vim-patch:8.2.0902: using searchcount() in 'statusline' causes an error
Problem: Using searchcount() in 'statusline' causes an error.
Solution: Avoid saving/restoring the search patten recursively.
(closes vim/vim#6194)
442a85369f
This commit is contained in:
parent
ce32545708
commit
4327fe8da5
@ -320,10 +320,9 @@ static bool saved_no_hlsearch = false;
|
|||||||
/// cancelling incremental searching even if it's called inside user functions.
|
/// cancelling incremental searching even if it's called inside user functions.
|
||||||
void save_last_search_pattern(void)
|
void save_last_search_pattern(void)
|
||||||
{
|
{
|
||||||
if (did_save_last_search_spat != 0) {
|
if (++did_save_last_search_spat != 1) {
|
||||||
IEMSG("did_save_last_search_spat is not zero");
|
// nested call, nothing to do
|
||||||
} else {
|
return;
|
||||||
did_save_last_search_spat++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saved_last_search_spat = spats[RE_SEARCH];
|
saved_last_search_spat = spats[RE_SEARCH];
|
||||||
@ -336,11 +335,15 @@ void save_last_search_pattern(void)
|
|||||||
|
|
||||||
void restore_last_search_pattern(void)
|
void restore_last_search_pattern(void)
|
||||||
{
|
{
|
||||||
if (did_save_last_search_spat != 1) {
|
if (--did_save_last_search_spat > 0) {
|
||||||
IEMSG("did_save_last_search_spat is not one");
|
// nested call, nothing to do
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (did_save_last_search_spat != 0) {
|
||||||
|
iemsg("restore_last_search_pattern() called more often than"
|
||||||
|
" save_last_search_pattern()");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
did_save_last_search_spat--;
|
|
||||||
|
|
||||||
xfree(spats[RE_SEARCH].pat);
|
xfree(spats[RE_SEARCH].pat);
|
||||||
spats[RE_SEARCH] = saved_last_search_spat;
|
spats[RE_SEARCH] = saved_last_search_spat;
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
" as test!
|
" as test!
|
||||||
|
|
||||||
source shared.vim
|
source shared.vim
|
||||||
|
source screendump.vim
|
||||||
|
source check.vim
|
||||||
|
|
||||||
func! Test_search_stat()
|
func! Test_search_stat()
|
||||||
new
|
new
|
||||||
@ -164,3 +166,31 @@ func! Test_search_stat()
|
|||||||
set shortmess+=S
|
set shortmess+=S
|
||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user