From 7a19c3e747f8953ed50c2f97a7d070f7a86190e8 Mon Sep 17 00:00:00 2001 From: kiyan Date: Tue, 8 Feb 2022 21:42:14 +0100 Subject: [PATCH] fix: reschedule on_enter and setup autocmd Wait for nvim to finish before checking buftypes. Fixes #944 Fixes #942 --- lua/nvim-tree.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 4aa178a1..508c684f 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -103,9 +103,10 @@ function M.on_enter(netrw_disabled) local lines = not is_dir and api.nvim_buf_get_lines(bufnr, 0, -1, false) or {} local buf_has_content = #lines > 1 or (#lines == 1 and lines[1] ~= "") - local should_open = _config.open_on_setup - and ((is_dir and netrw_disabled) or (bufname == "" and not buf_has_content)) - and not vim.tbl_contains(ft_ignore, buftype) + local buf_is_dir = is_dir and netrw_disabled + local buf_is_empty = bufname == "" and not buf_has_content + local should_be_preserved = vim.tbl_contains(ft_ignore, buftype) + local should_open = _config.open_on_setup and not should_be_preserved and (buf_is_dir or buf_is_empty) if should_open then M.hijack_current_window() @@ -372,9 +373,11 @@ function M.setup(conf) require'nvim-tree.explorer'.setup(opts) require'nvim-tree.git'.setup(opts) setup_vim_commands() - setup_autocommands(opts) - M.on_enter(netrw_disabled) + vim.schedule(function() + M.on_enter(netrw_disabled) + setup_autocommands(opts) + end) end return M