rktjmp / lush.nvim

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

Loading an extended theme on startup? #50

Closed zetashift closed 3 years ago

zetashift commented 3 years ago

Hiya, I extended a theme: https://github.com/elianiva/gruvy.nvim and the process was easy and the docs were clear, thanks a lot!

I was wondering however how I would load my spec that I extended and specify it to the colorscheme, because currently I can only apply my extensions when :Lushify'ing it manually.

This is my code (it's in Fennel but I can always specify the Lua code):

(module magic.plugin.gruvy
  {autoload {lush lush
             hsl lush.hsl}})

(local colors { :yellow       (hsl :#d8a657)
                :red_error    (hsl :#c14a4a)
                :aqua         (hsl :#89b482)
                :red          (hsl :#EA6962)
                :string_green (hsl :#A9B665)
                :tag          (hsl :#E78A4E)
                :property     (hsl :#D8A657)
                :green        (hsl :#89B482)
                :blue         (hsl :#7DAEA3)
                :gutter       (hsl :#5a524c)
              })

(local gruvy (require :lush_theme.gruvy))

(local spec ((. (lush.extends [gruvy]) :with) (fn []
  [ ( WarningMessage          { :fg colors.yellow })
    ( Error                   { :fg colors.red } )
    ( TSVariable              { :fg colors.aqua })
    ( TSFunction              { :fg colors.red } )
    ( Function                { :fg colors.red } )
    ( String                  { :fg colors.string_green } )
    ( TSConstant              { :fg colors.yellow })
    ( TSVariableBuiltin       { :fg colors.aqua } )
    ( vueTSTag                { :fg colors.tag } )
    ( cssTSProperty           { :fg colors.green } )
    ( javascriptTSProperty    { :fg colors.blue } )
    ( TSProperty              { :fg colors.property } )
    ( javascriptTSConstructor { :fg colors.blue} )
  ])))

spec
zetashift commented 3 years ago

Never mind, I figured it out, I had to create my own plugin, I thought I could do it from my init.fnl!

rktjmp commented 3 years ago

@zetashift glad you worked out a solution and that the extension stuff works!

You should be able to pass your parsed spec (what lush(fn) returns) to lush again to apply it (that's all the default .vim file does).

This looks something like

local lush = require('lush')
local spec = lush(function()
  return {
    Normal { bg = "red", fg = "yellow" }
  }
end)
lush(spec)

So for you it's probably something like (just guessing from my limited play with fennel):

(module magic.plugin.gruvy
  {autoload {lush lush
             hsl lush.hsl}})

(local colors {
  ; ...
              })

(local gruvy (require :lush_theme.gruvy))

(local spec ((. (lush.extends [gruvy]) :with) (fn []
  [ 
  ; ...
  ])))

; send parsed spec to lush for compile -> apply
(lush spec)

You might get weird behaviour from vim if you're not calling colorscheme explicitly, can't speak to any of those side effects. Probably fine?

The h lush-manual-toolchain shows a bit more detail if you wanted more control for whatever reason:

https://github.com/rktjmp/lush.nvim/blob/3232af465ed86b9a188389e52ce3c47cd811c3f3/doc/lush.txt#L587-L598

zetashift commented 3 years ago

(lush spec) was one of the things I tried, but it didn't work, now it does! I was so sure I did it too haha. Maybe I did (apply lush spec) or something else wrong, but now I would say my dotfiles are completely done!

Thank you, I really like the docs and this plugin :D

zetashift commented 3 years ago

Wait actually it doesn't totally: this is currently what I see, comments and TSInclude are wrongly colored using extends in my config. The same code works fine if it's a separate plugin:

image

zetashift commented 3 years ago

Doing:

(vim.cmd "colorscheme gruvy") makes my extends modifications not show up (so the standard gruvy theme). But (lush spec) seems to mess things up for non treesitter files: image

zetashift commented 3 years ago

Here is my code: https://github.com/zetashift/.dotfiles/blob/main/.config/nvim/fnl/magic/plugin/gruvy.fnl

EDIT: might actually be an issue here: https://github.com/Olical/magic-kit/issues/2

rktjmp commented 3 years ago

Doing (vim.cmd "colorscheme gruvy") makes my extends modifications not show up (so the standard gruvy theme).

The extends syntax won't define a "new" colorscheme, to vim, since vim only knows about them by looking for colors/<name>.vim, so your extensions don't get written "into" gruvy if that makes sense, you're constructing and applying it in-memory.

This is why you would see it working when you set via colorscheme my-gruvy-flat.

I assume if you copy-paste your plugins/gruvy.fnl into the end of init.fnl, it probably works by making sure it's the last thing to run?

Or you can maybe just remove the (vim.ex.colorscheme gruvy) line and rely on Lush to do the work when it hits your extension? The only issue I can think of with that might be anything that's watching for ColorScheme|ColorSchemePre|ColorSchemePost au commands.

Lush doesn't do much in terms of application, when you call (lush spec) it converts the lua table into viml and sends it off to vim to execute, not much space for things to go wrong, that race-ish issue you linked is probably a reasonable culprit.

rktjmp commented 3 years ago

Seems this might have been resolved upstream?

zetashift commented 3 years ago

Seems this might have been resolved upstream?

My config changed heavily and I don't use lush no more, sadly, so I'm not sure if I can check.

However even if I don't use lush anymore, it was my first foray into theming anything in NeoVim and it made things significantly easier and was nice to use, it's perfect for a starter!