Add additional 'using_persistence' global vars

In further testing, it became clear that adding the global variables to the setup and start functions would be useful.

It also seemed to make sense to return boolean values to detect if Persistence has stopped (false) or is in active use (true).
main
olimorris 2021-09-07 22:31:12 +01:00
parent f4e7632db2
commit 2d6a222073
1 changed files with 4 additions and 3 deletions

View File

@ -43,14 +43,15 @@ function M.start()
autocmd VimLeavePre * lua require("persistence").save() autocmd VimLeavePre * lua require("persistence").save()
augroup end augroup end
]]) ]])
vim.g.using_persistence = true
end end
function M.stop() function M.stop()
vim.g.using_persistence = nil
vim.cmd([[ vim.cmd([[
autocmd! Persistence autocmd! Persistence
augroup! Persistence augroup! Persistence
]]) ]])
vim.g.using_persistence = false
end end
function M.save() function M.save()
@ -58,15 +59,15 @@ function M.save()
vim.o.sessionoptions = table.concat(Config.options.options, ",") vim.o.sessionoptions = table.concat(Config.options.options, ",")
vim.cmd("mks! " .. e(M.get_current())) vim.cmd("mks! " .. e(M.get_current()))
vim.o.sessionoptions = tmp vim.o.sessionoptions = tmp
vim.g.using_persistence = e(M.get_current()) vim.g.using_persistence = true
end end
function M.load(opt) function M.load(opt)
opt = opt or {} opt = opt or {}
local sfile = opt.last and M.get_last() or M.get_current() local sfile = opt.last and M.get_last() or M.get_current()
if sfile and vim.fn.filereadable(sfile) ~= 0 then if sfile and vim.fn.filereadable(sfile) ~= 0 then
vim.g.using_persistence = e(sfile)
vim.cmd("source " .. e(sfile)) vim.cmd("source " .. e(sfile))
vim.g.using_persistence = true
end end
end end