Skip to content

Commit da8d3f8

Browse files
committed
docs: update for examples
1 parent 3da2a5e commit da8d3f8

File tree

2 files changed

+69
-13
lines changed

2 files changed

+69
-13
lines changed

README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ The plugin also comes with pre-defined highlight groups for the Telescope implem
384384

385385
The plugin has been designed to be fully extensible. All of the functions in the [init.lua](https://github.com/olimorris/persisted.nvim/blob/main/lua/persisted/init.lua) and [utils.lua](https://github.com/olimorris/persisted.nvim/blob/main/lua/persisted/utils.lua) file are public.
386386

387-
**Custom Autoloading** by [neandrake](https://github.com/neandrake)
387+
**Custom autoloading** by [neandrake](https://github.com/neandrake)
388388

389389
Autoloading a session if arguments are passed to Neovim:
390390

@@ -425,7 +425,7 @@ vim.api.nvim_create_autocmd("VimEnter", {
425425
})
426426
```
427427

428-
**Git Branching and Sub-directories** by [mrloop](https://github.com/mrloop)
428+
**Git branching and sub-directories** by [mrloop](https://github.com/mrloop)
429429

430430
As per [#149](https://github.com/olimorris/persisted.nvim/discussions/149), if you invoke Neovim from a sub-directory then the git branch will not be detected. The code below amends for this:
431431

@@ -449,7 +449,7 @@ As per [#149](https://github.com/olimorris/persisted.nvim/discussions/149), if y
449449
}
450450
```
451451

452-
**Ignore Certain Branches**
452+
**Ignore certain branches**
453453

454454
If you'd like to ignore certain branches from being saved as a session:
455455

@@ -479,7 +479,34 @@ If you'd like to ignore certain branches from being saved as a session:
479479
}
480480
```
481481

482-
**Only Save Certain Sessions**
482+
**Only save session if a minimum number of buffers are present**
483+
484+
```lua
485+
{
486+
"olimorris/persisted.nvim",
487+
lazy = false,
488+
config = function()
489+
local persisted = require("persisted")
490+
persisted.setup({
491+
should_save = function()
492+
-- Ref: https://github.com/folke/persistence.nvim/blob/166a79a55bfa7a4db3e26fc031b4d92af71d0b51/lua/persistence/init.lua#L46
493+
local bufs = vim.tbl_filter(function(b)
494+
if vim.bo[b].buftype ~= "" or vim.tbl_contains({ "gitcommit", "gitrebase", "jj" }, vim.bo[b].filetype) then
495+
return false
496+
end
497+
return vim.api.nvim_buf_get_name(b) ~= ""
498+
end, vim.api.nvim_list_bufs())
499+
if #bufs < 1 then
500+
return false
501+
end
502+
return true
503+
end,
504+
})
505+
end,
506+
}
507+
```
508+
509+
**Only save a session in a certain dir**
483510

484511
You may wish to only save a session if the current working directory is in a table of allowed directories:
485512

doc/persisted.nvim.txt

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -338,17 +338,19 @@ their default setting (ignoring all listed directory and its children), however
338338

339339
The plugin fires events at various points during its lifecycle:
340340

341+
- `PersistedDeletePre` - For _before_ a session is deleted
342+
- `PersistedDeletePost` - For _after_ a session is deleted
341343
- `PersistedLoadPre` - For _before_ a session is loaded
342344
- `PersistedLoadPost` - For _after_ a session is loaded
343-
- `PersistedTelescopeLoadPre` - For _before_ a session is loaded via Telescope
344-
- `PersistedTelescopeLoadPost` - For _after_ a session is loaded via Telescope
345345
- `PersistedSavePre` - For _before_ a session is saved
346346
- `PersistedSavePost` - For _after_ a session is saved
347-
- `PersistedDeletePre` - For _before_ a session is deleted
348-
- `PersistedDeletePost` - For _after_ a session is deleted
347+
- `PersistedSelectPre` - For _before_ a session is selected (via `:SessionSelect`)
348+
- `PersistedSelectPost` - For _after_ a session is selected
349349
- `PersistedStart` - For when a session has _started_
350350
- `PersistedStop` - For when a session has _stopped_
351351
- `PersistedToggle` - For when a session is toggled
352+
- `PersistedTelescopeLoadPre` - For _before_ a session is loaded via Telescope
353+
- `PersistedTelescopeLoadPost` - For _after_ a session is loaded via Telescope
352354

353355
These events can be consumed anywhere within your configuration by utilising
354356
the `vim.api.nvim_create_autocmd` function.
@@ -360,7 +362,7 @@ session, saving the current session before clearing all of the open buffers:
360362
vim.api.nvim_create_autocmd("User", {
361363
pattern = "PersistedTelescopeLoadPre",
362364
callback = function(session)
363-
-- Save the currently loaded session using the global variable
365+
-- Save the currently loaded session passing in the path to the current session
364366
require("persisted").save({ session = vim.g.persisted_loaded_session })
365367

366368
-- Delete all of the open buffers
@@ -404,7 +406,7 @@ and utils.lua
404406
<https://github.com/olimorris/persisted.nvim/blob/main/lua/persisted/utils.lua>
405407
file are public.
406408

407-
**Custom Autoloading** by neandrake <https://github.com/neandrake>
409+
**Custom autoloading** by neandrake <https://github.com/neandrake>
408410

409411
Autoloading a session if arguments are passed to Neovim:
410412

@@ -445,7 +447,7 @@ Autoloading a session if arguments are passed to Neovim:
445447
})
446448
<
447449

448-
**Git Branching and Sub-directories** by mrloop <https://github.com/mrloop>
450+
**Git branching and sub-directories** by mrloop <https://github.com/mrloop>
449451

450452
As per #149 <https://github.com/olimorris/persisted.nvim/discussions/149>, if
451453
you invoke Neovim from a sub-directory then the git branch will not be
@@ -471,7 +473,7 @@ detected. The code below amends for this:
471473
}
472474
<
473475

474-
**Ignore Certain Branches**
476+
**Ignore certain branches**
475477

476478
If you’d like to ignore certain branches from being saved as a session:
477479

@@ -501,7 +503,34 @@ If you’d like to ignore certain branches from being saved as a session:
501503
}
502504
<
503505

504-
**Only Save Certain Sessions**
506+
**Only save session if a minimum number of buffers are present**
507+
508+
>lua
509+
{
510+
"olimorris/persisted.nvim",
511+
lazy = false,
512+
config = function()
513+
local persisted = require("persisted")
514+
persisted.setup({
515+
should_save = function()
516+
-- Ref: https://github.com/folke/persistence.nvim/blob/166a79a55bfa7a4db3e26fc031b4d92af71d0b51/lua/persistence/init.lua#L46
517+
local bufs = vim.tbl_filter(function(b)
518+
if vim.bo[b].buftype ~= "" or vim.tbl_contains({ "gitcommit", "gitrebase", "jj" }, vim.bo[b].filetype) then
519+
return false
520+
end
521+
return vim.api.nvim_buf_get_name(b) ~= ""
522+
end, vim.api.nvim_list_bufs())
523+
if #bufs < 1 then
524+
return false
525+
end
526+
return true
527+
end,
528+
})
529+
end,
530+
}
531+
<
532+
533+
**Only save a session in a certain dir**
505534

506535
You may wish to only save a session if the current working directory is in a
507536
table of allowed directories:

0 commit comments

Comments
 (0)