add: auto save config

This commit is contained in:
asep.komarudin 2024-06-25 06:41:59 +07:00
parent a3143f9ae0
commit 7162f65a13
3 changed files with 41 additions and 0 deletions

View file

@ -3,6 +3,7 @@
"FixCursorHold.nvim": { "branch": "master", "commit": "1900f89dc17c603eec29960f57c00bd9ae696495" },
"LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" },
"alpha-nvim": { "branch": "main", "commit": "41283fb402713fc8b327e60907f74e46166f4cfd" },
"auto-save.nvim": { "branch": "main", "commit": "5fe9ab0c42f0457f2a973e814a6352b8eeb04730" },
"bigfile.nvim": { "branch": "main", "commit": "33eb067e3d7029ac77e081cfe7c45361887a311a" },
"bufferline.nvim": { "branch": "main", "commit": "1662fed6ecd512d1f381fc2a4e77532c379d25c6" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },

View file

@ -128,6 +128,9 @@ pcode.adaptive_color_icon = true
-- https://github.com/lukas-reineke/virt-column.nvim
pcode.columnline = true
-- https://github.com/okuuva/auto-save.nvim
pcode.auto_save = true
-- https://github.com/nvim-telescope/telescope.nvim
---@alias telescope_themes
---| "cursor" # see `telescope.themes.get_cursor()`

37
lua/plugins/autosave.lua Normal file
View 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