olimorris / persisted.nvim

💾 Simple session management for Neovim with git branching, autoloading and Telescope support
MIT License
418 stars 24 forks source link

[Bug] The cmdheight reset to 1 after SessionLoad #53

Closed adoyle-h closed 1 year ago

adoyle-h commented 1 year ago

I set vim.o.cmdheight=2 in my init.lua and the cmdheight is 2 when enter the nvim. But it will be set to 1 after open session (by SessionLoad).

Before SessionLoad, :verb set cmdheight shows,

  cmdheight=2
        Last set from Lua

After SessionLoad, :verb set cmdheight shows,

  cmdheight=1
        Last set from Lua

Notice: When a session saved two or more buffers, cmdheight will be set to 1. If a session saved only 1 buffer, the cmdheight is still be 2.

I have disabled all plugins except persisted.nvim. So I am sure this issue is related with persisted.nvim.

The cmdheight won't be set to 1 when open files directly with nvim file and nvim -o file1 file2.

My environment

nvim version: NVIM v0.8.0 Build type: Release LuaJIT 2.1.0-beta3

persisted.nvim version: commit 587b90b

My persisted.nvim options:

{
    silent = false, -- silent nvim message when sourcing session file
    use_git_branch = true, -- create session files based on the branch of the git enabled repository
    autosave = true, -- automatically save session files when exiting Neovim
}

My sessionoptions vim option: curdir,folds,tabpages,winpos

Sesssion file

For example, it is the sesssion file which saved two 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 ~/.local/share/nvim/plugins/trouble.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 README.md
badd +0 CHANGELOG.md
argglobal
%argdel
edit CHANGELOG.md
let s:save_splitbelow = &splitbelow
let s:save_splitright = &splitright
set splitbelow splitright
wincmd _ | wincmd |
split
1wincmd k
wincmd w
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
wincmd =
argglobal
balt README.md
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let &fdl = &fdl
let s:l = 3 - ((2 * winheight(0) + 9) / 18)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 3
normal! 0
wincmd w
argglobal
if bufexists(fnamemodify("README.md", ":p")) | buffer README.md | else | edit README.md | endif
if &buftype ==# 'terminal'
  silent file README.md
endif
balt CHANGELOG.md
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let &fdl = &fdl
let s:l = 1 - ((0 * winheight(0) + 9) / 18)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 1
normal! 0
wincmd w
wincmd =
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 :
olimorris commented 1 year ago

Thank you for raising. Will look into this during the week. I'll be surprised if this is plugin related as we're mostly using core Vim functionality at load.

olimorris commented 1 year ago

Can you reproduce this with a minimal.lua file? I've just tried with my config and I can't reproduce it:

Screen Shot 2023-02-26 at 21 29 41

adoyle-h commented 1 year ago

@olimorris

Notice: When a session saved two or more buffers, cmdheight will be set to 1. If a session saved only 1 buffer, the cmdheight is still be 2.

You should save session with 2 buffers (vsplit or split) to reproduce this issue.

The minimal.lua file.

vim.opt.sessionoptions = { 'curdir', 'folds', 'tabpages', 'winpos' }
vim.opt.cmdheight = 2
vim.opt.rtp:prepend('~/.local/share/nvim/plugins/persisted.nvim/')
require('persisted').setup {}

Open neovim with nvim -u ./minimal.lua.

olimorris commented 1 year ago

@tmpm697 can you raise a new issue. This is not related to this

olimorris commented 1 year ago

@adoyle-h. Struggling to reproduce this now, I've just tried with the following config and two buffers written into a session.

local root = "/tmp/persisted"

-- Set stdpaths to use root dir
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- Bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

vim.opt.sessionoptions = { 'curdir', 'folds', 'tabpages', 'winpos' }
vim.opt.cmdheight = 2

-- Install plugins
local plugins = {
  {
    "olimorris/persisted.nvim",
    config = true
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

Screenshot below:

Screen Shot 2023-02-27 at 22 56 18

Can you try with my config above?

adoyle-h commented 1 year ago

@olimorris You should use :vs or :sp to open two buffers in same screen to reproduce this issue.

You don't need plugin manager to install plugin. Just use git clone <dir> to download plugin. And add the <dir> to vim.opt.rtp.

vim.opt.sessionoptions = { 'curdir', 'folds', 'tabpages', 'winpos' }
vim.opt.cmdheight = 2
vim.opt.rtp:prepend('~/.local/share/nvim/plugins/persisted.nvim/') -- git clone directory
require('persisted').setup {}

This my record.

1

olimorris commented 1 year ago

Okay sorry. Long day yesterday. So I can recreate this bug without persisted and using native vim commands:

vim.opt.sessionoptions = { 'curdir', 'folds', 'tabpages', 'winpos' }
vim.opt.cmdheight = 2

Creating the session

Screen Shot 2023-02-28 at 08 31 41

Sourcing the session

Screen Shot 2023-02-28 at 08 34 10

Can you test the same and then I propose one of us raises an issue in Neovim core.

adoyle-h commented 1 year ago

Yes. I reproduce it with your codes. Thank you so much. @olimorris

olimorris commented 1 year ago

@adoyle-h I've now raised this https://github.com/neovim/neovim/issues/22450

adoyle-h commented 1 year ago

Emmm.... I raised it too. 😅

olimorris commented 1 year ago

Haha damn. Who's written the cleaner issue? 🤣🤣🤣

adoyle-h commented 1 year ago

I think mine is better. I test it with { 'options', 'localoptions' }, and get the same issue.