mirror of
https://github.com/vim-airline/vim-airline.git
synced 2025-07-24 22:45:12 +02:00
Merge pull request #2161 from kazukazuinaina/add_support_searchcount
[RFC] Add support for searchcount extension
This commit is contained in:
commit
ba9b3e1839
@ -428,6 +428,11 @@ function! airline#extensions#load()
|
|||||||
call add(s:loaded_ext, 'cursormode')
|
call add(s:loaded_ext, 'cursormode')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if get(g:, 'airline#extensions#searchcount#enabled', 1) && exists('*searchcount')
|
||||||
|
call airline#extensions#searchcount#init(s:ext)
|
||||||
|
call add(s:loaded_ext, 'searchcount')
|
||||||
|
endif
|
||||||
|
|
||||||
if !get(g:, 'airline#extensions#disable_rtp_load', 0)
|
if !get(g:, 'airline#extensions#disable_rtp_load', 0)
|
||||||
" load all other extensions, which are not part of the default distribution.
|
" load all other extensions, which are not part of the default distribution.
|
||||||
" (autoload/airline/extensions/*.vim outside of our s:script_path).
|
" (autoload/airline/extensions/*.vim outside of our s:script_path).
|
||||||
|
47
autoload/airline/extensions/searchcount.vim
Normal file
47
autoload/airline/extensions/searchcount.vim
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
" 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
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
let result = searchcount(#{recompute: 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)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
autocmd CursorMoved *
|
||||||
|
\ let s:searchcount_timer = timer_start(
|
||||||
|
\ 10, function('s:update_searchcount'))
|
||||||
|
|
||||||
|
function! s:update_searchcount(timer) abort
|
||||||
|
if a:timer ==# s:searchcount_timer
|
||||||
|
call searchcount(#{
|
||||||
|
\ recompute: 1, maxcount: 0, timeout: 100})
|
||||||
|
endif
|
||||||
|
endfunction
|
Loading…
x
Reference in New Issue
Block a user