Standardize <mods> handling for quickfix commands

Use <mods> for :copen rather than :cfirst, as that seems to be the more
useful of the two.

When I call :vertical copen, I get a window that is initially 10
columns wide, but which resizes to 20 columns upon blurring and
refocusing. Not sure what's up with that, but 10 columns is comically
narrow, so let's go ahead and open at 20 columns to begin with.

Resolves: https://github.com/tpope/vim-fugitive/issues/1831
This commit is contained in:
Tim Pope
2021-09-08 15:44:46 -04:00
parent 02eb2e871c
commit be0abe0b21

View File

@@ -1336,15 +1336,19 @@ function! s:QuickfixCreate(nr, opts) abort
endif
endfunction
function! s:QuickfixOpen(nr, mods) abort
let mods = substitute(s:Mods(a:mods), '\<tab\>', '', '')
return mods . (a:nr < 0 ? 'c' : 'l').'open' . (mods =~# '\<vertical\>' ? ' 20' : '')
endfunction
function! s:QuickfixStream(nr, event, title, cmd, first, mods, callback, ...) abort
call s:BlurStatus()
let mods = s:Mods(a:mods)
let opts = {'title': a:title, 'context': {'items': []}}
call s:QuickfixCreate(a:nr, opts)
let event = (a:nr < 0 ? 'c' : 'l') . 'fugitive-' . a:event
silent exe s:DoAutocmd('QuickFixCmdPre ' . event)
let winnr = winnr()
exe a:nr < 0 ? 'copen' : 'lopen'
exe s:QuickfixOpen(a:nr, a:mods)
if winnr != winnr()
wincmd p
endif
@@ -1359,7 +1363,7 @@ function! s:QuickfixStream(nr, event, title, cmd, first, mods, callback, ...) ab
call extend(opts.context.items, contexts)
unlet contexts
call s:QuickfixSet(a:nr, remove(buffer, 0, -1), 'a')
if mods !~# '\<silent\>'
if a:mods !~# '\<silent\>'
redraw
endif
endif
@@ -1371,7 +1375,7 @@ function! s:QuickfixStream(nr, event, title, cmd, first, mods, callback, ...) ab
silent exe s:DoAutocmd('QuickFixCmdPost ' . event)
if a:first && len(s:QuickfixGet(a:nr))
return mods . (a:nr < 0 ? 'cfirst' : 'lfirst')
return (a:nr < 0 ? 'cfirst' : 'lfirst')
else
return 'exe'
endif
@@ -5541,7 +5545,7 @@ function! s:GrepSubcommand(line1, line2, range, bang, mods, options) abort
silent exe s:DoAutocmd('QuickFixCmdPost ' . event)
if quiet
let bufnr = bufnr('')
silent exe substitute(s:Mods(a:mods), '\<tab\>', '', '') (listnr < 0 ? 'c' : 'l').'open'
exe s:QuickfixOpen(listnr, a:mods)
if bufnr != bufnr('') && !a:bang
wincmd p
endif