Files
auto-save.nvim/lua/auto-save/config.lua
2023-11-08 09:30:21 +01:00

46 lines
1.9 KiB
Lua

--- @class Config
Config = {
opts = {
enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it)
execution_message = {
enabled = true,
--- @type string|fun(): string
message = function() -- message to print on save
return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S"))
end,
dim = 0.18, -- dim the color of `message`
cleaning_interval = 1250, -- (milliseconds) automatically clean MsgArea after displaying `message`. See :h MsgArea
},
trigger_events = { -- See :h events
--- @type TriggerEvent[]?
immediate_save = { "BufLeave", "FocusLost" }, -- vim events that trigger an immediate save
--- @type TriggerEvent[]?
defer_save = { "InsertLeave", "TextChanged" }, -- vim events that trigger a deferred save (saves after `debounce_delay`)
--- @type TriggerEvent[]?
cancel_defered_save = { "InsertEnter" }, -- vim events that cancel a pending deferred save
},
-- function that takes the buffer handle and determines whether to save the current buffer or not
-- return true: if buffer is ok to be saved
-- return false: if it's not ok to be saved
-- if set to `nil` then no specific condition is applied
--- @type nil|fun(buf: number): boolean
condition = nil,
write_all_buffers = false, -- write all buffers when the current one meets `condition`
noautocmd = false, -- do not execute autocmds when saving
debounce_delay = 1000, -- delay after which a pending save is executed
-- log debug messages to 'auto-save.log' file in neovim cache directory, set to `true` to enable
debug = false, -- print debug messages, set to `true` to enable
},
}
function Config:set_options(opts)
opts = opts or {}
self.opts = vim.tbl_deep_extend("keep", opts, self.opts)
end
function Config:get_options()
return self.opts
end
return Config