summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/core/nvimtree.lua
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2021-08-10 23:15:04 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2021-08-10 23:15:04 +0200
commit540268d618627079c9b958a955b586e1888b46a8 (patch)
tree1a22a5feb457135178b9d4fe8b6c1755f5ca66bc /.config/nvim/lua/core/nvimtree.lua
parente79bd3273f58ba38e8fcd716090b89326791afbb (diff)
Major refactor of nvim
Diffstat (limited to '.config/nvim/lua/core/nvimtree.lua')
-rw-r--r--.config/nvim/lua/core/nvimtree.lua58
1 files changed, 48 insertions, 10 deletions
diff --git a/.config/nvim/lua/core/nvimtree.lua b/.config/nvim/lua/core/nvimtree.lua
index a763c71..698bd6e 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()
- O.plugin.nvimtree = {
+ options.builtin.nvimtree = {
side = "left",
+ width = 30,
show_icons = {
git = 1,
folders = 1,
@@ -48,23 +50,54 @@ end
M.setup = function()
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"
return
end
local g = vim.g
- for opt, val in pairs(O.plugin.nvimtree) do
+ for opt, val in pairs(options.builtin.nvimtree) do
g["nvim_tree_" .. opt] = val
end
local tree_cb = nvim_tree_config.nvim_tree_callback
- g.nvim_tree_bindings = {
- { key = { "l", "<CR>", "o" }, cb = tree_cb "edit" },
- { key = "h", cb = tree_cb "close_node" },
- { key = "v", cb = tree_cb "vsplit" },
- }
+ if not g.nvim_tree_bindings then
+ g.nvim_tree_bindings = {
+ { key = { "l", "<CR>", "o" }, cb = tree_cb "edit" },
+ { key = "h", cb = tree_cb "close_node" },
+ { key = "v", cb = tree_cb "vsplit" },
+ }
+ end
end
--
+M.focus_or_close = function()
+ local view_status_ok, view = pcall(require, "nvim-tree.view")
+ if not view_status_ok then
+ return
+ 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()
+
+ 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
+ end
+end
--
M.toggle_tree = function()
local view_status_ok, view = pcall(require, "nvim-tree.view")
@@ -77,12 +110,17 @@ M.toggle_tree = function()
require("bufferline.state").set_offset(0)
end
else
- if package.loaded["bufferline.state"] then
- -- require'bufferline.state'.set_offset(31, 'File Explorer')
- require("bufferline.state").set_offset(31, "")
+ 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
end
--
+function M.change_tree_dir(dir)
+ if vim.g.loaded_tree then
+ require("nvim-tree.lib").change_dir(dir)
+ end
+end
+--
return M