chore: release 0.1.2
### Fixed - `BufWritePre` formatters (e.g. conform.nvim format-on-save) now run on autosave. The trigger autocmd now uses `nested = true`, so the `:write` invoked from inside the `InsertLeave` / `TextChanged` / `FocusLost` handler fires nested autocmds (see `:help autocmd-nested`). ### Changed - Skip saves for unmodified, unnamed, or special (`buftype`) buffers instead of always attempting a write. - Drop `:wall` — autosave only writes the buffer the event fired on. - Use `silent` (not `silent!`) so write errors surface instead of being swallowed.
This commit is contained in:
3 files changed
+81
-5
No files matched your search
@@ -9,13 +9,22 @@ function M.setup(opts)
|
||||
|
||||
vim.api.nvim_create_autocmd(events, {
|
||||
group = vim.api.nvim_create_augroup("tiny-autosave", { clear = true }),
|
||||
callback = function()
|
||||
local name = vim.api.nvim_buf_get_name(0)
|
||||
if name ~= "" and vim.fn.filereadable(name) == 0 then
|
||||
nested = true,
|
||||
callback = function(args)
|
||||
local buf = args.buf
|
||||
if vim.bo[buf].buftype ~= "" or not vim.bo[buf].modified then
|
||||
return
|
||||
end
|
||||
local name = vim.api.nvim_buf_get_name(buf)
|
||||
if name == "" then
|
||||
return
|
||||
end
|
||||
if 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")
|
||||
vim.api.nvim_buf_call(buf, function()
|
||||
vim.cmd("silent keepalt keepjumps write")
|
||||
end)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user