mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 23:10:06 +08:00
Improve foldsearch plugin (#3768)
This commit is contained in:
parent
c791b3661b
commit
5ff1277666
@ -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
|
||||
|
@ -27,7 +27,7 @@ lang: zh
|
||||
name = "foldsearch"
|
||||
```
|
||||
|
||||
该模块依赖于命令:[ripgrep](https://github.com/BurntSushi/ripgrep)。
|
||||
使用这一模块,需要安装一个文本搜索命令,可以选择:`ag`、`rg`、`ack`、`pt` 或者 `grep`。
|
||||
|
||||
## 快捷键
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user