xiyaowong / transparent.nvim

Remove all background colors to make nvim transparent
806 stars 23 forks source link

Question: what's the point of caching the last state of transparency? #44

Closed pocco81 closed 1 year ago

pocco81 commented 1 year ago

I don't really get it. Is it supposed to be used for synchronizing transparency states? Is it to load the last stage of transparency? If it's the latter then I don't think it works that well. Because say transparency_cache has true. But then I go to open a neovim instance where transparency is not enabled at lunch, and when I run :TransparentToggle I expect to enable transparency, but since the plugin first reads the cached file, it will try to disable transparency.

Correct me if I'm wrong, but I think the logic is faulty? I had some issues with it so I rewrote M.toggle():

-- note: I also removed the initial `cache.read()` at the top of `init.lua` because I'm not using it here

function M.toggle(opt)
    opt = opt == nil and not vim.g.transparent_enabled or opt
    if opt == vim.g.transparent_enabled then return end

    vim.g.transparent_enabled = opt

    if opt then
        clear()
    else
        pcall(vim.cmd.colorscheme, vim.g.colors_name)
    end
end

Let me know if I should make a PR.

pocco81 commented 1 year ago

Ah, I just read the bottom line on the README. So this is supposed to enable transparency at startup, right?

In that case, with the logic above, this should be appended:

-- at the bottom of `setup()` at `config.lua`
if cache.read() then
    require("transparent").toggle(vim.g.transparent_enabled)
end

-- where `cache.read()` should return true or false depending on `transparent_cache`
-- at the bottom of `toggle()` at `init.lua`
cache.write()

This is better because:

  1. vim.g.transparent_enabled should ideally track exclusively the state of transparency of its running NeoVim instance, and thus avoid being affected by said caching
  2. I personally don't really care about the caching, so it'd be cool to have a setting one could tweak like caching = false
  3. And perhaps it'd be better to only save the cache at VimLeave?
xiyaowong commented 1 year ago

I'm not sure about your question as everything seems normal on my end. Could you please share your configuration for reference? tran