Closed calops closed 11 months ago
Yes, this is a known issue. The session won't store the tab variable, I tried some methods but failed or too complicated.
As a side comment, I really enjoy tabby but wish this feature existed as well. I know that Taboo.vim supports this but as you said, I am not sure how it does that @nanozuki unless if you perhaps integrate the plugin with something like Obsession to restore tab names...
Either way, thanks for the great plugin!
Good call about Taboo.vim. I looked around and they use global variables to remember tab names: https://github.com/gcmt/taboo.vim/blob/caf948187694d3f1374913d36f947b3f9fa1c22f/plugin/taboo.vim#L23
Seems a bit tedious as you would need to serialize all the names as a string on session save, and parse it on load. But perfectly doable. I may try to implement this whenever I have some time.
Amazing @calops - if you end up making a PR, please ping me there and I will give a review as well as test it out. :smile:
I've been a bit busy lately and just recently saw the messages. I was struggling with how to store an array to a global variable. After looking at the code in Taboo.vim, I was inspired that we can encode it as a string.
No worries at all @nanozuki ! Happy to provide a demo or this functionality working in Taboo. Thanks for the package and hope you are having a great day. :)
FYI: nyngwang/suave.lua is a lightweight auto project-session plugin that supports this (and more). There is a DEMO in the README and an example setup
config in the Wiki.
@nyngwang Thanks! I'll read that. This is an excellent reference. I found that nvim has API to encode/decode JSON; it also may be helpful. Because of some personal reasons and my new year holiday, I'm late! However, I want to implement this feature this month.
My hack for rmagatti/auto-session
(plugin use x.vim):
save_extra_cmds = {
-- tabby: tabs name
function()
local cmds = {}
for _, t in pairs(vim.api.nvim_list_tabpages()) do
local tabname = require("tabby.feature.tab_name").get_raw(t)
if tabname ~= "" then
table.insert(cmds, 'require("tabby.feature.tab_name").set(' .. t .. ', "' .. tabname:gsub('"', '\\"') .. '")')
end
end
if #cmds == 0 then
return ""
end
return "lua " .. table.concat(cmds, ";")
end,
},
@qRoC It works! But I currently have return "colorscheme " .. vim.g.colors_name
inside save_extra_cmds in order to put a persistent colorscheme by session. It is possible to implement those two things (persistent colorscheme and persistent tab names) inside save_extra_cmds? I'm not a master in Lua.
@sergiornelas Hi, try:
save_extra_cmds = {
-- tabby: tabs name
function()
local cmds = {}
for _, t in pairs(vim.api.nvim_list_tabpages()) do
local tabname = require("tabby.feature.tab_name").get_raw(t)
if tabname ~= "" then
table.insert(cmds, 'require("tabby.feature.tab_name").set(' .. t .. ', "' .. tabname:gsub('"', '\\"') .. '")')
end
end
if #cmds == 0 then
return ""
end
return "lua " .. table.concat(cmds, ";")
end,
-- colorscheme
function()
return "colorscheme " .. vim.g.colors_name
end,
},
@qRoC works as expected, but I found new a bug. When you create and rename 3 tabs, if you delete the tab number 1 or 2 and reload the session it breaks.
Change
if tabname ~= "" then
table.insert(cmds, 'require("tabby.feature.tab_name").set(' .. t .. ', "' .. tabname:gsub('"', '\\"') .. '")')
end
to
if tabname ~= "" then
table.insert(
cmds,
'pcall(require("tabby.feature.tab_name").set, ' .. t .. ', "' .. tabname:gsub('"', '\\"') .. '")'
)
end
:)
@qRoC It doesn't break, however now after you delete the second tab and reload the session, the name of the second tab (previously was the third), disappears. 😬
Sorry for being late! 😠The ids of tabs are not stable in every neovim startup. If want to persist the names, we should use the numbers of tabs.
The problem can be solved by storing all the tabby titles in an array using tab number(1~n) instead of tab handle, as keeping the ordering has nothing to do with storing tab handles. (as stated by the author)
So no need to change anything in tabby.nvim side. This is not a bug. Tabby.nvim does a great job only taking the tab handle as the argument, which conforms to the APIs Neovim provides.
-- storing.
for tabn, tabh in pairs(vim.api.nvim_list_tabpages()) do
tabby[tabn] = require('tabby.feature.tab_name').get_raw(tabh)
end
-- restoring.
for tabn, tabh in pairs(vim.api.nvim_list_tabpages()) do
if tabby[tabn] then
require('tabby.feature.tab_name').set(tabh, tabby[tabn])
end
end
Sorry for being late; I'm too busy this year. I use JSON encode/decode to save and restore the tab names to vim global variables. Now, we can restore tab names from the session by addingglobals
to sessionoptions
!
When renaming a tab through
:TabRename
, it won't persist after closing the editor and recovering the previous session. Instead, the default behavior is back, with the focused buffer's name as the tab name.I don't actually know if it's possible to persist this information, I have very little insight into how vim sessions work.