mirror of
https://github.com/zoriya/auto-save.nvim.git
synced 2025-12-06 06:36:11 +00:00
67 lines
1.1 KiB
Lua
67 lines
1.1 KiB
Lua
local cmd = vim.cmd
|
|
|
|
local opts = require("autosave.config").options
|
|
local autocmds = require("autosave.modules.autocmds")
|
|
local autosave = require("autosave")
|
|
|
|
local M = {}
|
|
|
|
|
|
local function set_status(value)
|
|
status_autosave = value
|
|
end
|
|
|
|
local function get_status()
|
|
return status_autosave
|
|
end
|
|
|
|
local function on()
|
|
|
|
if (autosave.hook_before_on ~= nil) then
|
|
autosave.hook_before_on()
|
|
end
|
|
|
|
autocmds.load_autocommands()
|
|
set_status('on')
|
|
|
|
if (autosave.hook_after_on ~= nil) then
|
|
autosave.hook_after_on()
|
|
end
|
|
end
|
|
|
|
local function off()
|
|
|
|
if (autosave.hook_before_off ~= nil) then
|
|
autosave.hook_before_off()
|
|
end
|
|
|
|
autocmds.unload_autocommands()
|
|
set_status('off')
|
|
|
|
if (autosave.hook_after_off ~= nil) then
|
|
autosave.hook_after_off()
|
|
end
|
|
end
|
|
|
|
function M.main(option)
|
|
option = option or 'load'
|
|
|
|
if (option == 'toggle') then
|
|
if (get_status() == 'on') then
|
|
off()
|
|
else
|
|
on()
|
|
end
|
|
elseif (option == 'on') then
|
|
on()
|
|
elseif (option == 'off') then
|
|
off()
|
|
elseif (option == 'startup') then
|
|
if (opts["enabled"] == true) then
|
|
on()
|
|
end
|
|
end
|
|
end
|
|
|
|
return M
|