mirror of
https://github.com/zoriya/auto-save.nvim.git
synced 2026-05-17 05:13:08 +00:00
feat #18: global var to check for current state
This commit is contained in:
@@ -1,24 +1,26 @@
|
||||
|
||||
local opts = require("autosave.config").options
|
||||
local cmd = vim.cmd
|
||||
|
||||
local M = {}
|
||||
|
||||
local function setup_load()
|
||||
if (opts["enabled"] == true) then
|
||||
require('autosave.main').main('on')
|
||||
if opts["enabled"] == true then
|
||||
vim.g.autosave_state = true
|
||||
require("autosave.main").main("on")
|
||||
else
|
||||
vim.g.autosave_state = false
|
||||
end
|
||||
end
|
||||
|
||||
local function setup_commands()
|
||||
if (opts["on_off_commands"] == true) then
|
||||
cmd([[command! ASOn lua require'autosave.main'.main('on')]])
|
||||
cmd([[command! ASOff lua require'autosave.main'.main('off')]])
|
||||
if opts["on_off_commands"] == true then
|
||||
cmd([[command! ASOn lua require'autosave.main'.main('on')]])
|
||||
cmd([[command! ASOff lua require'autosave.main'.main('off')]])
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(custom_opts)
|
||||
require("autosave.config").set_options(custom_opts)
|
||||
require("autosave.config").set_options(custom_opts)
|
||||
setup_load()
|
||||
setup_commands()
|
||||
end
|
||||
|
||||
+5
-19
@@ -1,22 +1,8 @@
|
||||
local cmd = vim.cmd
|
||||
|
||||
local opts = require("autosave.config").options
|
||||
local autocmds = require("autosave.modules.autocmds")
|
||||
local autosave = require("autosave")
|
||||
local status_autosave
|
||||
|
||||
require("autosave.utils.viml_funcs")
|
||||
|
||||
local g = vim.g
|
||||
local M = {}
|
||||
|
||||
|
||||
local function set_status(value)
|
||||
status_autosave = value
|
||||
end
|
||||
|
||||
local function get_status()
|
||||
return status_autosave
|
||||
end
|
||||
require("autosave.utils.viml_funcs")
|
||||
|
||||
local function on()
|
||||
|
||||
@@ -25,7 +11,7 @@ local function on()
|
||||
end
|
||||
|
||||
autocmds.load_autocommands()
|
||||
set_status('on')
|
||||
g.autosave_state = true
|
||||
|
||||
if (autosave.hook_after_on ~= nil) then
|
||||
autosave.hook_after_on()
|
||||
@@ -39,7 +25,7 @@ local function off()
|
||||
end
|
||||
|
||||
autocmds.unload_autocommands()
|
||||
set_status('off')
|
||||
g.autosave_state = false
|
||||
|
||||
if (autosave.hook_after_off ~= nil) then
|
||||
autosave.hook_after_off()
|
||||
@@ -50,7 +36,7 @@ function M.main(option)
|
||||
option = option or 'load'
|
||||
|
||||
if (option == 'toggle') then
|
||||
if (get_status() == 'on') then
|
||||
if (g.autosave_state == true) then
|
||||
off()
|
||||
else
|
||||
on()
|
||||
|
||||
Reference in New Issue
Block a user