From ae65f89bac849c099533a00ada422f3a32d7a46f Mon Sep 17 00:00:00 2001 From: ava5627 Date: Thu, 15 Feb 2024 01:14:14 -0600 Subject: [PATCH 01/10] Add update_focused_file.exclude and move update_focused_file.ignore_list to update_focused_file.update_root.ignore_list --- doc/nvim-tree-lua.txt | 31 ++++++++++++++++++++----------- lua/nvim-tree.lua | 18 ++++++++++++++---- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index ced571f17c4..0e8d5cfa03c 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -486,8 +486,11 @@ Following is the default configuration. See |nvim-tree-opts| for details. }, update_focused_file = { enable = false, - update_root = false, - ignore_list = {}, + update_root = { + enable = false, + ignore_list = {}, + }, + exclude = { "gitcommit" }, }, system_open = { cmd = "", @@ -657,12 +660,12 @@ Opens in place of the unnamed buffer if it's empty. *nvim-tree.root_dirs* Preferred root directories. -Only relevant when `update_focused_file.update_root` is `true` +Only relevant when `update_focused_file.update_root` is `enabled` Type: `{string}`, Default: `{}` *nvim-tree.prefer_startup_root* Prefer startup root directory when updating root directory of the tree. -Only relevant when `update_focused_file.update_root` is `true` +Only relevant when `update_focused_file.update_root` is `enabled` Type: `boolean`, Default: `false` *nvim-tree.sync_root_with_cwd* (previously `update_cwd`) @@ -1091,14 +1094,20 @@ Update the root directory of the tree if the file is not under current root directory. It prefers vim's cwd and `root_dirs`. Otherwise it falls back to the folder containing the file. Only relevant when `update_focused_file.enable` is `true` - Type: `boolean`, Default: `false` -*nvim-tree.update_focused_file.ignore_list* -List of buffer names and filetypes that will not update the root dir -of the tree if the file isn't found under the current root directory. -Only relevant when `update_focused_file.update_root` and -`update_focused_file.enable` are `true`. - Type: {string}, Default: `{}` + *nvim-tree.update_focused_file.update_root.enable* + Type: `boolean`, Default: `false` + + *nvim-tree.update_focused_file.update_root.ignore_list* + List of buffer names and filetypes that will not update the root dir + of the tree if the file isn't found under the current root directory. + Only relevant when `update_focused_file.update_root.enable` and + `update_focused_file.enable` are `true`. + Type: {string}, Default: `{}` + +*nvim-tree.update_focused_file.exclude* +List of buffer names and filetypes that will not update the focused file. + Type: {string}, Default: `{ "gitcommit" }` ============================================================================== 5.6 OPTS: SYSTEM OPEN *nvim-tree-opts-system-open* diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 07d06140363..a14dc361aae 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -27,7 +27,7 @@ function M.change_root(path, bufnr) -- skip if current file is in ignore_list if type(bufnr) == "number" then local ft = vim.api.nvim_buf_get_option(bufnr, "filetype") or "" - for _, value in pairs(_config.update_focused_file.ignore_list) do + for _, value in pairs(_config.update_focused_file.update_root.ignore_list) do if utils.str_find(path, value) or utils.str_find(ft, value) then return end @@ -149,7 +149,7 @@ function M.change_dir(name) actions.root.change_dir.fn(name) end - if _config.update_focused_file.enable then + if _config.update_focused_file.update_root.enable then actions.tree.find_file.fn() end end @@ -248,6 +248,13 @@ local function setup_autocommands(opts) if opts.update_focused_file.enable then create_nvim_tree_autocmd("BufEnter", { callback = function() + for _, value in pairs(_config.update_focused_file.exclude) do + local ft = vim.api.nvim_buf_get_option(0, "filetype") + local path = vim.fn.expand("%:p") + if utils.str_find(path, value) or utils.str_find(ft, value) then + return + end + end utils.debounce("BufEnter:find_file", opts.view.debounce_delay, function() actions.tree.find_file.fn() end) @@ -462,8 +469,11 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS }, update_focused_file = { enable = false, - update_root = false, - ignore_list = {}, + update_root = { + enable = false, + ignore_list = {}, + }, + exclude = { "gitcommit" }, }, system_open = { cmd = "", From dd07673abd415b8c6053b7d463696d381de74fd7 Mon Sep 17 00:00:00 2001 From: ava5627 Date: Thu, 15 Feb 2024 11:42:53 -0600 Subject: [PATCH 02/10] Pass ci checks --- doc/nvim-tree-lua.txt | 4 ++-- lua/nvim-tree.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 0e8d5cfa03c..57c8b048596 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -487,8 +487,8 @@ Following is the default configuration. See |nvim-tree-opts| for details. update_focused_file = { enable = false, update_root = { - enable = false, - ignore_list = {}, + enable = false, + ignore_list = {}, }, exclude = { "gitcommit" }, }, diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index a14dc361aae..f2cad007e85 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -250,7 +250,7 @@ local function setup_autocommands(opts) callback = function() for _, value in pairs(_config.update_focused_file.exclude) do local ft = vim.api.nvim_buf_get_option(0, "filetype") - local path = vim.fn.expand("%:p") + local path = vim.fn.expand "%:p" if utils.str_find(path, value) or utils.str_find(ft, value) then return end From 2f465de64e30750b051c147bdfde3c6cf833df6b Mon Sep 17 00:00:00 2001 From: ava5627 Date: Thu, 15 Feb 2024 11:52:25 -0600 Subject: [PATCH 03/10] Add config migration for update_root and ignore_list --- lua/nvim-tree/legacy.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lua/nvim-tree/legacy.lua b/lua/nvim-tree/legacy.lua index 9d95da69326..a2da52adafd 100644 --- a/lua/nvim-tree/legacy.lua +++ b/lua/nvim-tree/legacy.lua @@ -51,6 +51,17 @@ local function refactored(opts) if type(opts.renderer) == "table" and type(opts.renderer.highlight_git) == "boolean" then opts.renderer.highlight_git = opts.renderer.highlight_git and "name" or "none" end + + -- 2024/02/15 + if type(opts.update_focused_file.update_root) == "boolean" then + opts.update_focused_file.update_root = { + enable = opts.update_focused_file.update_root, + } + if opts.update_focused_file.ignore_list then + opts.update_focused_file.update_root.ignore_list = opts.update_focused_file.ignore_list + opts.update_focused_file.ignore_list = nil + end + end end local function deprecated(opts) From 6e0f85e439dbac4a06c294f132280630a0b15624 Mon Sep 17 00:00:00 2001 From: ava5627 Date: Fri, 16 Feb 2024 12:31:52 -0600 Subject: [PATCH 04/10] Missed one mention of update root in find_file.lua --- lua/nvim-tree/actions/tree/find-file.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-tree/actions/tree/find-file.lua b/lua/nvim-tree/actions/tree/find-file.lua index 3678276d654..610c534989a 100644 --- a/lua/nvim-tree/actions/tree/find-file.lua +++ b/lua/nvim-tree/actions/tree/find-file.lua @@ -55,7 +55,7 @@ function M.fn(opts) end -- update root - if opts.update_root or M.config.update_focused_file.update_root then + if opts.update_root or M.config.update_focused_file.update_root.enable then require("nvim-tree").change_root(path, bufnr) end From 5f4a19bccc5a0a4448a7780f1bf26728670bdb97 Mon Sep 17 00:00:00 2001 From: Ava Harris <40039652+ava5627@users.noreply.github.com> Date: Sat, 17 Feb 2024 20:34:06 -0600 Subject: [PATCH 05/10] Update migration code Co-authored-by: Alexander Courtis --- lua/nvim-tree/legacy.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lua/nvim-tree/legacy.lua b/lua/nvim-tree/legacy.lua index a2da52adafd..fe0d4f5a219 100644 --- a/lua/nvim-tree/legacy.lua +++ b/lua/nvim-tree/legacy.lua @@ -53,15 +53,12 @@ local function refactored(opts) end -- 2024/02/15 - if type(opts.update_focused_file.update_root) == "boolean" then - opts.update_focused_file.update_root = { - enable = opts.update_focused_file.update_root, - } - if opts.update_focused_file.ignore_list then - opts.update_focused_file.update_root.ignore_list = opts.update_focused_file.ignore_list - opts.update_focused_file.ignore_list = nil + if type(opts.update_focused_file) == "table" then + if type(opts.update_focused_file.update_root) ~= "table" then + opts.update_focused_file.update_root = { enable = opts.update_focused_file.update_root } end end + utils.move_missing_val(opts, "update_focused_file", "ignore_list", opts, "update_focused_file.update_root", "ignore_list", true) end local function deprecated(opts) From bf07615c0df1a40e454c96085da71ff130a79a9f Mon Sep 17 00:00:00 2001 From: ava5627 Date: Sat, 17 Feb 2024 20:34:44 -0600 Subject: [PATCH 06/10] make docs consistent --- doc/nvim-tree-lua.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 57c8b048596..c6a7bb37400 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -660,12 +660,12 @@ Opens in place of the unnamed buffer if it's empty. *nvim-tree.root_dirs* Preferred root directories. -Only relevant when `update_focused_file.update_root` is `enabled` +Only relevant when `update_focused_file.update_root` is `true` Type: `{string}`, Default: `{}` *nvim-tree.prefer_startup_root* Prefer startup root directory when updating root directory of the tree. -Only relevant when `update_focused_file.update_root` is `enabled` +Only relevant when `update_focused_file.update_root` is `true` Type: `boolean`, Default: `false` *nvim-tree.sync_root_with_cwd* (previously `update_cwd`) From 3804f31bffd951c085fe678d1da5d425a66149ea Mon Sep 17 00:00:00 2001 From: ava5627 Date: Sat, 17 Feb 2024 20:35:40 -0600 Subject: [PATCH 07/10] match on filename instead of entire path --- lua/nvim-tree.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index f2cad007e85..d0be4e90659 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -250,7 +250,7 @@ local function setup_autocommands(opts) callback = function() for _, value in pairs(_config.update_focused_file.exclude) do local ft = vim.api.nvim_buf_get_option(0, "filetype") - local path = vim.fn.expand "%:p" + local path = vim.fn.expand "%:t" if utils.str_find(path, value) or utils.str_find(ft, value) then return end From fb3392569cdb88cdbd14dbb9157c84e6314751a1 Mon Sep 17 00:00:00 2001 From: ava5627 Date: Sun, 24 Mar 2024 12:08:27 -0500 Subject: [PATCH 08/10] exclude as a function --- doc/nvim-tree-lua.txt | 5 +++-- lua/nvim-tree.lua | 14 ++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index c6a7bb37400..ab3d80a7ab2 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1106,8 +1106,9 @@ Only relevant when `update_focused_file.enable` is `true` Type: {string}, Default: `{}` *nvim-tree.update_focused_file.exclude* -List of buffer names and filetypes that will not update the focused file. - Type: {string}, Default: `{ "gitcommit" }` +A function that returns true if the file should not be focused when opening. +Takes the `BufEnter` event as an argument. see |autocmd-events| + Type: {function}, Default: `function() return false end` ============================================================================== 5.6 OPTS: SYSTEM OPEN *nvim-tree-opts-system-open* diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index d0be4e90659..fcc997f372d 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -247,13 +247,9 @@ local function setup_autocommands(opts) end if opts.update_focused_file.enable then create_nvim_tree_autocmd("BufEnter", { - callback = function() - for _, value in pairs(_config.update_focused_file.exclude) do - local ft = vim.api.nvim_buf_get_option(0, "filetype") - local path = vim.fn.expand "%:t" - if utils.str_find(path, value) or utils.str_find(ft, value) then - return - end + callback = function(event) + if opts.update_focused_file.exclude(event) then + return end utils.debounce("BufEnter:find_file", opts.view.debounce_delay, function() actions.tree.find_file.fn() @@ -473,7 +469,9 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS enable = false, ignore_list = {}, }, - exclude = { "gitcommit" }, + exclude = function() + return false + end, }, system_open = { cmd = "", From 878d061c829b2fdd58706e074e898580b1525a2c Mon Sep 17 00:00:00 2001 From: ava5627 Date: Sun, 24 Mar 2024 12:17:40 -0500 Subject: [PATCH 09/10] fix docs --- doc/nvim-tree-lua.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index e4afcda229a..d203df8b942 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -504,7 +504,9 @@ Following is the default configuration. See |nvim-tree-opts| for details. enable = false, ignore_list = {}, }, - exclude = { "gitcommit" }, + exclude = function() + return false + end, }, system_open = { cmd = "", @@ -2879,8 +2881,10 @@ highlight group is not, hard linking as follows: > |nvim-tree.ui.confirm.remove| |nvim-tree.ui.confirm.trash| |nvim-tree.update_focused_file.enable| -|nvim-tree.update_focused_file.ignore_list| +|nvim-tree.update_focused_file.exclude| |nvim-tree.update_focused_file.update_root| +|nvim-tree.update_focused_file.update_root.enable| +|nvim-tree.update_focused_file.update_root.ignore_list| |nvim-tree.view.centralize_selection| |nvim-tree.view.cursorline| |nvim-tree.view.debounce_delay| From da9ad4d4744d8094ce3ed3ade921b2dd22e9487f Mon Sep 17 00:00:00 2001 From: ava5627 Date: Sun, 24 Mar 2024 20:12:05 -0500 Subject: [PATCH 10/10] default exclude value --- doc/nvim-tree-lua.txt | 6 ++---- lua/nvim-tree.lua | 10 ++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index d203df8b942..b9b2225f159 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -504,9 +504,7 @@ Following is the default configuration. See |nvim-tree-opts| for details. enable = false, ignore_list = {}, }, - exclude = function() - return false - end, + exclude = false, }, system_open = { cmd = "", @@ -1124,7 +1122,7 @@ Only relevant when `update_focused_file.enable` is `true` *nvim-tree.update_focused_file.exclude* A function that returns true if the file should not be focused when opening. Takes the `BufEnter` event as an argument. see |autocmd-events| - Type: {function}, Default: `function() return false end` + Type: {function}, Default: `false` ============================================================================== 5.6 OPTS: SYSTEM OPEN *nvim-tree-opts-system-open* diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 73b216ca4ad..b2103be3c23 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -248,7 +248,8 @@ local function setup_autocommands(opts) if opts.update_focused_file.enable then create_nvim_tree_autocmd("BufEnter", { callback = function(event) - if opts.update_focused_file.exclude(event) then + local exclude = opts.update_focused_file.exclude + if type(exclude) == "function" and exclude(event) then return end utils.debounce("BufEnter:find_file", opts.view.debounce_delay, function() @@ -469,9 +470,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS enable = false, ignore_list = {}, }, - exclude = function() - return false - end, + exclude = false, }, system_open = { cmd = "", @@ -632,6 +631,9 @@ local ACCEPTED_TYPES = { group_empty = { "boolean", "function" }, root_folder_label = { "function", "string", "boolean" }, }, + update_focused_file = { + exclude = { "function" }, + }, filters = { custom = { "function" }, },