mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-06-21 16:39:04 +02:00
add: auto save config
This commit is contained in:
parent
a3143f9ae0
commit
7162f65a13
3 changed files with 41 additions and 0 deletions
37
lua/plugins/autosave.lua
Normal file
37
lua/plugins/autosave.lua
Normal file
|
@ -0,0 +1,37 @@
|
|||
local M = {}
|
||||
if pcode.auto_save then
|
||||
M = {
|
||||
"okuuva/auto-save.nvim",
|
||||
event = { "InsertLeave", "TextChanged" },
|
||||
opts = {
|
||||
execution_message = {
|
||||
enabled = false,
|
||||
},
|
||||
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,
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
Loading…
Add table
Add a link
Reference in a new issue