From e513dcd16c6161ede1d5b42e8012d7df1658f188 Mon Sep 17 00:00:00 2001 From: olimorris Date: Thu, 20 Jan 2022 15:24:17 +0000 Subject: [PATCH] feat: :sparkles: 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 --- README.md | 18 +++++++++++------- lua/persisted/config.lua | 3 ++- lua/persisted/init.lua | 4 +++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8f45562..ac19688 100644 --- a/README.md +++ b/README.md @@ -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", "qs", [[lua require("persisted").load()]]) +vim.api.nvim_set_keymap("n", "qr", [[lua require("persisted").load()]]) -- restore the last session vim.api.nvim_set_keymap("n", "ql", [[lua require("persisted").load({ last = true })]]) --- stop Persistence => session won't be saved on exit -vim.api.nvim_set_keymap("n", "qd", [[lua require("persisted").stop()]]) +-- start persisted => if autosave is set to false +vim.api.nvim_set_keymap("n", "qs", [[lua require("persisted").start()]]) + +-- stop persisted => session won't be saved on exit +vim.api.nvim_set_keymap("n", "qx", [[lua require("persisted").stop()]]) ``` diff --git a/lua/persisted/config.lua b/lua/persisted/config.lua index 9606e52..27453e2 100644 --- a/lua/persisted/config.lua +++ b/lua/persisted/config.lua @@ -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 diff --git a/lua/persisted/init.lua b/lua/persisted/init.lua index b9647d8..307a68f 100644 --- a/lua/persisted/init.lua +++ b/lua/persisted/init.lua @@ -40,7 +40,9 @@ end function M.setup(opts) Config.setup(opts) - M.start() + if Config.options.autosave then + M.start() + end end function M.start()