rktjmp / lush.nvim

Create Neovim themes with real-time feedback, export anywhere.
MIT License
1.45k stars 47 forks source link

Whole spec inheritance #10

Closed rktjmp closed 3 years ago

rktjmp commented 3 years ago

8 #23

Elected for no hard example in examples/ but see :h lush-extending-specs and

-- undo_tree.lua
local base = require 'lush_theme.gruv_base' 

return lush(function()
  return {
   UndoTreeHeading { fg = base.Normal.fg, bg = base.Normal.bg },
   -- note: it *should* be ok to write links here, but whether they work is 
   --       dependent on you actually including the base group in the
   --       final spec, else it ends up linking to nothing.
   UndoTreeTime { base.Comment }
  }
end)
-- gruvbox.lua
local base = require 'lush_theme.gruv_base'

specs = {base}
for _, plugin in ipairs(config.plugins) do
  -- where plugins is something like {"undo_tree", "elixir", "fzf"}
  table.insert(specs, require('lush_theme.plugins.'..plugin))
end

return lush.extends(specs).with((function() return {} end)
-- or return lush.merge(specs)
rktjmp commented 3 years ago

WIP in https://github.com/rktjmp/lush.nvim/compare/main..extend-spec, usage https://github.com/rktjmp/lush.nvim/blob/d97aa6399a53bd6781b60bce248d4d23267aa846/spec/lush_extends_spec.moon

rktjmp commented 3 years ago

Pretty major bug where

base = parse -> {
  A { bg: "a_bg" , fg: "a_fg" },
  Z { bg: "z_bg", fg: "z_fg" }
}

base_2 = parse((-> {
  A { fg: A.bg },
  B { bg: "arst", fg: "rsast" }
  X { Z, fg: "x_z_fg" }
}), {extends: {base}})

will collapse because we try to define an existing group. I think this use case is actually pretty natural to fall into.

Can get around with some code changes and

base = parse -> {
  A { bg: "a_bg" , fg: "a_fg" },
  Z { bg: "z_bg", fg: "z_fg" }
}

base_2 = parse((-> {
  A { fg: base.A.bg },
  B { bg: "arst", fg: "rsast" }
  X { Z, fg: "x_z_fg" }
}), {extends: {base}})

but it makes the API inconsistent. May disable automatic lookup in favour of always using base.Group which is less magical, for better or worse.

rktjmp commented 3 years ago

Prefer base.Group syntax in https://github.com/rktjmp/lush.nvim/commit/39ef2bf99bdb383397db4e0caad1ec0cbc232f4e

rktjmp commented 3 years ago

https://github.com/rktjmp/lush-light-dark-example

rktjmp commented 3 years ago

Example for docs

nord = require('lush_theme.nord)

lush.extend(nord).with(function()
  return {
    -- i like nord but need brighter normal text
    Normal { fg = nord.Normal.fg.li(30) },
    Comment { fg = colorblind_safe_green } -- also I cant see normal color
    MyPlug { ... } -- and I want my custom local plugin to mirror some nord settings. 
  }
end)
rktjmp commented 3 years ago

Generally needs a "bang" fn at the end to roll up all the specs.

extends(specs).with(spec), most semantic in my mind (but i wrote it so that seems obvious).

chain(specs).combine(spec), suggestion but I am not sold on it.

merge(specs).into(spec), relationship is a bit inverse "into"

lush(spec).merge_with/onto(specs) puts parents at the end which may be many loc down.

Possibly have two styles

extends(specs).with(spec) for alteration, merge(specs) auto bangs, merge to me reads as an verb not an... adverb?

Could also just allow extends(specs).with(nil) but I would almost expect that to return nothing.

rktjmp commented 3 years ago

:shipit: