Skip to content

Commit 524758a

Browse files
committed
chore: remove auto close
also fix emmylua errors in log.lua file fixes #1005 fixes #871
1 parent ba121f0 commit 524758a

File tree

5 files changed

+11
-52
lines changed

5 files changed

+11
-52
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ require'nvim-tree'.setup {
117117
-- setup with all defaults
118118
-- each of these are documented in `:help nvim-tree.OPTION_NAME`
119119
require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
120-
auto_close = false,
121120
auto_reload_on_write = true,
122121
disable_netrw = false,
123122
hide_root_folder = false,
@@ -331,6 +330,10 @@ You can toggle the help UI by pressing `g?`.
331330
3. `toggle` has a second parameter which allows to toggle without focusing the explorer (`require"nvim-tree.toggle(false, false)`).
332331
4. You can allow nvim-tree to behave like vinegar (see `:help nvim-tree-vinegar`).
333332
5. If you `:set nosplitright`, the files will open on the left side of the tree, placing the tree window in the right side of the file you opened.
333+
6. You can automatically close the tab/vim when nvim-tree is the last window in the tab. WARNING: other plugins or automation may interfere with this:
334+
```vim
335+
autocmd BufEnter * ++nested if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif
336+
```
334337

335338
## Diagnostic Logging
336339

doc/nvim-tree-lua.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ function.
8484

8585
>
8686
require("nvim-tree").setup { -- BEGIN_DEFAULT_OPTS
87-
auto_close = false,
8887
auto_reload_on_write = true,
8988
disable_netrw = false,
9089
hide_root_folder = false,
@@ -215,11 +214,6 @@ Here is a list of the options available in the setup call:
215214
type: `{string}`
216215
default: `{}`
217216

218-
*nvim-tree.auto_close*
219-
- |auto_close|: force closing neovim when the tree is the last window in the view.
220-
type: `boolean`
221-
default: `false`
222-
223217
*nvim-tree.auto_reload_on_write*
224218
- |auto_reload_on_write|: reloads the explorer every time a buffer is written to
225219
type: `boolean`

lua/nvim-tree.lua

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -131,38 +131,6 @@ end
131131

132132
M.resize = view.resize
133133

134-
local function should_abort_auto_close()
135-
local buf = api.nvim_get_current_buf()
136-
local buftype = api.nvim_buf_get_option(buf, "ft")
137-
local modified = vim.tbl_filter(function(b)
138-
return api.nvim_buf_get_option(b, "modified")
139-
end, api.nvim_list_bufs())
140-
return #modified > 0 or buftype:match "Telescope" ~= nil
141-
end
142-
143-
function M.auto_close()
144-
if should_abort_auto_close() then
145-
return
146-
end
147-
148-
vim.defer_fn(function()
149-
if not view.is_visible() then
150-
return
151-
end
152-
153-
local windows = api.nvim_list_wins()
154-
local curtab = api.nvim_get_current_tabpage()
155-
local wins_in_tabpage = vim.tbl_filter(function(w)
156-
return api.nvim_win_get_tabpage(w) == curtab
157-
end, windows)
158-
if #windows == 1 then
159-
api.nvim_command ":silent qa!"
160-
elseif #wins_in_tabpage == 1 then
161-
api.nvim_command ":tabclose"
162-
end
163-
end, 50)
164-
end
165-
166134
function M.open_on_directory()
167135
local should_proceed = M.initialized and (_config.hijack_directories.auto_open or view.is_visible())
168136
if not should_proceed then
@@ -305,9 +273,6 @@ local function setup_autocommands(opts)
305273
end
306274
vim.cmd "au User FugitiveChanged,NeogitStatusRefreshed lua require'nvim-tree.actions.reloaders'.reload_git()"
307275

308-
if opts.auto_close then
309-
vim.cmd "au WinClosed * lua require'nvim-tree'.auto_close()"
310-
end
311276
if opts.open_on_tab then
312277
vim.cmd "au TabEnter * lua require'nvim-tree'.tab_change()"
313278
end
@@ -335,7 +300,6 @@ local function setup_autocommands(opts)
335300
end
336301

337302
local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
338-
auto_close = false,
339303
auto_reload_on_write = true,
340304
disable_netrw = false,
341305
hide_root_folder = false,
@@ -445,6 +409,10 @@ function M.setup(conf)
445409
local opts = merge_options(conf)
446410
local netrw_disabled = opts.disable_netrw or opts.hijack_netrw
447411

412+
if opts.auto_close then
413+
utils.warn "auto close feature has been removed, see note in the README (tips & reminder section)"
414+
end
415+
448416
_config.update_focused_file = opts.update_focused_file
449417
_config.open_on_setup = opts.open_on_setup
450418
_config.ignore_buffer_on_setup = opts.ignore_buffer_on_setup

lua/nvim-tree/legacy.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ local migrations = {
2424
end
2525
end,
2626

27-
nvim_tree_auto_close = function(o)
28-
if o.auto_close == nil then
29-
o.auto_close = vim.g.nvim_tree_auto_close ~= 0
30-
end
31-
end,
32-
3327
nvim_tree_tab_open = function(o)
3428
if o.open_on_tab == nil then
3529
o.open_on_tab = vim.g.nvim_tree_tab_open ~= 0

lua/nvim-tree/log.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local M = {
88
--- Write to log file
99
--- @param typ string as per log.types config
1010
--- @param fmt string for string.format
11-
--- @param ... any arguments for string.format
11+
--- @vararg any arguments for string.format
1212
function M.raw(typ, fmt, ...)
1313
if not M.path or not M.config.types[typ] and not M.config.types.all then
1414
return
@@ -23,7 +23,7 @@ end
2323

2424
--- Write to log file via M.line
2525
--- START is prefixed
26-
--- @return nanos to pass to profile_end
26+
--- @return number nanos to pass to profile_end
2727
function M.profile_start(fmt, ...)
2828
if not M.path or not M.config.types.profile and not M.config.types.all then
2929
return
@@ -34,7 +34,7 @@ end
3434

3535
--- Write to log file via M.line
3636
--- END is prefixed and duration in seconds is suffixed
37-
--- @param start nanos returned from profile_start
37+
--- @param start number nanos returned from profile_start
3838
function M.profile_end(start, fmt, ...)
3939
if not M.path or not M.config.types.profile and not M.config.types.all then
4040
return

0 commit comments

Comments
 (0)