Skip to content

Commit a02fd5d

Browse files
committed
Merge branch 'master' into filters-multi-instance
2 parents 29a72ef + 4e396b2 commit a02fd5d

17 files changed

+256
-68
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/luals-out/
22
/luals/
3+
# backup vim files
4+
*~

doc/nvim-tree-lua.txt

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
428428
highlight_diagnostics = "none",
429429
highlight_opened_files = "none",
430430
highlight_modified = "none",
431+
highlight_hidden = "none",
431432
highlight_bookmarks = "none",
432433
highlight_clipboard = "name",
433434
indent_markers = {
@@ -454,6 +455,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
454455
},
455456
git_placement = "before",
456457
modified_placement = "after",
458+
hidden_placement = "after",
457459
diagnostics_placement = "signcolumn",
458460
bookmarks_placement = "signcolumn",
459461
padding = " ",
@@ -464,6 +466,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
464466
folder_arrow = true,
465467
git = true,
466468
modified = true,
469+
hidden = false,
467470
diagnostics = true,
468471
bookmarks = true,
469472
},
@@ -472,6 +475,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
472475
symlink = "",
473476
bookmark = "󰆤",
474477
modified = "●",
478+
hidden = "󰜌",
475479
folder = {
476480
arrow_closed = "",
477481
arrow_open = "",
@@ -904,6 +908,13 @@ Requires |nvim-tree.modified.enable|
904908
Value can be `"none"`, `"icon"`, `"name"` or `"all"`
905909
Type: `string`, Default `"none"`
906910

911+
*nvim-tree.renderer.highlight_hidden*
912+
Highlight icons and/or names for hidden files (dotfiles) using the
913+
`NvimTreeHiddenFileHL` highlight group.
914+
Requires |nvim-tree.hidden.enable|
915+
Value can be `"none"`, `"icon"`, `"name"` or `"all"`
916+
Type: `string`, Default `"none"`
917+
907918
*nvim-tree.renderer.highlight_bookmarks*
908919
Highlight bookmarked using the `NvimTreeBookmarkHL` group.
909920
Value can be `"none"`, `"icon"`, `"name"` or `"all"`
@@ -942,7 +953,7 @@ Configuration options for tree indent markers.
942953
Configuration options for icons.
943954

944955
Icon order and sign column precedence:
945-
git < modified < bookmarked < diagnostics
956+
git < hidden < modified < bookmarked < diagnostics
946957

947958
*nvim-tree.renderer.icons.web_devicons*
948959
Configure optional plugin `"nvim-tree/nvim-web-devicons"`
@@ -989,6 +1000,12 @@ Icon order and sign column precedence:
9891000
or `"signcolumn"` (requires |nvim-tree.view.signcolumn| enabled).
9901001
Type: `string`, Default: `"after"`
9911002

1003+
*nvim-tree.renderer.icons.hidden_placement*
1004+
Place where the hidden (dotfile) icon will be rendered.
1005+
Can be `"after"` or `"before"` filename (after the file/folders icons)
1006+
or `"signcolumn"` (requires |nvim-tree.view.signcolumn| enabled).
1007+
Type: `string`, Default: `"after"`
1008+
9921009
*nvim-tree.renderer.icons.bookmarks_placement*
9931010
Place where the bookmarks icon will be rendered.
9941011
Can be `"after"` or `"before"` filename (after the file/folders icons)
@@ -1005,7 +1022,7 @@ Icon order and sign column precedence:
10051022

10061023
*nvim-tree.renderer.icons.show*
10071024
Configuration options for showing icon types.
1008-
Left to right order: file/folder, git, modified, diagnostics, bookmarked.
1025+
Left to right order: file/folder, git, modified, hidden, diagnostics, bookmarked.
10091026

10101027
*nvim-tree.renderer.icons.show.file*
10111028
Show an icon before the file name.
@@ -1030,6 +1047,11 @@ Icon order and sign column precedence:
10301047
Requires |modified.enable| `= true`
10311048
Type: `boolean`, Default: `true`
10321049

1050+
*nvim-tree.renderer.icons.show.hidden*
1051+
Show a hidden icon, see |renderer.icons.hidden_placement|
1052+
Requires |hidden.enable| `= true`
1053+
Type: `boolean`, Default: `true`
1054+
10331055
*nvim-tree.renderer.icons.show.diagnostics*
10341056
Show a diagnostics status icon, see |renderer.icons.diagnostics_placement|
10351057
Requires |diagnostics.enable| `= true`
@@ -1057,6 +1079,10 @@ Icon order and sign column precedence:
10571079
Icon to display for modified files.
10581080
Type: `string`, Default: `""`
10591081

1082+
*nvim-tree.renderer.icons.glyphs.hidden*
1083+
Icon to display for hidden files.
1084+
Type: `string`, Default: `"󰜌""`
1085+
10601086
*nvim-tree.renderer.icons.glyphs.folder*
10611087
Glyphs for directories.
10621088
Overridden by |nvim-tree.renderer.icons.web_devicons| if available.
@@ -2433,6 +2459,11 @@ Modified: >
24332459
NvimTreeModifiedIcon Type
24342460
NvimTreeModifiedFileHL NvimTreeModifiedIcon
24352461
NvimTreeModifiedFolderHL NvimTreeModifiedIcon
2462+
2463+
Hidden: >
2464+
NvimTreeModifiedIcon Conceal
2465+
NvimTreeModifiedFileHL NvimTreeHiddenIcon
2466+
NvimTreeModifiedFolderHL NvimTreeHiddenFileHL
24362467
<
24372468
Opened: >
24382469
NvimTreeOpenedHL Special
@@ -2853,6 +2884,7 @@ highlight group is not, hard linking as follows: >
28532884
|nvim-tree.renderer.highlight_clipboard|
28542885
|nvim-tree.renderer.highlight_diagnostics|
28552886
|nvim-tree.renderer.highlight_git|
2887+
|nvim-tree.renderer.highlight_hidden|
28562888
|nvim-tree.renderer.highlight_modified|
28572889
|nvim-tree.renderer.highlight_opened_files|
28582890
|nvim-tree.renderer.icons|
@@ -2863,8 +2895,10 @@ highlight group is not, hard linking as follows: >
28632895
|nvim-tree.renderer.icons.glyphs.default|
28642896
|nvim-tree.renderer.icons.glyphs.folder|
28652897
|nvim-tree.renderer.icons.glyphs.git|
2898+
|nvim-tree.renderer.icons.glyphs.hidden|
28662899
|nvim-tree.renderer.icons.glyphs.modified|
28672900
|nvim-tree.renderer.icons.glyphs.symlink|
2901+
|nvim-tree.renderer.icons.hidden_placement|
28682902
|nvim-tree.renderer.icons.modified_placement|
28692903
|nvim-tree.renderer.icons.padding|
28702904
|nvim-tree.renderer.icons.show|
@@ -2874,6 +2908,7 @@ highlight group is not, hard linking as follows: >
28742908
|nvim-tree.renderer.icons.show.folder|
28752909
|nvim-tree.renderer.icons.show.folder_arrow|
28762910
|nvim-tree.renderer.icons.show.git|
2911+
|nvim-tree.renderer.icons.show.hidden|
28772912
|nvim-tree.renderer.icons.show.modified|
28782913
|nvim-tree.renderer.icons.symlink_arrow|
28792914
|nvim-tree.renderer.icons.web_devicons|

lua/nvim-tree.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
403403
highlight_diagnostics = "none",
404404
highlight_opened_files = "none",
405405
highlight_modified = "none",
406+
highlight_hidden = "none",
406407
highlight_bookmarks = "none",
407408
highlight_clipboard = "name",
408409
indent_markers = {
@@ -429,6 +430,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
429430
},
430431
git_placement = "before",
431432
modified_placement = "after",
433+
hidden_placement = "after",
432434
diagnostics_placement = "signcolumn",
433435
bookmarks_placement = "signcolumn",
434436
padding = " ",
@@ -439,6 +441,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
439441
folder_arrow = true,
440442
git = true,
441443
modified = true,
444+
hidden = false,
442445
diagnostics = true,
443446
bookmarks = true,
444447
},
@@ -447,6 +450,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
447450
symlink = "",
448451
bookmark = "󰆤",
449452
modified = "",
453+
hidden = "󰜌",
450454
folder = {
451455
arrow_closed = "",
452456
arrow_open = "",
@@ -679,12 +683,14 @@ local ACCEPTED_STRINGS = {
679683
highlight_git = { "none", "icon", "name", "all" },
680684
highlight_opened_files = { "none", "icon", "name", "all" },
681685
highlight_modified = { "none", "icon", "name", "all" },
686+
highlight_hidden = { "none", "icon", "name", "all" },
682687
highlight_bookmarks = { "none", "icon", "name", "all" },
683688
highlight_diagnostics = { "none", "icon", "name", "all" },
684689
highlight_clipboard = { "none", "icon", "name", "all" },
685690
icons = {
686691
git_placement = { "before", "after", "signcolumn" },
687692
modified_placement = { "before", "after", "signcolumn" },
693+
hidden_placement = { "before", "after", "signcolumn" },
688694
diagnostics_placement = { "before", "after", "signcolumn" },
689695
bookmarks_placement = { "before", "after", "signcolumn" },
690696
},

lua/nvim-tree/api.lua

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
local lib = require "nvim-tree.lib"
2+
local core = require "nvim-tree.core"
23
local view = require "nvim-tree.view"
34
local utils = require "nvim-tree.utils"
45
local actions = require "nvim-tree.actions"
56
local appearance_diagnostics = require "nvim-tree.appearance.diagnostics"
67
local events = require "nvim-tree.events"
78
local help = require "nvim-tree.help"
89
local live_filter = require "nvim-tree.live-filter"
9-
local marks = require "nvim-tree.marks"
1010
local marks_navigation = require "nvim-tree.marks.navigation"
1111
local marks_bulk_delete = require "nvim-tree.marks.bulk-delete"
1212
local marks_bulk_trash = require "nvim-tree.marks.bulk-trash"
@@ -43,9 +43,10 @@ local Api = {
4343
diagnostics = {},
4444
}
4545

46-
--- Do nothing when setup not called.
46+
--- Print error when setup not called.
4747
--- f function to invoke
4848
---@param f function
49+
---@return fun(...) : any
4950
local function wrap(f)
5051
return function(...)
5152
if vim.g.NvimTreeSetup == 1 then
@@ -56,13 +57,13 @@ local function wrap(f)
5657
end
5758
end
5859

59-
---Inject the node as the first argument if absent.
60+
---Inject the node as the first argument if present otherwise do nothing.
6061
---@param fn function function to invoke
6162
local function wrap_node(fn)
6263
return function(node, ...)
6364
node = node or lib.get_node_at_cursor()
6465
if node then
65-
fn(node, ...)
66+
return fn(node, ...)
6667
end
6768
end
6869
end
@@ -72,10 +73,36 @@ end
7273
local function wrap_node_or_nil(fn)
7374
return function(node, ...)
7475
node = node or lib.get_node_at_cursor()
75-
fn(node, ...)
76+
return fn(node, ...)
7677
end
7778
end
7879

80+
---Inject the explorer as the first argument if present otherwise do nothing.
81+
---@param fn function function to invoke
82+
---@return fun(...) : any
83+
local function wrap_explorer(fn)
84+
return function(...)
85+
local explorer = core.get_explorer()
86+
if explorer then
87+
return fn(explorer, ...)
88+
end
89+
end
90+
end
91+
92+
---Invoke a member's method on the singleton explorer.
93+
---Print error when setup not called.
94+
---@param explorer_member string explorer member name
95+
---@param member_method string method name to invoke on member
96+
---@return fun(...) : any
97+
local function wrap_explorer_member(explorer_member, member_method)
98+
return wrap(function(...)
99+
local explorer = core.get_explorer()
100+
if explorer then
101+
return explorer[explorer_member][member_method](explorer[explorer_member], ...)
102+
end
103+
end)
104+
end
105+
79106
---@class ApiTreeOpenOpts
80107
---@field path string|nil path
81108
---@field current_window boolean|nil default false
@@ -241,13 +268,13 @@ Api.events.Event = events.Event
241268
Api.live_filter.start = wrap(live_filter.start_filtering)
242269
Api.live_filter.clear = wrap(live_filter.clear_filter)
243270

244-
Api.marks.get = wrap_node(marks.get_mark)
245-
Api.marks.list = wrap(marks.get_marks)
246-
Api.marks.toggle = wrap_node(marks.toggle_mark)
247-
Api.marks.clear = wrap(marks.clear_marks)
248-
Api.marks.bulk.delete = wrap(marks_bulk_delete.bulk_delete)
249-
Api.marks.bulk.trash = wrap(marks_bulk_trash.bulk_trash)
250-
Api.marks.bulk.move = wrap(marks_bulk_move.bulk_move)
271+
Api.marks.get = wrap_node(wrap_explorer_member("marks", "get_mark"))
272+
Api.marks.list = wrap_explorer_member("marks", "get_marks")
273+
Api.marks.toggle = wrap_node(wrap_explorer_member("marks", "toggle_mark"))
274+
Api.marks.clear = wrap_explorer_member("marks", "clear_marks")
275+
Api.marks.bulk.delete = wrap_explorer(marks_bulk_delete.bulk_delete)
276+
Api.marks.bulk.trash = wrap_explorer(marks_bulk_trash.bulk_trash)
277+
Api.marks.bulk.move = wrap_explorer(marks_bulk_move.bulk_move)
251278
Api.marks.navigate.next = wrap(marks_navigation.next)
252279
Api.marks.navigate.prev = wrap(marks_navigation.prev)
253280
Api.marks.navigate.select = wrap(marks_navigation.select)

lua/nvim-tree/appearance/init.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ M.HIGHLIGHT_GROUPS = {
7676
{ group = "NvimTreeModifiedFileHL", link = "NvimTreeModifiedIcon" },
7777
{ group = "NvimTreeModifiedFolderHL", link = "NvimTreeModifiedFileHL" },
7878

79+
-- Hidden
80+
{ group = "NvimTreeHiddenIcon", link = "Conceal" },
81+
{ group = "NvimTreeHiddenFileHL", link = "NvimTreeHiddenIcon" },
82+
{ group = "NvimTreeHiddenFolderHL", link = "NvimTreeHiddenFileHL" },
83+
7984
-- Opened
8085
{ group = "NvimTreeOpenedHL", link = "Special" },
8186

lua/nvim-tree/explorer/filters.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
local utils = require "nvim-tree.utils"
2-
local marks = require "nvim-tree.marks"
32

43
---@class Filters to handle all opts.filters and related API
54
---@field config table hydrated user opts.filters
@@ -192,8 +191,11 @@ function Filters:prepare(git_status)
192191
status.bufinfo = vim.fn.getbufinfo { buflisted = 1 }
193192
end
194193

195-
for _, node in pairs(marks.get_marks()) do
196-
status.bookmarks[node.absolute_path] = node.type
194+
local explorer = require("nvim-tree.core").get_explorer()
195+
if explorer then
196+
for _, node in pairs(explorer.marks:get_marks()) do
197+
status.bookmarks[node.absolute_path] = node.type
198+
end
197199
end
198200

199201
return status

lua/nvim-tree/explorer/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local notify = require "nvim-tree.notify"
33
local watch = require "nvim-tree.explorer.watch"
44
local explorer_node = require "nvim-tree.explorer.node"
55
local Filters = require "nvim-tree.explorer.filters"
6+
local Marks = require "nvim-tree.marks"
67

78
local M = {}
89

@@ -13,6 +14,7 @@ M.reload = require("nvim-tree.explorer.reload").reload
1314
---@field absolute_path string
1415
---@field nodes Node[]
1516
---@field open boolean
17+
---@field marks Marks
1618

1719
local Explorer = {}
1820
Explorer.__index = Explorer
@@ -37,6 +39,7 @@ function Explorer.new(path)
3739
absolute_path = path,
3840
nodes = {},
3941
open = true,
42+
marks = Marks:new(),
4043
}, Explorer)
4144
explorer.watcher = watch.create_watcher(explorer)
4245
explorer.filters = Filters:new(M.config, explorer)

lua/nvim-tree/explorer/node.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ function M.is_git_ignored(node)
128128
return node and node.git_status ~= nil and node.git_status.file == "!!"
129129
end
130130

131+
---@param node Node
132+
---@return boolean
133+
function M.is_dotfile(node)
134+
if node == nil then
135+
return false
136+
end
137+
if node.is_dot or (node.name and (node.name:sub(1, 1) == ".")) or M.is_dotfile(node.parent) then
138+
node.is_dot = true
139+
return true
140+
end
141+
return false
142+
end
143+
131144
---@param node Node
132145
function M.node_destroy(node)
133146
if not node then

0 commit comments

Comments
 (0)