Compare commits
13 Commits
v1.2.0
...
release-pl
Author | SHA1 | Date | |
---|---|---|---|
55b0b4f434 | |||
95d03ad545 | |||
a2fd3d9965 | |||
5fe077056c | |||
3d443bd0a7 | |||
4982499c16 | |||
9dbe2648c6 | |||
09af251a93 | |||
ad538bfd53 | |||
01d7fa95fe | |||
0361df7775 | |||
9730a073fd | |||
8f7cbccfb5 |
31
CHANGELOG.md
31
CHANGELOG.md
@ -1,5 +1,36 @@
|
||||
# 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)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* **start:** session name is now based on the cwd when the session starts and not when the session ends. Fixes #1688
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **start:** session name is now based on the cwd when the session starts and not when the session ends. Fixes [#1688](https://github.com/folke/persistence.nvim/issues/1688) ([0361df7](https://github.com/folke/persistence.nvim/commit/0361df7775f5b4ed51a6d7fe159438573b7f07a6))
|
||||
|
||||
## [1.2.1](https://github.com/folke/persistence.nvim/compare/v1.2.0...v1.2.1) (2023-10-13)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* dont save the session when only `gitcommit` buffers are present. Fixes [#14](https://github.com/folke/persistence.nvim/issues/14) ([8f7cbcc](https://github.com/folke/persistence.nvim/commit/8f7cbccfb506fe6cb35db9ad966137c363b049c5))
|
||||
|
||||
## [1.2.0](https://github.com/folke/persistence.nvim/compare/v1.1.0...v1.2.0) (2023-10-13)
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
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
|
||||
@ -34,10 +34,13 @@ Persistence comes with the following defaults:
|
||||
|
||||
```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
|
||||
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
|
||||
pre_load = nil, -- a function to call before loading the session
|
||||
post_load = nil, -- a function to call after loading the session
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
*persistence.nvim.txt* For Neovim >= 0.8.0 Last change: 2023 October 13
|
||||
*persistence.nvim.txt* For Neovim >= 0.8.0 Last change: 2024 June 12
|
||||
|
||||
==============================================================================
|
||||
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:
|
||||
|
||||
|
||||
FOLKE ~
|
||||
LAZY.NVIM ~
|
||||
|
||||
>lua
|
||||
-- Lua
|
||||
@ -52,10 +52,13 @@ Persistence comes with the following defaults:
|
||||
|
||||
>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
|
||||
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
|
||||
pre_load = nil, -- a function to call before loading the session
|
||||
post_load = nil, -- a function to call after loading the session
|
||||
}
|
||||
<
|
||||
|
||||
|
@ -2,8 +2,11 @@ local M = {}
|
||||
|
||||
---@class PersistenceOptions
|
||||
---@field pre_save? fun()
|
||||
---@field post_save? fun()
|
||||
---@field pre_load? fun()
|
||||
---@field post_load? fun()
|
||||
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
|
||||
save_empty = false, -- don't save if there are no open file buffers
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
local Config = require("persistence.config")
|
||||
|
||||
local M = {}
|
||||
---@type string?
|
||||
M.current = nil
|
||||
|
||||
local e = vim.fn.fnameescape
|
||||
|
||||
@ -27,6 +29,7 @@ function M.setup(opts)
|
||||
end
|
||||
|
||||
function M.start()
|
||||
M.current = M.get_current()
|
||||
vim.api.nvim_create_autocmd("VimLeavePre", {
|
||||
group = vim.api.nvim_create_augroup("persistence", { clear = true }),
|
||||
callback = function()
|
||||
@ -39,6 +42,12 @@ function M.start()
|
||||
if vim.bo[b].buftype ~= "" then
|
||||
return false
|
||||
end
|
||||
if vim.bo[b].filetype == "gitcommit" then
|
||||
return false
|
||||
end
|
||||
if vim.bo[b].filetype == "gitrebase" then
|
||||
return false
|
||||
end
|
||||
return vim.api.nvim_buf_get_name(b) ~= ""
|
||||
end, vim.api.nvim_list_bufs())
|
||||
if #bufs == 0 then
|
||||
@ -47,18 +56,23 @@ function M.start()
|
||||
end
|
||||
|
||||
M.save()
|
||||
|
||||
if type(Config.options.post_save) == "function" then
|
||||
Config.options.post_save()
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
function M.stop()
|
||||
M.current = nil
|
||||
pcall(vim.api.nvim_del_augroup_by_name, "persistence")
|
||||
end
|
||||
|
||||
function M.save()
|
||||
local tmp = vim.o.sessionoptions
|
||||
vim.o.sessionoptions = table.concat(Config.options.options, ",")
|
||||
vim.cmd("mks! " .. e(M.get_current()))
|
||||
vim.cmd("mks! " .. e(M.current or M.get_current()))
|
||||
vim.o.sessionoptions = tmp
|
||||
end
|
||||
|
||||
@ -66,7 +80,15 @@ function M.load(opt)
|
||||
opt = opt or {}
|
||||
local sfile = opt.last and M.get_last() or M.get_current()
|
||||
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))
|
||||
|
||||
if type(Config.options.post_load) == "function" then
|
||||
Config.options.post_load()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user