mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-22 17:05:42 +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: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:matched_lines = []
|
||||||
let s:foldsearch_highlight_id = -1
|
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
|
normal! zE
|
||||||
try
|
try
|
||||||
call matchdelete(s:foldsearch_highlight_id)
|
call matchdelete(s:foldsearch_highlight_id)
|
||||||
@ -19,8 +32,12 @@ function! SpaceVim#plugins#foldsearch#end()
|
|||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#plugins#foldsearch#word(word)
|
function! SpaceVim#plugins#foldsearch#word(word) abort
|
||||||
let argv = ['rg', '--line-number', '--fixed-strings', a:word]
|
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
|
try
|
||||||
call matchdelete(s:foldsearch_highlight_id)
|
call matchdelete(s:foldsearch_highlight_id)
|
||||||
catch
|
catch
|
||||||
@ -29,8 +46,12 @@ function! SpaceVim#plugins#foldsearch#word(word)
|
|||||||
call s:foldsearch(argv)
|
call s:foldsearch(argv)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#plugins#foldsearch#expr(expr)
|
function! SpaceVim#plugins#foldsearch#expr(expr) abort
|
||||||
let argv = ['rg', '--line-number', a:expr]
|
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
|
try
|
||||||
call matchdelete(s:foldsearch_highlight_id)
|
call matchdelete(s:foldsearch_highlight_id)
|
||||||
catch
|
catch
|
||||||
@ -52,11 +73,12 @@ endfunction
|
|||||||
|
|
||||||
function! s:std_out(id, data, event) abort
|
function! s:std_out(id, data, event) abort
|
||||||
for line in filter(a:data, '!empty(v:val)')
|
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
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:exit(id, data, event) abort
|
function! s:exit(id, data, event) abort
|
||||||
|
call s:LOGGER.info('foldsearch job exit with: '. a:data)
|
||||||
let preview = 0
|
let preview = 0
|
||||||
for nr in s:matched_lines
|
for nr in s:matched_lines
|
||||||
if nr - preview >= 3 " first matched line is 3
|
if nr - preview >= 3 " first matched line is 3
|
||||||
|
@ -27,7 +27,7 @@ lang: zh
|
|||||||
name = "foldsearch"
|
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"
|
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
|
## Options
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user