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(auto-save-nvim)!: swap to okuuva repo #1239

Merged
merged 2 commits into from
Oct 23, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

🧶 Automatically save your changes in NeoVim

**Repository:** <https://github.com/Pocco81/auto-save.nvim>
**Repository:** <https://github.com/okuuva/auto-save.nvim>
67 changes: 42 additions & 25 deletions lua/astrocommunity/editing-support/auto-save-nvim/init.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
return {
"Pocco81/auto-save.nvim",
"okuuva/auto-save.nvim",
event = { "User AstroFile", "InsertEnter" },
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,
dependencies = {
"AstroNvim/astrocore",
opts = {
autocmds = {
autoformat_toggle = {
-- Disable autoformat before saving
{
event = "User",
desc = "Disable autoformat before saving",
pattern = "AutoSaveWritePre",
callback = function()
-- Save global autoformat status
vim.g.OLD_AUTOFORMAT = vim.g.autoformat
vim.g.autoformat = 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 then
table.insert(vim.g.OLD_AUTOFORMAT_BUFFERS, bufnr)
vim.b[bufnr].autoformat = false
end
end
end,
},
-- Re-enable autoformat after saving
{
event = "User",
desc = "Re-enable autoformat after saving",
pattern = "AutoSaveWritePost",
callback = function()
-- Restore global autoformat status
vim.g.autoformat = vim.g.OLD_AUTOFORMAT
-- Re-enable all manually enabled buffers
for _, bufnr in ipairs(vim.g.OLD_AUTOFORMAT_BUFFERS or {}) do
vim.b[bufnr].autoformat = true
end
end,
},
},
},
},
},
opts = {},
}
Loading