@@ -850,117 +850,6 @@ configurations for different types of prompts.
850850- `nvimtree_bulk_trash`
851851 send all bookmarked to trash during | nvim_tree.api.marks.bulk.trash() |
852852
853- ==============================================================================
854- Decorators *nvim-tree-decorators*
855-
856- Highlighting and icons for nodes are provided by Decorators. You may provide
857- your own in addition to the builtin decorators.
858-
859- Decorators may:
860- - Add icons
861- - Set highlight group for the name or icons
862- - Override node icon
863-
864- Create a `nvim_tree.api.decorator.UserDecorator` class and register it with
865- precedence via | nvim_tree.config.renderer | {decorators}
866-
867- See | nvim-tree-decorator-example |
868-
869- ==============================================================================
870- Decorators: Example *nvim-tree-decorator-example*
871-
872- A decorator class for nodes named "example", overridind all builtin decorators
873- except for Cut.
874-
875- - Highlights node name with `IncSearch `
876- - Creates two icons `" 1" ` and `" 2" ` placed after the node name, highlighted with
877- `DiffAdd ` and `DiffText `
878- - Replaces the node icon with `" N" ` , highlighted with `Error `
879-
880- Create a class file `~/.config/nvim/lua/my-decorator.lua `
881-
882- Require and register it during | nvim-tree-setup | :
883- >lua
884- local MyDecorator = require("my-decorator")
885-
886- require("nvim-tree").setup({
887- renderer = {
888- decorators = {
889- "Git",
890- "Open",
891- "Hidden",
892- "Modified",
893- "Bookmark",
894- "Diagnostics",
895- "Copied",
896- MyDecorator,
897- "Cut",
898- },
899- },
900- })
901- <
902- Contents of `my- decorator.lua ` :
903- >lua
904- ---@class (exact) MyDecorator: nvim_tree.api.Decorator
905- ---@field private my_icon1 nvim_tree.api.highlighted_string
906- ---@field private my_icon2 nvim_tree.api.highlighted_string
907- ---@field private my_icon_node nvim_tree.api.highlighted_string
908- ---@field private my_highlight_group string
909- local MyDecorator = require("nvim-tree.api").Decorator:extend()
910-
911- ---Mandatory constructor :new() will be called once per tree render, with no arguments.
912- function MyDecorator:new()
913- self.enabled = true
914- self.highlight_range = "name"
915- self.icon_placement = "after"
916-
917- -- create your icons and highlights once, applied to every node
918- self.my_icon1 = { str = "1", hl = { "DiffAdd" } }
919- self.my_icon2 = { str = "2", hl = { "DiffText" } }
920- self.my_icon_node = { str = "N", hl = { "Error" } }
921- self.my_highlight_group = "IncSearch"
922-
923- -- Define the icon signs only once
924- -- Only needed if you are using icon_placement = "signcolumn"
925- -- self:define_sign(self.my_icon1)
926- -- self:define_sign(self.my_icon2)
927- end
928-
929- ---Override node icon
930- ---@param node nvim_tree.api.Node
931- ---@return nvim_tree.api.highlighted_string? icon_node
932- function MyDecorator:icon_node(node)
933- if node.name == "example" then
934- return self.my_icon_node
935- else
936- return nil
937- end
938- end
939-
940- ---Return two icons for DecoratorIconPlacement "after"
941- ---@param node nvim_tree.api.Node
942- ---@return nvim_tree.api.highlighted_string[]? icons
943- function MyDecorator:icons(node)
944- if node.name == "example" then
945- return { self.my_icon1, self.my_icon2, }
946- else
947- return nil
948- end
949- end
950-
951- ---Exactly one highlight group for DecoratorHighlightRange "name"
952- ---@param node nvim_tree.api.Node
953- ---@return string? highlight_group
954- function MyDecorator:highlight_group(node)
955- if node.name == "example" then
956- return self.my_highlight_group
957- else
958- return nil
959- end
960- end
961-
962- return MyDecorator
963- <
964853==============================================================================
965854OS Specific Restrictions *nvim-tree-os-specific*
966855
@@ -3273,12 +3162,14 @@ Class:nop({...}) *nvim_tree.Class:nop()*
32733162Class: Decorator *nvim-tree-class-decorator*
32743163
32753164Highlighting and icons for nodes are provided by Decorators, see
3276- | nvim-tree-icons-highlighting | for an overview. You may provide your own in
3277- addition to the builtin decorators.
3165+ | nvim-tree-icons-highlighting | for an overview.
32783166
32793167Decorators are rendered in | nvim_tree.config.renderer | {decorators} order of
32803168precedence, with later decorators applying additively over earlier.
32813169
3170+ You may provide your own in addition to the builtin decorators, see
3171+ | nvim-tree-class-decorator-example | .
3172+
32823173Decorators may:
32833174• Add icons
32843175• Set a highlight group name for the name or icons
@@ -3387,4 +3278,102 @@ Decorator:icons({node}) *nvim_tree.api.Decorator:icons()*
33873278 is `" signcolumn" `
33883279
33893280
3281+ ==============================================================================
3282+ Class: Decorator: example *nvim-tree-class-decorator-example*
3283+
3284+ A decorator class for nodes named "example", overriding all builtin decorators
3285+ except for Cut.
3286+ • Highlights node name with `IncSearch `
3287+ • Creates two icons `" 1" ` and `" 2" ` placed after the node name, highlighted
3288+ with `DiffAdd ` and `DiffText `
3289+ • Replaces the node icon with `" N" ` , highlighted with `Error `
3290+
3291+ Create a class file `~/.config/nvim/lua/my-decorator.lua `
3292+
3293+ Require and register it during | nvim-tree-setup | : >lua
3294+
3295+ local MyDecorator = require("my-decorator")
3296+
3297+ require("nvim-tree").setup({
3298+ renderer = {
3299+ decorators = {
3300+ "Git",
3301+ "Open",
3302+ "Hidden",
3303+ "Modified",
3304+ "Bookmark",
3305+ "Diagnostics",
3306+ "Copied",
3307+ MyDecorator,
3308+ "Cut",
3309+ },
3310+ },
3311+ })
3312+ <
3313+
3314+ Contents of `my- decorator.lua ` : >lua
3315+
3316+ ---@class (exact) MyDecorator: nvim_tree.api.Decorator
3317+ ---@field private my_icon1 nvim_tree.api.highlighted_string
3318+ ---@field private my_icon2 nvim_tree.api.highlighted_string
3319+ ---@field private my_icon_node nvim_tree.api.highlighted_string
3320+ ---@field private my_highlight_group string
3321+ local MyDecorator = require("nvim-tree.api").Decorator:extend()
3322+
3323+ ---Mandatory constructor :new() will be called once per tree render, with no arguments.
3324+ function MyDecorator:new()
3325+ self.enabled = true
3326+ self.highlight_range = "name"
3327+ self.icon_placement = "after"
3328+
3329+ -- create your icons and highlights once, applied to every node
3330+ self.my_icon1 = { str = "1", hl = { "DiffAdd" } }
3331+ self.my_icon2 = { str = "2", hl = { "DiffText" } }
3332+ self.my_icon_node = { str = "N", hl = { "Error" } }
3333+ self.my_highlight_group = "IncSearch"
3334+
3335+ -- Define the icon signs only once
3336+ -- Only needed if you are using icon_placement = "signcolumn"
3337+ -- self:define_sign(self.my_icon1)
3338+ -- self:define_sign(self.my_icon2)
3339+ end
3340+
3341+ ---Override node icon
3342+ ---@param node nvim_tree.api.Node
3343+ ---@return nvim_tree.api.highlighted_string? icon_node
3344+ function MyDecorator:icon_node(node)
3345+ if node.name == "example" then
3346+ return self.my_icon_node
3347+ else
3348+ return nil
3349+ end
3350+ end
3351+
3352+ ---Return two icons for DecoratorIconPlacement "after"
3353+ ---@param node nvim_tree.api.Node
3354+ ---@return nvim_tree.api.highlighted_string[]? icons
3355+ function MyDecorator:icons(node)
3356+ if node.name == "example" then
3357+ return { self.my_icon1, self.my_icon2, }
3358+ else
3359+ return nil
3360+ end
3361+ end
3362+
3363+ ---Exactly one highlight group for DecoratorHighlightRange "name"
3364+ ---@param node nvim_tree.api.Node
3365+ ---@return string? highlight_group
3366+ function MyDecorator:highlight_group(node)
3367+ if node.name == "example" then
3368+ return self.my_highlight_group
3369+ else
3370+ return nil
3371+ end
3372+ end
3373+
3374+ return MyDecorator
3375+ <
3376+
3377+
3378+
33903379 vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl:
0 commit comments