lambdalisue / vim-gina

👣 Asynchronously control git repositories in Neovim/Vim 8
http://www.vim.org/scripts/script.php?script_id=5531
MIT License
689 stars 27 forks source link

Refresh `gina-status` buffer whenever you enter it #263

Closed resolritter closed 4 years ago

resolritter commented 4 years ago

Hello!

I don't have exact reproduction steps, but sometimes, when I re-enter the gina-status buffer, it's not updated after a commit. That may also happen if you commit something outside of Vim and come back to it later.

In those situations, I'm often forced to call :edit which refreshes the buffer through autocommands. It would be very nice if the buffer automatically refreshed whenever you switched to it. I am thinking of something along those lines:

fun! s:RefreshIfPreviouslyInvisible()
  if win_findbuf(bufnr('#')) == []
    " refresh here
  endif
endfun

autocmd BufEnter <buffer> call s:RefreshIfPreviouslyInvisible()

as win_findbuf only checks if a buffer is open in the current tab, this "automatic refresh" wouldn't happen if gina-status is already open in a split (this concern is necessary to avoid refreshing the buffer while the cursor is already doing something in it).

lambdalisue commented 4 years ago

Well, so what this issue for? Bug report or feature request or else?

resolritter commented 4 years ago

The issue suggests that this behavior "Refresh gina-status buffer whenever you enter it" is not happening currently, but is desirable. It'd be a feature request if this is not intended by design or a bug report if you believe this is supposed to be happening already.

The behavior I notice currently is:

However, if I switch back to a existing status buffer, it seems like it doesn't update on BufEnter. It should, because changes could have been made on a terminal (ex: Gina!! add -i) or outside of vim.

The workaround for this problem is to manually call :edit, which will trigger the autocommand to refresh the buffer, but I find this is annoying to keep doing manually for every single commit.

When I opened this issue, I did not know what to do. Just recently I took a deeper look at the autocommands and made a script which works decently well.

fun! RefreshStatus()
  if win_findbuf(bufnr('#')) == []
    set modifiable
    call deletebufline(bufnr('%'), 1, line('$'))
    set nomodifiable
    call gina#util#doautocmd('BufReadCmd')
  endif
endfun

autocmd BufEnter,FocusGained <buffer> call RefreshStatus()

I think this solution is fine. Thanks for your time.