Skip to content

Commit edd8aa4

Browse files
authored
chore: use vim.notify (#108)
* Updated warnings and info to print with vim.notify * Updated formatting
1 parent 284d714 commit edd8aa4

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

doc/persisted.nvim.txt

+4-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Table of Contents *persisted.nvim-table-of-contents*
1212

1313
FEATURES *persisted.nvim-features*
1414

15-
1615
- Supports sessions across multiple git branches
1716
- Telescope extension to work with saved sessions
1817
- Custom events which users can hook into for tighter integration
@@ -23,7 +22,6 @@ FEATURES *persisted.nvim-features*
2322

2423
REQUIREMENTS *persisted.nvim-requirements*
2524

26-
2725
- Neovim >= 0.8.0
2826

2927

@@ -60,7 +58,7 @@ Install the plugin with your preferred package manager:
6058
>vim
6159
" Vim Script
6260
Plug 'olimorris/persisted.nvim'
63-
61+
6462
lua << EOF
6563
require("persisted").setup {
6664
-- your configuration comes here
@@ -107,7 +105,6 @@ COMMANDS ~
107105

108106
The plugin comes with a number of commands:
109107

110-
111108
- `:SessionToggle` - Determines whether to load, start or stop a session
112109
- `:SessionStart` - Start recording a session. Useful if `autosave = false`
113110
- `:SessionStop` - Stop recording a session
@@ -123,7 +120,6 @@ TELESCOPE EXTENSION ~
123120
The Telescope extension may be opened via `:Telescope persisted`. The available
124121
actions are:
125122

126-
127123
- `<CR>` - Open/source the session file
128124
- `<C-b>` - Add/update the git branch for the session file
129125
- `<C-c>` - Copy the session file
@@ -134,7 +130,6 @@ GLOBAL VARIABLES ~
134130

135131
The plugin sets a number of global variables throughout its lifecycle:
136132

137-
138133
- `vim.g.persisting` - (bool) Determines if the plugin is active for the current session
139134
- `vim.g.persisted_exists` - (bool) Determines if a session exists for the current working directory
140135
- `vim.g.persisted_loaded_session` - (string) The file path to the current session
@@ -171,7 +166,7 @@ WHAT IS SAVED IN THE SESSION? ~
171166

172167
As the plugin uses Vim’s `:mksession` command then you may change the
173168
`vim.o.sessionoptions` value to determine what to write into the session.
174-
Please see `:h sessionoptions` for more information.
169+
Please see |sessionoptions| for more information.
175170

176171

177172
**Note**The author uses: `vim.o.sessionoptions =
@@ -356,7 +351,6 @@ EVENTS / CALLBACKS ~
356351

357352
The plugin fires events at various points during its lifecycle:
358353

359-
360354
- `PersistedLoadPre` - For _before_ a session is loaded
361355
- `PersistedLoadPost` - For _after_ a session is loaded
362356
- `PersistedTelescopeLoadPre` - For _before_ a session is loaded via Telescope
@@ -379,14 +373,14 @@ session, saving the current session before clearing all of the open buffers:
379373

380374
>lua
381375
local group = vim.api.nvim_create_augroup("PersistedHooks", {})
382-
376+
383377
vim.api.nvim_create_autocmd({ "User" }, {
384378
pattern = "PersistedTelescopeLoadPre",
385379
group = group,
386380
callback = function(session)
387381
-- Save the currently loaded session using a global variable
388382
require("persisted").save({ session = vim.g.persisted_loaded_session })
389-
383+
390384
-- Delete all of the open buffers
391385
vim.api.nvim_input("<ESC>:%bd!<CR>")
392386
end,

lua/persisted/init.lua

+8-9
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,14 @@ function M.get_branch(dir)
113113
if vim.fn.filereadable(branch_session) ~= 0 then
114114
return branch
115115
else
116-
vim.api.nvim_echo({
117-
{ "[Persisted.nvim]\n", "Question" },
118-
{ "Could not load a session for branch " },
119-
{ git_branch[1] .. "\n", "WarningMsg" },
120-
{ "Trying to load a session for branch " },
121-
{ config.options.default_branch, "Title" },
122-
{ " ..." },
123-
}, true, {})
124-
116+
vim.notify(
117+
string.format("[Persisted.nvim]: Trying to load a session for branch %s", config.options.default_branch),
118+
vim.log.levels.INFO
119+
)
120+
vim.notify(
121+
string.format("[Persisted.nvim]: Could not load a session for branch %s.", git_branch[1]),
122+
vim.log.levels.WARN
123+
)
125124
vim.g.persisted_branch_session = branch_session
126125
return config.options.branch_separator .. config.options.default_branch
127126
end

lua/persisted/utils.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local fp_sep = vim.loop.os_uname().sysname:lower():match("windows") and "\\" or
88
--@return string
99
local function echoerr(msg, error)
1010
vim.api.nvim_echo({
11-
{ "[persisted.nvim]: ", "ErrorMsg" },
11+
{ "[Persisted.nvim]: ", "ErrorMsg" },
1212
{ msg, "WarningMsg" },
1313
{ error, "Normal" },
1414
}, true, {})

0 commit comments

Comments
 (0)