Filenotify is an Eovim plugin that warns the user through Eovim's user interface when a file open in Eovim was changed from the outside.
To make filenotify work, Eovim defines two vim APIs:
- when a file has been read by neovim,
- when a file has been written by neovim.
Both APIs use the Eovim() function, with "filenotify" as the first argument:
|API||1st argument||2nd argument||3rd argument|
|File Read||"filenotify"||file name||1|
|File Written||"filenotify"||file name||0|
For example, this API can be used as follows:
function! OnReadFile (file_matched) call Eovim("filenotify", a:file_matched, 1) endfunction function! OnWriteFile (file_matched) call Eovim("filenotify", a:file_matched, 0) endfunction
And then triggered using neovim's autocmd:
augroup EovimFileNotify autocmd! autocmd BufNewFile,BufReadPre,FileReadPre * call OnReadFile(expand('<amatch>')) autocmd BufWritePre * call OnWriteFile(expand('<amatch>')) augroup END
Eovim (e.g. the filenotify plugin) is made aware when a file has been read or written thanks to the neovim API presented above. During its lifetime, filenotify follows the following statechart regarding files edited within neovim:
- Existing files read by neovim are monitored (through an Ecore_File_Monitor).
- Upon write from inside neovim, filenotify shall receive a message, to try to distinguish external writes from internal writes.
- If a file is changed and the internal write signal was not received within a given window of time, the file is marked as being changed from the outside.
- Newly created files do not need to be registered, until they are written to the disk.
- When a file is closed, it is unregistered.