SmiteshP / nvim-navbuddy

A simple popup display that provides breadcrumbs feature using LSP server
Apache License 2.0
762 stars 30 forks source link

Feature: allow to configure window options as functions #68

Open weilbith opened 1 year ago

weilbith commented 1 year ago

This adds the possibility for more dynamic window configuration. To do so, it allows some window configuration options to be a function. If so, it evaluates the function by calling it with the window number as first parameter. The output of the function is taken as the actual configuration value that is then passed to the Nui library.

In addition to this, it also makes the "relative" option of Nui configurable. The default value reflects the former fixed constant.

A possible usage of this would be a configuration that sizes and positions Navbuddy relative to the current window and with the same width as the window. Moreover this allows to easily require a minimum width of Navbuddy and much more. It does so without putting the burden to the plugin, but rather the experienced power user.

All changes are fully backwards compatible.

weilbith commented 1 year ago

An example configuration I'm using atm with this branch:

{
  window = {
    relative = 'win'
    size = function(window_number)
      local window_width = vim.api.nvim_win_get_width(window_number)
      local width = window_width > minimum_width and window_width or '100%'

      return {
        width = width,
        height = 20,
      }
    end,
    position = function(window_number)
      local window_width = vim.api.nvim_win_get_width(window_number)
      local window_column = vim.api.nvim_win_get_position(window_number)[2]
      local column = window_width > minimum_width and window_column or 0

      return {
        row = '50%',
        col = column,
      }
    end,
  },
}
SmiteshP commented 1 year ago

I see what you mean, makes sense to me. Maybe consider raising this as a feature of Nui library itself so that other plugins could also benefit from this. If its not accepted by nui, we can merge this PR here anyways.