chore: use vim.notify (#108)
* Updated warnings and info to print with vim.notify * Updated formattingmain
parent
284d714b8d
commit
edd8aa41cd
|
|
@ -12,7 +12,6 @@ Table of Contents *persisted.nvim-table-of-contents*
|
||||||
|
|
||||||
FEATURES *persisted.nvim-features*
|
FEATURES *persisted.nvim-features*
|
||||||
|
|
||||||
|
|
||||||
- Supports sessions across multiple git branches
|
- Supports sessions across multiple git branches
|
||||||
- Telescope extension to work with saved sessions
|
- Telescope extension to work with saved sessions
|
||||||
- Custom events which users can hook into for tighter integration
|
- Custom events which users can hook into for tighter integration
|
||||||
|
|
@ -23,7 +22,6 @@ FEATURES *persisted.nvim-features*
|
||||||
|
|
||||||
REQUIREMENTS *persisted.nvim-requirements*
|
REQUIREMENTS *persisted.nvim-requirements*
|
||||||
|
|
||||||
|
|
||||||
- Neovim >= 0.8.0
|
- Neovim >= 0.8.0
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -60,7 +58,7 @@ Install the plugin with your preferred package manager:
|
||||||
>vim
|
>vim
|
||||||
" Vim Script
|
" Vim Script
|
||||||
Plug 'olimorris/persisted.nvim'
|
Plug 'olimorris/persisted.nvim'
|
||||||
|
|
||||||
lua << EOF
|
lua << EOF
|
||||||
require("persisted").setup {
|
require("persisted").setup {
|
||||||
-- your configuration comes here
|
-- your configuration comes here
|
||||||
|
|
@ -107,7 +105,6 @@ COMMANDS ~
|
||||||
|
|
||||||
The plugin comes with a number of commands:
|
The plugin comes with a number of commands:
|
||||||
|
|
||||||
|
|
||||||
- `:SessionToggle` - Determines whether to load, start or stop a session
|
- `:SessionToggle` - Determines whether to load, start or stop a session
|
||||||
- `:SessionStart` - Start recording a session. Useful if `autosave = false`
|
- `:SessionStart` - Start recording a session. Useful if `autosave = false`
|
||||||
- `:SessionStop` - Stop recording a session
|
- `:SessionStop` - Stop recording a session
|
||||||
|
|
@ -123,7 +120,6 @@ TELESCOPE EXTENSION ~
|
||||||
The Telescope extension may be opened via `:Telescope persisted`. The available
|
The Telescope extension may be opened via `:Telescope persisted`. The available
|
||||||
actions are:
|
actions are:
|
||||||
|
|
||||||
|
|
||||||
- `<CR>` - Open/source the session file
|
- `<CR>` - Open/source the session file
|
||||||
- `<C-b>` - Add/update the git branch for the session file
|
- `<C-b>` - Add/update the git branch for the session file
|
||||||
- `<C-c>` - Copy 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:
|
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.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_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
|
- `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 Vim’s `:mksession` command then you may change the
|
As the plugin uses Vim’s `:mksession` command then you may change the
|
||||||
`vim.o.sessionoptions` value to determine what to write into the session.
|
`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 =
|
**Note**The author uses: `vim.o.sessionoptions =
|
||||||
|
|
@ -356,7 +351,6 @@ EVENTS / CALLBACKS ~
|
||||||
|
|
||||||
The plugin fires events at various points during its lifecycle:
|
The plugin fires events at various points during its lifecycle:
|
||||||
|
|
||||||
|
|
||||||
- `PersistedLoadPre` - For _before_ a session is loaded
|
- `PersistedLoadPre` - For _before_ a session is loaded
|
||||||
- `PersistedLoadPost` - For _after_ a session is loaded
|
- `PersistedLoadPost` - For _after_ a session is loaded
|
||||||
- `PersistedTelescopeLoadPre` - For _before_ a session is loaded via Telescope
|
- `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
|
>lua
|
||||||
local group = vim.api.nvim_create_augroup("PersistedHooks", {})
|
local group = vim.api.nvim_create_augroup("PersistedHooks", {})
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd({ "User" }, {
|
vim.api.nvim_create_autocmd({ "User" }, {
|
||||||
pattern = "PersistedTelescopeLoadPre",
|
pattern = "PersistedTelescopeLoadPre",
|
||||||
group = group,
|
group = group,
|
||||||
callback = function(session)
|
callback = function(session)
|
||||||
-- Save the currently loaded session using a global variable
|
-- Save the currently loaded session using a global variable
|
||||||
require("persisted").save({ session = vim.g.persisted_loaded_session })
|
require("persisted").save({ session = vim.g.persisted_loaded_session })
|
||||||
|
|
||||||
-- Delete all of the open buffers
|
-- Delete all of the open buffers
|
||||||
vim.api.nvim_input("<ESC>:%bd!<CR>")
|
vim.api.nvim_input("<ESC>:%bd!<CR>")
|
||||||
end,
|
end,
|
||||||
|
|
|
||||||
|
|
@ -113,15 +113,14 @@ function M.get_branch(dir)
|
||||||
if vim.fn.filereadable(branch_session) ~= 0 then
|
if vim.fn.filereadable(branch_session) ~= 0 then
|
||||||
return branch
|
return branch
|
||||||
else
|
else
|
||||||
vim.api.nvim_echo({
|
vim.notify(
|
||||||
{ "[Persisted.nvim]\n", "Question" },
|
string.format("[Persisted.nvim]: Trying to load a session for branch %s", config.options.default_branch),
|
||||||
{ "Could not load a session for branch " },
|
vim.log.levels.INFO
|
||||||
{ git_branch[1] .. "\n", "WarningMsg" },
|
)
|
||||||
{ "Trying to load a session for branch " },
|
vim.notify(
|
||||||
{ config.options.default_branch, "Title" },
|
string.format("[Persisted.nvim]: Could not load a session for branch %s.", git_branch[1]),
|
||||||
{ " ..." },
|
vim.log.levels.WARN
|
||||||
}, true, {})
|
)
|
||||||
|
|
||||||
vim.g.persisted_branch_session = branch_session
|
vim.g.persisted_branch_session = branch_session
|
||||||
return config.options.branch_separator .. config.options.default_branch
|
return config.options.branch_separator .. config.options.default_branch
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ local fp_sep = vim.loop.os_uname().sysname:lower():match("windows") and "\\" or
|
||||||
--@return string
|
--@return string
|
||||||
local function echoerr(msg, error)
|
local function echoerr(msg, error)
|
||||||
vim.api.nvim_echo({
|
vim.api.nvim_echo({
|
||||||
{ "[persisted.nvim]: ", "ErrorMsg" },
|
{ "[Persisted.nvim]: ", "ErrorMsg" },
|
||||||
{ msg, "WarningMsg" },
|
{ msg, "WarningMsg" },
|
||||||
{ error, "Normal" },
|
{ error, "Normal" },
|
||||||
}, true, {})
|
}, true, {})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue