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 sessionsmain
parent
d9b386c618
commit
e513dcd16c
18
README.md
18
README.md
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
**Persisted** is a simple lua plugin for automated session management within Neovim.
|
**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
|
## ✨ 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
|
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
|
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
|
## 🚀 Usage
|
||||||
|
|
||||||
**Persisted** works well with plugins like `startify` or `dashboard`. It will never restore a session automatically,
|
**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.
|
||||||
but you can of course write an autocmd that does exactly that if you want.
|
|
||||||
|
|
||||||
|
Some example keybindings are contained below:
|
||||||
```lua
|
```lua
|
||||||
-- restore the session for the current directory
|
-- 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
|
-- restore the last session
|
||||||
vim.api.nvim_set_keymap("n", "<leader>ql", [[<cmd>lua require("persisted").load({ last = true })<cr>]])
|
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
|
-- start persisted => if autosave is set to false
|
||||||
vim.api.nvim_set_keymap("n", "<leader>qd", [[<cmd>lua require("persisted").stop()<cr>]])
|
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>]])
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ local M = {}
|
||||||
local defaults = {
|
local defaults = {
|
||||||
dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved
|
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
|
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
|
---@type PersistedOptions
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,9 @@ end
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
Config.setup(opts)
|
Config.setup(opts)
|
||||||
M.start()
|
if Config.options.autosave then
|
||||||
|
M.start()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.start()
|
function M.start()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue