Skip to content

Commit 4f3feb4

Browse files
committed
feat: add "modified" component, re-order default config
1 parent 54b5f25 commit 4f3feb4

File tree

6 files changed

+96
-68
lines changed

6 files changed

+96
-68
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,26 @@ use {
9595
folder_empty = "",
9696
default = "*",
9797
},
98+
modified = {
99+
symbol = "[+]",
100+
highlight = "NeoTreeModified",
101+
},
98102
name = {
99103
trailing_slash = false,
100104
use_git_status_colors = true,
101105
},
102106
git_status = {
103107
symbols = {
104108
-- Change type
105-
added = "",
106-
deleted = "",
107-
modified = "",
108-
renamed = "",
109+
added = "", -- or "✚", but this is redundant info if you use git_status_colors on the name
110+
modified = "", -- or "", but this is redundant info if you use git_status_colors on the name
111+
deleted = "",-- this can only be used in the git_status source
112+
renamed = "",-- this can only be used in the git_status source
109113
-- Status type
110114
untracked = "",
111115
ignored = "",
112-
unstaged = "", --"",
113-
staged = "", --"",
116+
unstaged = "",
117+
staged = "",
114118
conflict = "",
115119
}
116120
},

lua/neo-tree/defaults.lua

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
local config = {
2-
default_source = "filesystem",
32
close_if_last_window = false, -- Close Neo-tree if it is the last window left in the tab
43
-- popup_border_style is for input and confirmation dialogs.
54
-- Configurtaion of floating window is done in the individual source sections.
65
-- "NC" is a special style that works well with NormalNC set
7-
popup_border_style = "NC", -- "double", "none", "rounded", "shadow", "single" or "solid"
8-
use_popups_for_input = true, -- If false, inputs will use vim.ui.input() instead of custom floats.
96
close_floats_on_escape_key = true,
7+
default_source = "filesystem",
108
enable_diagnostics = true,
119
enable_git_status = true,
1210
git_status_async = true,
13-
open_files_in_last_window = true, -- false = open files in top left window
14-
sort_case_insensitive = false, -- used when sorting files and directories in the tree
1511
log_level = "info", -- "trace", "debug", "info", "warn", "error", "fatal"
1612
log_to_file = false, -- true, false, "/path/to/file.log", use :NeoTreeLogs to show the file
13+
open_files_in_last_window = true, -- false = open files in top left window
14+
popup_border_style = "NC", -- "double", "none", "rounded", "shadow", "single" or "solid"
15+
sort_case_insensitive = false, -- used when sorting files and directories in the tree
16+
use_popups_for_input = true, -- If false, inputs will use vim.ui.input() instead of custom floats.
1717
--
1818
--event_handlers = {
1919
-- {
@@ -84,63 +84,31 @@ local config = {
8484
folder_empty = "",
8585
default = "*",
8686
},
87+
modified = {
88+
symbol = "[+]",
89+
highlight = "NeoTreeModified",
90+
},
8791
name = {
8892
trailing_slash = false,
8993
use_git_status_colors = true,
9094
},
9195
git_status = {
9296
symbols = {
9397
-- Change type
94-
added = "",
98+
added = "", -- NOTE: you can set any of these to an empty string to not show them
9599
deleted = "",
96100
modified = "",
97101
renamed = "",
98102
-- Status type
99103
untracked = "",
100104
ignored = "",
101-
unstaged = "", -- "",
102-
staged = "", -- "",
105+
unstaged = "",
106+
staged = "",
103107
conflict = "",
104108
},
105109
align = "right",
106110
},
107111
},
108-
window = { -- see https://github.com/MunifTanjim/nui.nvim/tree/main/lua/nui/popup for
109-
-- possible options. These can also be functions that return these options.
110-
position = "left", -- left, right, float, current
111-
width = 40, -- applies to left and right positions
112-
popup = { -- settings that apply to float position only
113-
size = {
114-
height = "80%",
115-
width = "50%",
116-
},
117-
position = "50%", -- 50% means center it
118-
-- you can also specify border here, if you want a different setting from
119-
-- the global popup_border_style.
120-
},
121-
-- Mappings for tree window. See `:h nep-tree-mappings` for a list of built-in commands.
122-
-- You can also create your own commands by providing a function instead of a string.
123-
mappings = {
124-
["<space>"] = "toggle_node",
125-
["<2-LeftMouse>"] = "open",
126-
["<cr>"] = "open",
127-
["S"] = "open_split",
128-
["s"] = "open_vsplit",
129-
["C"] = "close_node",
130-
["z"] = "close_all_nodes",
131-
["R"] = "refresh",
132-
["a"] = "add",
133-
["A"] = "add_directory",
134-
["d"] = "delete",
135-
["r"] = "rename",
136-
["y"] = "copy_to_clipboard",
137-
["x"] = "cut_to_clipboard",
138-
["p"] = "paste_from_clipboard",
139-
["c"] = "copy", -- takes text input for destination
140-
["m"] = "move", -- takes text input for destination
141-
["q"] = "close_window",
142-
},
143-
},
144112
renderers = {
145113
directory = {
146114
{ "indent" },
@@ -181,14 +149,52 @@ local config = {
181149
-- highlight = "NeoTreeSymbolicLinkTarget",
182150
-- },
183151
{ "clipboard", zindex = 10 },
184-
--{ "bufnr", zindex = 10 },
152+
{ "bufnr", zindex = 10 },
153+
{ "modified", zindex = 20, align = "right" },
154+
{ "diagnostics", errors_only = true, zindex = 20, align = "right" },
185155
{ "diagnostics", zindex = 20, align = "right" },
186156
{ "git_status", zindex = 20, align = "right" },
187157
},
188158
},
189159
},
190160
},
191161
nesting_rules = {},
162+
window = { -- see https://github.com/MunifTanjim/nui.nvim/tree/main/lua/nui/popup for
163+
-- possible options. These can also be functions that return these options.
164+
position = "left", -- left, right, float, current
165+
width = 40, -- applies to left and right positions
166+
popup = { -- settings that apply to float position only
167+
size = {
168+
height = "80%",
169+
width = "50%",
170+
},
171+
position = "50%", -- 50% means center it
172+
-- you can also specify border here, if you want a different setting from
173+
-- the global popup_border_style.
174+
},
175+
-- Mappings for tree window. See `:h nep-tree-mappings` for a list of built-in commands.
176+
-- You can also create your own commands by providing a function instead of a string.
177+
mappings = {
178+
["<space>"] = "toggle_node",
179+
["<2-LeftMouse>"] = "open",
180+
["<cr>"] = "open",
181+
["S"] = "open_split",
182+
["s"] = "open_vsplit",
183+
["C"] = "close_node",
184+
["z"] = "close_all_nodes",
185+
["R"] = "refresh",
186+
["a"] = "add",
187+
["A"] = "add_directory",
188+
["d"] = "delete",
189+
["r"] = "rename",
190+
["y"] = "copy_to_clipboard",
191+
["x"] = "cut_to_clipboard",
192+
["p"] = "paste_from_clipboard",
193+
["c"] = "copy", -- takes text input for destination
194+
["m"] = "move", -- takes text input for destination
195+
["q"] = "close_window",
196+
},
197+
},
192198
filesystem = {
193199
window = {
194200
mappings = {
@@ -224,7 +230,7 @@ local config = {
224230
},
225231
find_by_full_path_words = false, -- `false` means it only searches the tail of a path.
226232
-- `true` will change the filter into a full path
227-
-- search with space as an implicit ".*", so
233+
-- search with space as an implicit ".*", so
228234
-- `fi init`
229235
-- will match: `./sources/filesystem/init.lua
230236
--find_command = "fd", -- this is determined automatically, you probably don't need to set it

lua/neo-tree/sources/buffers/components.lua

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,4 @@ M.name = function(config, node, state)
3838
}
3939
end
4040

41-
M.bufnr = function(config, node, state)
42-
local highlight = config.highlight or highlights.BUFFER_NUMBER
43-
local bufnr = node.extra.bufnr
44-
if not bufnr then
45-
return {}
46-
end
47-
return {
48-
text = string.format(" #%s", bufnr),
49-
highlight = highlight,
50-
}
51-
end
52-
5341
return vim.tbl_deep_extend("force", common, M)

lua/neo-tree/sources/buffers/lib/items.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ M.get_open_buffers = function(state)
2929
if rootsub == state.path then
3030
local is_loaded = vim.api.nvim_buf_is_loaded(b)
3131
if is_loaded or state.show_unloaded then
32-
local bufnr = vim.api.nvim_buf_get_number(b)
33-
local is_listed = vim.fn.buflisted(bufnr)
32+
local is_listed = vim.fn.buflisted(b)
3433
if is_listed == 1 then
3534
local success, item = pcall(file_items.create_item, context, path, "file")
3635
if success then
3736
item.extra = {
38-
bufnr = bufnr,
39-
bufhandle = b,
37+
bufnr = b,
4038
is_listed = is_listed,
4139
}
4240
else

lua/neo-tree/sources/common/components.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ local log = require("neo-tree.log")
1818

1919
local M = {}
2020

21+
-- only works in the buffers component, but it's here so we don't have to defined
22+
-- multple renderers.
23+
M.bufnr = function(config, node, state)
24+
local highlight = config.highlight or highlights.BUFFER_NUMBER
25+
local bufnr = node.extra and node.extra.bufnr
26+
if not bufnr then
27+
return {}
28+
end
29+
return {
30+
text = string.format(" #%s", bufnr),
31+
highlight = highlight,
32+
}
33+
end
34+
2135
M.clipboard = function(config, node, state)
2236
local clipboard = state.clipboard or {}
2337
local clipboard_state = clipboard[node:get_id()]
@@ -241,6 +255,22 @@ M.icon = function(config, node, state)
241255
}
242256
end
243257

258+
M.modified = function(config, node, state)
259+
local success, bufnr = pcall(vim.fn.bufnr, node.path)
260+
if not success or bufnr < 0 then
261+
return {}
262+
end
263+
local success2, modified = pcall(vim.api.nvim_buf_get_option, bufnr, "modified")
264+
if success2 and modified then
265+
return {
266+
text = " " .. (config.symbol or "[+]"),
267+
highlight = config.highlight or highlights.MODIFIED,
268+
}
269+
else
270+
return {}
271+
end
272+
end
273+
244274
M.name = function(config, node, state)
245275
local highlight = config.highlight or highlights.FILE_NAME
246276
local text = node.name

lua/neo-tree/ui/highlights.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ M.GIT_RENAMED = "NeoTreeGitRenamed"
2626
M.GIT_UNTRACKED = "NeoTreeGitUntracked"
2727
M.HIDDEN_BY_NAME = "NeoTreeHiddenByName"
2828
M.INDENT_MARKER = "NeoTreeIndentMarker"
29+
M.MODIFIED = "NeoTreeModified"
2930
M.NORMAL = "NeoTreeNormal"
3031
M.NORMALNC = "NeoTreeNormalNC"
3132
M.ROOT_NAME = "NeoTreeRootName"
@@ -196,6 +197,7 @@ M.setup = function()
196197
create_highlight_group(M.ROOT_NAME, {}, nil, nil, "bold,italic")
197198
create_highlight_group(M.INDENT_MARKER, { M.DIM_TEXT })
198199
create_highlight_group(M.EXPANDER, { M.DIM_TEXT })
200+
create_highlight_group(M.MODIFIED, {}, nil, "d7d787")
199201

200202
local added = create_highlight_group(
201203
M.GIT_ADDED,

0 commit comments

Comments
 (0)