2021-01-01 20:57:00 +08:00
|
|
|
" MIT License. Copyright (c) 2013-2021 Bailey Ling et al.
|
2020-06-28 04:56:57 +08:00
|
|
|
" 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
|
|
|
|
|
2020-07-21 13:08:21 +08:00
|
|
|
if !exists('*searchcount')
|
|
|
|
finish
|
|
|
|
endif
|
2020-06-28 04:56:57 +08:00
|
|
|
|
|
|
|
function! airline#extensions#searchcount#init(ext) abort
|
|
|
|
call a:ext.add_statusline_func('airline#extensions#searchcount#apply')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#searchcount#apply(...) abort
|
2020-07-21 13:35:22 +08:00
|
|
|
call airline#extensions#append_to_section('y',
|
2020-06-28 04:56:57 +08:00
|
|
|
\ '%{v:hlsearch ? airline#extensions#searchcount#status() : ""}')
|
|
|
|
endfunction
|
|
|
|
|
2021-01-03 03:25:00 +08:00
|
|
|
function! s:search_term()
|
|
|
|
" shorten for all width smaller than 300 (this is just a guess)
|
|
|
|
" this uses a non-breaking space, because it looks like
|
|
|
|
" a leading space is stripped :/
|
|
|
|
return "\ua0" . '/' . airline#util#shorten(getreg('/'), 300, 8)
|
|
|
|
endfunction
|
|
|
|
|
2020-06-28 04:56:57 +08:00
|
|
|
function! airline#extensions#searchcount#status() abort
|
2020-08-25 19:36:03 +08:00
|
|
|
try
|
|
|
|
let result = searchcount(#{recompute: 1, maxcount: -1})
|
|
|
|
if empty(result) || result.total ==# 0
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
if result.incomplete ==# 1 " timed out
|
2021-01-03 03:25:00 +08:00
|
|
|
return printf('%s [?/??]', s:search_term())
|
2020-08-25 19:36:03 +08:00
|
|
|
elseif result.incomplete ==# 2 " max count exceeded
|
|
|
|
if result.total > result.maxcount &&
|
|
|
|
\ result.current > result.maxcount
|
2021-01-03 03:25:00 +08:00
|
|
|
return printf('%s[>%d/>%d]', s:search_term(),
|
2020-08-25 19:36:03 +08:00
|
|
|
\ result.current, result.total)
|
|
|
|
elseif result.total > result.maxcount
|
2021-01-03 03:25:00 +08:00
|
|
|
return printf('%s[%d/>%d]', s:search_term(),
|
2020-08-25 19:36:03 +08:00
|
|
|
\ result.current, result.total)
|
|
|
|
endif
|
2020-06-28 04:56:57 +08:00
|
|
|
endif
|
2021-01-03 03:25:00 +08:00
|
|
|
return printf('%s[%d/%d]', s:search_term(),
|
2020-08-25 19:36:03 +08:00
|
|
|
\ result.current, result.total)
|
|
|
|
catch
|
|
|
|
return ''
|
|
|
|
endtry
|
2020-06-28 04:56:57 +08:00
|
|
|
endfunction
|