-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor!: use vim.api.nvim_set_hl() #70
base: main
Are you sure you want to change the base?
Conversation
Not sure why it's never going into I am trying to make output from nordic functions to return objects that are ready to be injected into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to touch the abstraction here. You can simply replace:
vim.highlight.create(group[1], {
guifg = group[2] or 'NONE',
guibg = group[3] or 'NONE',
gui = group[4] or 'NONE',
guisp = group[5] or 'NONE',
})
with:
vim.api.nvim_set_hl(0, group[1], {
guifg = group[2] or 'NONE',
guibg = group[3] or 'NONE',
gui = group[4] or 'NONE',
guisp = group[5] or 'NONE',
})
Ignore that comment. I clearly misread something in the docs. Stand by... |
Well, not that far off 😅 I was unaware of the naming and that the local definition = {
fg = group[2] or 'NONE',
bg = group[3] or 'NONE',
sp = group[5] or 'NONE',
}
if group[4] then
definition[group[4]] = true
end
vim.api.nvim_set_hl(0, group[1], definition)
One thing I don't know about here is |
Thanks! Will look into it tomorrow. But basically you are against changing group configurations the way I did in fidget.lua or standard.lua? Should make it easier for that very PR, but could get rid of those Thanks for looking into it! |
Nope. I just didn't understand the impact of using this function. But now that I get it this should be fairly easy to do. The fastest way is to change the tables from this:
to:
Then finally: local function load_group(list)
for _, group in ipairs(list) do
if type(group) == 'function' then
load_group(group(unpack(arguments)))
elseif type(group[1]) == 'table' then
load_group(vim.tbl_map(function(highlight)
return { highlight, group[2] }
end, group[1]))
else
vim.api.nvim_set_hl(0, group[1], group[2])
end
end
end |
FYI: I updated the description with some tasks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the changes in the following reference is the best way to solve this considering the internal API for color definitions supports tables as names.
Basically, keep things as is, but put the stylings into a separate nested table instead of a completely flat table.
There's actually an even simpler way for this, but I'm not sure how I feel about it because it involves using some black Lua magic to have a mix between a list and a map: -- This works :o
local t = { "foo", fg = "bar" }
print(t[0])
print(t.fg) Which means that technically one can do this:
for _, group in ipairs(list) do
if type(group) == 'function' then
load_group(group(unpack(arguments)))
elseif type(group[1]) == 'table' then
load_group(vim.tbl_map(function(highlight)
return { highlight, group }
end, group[1]))
else
local definition = {}
for k, v in pairs(group) do
if type(k) == 'string' then
definition[k] = v
end
end
vim.highlight.create(group[1], definition)
end
end |
I will come back to it, but most likely not in next couple of weeks unfortunately. |
Alright. Take your time :) |
Completely broken.
Edited by @andersevenrud