Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,20 @@ use {
indent = {
indent_size = 2,
padding = 1, -- extra padding on left hand side
-- indent guides
with_markers = true,
indent_marker = "│",
last_indent_marker = "└",
highlight = "NeoTreeIndentMarker",
-- expander config, needed for nesting files
with_expanders = nil, -- if nil and file nesting is enabled, will enable expanders
expander_collapsed = "",
expander_expanded = "",
expander_highlight = "NeoTreeExpander",
},
icon = {
folder_closed = "",
folder_open = "",
folder_closed = "",
folder_open = "",
folder_empty = "ﰊ",
default = "*",
},
Expand Down Expand Up @@ -136,6 +142,7 @@ use {
["q"] = "close_window",
}
},
nesting_rules = {},
filesystem = {
filtered_items = {
visible = false, -- when true, they will just be displayed differently than normal items
Expand Down Expand Up @@ -325,6 +332,10 @@ automatically change the directory without prompting. This option implies

See `:h neo-tree-commands` for details and a full listing of available arguments.

### File Nesting

See `:h neo-tree-file-nesting` for mmore details about file nesting


### Netrw Hijack

Expand Down
38 changes: 38 additions & 0 deletions doc/neo-tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Configuration ............... |neo-tree-configuration|
Git Status ................ |neo-tree-git-status|
Diagnostics ............... |neo-tree-diagnostics|
Indent markers ............ |neo-tree-indent-markers|
Expanders ................. |neo-tree-expanders|
File nesting .............. |neo-tree-file-nesting|
Highlights ................ |neo-tree-highlights|
Events .................... |neo-tree-events|
Components and Renderers .. |neo-tree-renderers|
Expand Down Expand Up @@ -612,6 +614,41 @@ To change highlight of indent markers, you need configure `NeoTreeIndentMarker`
highlight group. By default, it refers to `Normal` highlight.


EXPANDERS *neo-tree-expanders*
Is hightly recommended enable if file nesting is enabled (this is the default
behavior if `with_expanders` is nil). The config can be done inside the `indent`
component:
>
require("neo-tree").setup({
default_component_configs = {
indent = {
with_expanders = true,
expander_collapsed = "",
expander_expanded = "",
expander_highlight = "NeoTreeExpander",
},
},
})
<

FILE NESTING *neo-tree-file-nesting*

By default, file nesting is disabled since `nesting_rules` table is empty,
there is not files to apply the nesting, this can be enabled filling the
`nesting_rules` table with the following structure:
>
require("neo-tree").setup({
nesting_rules = {
["js"] = { "js.map" }
}
})
<
This will render:
>
FILENAME.js
FILENAME.js.map
<

HIGHLIGHTS *neo-tree-highlights*

The following highlight groups are defined by this plugin. If you set any of
Expand Down Expand Up @@ -643,6 +680,7 @@ NeoTreeGitUntracked File name when the git status is untracked.
NeoTreeHiddenByName Used for icons and names when `hide_by_name` is used.
NeoTreeIndentMarker The style of indentation markers (guides). By default,
the "Normal" highlight is used.
NeoTreeExpander Used for collapsed/expanded icons.
NeoTreeNormal |hl-Normal| override in Neo-tree window.
NeoTreeNormalNC |hi-NormalNC| override in Neo-tree window.
NeoTreeRootName The name of the root node.
Expand Down
14 changes: 11 additions & 3 deletions lua/neo-tree/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,21 @@ local config = {
indent = {
indent_size = 2,
padding = 1,
with_markers = false,
-- indent guides
with_markers = true,
indent_marker = "│",
last_indent_marker = "└",
highlight = "NeoTreeIndentMarker",
-- expander config, needed for nesting files
with_expanders = nil, -- if nil and file nesting is enabled, will enable expanders
expander_collapsed = "",
expander_expanded = "",
expander_highlight = "NeoTreeExpander",
},
icon = {
folder_closed = "",
folder_open = "",
folder_closed = "",
folder_open = "",
folder_empty = "ﰊ",
default = "*",
},
name = {
Expand Down Expand Up @@ -151,6 +158,7 @@ local config = {
{ "git_status" },
},
},
nesting_rules = {},
filesystem = {
window = {
mappings = {
Expand Down
15 changes: 10 additions & 5 deletions lua/neo-tree/setup/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local defaults = require("neo-tree.defaults")
local mapping_helper = require("neo-tree.setup.mapping-helper")
local events = require("neo-tree.events")
local log = require("neo-tree.log")
local file_nesting = require("neo-tree.sources.common.file-nesting")
local highlights = require("neo-tree.ui.highlights")
local manager = require("neo-tree.sources.manager")
local netrw = require("neo-tree.setup.netrw")
Expand Down Expand Up @@ -193,7 +194,6 @@ M.win_enter_event = function()
end
end


M.set_log_level = function(level)
log.set_level(level)
end
Expand Down Expand Up @@ -243,8 +243,10 @@ M.merge_config = function(config, is_auto_config)
local migrations = require("neo-tree.setup.deprecations").migrate(config)
if #migrations > 0 then
-- defer to make sure it is the last message printed
vim.defer_fn(function ()
vim.cmd("echohl WarningMsg | echo 'Some options have changed, please run `:Neotree migrations` to see the changes' | echohl NONE")
vim.defer_fn(function()
vim.cmd(
"echohl WarningMsg | echo 'Some options have changed, please run `:Neotree migrations` to see the changes' | echohl NONE"
)
end, 50)
end

Expand Down Expand Up @@ -289,13 +291,14 @@ M.merge_config = function(config, is_auto_config)
"force",
default_config.window or {},
source_config.window or {},
config.window or {})
config.window or {}
)
source_config.renderers = source_config.renderers or {}
-- if source does not specify a renderer, use the global default
for name, renderer in pairs(default_config.renderers or {}) do
if source_config.renderers[name] == nil then
local r = {}
for _, value in ipairs(renderer) do
for _, value in ipairs(renderer) do
if value[1] and source_config.components[value[1]] ~= nil then
table.insert(r, value)
end
Expand Down Expand Up @@ -331,6 +334,8 @@ M.merge_config = function(config, is_auto_config)
-- apply the users config
M.config = vim.tbl_deep_extend("force", default_config, config)

file_nesting.setup(M.config.nesting_rules)

for _, source_name in ipairs(sources) do
for name, rndr in pairs(M.config[source_name].renderers) do
M.config[source_name].renderers[name] = merge_global_components_config(rndr, M.config)
Expand Down
49 changes: 29 additions & 20 deletions lua/neo-tree/sources/common/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,31 @@ local utils = require("neo-tree.utils")
local renderer = require("neo-tree.ui.renderer")
local log = require("neo-tree.log")

---Gets the node parent folder recursively
---@param tree tree to look for nodes
---@param node node to look for folder parent
---@return node
local function get_folder_node(tree, node)
if node.type == "directory" then
return node
end
return get_folder_node(tree, tree:get_node(node:get_parent_id()))
end

local M = {}

---Add a new file or dir at the current node
---@param state table The state of the source
---@param callback function The callback to call when the command is done. Called with the parent node as the argument.
M.add = function(state, callback)
local tree = state.tree
local node = tree:get_node()
if node.type == "file" then
node = tree:get_node(node:get_parent_id())
end
local node = get_folder_node(tree, tree:get_node())

fs_actions.create_node(node:get_id(), callback)
end

M.close_all_nodes = function(state)
renderer.collapse_all_nodes(state.tree)
state.tree:get_nodes()[1]:expand()
state.tree:render()
end

Expand All @@ -32,13 +40,13 @@ M.close_node = function(state, callback)
local parent_node = tree:get_node(node:get_parent_id())
local target_node

if node.type == "directory" and node:is_expanded() then
if node:has_children() and node:is_expanded() then
target_node = node
else
target_node = parent_node
end

if target_node then
if target_node and target_node:has_children() then
target_node:collapse()
tree:render()
renderer.focus_node(state, target_node:get_id())
Expand Down Expand Up @@ -90,12 +98,7 @@ end
---@param callback function The callback to call when the command is done. Called with the parent node as the argument.
M.paste_from_clipboard = function(state, callback)
if state.clipboard then
local at_node = state.tree:get_node()
local folder = at_node:get_id()
if at_node.type == "file" then
folder = at_node:get_parent_id()
end

local folder = get_folder_node(state.tree, state.tree:get_node()):get_id()
-- Convert to list so to make it easier to pop items from the stack.
local clipboard_list = {}
for _, item in pairs(state.clipboard) do
Expand Down Expand Up @@ -177,10 +180,20 @@ local open_with_cmd = function(state, open_cmd, toggle_directory)
log.debug("Could not get node.")
return
end
if node.type == "directory" then
if toggle_directory then

local function open()
local path = node:get_id()
utils.open_file(state, path, open_cmd)
end

if utils.is_expandable(node) then
if toggle_directory and node.type == "directory" then
toggle_directory(node)
elseif node:has_children() then
if node:is_expanded() and node.type == "file" then
return open()
end

local updated = false
if node:is_expanded() then
updated = node:collapse()
Expand All @@ -191,10 +204,8 @@ local open_with_cmd = function(state, open_cmd, toggle_directory)
tree:render()
end
end
return nil
else
local path = node:get_id()
utils.open_file(state, path, open_cmd)
open()
end
end

Expand Down Expand Up @@ -248,8 +259,6 @@ M.toggle_directory = function(state)
end
if updated then
tree:render()
else
tree:render()
end
end
end
Expand Down
Loading