diff --git a/CHANGELOG.md b/CHANGELOG.md index 8516075..e7e55c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ 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/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.1] - 2026-04-09 + +### Fixed + +- Save after normal mode changes (undo, redo, paste, delete) by adding + `TextChanged` to default events + ## [0.1.0] - 2026-04-09 ### Added @@ -14,4 +21,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Configurable trigger events - Zero-config auto-loading via `plugin/` directory +[0.1.1]: https://github.com/swaits/tiny-autosave.nvim/releases/tag/v0.1.1 [0.1.0]: https://github.com/swaits/tiny-autosave.nvim/releases/tag/v0.1.0 diff --git a/README.md b/README.md index 0fac69c..3bf55cb 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Zero config. ~15 lines of Lua. ## Features -- Auto-saves on leaving insert mode and losing focus +- Auto-saves on leaving insert mode, normal mode changes (undo, paste, etc.), and losing focus - Only saves normal file buffers (skips special buffers) - Configurable trigger events - Works out of the box — no setup call required @@ -32,7 +32,7 @@ All options are optional. Call `setup()` only if you want to customize: ```lua require("tiny-autosave").setup({ - events = { "InsertLeave", "FocusLost" }, -- events that trigger save + events = { "InsertLeave", "TextChanged", "FocusLost" }, -- events that trigger save }) ``` diff --git a/doc/tiny-autosave.txt b/doc/tiny-autosave.txt index 92ef2f9..9590dac 100644 --- a/doc/tiny-autosave.txt +++ b/doc/tiny-autosave.txt @@ -1,4 +1,4 @@ -*tiny-autosave.txt* Auto-save buffers on InsertLeave and FocusLost +*tiny-autosave.txt* Auto-save buffers on text changes and focus loss Author: Stephen Waits License: MIT @@ -15,7 +15,8 @@ CONTENTS *tiny-autosave-contents* 1. INTRODUCTION *tiny-autosave-introduction* tiny-autosave.nvim automatically saves modified buffers when leaving insert -mode or when Neovim loses focus. Works out of the box with zero configuration. +mode, after normal mode changes (undo, paste, etc.), and when Neovim loses +focus. Works out of the box with zero configuration. ============================================================================== 2. REQUIREMENTS *tiny-autosave-requirements* @@ -32,7 +33,7 @@ Add to your |vim.pack.add()| call: >lua That's it. The plugin auto-loads with defaults. To customize, call setup: >lua require("tiny-autosave").setup({ - events = { "InsertLeave", "FocusLost" }, + events = { "InsertLeave", "TextChanged", "FocusLost" }, }) < ============================================================================== @@ -47,7 +48,7 @@ setup({opts}) All options shown with defaults: >lua require("tiny-autosave").setup({ - events = { "InsertLeave", "FocusLost" }, + events = { "InsertLeave", "TextChanged", "FocusLost" }, }) < Parameters: ~ @@ -55,7 +56,7 @@ setup({opts}) Fields: ~ {events} (table) List of events that trigger auto-save. - Default: { "InsertLeave", "FocusLost" } + Default: { "InsertLeave", "TextChanged", "FocusLost" } ============================================================================== vim:tw=78:ts=8:ft=help:norl: diff --git a/lua/tiny-autosave/init.lua b/lua/tiny-autosave/init.lua index 04c28d0..353ffa2 100644 --- a/lua/tiny-autosave/init.lua +++ b/lua/tiny-autosave/init.lua @@ -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