Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
016ca89f87
|
||
|
|
e95071442b
|
||
|
|
c06115fa81
|
No files matched your search
+20
-2
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [0.1.2] - 2026-04-12
|
||||||
|
|
||||||
|
### 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.
|
||||||
|
|
||||||
## [0.1.1] - 2026-04-09
|
## [0.1.1] - 2026-04-09
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
@@ -21,5 +38,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Configurable trigger events
|
- Configurable trigger events
|
||||||
- Zero-config auto-loading via `plugin/` directory
|
- Zero-config auto-loading via `plugin/` directory
|
||||||
|
|
||||||
[0.1.1]: https://github.com/swaits/tiny-autosave.nvim/releases/tag/v0.1.1
|
[0.1.2]: https://git.swaits.com/swaits/tiny-autosave.nvim/releases/tag/v0.1.2
|
||||||
[0.1.0]: https://github.com/swaits/tiny-autosave.nvim/releases/tag/v0.1.0
|
[0.1.1]: https://git.swaits.com/swaits/tiny-autosave.nvim/releases/tag/v0.1.1
|
||||||
|
[0.1.0]: https://git.swaits.com/swaits/tiny-autosave.nvim/releases/tag/v0.1.0
|
||||||
@@ -21,7 +21,7 @@ Zero config. ~15 lines of Lua.
|
|||||||
Add to your `vim.pack.add()` call:
|
Add to your `vim.pack.add()` call:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
"https://github.com/swaits/tiny-autosave.nvim",
|
"https://git.swaits.com/swaits/tiny-autosave.nvim",
|
||||||
```
|
```
|
||||||
|
|
||||||
Done. The plugin auto-loads with sensible defaults.
|
Done. The plugin auto-loads with sensible defaults.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
*tiny-autosave.txt* Auto-save buffers on text changes and focus loss
|
*tiny-autosave.txt* Auto-save buffers on text changes and focus loss
|
||||||
|
|
||||||
Author: Stephen Waits <https://github.com/swaits>
|
Author: Stephen Waits <https://git.swaits.com/swaits>
|
||||||
License: MIT
|
License: MIT
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
@@ -28,7 +28,7 @@ focus. Works out of the box with zero configuration.
|
|||||||
|
|
||||||
Add to your |vim.pack.add()| call: >lua
|
Add to your |vim.pack.add()| call: >lua
|
||||||
|
|
||||||
"https://github.com/swaits/tiny-autosave.nvim",
|
"https://git.swaits.com/swaits/tiny-autosave.nvim",
|
||||||
<
|
<
|
||||||
That's it. The plugin auto-loads with defaults. To customize, call setup: >lua
|
That's it. The plugin auto-loads with defaults. To customize, call setup: >lua
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,22 @@ function M.setup(opts)
|
|||||||
|
|
||||||
vim.api.nvim_create_autocmd(events, {
|
vim.api.nvim_create_autocmd(events, {
|
||||||
group = vim.api.nvim_create_augroup("tiny-autosave", { clear = true }),
|
group = vim.api.nvim_create_augroup("tiny-autosave", { clear = true }),
|
||||||
callback = function()
|
nested = true,
|
||||||
local name = vim.api.nvim_buf_get_name(0)
|
callback = function(args)
|
||||||
if name ~= "" and vim.fn.filereadable(name) == 0 then
|
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")
|
vim.fn.mkdir(vim.fn.fnamemodify(name, ":p:h"), "p")
|
||||||
end
|
end
|
||||||
vim.cmd("silent! write")
|
vim.api.nvim_buf_call(buf, function()
|
||||||
vim.cmd("silent! wall")
|
vim.cmd("silent keepalt keepjumps write")
|
||||||
|
end)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,4 +21,53 @@ T["setup"]["respects custom events"] = function()
|
|||||||
eq(#groups, 1)
|
eq(#groups, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
T["save"] = MiniTest.new_set()
|
||||||
|
|
||||||
|
T["save"]["fires BufWritePre once and applies formatter changes"] = function()
|
||||||
|
require("tiny-autosave").setup()
|
||||||
|
local tmp = vim.fn.tempname() .. ".txt"
|
||||||
|
vim.cmd("edit " .. tmp)
|
||||||
|
local buf = vim.api.nvim_get_current_buf()
|
||||||
|
local pre_count = 0
|
||||||
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
|
buffer = buf,
|
||||||
|
callback = function()
|
||||||
|
pre_count = pre_count + 1
|
||||||
|
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { "formatted" })
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { "original", "", "", "" })
|
||||||
|
vim.api.nvim_exec_autocmds("InsertLeave", { buffer = buf })
|
||||||
|
eq(pre_count, 1)
|
||||||
|
eq(vim.fn.readfile(tmp), { "formatted" })
|
||||||
|
os.remove(tmp)
|
||||||
|
end
|
||||||
|
|
||||||
|
T["save"]["skips unnamed buffers"] = function()
|
||||||
|
require("tiny-autosave").setup()
|
||||||
|
vim.cmd("enew")
|
||||||
|
local buf = vim.api.nvim_get_current_buf()
|
||||||
|
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { "scratch" })
|
||||||
|
local ok = pcall(vim.api.nvim_exec_autocmds, "InsertLeave", {})
|
||||||
|
eq(ok, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
T["save"]["skips unmodified buffers"] = function()
|
||||||
|
require("tiny-autosave").setup()
|
||||||
|
local tmp = vim.fn.tempname() .. ".txt"
|
||||||
|
vim.fn.writefile({ "hello" }, tmp)
|
||||||
|
vim.cmd("edit " .. tmp)
|
||||||
|
local buf = vim.api.nvim_get_current_buf()
|
||||||
|
local pre_count = 0
|
||||||
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
|
buffer = buf,
|
||||||
|
callback = function()
|
||||||
|
pre_count = pre_count + 1
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
vim.api.nvim_exec_autocmds("InsertLeave", { buffer = buf })
|
||||||
|
eq(pre_count, 0)
|
||||||
|
os.remove(tmp)
|
||||||
|
end
|
||||||
|
|
||||||
return T
|
return T
|
||||||
Reference in new issue
Block a user