mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 06:30:03 +08:00
Add background searching feature
This commit is contained in:
parent
274ecb35d3
commit
498cbe0fa0
@ -241,6 +241,7 @@ function! s:active() abort
|
||||
if index(s:loaded_sections, 'version control info') != -1
|
||||
call add(lsec, s:git_branch())
|
||||
endif
|
||||
call add(lsec, SpaceVim#plugins#searcher#count())
|
||||
if index(s:loaded_sections, 'battery status') != -1
|
||||
call add(rsec, s:battery_status())
|
||||
endif
|
||||
|
@ -105,6 +105,11 @@ function! SpaceVim#mapping#space#init() abort
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['s', 'p'], 'Unite grep:.', 'grep in project', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['s', 'P'], "execute 'Unite grep:.::' . expand(\"<cword>\") . ' -start-insert'",
|
||||
\ 'grep in project', 1)
|
||||
" Searching background
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['s', 'j'], 'call SpaceVim#plugins#searcher#find()', 'Background search keywords in project', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['s', 'J'], 'call SpaceVim#plugins#searcher#find(expand("<cword>"))',
|
||||
\ 'Background search cursor words in project', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['s', 'l'], 'call SpaceVim#plugins#searcher#list()', 'List all searching results', 1)
|
||||
|
||||
" Searching tools
|
||||
" ag
|
||||
|
47
autoload/SpaceVim/plugins/searcher.vim
Normal file
47
autoload/SpaceVim/plugins/searcher.vim
Normal file
@ -0,0 +1,47 @@
|
||||
let s:rst = []
|
||||
function! SpaceVim#plugins#searcher#find(...)
|
||||
if a:0 == 0
|
||||
let expr = input('search expr: ')
|
||||
else
|
||||
let expr = a:1
|
||||
endif
|
||||
call jobstart(['ag', expr], {
|
||||
\ 'on_stdout' : function('s:search_stdout'),
|
||||
\ 'on_exit' : function('s:search_exit'),
|
||||
\ })
|
||||
endfunction
|
||||
function! s:search_stdout(id, data, event) abort
|
||||
for data in a:data
|
||||
let info = split(data, '\:\d\+\:')
|
||||
if len(info) == 2
|
||||
let [fname, text] = info
|
||||
let lnum = matchstr(data, '\:\d\+\:')[1:-2]
|
||||
call add(s:rst, {
|
||||
\ 'filename' : fnamemodify(fname, ':p'),
|
||||
\ 'lnum' : lnum,
|
||||
\ 'text' : text,
|
||||
\ })
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:search_exit(id, data, event) abort
|
||||
let &l:statusline = SpaceVim#layers#core#statusline#get(1)
|
||||
endfunction
|
||||
|
||||
|
||||
function! SpaceVim#plugins#searcher#list()
|
||||
call setqflist(s:rst)
|
||||
let s:rst = []
|
||||
copen
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#searcher#count()
|
||||
if empty(s:rst)
|
||||
return ''
|
||||
else
|
||||
return ' ' . len(s:rst) . ' items '
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user