From c7427f4d7899f7b42d356775e55667964db83ee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20M=C3=BCller?= Date: Fri, 21 Jul 2023 08:32:24 +0200 Subject: [PATCH] feat: [#15] Implement config option for `noautocmd` (#31) --- README.md | 1 + lua/auto-save/config.lua | 1 + lua/auto-save/init.lua | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c9a06a2..5952ed8 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ EOF -- if set to `nil` then no specific condition is applied condition = nil, write_all_buffers = false, -- write all buffers when the current one meets `condition` + noautocmd = false, -- do not execute autocmds when saving debounce_delay = 1000, -- delay after which a pending save is executed -- log debug messages to 'auto-save.log' file in neovim cache directory, set to `true` to enable debug = false, diff --git a/lua/auto-save/config.lua b/lua/auto-save/config.lua index 07d3d80..ae5cbf8 100644 --- a/lua/auto-save/config.lua +++ b/lua/auto-save/config.lua @@ -23,6 +23,7 @@ Config = { --- @type nil|fun(buf: number): boolean condition = nil, write_all_buffers = false, -- write all buffers when the current one meets `condition` + noautocmd = false, -- do not execute autocmds when saving debounce_delay = 1000, -- delay after which a pending save is executed -- log debug messages to 'auto-save.log' file in neovim cache directory, set to `true` to enable debug = false, -- print debug messages, set to `true` to enable diff --git a/lua/auto-save/init.lua b/lua/auto-save/init.lua index 85113a6..032b002 100644 --- a/lua/auto-save/init.lua +++ b/lua/auto-save/init.lua @@ -81,11 +81,12 @@ local function save(buf) autocmds.exec_autocmd("AutoSaveWritePre", buf) + local noautocmd = cnf.opts.noautocmd and "noautocmd " or "" if cnf.opts.write_all_buffers then - cmd("silent! wall") + cmd(noautocmd .. "silent! wall") else api.nvim_buf_call(buf, function() - cmd("silent! write") + cmd(noautocmd .. "silent! write") end) end