Compatibility with nvim terminal
Opened this issue · 10 comments
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?
Yes I think this is totally related to #8, but I don't understand how I can force their deletion ?
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.
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')
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.
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.
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.
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.
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
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?