xiyaowong / transparent.nvim

Remove all background colors to make nvim transparent
877 stars 24 forks source link

Feature: add a post hook feature #62

Closed mehalter closed 3 months ago

mehalter commented 7 months ago

I use Heirline for my statusline and tabline which refreshes the highlights on an autocommand on the colorscheme event. This means that when I use it alongside this plugin there is a race condition on when the highlights are cleared or not. It would be nice to have a configuration option to run an arbitrary function after the highlight groups change that way I can call the function to refresh my statusline colors.

Thanks so much for a great plugin!

xiyaowong commented 5 months ago

It shouldn't encounter the issue you described because transparent.nvim has already taken that scenario into consideration. transparent.nvim will execute multiple times.

mehalter commented 5 months ago

Maybe it needs to do it a few more times 😅 I'm not sure

mehalter commented 5 months ago

It's definitely hard to solve a non-deterministic delay with deterministic delays

xiyaowong commented 3 months ago

@mehalter I reviewed your described scenario, and it seems you want to clear it yourself. If that's the case, you can directly call require('transparent').clear().

mehalter commented 3 months ago

I think I see the confusion here and the reason your application of clear several times also doesn't solve the problem. I don't want the clear() function to be the last thing called. The use case is I want to make sure some things are explicitly called after clear() is finished resolving. In the case of updating colors for a statusline like Heirline I want to guarantee that the color update happens after the highlight groups are cleared. So if I have an autocommand for Heirline on ColorScheme and your plugin also is on ColorScheme, there is a race condition where Heirline might update its colors on the non-transparent highlight groups before they are cleared. This is where something like a user autocommand event comes in place or a post clear hook function comes in. Either I can add the user autocommand event to my already existing autocommand, or I can add to some post_hook function which guarantees some code happens explicitly after the colorscheme has "settled" and nothing else is changing.

Hopefully this clears up any confusion, let me know if anything doesn't make sense :D