EdenEast / nightfox.nvim

🦊A highly customizable theme for vim and neovim with support for lsp, treesitter and a variety of plugins.
MIT License
3.02k stars 135 forks source link

feature: Programmatically get a table of supported modules #309

Closed quantumfate closed 1 year ago

quantumfate commented 1 year ago

Is your feature request related to a problem? Please describe.

I want to write as little configuration as possible. But currently I have to maintain a list of supported modules myself.

Describe the solution you'd like

I would like to be able to require the module section in my config to return a list of supported modules. That way I can hook information based on supported modules when I have them setup.

Lets say I want to make use of the lualine module, I don't want to enable it manually in my config but rather have it enabled when a configuration file for lualine exists in my neovim config.

local modules = require("nightfox.modules")

-- now modules is a table of supported modules

for _, value ipairs(modules) do
-- update config table
end

Describe alternatives you've considered

Manually maintaining a table myself.

Additional context

No response

EdenEast commented 1 year ago

Could you explain your reasoning for why having a list of modules would be useful. A module is just a list of highlights for a particular plugin. For example, the cmp module just lists the highlight group definitions for that plugin.

All the modules are enabled by default. There is no need to manage the modules table.

As for lualine, it checks the current colorscheme (stored in vim.g.colors_name by the colorscheme command) and will try and try to load lualine.themes.xxxxx (these files for nightfox). The only thing that you would consider on startup is making sure that the colorshceme is applied before the lualine setup call. (lualine will update this anyways when the ColorScheme event is emitted`.

quantumfate commented 1 year ago

It would be useful in advanced setups. I have a global configuration table that lazy loads plugins on demand. If this plugin exposed a list of supported plugins I could safe some effort by having to define modules manually. I just check whether the modules are configured my my global variable and when they are, I add them to the nightfox config table.

M.setup = function()
  local status_ok, nightfox = pcall(reload, "nightfox")
  if not status_ok then
    Log:warn("The plugin '%s' could not be loaded.", nightfox)
    return
  end

  local supported_modules = qvim.integrations.nightfox.supported_modules
  local modules = qvim.integrations.nightfox.options.options.modules
  for module, _ in pairs(supported_modules) do
    if qvim.integrations[module] and qvim.integrations[module].active then
      modules[modules + 1] = module
    end
  end
  nightfox.setup(qvim.integrations.nightfox.options)

  vim.cmd("colorscheme nightfox")

  local lualine = qvim.integrations.lualine
  lualine.options.theme = "nightfox"

  if qvim.integrations.nightfox.on_config_done then
    qvim.integrations.nightfox.on_config_done()
  end
end