equalsraf / neovim-qt

Neovim client library and GUI, in Qt5.
https://github.com/equalsraf/neovim-qt/wiki
ISC License
1.86k stars 171 forks source link

FocusGained does not reload buffer when autoread is set #846

Open przepompownia opened 3 years ago

przepompownia commented 3 years ago

I have to run :checktime manually or write autocommand for nvim-qt only. Is it intentional?

There is no such need on pure nvim.

equalsraf commented 3 years ago

I have to run :checktime manually or write autocommand for nvim-qt only. Is it intentional?

No, I dont think it is.

In nvim the autoread check is triggered in check_timestamps (among other places) called when there is a focus change (do_autocmd_focusgained).

Since #329 the focus events are implemented as an autocommand

https://github.com/equalsraf/neovim-qt/blob/e1d5487e69e798a0c743b1770ec50d6de005e7bf/src/gui/shell.cpp#L1566

As far as i can see the focus auto commands are working properly, but the autoread option is not.

There are a couple of conditions in nvim which can cause autoread to be skipped

https://github.com/neovim/neovim/blob/71107e12c7b68d8faf1bcc1a5794a55b21e146f3/src/nvim/fileio.c#L4678

and as you already pointed out calling :checktime does work, and is very similar

https://github.com/neovim/neovim/blob/c2624b87cb6b5ba1fe811a005cc3c0977a864633/src/nvim/ex_cmds2.c#L3509

I would have to trace nvim to figure out why this is not being called.

przepompownia commented 3 years ago

As far as i can see the focus auto commands are working properly, but the autoread option is not.

You are right. While I used https://github.com/tmux-plugins/vim-tmux-focus-events it executed :checktime on FocusGained with autocommand. The problem was revealed after removing this autocommand along with the plugin. Now the event is triggered but autoread does not work on it.

przepompownia commented 1 year ago

The bug is still present on recent master versions of both Neovim and Neovim-qt.

drmikehenry commented 1 year ago

The 'autoread' feature does not work out-of-the-box for both nvim-qt and neovide:

The 'autoread' feature does work for nvim's TUI.

The reason it works for the TUI is mentioned in this now-closed Neovim issue: https://github.com/neovim/neovim/issues/20082#issuecomment-1236324274

No. I just noticed that neovide already triggers FocusGained, and that triggering FocusGained from :doautocmd doesn't actually trigger a timestamp check. With TUI a timestamp check is done the same time as FocusGained, but it is not an autocommand callback, but something triggered the same time as the autocommand.

In that issue, Neovim maintainer @justinmk has commented on the 'autoread' feature: https://github.com/neovim/neovim/issues/20082#issuecomment-1288913518

As mentioned above, FocusGained can be used to opt-in to the behavior you want.

The general story of improving autoread is tracked in https://github.com/neovim/neovim/issues/1380

This refers to having GUI users add this to their configuration:

autocmd FocusGained * checktime

I can confirm that this work-around does restore the 'autoread' functionality for me, with both GUIs.

It's unclear to me whether there is a long-term plan to restore the 'autoread' feature for Neovim GUIs users without requiring the above work-around.

justinmk commented 1 year ago

Thanks for that summary @drmikehenry . As noted in https://github.com/neovide/neovide/issues/1477 , the GUI just needs to call nvim_ui_set_focus.