Skip to content

Commit

Permalink
feat: current indent
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Reineke <lukas.reineke@protonmail.com>
Co-authored-by: Daniel Kongsgaard <daniel@Daniels-MBP.home>
  • Loading branch information
lukas-reineke and Daniel Kongsgaard committed Oct 20, 2023
1 parent 8a7b48f commit 70bbdf3
Show file tree
Hide file tree
Showing 11 changed files with 1,160 additions and 219 deletions.
155 changes: 151 additions & 4 deletions doc/indent_blankline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ config *ibl.config*
{scope} (|ibl.config.scope|)
Configures the scope

• {current_indent} (|ibl.config.current_indent|)
Configures the current_indent

{exclude} (|ibl.config.exclude|)
Configures what is excluded from indent-blankline

Expand Down Expand Up @@ -366,9 +369,11 @@ config.scope *ibl.config.scope*

Configures the scope

The scope is *not* the current indentation level! Instead, it is the
indentation level where variables or functions are accessible. This depends
on the language you are writing.
The scope is *not* the current indentation level!
See |ibl.config.current_indent| if you want to highlight the current
indentation.
Instead, scope it is the indentation level where variables or functions
are accessible. This depends on the language you are writing.

Example: ~

Expand Down Expand Up @@ -541,6 +546,78 @@ config.scope.exclude *ibl.config.scope.exclude*
}
<

config.current_indent *ibl.config.current_indent*

Configures the current indent

The current indent *is* just the current indentation level (unlike scope).

Example: ~

In Python, using the same example as for scope, current indent will
highlight the current inner most indentation guide. With scope disabled,
this will look like this:
>python
def foo();
if True:
┋ a = "foo █ar"
┋ # ↳ cursor here
print(a)
<
If we have the same code with scope enabled, it will look like this:
>python
def foo();
┋ if True:
┋ ┋ a = "foo █ar"
┋ ┋ # ↳ cursor here
┋ print(a)
<
If you have both scope and current indent enabled, and the two overlap,
|ibl.config.scope.priority| and |ibl.config.current_indent.priority| will
determine which is displayed.

Fields: ~
*ibl.config.current_indent.enabled*
{enabled} (boolean)
Enables or disables current indent

Default: `false` ~

*ibl.config.current_indent.char*
{char} (string)
Character that gets used to display the current
indentation guide
Each character has to have a display width
of 0 or 1

Default: |ibl.config.indent.char| ~

*ibl.config.current_indent.highlight*
{highlight} (string)
Highlight group that gets applied to the current
indent

Default: |hl-IblCurrentIndent| ~

*ibl.config.current_indent.show_start*
• {show_start} (boolean)
Shows an underline on the line above the current indent

Default: `true` ~

*ibl.config.current_indent.show_end*
• {show_end} (boolean)
Shows an underline on the line of the current indent

Default: `true` ~

*ibl.config.current_indent.priority*
{priority} (number)
Virtual text priority for the current indent

Default: `1023` ~


config.exclude *ibl.config.exclude*

Configures what is excluded from indent-blankline
Expand Down Expand Up @@ -591,7 +668,6 @@ indent.whitespace *ibl.indent.whitespace*
{SPACE}
{INDENT}


hooks *ibl.hooks*

Hooks provide a way to extend the functionality of indent-blankline. Either
Expand All @@ -611,10 +687,12 @@ hooks.type *ibl.hooks.type*
Variants: ~
{ACTIVE}
• {SCOPE_ACTIVE}
• {CURRENT_INDENT_ACTIVE}
• {SKIP_LINE}
{WHITESPACE}
• {VIRTUAL_TEXT}
• {SCOPE_HIGHLIGHT}
• {CURRENT_INDENT_HIGHLIGHT}
{CLEAR}
• {HIGHLIGHT_SETUP}

Expand Down Expand Up @@ -653,6 +731,20 @@ hooks.cb.scope_active({bufnr}) *ibl.hooks.cb.scope_active()*
(boolean)


hooks.cb.current_indent_active({bufnr}) *ibl.hooks.cb.current_indent_active()*

