Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow autosaving without triggering post-save commands #58

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ EOF
```lua
{
enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it)
noautocmd_save = false, -- prevent auto-save from triggering events like autoformatting
execution_message = {
message = function() -- message to print on save
return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S"))
Expand Down
1 change: 1 addition & 0 deletions lua/auto-save/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Config = {
end
return false -- can't save
end,
noautocmd_save = false, -- prevent auto-save from triggering events like autoformatting
write_all_buffers = false, -- write all buffers when the current one meets `condition`
debounce_delay = 135, -- saves the file at most every `debounce_delay` milliseconds
callbacks = { -- functions to be executed at different intervals
Expand Down
10 changes: 8 additions & 2 deletions lua/auto-save/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,16 @@ function M.save(buf)
return
end

local save_command_prefix = ""

if cnf.opts.noautocmd_save then
save_command_prefix = "noautocmd "
end

if cnf.opts.write_all_buffers then
cmd("silent! wall")
cmd(save_command_prefix .. "silent! wall")
else
api.nvim_buf_call(buf, function () cmd("silent! write") end)
api.nvim_buf_call(buf, function () cmd(save_command_prefix .. "silent! write") end)
end

callback("after_saving")
Expand Down