Combining | Merging | Extending themes #8
-
First off thanks for a great plugin! It's made configuring a personal colour scheme a pleasure. From my limited understanding, it doesn't look as if there is a way to extend a theme? For example I would like to have variants of my colour scheme (namely light and dark, but doesn't need to be) but there are quite a lot of highlight groups that are the same between them, ideally one could extend a shared base with the different groups. e.g. Base highlight groups {
ErrorMsg {bg = lightWhite, fg = red, gui = "nocombine"},
WarningMsg { bg = yellow, fg = black.darken(40), gui = "nocombine,bold,italic" },
Ignore {},
Error {bg = red, fg = lightWhite, gui = "nocombine,bold,italic"},
Todo {bg = blue, fg = lightWhite, gui = "nocombine,bold,italic"},
-- ... More common highlight groups
} Variant highlight groups (dark) {
Normal {bg = black, fg = white, gui = "nocombine"},
NormalFloat {bg = grey, gui = "nocombine"},
NormalNC {bg = lightBlack, fg = white, gui = "nocombine"},
ColorColumn {bg = black.darken(20), gui = "nocombine"},
Comment {fg = black.lighten(15), gui = "nocombine,italic"},
CursorLine {bg = black.darken(20), gui = "nocombine"},
CursorLineNr {bg = black, fg = yellow, gui = "nocombine,bold"},
-- ... More variant highlight groups
} similarly for light highlights. Being able to then combine these to produce a full theme would make maintenance and consistency easier. Something like: lush.merge(base, if background == 'dark' then dark else light end) If this is already trivial, please forgive my lack of understanding and it would be greatly appreciated if you could point me in the right direction! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 14 replies
-
TLDR: you can't do it in one step right now but I can plan to (try to) make it work. This has been something on my mind from the start https://github.com/rktjmp/lush.nvim/blob/main/TODO.md#theme-inheritance It was some time ago, pretty sure I wrote a demo implementation for that but it was on a different OS install so I think the local branch got nuked. I wasn't sure anyone would even use Lush at the time so I didn't pursue it much further. I actually think the main roadblock was how the API should look, rather than any technical limitation. You would have to import the spec (base) in the child (dark), then pass the child into lush(), but basically I thought it felt awkward to do that at the end of the spec. -- options at end
local base = require('lush_theme.burrito_base')
local spec = lush(function()
return {
Normal {...}
}
end, {inherit: base}) -- awkward when the spec is longer I think I toyed with optionally accepting options as the first argument, but I think I didn't like the complexity it added to maintaining the lush() function, which was feeling pretty overloaded. -- optional options at start
local base = require('lush_theme.burrito_base')
rush({parent: base}, function() -- sometimes options, sometimes not
return {
Normal {...}
}
end) Thinking about it now I would like something like, -- functionally spec'd
local base = require('lush_theme.burrito_base')
local spec = lush(base).extend(function()
return {
Normal {...}
}
end) You can sneak by, maybe you already know, by requiring your base spec then just accessing it in your second spec, which sort of lessens the burden (not really). local base = require('lush_theme.burrito_base')
local spec = lush(function()
return {
Normal { fg = base.Normal.fg }
}
end) Ideally you could just pass the group in via the group inheritance stuff,see doc and demo but you have discovered a bug #9 You mentioning If you, thinking out loud,
That might work for free, no guarantee though. local base = require('lush_theme.burrito_base')
local spec = lush(function()
return {
Normal {...}
}
end)
return deep_merge_a_onto_b(base, spec) |
Beta Was this translation helpful? Give feedback.
-
This would be a nice feature for my current plugin. I am now using |
Beta Was this translation helpful? Give feedback.
-
I have pushed a WIP branch that I would appreciate some feedback on. Does it let you do what you want? I think it probably solves the original post here, as well as #10 and #13. https://github.com/rktjmp/lush.nvim/compare/main..extend-spec The functionality should not change (I believe it covers all it needs to) but the external API (extends, with) might change. (The Later parents take precedence. base = lush(function
return {
Normal { ... },
Function { ... },
Search { ... }
})
extras = lush(function
return {
Normal { ... },
Comment { ... },
Function { ... },
CursorColumn { Normal },
})
dark = lush.extends(base, extras).with{function
return {
Match { Function },
CursorLine { CursorColumn },
}) Roughly results in:
You can see the basics of how to use it in the test file. lush(function
return {
B { A }
}, {extends: {parent}) or lush.extends(parent).with(function
return {
B { A }
}) or lush.extends(parent).extends(parent2).with(function
return {
B { A }
})
-- i.e:
x = lush.extends(parent)
x = x.extends(parent2)
return x.with(function
return {
B { A }
}) or lush.extends(parent, parent2).with(function
return {
B { A }
}) or parents = {p1, p2}
-- unpack list
lush.extends(unpack(parents)).with(function
return {
B { A }
}) The |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
extends.with
andmerge
now in mainline cc5ba40. https://github.com/rktjmp/lush.nvim#advanced-usage.