folke / persistence.nvim

💾 Simple session management for Neovim
Apache License 2.0
591 stars 26 forks source link

bug: session isn't saved when `vim.cmd "wa"` gets called in the `pre_save` hook #37

Closed alex35mil closed 6 months ago

alex35mil commented 8 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.9.2

Operating system/version

macOS 14.0

Describe the bug

When I call vim.cmd "wa" in the pre_save hook, session isn't saved.

pre_save = function()
    vim.cmd "wa"
end

Steps To Reproduce

  1. Add pre_save hook with vim.cmd "wa" call
  2. Exit Neovim
  3. Session is not saved

Expected Behavior

Buffers and sessions are saved.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
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", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    "folke/tokyonight.nvim",
    {
        "folke/persistence.nvim",
        event = "BufReadPre",
        config = function()
            require("persistence").setup({
                pre_save = function()
                    vim.cmd "wa"
                end,
                save_empty = true,
            })
        end,
    },
    -- add any other plugins here
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
b0ae989c commented 8 months ago

This seems to be a Neovim v0.9.2 issue. With this config on macOS Neovim v0.9.4, persistence.nvim saves and loads the session properly.

alex35mil commented 5 months ago

I'm on nightly now and it still breaks the same way. My config is here.

NVIM v0.10.0-dev-2138+gfa9a85ae4
Build type: Release
LuaJIT 2.1.1703358377
Run "nvim -V1 -v" for more info