searchcount: Ignore errors from searchcount() function

If the search regex causes an error, an ugly error message is thrown,
so ignore errors in that case silently.

closes #2216
This commit is contained in:
Christian Brabandt 2020-08-25 13:36:03 +02:00
parent ef4666bd86
commit 3a55368320
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
1 changed files with 21 additions and 17 deletions

View File

@ -18,22 +18,26 @@ function! airline#extensions#searchcount#apply(...) abort
endfunction
function! airline#extensions#searchcount#status() abort
let result = searchcount(#{recompute: 1, maxcount: -1})
if empty(result) || result.total ==# 0
return ''
endif
if result.incomplete ==# 1 " timed out
return printf(' /%s [?/??]', @/)
elseif result.incomplete ==# 2 " max count exceeded
if result.total > result.maxcount &&
\ result.current > result.maxcount
return printf('%s[>%d/>%d]', @/,
\ result.current, result.total)
elseif result.total > result.maxcount
return printf('%s[%d/>%d]', @/,
\ result.current, result.total)
try
let result = searchcount(#{recompute: 1, maxcount: -1})
if empty(result) || result.total ==# 0
return ''
endif
endif
return printf('%s[%d/%d]', @/,
\ result.current, result.total)
if result.incomplete ==# 1 " timed out
return printf(' /%s [?/??]', @/)
elseif result.incomplete ==# 2 " max count exceeded
if result.total > result.maxcount &&
\ result.current > result.maxcount
return printf('%s[>%d/>%d]', @/,
\ result.current, result.total)
elseif result.total > result.maxcount
return printf('%s[%d/>%d]', @/,
\ result.current, result.total)
endif
endif
return printf('%s[%d/%d]', @/,
\ result.current, result.total)
catch
return ''
endtry
endfunction