Skip to content

Commit

Permalink
feat(auto-save-nvim): swap to okuuva repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ALameLlama committed Oct 11, 2024
1 parent 2191331 commit f40a889
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 37 deletions.
5 changes: 0 additions & 5 deletions lua/astrocommunity/completion/magazine-nvim/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions lua/astrocommunity/completion/magazine-nvim/init.lua

This file was deleted.

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>
64 changes: 37 additions & 27 deletions lua/astrocommunity/editing-support/auto-save-nvim/init.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
local group = vim.api.nvim_create_augroup("autosave", {})

-- Disable autoformat before saving
vim.api.nvim_create_autocmd("User", {
pattern = "AutoSaveWritePre",
group = group,
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
vim.api.nvim_create_autocmd("User", {
pattern = "AutoSaveWritePost",
group = group,
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,
})

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,
},
},
opts = {},
}

0 comments on commit f40a889

Please sign in to comment.