plugins/indent-blankline: update options

This commit is contained in:
Gaetan Lepage 2023-10-17 10:11:13 +02:00 committed by Gaétan Lepage
parent 954706ca4d
commit 2f06f921e0
2 changed files with 340 additions and 344 deletions

View file

@ -6,259 +6,243 @@
} @ args: } @ args:
with lib; let with lib; let
helpers = import ../helpers.nix args; helpers = import ../helpers.nix args;
basePluginPath = ["plugins" "indent-blankline"];
in { in {
options.plugins.indent-blankline = { # TODO: Those warnings were introduced on 2023/10/17.
# Please, remove in early December 2023.
imports =
# Removed options
(
map
(
optionName:
mkRemovedOptionModule
(basePluginPath ++ [optionName])
''
Please use the new options.
See https://github.com/lukas-reineke/indent-blankline.nvim.
''
)
[
"charBlankline"
"charList"
"charListBlankline"
"charHighlightList"
"spaceCharBlankline"
"spaceCharHighlightList"
"spaceCharBlanklineHighlightList"
"useTreesitter"
"indentLevel"
"maxIndentIncrease"
"showFirstIndentLevel"
"showEndOfLine"
"showFoldtext"
"disableWithNolist"
"filetype"
"bufnameExclude"
"strictTabs"
"showCurrentContextStartOnCurrentLine"
"contextCharBlankline"
"contextCharListBlankline"
"charPriority"
"contextStartPriority"
"contextPatterns"
"useTreesitterScope"
"contextPatternHighlight"
"disableWarningMessage"
]
)
# New options
++ (
mapAttrsToList
(
oldName: newPath:
mkRenamedOptionModule
(basePluginPath ++ [oldName])
(basePluginPath ++ newPath)
)
{
char = ["indent" "char"];
showCurrentContext = ["scope" "enabled"];
showTrailingBlanklineIndent = ["whitespace" "removeBlanklineTrail"];
filetypeExclude = ["exclude" "filetypes"];
buftypeExclude = ["exclude" "buftypes"];
showCurrentContextStart = ["scope" "showStart"];
contextChar = ["scope" "char"];
contextCharList = ["scope" "char"];
contextHighlightList = ["scope" "highlight"];
}
);
options.plugins.indent-blankline =
helpers.extraOptionsOptions
// {
enable = mkEnableOption "indent-blankline.nvim"; enable = mkEnableOption "indent-blankline.nvim";
package = helpers.mkPackageOption "indent-blankline" pkgs.vimPlugins.indent-blankline-nvim; package = helpers.mkPackageOption "indent-blankline" pkgs.vimPlugins.indent-blankline-nvim;
char = helpers.defaultNullOpts.mkStr "" '' debounce = helpers.defaultNullOpts.mkUnsignedInt 200 ''
Specifies the character to be used as indent line. Not used if charList is not empty. Sets the amount indent-blankline debounces refreshes in milliseconds.
When set explicitly to empty string (""), no indentation character is displayed at all,
even when 'charList' is not empty. This can be useful in combination with
spaceCharHighlightList to only rely on different highlighting of different indentation
levels without needing to show a special character.
''; '';
charBlankline = helpers.defaultNullOpts.mkStr "" '' viewportBuffer = {
Specifies the character to be used as indent line for blanklines. Not used if min = helpers.defaultNullOpts.mkUnsignedInt 30 ''
charListBlankline is not empty. Minimum number of lines above and below of what is currently visible in the window for
which indentation guides will be generated.
''; '';
charList = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" '' max = helpers.defaultNullOpts.mkUnsignedInt 500 ''
Specifies a list of characters to be used as indent line for Maximum number of lines above and below of what is currently visible in the window for
each indentation level. which indentation guides will be generated.
Ignored if the value is an empty list.
''; '';
charListBlankline = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Specifies a list of characters to be used as indent line for
each indentation level on blanklines.
Ignored if the value is an empty list.
'';
charHighlightList = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Specifies the list of character highlights for each indentation level.
Ignored if the value is an empty list.
'';
spaceCharBlankline = helpers.defaultNullOpts.mkStr " " ''
Specifies the character to be used as the space value in between indent
lines when the line is blank.
'';
spaceCharHighlightList = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Specifies the list of space character highlights for each indentation
level.
Ignored if the value is an empty list.
'';
spaceCharBlanklineHighlightList = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Specifies the list of space character highlights for each indentation
level when the line is empty.
Ignored if the value is an empty list.
'';
useTreesitter =
helpers.defaultNullOpts.mkBool false
"Use treesitter to calculate indentation when possible.";
indentLevel = helpers.defaultNullOpts.mkInt 10 "Specifies the maximum indent level to display.";
maxIndentIncrease = helpers.defaultNullOpts.mkInt config.plugins.indent-blankline.indentLevel ''
The maximum indent level increase from line to line.
Set this option to 1 to make aligned trailing multiline comments not
create indentation.
'';
showFirstIndentLevel =
helpers.defaultNullOpts.mkBool true "Displays indentation in the first column.";
showTrailingBlanklineIndent = helpers.defaultNullOpts.mkBool true ''
Displays a trailing indentation guide on blank lines, to match the
indentation of surrounding code.
Turn this off if you want to use background highlighting instead of chars.
'';
showEndOfLine = helpers.defaultNullOpts.mkBool false ''
Displays the end of line character set by |listchars| instead of the
indent guide on line returns.
'';
showFoldtext = helpers.defaultNullOpts.mkBool true ''
Displays the full fold text instead of the indent guide on folded lines.
Note: there is no autocommand to subscribe to changes in folding. This
might lead to unexpected results. A possible solution for this is to
remap folding bindings to also call |IndentBlanklineRefresh|
'';
disableWithNolist = helpers.defaultNullOpts.mkBool false ''
When true, automatically turns this plugin off when |nolist| is set.
When false, setting |nolist| will keep displaying indentation guides but
removes whitespace characters set by |listchars|.
'';
filetype = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Specifies a list of |filetype| values for which this plugin is enabled.
All |filetypes| are enabled if the value is an empty list.
'';
filetypeExclude =
helpers.defaultNullOpts.mkNullable (types.listOf types.str)
''["lspinfo" "packer" "checkhealth" "help" "man" ""]'' ''
Specifies a list of |filetype| values for which this plugin is not enabled.
Ignored if the value is an empty list.
'';
buftypeExclude =
helpers.defaultNullOpts.mkNullable (types.listOf types.str)
''["terminal" "nofile" "quickfix" "prompt"]'' ''
Specifies a list of |buftype| values for which this plugin is not enabled.
Ignored if the value is an empty list.
'';
bufnameExclude = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Specifies a list of buffer names (file name with full path) for which
this plugin is not enabled.
A name can be regular expression as well.
'';
strictTabs = helpers.defaultNullOpts.mkBool false ''
When on, if there is a single tab in a line, only tabs are used to
calculate the indentation level.
When off, both spaces and tabs are used to calculate the indentation
level.
Only makes a difference if a line has a mix of tabs and spaces for
indentation.
'';
showCurrentContext = helpers.defaultNullOpts.mkBool false ''
When on, use treesitter to determine the current context. Then show the
indent character in a different highlight.
Note: Requires https://github.com/nvim-treesitter/nvim-treesitter to be
installed
Note: With this option enabled, the plugin refreshes on |CursorMoved|,
which might be slower
'';
showCurrentContextStart = helpers.defaultNullOpts.mkBool false ''
Applies the |hl-IndentBlanklineContextStart| highlight group to the first
line of the current context.
By default this will underline.
Note: Requires https://github.com/nvim-treesitter/nvim-treesitter to be
installed
Note: You need to have set |gui-colors| and it depends on your terminal
emulator if this works as expected.
If you are using kitty and tmux, take a look at this article to
make it work
http://evantravers.com/articles/2021/02/05/curly-underlines-in-kitty-tmux-neovim/
'';
showCurrentContextStartOnCurrentLine = helpers.defaultNullOpts.mkBool true ''
Shows showCurrentContextStart even when the cursor is on the same line
'';
contextChar = helpers.defaultNullOpts.mkStr config.plugins.indent-blankline.char ''
Specifies the character to be used for the current context indent line.
Not used if contextCharList is not empty.
Useful to have a greater distinction between the current context indent
line and others.
Also useful in combination with char set to empty string
(""), as this allows only the current context indent line to be shown.
'';
contextCharBlankline = helpers.defaultNullOpts.mkStr "" ''
Equivalent of charBlankline for contextChar.
'';
contextCharList = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Equivalent of charList for contextChar.
'';
contextCharListBlankline = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Equivalent of charListBlankline for contextChar.
'';
contextHighlightList = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
Specifies the list of character highlights for the current context at
each indentation level.
Ignored if the value is an empty list.
'';
charPriority = helpers.defaultNullOpts.mkInt 1 "Specifies the |extmarks| priority for chars.";
contextStartPriority =
helpers.defaultNullOpts.mkInt 10000
"Specifies the |extmarks| priority for the context start.";
contextPatterns = helpers.defaultNullOpts.mkNullable (types.listOf types.str) ''
[
"class"
"^func"
"method"
"^if"
"while"
"for"
"with"
"try"
"except"
"arguments"
"argument_list"
"object"
"dictionary"
"element"
"table"
"tuple"
"do_block"
]'' ''
Specifies a list of lua patterns that are used to match against the
treesitter |tsnode:type()| at the cursor position to find the current
context.
To learn more about how lua pattern work, see here:
https://www.lua.org/manual/5.1/manual.html#5.4.1
'';
useTreesitterScope = helpers.defaultNullOpts.mkBool false ''
Instead of using contextPatters use the current scope defined by nvim-treesitter as the
context
'';
contextPatternHighlight = helpers.defaultNullOpts.mkNullable (types.attrsOf types.str) "{}" ''
Specifies a map of patterns set in contextPatterns to highlight groups.
When the current matching context pattern is in the map, the context
will be highlighted with the corresponding highlight group.
'';
viewportBuffer = helpers.defaultNullOpts.mkInt 10 ''
Sets the buffer of extra lines before and after the current viewport that
are considered when generating indentation and the context.
'';
disableWarningMessage =
helpers.defaultNullOpts.mkBool false "Turns deprecation warning messages off.";
extraOptions = mkOption {
type = types.attrs;
default = {};
description = ''
Extra configuration options for indent-blankline without the 'indent_blankline_' prefix.
Example: To set 'indent_blankline_foobar' to 1, write
```nix
extraConfig = {
foobar = true;
}; };
```
indent = {
char = helpers.defaultNullOpts.mkNullable (with types; either str (listOf str)) "" ''
Character, or list of characters, that get used to display the indentation guide.
Each character has to have a display width of 0 or 1.
''; '';
tabChar = helpers.mkNullOrOption (with types; either str (listOf str)) ''
Character, or list of characters, that get used to display the indentation guide for tabs.
Each character has to have a display width of 0 or 1.
Default: uses `|lcs-tab|` if `|'list'|` is set, otherwise, uses
`|ibl.config.indent.char|`.
'';
highlight = helpers.mkNullOrOption (with types; either str (listOf str)) ''
Highlight group, or list of highlight groups, that get applied to the indentation guide.
Default: `|hl-IblIndent|`
'';
smartIndentCap = helpers.defaultNullOpts.mkBool true ''
Caps the number of indentation levels by looking at the surrounding code.
'';
priority = helpers.defaultNullOpts.mkUnsignedInt 1 ''
Virtual text priority for the indentation guide.
'';
};
whitespace = {
highlight = helpers.mkNullOrOption (with types; either str (listOf str)) ''
Highlight group, or list of highlight groups, that get applied to the whitespace.
Default: `|hl-IblWhitespace|`
'';
removeBlanklineTrail = helpers.defaultNullOpts.mkBool true ''
Removes trailing whitespace on blanklines.
Turn this off if you want to add background color to the whitespace highlight group.
'';
};
scope = {
enabled = helpers.defaultNullOpts.mkBool true "Enables or disables scope.";
char = helpers.mkNullOrOption (with types; either str (listOf str)) ''
Character, or list of characters, that get used to display the scope indentation guide.
Each character has to have a display width of 0 or 1.
Default: `indent.char`
'';
showStart = helpers.defaultNullOpts.mkBool true ''
Shows an underline on the first line of the scope.
'';
showEnd = helpers.defaultNullOpts.mkBool true ''
Shows an underline on the last line of the scope.
'';
showExactScope = helpers.defaultNullOpts.mkBool false ''
Shows an underline on the first line of the scope starting at the exact start of the scope
(even if this is to the right of the indent guide) and an underline on the last line of
the scope ending at the exact end of the scope.
'';
injectedLanguages = helpers.defaultNullOpts.mkBool true ''
Checks for the current scope in injected treesitter languages.
This also influences if the scope gets excluded or not.
'';
highlight = helpers.mkNullOrOption (with types; either str (listOf str)) ''
Highlight group, or list of highlight groups, that get applied to the scope.
Default: `|hl-IblScope|`
'';
priority = helpers.defaultNullOpts.mkUnsignedInt 1024 ''
Virtual text priority for the scope.
'';
include = {
nodeType = helpers.defaultNullOpts.mkNullable (with types; attrsOf (listOf str)) "{}" ''
Map of language to a list of node types which can be used as scope.
- Use `*` as the language to act as a wildcard for all languages.
- Use `*` as a node type to act as a wildcard for all node types.
'';
};
exclude = {
language = helpers.defaultNullOpts.mkNullable (with types; listOf str) "[]" ''
List of treesitter languages for which scope is disabled.
'';
nodeType =
helpers.defaultNullOpts.mkNullable
(with types; attrsOf (listOf str))
''
{
"*" = ["source_file" "program"];
lua = ["chunk"];
python = ["module"];
}
''
''
Map of language to a list of node types which should not be used as scope.
Use `*` as a wildcard for all languages.
'';
};
};
exclude = {
filetypes =
helpers.defaultNullOpts.mkNullable
(with types; listOf str)
''
[
"lspinfo"
"packer"
"checkhealth"
"help"
"man"
"gitcommit"
"TelescopePrompt"
"TelescopeResults"
"\'\'"
]
''
"List of filetypes for which indent-blankline is disabled.";
buftypes =
helpers.defaultNullOpts.mkNullable
(with types; listOf str)
''
[
"terminal"
"nofile"
"quickfix"
"prompt"
]
''
"List of buftypes for which indent-blankline is disabled.";
}; };
}; };
@ -268,49 +252,59 @@ in {
mkIf cfg.enable { mkIf cfg.enable {
extraPlugins = [cfg.package]; extraPlugins = [cfg.package];
globals = extraConfigLua = let
mapAttrs' setupOptions = with cfg;
(name: nameValuePair ("indent_blankline_" + name))
(
{ {
inherit (cfg) char; enabled = true;
char_blankline = cfg.charBlankline; inherit debounce;
char_list = cfg.charList; viewport_buffer = with viewportBuffer; {
char_list_blankline = cfg.charListBlankline; inherit
char_highlight_list = cfg.charHighlightList; min
space_char_blankline = cfg.spaceCharBlankline; max
space_char_highlight_list = cfg.spaceCharHighlightList; ;
space_char_blankline_highlight_list = cfg.spaceCharBlanklineHighlightList; };
use_treesitter = cfg.useTreesitter; indent = with indent; {
indent_level = cfg.indentLevel; inherit char;
max_indent_increase = cfg.maxIndentIncrease; tab_char = tabChar;
show_first_indent_level = cfg.showFirstIndentLevel; inherit highlight;
show_trailing_blankline_indent = cfg.showTrailingBlanklineIndent; smart_indent_cap = smartIndentCap;
show_end_of_line = cfg.showEndOfLine; inherit priority;
show_foldtext = cfg.showFoldtext; };
disable_with_nolist = cfg.disableWithNolist; whitespace = with whitespace; {
inherit (cfg) filetype; inherit highlight;
filetype_exclude = cfg.filetypeExclude; remove_blankline_trail = removeBlanklineTrail;
buftype_exclude = cfg.buftypeExclude; };
bufname_exclude = cfg.bufnameExclude; scope = with scope; {
strict_tabs = cfg.strictTabs; inherit
show_current_context = cfg.showCurrentContext; enabled
show_current_context_start = cfg.showCurrentContextStart; char
show_current_context_start_on_current_line = cfg.showCurrentContextStartOnCurrentLine; ;
context_char = cfg.contextChar; show_start = showStart;
context_char_blankline = cfg.contextCharBlankline; show_end = showEnd;
context_char_list = cfg.contextCharList; show_exact_scope = showExactScope;
context_char_list_blankline = cfg.contextCharListBlankline; injected_languages = injectedLanguages;
context_highlight_list = cfg.contextHighlightList; inherit
char_priority = cfg.charPriority; highlight
context_start_priority = cfg.contextStartPriority; priority
context_patterns = cfg.contextPatterns; ;
use_treesitter_scope = cfg.useTreesitterScope; include = with include; {
context_pattern_highlight = cfg.contextPatternHighlight; node_type = nodeType;
viewport_buffer = cfg.viewportBuffer; };
disable_warning_message = cfg.disableWarningMessage; exclude = with exclude; {
inherit language;
node_type = nodeType;
};
};
exclude = with exclude; {
inherit
filetypes
buftypes
;
};
} }
// cfg.extraOptions // cfg.extraOptions;
); in ''
require("ibl").setup(${helpers.toLuaObject setupOptions})
'';
}; };
} }

View file

@ -7,60 +7,62 @@
plugins.indent-blankline = { plugins.indent-blankline = {
enable = true; enable = true;
char = ""; debounce = 200;
charBlankline = ""; viewportBuffer = {
charList = []; min = 30;
charListBlankline = []; max = 500;
charHighlightList = []; };
spaceCharBlankline = " "; indent = {
spaceCharHighlightList = []; char = "";
spaceCharBlanklineHighlightList = []; tabChar = null;
useTreesitter = false; highlight = null;
indentLevel = 10; smartIndentCap = true;
maxIndentIncrease = 10; priority = 1;
showFirstIndentLevel = true; };
showTrailingBlanklineIndent = true; whitespace = {
showEndOfLine = false; highlight = null;
showFoldtext = true; removeBlanklineTrail = true;
disableWithNolist = false; };
filetype = []; scope = {
filetypeExclude = ["lspinfo" "packer" "checkhealth" "help" "man" ""]; enabled = true;
buftypeExclude = ["terminal" "nofile" "quickfix" "prompt"]; char = null;
bufnameExclude = []; showStart = true;
strictTabs = false; showEnd = true;
showCurrentContext = false; showExactScope = false;
showCurrentContextStart = false; injectedLanguages = true;
showCurrentContextStartOnCurrentLine = true; highlight = null;
contextChar = ""; priority = 1024;
contextCharBlankline = ""; include = {
contextCharList = []; nodeType = {};
contextCharListBlankline = []; };
contextHighlightList = []; exclude = {
charPriority = 1; language = [];
contextStartPriority = 10000; nodeType = {
contextPatterns = [ "*" = ["source_file" "program"];
"class" lua = ["chunk"];
"^func" python = ["module"];
"method" };
"^if" };
"while" };
"for" exclude = {
"with" filetypes = [
"try" "lspinfo"
"except" "packer"
"arguments" "checkhealth"
"argument_list" "help"
"object" "man"
"dictionary" "gitcommit"
"element" "TelescopePrompt"
"table" "TelescopeResults"
"tuple" "\'\'"
"do_block"
]; ];
useTreesitterScope = false; buftypes = [
contextPatternHighlight = {}; "terminal"
viewportBuffer = 10; "nofile"
disableWarningMessage = false; "quickfix"
"prompt"
];
};
}; };
}; };
} }