Related to this post How to display multiple changed files on disk in Vim?,
I want to implement this feature in Lua. Some help would be appreciated.
set autoread
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI *
\ if mode() !~ '\v(c|r.?|!|t)' && getcmdwintype() == '' | checktime | endif
let g:filechanged_timer = 0
let g:filechanged = ""
function! FileChangedCallback(timer)
echohl WarningMsg
echo "File " . g:filechanged . " changed on disk. Buffer reloaded."
echohl None
" Reset the timer and the list of files:
let g:filechanged_timer = 0
let g:filechanged = ""
endfunction
function! FileChanged(path)
if g:filechanged_timer == 0
" First change detected
let g:filechanged = a:path
" Wait 0.1 seconds for a new changes to come:
let g:filechanged_timer = timer_start(100, 'FileChangedCallback')
else
" Some more change detected
" Add the file path to the list:
let g:filechanged = g:filechanged .. ', ' .. a:path
endif
endfunction
autocmd! FileChangedShellPost * call FileChanged(expand('<afile>'))