Closed Iron-E closed 1 year ago
Re: https://github.com/romgrk/barbar.nvim/issues/361#issuecomment-1442142991
nvim a b c d
, then:
BufferPin
doautocmd User SessionSavePre
mksession! foo.vim
qa
…and then nvim -S foo.vim
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(":p")
let Bufferline__session_restore = "lua require'bufferline.state'.restore_buffers {{name = \"a\",pinned = true,},{name = \"b\",pinned = false,},{name = \"c\",pinned = false,},{name = \"d\",pinned = false,}}"
silent only
silent tabonly
cd /tmp
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
badd +0 a
badd +0 b
badd +0 c
badd +0 d
argglobal
%argdel
$argadd a
$argadd b
$argadd c
$argadd d
edit a
argglobal
setlocal fdm=marker
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
let s:l = 1 - ((0 * winheight(0) + 19) / 38)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 1
normal! 0
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 s:sx = expand(":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 :
Note line 4:
let Bufferline__session_restore = "lua require'bufferline.state'.restore_buffers {{name = \"a\",pinned = true,},{name = \"b\",pinned = false,},{name = \"c\",pinned = false,},{name = \"d\",pinned = false,}}"
That variable was missing in the session file generated by persistence.nvim, so I'll have to do some investigating.
mksession! foo.vim
here, even with mksession! it doesn't save the pin, maybe something in my config?
doautocmd User SessionSavePre
Nevermind, it works (i forgot the doautocmd User SessionSavePre)
here, even with mksession! it doesn't save the pin, maybe something in my config?
Hmm, perhaps. That should definitely be working.
Since persistence.nvim is normally being used, vim.opt.sessionoptions:append 'globals'
would need to be added to your config for this to work without it (although I think you already did that).
If your dots are online I can take a look.
Nevermind, it works (i forgot the doautocmd User SessionSavePre)
Ah, gotcha. So long as persistence.nvim still isn't working I'll keep this open
my dotfiles:
https://github.com/otavioschwanck/mood-nvim
(still using bufferline on it, i didn't push barbar)
@Iron-E
(saved with persistence.nvim)
It should be persisted, right?
lua = vim.g.Bufferline__session_restore returns nil
maybe changing the variable name to BufferlineSessionRestore fixes it ?
..
The SessionSavePre is not being called for some reason.
:au SessionSavePre:
It should be persisted, right?
Yeah, it should be.
lua = vim.g.Bufferline__session_restore
returns nilmaybe changing the variable name to BufferlineSessionRestore fixes it ?
That's a good thought, though persistence.nvim also uses :mksession
under the hood, so it would be strange for it to work in one setting and not the other (then again, computers are strange). I'm going to download the plugin and check it out.
The SessionSavePre is not being called for some reason.
To clarify, SessionSavePre
is not an actual event. We are using the User
event (:h User
) with the SessionSavePre
pattern, like so:
vim.api.nvim_exec_autocmds('User', {pattern = 'SessionSavePre'})
If you run :autocmd User SessionSavePre
you should see barbar.nvim's autocommand.
@otavioschwanck I just tried persistence.nvim, and it worked for me. Here's my config (using lazy.nvim):
{'folke/persistence.nvim', opts = {
dir = '/tmp/persistence.nvim', -- you can leave this out, I'm just setting it because I'm testing the plugin
options = {'buffers', 'curdir', 'globals', 'tabpages', 'winsize'},
}},
Here's what I did:
nvim a b c d
BufferPin b
doautocmd User SessionSavePre
qa
:lua require'persistence'.load {last = true}
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(":p")
let Bufferline__session_restore = "lua require'bufferline.state'.restore_buffers {{name = \"b\",pinned = true,},{name = \"a\",pinned = false,},{name = \"c\",pinned = false,},{name = \"d\",pinned = false,}}"
silent only
silent tabonly
cd /tmp
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
badd +1 a
badd +1 b
badd +1 c
badd +1 d
badd +2831 \[Command\ Line]
argglobal
%argdel
$argadd a
$argadd b
$argadd c
$argadd d
edit a
let s:save_splitbelow = &splitbelow
let s:save_splitright = &splitright
set splitbelow splitright
let &splitbelow = s:save_splitbelow
let &splitright = s:save_splitright
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
let s:l = 1 - ((0 * winheight(0) + 15) / 30)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 1
normal! 0
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(":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 :
I have also made a pull request (folke/persistence.nvim#22) which will automate the :doautocmd
calls. The PR has an example configuration for this plugin.
@otavioschwanck I just tried persistence.nvim, and it worked for me. Here's my config (using lazy.nvim):
{'folke/persistence.nvim', opts = { dir = '/tmp/persistence.nvim', -- you can leave this out, I'm just setting it because I'm testing the plugin options = {'buffers', 'curdir', 'globals', 'tabpages', 'winsize'}, }},
Here's what I did:
nvim a b c d
- Enter these commands (in order):
BufferPin b doautocmd User SessionSavePre qa
- Open Neovim and do
:lua require'persistence'.load {last = true}
Here's what the session file looked like for me
didn't work either:
if i call the autocmd, persistence don't save the session if i dont call, it saves (but not the pins)
..
i tried https://github.com/rmagatti/auto-session and same problem happens, no pins either. My neovim: 0.8.3.
With https://github.com/akinsho/bufferline.nvim the tabs are persisted without any issues
Tried your fix on persistence and same thing happen: Only the buffer position are being saved, not the pins:
{
"Iron-E/persistence.nvim", branch = 'feat/pre-save',
event = "BufReadPre", -- this will only start session saving when an actual file was opened
module = "persistence",
config = function()
require("persistence").setup({
options = { "buffers", "curdir", "tabpages", "winsize", "globals" }, -- sessionoptions used for saving
pre_save = function() vim.api.nvim_exec_autocmds('User', {pattern = 'SessionSavePre'}) end,
})
-- require("scripts.auto-save-session").setup()
end,
}```
With https://github.com/akinsho/bufferline.nvim the tabs are persisted without any issues
Correct. I outlined the reason for this in folke/persistence.nvim#22— namely, bufferline.nvim sacrifices performance to cut down on the need for explicit configuration with session managers, whereas this plugin tries to preserve performance (but it requires configuration with session managers to function).
I made a fork of your dots to test this, and wasn't able to reproduce the issue. Most of the changes were just commenting things out (because I didn't have particular software installed, notably tmux
), but these two files will be of interest:
module = 'persistence'
— it doesn't mean the same thing to lazy.nvim as it did to packer. Since the persistence.nvim instructions are for packer, I got rid of it.event = 'BufReadPre'
, because I've been testing on random files (e.g. "a", "b", "c"), and opening these files does not trigger that event since they don't already exist.
:doautocmd
before exiting does the same thing. I also tested that, and it worked for meYou can view the full diff here.
Try out my fork of your config (if you have Neovim 0.9, you can change $NVIM_APPNAME
to avoid messing with your current configuration) and see if you can still reproduce.
Edit: you're also welcome to try my config. Same thing about $NVIM_APPNAME
First, thanks for your help, you are awesome!
Second:
I tested on mood and it worked (the pin).
On my real private config (based on mood, it wont):
It only saves the tabs positions on the session, not the pinned (always saves as false):
let Bufferline__session_restore = "lua require'bufferline.state'.restore_buffers {{name = \"lua/plugins/lsp-zero.lua\",pinned = false,},{name = \"init.lua\",pinned = false,}}"
Using barbar and persistence the same way you did on mood.
EDIT: I invited you to my dotfiles.
EDIT 2: Debugging here, i found that the Load is being executed, but it doesn't pin =C:
EDIT 3:
Is getting inside here:
But the pin command is not working for some reason.
Just to remember: The buffer order is being keep, just the pin is not being set (even calling the state.toggle_pin(bufnr))
EDIT 4:
If i load some buffer before loading the session, it works. The problem is only i quickly load session
@Iron-E after a lot of debugging:
The problem is:
Tried to fix but no success!
@otavioschwanck thank you for the kind words!
I haven't had time to check out your dots (yet— I can later today), but have you tried applying some of the changes I made to mood-nvim in https://github.com/romgrk/barbar.nvim/issues/364#issuecomment-1442596194 ? Try copying over the two files I mentioned, especially "persistence.lua". From the sounds of it, the event
or module
key might be messing things up.
@otavioschwanck thank you for the kind words!
I haven't had time to check out your dots (yet— I can later today), but have you tried applying some of the changes I made to mood-nvim in #364 (comment) ? Try copying over the two files I mentioned, especially "persistence.lua". From the sounds of it, the
event
ormodule
key might be messing things up.
i already removed. Look this comment: https://github.com/romgrk/barbar.nvim/issues/364#issuecomment-1444135373
At the end:
The session is being loaded successfully (i debugged the barbar gem), the order is being set but the pins is not being set.
If i open neovim, open a random file, and after that, load the session, the pins are loaded.
I've downloaded your dotfiles, and I can confirm that it does not work either for me. I'll do some investigating on my end.
Edit: @otavioschwanck I think I've located the problem. In "lua/plugins/lsp-zero.lua", if I comment out lsp.preset('recommended')
or lsp.setup()
, everything works. I don't have any experience with lsp-zero, so I hope that this is able to point you in the right direction.
Maybe it's a problem with managing nvim-cmp? I get this warning:
[lsp-zero] Settings for nvim_cmp should be handled by the user
It could be quite a few things— lsp-zero.nvim is ~100 lines shy of being bigger than barbar :smile:
I've downloaded your dotfiles, and I can confirm that it does not work either for me. I'll do some investigating on my end.
Edit: @otavioschwanck I think I've located the problem. In "lua/plugins/lsp-zero.lua", if I comment out
lsp.preset('recommended')
orlsp.setup()
, everything works. I don't have any experience with lsp-zero, so I hope that this is able to point you in the right direction.Maybe it's a problem with managing nvim-cmp? I get this warning:
[lsp-zero] Settings for nvim_cmp should be handled by the user
It could be quite a few things— lsp-zero.nvim is ~100 lines shy of being bigger than barbar 😄
the problem is with the nvim-cmp of lsp-zero.
changing to:
lsp.preset({ manage_nvim_cmp = false })```
The problem don't happen
Lets close this! Thanks for your help!
For who that don't wanna wait the persistence fix, just call persistence this way:
return {
{
"folke/persistence.nvim",
event = "BufReadPre",
config = function ()
require("persistence").setup({
options = {'buffers', 'curdir', 'globals', 'tabpages', 'winsize'},
})
vim.api.nvim_create_autocmd("VimLeavePre", {
group = vim.api.nvim_create_augroup("persistence_pre_save", { clear = true }),
callback = function ()
vim.cmd("doautocmd User SessionSavePre")
require('persistence').save()
end
})
end
}
}
even using :doautocmd User SessionSavePre it not save.
The session file:
Originally posted by @otavioschwanck in https://github.com/romgrk/barbar.nvim/issues/361#issuecomment-1442134965