fix(highlite): self.<highlight_link>.<attr> 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.
This commit is contained in:
Iron-E 2020-12-13 16:07:54 -05:00
parent 2f28f199b4
commit d1dad7ee27
No known key found for this signature in database
GPG Key ID: 19B71B7B7B021D22
1 changed files with 8 additions and 4 deletions

View File

@ -161,14 +161,18 @@ end
return setmetatable(highlite, { return setmetatable(highlite, {
['__call'] = function(self, normal, highlights, terminal_ansi_colors) ['__call'] = function(self, normal, highlights, terminal_ansi_colors)
-- function to resolve function highlight groups being defined by function calls. -- 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] 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 -- lazily cache the result; next time, if it isn't a function this step will be skipped
tbl[key] = value(setmetatable({}, { 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 end
return tbl[key] return tbl[key]
end end
@ -194,7 +198,7 @@ return setmetatable(highlite, {
-- Highlight everything else. -- Highlight everything else.
for highlight_group, _ in pairs(highlights) do 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 end
-- Set the terminal highlight colors. -- Set the terminal highlight colors.