commit 86a45846fcbb7f3e8dedd85d47f6b55d9cb26db5 (tree)
parent e716ebdda9cbc50a21af0c0cfa1d41b040e78bf8
Author: Tim Pope <code@tpope.net>
Date: Fri, 20 Aug 2021 00:30:53 -0400
Use :Ggrep -q to eschew output in favor of quickfix window
The q works on 2 levels!
Diffstat:
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim
@@ -5210,9 +5210,10 @@ endfunction
function! s:GrepSubcommand(line1, line2, range, bang, mods, options) abort
let args = copy(a:options.subcommand_args)
let handle = -1
+ let quiet = 0
let i = 0
while i < len(args) && args[i] !=# '--'
- let partition = matchstr(args[i], '^-' . s:grep_combine_flags . '\zeO')
+ let partition = matchstr(args[i], '^-' . s:grep_combine_flags . '\ze[qO]')
if len(partition) > 1
call insert(args, '-' . strpart(args[i], len(partition)), i+1)
let args[i] = partition
@@ -5224,6 +5225,14 @@ function! s:GrepSubcommand(line1, line2, range, bang, mods, options) abort
continue
elseif args[i] =~# '^\%(-O\|--open-files-in-pager=\)'
let handle = 0
+ elseif args[i] =~# '^-q.'
+ let args[i] = '-' . args[i][2:-1]
+ let quiet = 1
+ elseif args[i] =~# '^\%(-q\|--quiet\)$'
+ let quiet = 1
+ call remove(args, i)
+ elseif args[i] =~# '^--no-quiet$'
+ let quiet = 0
elseif args[i] =~# '^\%(--heading\)$'
call remove(args, i)
continue
@@ -5259,18 +5268,20 @@ function! s:GrepSubcommand(line1, line2, range, bang, mods, options) abort
let event = listnr < 0 ? 'grep-fugitive' : 'lgrep-fugitive'
silent exe s:DoAutocmd('QuickFixCmdPre ' . event)
try
- if &more
+ if !quiet && &more
let more = 1
set nomore
endif
- echo title
+ if !quiet
+ echo title
+ endif
let list = s:SystemList(s:UserCommandList(a:options) + cmd + args)[0]
call writefile(list + [''], tempfile, 'b')
call s:RunSave(state)
- call map(list, 's:GrepParseLine(options, 0, dir, v:val)')
+ call map(list, 's:GrepParseLine(options, ' . quiet . ', dir, v:val)')
call s:QuickfixSet(listnr, list, 'a')
let press_enter_shortfall = &cmdheight - len(list)
- if press_enter_shortfall > 0
+ if press_enter_shortfall > 0 && !quiet
echo repeat("\n", press_enter_shortfall - 1)
endif
finally
@@ -5280,6 +5291,13 @@ function! s:GrepSubcommand(line1, line2, range, bang, mods, options) abort
endtry
call s:RunFinished(state)
silent exe s:DoAutocmd('QuickFixCmdPost ' . event)
+ if quiet
+ let bufnr = bufnr('')
+ silent exe substitute(s:Mods(a:mods), '\<tab\>', '', '') (listnr < 0 ? 'c' : 'l').'open'
+ if bufnr != bufnr('')
+ wincmd p
+ endif
+ end
if !a:bang && !empty(list)
return 'silent ' . (listnr < 0 ? 'c' : 'l').'first'
else