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

:PossessionSave closes all non-visible buffers #18

Open
mawkler opened this issue Oct 19, 2022 · 3 comments
Open

:PossessionSave closes all non-visible buffers #18

mawkler opened this issue Oct 19, 2022 · 3 comments

Comments

@mawkler
Copy link
Contributor

mawkler commented Oct 19, 2022

:PossessionSave closes any buffer that's not in a window. To reproduce, use the following config:

Click to expand
-- Ignore default config and plugins
vim.opt.runtimepath:remove(vim.fn.expand('~/.config/nvim'))
vim.opt.packpath:remove(vim.fn.expand('~/.local/share/nvim/site'))

-- Append test directory
local test_dir = vim.fn.expand('~/code-other/nvim-test-config')
vim.opt.runtimepath:append(vim.fn.expand(test_dir))
vim.opt.packpath:append(vim.fn.expand(test_dir))

-- Install packer
local install_path = test_dir .. '/pack/packer/start/packer.nvim'
local install_plugins = false

if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
  vim.cmd('!git clone https://github.com/wbthomason/packer.nvim ' .. install_path)
  vim.cmd('packadd packer.nvim')
  install_plugins = true
end

local packer = require('packer')

packer.init({
  package_root = test_dir .. '/pack',
  compile_path = test_dir .. '/plugin/packer_compiled.lua'
})

packer.startup(function()
  function Use(module)
    use(require(string.format('configs.%s', module)))
  end

  -- Packer can manage itself
  packer.use 'wbthomason/packer.nvim'


  use { 'jedrzejboczar/possession.nvim',
    requires = { 'nvim-lua/plenary.nvim' },
    config = function()
      require('possession').setup()
    end
  }

  if install_plugins then
    packer.sync()
  else
    -- load plugins at your earliest convenience
    vim.defer_fn(function()
      vim.cmd('doautocmd User LoadPlugins')
    end, 1)
  end
end)
And then run this:
> nvim -u path/to/file/above.lua foo bar baz -c ':buffers' -c ':PossessionSave test' -c ':buffers'

Here's the output of the first :buffers:

  1 %a   "foo"                          line 0
  2      "bar"                          line 0
  3      "baz"                          line 0

And here's the output of the second :buffers:

  1 %a   "foo"                          line 1

You get the same behaviour if you run :PossessionSave manually from inside Neovim.

@jedrzejboczar
Copy link
Owner

This is most likely caused by setup option plugins.delete_hidden_buffers (runs on before_save if you have buffers in your sessionoptions). You can use plugins = { delete_hidden_buffers = false } to disable this behaviour. What to do with windows/buffers depends on specific user preference, so this is configurable. See :h possession-delete-hidden-buffers for more information. If you disable it you probably want to enable :h possession-delete-buffers to delete all buffers before loading another session.

@mawkler
Copy link
Contributor Author

mawkler commented Oct 20, 2022

I see, but why does delete_hidden_buffers delete hidden buffers if I have 'buffers' set in 'sessionoptions'? The option 'buffers' states that I want to include hidden buffers. Shouldn't this :

vim.o.sessionoptions:match('buffer') and 'before_save'

instead be this:

not vim.o.sessionoptions:match('buffer') and 'before_save'

Here's what :help sessionoptions says:

Each word enables saving and restoring something:

[...]

"buffers: hidden and unloaded buffers, not just those in windows"

@jedrzejboczar
Copy link
Owner

Yeah, maybe it's confusing, it's partially due to "historic" reasons. I added this because I don't like saving hidden buffers, because I can easily have tens of "throwaway" buffers open due to jumping through the code. And these would accumulate when changing sessions, so buffers from session A would still be there in session B (and then would be saved). At that time there was no possession.delete_buffers. I still don't like storing hidden buffers due to my kind of workflow, but I assume it's essential for some people workflows (especially when someone likes using bufferline instead of tabline). Maybe it's not the best default, but I don't want to change it now, because I would also have to change the default for delete_buffers and I'd rather avoid breaking changes, when it's quite easy for anyone to just disable/enable these to their liking.

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