diff options
Diffstat (limited to '.config/nvim/lua/plugins/auto-save.lua')
| -rw-r--r-- | .config/nvim/lua/plugins/auto-save.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/.config/nvim/lua/plugins/auto-save.lua b/.config/nvim/lua/plugins/auto-save.lua new file mode 100644 index 0000000..5da836b --- /dev/null +++ b/.config/nvim/lua/plugins/auto-save.lua @@ -0,0 +1,33 @@ +return { + 'okuuva/auto-save.nvim', + cmd = 'ASToggle', + event = { 'InsertLeave', 'TextChanged' }, + opts = function() + -- Disable autoformat between automatic saves + vim.api.nvim_create_autocmd('User', { + pattern = 'AutoSaveWritePre', + group = vim.api.nvim_create_augroup('autosave-pre', { clear = true }), + callback = function(opts) + local bufnr = opts.data.saved_buffer + vim.b[bufnr].disable_autoformat = true + end, + }) + + vim.api.nvim_create_autocmd('User', { + pattern = 'AutoSaveWritePost', + group = vim.api.nvim_create_augroup('autosave-post', { clear = true }), + callback = function(opts) + local bufnr = opts.data.saved_buffer + vim.b[bufnr].disable_autoformat = false + end, + }) + + return { + -- execution_message = { enabled = false }, removed + condition = function(buf) + -- Save only if the buffer is not a "special buffer" + return vim.fn.getbufvar(buf, '&buftype') == '' + end, + } + end, +} |
