Skip to content

Commit b0de69d

Browse files
committed
docs: update README.md
1 parent e2ae8b3 commit b0de69d

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

README.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ The plugin also comes with pre-defined highlight groups for the Telescope implem
367367

368368
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.
369369

370-
Consider a user who wishes to autoload a session if arguments are passed to Neovim. A custom autocmd can be created which forces the autoload:
370+
Consider a user who wishes to autoload a session if arguments are passed to Neovim. A custom autocmd can be created which forces the autoload (thanks to [neandrake](https://github.com/neandrake) for this solution):
371371

372372
```lua
373373
local persisted = require("persisted")
@@ -379,11 +379,25 @@ persisted.setup({
379379
vim.api.nvim_create_autocmd("VimEnter", {
380380
nested = true,
381381
callback = function()
382-
-- Add more complex logic here
383-
if vim.fn.argc() > 0 then
384-
-- Leverage the plugin's ability to resolve allowed_dirs and ignored_dirs
385-
require("persisted").autoload({ force = true })
382+
if vim.g.started_with_stdin then
383+
return
386384
end
385+
386+
local forceload = false
387+
if vim.fn.argc() == 0 then
388+
forceload = true
389+
elseif vim.fn.argc() == 1 then
390+
local dir = vim.fn.expand(vim.fn.argv(0))
391+
if dir == '.' then
392+
dir = vim.fn.getcwd()
393+
end
394+
395+
if vim.fn.isdirectory(dir) ~= 0 then
396+
forceload = true
397+
end
398+
end
399+
400+
persisted.autoload({ force = forceload })
387401
end,
388402
})
389403
```

doc/persisted.nvim.txt

+20-5
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ and utils.lua
388388
file are public.
389389

390390
Consider a user who wishes to autoload a session if arguments are passed to
391-
Neovim. A custom autocmd can be created which forces the autoload:
391+
Neovim. A custom autocmd can be created which forces the autoload (thanks to
392+
neandrake <https://github.com/neandrake> for this solution):
392393

393394
>lua
394395
local persisted = require("persisted")
@@ -400,11 +401,25 @@ Neovim. A custom autocmd can be created which forces the autoload:
400401
vim.api.nvim_create_autocmd("VimEnter", {
401402
nested = true,
402403
callback = function()
403-
-- Add more complex logic here
404-
if vim.fn.argc() > 0 then
405-
-- Leverage the plugin's ability to resolve allowed_dirs and ignored_dirs
406-
require("persisted").autoload({ force = true })
404+
if vim.g.started_with_stdin then
405+
return
407406
end
407+
408+
local forceload = false
409+
if vim.fn.argc() == 0 then
410+
forceload = true
411+
elseif vim.fn.argc() == 1 then
412+
local dir = vim.fn.expand(vim.fn.argv(0))
413+
if dir == '.' then
414+
dir = vim.fn.getcwd()
415+
end
416+
417+
if vim.fn.isdirectory(dir) ~= 0 then
418+
forceload = true
419+
end
420+
end
421+
422+
persisted.autoload({ force = forceload })
408423
end,
409424
})
410425
<

0 commit comments

Comments
 (0)