Guest User

Untitled

a guest
Mar 26th, 2020
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.49 KB | None | 0 0
  1. local w = vim.loop.new_fs_event()
  2. local function on_change(err, fname, status)
  3.   -- Do work...
  4.   vim.api.nvim_command('checktime')
  5.   -- Debounce: stop/start.
  6.   w:stop()
  7.   watch_file(fname)
  8. end
  9. function watch_file(fname)
  10.   local fullpath = vim.api.nvim_call_function(
  11.     'fnamemodify', {fname, ':p'})
  12.   w:start(fullpath, {}, vim.schedule_wrap(function(...)
  13.     on_change(...) end))
  14. end
  15. vim.api.nvim_command(
  16.   "command! -nargs=1 Watch call luaeval('watch_file(_A)', expand('<args>'))")
Add Comment
Please, Sign In to add comment