shellRaining / hlchunk.nvim

This is the lua implementation of nvim-hlchunk, you can use this neovim plugin to highlight your indent line and the current chunk (context) your cursor stayed
MIT License
537 stars 31 forks source link

Unable to set colors using hl groups #122

Open sho-87 opened 2 months ago

sho-87 commented 2 months ago

I'm trying to set indent/chunk/etc colors using highlight groups in a colorscheme package. I noticed hlchunk creates some highlight groups, so in my package I've assigned a foreground color to them:

HLChunk1 = { fg = theme.ui.indent },
HLChunk2 = { fg = theme.ui.indent },
HLIndent1 = { fg = theme.ui.indent },
HLLineNum1 = { fg = theme.ui.indent },
HLBlank1 = { fg = theme.ui.indent },

The problem is that those groups get overridden by the defaults that get created by this plugin (or the ones I've defined are not being used at all)

Whats the correct way around this?

Would prefer to define colors using hl groups so they can be adjusted easily for different themes

shellRaining commented 1 month ago

You can override the default highlight groups of the plugin by following the settings you provide after call setup function

    M.hlchunk.setup({
        chunk = {
            enable = true,
            style = {
                { fg = "#806d9c" }, -- will translate to HLChunk1
                { fg = "#f35336" },  -- HLChunk2
            },
            textobject = "ic",
            duration = 100,
            delay = 50,
        },

        indent = {
            enable = true,
        },
        style = {
            { fg = "#806d9c" }, -- will translate to HLIndent1
            { fg = "#f35336" },  -- HLIndent2
            -- ... similar as above
         },
    })
    vim.api.nvim_set_hl(0, "HLChunk1", {fg = "#FF0000"})
sho-87 commented 1 month ago

I understand, but unless I'm missing something, that can't be set from within a colorscheme package?

shellRaining commented 1 month ago

No, it's because my plugin doesn't provide this feature... Can you give me an example config you prefer, and I'll try to implement it~

sho-87 commented 1 month ago

in terms of a feature request, I don't think anything about the config structure itself needs to change, but more what those config options are doing under the hood

what i would like would be something like this:

style = {
    { fg = "#806d9c" }, -- will translate to HLChunk1
    { fg = "#f35336" },  -- HLChunk2
},

have that set the highlight groups for HLChunk1 etc (which it currently does)

but then also allow changing those highlight group values from other places. this currently doesnt work as it seems the settings in the config overwrite those other changes

for example, my color scheme sets values for different plugin highlight groups here. I think this is somewhat typical of colorscheme packages. I would like to be able to add HLChunk1 etc to that list and have this plugin respect those values instead of just using the current default ones

so, basically allow overriding colors by setting external highlight groups instead of directly in the config

tan-wei commented 2 weeks ago

Hmm. Seems an interesting feature and useful for me at least. I use modicator.nvim, if the feature is implemented, we can make LineNr highlight group the same with modicator. However, it seems that style should be a fixed hex string (or a function which returns a hex string), so now it is impossible.