0

I've been working on a plugin that lets you customize your color scheme based on the color values you provide. I've been stuck on a bug for two days now and was wondering if anyone has run into this issue

In my setup function I declare vim.g.black_3 = black_3

generate-colors.lua:

local M = {}

M.setup function()

-- Generate colors based on setup config values up here

 vim.g.black_3 = black_3
end

return M

I reference that value in my config but it doesn't recognize it

colors-config.lua:

require("generate-colors").setup({ 
 custom_highlights = {
  SignColumn = {bg = "#333333"} -- works
  SignColumn = {bg = vim.g.black_3} -- read as empty
 }
})

I'm assuming that this is because the vim.g variables only exist after the setup function is called, I've tried returning the values from setup, and declaring vim.g variables after the setup function but no luck.

  • 1
    The variable doesn't get set until the function is called. The function doesn't get called until after its arguments have been calculated. What were you expecting? – user253751 Jun 01 '22 at 09:47
  • @user253751 Makes sense. The solution would be to define globals after setup is called. Is there any way to await a function in Lua? or ensure code gets ran after a function, or would that not even be necessary – evan-leigh Jun 01 '22 at 10:55
  • the way to run code after a function is called is to put the code after the function call... – user253751 Jun 01 '22 at 11:00
  • @user253751 sure that's what you would do In a typical program, but this is a plugin, the user should only have to call setup – evan-leigh Jun 01 '22 at 11:04
  • Have you considered setting the global variables outside of the setup function? – user253751 Jun 01 '22 at 11:10
  • @user253751 this is what I've tried, at the end of the set up function `return M.black_3`, then in my config file I require `black_3 = require("generated-colors").black_3`, and do `vim.g.black_3 = black_3`, but still doesn't work – evan-leigh Jun 01 '22 at 11:24
  • @user253751 okay I got it, the way I was trying wasn't possible it seems, declaring vim.g after setup worked – evan-leigh Jun 01 '22 at 11:48

0 Answers0