[Bug]: no-neck-pain.nvim `disable` doesn't work in `SavePre` hook
Closed this issue · 9 comments
Your minimal.lua
config
local root = "/tmp/persisted"
-- Set stdpaths to use root dir
for _, name in ipairs({ "config", "data", "state", "cache" }) do
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
-- Bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--single-branch",
"https://github.com/folke/lazy.nvim.git",
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
vim.opt.sessionoptions = "buffers,curdir,folds,globals,tabpages,winpos,winsize" -- Session options to store in the session
-- Install plugins
local plugins = {
{
"olimorris/persisted.nvim",
opts = {
autoload = true,
},
},
{
"shortcuts/no-neck-pain.nvim",
opts = {
buffers = {
scratchPad = {
enabled = true,
location = "/tmp/",
},
bo = {
filetype = "md",
},
},
},
},
-- Put any other plugins here
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
local persisted_hooks = vim.api.nvim_create_augroup("PersistedHooks", {})
vim.api.nvim_create_autocmd({ "User" }, {
pattern = "PersistedSavePre",
group = persisted_hooks,
callback = function()
require("no-neck-pain").disable()
end,
})
Error messages
No response
Describe the bug
What I expect
After :q
uitting a file while using :NoNeckPain
to center the code, I expect to get back into the file at the same position where I left off when loading the Session.
What happens instead
Persisted.nvim opens the side buffer of NoNeckPain instead of my file. Even though I disable NoNeckPain using the PersistedSavePre
hook.
Reproduce the bug
Steps to reproduce:
nvim
:e some-file.txt
:NoNeckPain
:q
nvim
Final checks
- I have made sure this issue exists in the latest version of the plugin
- I have tested with the
minimal.lua
config file above and still get the issue - I have used
SessionSave
to save the session before restarting Neovim and usingSessionLoad
- I have made sure this is not a duplicate issue
I see. But if I disable
them pre save, how are they getting persisted? Is that because the working buffer closes first?
So doing :q
triggers the VimLeavePre
autocmd. I've built Persisted to listen for that autocmd and run the persisted.save
method which in turn calls this method:
---Write the session to disk
---@param session string
---@return nil
local function write(session)
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedSavePre" })
vim.cmd("mks! " .. e(session))
vim.g.persisting = true
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedSavePost" })
end
I suspect that VimLeavePre
causes a conflict with NoNeckPain which doesn't allow it to close down its buffers. Might be worth asking the creator how this works in their plugin.
A quick search on GitHub reveals that there are a lot of users utilising the PersistedSavePre
hook with other plugins.
I'm taking @shortcuts up on their offer to ping them.
@shortcuts Any ideas/insight, why this doesn't work?
Hey there, thanks for the investigation! I've tried with your reproduction and the only weird thing I've seen is that the reopened file is one of the nnp side buffer.
My guess is that there is a race condition between the two plugin since we both have hooks on the quit events. I noticed the prompt before quitting on your recording @olimorris and I do believe this might cause an issue, from my investigation it seems to be on the nnp side so I'll try to see if I can improve that!
@shortcuts sounds great. Totally up for rework on my side too to get our plugins to be friends 😉
I found someone close the NoNeckPain buffers "manually": https://github.com/yuma140902/dotfiles-public/blob/8dd33b742a45e74416b785d1a529ef4e35120752/neovim/nvim/lua/rc/plugins.lua#L568
They are using the blank buffers, I'm not sure how I can identify the buffers when I have scratch pads enabled.
I tried some things, but couldn't get it to work. It's probably a skill issue though.
I found someone close the NoNeckPain buffers "manually": https://github.com/yuma140902/dotfiles-public/blob/8dd33b742a45e74416b785d1a529ef4e35120752/neovim/nvim/lua/rc/plugins.lua#L568
They are using the blank buffers, I'm not sure how I can identify the buffers when I have scratch pads enabled. I tried some things, but couldn't get it to work. It's probably a skill issue though.
You can maybe try to compare the path of the file opened in the buffer? You can get access to it via _G.NoNeckPain.config
and from there you have the path of the opened file in buffers.[left|right].scratchPad.pathToFile
I find a way to remove the prompt when quitting nvim with persisted enabled but it doesn't yet solve the issue of the side buffers :/ i'll keep digging
Closing this for now and please let me know if we do find a solution