From b1c447946b1d0afa8f0bbd92f5a6bad0b54a3f3c Mon Sep 17 00:00:00 2001 From: kiyan Date: Tue, 31 Aug 2021 21:22:30 +0200 Subject: [PATCH] fix: luacheck, buffer override erroring with mark not set --- lua/nvim-tree.lua | 11 ++++------- lua/nvim-tree/view.lua | 6 ++++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 22717952..2c8b4e02 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -218,8 +218,7 @@ end local function is_file_readable(fname) local stat = luv.fs_stat(fname) - if not stat or not stat.type == 'file' or not luv.fs_access(fname, 'R') then return false end - return true + return stat and stat.type == "file" and luv.fs_access(fname, 'R') end local function update_base_dir_with_filepath(filepath) @@ -238,13 +237,11 @@ function M.find_file(with_open) if with_open then M.open() view.focus() - if not is_file_readable(filepath) then return end - update_base_dir_with_filepath(filepath) - lib.set_index_and_redraw(filepath) - return end - if not is_file_readable(filepath) then return end + if not is_file_readable(filepath) then + return + end update_base_dir_with_filepath(filepath) lib.set_index_and_redraw(filepath) end diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 7ef89294..b0dcee56 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -137,7 +137,7 @@ function M.setup() vim.cmd "au BufWinEnter,BufWinLeave * lua require'nvim-tree.view'._prevent_buffer_override()" vim.cmd "au BufEnter,BufNewFile * lua require'nvim-tree'.open_on_directory()" vim.cmd "augroup END" - + if vim.g.nvim_tree_disable_keybindings == 1 then return end @@ -189,7 +189,9 @@ function M._prevent_buffer_override() end if a.nvim_buf_is_loaded(M.View.bufnr) and a.nvim_buf_is_valid(M.View.bufnr) then - vim.cmd("buffer "..M.View.bufnr) + -- pcall necessary to avoid erroring with `mark not set` although no mark are set + -- this avoid other issues + pcall(vim.api.nvim_win_set_buf, M.get_winnr(), M.View.bufnr) end local bufname = a.nvim_buf_get_name(curbuf)