-
-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auto-save-nvim)!: swap to okuuva repo (#1239)
* feat(auto-save-nvim): swap to okuuva repo * feat(autosave-nvim): move to astrocore autocmd
- Loading branch information
1 parent
6c4c080
commit 033dde8
Showing
2 changed files
with
43 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 42 additions & 25 deletions
67
lua/astrocommunity/editing-support/auto-save-nvim/init.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {}, | ||
} |