feat: add option to disable autosave

As per: https://github.com/folke/persistence.nvim/pull/4

Think is a useful feature to have as users may wish to manually trigger the saving of sessions
main
olimorris 2022-01-20 15:24:17 +00:00
parent d9b386c618
commit e513dcd16c
3 changed files with 16 additions and 9 deletions

View File

@ -2,7 +2,7 @@
**Persisted** is a simple lua plugin for automated session management within Neovim.
The plugin was forked from the fantastic [Persistence.nvim](https://github.com/folke/persistence.nvim) as active development had paused.
The plugin was forked from the fantastic [Persistence.nvim](https://github.com/folke/persistence.nvim) as active development seems to have been paused and there were some useful pull requests.
## ✨ Features
@ -55,22 +55,26 @@ Persisted comes with the following defaults:
{
dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved
use_git_branch = false, -- create session files based on the branch of the git enabled repository
options = { "buffers", "curdir", "tabpages", "winsize" }, -- sessionoptions used for saving
autosave = true, -- automatically save session files
options = { "buffers", "curdir", "tabpages", "winsize" }, -- session options used for saving
}
```
## 🚀 Usage
**Persisted** works well with plugins like `startify` or `dashboard`. It will never restore a session automatically,
but you can of course write an autocmd that does exactly that if you want.
**Persisted** works well with plugins like `startify` or `dashboard`. It will never restore a session automatically, but you can of course write an autocmd that does exactly that.
Some example keybindings are contained below:
```lua
-- restore the session for the current directory
vim.api.nvim_set_keymap("n", "<leader>qs", [[<cmd>lua require("persisted").load()<cr>]])
vim.api.nvim_set_keymap("n", "<leader>qr", [[<cmd>lua require("persisted").load()<cr>]])
-- restore the last session
vim.api.nvim_set_keymap("n", "<leader>ql", [[<cmd>lua require("persisted").load({ last = true })<cr>]])
-- stop Persistence => session won't be saved on exit
vim.api.nvim_set_keymap("n", "<leader>qd", [[<cmd>lua require("persisted").stop()<cr>]])
-- start persisted => if autosave is set to false
vim.api.nvim_set_keymap("n", "<leader>qs", [[<cmd>lua require("persisted").start()<cr>]])
-- stop persisted => session won't be saved on exit
vim.api.nvim_set_keymap("n", "<leader>qx", [[<cmd>lua require("persisted").stop()<cr>]])
```

View File

@ -4,7 +4,8 @@ local M = {}
local defaults = {
dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved
use_git_branch = false, -- create session files based on the branch of the git enabled repository
options = { "buffers", "curdir", "tabpages", "winsize" }, -- sessionoptions used for saving
autosave = true, -- automatically save session files
options = { "buffers", "curdir", "tabpages", "winsize" }, -- session options used for saving
}
---@type PersistedOptions

View File

@ -40,7 +40,9 @@ end
function M.setup(opts)
Config.setup(opts)
if Config.options.autosave then
M.start()
end
end
function M.start()