From 89bf2d660b6696b7548214e22f74d343397c9d4e Mon Sep 17 00:00:00 2001 From: traxys Date: Wed, 1 Feb 2023 17:11:30 +0100 Subject: [PATCH] indent-blankline: init plugin (#161) --- plugins/default.nix | 1 + plugins/utils/indent-blankline.nix | 297 +++++++++++++++++++++++++++++ 2 files changed, 298 insertions(+) create mode 100644 plugins/utils/indent-blankline.nix diff --git a/plugins/default.nix b/plugins/default.nix index bd8ea096..2db1547b 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -55,6 +55,7 @@ ./utils/endwise.nix ./utils/floaterm.nix ./utils/goyo.nix + ./utils/indent-blankline.nix ./utils/intellitab.nix ./utils/mark-radar.nix ./utils/notify.nix diff --git a/plugins/utils/indent-blankline.nix b/plugins/utils/indent-blankline.nix new file mode 100644 index 00000000..63353b6b --- /dev/null +++ b/plugins/utils/indent-blankline.nix @@ -0,0 +1,297 @@ +{ lib +, pkgs +, config +, ... +} @ args: +with lib; let + helpers = import ../helpers.nix args; +in +{ + options.plugins.indent-blankline = { + enable = helpers.defaultNullOpts.mkBool false "Enable indent-blankline.nvim"; + + package = helpers.mkPackageOption "indent-blankline" pkgs.vimPlugins.indent-blankline-nvim; + + char = helpers.defaultNullOpts.mkStr "│" '' + Specifies the character to be used as indent line. Not used if charList is not empty. + + 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 "" '' + Specifies the character to be used as indent line for blanklines. Not used if + charListBlankline is not empty. + ''; + + charList = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" '' + Specifies a list of characters to be used as indent line for + each indentation level. + 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."; + }; + + config = + let + cfg = config.plugins.indent-blankline; + in + mkIf cfg.enable { + extraPlugins = [ cfg.package ]; + + globals = { + indent_blankline_char = cfg.char; + indent_blankline_char_blankline = cfg.charBlankline; + indent_blankline_char_list = cfg.charList; + indent_blankline_char_list_blankline = cfg.charListBlankline; + indent_blankline_char_highlight_list = cfg.charHighlightList; + indent_blankline_space_char_blankline = cfg.spaceCharBlankline; + indent_blankline_space_char_highlight_list = cfg.spaceCharHighlightList; + indent_blankline_space_char_blankline_highlight_list = cfg.spaceCharBlanklineHighlightList; + indent_blankline_use_treesitter = cfg.useTreesitter; + indent_blankline_indent_level = cfg.indentLevel; + indent_blankline_max_indent_increase = cfg.maxIndentIncrease; + indent_blankline_show_first_indent_level = cfg.showFirstIndentLevel; + indent_blankline_show_trailing_blankline_indent = cfg.showTrailingBlanklineIndent; + indent_blankline_show_end_of_line = cfg.showEndOfLine; + indent_blankline_show_foldtext = cfg.showFoldtext; + indent_blankline_disable_with_nolist = cfg.disableWithNolist; + indent_blankline_filetype = cfg.filetype; + indent_blankline_filetype_exclude = cfg.filetypeExclude; + indent_blankline_buftype_exclude = cfg.buftypeExclude; + indent_blankline_bufname_exclude = cfg.bufnameExclude; + indent_blankline_strict_tabs = cfg.strictTabs; + indent_blankline_show_current_context = cfg.showCurrentContext; + indent_blankline_show_current_context_start = cfg.showCurrentContextStart; + indent_blankline_show_current_context_start_on_current_line = cfg.showCurrentContextStartOnCurrentLine; + indent_blankline_context_char = cfg.contextChar; + indent_blankline_context_char_blankline = cfg.contextCharBlankline; + indent_blankline_context_char_list = cfg.contextCharList; + indent_blankline_context_char_list_blankline = cfg.contextCharListBlankline; + indent_blankline_context_highlight_list = cfg.contextHighlightList; + indent_blankline_char_priority = cfg.charPriority; + indent_blankline_context_start_priority = cfg.contextStartPriority; + indent_blankline_context_patterns = cfg.contextPatterns; + indent_blankline_use_treesitter_scope = cfg.useTreesitterScope; + indent_blankline_context_pattern_highlight = cfg.contextPatternHighlight; + indent_blankline_viewport_buffer = cfg.viewportBuffer; + indent_blankline_disable_warning_message = cfg.disableWarningMessage; + }; + }; +}