Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autowrite doesn't work for local sessions #1598

Open
3 tasks done
maskudo opened this issue Feb 22, 2025 · 2 comments
Open
3 tasks done

Autowrite doesn't work for local sessions #1598

maskudo opened this issue Feb 22, 2025 · 2 comments
Labels
mini.sessions needs-repro This needs a reproduction example

Comments

@maskudo
Copy link

maskudo commented Feb 22, 2025

Contributing guidelines

Module(s)

mini.sessions

Neovim version

0.10.x

Description

Autowrite doesn't seem to work for local sessions. I tried:

  • Initialize local session
  • Open a bunch of buffers
  • Write session
  • Close neovim and again open a few buffers
  • Reopen neovim and call the read function with the local session name
  • Buffers from previous write are opened

I checked the code and the autowrite function seems to default to global session

    local autowrite = function()
      if H.get_this_session() ~= '' then MiniSessions.write(nil, { force = true }) end
    end

Reproduction

Default mini.nvim with

local file = "." .. vim.fn.fnamemodify(vim.fn.getcwd(), ":t") .. ".session.vim"

require("mini.sessions").setup({
  autowrite = true,
  file = file,
  dir = vim.fn.stdpath("state"),
  force = { read = true },
})

local session = require("mini.sessions")

local map = vim.keymap.set
map(
  "n",
  "<leader>qs",
  [[<cmd>lua =vim.v.this_session<cr>]],
  { desc = "Show Session" }
)
map("n", "<leader>ql", function()
  session.select()
end, { desc = "Select session" })
map("n", "<leader>qw", function()
  session.write(file)
end, { desc = "Write session" })

vim.api.nvim_create_autocmd("VimEnter", {
  group = vim.api.nvim_create_augroup("mini-session", { clear = true }),
  callback = function()
    local info = vim.uv.fs_stat(vim.fn.getcwd() .. "/" .. file)
    if not info then
      session.write(file)
    end
  end,
})

and Snacks.dashboard with a section:

           {
            icon = " ",
            key = "s",
            action = function()
              local sessionFile = "."
                .. vim.fn.fnamemodify(vim.fn.getcwd(), ":t")
                .. ".session.vim"
              print(vim.inspect(sessionFile))
              vim.notify(sessionFile)
              require("mini.sessions").read(sessionFile)
            end,
            desc = "Restore Session",
            section = "session",
          }
@maskudo maskudo added the bug Something isn't working label Feb 22, 2025
@echasnovski echasnovski added mini.sessions needs-repro This needs a reproduction example and removed bug Something isn't working labels Feb 22, 2025
@echasnovski
Copy link
Owner

Thanks for the issue!

Unfortunately, I can not reproduce. Autowriting works as expected with both global and local sessions.

  • Initialize local session

  • Open a bunch of buffers

  • Write session

  • Close neovim and again open a few buffers

  • Reopen neovim and call the read function with the local session name

  • Buffers from previous write are opened

I don't understand steps 4-5: is there a missing "open neovim" after the first "close neovim" step? What works is the following:

  • Open buffer 1.
  • Execute :lua MiniSessions.write('.cwd.session.vim') (replace cwd with the current directory name).
  • Open buffer 2 (so that there are two buffers now).
  • Close Neovim.
  • Open Neovim.
  • Execute :lua MiniSessions.read('.cwd.session.vim'). There are two buffers shown, because autowrite works as expected.
  • It can be repeated: open buffer 3 (so that there are two buffers now); close Neovim, open Neovim, read the session, and see that there are three buffers now.

@maskudo
Copy link
Author

maskudo commented Feb 22, 2025

Included a video showing the issue. The buffer count is in the bottom left corner in the statusline.
https://github.com/user-attachments/assets/883d2bc4-4625-4351-ad47-10df2bbf0545

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mini.sessions needs-repro This needs a reproduction example
Projects
None yet
Development

No branches or pull requests

2 participants