mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 17:40:06 +08:00
Improve FlyGrep
ref: https://github.com/BurntSushi/ripgrep/issues/769#issuecomment-362810112 Handle ignorcase and smartcase option in vim
This commit is contained in:
parent
0d997d2b00
commit
83ce1fa2be
@ -136,6 +136,9 @@ func! s:self._build_prompt() abort
|
||||
echohl None | echon self._prompt.begin
|
||||
echohl Wildmenu | echon self._prompt.cursor
|
||||
echohl None | echon self._prompt.end
|
||||
if empty(self._prompt.cursor) && !has('nvim')
|
||||
echohl Comment | echon '_' | echohl None
|
||||
endif
|
||||
endf
|
||||
|
||||
function! s:self._clear_prompt() abort
|
||||
|
@ -14,31 +14,51 @@ let s:search_tools.a.default_opts =
|
||||
\ '.hg', '--ignore', '.svn', '--ignore', '.git', '--ignore', '.bzr',
|
||||
\ ]
|
||||
let s:search_tools.a.recursive_opt = []
|
||||
let s:search_tools.a.expr_opt = []
|
||||
let s:search_tools.a.fixed_string_opt = ['-F']
|
||||
let s:search_tools.a.default_fopts = ['--nonumber']
|
||||
let s:search_tools.a.smart_case = ['-S']
|
||||
let s:search_tools.a.ignore_case = ['-i']
|
||||
|
||||
let s:search_tools.t = {}
|
||||
let s:search_tools.t.command = 'pt'
|
||||
let s:search_tools.t.default_opts = ['--nogroup', '--nocolor']
|
||||
let s:search_tools.t.recursive_opt = []
|
||||
let s:search_tools.t.expr_opt = ['-e']
|
||||
let s:search_tools.t.fixed_string_opt = []
|
||||
let s:search_tools.t.default_fopts = []
|
||||
let s:search_tools.t.smart_case = ['-S']
|
||||
let s:search_tools.t.ignore_case = ['-i']
|
||||
|
||||
let s:search_tools.r = {}
|
||||
let s:search_tools.r.command = 'rg'
|
||||
let s:search_tools.r.default_opts = ['--hidden', '--no-heading', '--vimgrep', '-S']
|
||||
let s:search_tools.r.default_opts = ['--hidden', '--no-heading', '--vimgrep']
|
||||
let s:search_tools.r.recursive_opt = []
|
||||
let s:search_tools.r.default_fopts = ['--hidden', '-S', '-N']
|
||||
let s:search_tools.r.expr_opt = ['-e']
|
||||
let s:search_tools.r.fixed_string_opt = ['-F']
|
||||
let s:search_tools.r.default_fopts = ['--hidden', '-N']
|
||||
let s:search_tools.r.smart_case = ['-S']
|
||||
let s:search_tools.r.ignore_case = ['-i']
|
||||
|
||||
let s:search_tools.k = {}
|
||||
let s:search_tools.k.command = 'ack'
|
||||
let s:search_tools.k.default_opts = ['-i', '--no-heading', '--no-color', '-k', '-H']
|
||||
let s:search_tools.k.recursive_opt = []
|
||||
let s:search_tools.k.expr_opt = []
|
||||
let s:search_tools.k.fixed_string_opt = []
|
||||
let s:search_tools.k.default_fopts = []
|
||||
let s:search_tools.k.smart_case = ['--smart-case']
|
||||
let s:search_tools.k.ignore_case = ['--ignore-case']
|
||||
|
||||
let s:search_tools.g = {}
|
||||
let s:search_tools.g.command = 'grep'
|
||||
let s:search_tools.g.default_opts = ['-inHr']
|
||||
let s:search_tools.g.expr_opt = ['-e']
|
||||
let s:search_tools.g.fixed_string_opt = ['-F']
|
||||
let s:search_tools.g.recursive_opt = ['.']
|
||||
let s:search_tools.g.default_fopts = []
|
||||
let s:search_tools.g.smart_case = []
|
||||
let s:search_tools.g.ignore_case = ['-i']
|
||||
|
||||
function! SpaceVim#mapping#search#grep(key, scope)
|
||||
let cmd = s:search_tools[a:key]['command']
|
||||
@ -101,11 +121,23 @@ function! SpaceVim#mapping#search#default_tool() abort
|
||||
let key = s:search_tools.namespace[t]
|
||||
let s:search_tools.default_opt = s:search_tools[key]['default_opts']
|
||||
let s:search_tools.default_ropt = s:search_tools[key]['recursive_opt']
|
||||
let s:search_tools.expr_opt = s:search_tools[key]['expr_opt']
|
||||
let s:search_tools.fixed_string_opt = s:search_tools[key]['fixed_string_opt']
|
||||
let s:search_tools.ignore_case = s:search_tools[key]['ignore_case']
|
||||
let s:search_tools.smart_case = s:search_tools[key]['smart_case']
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
return [s:search_tools.default_exe, s:search_tools.default_opt, s:search_tools.default_ropt]
|
||||
return [
|
||||
\ s:search_tools.default_exe,
|
||||
\ s:search_tools.default_opt,
|
||||
\ s:search_tools.default_ropt,
|
||||
\ s:search_tools.expr_opt,
|
||||
\ s:search_tools.fixed_string_opt,
|
||||
\ s:search_tools.ignore_case,
|
||||
\ s:search_tools.smart_case,
|
||||
\ ]
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#mapping#search#getFopt(exe) abort
|
||||
|
@ -8,7 +8,15 @@ let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||
|
||||
" Init local options: {{{
|
||||
let s:grep_expr = ''
|
||||
let [s:grep_default_exe, s:grep_default_opt, s:grep_default_ropt] = SpaceVim#mapping#search#default_tool()
|
||||
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_ignore_case,
|
||||
\ s:grep_smart_case
|
||||
\ ] = SpaceVim#mapping#search#default_tool()
|
||||
let s:grep_timer_id = 0
|
||||
let s:grepid = 0
|
||||
" }}}
|
||||
@ -21,7 +29,6 @@ function! s:grep_timer(timer) abort
|
||||
call SpaceVim#logger#info('grep cmd: ' . string(cmd))
|
||||
let s:grepid = s:JOB.start(cmd, {
|
||||
\ 'on_stdout' : function('s:grep_stdout'),
|
||||
\ 'on_stderr' : function('s:grep_stderr'),
|
||||
\ 'in_io' : 'null',
|
||||
\ 'on_exit' : function('s:grep_exit'),
|
||||
\ })
|
||||
@ -29,6 +36,13 @@ endfunction
|
||||
|
||||
function! s:get_search_cmd(expr) abort
|
||||
let cmd = [s:grep_exe] + s:grep_opt
|
||||
if &ignorecase
|
||||
let cmd += s:grep_ignore_case
|
||||
endif
|
||||
if &smartcase
|
||||
let cmd += s:grep_smart_case
|
||||
endif
|
||||
let cmd += s:grep_default_expr_opt
|
||||
if !empty(s:grep_files) && type(s:grep_files) == 3
|
||||
return cmd + [a:expr] + s:grep_files
|
||||
elseif !empty(s:grep_files) && type(s:grep_files) == 1
|
||||
@ -56,8 +70,6 @@ function! s:flygrep(expr) abort
|
||||
let s:grep_timer_id = timer_start(200, function('s:grep_timer'), {'repeat' : 1})
|
||||
endfunction
|
||||
|
||||
" set default handle func: s:flygrep
|
||||
let s:MPT._handle_fly = function('s:flygrep')
|
||||
" }}}
|
||||
|
||||
" filter local funcs: {{{
|
||||
@ -100,10 +112,8 @@ endfunction
|
||||
|
||||
function! s:filter_timer(timer) abort
|
||||
let cmd = s:get_filter_cmd(join(split(s:grep_expr), '.*'))
|
||||
call SpaceVim#logger#info('filter cmd: ' . string(cmd))
|
||||
let s:grepid = s:JOB.start(cmd, {
|
||||
\ 'on_stdout' : function('s:grep_stdout'),
|
||||
\ 'on_stderr' : function('s:grep_stderr'),
|
||||
\ 'in_io' : 'null',
|
||||
\ 'on_exit' : function('s:grep_exit'),
|
||||
\ })
|
||||
@ -115,7 +125,6 @@ function! s:get_filter_cmd(expr) abort
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
let s:mode = ''
|
||||
" replace local funcs {{{
|
||||
function! s:start_replace() abort
|
||||
let s:mode = 'r'
|
||||
@ -174,17 +183,6 @@ 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_expr)))
|
||||
call s:MPT._build_prompt()
|
||||
endfunction
|
||||
|
||||
function! s:grep_exit(id, data, event) abort
|
||||
redrawstatus
|
||||
let s:grepid = 0
|
||||
@ -302,6 +300,9 @@ endif
|
||||
" files: files for grep, @buffers means listed buffer.
|
||||
" dir: specific a directory for grep
|
||||
function! SpaceVim#plugins#flygrep#open(agrv) abort
|
||||
let s:mode = ''
|
||||
" set default handle func: s:flygrep
|
||||
let s:MPT._handle_fly = function('s:flygrep')
|
||||
rightbelow split __flygrep__
|
||||
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber
|
||||
let save_tve = &t_ve
|
||||
|
@ -50,6 +50,7 @@ CONTENTS *SpaceVim-contents*
|
||||
27. operator...................................|SpaceVim-layer-operator|
|
||||
28. shell.........................................|SpaceVim-layer-shell|
|
||||
29. tmux...........................................|SpaceVim-layer-tmux|
|
||||
30. tools#dash...............................|SpaceVim-layer-tools-dash|
|
||||
6. API........................................................|SpaceVim-api|
|
||||
1. cmdlinemenu................................|SpaceVim-api-cmdlinemenu|
|
||||
2. data#list....................................|SpaceVim-api-data-list|
|
||||
@ -488,6 +489,10 @@ is on, if any.
|
||||
*g:ale_echo_delay*
|
||||
w0rp/ale {{{
|
||||
|
||||
*g:dash_map*
|
||||
rizzatti/dash.vim {{{ Allows configuration of mappings between Vim filetypes
|
||||
and Dash's docsets.
|
||||
|
||||
==============================================================================
|
||||
COMMANDS *SpaceVim-commands*
|
||||
|
||||
@ -1116,6 +1121,11 @@ MAPPINGS
|
||||
<C-l> normal Switch to vim/tmux pane in right direction
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
TOOLS#DASH *SpaceVim-layer-tools-dash*
|
||||
|
||||
This layer provides Dash integration for SpaceVim
|
||||
|
||||
==============================================================================
|
||||
API *SpaceVim-api*
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user