Comments (14)
workaround to destroy terminal tabs before save
possession.setup({
save_hook = function()
-- close terminal tabs as they can't be restored and break plugin
local tabpage_count = vim.fn.tabpagenr("$") -- Get the number of tabpages
for i = 1, tabpage_count do
local win_ids = vim.api.nvim_tabpage_list_wins(i) -- Get window IDs in tabpage
for _, win_id in ipairs(win_ids) do
local bufnr = vim.api.nvim_win_get_buf(win_id) -- Get buffer number
if vim.api.nvim_buf_get_option(bufnr, "buftype") == "terminal" then -- Check if buffer is terminal
vim.api.nvim_command(i .. "tabclose") -- Close the tabpage
return
end
end
end
end,
})
from nvim-possession.
Good morning and thank you for bringing the issue to my attention!
if a session is saved with terminal (tab in my case) opened it can't be loaded anymore
Could I ask to better specify what this means? Do you mean a session where some buffers are terminal buffers? If so, are you using neovim native terminal or some other terminal plugins? I have tried saving the session after opening a native terminal buffer and it all works fine. Could you indicate the steps you are taking so that I can reproduce?
from nvim-possession.
Yeah. I have 5 tabs. In the last one i have neovim terminal opened (:term
). It seems to save this session with no problems. But loading it brings the error that i showed, it opens all the saved tabs but the session is not actually loaded (which can be seen by trying to save it)
from nvim-possession.
Yeah. I have 5 tabs
What are you neovim session options? For vim to recognise tabs in sessions you must explicitly specify them (see :h sessionoptions
, you must activate tabpages, terminal
).
Could you try to reproduce it with buffers only, to understand whether this is due to tab or terminal session options?
- open an empty buffer
- open a terminal buffer
- save the session
- reload the session
in my case the above works fine.
from nvim-possession.
- opent an empty buffer
- command
:term
in it - save the session
- update the session => see the error
saved in: /home/glaux/.local/share/nvim/sessions/test2
overwrite session?
E5108: Error executing lua: /home/glaux/.config/nvim/lua/plugins.lua:111: Vim(tabclose):E784: Cannot close last tab page
stack traceback:
[C]: in function 'nvim_command'
/home/glaux/.config/nvim/lua/plugins.lua:111: in function 'save_hook'
...e/nvim/lazy/nvim-possession/lua/nvim-possession/init.lua:56: in function 'update'
/home/glaux/.config/nvim/lua/plugins.lua:125: in function </home/glaux/.config/nvim/lua/plugins.lua:124>
- close vim
- open vim
- load previous session => see the error
[Fzf-lua] fn_selected threw an error: ...e/nvim/lazy/nvim-possession/lua/nvim-possession/init.lua:73: /home/glaux/.local/share/
nvim/sessions/test2, line 36: Vim(normal):Can't re-enter normal mode from terminal mode
stack traceback:
^I...laux/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/core.lua:179: in function <...laux/.local/share/nvim/lazy/fzf-lua/lua/fzf-
lua/core.lua:178>
^I[C]: in function 'source'
^I...e/nvim/lazy/nvim-possession/lua/nvim-possession/init.lua:73: in function 'action'
^I...x/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/actions.lua:72: in function 'act'
^I...laux/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/core.lua:93: in function 'fn_selected'
^I...laux/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/core.lua:177: in function <...laux/.local/share/nvim/lazy/fzf-lua/lua/fzf-
lua/core.lua:176>
^I[C]: in function 'xpcall'
^I...laux/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/core.lua:176: in function <...laux/.local/share/nvim/lazy/fzf-lua/lua/fzf-
lua/core.lua:170>
from nvim-possession.
What are you neovim session options? For vim to recognise tabs in sessions you must explicitly specify them (see :h sessionoptions, you must activate tabpages, terminal).
i don't don't have any special sessionoptions set. (UPD: misunderstood):tab new
works out of the box, no?
from nvim-possession.
this is my sessionoptions
and it is set by default: sessionoptions=blank,buffers,curdir,folds,help,tabpages,winsize,terminal
from nvim-possession.
just tried it with an empty config, single plugin. And the error is there
init.lua
vim.g.mapleader = " " -- must be set prior plugins initialization
require "plugins"
plugins.lua
local lazypath = vim.fn.stdpath("data") .. "/lazy/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",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
local lazy = require "lazy"
local plugins = {
{ -- sessions management
"gennaro-tedesco/nvim-possession",
version = "*",
dependencies = {
"ibhagwan/fzf-lua",
},
config = true,
init = function()
local possession = require("nvim-possession")
vim.keymap.set("n", "<leader>sl", function()
possession.list()
end)
vim.keymap.set("n", "<leader>sn", function()
possession.new()
end)
vim.keymap.set("n", "<leader>su", function()
possession.update()
end)
vim.keymap.set("n", "<leader>sd", function()
possession.delete()
end)
end,
},
}
local options = {
defaults = {
lazy = false,
},
performance = {
cache = {
enabled = true,
},
rtp = {
disabled_plugins = {
"gzip",
-- "netrwPlugin",
"rplugin",
"tarPlugin",
"tohtml",
"tutor",
"zipPlugin",
},
},
},
ui = {
size = { width = 0.9, height = 0.9 },
border = { "┏", "━", "┓", "┃", "┛", "━", "┗", "┃" },
},
checker = {
-- automatically check for plugin updates
enabled = false,
},
}
lazy.setup(plugins, options)
from nvim-possession.
I have used the aforementioned minimal init.lua
and I have observed the following:
- save the session
- update the session => see the error
I do not see any error while doing so: what version of neovim are you on? P. S. you need not update the session after saving it, saving it suffices. Do you still see an error if just saving a session consisting of a normal buffer and a terminal buffer?
- load previous session => see the error
interestingly enough here I only see the error if the last buffer I operate on is the terminal buffer, namely if - after opening the terminal buffer - I switch back to any other normal buffer then no such error occurs. By looking at the stacktrace I suspect this is due to neovim trying to remember the last cursor position to be in terminal mode and being unable to re-enter normal mode upon loading the session: I have found a similar issue opened in core.
Can you confirm this behaviour, namely that if you switch back to a normal buffer and save the session then no error occurs?
from nvim-possession.
what version of neovim are you on?
it's in my initial post
NVIM v0.10.0-dev
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
you need not update the session after saving it, saving it suffices. Do you still see an error if just saving a session consisting of a normal buffer and a terminal buffer?
yeah, i know i don't need to do that. It's just the quickest way to repro the issue. Saving a new session doesn't raise any error. Loading it raises error and updating it as well. Loading does load the tabs and everything (looks like) but the session itself seems to be not set (because when trying to update it there is a message something like no session)
Can you confirm this behaviour, namely that if you switch back to a normal buffer and save the session then no error occurs?
I'm not sure i follow. Are you suggesting to:
- open vim
- open normal buffer (a file)
- open a terminal buffer (same single tab)
- switch back to a normal file buffer
- save session
- close vim
- open vim
- load session
If that's what you mean, then yeah, no errors there. But no surprise as terminal buffer is not present in the saved session at all
from nvim-possession.
If that's what you mean, then yeah, no errors there. But no surprise as terminal buffer is not present in the saved session at all
the terminal buffer is present in the saved session, is it not? See screenshot below to reproduce:
Screen.Recording.2023-10-04.at.15.45.27.mov
Is the terminal buffer no longer present in your case?
from nvim-possession.
yeah, my bad, it is there, terminal is there and no errors are there. So yeah, the problem is only when terminal buffer is active
from nvim-possession.
In which case I wouldn't really know what should be the intended behaviour (as it is a neovim problem, as per issue above): one solution could be to write a save_hook
as you did, I wouldn't however make it default part of the plugin as it could generate unwanted behaviours (i. e. wiping off terminal buffers unwantedly).
from nvim-possession.
yeah, i guess i'm ok with my solution. Ideally would be to have a setting for this. Like auto_close_active_terminal_buffers = false (default)
. But that's not i big issue. Feel free to close it
from nvim-possession.
Related Issues (20)
- nvim-tree not loading when restoring a session HOT 9
- Replace "new" and "update" with just "save", buggy when launched at start HOT 7
- About vimscript configuration issues HOT 11
- tag the rockspec with the "neovim" label. HOT 4
- Expose a delete() function HOT 6
- Bad filepath error (No such file or directory) HOT 24
- Files that are deleted still shows in session file. HOT 11
- The autoload setting makes the loaded buffer innactive HOT 1
- How to "close" session? HOT 9
- Bug in README with lualine HOT 2
- Plugin doesn't work HOT 9
- autoload cause double lualine in lazyvim HOT 4
- Close session HOT 9
- Auto-create session path HOT 3
- autoload doesn't work HOT 7
- I get an error when calling the setup function: Vim:E499: Empty file name for '%' or '#', only works with ":p:h" HOT 1
- I have a text on the top that I don't know how to turn off HOT 2
- Switch session will clean up buffers from current session? HOT 8
- Decouple fzf-lua to a plugin? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nvim-possession.