diff --git a/autoload/SpaceVim/plugins/foldsearch.vim b/autoload/SpaceVim/plugins/foldsearch.vim index 6f7b9086e..bfdadf0b2 100644 --- a/autoload/SpaceVim/plugins/foldsearch.vim +++ b/autoload/SpaceVim/plugins/foldsearch.vim @@ -7,11 +7,24 @@ "============================================================================= let s:JOB = SpaceVim#api#import('job') +let s:SYS = SpaceVim#api#import('system') +let s:LOGGER =SpaceVim#logger#derive('fsearch') + let s:matched_lines = [] let s:foldsearch_highlight_id = -1 +let [ + \ s:grep_default_exe, + \ s:grep_default_opt, + \ s:grep_default_ropt, + \ s:grep_default_expr_opt, + \ s:grep_default_fix_string_opt, + \ s:grep_default_ignore_case, + \ s:grep_default_smart_case + \ ] = SpaceVim#mapping#search#default_tool() -function! SpaceVim#plugins#foldsearch#end() + +function! SpaceVim#plugins#foldsearch#end() abort normal! zE try call matchdelete(s:foldsearch_highlight_id) @@ -19,8 +32,12 @@ function! SpaceVim#plugins#foldsearch#end() endtry endfunction -function! SpaceVim#plugins#foldsearch#word(word) - let argv = ['rg', '--line-number', '--fixed-strings', a:word] +function! SpaceVim#plugins#foldsearch#word(word) abort + let argv = [s:grep_default_exe] + + \ s:grep_default_opt + + \ s:grep_default_fix_string_opt + + \ [a:word] + call s:LOGGER.info('cmd: ' . string(argv)) try call matchdelete(s:foldsearch_highlight_id) catch @@ -29,8 +46,12 @@ function! SpaceVim#plugins#foldsearch#word(word) call s:foldsearch(argv) endfunction -function! SpaceVim#plugins#foldsearch#expr(expr) - let argv = ['rg', '--line-number', a:expr] +function! SpaceVim#plugins#foldsearch#expr(expr) abort + let argv = [s:grep_default_exe] + + \ s:grep_default_opt + + \ s:grep_default_expr_opt + + \ [a:expr] + call s:LOGGER.info('cmd: ' . string(argv)) try call matchdelete(s:foldsearch_highlight_id) catch @@ -52,11 +73,12 @@ endfunction function! s:std_out(id, data, event) abort for line in filter(a:data, '!empty(v:val)') - call add(s:matched_lines, str2nr(matchstr(line, '^\d\+'))) + call add(s:matched_lines, str2nr(matchstr(line, ':\d\+:')[1:-2])) endfor endfunction function! s:exit(id, data, event) abort + call s:LOGGER.info('foldsearch job exit with: '. a:data) let preview = 0 for nr in s:matched_lines if nr - preview >= 3 " first matched line is 3 diff --git a/docs/cn/layers/foldsearch.md b/docs/cn/layers/foldsearch.md index 5c2408295..928d89e80 100644 --- a/docs/cn/layers/foldsearch.md +++ b/docs/cn/layers/foldsearch.md @@ -27,7 +27,7 @@ lang: zh name = "foldsearch" ``` -该模块依赖于命令:[ripgrep](https://github.com/BurntSushi/ripgrep)。 +使用这一模块,需要安装一个文本搜索命令,可以选择:`ag`、`rg`、`ack`、`pt` 或者 `grep`。 ## 快捷键 diff --git a/docs/layers/foldsearch.md b/docs/layers/foldsearch.md index c1f3753d0..ad2851b8e 100644 --- a/docs/layers/foldsearch.md +++ b/docs/layers/foldsearch.md @@ -28,7 +28,8 @@ To use this layer, add it to your configuration file. name = "foldsearch" ``` -This layer requires [ripgrep](https://github.com/BurntSushi/ripgrep). +This layer requires at least one search tools: `ag`, `rg`, `ack`, `pt` and `grep`, +Choose your favorite one. ## Options