lukas-reineke / indent-blankline.nvim

Indent guides for Neovim
MIT License
4.07k stars 102 forks source link

allow disabling first level of scope indent #824

Open LokiNaBoki opened 8 months ago

LokiNaBoki commented 8 months ago

Problem

If you have the scope indents enabled, there is no option or hook to disable them in the first column.

As far as I can remember the show_first_indent_level option from V2 worked for both regular and scope indents. Now there is just hide_first_space_indent_level which hides only regular indents.

I made this hook to get rid of scope indents in the first column:

hooks.register(
    hooks.type.VIRTUAL_TEXT,
    function(_, _, _, virt_text)
        if virt_text[1] and virt_text[1][1] == '┃' then
            virt_text[1] = { ' ', { "@ibl.whitespace.char.1" } }
        end

        return virt_text
    end
)

but it feels really hacky. I have to hardcode the values: '┃' and { ' ', { "@ibl.whitespace.char.1" } }, instead of using indent.whitespace.INDENT and indent.whitespace.SPACE as in the built-in hook.

Expected behavior

The expected behavior is to have something like indent.whitespace enum, but for the scoped indents

Saulimedes commented 1 month ago

I stumbled upon the same issue and helped myself by defining a first highlight without colors.

local highlight = {
    "IblIndent", -- This will be invisible for the first level
    "RainbowRed",
    "RainbowYellow",
    "RainbowBlue",
    "RainbowOrange",
    "RainbowGreen",
    "RainbowViolet",
    "RainbowCyan",
}

local hooks = require "ibl.hooks"
-- create the highlight groups in the highlight setup hook, so they are reset
-- every time the colorscheme changes
hooks.register(hooks.type.HIGHLIGHT_SETUP, function()
    vim.api.nvim_set_hl(0, "IblIndent", { fg = "NONE" })
    vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" })
    vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" })
    vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" })
    vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" })
    vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" })
    vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" })
    vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" })
end)

But would have much more prefered some option like ident_level = 2.

lukas-reineke commented 1 month ago

The proper way to do this is probably to have a hook that can dynamically exclude a scope, here. https://github.com/lukas-reineke/indent-blankline.nvim/blob/65e20ab94a26d0e14acac5049b8641336819dfc7/lua/ibl/scope.lua#L78-L82

I'm open to add this if someone wants to make a PR.