Skip to content

Commit

Permalink
fix(auto-save-nvim): disable format on save when auto saving (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter authored Aug 8, 2023
1 parent 28f3865 commit ee65d95
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions lua/astrocommunity/editing-support/auto-save-nvim/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
return {
"Pocco81/auto-save.nvim",
-- "Pocco81/auto-save.nvim",
"zoriya/auto-save.nvim", -- HACK: use fork until PR is accepted
event = { "User AstroFile", "InsertEnter" },
opts = {},
opts = {
callbacks = {
before_saving = function()
-- save global autoformat status
vim.g.OLD_AUTOFORMAT = vim.g.autoformat_enabled

vim.g.autoformat_enabled = false
vim.g.OLD_AUTOFORMAT_BUFFERS = {}
-- disable all manually enabled buffers
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
if vim.b[bufnr].autoformat_enabled then
table.insert(vim.g.OLD_BUFFER_AUTOFORMATS, bufnr)
vim.b[bufnr].autoformat_enabled = false
end
end
end,
after_saving = function()
-- restore global autoformat status
vim.g.autoformat_enabled = vim.g.OLD_AUTOFORMAT
-- reenable all manually enabled buffers
for _, bufnr in ipairs(vim.g.OLD_AUTOFORMAT_BUFFERS or {}) do
vim.b[bufnr].autoformat_enabled = true
end
end,
},
},
}

0 comments on commit ee65d95

Please sign in to comment.