From 48d53a5934fbd51b655d03db7dad35551838f2c9 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 11 Apr 2023 14:53:27 +1000 Subject: [PATCH] feat(#1669): remove deprecated open_on_setup mechanisms (#2122) --- README.md | 4 -- doc/nvim-tree-lua.txt | 29 ------------ lua/nvim-tree.lua | 104 ++---------------------------------------- 3 files changed, 4 insertions(+), 133 deletions(-) diff --git a/README.md b/README.md index b6e5a54d944..ba71619e118 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,6 @@ Take a look at the [wiki](https://github.com/nvim-tree/nvim-tree.lua/wiki) for S [Join us on matrix](https://matrix.to/#/#nvim-tree:matrix.org) -## Breaking Change 2023-01-30 - -Existing `*_on_setup*` mechanisms have been removed in favour of [Open At Startup](https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup) - ## New Mapping Method 2023-02-27 [:help nvim-tree.view.mappings](doc/nvim-tree-lua.txt) have been deprecated in favour of [:help nvim-tree.on_attach](doc/nvim-tree-lua.txt). Please visit [Migrating To on_attach](https://github.com/nvim-tree/nvim-tree.lua/wiki/Migrating-To-on_attach) to transition. diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 915df23c0db..f25aef7918d 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -229,9 +229,6 @@ applying configuration. hijack_cursor = false, hijack_netrw = true, hijack_unnamed_buffer_when_opening = false, - ignore_buffer_on_setup = false, - open_on_setup = false, - open_on_setup_file = false, sort_by = "name", root_dirs = {}, prefer_startup_root = false, @@ -342,7 +339,6 @@ applying configuration. update_root = false, ignore_list = {}, }, - ignore_ft_on_setup = {}, system_open = { cmd = "", args = {}, @@ -485,31 +481,6 @@ Set the following at the very beginning of your `init.lua` / `init.vim`: > Hijack netrw windows (overridden if |disable_netrw| is `true`) Type: `boolean`, Default: `true` -*nvim-tree.open_on_setup* -Deprecated: please see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup -Will automatically open the tree when running setup if startup buffer is -a directory, is empty or is unnamed. nvim-tree window will be focused. - Type: `boolean`, Default: `false` - -*nvim-tree.open_on_setup_file* -Deprecated: please see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup -Will automatically open the tree when running setup if startup buffer is a file. -File window will be focused. -File will be found if update_focused_file is enabled. - Type: `boolean`, Default: `false` - -*nvim-tree.ignore_buffer_on_setup* -Deprecated: please see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup -Will ignore the buffer, when deciding to open the tree on setup. - Type: `boolean`, Default: `false` - -*nvim-tree.ignore_ft_on_setup* -Deprecated: please see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup -List of filetypes that will prevent `open_on_setup` to open. -You can use this option if you don't want the tree to open -in some scenarios (eg using vim startify). - Type: {string}, Default: `{}` - *nvim-tree.auto_reload_on_write* Reloads the explorer every time a buffer is written to. Type: `boolean`, Default: `true` diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index f0f372e65a4..40a17d8a407 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -12,7 +12,6 @@ local reloaders = require "nvim-tree.actions.reloaders.reloaders" local git = require "nvim-tree.git" local filters = require "nvim-tree.explorer.filters" local modified = require "nvim-tree.modified" -local notify = require "nvim-tree.notify" local keymap_legacy = require "nvim-tree.keymap-legacy" local find_file = require "nvim-tree.actions.tree.find-file" local open = require "nvim-tree.actions.tree.open" @@ -20,7 +19,6 @@ local open = require "nvim-tree.actions.tree.open" local _config = {} local M = { - setup_called = false, init_root = "", } @@ -117,15 +115,8 @@ function M.tab_enter() end end -local function find_existing_windows() - return vim.tbl_filter(function(win) - local buf = vim.api.nvim_win_get_buf(win) - return vim.api.nvim_buf_get_name(buf):match "NvimTree" ~= nil - end, vim.api.nvim_list_wins()) -end - function M.open_on_directory() - local should_proceed = M.initialized and (_config.hijack_directories.auto_open or view.is_visible()) + local should_proceed = _config.hijack_directories.auto_open or view.is_visible() if not should_proceed then return end @@ -167,70 +158,6 @@ function M.place_cursor_on_node() end end -function M.on_enter(netrw_disabled) - local bufnr = vim.api.nvim_get_current_buf() - local bufname = vim.api.nvim_buf_get_name(bufnr) - local buftype = vim.api.nvim_buf_get_option(bufnr, "filetype") - local ft_ignore = _config.ignore_ft_on_setup - - local stats = vim.loop.fs_stat(bufname) - local is_dir = stats and stats.type == "directory" - local is_file = stats and stats.type == "file" - - local lines = not is_dir and vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) or {} - local buf_has_content = #lines > 1 or (#lines == 1 and lines[1] ~= "") - - 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 = false - local should_focus_other_window = false - local should_find = false - if (_config.open_on_setup or _config.open_on_setup_file) and not should_be_preserved then - if buf_is_dir or buf_is_empty then - should_open = true - elseif is_file and _config.open_on_setup_file then - should_open = true - should_focus_other_window = true - should_find = _config.update_focused_file.enable - elseif _config.ignore_buffer_on_setup then - should_open = true - should_focus_other_window = true - end - end - - local should_hijack = _config.hijack_directories.enable - and _config.hijack_directories.auto_open - and is_dir - and not should_be_preserved - - -- Session that left a NvimTree Buffer opened, reopen with it - local existing_tree_wins = find_existing_windows() - if existing_tree_wins[1] then - vim.api.nvim_set_current_win(existing_tree_wins[1]) - end - - if should_open or should_hijack or existing_tree_wins[1] ~= nil then - local cwd - if is_dir then - cwd = vim.fn.expand(vim.fn.fnameescape(bufname)) - -- INFO: could potentially conflict with rooter plugins - vim.cmd("noautocmd cd " .. vim.fn.fnameescape(cwd)) - end - - lib.open { path = cwd } - - if should_focus_other_window then - vim.cmd "noautocmd wincmd p" - if should_find then - find_file.fn() - end - end - end - M.initialized = true -end - function M.get_config() return M.config end @@ -418,9 +345,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS hijack_cursor = false, hijack_netrw = true, hijack_unnamed_buffer_when_opening = false, - ignore_buffer_on_setup = false, - open_on_setup = false, - open_on_setup_file = false, sort_by = "name", root_dirs = {}, prefer_startup_root = false, @@ -531,7 +455,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS update_root = false, ignore_list = {}, }, - ignore_ft_on_setup = {}, system_open = { cmd = "", args = {}, @@ -738,10 +661,6 @@ function M.setup(conf) _config.root_dirs = opts.root_dirs _config.prefer_startup_root = opts.prefer_startup_root _config.update_focused_file = opts.update_focused_file - _config.open_on_setup = opts.open_on_setup - _config.open_on_setup_file = opts.open_on_setup_file - _config.ignore_buffer_on_setup = opts.ignore_buffer_on_setup - _config.ignore_ft_on_setup = opts.ignore_ft_on_setup _config.hijack_directories = opts.hijack_directories _config.hijack_directories.enable = _config.hijack_directories.enable and netrw_disabled @@ -777,7 +696,7 @@ function M.setup(conf) setup_autocommands(opts) - if not M.setup_called then + if vim.g.NvimTreeSetup ~= 1 then -- first call to setup commands.setup() else @@ -791,23 +710,8 @@ function M.setup(conf) end end - M.setup_called = true - - vim.schedule(function() - if - #opts.ignore_ft_on_setup > 0 - or opts.open_on_setup == true - or opts.open_on_setup_file - or opts.ignore_buffer_on_setup - then - notify.info "open_on_setup behaviour has been deprecated, please see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup" - M.on_enter(netrw_disabled) - else - M.initialized = true - end - vim.g.NvimTreeSetup = 1 - vim.api.nvim_exec_autocmds("User", { pattern = "NvimTreeSetup" }) - end) + vim.g.NvimTreeSetup = 1 + vim.api.nvim_exec_autocmds("User", { pattern = "NvimTreeSetup" }) end vim.g.NvimTreeRequired = 1