Code Monkey home page Code Monkey logo

Comments (14)

Seybo avatar Seybo commented on September 25, 2024

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.

gennaro-tedesco avatar gennaro-tedesco commented on September 25, 2024

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.

Seybo avatar Seybo commented on September 25, 2024

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.

gennaro-tedesco avatar gennaro-tedesco commented on September 25, 2024

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?

  1. open an empty buffer
  2. open a terminal buffer
  3. save the session
  4. reload the session

in my case the above works fine.

from nvim-possession.

Seybo avatar Seybo commented on September 25, 2024
  1. opent an empty buffer
  2. command :term in it
  3. save the session
  4. 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>
  1. close vim
  2. open vim
  3. 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.

Seybo avatar Seybo commented on September 25, 2024

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. :tab new works out of the box, no? (UPD: misunderstood)

from nvim-possession.

Seybo avatar Seybo commented on September 25, 2024

this is my sessionoptions and it is set by default: sessionoptions=blank,buffers,curdir,folds,help,tabpages,winsize,terminal

from nvim-possession.

Seybo avatar Seybo commented on September 25, 2024

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.

gennaro-tedesco avatar gennaro-tedesco commented on September 25, 2024

I have used the aforementioned minimal init.lua and I have observed the following:

  1. save the session
  2. 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?

  1. 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.

Seybo avatar Seybo commented on September 25, 2024

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.

gennaro-tedesco avatar gennaro-tedesco commented on September 25, 2024

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.

Seybo avatar Seybo commented on September 25, 2024

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.

gennaro-tedesco avatar gennaro-tedesco commented on September 25, 2024

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.

Seybo avatar Seybo commented on September 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.