fix: set autowrite/autowriteall, handle never-saved buffers

This commit is contained in:
swaits committed 2026-04-09 19:30:46 -06:00
1 parent 24a61f58f6
commit b84acda8a4
4 files changed
+26 -10

No files matched your search

+10 -3
View File
@@ -2,13 +2,20 @@ local M = {}
function M.setup(opts)
opts = opts or {}
local events = opts.events or { "InsertLeave", "FocusLost" }
local events = opts.events or { "InsertLeave", "TextChanged", "FocusLost" }
vim.opt.autowrite = true
vim.opt.autowriteall = true
vim.api.nvim_create_autocmd(events, {
group = vim.api.nvim_create_augroup("tiny-autosave", { clear = true }),
callback = function()
if vim.bo.buftype == "" and vim.bo.modified then
vim.cmd("silent! wall")
local name = vim.api.nvim_buf_get_name(0)
if name ~= "" and vim.fn.filereadable(name) == 0 then
vim.fn.mkdir(vim.fn.fnamemodify(name, ":p:h"), "p")
end
vim.cmd("silent! write")
vim.cmd("silent! wall")
end,
})
end