Callback function for the |ibl.hooks.type|.CURRENT_INDENT_ACTIVE hook.

Gets called before refreshing indent-blankline for a buffer.
If the callback returns false, |ibl.config.current_indent| will be disabled.

Parameters: ~
{bufnr} (number) Buffer number

Return: ~
(boolean)


hooks.cb.skip_line({tick}, {bufnr}, {row}, {line}) *ibl.hooks.cb.skip_line()*

Callback function for the |ibl.hooks.type|.SKIP_LINE hook.
Expand Down Expand Up @@ -727,6 +819,26 @@ hooks.cb.scope_highlight({tick}, {bufnr}, {scope}, {scope_index})
(number)


*ibl.hooks.cb.current_indent_highlight()*
hooks.cb.current_indent_highlight({tick}, {bufnr}, {current_indent}, {current_indent_index})

Callback function for the |ibl.hooks.type|.CURRENT_INDENT_HIGHLIGHT hook.

Gets called for once per refresh after the current indent is determined.
The return value overwrites the index of the highlight group
defined in |ibl.config.current_indent.highlight|

Parameters: ~
{tick} (number) auto-incrementing id of the
current refresh
{bufnr} (number) Buffer number
• {current_indent} (ibl.current_indent) The current scope
• {current_indent_index} (number) Index of the highlight group

Return: ~
(number)


hooks.cb.clear({bufnr}) *ibl.hooks.cb.clear()*

Callback function for the |ibl.hooks.type|.CLEAR hook.
Expand Down Expand Up @@ -800,6 +912,35 @@ hooks.builtin.scope_highlight_from_extmark
hooks.type.SCOPE_HIGHLIGHT,
hooks.builtin.scope_highlight_from_extmark
)
<
*hooks.builtin.current_indent_highlight_from_extmark*
hooks.builtin.current_indent_highlight_from_extmark

Gets the highlight group from existing extmark highlights at the end or
beginning of the current indent.
This can be used to get a somewhat reliable sync between
"rainbow parentheses" plugins like
https://gitlab.com/HiPhish/rainbow-delimiters.nvim and indent-blankline.

Example: ~
>lua
local highlight = {
"RainbowDelimiterRed",
"RainbowDelimiterYellow",
"RainbowDelimiterBlue",
"RainbowDelimiterOrange",
"RainbowDelimiterGreen",
"RainbowDelimiterViolet",
"RainbowDelimiterCyan",
}
vim.g.rainbow_delimiters = { highlight = highlight }
require "ibl".setup { scope = { highlight = highlight } }

local hooks = require "ibl.hooks"
hooks.register(
hooks.type.CURRENT_INDENT_HIGHLIGHT,
hooks.builtin.current_indent_highlight_from_extmark
)
<
*ibl.hooks.builtin.hide_first_space_indent_level*
hooks.builtin.hide_first_space_indent_level
Expand Down Expand Up @@ -852,6 +993,12 @@ IblScope *hl-IblScope*

Default: takes the values from |hl-LineNr| when not defined ~

IblCurrentIndent *hl-IblCurrentIndent*

The default highlight group for |ibl.config.current_indent| characters.

Default: takes the values from |hl-LineNr| when not defined ~

==============================================================================
5. COMMANDS *ibl.commands*

Expand Down
49 changes: 49 additions & 0 deletions lua/ibl/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ M.default_config = {
},
},
},
current_indent = {
enabled = false,
char = nil,
show_start = true,
show_end = true,
highlight = "IblCurrentIndent",
priority = 1023,
exclude = {
filetypes = {},
},
},
exclude = {
filetypes = {
"lspinfo",
Expand Down Expand Up @@ -116,6 +127,7 @@ local validate_config = function(config)
indent = { config.indent, "table", true },
whitespace = { config.whitespace, "table", true },
scope = { config.scope, "table", true },
current_indent = { config.current_indent, "table", true },
exclude = { config.exclude, "table", true },
}, config, "ibl.config")

Expand Down Expand Up @@ -229,6 +241,43 @@ local validate_config = function(config)
end
end

