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

Fix issue of auto save and auto format conflicting. #87

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions lua/auto-save/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ api.nvim_create_augroup("AutoSave", {
clear = true,
})


local global_vars = {}
local last_undo_seq = vim.fn.getreginfo('"').undo_seq

local function check_last_command_undo()
local current_undo_seq = vim.fn.getreginfo('"').undo_seq
last_undo_seq = current_undo_seq
return (current_undo_seq ~= last_undo_seq)
end

local function set_buf_var(buf, name, value)
if buf == nil then
Expand Down Expand Up @@ -54,6 +62,11 @@ local function debounce(lfn, duration)
end

function M.save(buf)
if check_last_command_undo() then
api.nvim.echo("Autosave skipped")
return
end

buf = buf or api.nvim_get_current_buf()

callback("before_asserting_save")
Expand Down Expand Up @@ -197,3 +210,4 @@ function M.setup(custom_opts)
end

return M