ghillb / cybu.nvim

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

Feature request/question: show Cybu window on any buffer switch, not just on `CybuPrev`/`CybuNext` #16

Closed nativerv closed 1 year ago

nativerv commented 1 year ago

Option to show Cybu window on <C-i>. <C-o>, Telescope jumps, as well as vanilla :bprev/:bnext etc, instead of hardcoded CybuPrev/CybuNext commands.


Can i maybe hack that behavior somehow without changing the code? I've tried the following:

vim.api.nvim_create_autocmd('BufWinEnter', {
  group = vim.api.nvim_create_augroup('nrv#cybu_show_on_buffer_switch', {}),
  callback = function()
    require('cybu').populate_state()
    require('cybu').show_cybu_win(require('cybu').get_cybu_win_pos())
  end,
})

And it sort of works, but the current file displays incorrectly: if i switch between two files multiple times like with <C-o><C-i><C-o><C-i> the highlighted file cycles bottom-up indefinitely instead of highlighting two files back and forth. Jumping to a file with Telescope, gf etc. also selects file incorrectly. And then if i open unusual buffer like help or lsp hover, the error is thrown: init.lua:357: attempt to perform arithmetic on a nil value.

ghillb commented 1 year ago

This is probably not possible with the current implementation. But it sounds like a reasonable feature, so I will try to come up with something. Unfortunately, I'm currently preoccupied with a few other things, so it can be a while.

ghillb commented 1 year ago

@nativerv I've added a few lines of code to the dev branch and enabled the capability to show Cybu on auto commands. The API for this will probably change for the final feature (expect a breaking change).

It would be cool if you could test it a bit and give some feedback :)

Example auto command:

vim.api.nvim_create_autocmd('BufWinEnter', {
  group = vim.api.nvim_create_augroup('cybu_show_on_buffer_switch', {}),
  callback = function()
    require('cybu').auto()
  end,
})

You can change the view type to rolling or paging via the following config key:

behavior = {
  mode = {
    auto = {
      view = "rolling",  -- paging
    },
  },
},

Update:

The API function changed from auto to autocmd and it is also possible now to use the show_on_autocmd config key like so:

behavior = {
  show_on_autocmd = "BufEnter",  -- can be any nvim event, default value: false
},