Skip to content

Commit b1c4479

Browse files
committed
fix: luacheck, buffer override erroring with mark not set
1 parent d41ca62 commit b1c4479

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lua/nvim-tree.lua

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ end
218218

219219
local function is_file_readable(fname)
220220
local stat = luv.fs_stat(fname)
221-
if not stat or not stat.type == 'file' or not luv.fs_access(fname, 'R') then return false end
222-
return true
221+
return stat and stat.type == "file" and luv.fs_access(fname, 'R')
223222
end
224223

225224
local function update_base_dir_with_filepath(filepath)
@@ -238,13 +237,11 @@ function M.find_file(with_open)
238237
if with_open then
239238
M.open()
240239
view.focus()
241-
if not is_file_readable(filepath) then return end
242-
update_base_dir_with_filepath(filepath)
243-
lib.set_index_and_redraw(filepath)
244-
return
245240
end
246241

247-
if not is_file_readable(filepath) then return end
242+
if not is_file_readable(filepath) then
243+
return
244+
end
248245
update_base_dir_with_filepath(filepath)
249246
lib.set_index_and_redraw(filepath)
250247
end

lua/nvim-tree/view.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function M.setup()
137137
vim.cmd "au BufWinEnter,BufWinLeave * lua require'nvim-tree.view'._prevent_buffer_override()"
138138
vim.cmd "au BufEnter,BufNewFile * lua require'nvim-tree'.open_on_directory()"
139139
vim.cmd "augroup END"
140-
140+
141141
if vim.g.nvim_tree_disable_keybindings == 1 then
142142
return
143143
end
@@ -189,7 +189,9 @@ function M._prevent_buffer_override()
189189
end
190190

191191
if a.nvim_buf_is_loaded(M.View.bufnr) and a.nvim_buf_is_valid(M.View.bufnr) then
192-
vim.cmd("buffer "..M.View.bufnr)
192+
-- pcall necessary to avoid erroring with `mark not set` although no mark are set
193+
-- this avoid other issues
194+
pcall(vim.api.nvim_win_set_buf, M.get_winnr(), M.View.bufnr)
193195
end
194196

195197
local bufname = a.nvim_buf_get_name(curbuf)

0 commit comments

Comments
 (0)