Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid non-file windows for :Gstatus open
Closes #1002
  • Loading branch information
tpope committed May 27, 2018
1 parent 614e20b commit 6faf165
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions plugin/fugitive.vim
@@ -1,6 +1,6 @@
" fugitive.vim - A Git wrapper so awesome, it should be illegal
" Maintainer: Tim Pope <http://tpo.pe/>
" Version: 2.2
" Version: 2.3
" GetLatestVimScripts: 2975 1 :AutoInstall: fugitive.vim

if exists('g:loaded_fugitive') || &cp
Expand Down Expand Up @@ -1420,17 +1420,23 @@ endfunction

" Section: Gedit, Gpedit, Gsplit, Gvsplit, Gtabedit, Gread

function! s:UsableWin(nr) abort
return a:nr && !getwinvar(a:nr, '&previewwindow') &&
\ index(['nofile','help','quickfix'], getbufvar(winbufnr(a:nr), '&buftype')) < 0
endfunction

function! s:Edit(cmd,bang,...) abort
let buffer = s:buffer()
if a:cmd !~# 'read'
if &previewwindow && getbufvar('','fugitive_type') ==# 'index'
if winnr('$') == 1
let winnrs = filter([winnr('#')] + range(1, winnr('$')), 's:UsableWin(v:val)')
if len(winnrs)
exe winnrs[1].'wincmd w'
elseif winnr('$') == 1
let tabs = (&go =~# 'e' || !has('gui_running')) && &stal && (tabpagenr('$') >= &stal)
execute 'rightbelow' (&lines - &previewheight - &cmdheight - tabs - 1 - !!&laststatus).'new'
elseif winnr('#')
wincmd p
else
wincmd w
rightbelow new
endif
if &diff
let mywinnr = winnr()
Expand Down

3 comments on commit 6faf165

@sodapopcan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting an error in the following case:

Open a fresh instance of vim in a dirty repo. Edit a file, invoke :Gstatus and then :help right after. Jump back to the Gstatus window and try and open a file. This is thrown:

Error detected while processing function <SNR>59_GF[7]..<SNR>59_Edit:
line    6:
E684: list index out of range: 1
E15: Invalid expression: winnrs[1].'wincmd w'

I've validated this with an empty vimrc and fugitive as my only plugin in vim 8.0 and 8.1.

Changing winnrs[1] on line 1434 to winnrs[0] fixes this and works in a few other test cases I did, but I haven't fully grokked why you want the [1] index.

As an aside, I really like this way of doing checks on multiple windows. I'm pretty sure I can leverage this pattern to speed up some other stuff of mine. Thanks!

@tpope
Copy link
Owner Author

@tpope tpope commented on 6faf165 May 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did mean [0], guess I never tested the one actual window case. I blame Lua.

@sodapopcan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ha! Well, thanks a lot for doing this—it's much appreciated.

Please sign in to comment.