mirror of
https://github.com/zoriya/auto-save.nvim.git
synced 2026-06-02 18:50:37 +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 opts = require("autosave.config").options
|
||||||
local cmd = vim.cmd
|
local cmd = vim.cmd
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local function setup_load()
|
local function setup_load()
|
||||||
if (opts["enabled"] == true) then
|
if opts["enabled"] == true then
|
||||||
require('autosave.main').main('on')
|
vim.g.autosave_state = true
|
||||||
|
require("autosave.main").main("on")
|
||||||
|
else
|
||||||
|
vim.g.autosave_state = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setup_commands()
|
local function setup_commands()
|
||||||
if (opts["on_off_commands"] == true) then
|
if opts["on_off_commands"] == true then
|
||||||
cmd([[command! ASOn lua require'autosave.main'.main('on')]])
|
cmd([[command! ASOn lua require'autosave.main'.main('on')]])
|
||||||
cmd([[command! ASOff lua require'autosave.main'.main('off')]])
|
cmd([[command! ASOff lua require'autosave.main'.main('off')]])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setup(custom_opts)
|
function M.setup(custom_opts)
|
||||||
require("autosave.config").set_options(custom_opts)
|
require("autosave.config").set_options(custom_opts)
|
||||||
setup_load()
|
setup_load()
|
||||||
setup_commands()
|
setup_commands()
|
||||||
end
|
end
|
||||||
|
|||||||
+5
-19
@@ -1,22 +1,8 @@
|
|||||||
local cmd = vim.cmd
|
|
||||||
|
|
||||||
local opts = require("autosave.config").options
|
|
||||||
local autocmds = require("autosave.modules.autocmds")
|
local autocmds = require("autosave.modules.autocmds")
|
||||||
local autosave = require("autosave")
|
local autosave = require("autosave")
|
||||||
local status_autosave
|
local g = vim.g
|
||||||
|
|
||||||
require("autosave.utils.viml_funcs")
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
require("autosave.utils.viml_funcs")
|
||||||
|
|
||||||
local function set_status(value)
|
|
||||||
status_autosave = value
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_status()
|
|
||||||
return status_autosave
|
|
||||||
end
|
|
||||||
|
|
||||||
local function on()
|
local function on()
|
||||||
|
|
||||||
@@ -25,7 +11,7 @@ local function on()
|
|||||||
end
|
end
|
||||||
|
|
||||||
autocmds.load_autocommands()
|
autocmds.load_autocommands()
|
||||||
set_status('on')
|
g.autosave_state = true
|
||||||
|
|
||||||
if (autosave.hook_after_on ~= nil) then
|
if (autosave.hook_after_on ~= nil) then
|
||||||
autosave.hook_after_on()
|
autosave.hook_after_on()
|
||||||
@@ -39,7 +25,7 @@ local function off()
|
|||||||
end
|
end
|
||||||
|
|
||||||
autocmds.unload_autocommands()
|
autocmds.unload_autocommands()
|
||||||
set_status('off')
|
g.autosave_state = false
|
||||||
|
|
||||||
if (autosave.hook_after_off ~= nil) then
|
if (autosave.hook_after_off ~= nil) then
|
||||||
autosave.hook_after_off()
|
autosave.hook_after_off()
|
||||||
@@ -50,7 +36,7 @@ function M.main(option)
|
|||||||
option = option or 'load'
|
option = option or 'load'
|
||||||
|
|
||||||
if (option == 'toggle') then
|
if (option == 'toggle') then
|
||||||
if (get_status() == 'on') then
|
if (g.autosave_state == true) then
|
||||||
off()
|
off()
|
||||||
else
|
else
|
||||||
on()
|
on()
|
||||||
|
|||||||
Reference in New Issue
Block a user