chore: use vim.notify (#108)

* Updated warnings and info to print with vim.notify

* Updated formatting
main
Mike Iversen 2024-01-06 03:40:32 -06:00 committed by GitHub
parent 284d714b8d
commit edd8aa41cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 20 deletions

View File

@ -12,7 +12,6 @@ Table of Contents *persisted.nvim-table-of-contents*
FEATURES *persisted.nvim-features*
- Supports sessions across multiple git branches
- Telescope extension to work with saved sessions
- Custom events which users can hook into for tighter integration
@ -23,7 +22,6 @@ FEATURES *persisted.nvim-features*
REQUIREMENTS *persisted.nvim-requirements*
- Neovim >= 0.8.0
@ -60,7 +58,7 @@ Install the plugin with your preferred package manager:
>vim
" Vim Script
Plug 'olimorris/persisted.nvim'
lua << EOF
require("persisted").setup {
-- your configuration comes here
@ -107,7 +105,6 @@ COMMANDS ~
The plugin comes with a number of commands:
- `:SessionToggle` - Determines whether to load, start or stop a session
- `:SessionStart` - Start recording a session. Useful if `autosave = false`
- `:SessionStop` - Stop recording a session
@ -123,7 +120,6 @@ TELESCOPE EXTENSION ~
The Telescope extension may be opened via `:Telescope persisted`. The available
actions are:
- `<CR>` - Open/source the session file
- `<C-b>` - Add/update the git branch for the session file
- `<C-c>` - Copy the session file
@ -134,7 +130,6 @@ GLOBAL VARIABLES ~
The plugin sets a number of global variables throughout its lifecycle:
- `vim.g.persisting` - (bool) Determines if the plugin is active for the current session
- `vim.g.persisted_exists` - (bool) Determines if a session exists for the current working directory
- `vim.g.persisted_loaded_session` - (string) The file path to the current session
@ -171,7 +166,7 @@ WHAT IS SAVED IN THE SESSION? ~
As the plugin uses Vims `:mksession` command then you may change the
`vim.o.sessionoptions` value to determine what to write into the session.
Please see `:h sessionoptions` for more information.
Please see |sessionoptions| for more information.
**Note**The author uses: `vim.o.sessionoptions =
@ -356,7 +351,6 @@ EVENTS / CALLBACKS ~
The plugin fires events at various points during its lifecycle:
- `PersistedLoadPre` - For _before_ a session is loaded
- `PersistedLoadPost` - For _after_ a session is loaded
- `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:
>lua
local group = vim.api.nvim_create_augroup("PersistedHooks", {})
vim.api.nvim_create_autocmd({ "User" }, {
pattern = "PersistedTelescopeLoadPre",
group = group,
callback = function(session)
-- Save the currently loaded session using a global variable
require("persisted").save({ session = vim.g.persisted_loaded_session })
-- Delete all of the open buffers
vim.api.nvim_input("<ESC>:%bd!<CR>")
end,

View File

@ -113,15 +113,14 @@ function M.get_branch(dir)
if vim.fn.filereadable(branch_session) ~= 0 then
return branch
else
vim.api.nvim_echo({
{ "[Persisted.nvim]\n", "Question" },
{ "Could not load a session for branch " },
{ git_branch[1] .. "\n", "WarningMsg" },
{ "Trying to load a session for branch " },
{ config.options.default_branch, "Title" },
{ " ..." },
}, true, {})
vim.notify(
string.format("[Persisted.nvim]: Trying to load a session for branch %s", config.options.default_branch),
vim.log.levels.INFO
)
vim.notify(
string.format("[Persisted.nvim]: Could not load a session for branch %s.", git_branch[1]),
vim.log.levels.WARN
)
vim.g.persisted_branch_session = branch_session
return config.options.branch_separator .. config.options.default_branch
end

View File

@ -8,7 +8,7 @@ local fp_sep = vim.loop.os_uname().sysname:lower():match("windows") and "\\" or
--@return string
local function echoerr(msg, error)
vim.api.nvim_echo({
{ "[persisted.nvim]: ", "ErrorMsg" },
{ "[Persisted.nvim]: ", "ErrorMsg" },
{ msg, "WarningMsg" },
{ error, "Normal" },
}, true, {})