romgrk / barbar.nvim

The neovim tabline plugin.
2.23k stars 83 forks source link

Persist pins through sessions #361

Closed otavioschwanck closed 1 year ago

otavioschwanck commented 1 year ago

Would be nice to have it on barbar.

Iron-E commented 1 year ago

Does #363 fit the use case? Or is there something different you had in mind?

otavioschwanck commented 1 year ago

Does #363 fit the use case? Or is there something different you had in mind?

i think it fits!

otavioschwanck commented 1 year ago

@Iron-E i upgraded and the buffer pin is still not being persisted!

image
Iron-E commented 1 year ago

Did you :doautocmd User SessionSavePre, then :mksession foo.vim (or any other session management command) before exiting? Then to load, nvim -S foo.vim

otavioschwanck commented 1 year ago

Did you :doautocmd User SessionSavePre, then :mksession foo.vim (or any other session management command) before exiting? Then to load, nvim -S foo.vim

Im using persistence.nvim. i already testes with bufferline pins and it works.

Iron-E commented 1 year ago

So it works now? Might be convenient to write a wrapper like this to ensure the autocmd event always gets fired in the future:

vim.api.nvim_create_user_command( 
  'Mksession',
  function()
    vim.api.nvim_exec_autocmds('User', {pattern = 'SessionSavePre'})
    --[[ session save command here 
         e.g. `vim.cmd.mksession()` 
              or persistence.nvim function ]]
  end,
  {} 
)

Edit: interesting. persistence.nvim doesn't have a session save command, it just does everything automatically


Edit 2: found the issue. persistence.nvim overrides your sessionoptions on save with these:

options = { "buffers", "curdir", "tabpages", "winsize" }

…which are specified when calling persistence.nvim's setup function. You'll need to add "globals" to this list. As long as persistence.nvim emits SessionLoadPost you shouldn't need to nvim -S either.

(Not sure why they do it this way, instead of just reading sessionoptions directly, but that's neither here nor there)

otavioschwanck commented 1 year ago

So it works now? Might be convenient to write a wrapper like this to ensure the autocmd event always gets fired in the future:

vim.api.nvim_create_user_command( 
  'Mksession',
  function()
    vim.api.nvim_exec_autocmds('User', {pattern = 'SessionSavePre'})
    --[[ session save command here 
         e.g. `vim.cmd.mksession()` 
              or persistence.nvim function ]]
  end,
  {} 
)

Edit: interesting. persistence.nvim doesn't have a session save command, it just does everything automatically

Edit 2: found the issue. persistence.nvim overrides your sessionoptions on save with these:

options = { "buffers", "curdir", "tabpages", "winsize" }

…which are specified when calling persistence.nvim's setup function. You'll need to add "globals" to this list. As long as persistence.nvim emits SessionLoadPost you shouldn't need to nvim -S either.

(Not sure why they do it this way, instead of just reading sessionoptions directly, but that's neither here nor there)

im already adding globals to persistence. Not working either.

{
    "folke/persistence.nvim",
    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
      })
    end,
  }
otavioschwanck commented 1 year ago

Another thing: The buffer order is not being keep too, maybe is something with the load of barbar?

Iron-E commented 1 year ago

@otavioschwanck Just double checking that you run :doautocmd User SessionSavePre before exiting vim.

If so, can you post one of the session files that persistence.nvim is generating? Make sure to censor personally identifying information, I don't need any actual filenames, just the leading setup info.

Since the order of buffers is lost, my guess is that the global barbar session restore variable isn't being stored by persistence.nvim, in which case I'll download the plugin and try it later as well

otavioschwanck commented 1 year ago

@otavioschwanck Just double checking that you run :doautocmd User SessionSavePre before exiting vim.

If so, can you post one of the session files that persistence.nvim is generating? Make sure to censor personally identifying information, I don't need any actual filenames, just the leading setup info.

Since the order of buffers is lost, my guess is that the global barbar session restore variable isn't being stored by persistence.nvim, in which case I'll download the plugin and try it later as well

even using :doautocmd User SessionSavePre it not save.

The session file:

   cat %Users%otavio%.config%nvim.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("<sfile>:p")
let VM_mouse_mappings =  0
let HowMuch_no_mappings =  1
let VM_default_mappings =  1
let VM_persistent_registers =  0
let VM_highlight_matches = "underline"
let VM_check_mappings =  1
let VM_theme = "olive"
silent only
silent tabonly
cd ~/.config/nvim
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 lua/plugins/init.lua
argglobal
%argdel
edit lua/plugins/init.lua
argglobal
balt lua/plugins/init.lua
let s:l = 120 - ((22 * winheight(0) + 22) / 45)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 120
normal! 026|
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("<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 :
Iron-E commented 1 year ago

Looks like it's not saving the global variables. I'll open a separate issue with regards to persistence.nvim and investigate later today— in the meantime, manually running :mksession and nvim -S should work.

otavioschwanck commented 1 year ago

Looks like it's not saving the global variables. I'll open a separate issue with regards to persistence.nvim and investigate later today— in the meantime, manually running :mksession and nvim -S should work.

the session only saves CamelCase variables, another variables are being save like:

:set g:MyVariable='hello'

reset nvim

:echo g:MyVariable

image

The global variable from barbar are being saved as CamelCase?

image