22 Commits

Author SHA1 Message Date
9730a073fd chore(main): release 1.2.1 (#34)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-10-13 08:56:34 +02:00
8f7cbccfb5 fix: dont save the session when only gitcommit buffers are present. Fixes #14 2023-10-13 08:47:08 +02:00
21f55da0d3 chore(main): release 1.2.0 (#33)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-10-13 07:58:56 +02:00
878c3b32d9 chore(build): auto-generate vimdoc 2023-10-13 05:57:50 +00:00
e9afeaf3a7 feat: don't save the session when no files are open (save_empty = false) 2023-10-13 07:57:09 +02:00
4b8051c01f chore(build): auto-generate vimdoc 2023-05-22 14:39:07 +00:00
7b86ec2430 docs: lazy install 2023-05-22 16:38:25 +02:00
c814fae5c3 chore: update templates 2023-03-19 21:15:43 +01:00
4d2857b647 chore(build): auto-generate vimdoc 2023-03-19 19:37:23 +00:00
74475d1f7d chore: update templates 2023-03-19 20:36:39 +01:00
adcf691369 chore(main): release 1.1.0 (#23)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-02-28 12:43:14 +01:00
5e47847262 chore(build): auto-generate vimdoc 2023-02-28 09:06:44 +00:00
f4bb0c5641 feat(persistence): pre_save option to call before saving (#22)
* feat(persistence): `pre_save` option to call before saving

This commit adds the `pre_save` option, which is a `fun()|nil` that will
be called (if present) before saving the current session. Use cases
include filtering buffers, executing `User` autocmds, etc.

* docs: `pre_save` option
2023-02-28 10:05:58 +01:00
d8a3eda0e1 chore(build): auto-generate vimdoc 2023-01-23 19:53:21 +00:00
b0e2b283c6 ci: checkout v3 2023-01-23 20:52:38 +01:00
cc68aed5a1 chore(build): auto-generate vimdoc 2023-01-17 09:54:20 +00:00
5b7e71abe9 docs: update path to session in state directory. Fixes #20 2023-01-17 10:53:36 +01:00
8484fdaa28 chore(main): release 1.0.1 (#18)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-01-06 19:33:37 +01:00
8c40aa7b80 chore(build): auto-generate vimdoc 2023-01-06 18:29:26 +00:00
70c281e54e fix: dont throw error when session was already stopped 2023-01-06 19:28:37 +01:00
7421e30704 chore(build): auto-generate vimdoc 2023-01-05 07:38:46 +00:00
5453a25028 docs: updated session directory (#16)
* Update README.md

* Update docs
2023-01-05 08:38:06 +01:00
9 changed files with 101 additions and 176 deletions

View File

@ -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

View File

@ -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
@ -55,7 +59,7 @@ jobs:
with: with:
release-type: simple release-type: simple
package-name: persistence.nvim package-name: persistence.nvim
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: tag stable versions - name: tag stable versions
if: ${{ steps.release.outputs.release_created }} if: ${{ steps.release.outputs.release_created }}
run: | run: |

2
.gitignore vendored
View File

@ -4,3 +4,5 @@ doc/tags
debug debug
.repro .repro
foo.* foo.*
*.log
data

View File

@ -1,5 +1,33 @@
# Changelog # Changelog
## [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)
### Features
* **persistence:** `pre_save` option to call before saving ([#22](https://github.com/folke/persistence.nvim/issues/22)) ([f4bb0c5](https://github.com/folke/persistence.nvim/commit/f4bb0c5641a0e6c9ac3675ddd794ca78099d8510))
## [1.0.1](https://github.com/folke/persistence.nvim/compare/v1.0.0...v1.0.1) (2023-01-06)
### Bug Fixes
* dont throw error when session was already stopped ([70c281e](https://github.com/folke/persistence.nvim/commit/70c281e54e34630d8bef9b1cf9f7a0ac3edd6a1c))
## 1.0.0 (2023-01-04) ## 1.0.0 (2023-01-04)

View File

@ -4,44 +4,28 @@
## ✨ Features ## ✨ Features
- automatically saves the active session under `.config/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 ## ⚡️ Requirements
- Neovim >= 0.5.0 - Neovim >= 0.7.2
## 📦 Installation ## 📦 Installation
Install the plugin with your preferred package manager: Install the plugin with your preferred package manager:
### [packer](https://github.com/wbthomason/packer.nvim) ### [folke](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,8 +34,10 @@ Persistence comes with the following defaults:
```lua ```lua
{ {
dir = vim.fn.expand(vim.fn.stdpath("config") .. "/sessions/"), -- directory where session files are saved dir = vim.fn.expand(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
save_empty = false, -- don't save if there are no open file buffers
} }
``` ```

View File

@ -1,81 +1,66 @@
*persistence.nvim.txt* For Neovim >= 0.8.0 Last change: 2023 January 04 *persistence.nvim.txt* For Neovim >= 0.8.0 Last change: 2023 October 13
============================================================================== ==============================================================================
Table of Contents *persistence.nvim-table-of-contents* Table of Contents *persistence.nvim-table-of-contents*
1. Persistence |persistence.nvim-persistence| 1. Persistence |persistence.nvim-persistence|
- Features |persistence.nvim-features| - Features |persistence.nvim-persistence-features|
- Requirements |persistence.nvim-requirements| - Requirements |persistence.nvim-persistence-requirements|
- Installation |persistence.nvim-installation| - Installation |persistence.nvim-persistence-installation|
- Configuration |persistence.nvim-configuration| - Configuration |persistence.nvim-persistence-configuration|
- Usage |persistence.nvim-usage| - Usage |persistence.nvim-persistence-usage|
============================================================================== ==============================================================================
1. Persistence *persistence.nvim-persistence* 1. Persistence *persistence.nvim-persistence*
**Persistence** is a simple lua plugin for automated session management. **Persistence** is a simple lua plugin for automated session management.
FEATURES *persistence.nvim-features*
FEATURES *persistence.nvim-persistence-features*
- automatically saves the active session under `.config/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-requirements* REQUIREMENTS *persistence.nvim-persistence-requirements*
- Neovim >= 0.7.2
- Neovim >= 0.5.0 INSTALLATION *persistence.nvim-persistence-installation*
INSTALLATION *persistence.nvim-installation*
Install the plugin with your preferred package manager: Install the plugin with your preferred package manager:
PACKER <HTTPS://GITHUB.COM/WBTHOMASON/PACKER.NVIM> ~
FOLKE ~
>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 *persistence.nvim-configuration* CONFIGURATION *persistence.nvim-persistence-configuration*
Persistence comes with the following defaults: Persistence comes with the following defaults:
>lua >lua
{ {
dir = vim.fn.expand(vim.fn.stdpath("config") .. "/sessions/"), -- directory where session files are saved dir = vim.fn.expand(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
save_empty = false, -- don't save if there are no open file buffers
} }
< <
USAGE *persistence.nvim-usage* USAGE *persistence.nvim-persistence-usage*
**Persistence** works well with plugins like `startify` or `dashboard`. It will **Persistence** works well with plugins like `startify` or `dashboard`. It will
never restore a session automatically, but you can of course write an autocmd never restore a session automatically, but you can of course write an autocmd
@ -92,7 +77,6 @@ that does exactly that if you want.
vim.api.nvim_set_keymap("n", "<leader>qd", [[<cmd>lua require("persistence").stop()<cr>]], {}) vim.api.nvim_set_keymap("n", "<leader>qd", [[<cmd>lua require("persistence").stop()<cr>]], {})
< <
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc> Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
vim:tw=78:ts=8:noet:ft=help:norl: vim:tw=78:ts=8:noet:ft=help:norl:

View File

@ -1,98 +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("config") .. "/sessions/"), -- directory where session files are saved
options = { "buffers", "curdir", "tabpages", "winsize" }, -- sessionoptions used for saving
}
<
🚀 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:

View File

@ -1,9 +1,11 @@
local M = {} local M = {}
---@class PersistenceOptions ---@class PersistenceOptions
---@field pre_save? fun()
local defaults = { local defaults = {
dir = vim.fn.expand(vim.fn.stdpath("state") .. "/sessions/"), -- directory where session files are saved dir = vim.fn.expand(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

View File

@ -27,19 +27,35 @@ function M.setup(opts)
end end
function M.start() function M.start()
vim.cmd([[ vim.api.nvim_create_autocmd("VimLeavePre", {
augroup Persistence group = vim.api.nvim_create_augroup("persistence", { clear = true }),
autocmd! callback = function()
autocmd VimLeavePre * lua require("persistence").save() if Config.options.pre_save then
augroup end Config.options.pre_save()
]]) 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
return vim.api.nvim_buf_get_name(b) ~= ""
end, vim.api.nvim_list_bufs())
if #bufs == 0 then
return
end
end
M.save()
end,
})
end end
function M.stop() function M.stop()
vim.cmd([[ pcall(vim.api.nvim_del_augroup_by_name, "persistence")
autocmd! Persistence
augroup! Persistence
]])
end end
function M.save() function M.save()