ghillb / cybu.nvim

Neovim plugin that offers context when cycling buffers in the form of a customizable notification window.
MIT License
308 stars 5 forks source link

Handle unlisted buffers while Cybu window is open #19

Open sQVe opened 1 year ago

sQVe commented 1 year ago

👋🏼,

First off, I want to say thank you - I'm really loving this plugin!


In my setup, I use bufignore.nvim to unlist Git ignored buffers once they are hidden. However, I've encountered an issue with Cybu when I move through the entire list of buffers it provides. When it encounters an unlisted buffer, Cybu silently stops working, and I have to use bnext to move to another listed buffer.

This behavior can be easily replicated with the following steps:

  1. Open multiple buffers.
  2. Use vim.defer.fn to unlist one of the buffers with a delay of 1-2 seconds.
  3. Continuously cycle through the items in the Cybu window.
  4. Once it reaches the unlisted buffer, Cybu fails to go to the next buffer silently.
ghillb commented 1 year ago

👋🏼, Glad you like it, and thank you for reporting the issue.

Based on your description, I was able to reproduce the issue. Previously, there was a hard-coded filter for unlisted buffers, which activated the fallback, which per default does nothing.

I have added a new config option (https://github.com/ghillb/cybu.nvim/commit/e74c3fa74e521f2b347f9f70f7c56c5db0abec56) that allows you to turn off the filter for unlisted buffers. By setting filter = { unlisted = false } in your config, Cybu will no longer stop working when cycling through unlisted buffers. I have plans for further improvements in handling and filtering unlisted buffers, but for now, I hope this new option resolves the issue.

Steps to reproduce 1. Execute the following command. ```lua lua vim.defer_fn(function() vim.api.nvim_buf_set_option(2, 'buflisted', false) end, 1500) ``` 2. Cycle until the delisted buffer is reached
sQVe commented 1 year ago

@ghillb Yeah, that fixes the issue of Cybu not working on unlisted buffers. Sadly, this counters the reason I'm using bufignore.nvim. There is no need to unlist buffers if I'm able to cycle thorough all buffers, including unlisted ones.

One solution, that I'm guessing would be possible, is to add a fallback to the cycle command. If cycle fails to run either bnext or bprevious, or even better allow the user to supply a fallback.

ghillb commented 1 year ago

Could you please test if the fallback setting can handle your use case? I just added the possibility to grab direction (values: "next" or "prev"), and mode (values: "default", "last_used" or"auto") parameters in the fallback (https://github.com/ghillb/cybu.nvim/commit/d15cd01439423ebf676b6d807049738be38d6582). You can find the conditions on when the fallback is called here.

Example:

fallback = function(direction, mode)
  if direction == "next" then
    vim.cmd("bnext")
  else
    vim.cmd("bprev")
  end
end,
sQVe commented 1 year ago

That looks like an awesome solution. It sort of works but there seems to be a bug. I have to run cycle sometime twice for a unlisted buffer and the Cybu window gets unsynced from the visible buffer. See screenrecording:

https://user-images.githubusercontent.com/2284724/233307605-d40d503d-3f9a-4620-94c6-f079de08eb25.mp4