toppair / reach.nvim

Buffer, mark, tabpage, colorscheme switcher for Neovim
MIT License
239 stars 7 forks source link

How to to call ReachOpen buffers with options. #14

Closed Nacho114 closed 1 year ago

Nacho114 commented 1 year ago

Hi,

I am new to lua based config, so this is probably trivial if you do know it, but how do I run ReachOpen buffers with options (i.e. custom config)?

:ReachOpen buffers, works as intended, I also added my on options as shown in the Readme (which does not change the behavior of ReachOpen buffers, which is expected from the doc).

But how do I run ReachOpen buffers with my options?

-- default
local options = {
  handle = 'auto',              -- 'bufnr' or 'dynamic' or 'auto'
  show_icons = true,
  show_current = false,         -- Include current buffer in the list
  show_modified = true,         -- Show buffer modified indicator
  modified_icon = '⬤',          -- Character to use as modified indicator
  grayout_current = true,       -- Wheter to gray out current buffer entry
  force_delete = {},            -- List of filetypes / buftypes to use
                                -- 'bdelete!' on, e.g. { 'terminal' }
  filter = nil,                 -- Function taking bufnr as parameter,
                                -- returning true or false
  sort = nil,                   -- Comparator function (bufnr, bufnr) -> bool
  terminal_char = '\\',         -- Character to use for terminal buffer handles
                                -- when options.handle is 'dynamic'
  grayout = true,               -- Gray out non matching entries

  -- A list of characters to use as handles when options.handle == 'auto'
  auto_handles = require('reach.buffers.constant').auto_handles,

  auto_exclude_handles = {'1', '2', '3'},    -- A list of characters not to use as handles when
                                -- options.handle == 'auto', e.g. { '8', '9', 'j', 'k' }
  previous = {
    enable = true,              -- Mark last used buffers with specified chars and colors
    depth = 2,                  -- Maximum number of buffers to mark
    chars = { '•' },            -- Characters to use as markers,
                                -- last one is used when depth > #chars
    groups = {                  -- Highlight groups for markers,
      'String',                 -- last one is used when depth > #groups
      'Comment',
    },
  },
  -- A map of action to key that should be used to invoke it
  actions = {
    split = '-',
    vertsplit = '|',
    tabsplit = ']',
    delete = '<Space>',
    priority = '=',
  },
}
require('reach').buffers(options)

I tried something like this:

vim.keymap.set('n', '<leader>rb', require('reach').buffers(options), {})

but I get a RHS nil error, so I guess this is not how it is intended. If you could tell me how to call it that would be great!

Love the plugin otherwise!

toppair commented 1 year ago

Hi, you need to wrap the reach.buffers(options) call in another function:

vim.keymap.set('n', '<leader>rb', function() require('reach').buffers(options) end, {})

Otherwise, it runs immediately and returns nil as expected.

Nacho114 commented 1 year ago

Ah thanks!

Could do a PR to include this example in the README (similar to the Telescope docs), let me know if you think it would be a good idea (I think it might help others who are just starting out with lua style vim config scripting).

toppair commented 1 year ago

Sure, go ahead.