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

auto sessions don't work on latest #4561

Closed
jw3126 opened this issue May 17, 2024 · 5 comments
Closed

auto sessions don't work on latest #4561

jw3126 opened this issue May 17, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@jw3126
Copy link

jw3126 commented May 17, 2024

Problem description

Restoring a session on startup does not work

LunarVim version

master-d15c8d7

Neovim version (>= 0.9.1)

0.10

Terminal name

kitty

Operating system/version

linux

Steps to reproduce

If I use the nightly lvim with nvim v0.10, the following config.lua does not work:

local function get_session_file()
  local cwd = vim.fn.getcwd()
  return cwd .. '/Session.vim'
end

local function save_session()
  local session_file = get_session_file()
  vim.cmd('mksession! ' .. session_file)
end

local function load_session()
  local session_file = get_session_file()
  if vim.fn.filereadable(session_file) == 1 then
    vim.cmd('source ' .. session_file)
  end
end

local auto_session_group = "AutoSession0xc611acb237cb7aa5"
vim.api.nvim_create_augroup(auto_session_group, { clear = true })

vim.api.nvim_create_autocmd('BufWritePost', {
  group = auto_session_group,
  callback = save_session,
})

vim.api.nvim_create_autocmd('VimEnter', {
  group = auto_session_group,
  callback = load_session,
})

It gives me

.../pack/lazy/opt/lazy.nvim/lua/lazy/core/handler/event.lua:157: Invalid buffer id: 1 

If I instead put the same content in init.lua for nvim 0.10 without lvim, it works.

Screenshots

No response

@jw3126 jw3126 added the bug Something isn't working label May 17, 2024
@kylo252
Copy link
Collaborator

kylo252 commented May 22, 2024

this seems related to lazy-loading:

  • is this still an issue if you update lazy.nvim to latest?
  • is it an issue if you defer the call after VimEnter?

@jw3126
Copy link
Author

jw3126 commented May 23, 2024

Thanks I will look into it. BTW are there any recommendations for easily being able to switch between combinations of lvim + nvim versions?

@jw3126
Copy link
Author

jw3126 commented May 23, 2024

is it an issue if you defer the call after VimEnter?

I can manually do :source Session.vim and it works. So in that is a case it would work after VimEnter. However I would like it to be an auto command. Any suggestions what to use instead of VimEnter?
I would like lvim to automatically bring me to my last session when I launch it. Is there something after VimEnter but still earlier that any user interaction?

@kylo252
Copy link
Collaborator

kylo252 commented May 23, 2024

I can manually do :source Session.vim and it works. So in that is a case it would work after VimEnter. However I would like it to be an auto command.

try adding the code snippet in a file under ~/.config/lvim/after/plugin

Any suggestions what to use instead of VimEnter? I would like lvim to automatically bring me to my last session when I launch it. Is there something after VimEnter but still earlier that any user interaction?

you can try UIEnter, but I was actually just thinking of using vim.defer_fn, see: folke/lazy.nvim@fd1fbef

@jw3126
Copy link
Author

jw3126 commented May 23, 2024

Thanks a lot!

  • UIEnter does not work
  • defer_fn works 🎉

@kylo252 kylo252 closed this as completed May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants