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

Compatibility with nvim terminal #24

Open
deft01 opened this issue Feb 7, 2023 · 10 comments
Open

Compatibility with nvim terminal #24

deft01 opened this issue Feb 7, 2023 · 10 comments

Comments

@deft01
Copy link

deft01 commented Feb 7, 2023

It looks like PossessionSave is not compatible with nvim terminals.
This happen when I want to save a session containing multiple terminals.

image

@deft01 deft01 changed the title Compatibility with vim terminal Compatibility with nvim terminal Feb 7, 2023
@jedrzejboczar
Copy link
Owner

I tried to reproduce but I couldn't get an error, and the terminal is loaded when I quit and run PossessionLoad.

Could you please provide the settings you use? Also, please try setting the following options:

require('possession').setup {
    silent = true,
    debug = true,
    logfile = true,
    -- ...
}

and paste here the output from the logfile (defaults to ~/.local/state/nvim/possession.log on Linux, otherwise check :echo stdpath('log')).

Also, may this be somehow related to #8?

@deft01
Copy link
Author

deft01 commented Feb 8, 2023

Yes I think this is totally related to #8, but I don't understand how I can force their deletion ?

@jedrzejboczar
Copy link
Owner

You should be able to use:

require('possession').setup {
    plugins = {
        delete_hidden_buffers = {
            force = function(buf) return vim.api.nvim_buf_get_option(buf, 'buftype') == 'terminal' end
        }
    },
}

It is described in more detail in :h possession.txt. But I guess that this happens because you have buffers in sessionoptions (you can check with :echo &sessionoptions). If you didn't explicitly want this settings you could just disable it which is described here.

@deft01
Copy link
Author

deft01 commented Feb 8, 2023

It works ! Thanks a lot for this plugin.

I don't want to flood your issues, I have another question, why my config doesn't save the session when I'm switching session with Telescope possession list

Config :


  require('possession').setup {
    session_dir =  vim.fn.stdpath("config") .. '/sessions',
    silent = false,
    load_silent = true,
    debug = false,
    logfile = false,
    prompt_no_cr = false,
    autosave = {
        on_load = true,
        on_quit = true,
    },
    commands = {
        save = 'PossessionSave',
        load = 'PossessionLoad',
        close = 'PossessionClose',
        delete = 'PossessionDelete',
        show = 'PossessionShow',
        list = 'PossessionList',
        migrate = 'PossessionMigrate',
    },
    hooks = {
        before_save = function(name) return {} end,
        after_save = function(name, user_data, aborted) end,
        before_load = function(name, user_data) return user_data end,
        after_load = function(name, user_data) end,
    },
    plugins = {
        delete_hidden_buffers = {
            force = function(buf) return vim.api.nvim_buf_get_option(buf, 'buftype') == 'terminal' end
        },
        nvim_tree = true,
        tabby = true,
        dap = true,
        delete_buffers = false,
    },
  }
  -- Possession telescope extension
  require('telescope').load_extension('possession')

@jedrzejboczar
Copy link
Owner

You don't actually have the autosave feature enabled. It requires "what" (current/tmp) and "when" (on_quit/on_load). In the default config both "what" options are disabled so it never auto-saves.

You could e.g. use:

require('possession').setup {
    -- ...
    autosave = {
        current = true,
        tmp = true,
        on_load = true,
        on_quit = true,
    },
    -- ...
}

You can check :h possession-autosave to see if you want both current and tmp enabled.

@deft01
Copy link
Author

deft01 commented Feb 10, 2023

Ok i thought the options on_load and on_quit would be enough to save the current session (if exists) when exiting nvim or loading another session.

@deft01
Copy link
Author

deft01 commented Feb 10, 2023

Also I don't find a way in the doc how to create a new empty Possession session. Since it's a custom json format I can't use the classic mksession command.

@jedrzejboczar
Copy link
Owner

jedrzejboczar commented Feb 10, 2023

What do you mean? You want to do this from Lua code? Because if not than you can just use the command :PossessionSave mysessionname. From Lua this function can be used.

@deft01
Copy link
Author

deft01 commented Feb 10, 2023

I want to get rid of tmux. And manage multiple nvim sessions with nvim.
To achieve this goal I need something to create a blank session with a command or lua function.

My dirty fix is to run a shell command inside nvim that create a new Possession session.
Then I can just load it from my actual Possession session.

Something like : function mks { nvim -c "PossessionSave $1" -c "quitall" }
And I run it inside nvim with : :!mks mynewsession
And load it with : :PossessionLoad mynewsession

@jedrzejboczar
Copy link
Owner

I'm not sure if I understand the idea correctly, but if you want to just generate a blank session than what you're doing seems ok. If you want to avoid spawning new neovim, then you could generate a "blank session" from mksession and then use it with save.

This is what I got when using mksession with no buffers:

let SessionLoad = 1
let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1
let v:this_session=expand("<sfile>:p")
silent only
silent tabonly
cd ~/workspace
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
  let s:wipebuf = bufnr('%')
endif
let s:shortmess_save = &shortmess
if &shortmess =~ 'A'
  set shortmess=aoOA
else
  set shortmess=aoO
endif
argglobal
%argdel
wincmd t
let s:save_winminheight = &winminheight
let s:save_winminwidth = &winminwidth
set winminheight=0
set winheight=1
set winminwidth=0
set winwidth=1
argglobal
enew
tabnext 1
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
  silent exe 'bwipe ' . s:wipebuf
endif
unlet! s:wipebuf
set winheight=1 winwidth=20
let &shortmess = s:shortmess_save
let &winminheight = s:save_winminheight
let &winminwidth = s:save_winminwidth
let s:sx = expand("<sfile>:p:r")."x.vim"
if filereadable(s:sx)
  exe "source " . fnameescape(s:sx)
endif
let &g:so = s:so_save | let &g:siso = s:siso_save
set hlsearch
nohlsearch
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :

Then you can save it in Lua string variable as a "blank session template" (local blank_session = [[...]]). Then, when creating a blank session you can use save with the vimscript as:

local blank_session_template = [[...]]
local vimscript = replace_cwd(blank_session_template, my_cwd) -- would replace line 6 with correct cwd
require('possession.session').save('my-session-name', { vimscript = vimscript, no_confirm = true, cwd = my_cwd })

Would this be ok for your use case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants