Compare commits

...

22 Commits
v3.0.0 ... main

Author SHA1 Message Date
Folke Lemaitre
166a79a55b
refactor: cleanup 2025-02-25 19:20:14 +01:00
folke
3ae5cb9bc0 chore(build): auto-generate docs 2025-02-25 18:17:41 +00:00
Jakub Okoński
ae0d7e8e45
fix(start): don't count ft=jj buffers for persistence (#90)
## Description

Don't count `ft=jj` buffers towards those that need persisting

## Related Issue(s)

https://github.com/LazyVim/LazyVim/discussions/5545
2025-02-25 19:16:59 +01:00
folke
f6aad7dde7 chore(build): auto-generate docs 2024-07-22 12:25:55 +00:00
Folke Lemaitre
fce1ea237e
ci: update 2024-07-22 14:24:46 +02:00
github-actions[bot]
40a137dd92
chore(update): update repository (#72)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action

Co-authored-by: folke <292349+folke@users.noreply.github.com>
2024-07-15 17:09:09 +02:00
folke
43f180d2f5 chore(build): auto-generate docs 2024-07-15 09:20:05 +00:00
github-actions[bot]
da993034f4
chore(update): update repository (#71)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action

Co-authored-by: folke <292349+folke@users.noreply.github.com>
2024-07-15 11:19:27 +02:00
github-actions[bot]
1e7d01fc7f
chore(update): update repository (#69)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action

Co-authored-by: folke <292349+folke@users.noreply.github.com>
2024-07-13 18:09:22 +02:00
github-actions[bot]
dbedb2fc07
chore(update): update repository (#68)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action

Co-authored-by: folke <292349+folke@users.noreply.github.com>
2024-07-13 16:15:44 +02:00
folke
96ca1ce371 chore(build): auto-generate docs 2024-07-13 08:09:16 +00:00
github-actions[bot]
f89430a7dc
chore(update): update repository (#67)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action

Co-authored-by: folke <292349+folke@users.noreply.github.com>
2024-07-13 10:08:36 +02:00
github-actions[bot]
c45ff862b5
chore(main): release 3.1.0 (#66)
🤖 I have created a release *beep* *boop*
---


##
[3.1.0](https://github.com/folke/persistence.nvim/compare/v3.0.1...v3.1.0)
(2024-07-07)


### Features

* **load:** fallback to regular session when branch session does not
exist (yet)
([a93748a](a93748acdb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-07-07 21:24:56 +02:00
Folke Lemaitre
a93748acdb
feat(load): fallback to regular session when branch session does not exist (yet) 2024-07-07 19:01:19 +02:00
github-actions[bot]
fc8273bac0
chore(main): release 3.0.1 (#63)
🤖 I have created a release *beep* *boop*
---


##
[3.0.1](https://github.com/folke/persistence.nvim/compare/v3.0.0...v3.0.1)
(2024-07-07)


### Bug Fixes

* branch detection. Closes
[#62](https://github.com/folke/persistence.nvim/issues/62)
([a1d37fa](a1d37fa32e))
* **branch:** escape branch name. Fixes
[#65](https://github.com/folke/persistence.nvim/issues/65)
([1565ca0](1565ca0af2))
* windows
([2d83b1a](2d83b1a5c3))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-07-07 09:24:55 +02:00
Folke Lemaitre
2d83b1a5c3
fix: windows 2024-07-07 05:36:38 +02:00
folke
f18d0131ed chore(build): auto-generate docs 2024-07-07 05:03:13 +00:00
Folke Lemaitre
1565ca0af2
fix(branch): escape branch name. Fixes #65 2024-07-07 07:02:32 +02:00
Folke Lemaitre
2c7d3eb6b8
ci: update 2024-07-06 23:45:36 +02:00
Folke Lemaitre
a1d37fa32e
fix: branch detection. Closes #62 2024-07-06 23:21:20 +02:00
Folke Lemaitre
34f337e383
ci: update 2024-07-06 23:19:54 +02:00
Folke Lemaitre
8b83876213
ci: update 2024-07-06 23:18:35 +02:00
9 changed files with 89 additions and 57 deletions

7
.editorconfig Normal file
View File

@ -0,0 +1,7 @@
root = true
[*]
insert_final_newline = true
indent_style = space
indent_size = 2
charset = utf-8

View File

@ -6,7 +6,10 @@ body:
- type: markdown - type: markdown
attributes: attributes:
value: | value: |
**Before** reporting an issue, make sure to read the [documentation](https://github.com/folke/persistence.nvim) and search [existing issues](https://github.com/folke/persistence.nvim/issues). Usage questions such as ***"How do I...?"*** belong in [Discussions](https://github.com/folke/persistence.nvim/discussions) and will be closed. **Before** reporting an issue, make sure to read the [documentation](https://github.com/folke/persistence.nvim)
and search [existing issues](https://github.com/folke/persistence.nvim/issues).
Usage questions such as ***"How do I...?"*** belong in [Discussions](https://github.com/folke/persistence.nvim/discussions) and will be closed.
- type: checkboxes - type: checkboxes
attributes: attributes:
label: Did you check docs and existing issues? label: Did you check docs and existing issues?
@ -14,6 +17,8 @@ body:
options: options:
- label: I have read all the persistence.nvim docs - label: I have read all the persistence.nvim docs
required: true required: true
- label: I have updated the plugin to the latest version before submitting this issue
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 existing issues of plugins related to this issue - label: I have searched the existing issues of plugins related to this issue
@ -57,33 +62,15 @@ body:
label: Repro label: Repro
description: Minimal `init.lua` to reproduce this issue. Save as `repro.lua` and run with `nvim -u repro.lua` description: Minimal `init.lua` to reproduce this issue. Save as `repro.lua` and run with `nvim -u repro.lua`
value: | value: |
-- DO NOT change the paths and don't remove the colorscheme vim.env.LAZY_STDPATH = ".repro"
local root = vim.fn.fnamemodify("./.repro", ":p") load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
-- set stdpaths to use .repro require("lazy.minit").repro({
for _, name in ipairs({ "config", "data", "state", "cache" }) do spec = {
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name { "folke/persistence.nvim", opts = {} },
end -- add any other plugins here
},
-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)
-- install plugins
local plugins = {
"folke/tokyonight.nvim",
{ "folke/persistence.nvim", opts = {} },
-- add any other plugins here
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
}) })
render: lua
vim.cmd.colorscheme("tokyonight")
-- add anything else here
render: Lua
validations: validations:
required: false required: false

View File

@ -12,4 +12,3 @@ jobs:
with: with:
plugin: persistence.nvim plugin: persistence.nvim
repo: folke/persistence.nvim repo: folke/persistence.nvim
tests: false

View File

@ -5,6 +5,7 @@ on:
- cron: "30 1 * * *" - cron: "30 1 * * *"
jobs: jobs:
ci: stale:
if: contains(fromJSON('["folke", "LazyVim"]'), github.repository_owner)
uses: folke/github/.github/workflows/stale.yml@main uses: folke/github/.github/workflows/stale.yml@main
secrets: inherit secrets: inherit

View File

@ -7,6 +7,7 @@ on:
- cron: "0 * * * *" - cron: "0 * * * *"
jobs: jobs:
ci: update:
if: contains(fromJSON('["folke", "LazyVim"]'), github.repository_owner)
uses: folke/github/.github/workflows/update.yml@main uses: folke/github/.github/workflows/update.yml@main
secrets: inherit secrets: inherit

11
.gitignore vendored
View File

@ -1,8 +1,9 @@
*.log *.log
.repro /.repro
.tests /.tests
build /build
debug /debug
doc/tags /doc/tags
foo.* foo.*
node_modules
tt.* tt.*

View File

@ -1,5 +1,21 @@
# Changelog # Changelog
## [3.1.0](https://github.com/folke/persistence.nvim/compare/v3.0.1...v3.1.0) (2024-07-07)
### Features
* **load:** fallback to regular session when branch session does not exist (yet) ([a93748a](https://github.com/folke/persistence.nvim/commit/a93748acdb2e7bc4389b3738b4c787b764c3b2a6))
## [3.0.1](https://github.com/folke/persistence.nvim/compare/v3.0.0...v3.0.1) (2024-07-07)
### Bug Fixes
* branch detection. Closes [#62](https://github.com/folke/persistence.nvim/issues/62) ([a1d37fa](https://github.com/folke/persistence.nvim/commit/a1d37fa32ef9431f6a57c217ba5c456d20834679))
* **branch:** escape branch name. Fixes [#65](https://github.com/folke/persistence.nvim/issues/65) ([1565ca0](https://github.com/folke/persistence.nvim/commit/1565ca0af2d93ee94335c2950d92bc133c90aa82))
* windows ([2d83b1a](https://github.com/folke/persistence.nvim/commit/2d83b1a5c3fe5b2251866f5263fb9607db8d64c0))
## [3.0.0](https://github.com/folke/persistence.nvim/compare/v2.0.0...v3.0.0) (2024-07-06) ## [3.0.0](https://github.com/folke/persistence.nvim/compare/v2.0.0...v3.0.0) (2024-07-06)

View File

@ -1,4 +1,4 @@
*persistence.nvim.txt* For Neovim Last change: 2024 July 06 *persistence.nvim.txt* For Neovim Last change: 2025 February 25
============================================================================== ==============================================================================
Table of Contents *persistence.nvim-table-of-contents* Table of Contents *persistence.nvim-table-of-contents*

View File

@ -3,17 +3,18 @@ local Config = require("persistence.config")
local uv = vim.uv or vim.loop local uv = vim.uv or vim.loop
local M = {} local M = {}
---@type string? M._active = false
M._current = nil
local e = vim.fn.fnameescape local e = vim.fn.fnameescape
function M.current() ---@param opts? {branch?: boolean}
local name = vim.fn.getcwd():gsub("[\\/:]", "%%") function M.current(opts)
if Config.options.branch then opts = opts or {}
local name = vim.fn.getcwd():gsub("[\\/:]+", "%%")
if Config.options.branch and opts.branch ~= false then
local branch = M.branch() local branch = M.branch()
if branch and branch ~= "main" and branch ~= "master" then if branch and branch ~= "main" and branch ~= "master" then
name = name .. "-" .. branch name = name .. "%%" .. branch:gsub("[\\/:]+", "%%")
end end
end end
return Config.options.dir .. name .. ".vim" return Config.options.dir .. name .. ".vim"
@ -32,11 +33,11 @@ end
-- Check if a session is active -- Check if a session is active
function M.active() function M.active()
return M._current ~= nil return M._active
end end
function M.start() function M.start()
M._current = M.current() M._active = true
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()
@ -44,7 +45,7 @@ function M.start()
if Config.options.need > 0 then if Config.options.need > 0 then
local bufs = vim.tbl_filter(function(b) local bufs = vim.tbl_filter(function(b)
if vim.bo[b].buftype ~= "" or vim.bo[b].filetype == "gitcommit" or vim.bo[b].filetype == "gitrebase" then if vim.bo[b].buftype ~= "" or vim.tbl_contains({ "gitcommit", "gitrebase", "jj" }, vim.bo[b].filetype) then
return false return false
end end
return vim.api.nvim_buf_get_name(b) ~= "" return vim.api.nvim_buf_get_name(b) ~= ""
@ -61,25 +62,31 @@ function M.start()
end end
function M.stop() function M.stop()
M._current = nil M._active = false
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()
vim.cmd("mks! " .. e(M._current or M.current())) vim.cmd("mks! " .. e(M.current()))
end end
---@param opts? { last?: boolean, file?: string } ---@param opts? { last?: boolean }
function M.load(opts) function M.load(opts)
opts = opts or {} opts = opts or {}
local file = opts.file or opts.last and M.last() or M.current() ---@type string
local file
if opts.last then
file = M.last()
else
file = M.current()
if vim.fn.filereadable(file) == 0 then
file = M.current({ branch = false })
end
end
if file and vim.fn.filereadable(file) ~= 0 then if file and vim.fn.filereadable(file) ~= 0 then
M.fire("LoadPre") M.fire("LoadPre")
vim.cmd("silent! source " .. e(file)) vim.cmd("silent! source " .. e(file))
M.fire("LoadPost") M.fire("LoadPost")
if M._current then
M.start()
end
end end
end end
@ -97,12 +104,21 @@ function M.last()
end end
function M.select() function M.select()
---@type { session: string, dir: string }[] ---@type { session: string, dir: string, branch?: string }[]
local items = {} local items = {}
local have = {} ---@type table<string, boolean>
for _, session in ipairs(M.list()) do for _, session in ipairs(M.list()) do
if uv.fs_stat(session) then if uv.fs_stat(session) then
local dir = session:sub(#Config.options.dir + 1, -5):gsub("%%", "/") local file = session:sub(#Config.options.dir + 1, -5)
items[#items + 1] = { session = session, dir = dir } local dir, branch = unpack(vim.split(file, "%%", { plain = true }))
dir = dir:gsub("%%", "/")
if jit.os:find("Windows") then
dir = dir:gsub("^(%w)/", "%1:/")
end
if not have[dir] then
have[dir] = true
items[#items + 1] = { session = session, dir = dir, branch = branch }
end
end end
end end
vim.ui.select(items, { vim.ui.select(items, {
@ -112,7 +128,8 @@ function M.select()
end, end,
}, function(item) }, function(item)
if item then if item then
M.load({ file = item.session }) vim.fn.chdir(item.dir)
M.load()
end end
end) end)
end end
@ -120,7 +137,10 @@ end
--- get current branch name --- get current branch name
---@return string? ---@return string?
function M.branch() function M.branch()
return vim.fn.systemlist("git branch --show-current")[1] if uv.fs_stat(".git") then
local ret = vim.fn.systemlist("git branch --show-current")[1]
return vim.v.shell_error == 0 and ret or nil
end
end end
return M return M