From be0abe0b2171f8be1b100f45856b9eb106773641 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 8 Sep 2021 15:44:46 -0400 Subject: [PATCH] Standardize handling for quickfix commands Use 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 --- autoload/fugitive.vim | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 548167a..20ea1e8 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -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), '\', '', '') + return mods . (a:nr < 0 ? 'c' : 'l').'open' . (mods =~# '\' ? ' 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 !~# '\' + if a:mods !~# '\' 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), '\', '', '') (listnr < 0 ? 'c' : 'l').'open' + exe s:QuickfixOpen(listnr, a:mods) if bufnr != bufnr('') && !a:bang wincmd p endif