From ee65d951937c34b636947b31905e7f98f675e472 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Tue, 8 Aug 2023 14:48:47 -0400 Subject: [PATCH] fix(auto-save-nvim): disable format on save when auto saving (#511) --- .../editing-support/auto-save-nvim/init.lua | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/lua/astrocommunity/editing-support/auto-save-nvim/init.lua b/lua/astrocommunity/editing-support/auto-save-nvim/init.lua index 1c056798e..d7f1d232e 100644 --- a/lua/astrocommunity/editing-support/auto-save-nvim/init.lua +++ b/lua/astrocommunity/editing-support/auto-save-nvim/init.lua @@ -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, + }, + }, }