aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2022-02-06 17:10:27 +0900
committernsfisis <nsfisis@gmail.com>2022-02-06 17:10:27 +0900
commitc330c2314a2cb1971cc08484b89e19552b03b75e (patch)
tree6d0c444fc897b3ff718f04c5059c5a51512444d9
parent0e8f2ecd4859812f2e57030fe2b1b27507f816a5 (diff)
downloaddotfiles-c330c2314a2cb1971cc08484b89e19552b03b75e.tar.gz
dotfiles-c330c2314a2cb1971cc08484b89e19552b03b75e.tar.zst
dotfiles-c330c2314a2cb1971cc08484b89e19552b03b75e.zip
neovim: fix autosaving
-rw-r--r--.config/nvim/lua/autosave.lua27
1 files changed, 18 insertions, 9 deletions
diff --git a/.config/nvim/lua/autosave.lua b/.config/nvim/lua/autosave.lua
index cba48fb..530b2d7 100644
--- a/.config/nvim/lua/autosave.lua
+++ b/.config/nvim/lua/autosave.lua
@@ -17,23 +17,26 @@ local function echo(text, hl_group)
end
-local function handler()
- if not vim.bo.modified then
+local function handler(bufnr)
+ if not vim.bo[bufnr].modified then
return
end
- if vim.bo.readonly then
+ if vim.bo[bufnr].readonly then
return
end
- if vim.bo.buftype ~= '' then
+ if vim.bo[bufnr].buftype ~= '' then
return
end
- if vim.fn.bufname() == '' then
+ local bufname = vim.fn.bufname(bufnr)
+ if bufname == '' then
return
end
- echo('Auto-saving...', 'Comment')
- vim.cmd('silent! write')
- echo('Saved.', 'Comment')
+ echo(('Auto-saving %s...'):format(bufname), 'Comment')
+ for _, win_id in ipairs(vim.fn.win_findbuf(bufnr)) do
+ vim.fn.win_execute(win_id, 'silent! update', true)
+ end
+ echo(('%s saved.'):format(bufname), 'Comment')
end
@@ -42,8 +45,14 @@ function M.enable()
return
end
+ local bufnr = vim.fn.bufnr()
local timer = vim.loop.new_timer()
- timer:start(INTERVAL_MS, INTERVAL_MS, vim.schedule_wrap(handler))
+ timer:start(
+ INTERVAL_MS,
+ INTERVAL_MS,
+ vim.schedule_wrap(function ()
+ handler(bufnr)
+ end))
local tid = #timers + 1
timers[tid] = timer
vim.b.autosave_timer_id = tid