if config.current_indent then
utils.validate({
enabled = { config.current_indent.enabled, "boolean", true },
char = { config.current_indent.char, { "string", "table" }, true },
show_start = { config.current_indent.show_start, "boolean", true },
show_end = { config.current_indent.show_end, "boolean", true },
highlight = { config.current_indent.highlight, { "string", "table" }, true },
priority = { config.current_indent.priority, "number", true },
exclude = { config.current_indent.exclude, "table", true },
}, config.current_indent, "ibl.config.current_indent")
if config.current_indent.char then
vim.validate {
char = {
config.current_indent.char,
validate_char,
"current_indent.char to have a display width of 0 or 1",
},
}
end
if type(config.current_indent.highlight) == "table" then
vim.validate {
tab_char = {
config.current_indent.highlight,
function(highlight)
return #highlight > 0
end,
"current_indent.highlight to be not empty",
},
}
end
if config.current_indent.exclude then
utils.validate({
filetypes = { config.current_indent.exclude.filetypes, "table", true },
}, config.current_indent.exclude, "ibl.config.current_indent.exclude")
end
end

if config.exclude then
if config.exclude then
utils.validate({
Expand Down
48 changes: 48 additions & 0 deletions lua/ibl/config.types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
---@field whitespace ibl.config.whitespace?
--- Configures the scope
---@field scope ibl.config.scope?
--- Configures the current_indent
---@field current_indent ibl.config.current_indent?
--- Configures what is excluded from indent-blankline
---@field exclude ibl.config.exclude?

Expand Down Expand Up @@ -109,6 +111,28 @@
--- </code>
---@field node_type table<string, string[]>?

---@class ibl.config.current_indent
--- Enables or disables current indent
---@field enabled boolean?
--- Character, or list of characters, that get used to display the current indent indentation guide
---
--- Each character has to have a display width of 0 or 1
---@field char string|string[]?
--- Shows an underline on the first line of the current indent
---@field show_start boolean?
--- Shows an underline on the last line of the current indent
---@field show_end boolean?
--- Highlight group, or list of highlight groups, that get applied to the current indent
---@field highlight string|string[]?
--- Virtual text priority for the current indent
---@field priority number?
--- Configures filetypes to be excluded from current indent
---@field exclude ibl.config.current_indent.exclude?

---@class ibl.config.current_indent.exclude
--- List of filetypes for which current indent is disabled
---@field filetypes string[]?

---@class ibl.config.exclude
--- List of `filetypes` for which indent-blankline is disabled
---@field filetypes string[]?
Expand All @@ -131,6 +155,8 @@
---@field whitespace ibl.config.full.whitespace: ibl.config.whitespace
--- Configures the scope
---@field scope ibl.config.full.scope: ig.config.scope
--- Configures the current_indent
---@field current_indent ibl.config.full.current_indent
--- Configures what is excluded from indent-blankline
---@field exclude ibl.config.full.exclude: ibl.config.exclude

Expand Down Expand Up @@ -225,6 +251,28 @@
--- </code>
---@field node_type table<string, string[]>

---@class ibl.config.full.current_indent
--- Enables or disables current indent
---@field enabled boolean
--- Character, or list of characters, that get used to display the current indent indentation guide
---
--- Each character has to have a display width of 0 or 1
---@field char string|string[]?
--- Shows an underline on the first line of the current indent
---@field show_start boolean
--- Shows an underline on the last line of the current indent
---@field show_end boolean
--- Highlight group, or list of highlight groups, that get applied to the current indent
---@field highlight string|string[]
--- Virtual text priority for the current indent
---@field priority number
--- Configures filetypes to be excluded from current indent
---@field exclude ibl.config.full.current_indent.exclude

---@class ibl.config.full.current_indent.exclude
--- List of filetypes for which current indent is disabled
---@field filetypes string[]

---@class ibl.config.full.exclude: ibl.config.exclude
--- List of `filetypes` for which indent-blankline is disabled
---@field filetypes string[]
Expand Down

0 comments on commit 70bbdf3

Please sign in to comment.