mirror of
https://github.com/neovim/neovim.git
synced 2026-06-15 16:23:48 +00:00
Problem: The 'autoread' option only checks for file changes reactively — on FocusGained, :checktime, CmdlineEnter, etc. — by polling timestamps. External changes are not detected until the user interacts with Neovim. Solution: Add a core module (runtime/lua/nvim/autoread.lua) enabled from runtime/plugin/autoread.lua that watches each buffer's file using vim._watch.watch() (libuv fs_event). On change detection it calls :checktime, which invokes the existing buf_check_timestamp() logic for reload/prompt handling. Watchers are managed via autocmds tied to buffer lifecycle events and respect the 'autoread' option (global and buffer-local).
13 lines
440 B
Lua
13 lines
440 B
Lua
-- File-watcher backing for the 'autoread' option.
|
|
-- Lives here (not in vim/_core/defaults.lua) so that `-u NONE` / `--noplugin`
|
|
-- skip it: the BufReadPost/BufWritePost autocmds it registers would otherwise
|
|
-- show up in every test that inspects the autocmd list. Matches the pattern
|
|
-- used by runtime/plugin/matchparen.lua.
|
|
|
|
if vim.g.loaded_autoread ~= nil then
|
|
return
|
|
end
|
|
vim.g.loaded_autoread = 1
|
|
|
|
require('nvim.autoread').enable()
|