Skip to content

[WIP] allow passing a custom function as a window picker #1782

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

Merged

Conversation

davidsierradz
Copy link
Contributor

Hi! According to [WIP] allow using the winbar instead of statusbar as a window picker by davidsierradz · Pull Request #1767 · nvim-tree/nvim-tree.lua, this replaces that PR.

With something like:

...
    open_file = {
      window_picker = {
        enable = true,
        custom_function = function()
          return require('window-picker').pick_window({
            selection_chars = '12345',
            use_winbar = 'always',
            filter_rules = {
              bo = {
                filetype = { 'notify', 'packer', 'qf', 'diff', 'fugitive', 'fugitiveblame' },
                buftype = { 'nofile', 'terminal', 'help' },
              },
            },
          })
        end,
      },
  },
...

Let me know what you think, thanks!

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! That is clean!

Please add :help and update as per https://github.com/nvim-tree/nvim-tree.lua/blob/master/CONTRIBUTING.md I'm happy to assist with the :help

Please provide an example so that I may test this out and we can add to the :help

If `M.window_picker.custom_function()` returns `nil` then `pick_win_id()`
will run (the or part). We don't want that. More verbose, but better.
@davidsierradz
Copy link
Contributor Author

Please add :help and update as per https://github.com/nvim-tree/nvim-tree.lua/blob/master/CONTRIBUTING.md I'm happy to assist with the :help

Please provide an example so that I may test this out and we can add to the :help

Thanks, will do!

@davidsierradz
Copy link
Contributor Author

davidsierradz commented Nov 29, 2022

This function uses vim.ui.select to pick a window (not the best example, but works):

function()
  local window_id
  local window_list = {}
  for _, win in ipairs(vim.api.nvim_list_wins()) do
    if vim.api.nvim_win_get_config(win).relative == '' then
      table.insert(window_list, win)
    end
  end
  vim.ui.select(window_list, {
    prompt = 'Select window:',
  }, function(choice)
    window_id = choice
  end)
  return window_id
end

This one uses s1n7ax/nvim-window-picker:

require('window-picker').setup()

function()
  return require('window-picker').pick_window()
end

@alex-courtis
Copy link
Member

This function uses vim.ui.select to pick a window (not the best example, but works):

Fantastic. I'm out of time and will review next weekend.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works beautifully, and allows full control for the user i.e. ability to pick the nvim-tree window itself.

Please:

  • add to :help (I'll help out with this)
  • use the s1n7ax/nvim-window-picker example in the help

@alex-courtis alex-courtis marked this pull request as ready for review December 3, 2022 04:43
Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for your contribution.

Your complete example #1782 (comment) would be a fantastic addition to the wiki Recipes

@alex-courtis alex-courtis merged commit d85b671 into nvim-tree:master Dec 16, 2022
@alex-courtis alex-courtis mentioned this pull request Dec 18, 2022
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

Successfully merging this pull request may close these issues.

2 participants