mirror of
https://github.com/vim-airline/vim-airline.git
synced 2024-12-02 22:13:53 +08:00
3a55368320
If the search regex causes an error, an ugly error message is thrown, so ignore errors in that case silently. closes #2216
44 lines
1.3 KiB
VimL
44 lines
1.3 KiB
VimL
" MIT License. Copyright (c) 2013-2020 Bailey Ling et al.
|
|
" This extension is inspired by vim-anzu <https://github.com/osyo-manga/vim-anzu>.
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
scriptencoding utf-8
|
|
|
|
if !exists('*searchcount')
|
|
finish
|
|
endif
|
|
|
|
function! airline#extensions#searchcount#init(ext) abort
|
|
call a:ext.add_statusline_func('airline#extensions#searchcount#apply')
|
|
endfunction
|
|
|
|
function! airline#extensions#searchcount#apply(...) abort
|
|
call airline#extensions#append_to_section('y',
|
|
\ '%{v:hlsearch ? airline#extensions#searchcount#status() : ""}')
|
|
endfunction
|
|
|
|
function! airline#extensions#searchcount#status() abort
|
|
try
|
|
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)
|
|
endif
|
|
endif
|
|
return printf('%s[%d/%d]', @/,
|
|
\ result.current, result.total)
|
|
catch
|
|
return ''
|
|
endtry
|
|
endfunction
|