Compare commits
21 Commits
v1.1.0
...
release-pl
Author | SHA1 | Date | |
---|---|---|---|
55b0b4f434 | |||
95d03ad545 | |||
a2fd3d9965 | |||
5fe077056c | |||
3d443bd0a7 | |||
4982499c16 | |||
9dbe2648c6 | |||
09af251a93 | |||
ad538bfd53 | |||
01d7fa95fe | |||
0361df7775 | |||
9730a073fd | |||
8f7cbccfb5 | |||
21f55da0d3 | |||
878c3b32d9 | |||
e9afeaf3a7 | |||
4b8051c01f | |||
7b86ec2430 | |||
c814fae5c3 | |||
4d2857b647 | |||
74475d1f7d |
3
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
3
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@ -16,7 +16,7 @@ body:
|
|||||||
required: true
|
required: true
|
||||||
- label: I have searched the existing issues of persistence.nvim
|
- label: I have searched the existing issues of persistence.nvim
|
||||||
required: true
|
required: true
|
||||||
- label: I have searched the exsiting issues of plugins related to this issue
|
- label: I have searched the existing issues of plugins related to this issue
|
||||||
required: true
|
required: true
|
||||||
- type: input
|
- type: input
|
||||||
attributes:
|
attributes:
|
||||||
@ -59,6 +59,7 @@ body:
|
|||||||
value: |
|
value: |
|
||||||
-- DO NOT change the paths and don't remove the colorscheme
|
-- DO NOT change the paths and don't remove the colorscheme
|
||||||
local root = vim.fn.fnamemodify("./.repro", ":p")
|
local root = vim.fn.fnamemodify("./.repro", ":p")
|
||||||
|
|
||||||
-- set stdpaths to use .repro
|
-- set stdpaths to use .repro
|
||||||
for _, name in ipairs({ "config", "data", "state", "cache" }) do
|
for _, name in ipairs({ "config", "data", "state", "cache" }) do
|
||||||
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
|
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
|
||||||
|
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@ -15,8 +15,12 @@ jobs:
|
|||||||
- name: Install Neovim
|
- name: Install Neovim
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
wget -q https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.deb -O /tmp/nvim.deb
|
mkdir -p /tmp/nvim
|
||||||
sudo dpkg -i /tmp/nvim.deb
|
wget -q https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage -O /tmp/nvim/nvim.appimage
|
||||||
|
cd /tmp/nvim
|
||||||
|
chmod a+x ./nvim.appimage
|
||||||
|
./nvim.appimage --appimage-extract
|
||||||
|
echo "/tmp/nvim/squashfs-root/usr/bin/" >> $GITHUB_PATH
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: |
|
run: |
|
||||||
nvim --version
|
nvim --version
|
||||||
|
38
CHANGELOG.md
38
CHANGELOG.md
@ -1,5 +1,43 @@
|
|||||||
# 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)
|
||||||
|
|
||||||
|
|
||||||
|
### ⚠ 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)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* don't save the session when no files are open (save_empty = false) ([e9afeaf](https://github.com/folke/persistence.nvim/commit/e9afeaf3a7bb645ca73980cd13048c48c292500c))
|
||||||
|
|
||||||
## [1.1.0](https://github.com/folke/persistence.nvim/compare/v1.0.1...v1.1.0) (2023-02-28)
|
## [1.1.0](https://github.com/folke/persistence.nvim/compare/v1.0.1...v1.1.0) (2023-02-28)
|
||||||
|
|
||||||
|
|
||||||
|
32
README.md
32
README.md
@ -15,33 +15,17 @@
|
|||||||
|
|
||||||
Install the plugin with your preferred package manager:
|
Install the plugin with your preferred package manager:
|
||||||
|
|
||||||
### [packer](https://github.com/wbthomason/packer.nvim)
|
### [lazy.nvim](https://github.com/folke/lazy.nvim)
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- Lua
|
-- Lua
|
||||||
use({
|
{
|
||||||
"folke/persistence.nvim",
|
"folke/persistence.nvim",
|
||||||
event = "BufReadPre", -- this will only start session saving when an actual file was opened
|
event = "BufReadPre", -- this will only start session saving when an actual file was opened
|
||||||
module = "persistence",
|
opts = {
|
||||||
config = function()
|
-- add any custom options here
|
||||||
require("persistence").setup()
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
### [vim-plug](https://github.com/junegunn/vim-plug)
|
|
||||||
|
|
||||||
```vim
|
|
||||||
" Vim Script
|
|
||||||
Plug 'folke/persistence.nvim'
|
|
||||||
|
|
||||||
lua << EOF
|
|
||||||
require("persistence").setup {
|
|
||||||
-- your configuration comes here
|
|
||||||
-- or leave it empty to use the default settings
|
|
||||||
-- refer to the configuration section below
|
|
||||||
}
|
}
|
||||||
EOF
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## ⚙️ Configuration
|
## ⚙️ Configuration
|
||||||
@ -50,9 +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
|
||||||
|
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 February 28
|
*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*
|
||||||
@ -18,14 +18,12 @@ Table of Contents *persistence.nvim-table-of-contents*
|
|||||||
|
|
||||||
FEATURES *persistence.nvim-persistence-features*
|
FEATURES *persistence.nvim-persistence-features*
|
||||||
|
|
||||||
|
|
||||||
- automatically saves the active session under `~/.local/state/nvim/sessions` on exit
|
- automatically saves the active session under `~/.local/state/nvim/sessions` on exit
|
||||||
- simple API to restore the current or last session
|
- simple API to restore the current or last session
|
||||||
|
|
||||||
|
|
||||||
REQUIREMENTS *persistence.nvim-persistence-requirements*
|
REQUIREMENTS *persistence.nvim-persistence-requirements*
|
||||||
|
|
||||||
|
|
||||||
- Neovim >= 0.7.2
|
- Neovim >= 0.7.2
|
||||||
|
|
||||||
|
|
||||||
@ -34,34 +32,17 @@ INSTALLATION *persistence.nvim-persistence-installation*
|
|||||||
Install the plugin with your preferred package manager:
|
Install the plugin with your preferred package manager:
|
||||||
|
|
||||||
|
|
||||||
PACKER ~
|
LAZY.NVIM ~
|
||||||
|
|
||||||
>lua
|
>lua
|
||||||
-- Lua
|
-- Lua
|
||||||
use({
|
{
|
||||||
"folke/persistence.nvim",
|
"folke/persistence.nvim",
|
||||||
event = "BufReadPre", -- this will only start session saving when an actual file was opened
|
event = "BufReadPre", -- this will only start session saving when an actual file was opened
|
||||||
module = "persistence",
|
opts = {
|
||||||
config = function()
|
-- add any custom options here
|
||||||
require("persistence").setup()
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
<
|
|
||||||
|
|
||||||
|
|
||||||
VIM-PLUG ~
|
|
||||||
|
|
||||||
>vim
|
|
||||||
" Vim Script
|
|
||||||
Plug 'folke/persistence.nvim'
|
|
||||||
|
|
||||||
lua << EOF
|
|
||||||
require("persistence").setup {
|
|
||||||
-- your configuration comes here
|
|
||||||
-- or leave it empty to use the default settings
|
|
||||||
-- refer to the configuration section below
|
|
||||||
}
|
}
|
||||||
EOF
|
}
|
||||||
<
|
<
|
||||||
|
|
||||||
|
|
||||||
@ -71,9 +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
|
||||||
|
pre_load = nil, -- a function to call before loading the session
|
||||||
|
post_load = nil, -- a function to call after loading the session
|
||||||
}
|
}
|
||||||
<
|
<
|
||||||
|
|
||||||
|
@ -1,99 +0,0 @@
|
|||||||
*persistence.txt* For NVIM v0.8.0 Last change: 2023 January 04
|
|
||||||
|
|
||||||
==============================================================================
|
|
||||||
Table of Contents *persistence-table-of-contents*
|
|
||||||
|
|
||||||
1. 💾 Persistence |persistence-💾-persistence|
|
|
||||||
- ✨ Features |persistence-✨-features|
|
|
||||||
- ⚡️ Requirements |persistence-⚡️-requirements|
|
|
||||||
- 📦 Installation |persistence-📦-installation|
|
|
||||||
- ⚙️ Configuration |persistence-⚙️-configuration|
|
|
||||||
- 🚀 Usage |persistence-🚀-usage|
|
|
||||||
|
|
||||||
==============================================================================
|
|
||||||
1. 💾 Persistence *persistence-💾-persistence*
|
|
||||||
|
|
||||||
**Persistence** is a simple lua plugin for automated session management.
|
|
||||||
|
|
||||||
✨ FEATURES *persistence-✨-features*
|
|
||||||
|
|
||||||
|
|
||||||
- automatically saves the active session under `.config/nvim/sessions` on exit
|
|
||||||
- simple API to restore the current or last session
|
|
||||||
|
|
||||||
|
|
||||||
⚡️ REQUIREMENTS *persistence-⚡️-requirements*
|
|
||||||
|
|
||||||
|
|
||||||
- Neovim >= 0.5.0
|
|
||||||
|
|
||||||
|
|
||||||
📦 INSTALLATION *persistence-📦-installation*
|
|
||||||
|
|
||||||
Install the plugin with your preferred package manager:
|
|
||||||
|
|
||||||
PACKER <HTTPS://GITHUB.COM/WBTHOMASON/PACKER.NVIM> ~
|
|
||||||
|
|
||||||
>
|
|
||||||
-- Lua
|
|
||||||
use({
|
|
||||||
"folke/persistence.nvim",
|
|
||||||
event = "BufReadPre", -- this will only start session saving when an actual file was opened
|
|
||||||
module = "persistence",
|
|
||||||
config = function()
|
|
||||||
require("persistence").setup()
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
<
|
|
||||||
|
|
||||||
|
|
||||||
VIM-PLUG <HTTPS://GITHUB.COM/JUNEGUNN/VIM-PLUG> ~
|
|
||||||
|
|
||||||
>
|
|
||||||
" Vim Script
|
|
||||||
Plug 'folke/persistence.nvim'
|
|
||||||
|
|
||||||
lua << EOF
|
|
||||||
require("persistence").setup {
|
|
||||||
-- your configuration comes here
|
|
||||||
-- or leave it empty to use the default settings
|
|
||||||
-- refer to the configuration section below
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
<
|
|
||||||
|
|
||||||
|
|
||||||
⚙️ CONFIGURATION *persistence-⚙️-configuration*
|
|
||||||
|
|
||||||
Persistence comes with the following defaults:
|
|
||||||
|
|
||||||
>
|
|
||||||
{
|
|
||||||
dir = vim.fn.expand(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
|
|
||||||
}
|
|
||||||
<
|
|
||||||
|
|
||||||
|
|
||||||
🚀 USAGE *persistence-🚀-usage*
|
|
||||||
|
|
||||||
**Persistence** 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.
|
|
||||||
|
|
||||||
>
|
|
||||||
-- restore the session for the current directory
|
|
||||||
vim.api.nvim_set_keymap("n", "<leader>qs", [[<cmd>lua require("persistence").load()<cr>]], {})
|
|
||||||
|
|
||||||
-- restore the last session
|
|
||||||
vim.api.nvim_set_keymap("n", "<leader>ql", [[<cmd>lua require("persistence").load({ last = true })<cr>]], {})
|
|
||||||
|
|
||||||
-- stop Persistence => session won't be saved on exit
|
|
||||||
vim.api.nvim_set_keymap("n", "<leader>qd", [[<cmd>lua require("persistence").stop()<cr>]], {})
|
|
||||||
<
|
|
||||||
|
|
||||||
|
|
||||||
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
|
|
||||||
|
|
||||||
vim:tw=78:ts=8:noet:ft=help:norl:
|
|
@ -2,9 +2,13 @@ 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" }, -- 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
|
||||||
}
|
}
|
||||||
|
|
||||||
---@type PersistenceOptions
|
---@type PersistenceOptions
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
local Config = require("persistence.config")
|
local Config = require("persistence.config")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
---@type string?
|
||||||
|
M.current = nil
|
||||||
|
|
||||||
local e = vim.fn.fnameescape
|
local e = vim.fn.fnameescape
|
||||||
|
|
||||||
@ -27,6 +29,7 @@ function M.setup(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.start()
|
function M.start()
|
||||||
|
M.current = M.get_current()
|
||||||
vim.api.nvim_create_autocmd("VimLeavePre", {
|
vim.api.nvim_create_autocmd("VimLeavePre", {
|
||||||
group = vim.api.nvim_create_augroup("persistence", { clear = true }),
|
group = vim.api.nvim_create_augroup("persistence", { clear = true }),
|
||||||
callback = function()
|
callback = function()
|
||||||
@ -34,19 +37,42 @@ function M.start()
|
|||||||
Config.options.pre_save()
|
Config.options.pre_save()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not Config.options.save_empty then
|
||||||
|
local bufs = vim.tbl_filter(function(b)
|
||||||
|
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
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
M.save()
|
M.save()
|
||||||
|
|
||||||
|
if type(Config.options.post_save) == "function" then
|
||||||
|
Config.options.post_save()
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.stop()
|
function M.stop()
|
||||||
|
M.current = nil
|
||||||
pcall(vim.api.nvim_del_augroup_by_name, "persistence")
|
pcall(vim.api.nvim_del_augroup_by_name, "persistence")
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.save()
|
function M.save()
|
||||||
local tmp = vim.o.sessionoptions
|
local tmp = vim.o.sessionoptions
|
||||||
vim.o.sessionoptions = table.concat(Config.options.options, ",")
|
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
|
vim.o.sessionoptions = tmp
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -54,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
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user