8 Commits

Author SHA1 Message Date
55b0b4f434 chore(main): release 2.1.0 2024-06-12 03:54:06 +00:00
95d03ad545 chore(build): auto-generate vimdoc 2024-06-12 03:53:44 +00:00
a2fd3d9965 fix: remove expand() as stdpath() expands itself (#50) 2024-06-12 05:53:08 +02:00
5fe077056c chore(build): auto-generate vimdoc 2024-05-16 17:03:50 +00:00
3d443bd0a7 feat(persistence): add pre- and post- load hooks (#24)
* Add optional hook typings to config object

* Add optional hooks conditional calls

* Add hooks description to main readme
2024-05-16 19:03:16 +02:00
4982499c16 chore(build): auto-generate vimdoc 2024-01-19 15:14:59 +00:00
9dbe2648c6 fix: don't save gitrebase session (#44) 2024-01-19 16:14:29 +01:00
09af251a93 docs: folke => lazy.nvim (#39) 2024-01-19 16:14:01 +01:00
5 changed files with 43 additions and 6 deletions

View File

@ -1,5 +1,18 @@
# Changelog # Changelog
## [2.1.0](https://github.com/folke/persistence.nvim/compare/v2.0.0...v2.1.0) (2024-06-12)
### Features
* **persistence:** add `pre-` and `post-` load hooks ([#24](https://github.com/folke/persistence.nvim/issues/24)) ([3d443bd](https://github.com/folke/persistence.nvim/commit/3d443bd0a7e1d9eebfa37321fc8118d8d538af13))
### Bug Fixes
* don't save `gitrebase` session ([#44](https://github.com/folke/persistence.nvim/issues/44)) ([9dbe264](https://github.com/folke/persistence.nvim/commit/9dbe2648c67b678bf7fe688f03b57a2514e03e6f))
* remove expand() as stdpath() expands itself ([#50](https://github.com/folke/persistence.nvim/issues/50)) ([a2fd3d9](https://github.com/folke/persistence.nvim/commit/a2fd3d99656ac496e56233aa4a40dd045a16fdc4))
## [2.0.0](https://github.com/folke/persistence.nvim/compare/v1.2.1...v2.0.0) (2023-10-15) ## [2.0.0](https://github.com/folke/persistence.nvim/compare/v1.2.1...v2.0.0) (2023-10-15)

View File

@ -15,7 +15,7 @@
Install the plugin with your preferred package manager: Install the plugin with your preferred package manager:
### [folke](https://github.com/folke/lazy.nvim) ### [lazy.nvim](https://github.com/folke/lazy.nvim)
```lua ```lua
-- Lua -- Lua
@ -34,10 +34,13 @@ Persistence comes with the following defaults:
```lua ```lua
{ {
dir = vim.fn.expand(vim.fn.stdpath("state") .. "/sessions/"), -- directory where session files are saved dir = vim.fn.stdpath("state") .. "/sessions/", -- directory where session files are saved
options = { "buffers", "curdir", "tabpages", "winsize" }, -- sessionoptions used for saving options = { "buffers", "curdir", "tabpages", "winsize" }, -- sessionoptions used for saving
pre_save = nil, -- a function to call before saving the session pre_save = nil, -- a function to call before saving the session
post_save = nil, -- a function to call after saving the session
save_empty = false, -- don't save if there are no open file buffers save_empty = false, -- don't save if there are no open file buffers
pre_load = nil, -- a function to call before loading the session
post_load = nil, -- a function to call after loading the session
} }
``` ```

View File

@ -1,4 +1,4 @@
*persistence.nvim.txt* For Neovim >= 0.8.0 Last change: 2023 October 15 *persistence.nvim.txt* For Neovim >= 0.8.0 Last change: 2024 June 12
============================================================================== ==============================================================================
Table of Contents *persistence.nvim-table-of-contents* Table of Contents *persistence.nvim-table-of-contents*
@ -32,7 +32,7 @@ INSTALLATION *persistence.nvim-persistence-installation*
Install the plugin with your preferred package manager: Install the plugin with your preferred package manager:
FOLKE ~ LAZY.NVIM ~
>lua >lua
-- Lua -- Lua
@ -52,10 +52,13 @@ Persistence comes with the following defaults:
>lua >lua
{ {
dir = vim.fn.expand(vim.fn.stdpath("state") .. "/sessions/"), -- directory where session files are saved dir = vim.fn.stdpath("state") .. "/sessions/", -- directory where session files are saved
options = { "buffers", "curdir", "tabpages", "winsize" }, -- sessionoptions used for saving options = { "buffers", "curdir", "tabpages", "winsize" }, -- sessionoptions used for saving
pre_save = nil, -- a function to call before saving the session pre_save = nil, -- a function to call before saving the session
post_save = nil, -- a function to call after saving the session
save_empty = false, -- don't save if there are no open file buffers save_empty = false, -- don't save if there are no open file buffers
pre_load = nil, -- a function to call before loading the session
post_load = nil, -- a function to call after loading the session
} }
< <

View File

@ -2,8 +2,11 @@ local M = {}
---@class PersistenceOptions ---@class PersistenceOptions
---@field pre_save? fun() ---@field pre_save? fun()
---@field post_save? fun()
---@field pre_load? fun()
---@field post_load? fun()
local defaults = { local defaults = {
dir = vim.fn.expand(vim.fn.stdpath("state") .. "/sessions/"), -- directory where session files are saved dir = vim.fn.stdpath("state") .. "/sessions/", -- directory where session files are saved
options = { "buffers", "curdir", "tabpages", "winsize", "skiprtp" }, -- sessionoptions used for saving options = { "buffers", "curdir", "tabpages", "winsize", "skiprtp" }, -- sessionoptions used for saving
save_empty = false, -- don't save if there are no open file buffers save_empty = false, -- don't save if there are no open file buffers
} }

View File

@ -45,6 +45,9 @@ function M.start()
if vim.bo[b].filetype == "gitcommit" then if vim.bo[b].filetype == "gitcommit" then
return false return false
end end
if vim.bo[b].filetype == "gitrebase" then
return false
end
return vim.api.nvim_buf_get_name(b) ~= "" return vim.api.nvim_buf_get_name(b) ~= ""
end, vim.api.nvim_list_bufs()) end, vim.api.nvim_list_bufs())
if #bufs == 0 then if #bufs == 0 then
@ -53,6 +56,10 @@ function M.start()
end end
M.save() M.save()
if type(Config.options.post_save) == "function" then
Config.options.post_save()
end
end, end,
}) })
end end
@ -73,7 +80,15 @@ 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
if type(Config.options.pre_load) == "function" then
Config.options.pre_load()
end
vim.cmd("silent! source " .. e(sfile)) vim.cmd("silent! source " .. e(sfile))
if type(Config.options.post_load) == "function" then
Config.options.post_load()
end
end end
end end