summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/core/nvimtree.lua
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2021-08-25 23:27:45 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2021-08-25 23:27:45 +0200
commitf93bad12f1b4feeeee007ceab4a350eb1aa26c1e (patch)
tree15b9edf259fc93da70a599dec47de3cfea551a95 /.config/nvim/lua/core/nvimtree.lua
parentf52dce93777c41671217ced2894c28d6da9114a0 (diff)
Updates from lvim, remove legacy
Diffstat (limited to '.config/nvim/lua/core/nvimtree.lua')
-rw-r--r--.config/nvim/lua/core/nvimtree.lua95
1 files changed, 41 insertions, 54 deletions
diff --git a/.config/nvim/lua/core/nvimtree.lua b/.config/nvim/lua/core/nvimtree.lua
index 376ae56..c640583 100644
--- a/.config/nvim/lua/core/nvimtree.lua
+++ b/.config/nvim/lua/core/nvimtree.lua
@@ -1,8 +1,10 @@
local M = {}
local Log = require "core.log"
---
-M.config = function()
+
+function M.config()
options.builtin.nvimtree = {
+ active = true,
+ on_config_done = nil,
side = "left",
width = 30,
show_icons = {
@@ -46,8 +48,8 @@ M.config = function()
},
}
end
---
-M.setup = function()
+
+function M.setup()
local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config")
if not status_ok then
Log:get_default().error "Failed to load nvim-tree.config"
@@ -59,6 +61,12 @@ M.setup = function()
g["nvim_tree_" .. opt] = val
end
+ -- Implicitly update nvim-tree when project module is active
+ if options.builtin.project.active then
+ vim.g.nvim_tree_update_cwd = 1
+ vim.g.nvim_tree_respect_buf_cwd = 1
+ end
+
local tree_cb = nvim_tree_config.nvim_tree_callback
if not g.nvim_tree_bindings then
@@ -66,67 +74,46 @@ M.setup = function()
{ key = { "l", "<CR>", "o" }, cb = tree_cb "edit" },
{ key = "h", cb = tree_cb "close_node" },
{ key = "v", cb = tree_cb "vsplit" },
-
- { key = "q", cb = ":lua require('core.nvimtree').toggle_tree()<cr>" },
}
end
-end
---
-M.focus_or_close = function()
- local view_status_ok, view = pcall(require, "nvim-tree.view")
- if not view_status_ok then
- return
+
+ options.builtin.which_key.mappings["e"] = { "<cmd>NvimTreeToggle<CR>", "Explorer" }
+
+ local tree_view = require "nvim-tree.view"
+
+ -- Add nvim_tree open callback
+ local open = tree_view.open
+ tree_view.open = function()
+ M.on_open()
+ open()
end
- local a = vim.api
- local curwin = a.nvim_get_current_win()
- local curbuf = a.nvim_win_get_buf(curwin)
- local bufnr = view.View.bufnr
- local winnr = view.get_winnr()
+ vim.cmd "au WinClosed * lua require('core.nvimtree').on_close()"
- if view.win_open() then
- if curwin == winnr and curbuf == bufnr then
- view.close()
- if package.loaded["bufferline.state"] then
- require("bufferline.state").set_offset(0)
- end
- else
- view.focus()
- end
- else
- view.open()
- if
- package.loaded["bufferline.state"] and options.builtin.nvimtree.side == "left"
- then
- require("bufferline.state").set_offset(options.builtin.nvimtree.width + 1, "")
- end
+ if options.builtin.nvimtree.on_config_done then
+ options.builtin.nvimtree.on_config_done(nvim_tree_config)
end
end
---
-M.toggle_tree = function()
- local view_status_ok, view = pcall(require, "nvim-tree.view")
- if not view_status_ok then
- return
+
+function M.on_open()
+ if package.loaded["bufferline.state"] and options.builtin.nvimtree.side == "left" then
+ require("bufferline.state").set_offset(options.builtin.nvimtree.width + 1, "")
end
- if view.win_open() then
- require("nvim-tree").close()
- if package.loaded["bufferline.state"] then
- require("bufferline.state").set_offset(0)
- end
- else
- if
- package.loaded["bufferline.state"] and options.builtin.nvimtree.side == "left"
- then
- require("bufferline.state").set_offset(options.builtin.nvimtree.width + 1, "")
- end
- require("nvim-tree").toggle()
+end
+
+function M.on_close()
+ local buf = tonumber(vim.fn.expand "<abuf>")
+ local ft = vim.api.nvim_buf_get_option(buf, "filetype")
+ if ft == "NvimTree" and package.loaded["bufferline.state"] then
+ require("bufferline.state").set_offset(0)
end
end
---
+
function M.change_tree_dir(dir)
- if vim.g.loaded_tree then
- require("nvim-tree.lib").change_dir(dir)
+ local lib_status_ok, lib = pcall(require, "nvim-tree.lib")
+ if lib_status_ok then
+ lib.change_dir(dir)
end
end
---
+
return M