From d1dad7ee27e380b0251bf984b09410fbbf0cdf87 Mon Sep 17 00:00:00 2001 From: Iron-E Date: Sun, 13 Dec 2020 16:07:54 -0500 Subject: [PATCH] fix(highlite): self.. fails When using the self-referencial syntax to create new groups out of the predefined attributes of another: ```lua Foo = function(self) return {fg=self.Foo.fg, bg=self.Bar.bg} end ``` If either `Foo` or `Bar` were a highlight link, they would fail to be resolved. This is now fixed. --- lua/highlite.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/highlite.lua b/lua/highlite.lua index 3d478a3..44699fb 100644 --- a/lua/highlite.lua +++ b/lua/highlite.lua @@ -161,14 +161,18 @@ end return setmetatable(highlite, { ['__call'] = function(self, normal, highlights, terminal_ansi_colors) -- function to resolve function highlight groups being defined by function calls. - local function resolve(tbl, key) + local function resolve(tbl, key, resolve_links) local value = tbl[key] - if type(value) == 'function' then + local value_type = type(value) + if value_type == 'function' then -- lazily cache the result; next time, if it isn't a function this step will be skipped tbl[key] = value(setmetatable({}, { - ['__index'] = function(_, inner_key) return resolve(tbl, inner_key) end + ['__index'] = function(_, inner_key) return resolve(tbl, inner_key, true) end })) + elseif value_type == _TYPE_STRING and not string.find(value, '^#') and resolve_links then + return resolve(tbl, tbl[key], resolve_links) end + return tbl[key] end @@ -194,7 +198,7 @@ return setmetatable(highlite, { -- Highlight everything else. for highlight_group, _ in pairs(highlights) do - self.highlight(highlight_group, resolve(highlights, highlight_group)) + self.highlight(highlight_group, resolve(highlights, highlight_group, false)) end -- Set the terminal highlight colors.