rktjmp / lush.nvim

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

Compile with vim-friendly settings #30

Closed milisims closed 3 years ago

milisims commented 3 years ago

Hi there, this is an extremely cool plugin!

Would you consider adding an option to lush.compile that forces vim-friendly settings? As far as I know, that would just be the removal of the blend option. I use this function to update my colorscheme:

function! colors#fromlush(name) abort " {{{1
  " use runtimepath?
  let cname = fnamemodify($MYVIMRC, ':h') . '/colors/' . a:name . '.vim'
  if !has('nvim') || getftime(fnamemodify($MYVIMRC, ':h') . '/lua/' . a:name . '/init.lua') <= getftime(cname)
    execute 'colorscheme' a:name
    return
  endif
  let lines = luaeval('require("lush").compile(require("' . a:name . '"), {force_clean = true})')
  " Remove incompatible with vim option -- TODO select based on nvim/vim
  call map(lines, 'substitute(v:val, ''\s\?blend\s*=\s*\S*'', "", "")')
  call writefile(lines, cname)
  execute 'colorscheme' a:name
endfunction

Evidently, it's not a big complication to add this code myself as the user, but it was a bit tricky to understand where the issue was and why my colorscheme was causing issues on loading in vim.

rktjmp commented 3 years ago

As it happens, was also asked yesterday, https://github.com/rktjmp/lush.nvim/issues/29

Lush is a neovim plugin that happens to have some vim compatibility, basically by accident.

Why I am hesitant to just throw the option in (as you say, it's not a hard code problem) is sort of two fold:

That's not to say no, just why I feel a bit uncomfortable adding it... Obviously it would be useful to people so it will probably appear in some form.

The readme definitely needs a warning about blend options right now at any rate.

milisims commented 3 years ago

Huh, sorry for missing that! I think I just searched for 'compile'.

You do make really good points about why not to include it. For me, it would have been helpful to have:

  1. a clear path for how to get the compiled lines in vimscript or lua
  2. a list of known incompatible options (i.e including a disclaimer that this may be extended without your notice)

That way you don't need to extend the API, and I would have known what I needed to do. Filtering some strings pretty programming 101, so the user should be able to understand what to do from there.

Didn't mean to close the issue, sorry!

rktjmp commented 3 years ago

Likely to just include a strip option to compile.

lush.compile(spec, {
  strip = {"gui",  "blend"}
})

That way I can pretend it isn't for Vim :eyes:

strip
drop
remove
dump
dont_include
exclude

Probably exclude. Maybe exclude_keys.

rktjmp commented 3 years ago

Fixed in aaa9a4c77330ea2a69a88d8e7950edeb01e9f359

You may still need to do some manual touch ups. compile won't include code to clear existing highlights (even though that was listed as an option, it was an error in the docs) because it relies on checking some vim-runtime settings that I don't want to pollute down to that layer.

This really only needs to be done if you're hot-reloading like :Lushify does, so it is likely not a problem if you're targeting vim.

See instructions, specifically compiles exclude_keys option.

https://github.com/rktjmp/lush.nvim/blob/3a188f13ffcd026e1c29938ff2fb1a8177b8f953/doc/lush.txt#L549-L599

https://github.com/rktjmp/lush.nvim/blob/3a188f13ffcd026e1c29938ff2fb1a8177b8f953/lua/lush.lua#L15-L31