1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 08:30:06 +08:00

Add support searching in another dir

This commit is contained in:
wsdjeg 2018-01-22 20:17:52 +08:00
parent 7f4da473b4
commit 6f5bdefbed
2 changed files with 19 additions and 3 deletions

View File

@ -178,7 +178,9 @@ function! SpaceVim#mapping#space#init() abort
call SpaceVim#mapping#space#def('nnoremap', ['s', 'B'], "call SpaceVim#plugins#flygrep#open({'input' : expand(\"<cword>\"), 'files':'@buffers'})",
\ 'grep cursor word in all loaded buffers', 1)
" Searching in files in an arbitrary directory
call SpaceVim#mapping#space#def('nnoremap', ['s', 'f'], 'Unite grep', 'grep in arbitrary directory', 1)
call SpaceVim#mapping#space#def('nnoremap', ['s', 'f'], "call SpaceVim#plugins#flygrep#open({'input' :"
\ . " input(\"grep pattern:\"), 'dir' : input(\"arbitrary dir:\", '', 'dir')})",
\ 'grep in arbitrary directory', 1)
call SpaceVim#mapping#space#def('nnoremap', ['s', 'F'], "execute 'Unite grep:::' . expand(\"<cword>\") . ' -start-insert'",
\ 'grep in arbitrary directory', 1)
" Searching in project

View File

@ -25,7 +25,7 @@ function! SpaceVim#plugins#flygrep#open(agrv) abort
else
let s:grep_files = ''
endif
let dir = get(a:agrv, 'dir', '')
let dir = expand(get(a:agrv, 'dir', ''))
if !empty(dir) && isdirectory(dir)
let s:grep_dir = dir
else
@ -43,6 +43,7 @@ let s:grep_timer_id = 0
function! s:grep_timer(timer) abort
let s:grepid = s:JOB.start(s:get_search_cmd(s:grep_exe, s:grep_expr), {
\ 'on_stdout' : function('s:grep_stdout'),
\ 'on_stderr' : function('s:grep_stderr'),
\ 'in_io' : 'null',
\ 'on_exit' : function('s:grep_exit'),
\ })
@ -105,6 +106,17 @@ function! s:grep_stdout(id, data, event) abort
call s:MPT._build_prompt()
endfunction
function! s:grep_stderr(id, data, event) abort
let datas =filter(a:data, '!empty(v:val)')
if getline(1) ==# ''
call setline(1, datas)
else
call append('$', datas)
endif
call append('$', 'job:' . string(s:get_search_cmd(s:grep_exe, s:grep_expr)))
call s:MPT._build_prompt()
endfunction
function! s:grep_exit(id, data, event) abort
redrawstatus
let s:grepid = 0
@ -122,8 +134,10 @@ function! s:get_search_cmd(exe, expr) abort
return ['rg', '-H', '-n', '-i', a:expr] + s:grep_files
elseif !empty(s:grep_files) && type(s:grep_files) == 1
return ['rg', '-H', '-n', '-i', a:expr] + [s:grep_files]
elseif !empty(s:grep_dir)
return ['rg', '-H', '-n', '-i', a:expr] + [s:grep_dir]
else
return ['rg', '-H', '-n', '-i', a:expr]
return ['rg', '-H', '-n', '-i', a:expr, s:grep_dir]
endif
else
return [a:exe, a:expr]