~gpanders/dotfiles

ref: 2da1dde5ea566f82ebe6532bc6d3b8670fd77ce8 dotfiles/vim/.vim/autoload/grep.vim -rw-r--r-- 916 bytes
2da1dde5Greg Anders Note 'open' subcommand opens editor in NOTES_DIR when no argument given 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
" Asynchronous grep
" Author: Greg Anders
" Date: 2019-05-18

function! s:callback(l, lines) abort
  let F = a:l ? function('setloclist', [0]) : function('setqflist')
  call F([], 'a', {'lines': a:lines})
endfunction

function! s:completed(l) abort
  silent exe 'doautocmd QuickFixCmdPost' a:l ? 'lgrep' : 'grep'
endfunction

function! grep#grep(l, args)
  if stridx(&grepprg, '$*') != -1
    let cmd = substitute(&grepprg, '$\*', a:args, 'g')
  else
    let cmd = &grepprg . ' ' . a:args
  endif

  " Run the grep command in a shell to enable shell expansion
  call async#run(cmd, {lines -> s:callback(a:l, lines)}, {'shell': 1, 'buffered': 0, 'completed': {_ -> s:completed(a:l)}})

  silent exe 'doautocmd QuickFixCmdPre' a:l ? 'lgrep' : 'grep'
  let F = a:l ? function('setloclist', [0]) : function('setqflist')
  call F([], 'r', {'title': cmd, 'items': []})
  exe 'botright' a:l ? 'lopen' : 'copen'
endfunction