From 3c3100b4d235a91243ebd02d2f48fa79edf7f26f Mon Sep 17 00:00:00 2001 From: eph Date: Fri, 14 Jun 2024 00:18:29 +0800 Subject: [PATCH 1/6] temp workaround for issue #2803 --- lua/nvim-tree/actions/node/open-file.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 39026253376..7821c2451f3 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -310,7 +310,8 @@ local function open_in_new_window(filename, mode) end end - local fname = utils.escape_special_chars(vim.fn.fnameescape(filename)) + -- TODO: nvim-tree 会改变当前目录, 调用结束前恢复 + local fname = utils.escape_special_chars(vim.fn.fnameescape(vim.fn.fnamemodify(filename, ':.'))) local command if create_new_window then From 80d580d75177605ef189e1fd5818f921133ceb2d Mon Sep 17 00:00:00 2001 From: eph Date: Mon, 17 Jun 2024 01:08:28 +0800 Subject: [PATCH 2/6] fix #2127 and #2803 --- lua/nvim-tree.lua | 6 +++++- lua/nvim-tree/actions/node/open-file.lua | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 395dc3a96c2..ac99ef52176 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -584,7 +584,11 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS default_yes = false, }, }, - experimental = {}, + experimental = { + open = { + relative_path = false, + }, + }, log = { enable = false, truncate = false, diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 7821c2451f3..9457bedcffd 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -190,6 +190,9 @@ local function open_file_in_tab(filename) if M.quit_on_open then view.close() end + if require('nvim-tree').config.experimental.open.relative_path then + filename = utils.path_relative(filename, vim.fn.getcwd()) + end vim.cmd("tabe " .. vim.fn.fnameescape(filename)) end @@ -197,6 +200,9 @@ local function drop(filename) if M.quit_on_open then view.close() end + if require('nvim-tree').config.experimental.open.relative_path then + filename = utils.path_relative(filename, vim.fn.getcwd()) + end vim.cmd("drop " .. vim.fn.fnameescape(filename)) end @@ -204,6 +210,9 @@ local function tab_drop(filename) if M.quit_on_open then view.close() end + if require('nvim-tree').config.experimental.open.relative_path then + filename = utils.path_relative(filename, vim.fn.getcwd()) + end vim.cmd("tab :drop " .. vim.fn.fnameescape(filename)) end @@ -310,8 +319,12 @@ local function open_in_new_window(filename, mode) end end - -- TODO: nvim-tree 会改变当前目录, 调用结束前恢复 - local fname = utils.escape_special_chars(vim.fn.fnameescape(vim.fn.fnamemodify(filename, ':.'))) + local fname + if require('nvim-tree').config.experimental.open.relative_path then + fname = utils.escape_special_chars(vim.fn.fnameescape(utils.path_relative(filename, vim.fn.getcwd()))) + else + fname = utils.escape_special_chars(vim.fn.fnameescape(filename)) + end local command if create_new_window then @@ -347,6 +360,9 @@ end local function edit_in_current_buf(filename) require("nvim-tree.view").abandon_current_window() + if require('nvim-tree').config.experimental.open.relative_path then + filename = utils.path_relative(filename, vim.fn.getcwd()) + end vim.cmd("keepalt keepjumps edit " .. vim.fn.fnameescape(filename)) end From b51181627cb49fae98cfd7dcf503f0c715450e2d Mon Sep 17 00:00:00 2001 From: eph Date: Mon, 17 Jun 2024 08:57:11 +0800 Subject: [PATCH 3/6] chore(#2127): read the configuration correctly --- lua/nvim-tree/actions/node/open-file.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 9457bedcffd..c77c5108e97 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -190,7 +190,7 @@ local function open_file_in_tab(filename) if M.quit_on_open then view.close() end - if require('nvim-tree').config.experimental.open.relative_path then + if M.relative_path then filename = utils.path_relative(filename, vim.fn.getcwd()) end vim.cmd("tabe " .. vim.fn.fnameescape(filename)) @@ -200,7 +200,7 @@ local function drop(filename) if M.quit_on_open then view.close() end - if require('nvim-tree').config.experimental.open.relative_path then + if M.relative_path then filename = utils.path_relative(filename, vim.fn.getcwd()) end vim.cmd("drop " .. vim.fn.fnameescape(filename)) @@ -210,7 +210,7 @@ local function tab_drop(filename) if M.quit_on_open then view.close() end - if require('nvim-tree').config.experimental.open.relative_path then + if M.relative_path then filename = utils.path_relative(filename, vim.fn.getcwd()) end vim.cmd("tab :drop " .. vim.fn.fnameescape(filename)) @@ -320,7 +320,7 @@ local function open_in_new_window(filename, mode) end local fname - if require('nvim-tree').config.experimental.open.relative_path then + if M.relative_path then fname = utils.escape_special_chars(vim.fn.fnameescape(utils.path_relative(filename, vim.fn.getcwd()))) else fname = utils.escape_special_chars(vim.fn.fnameescape(filename)) @@ -360,7 +360,7 @@ end local function edit_in_current_buf(filename) require("nvim-tree.view").abandon_current_window() - if require('nvim-tree').config.experimental.open.relative_path then + if M.relative_path then filename = utils.path_relative(filename, vim.fn.getcwd()) end vim.cmd("keepalt keepjumps edit " .. vim.fn.fnameescape(filename)) @@ -419,6 +419,7 @@ end function M.setup(opts) M.quit_on_open = opts.actions.open_file.quit_on_open M.resize_window = opts.actions.open_file.resize_window + M.relative_path = opts.experimental.open.relative_path if opts.actions.open_file.window_picker.chars then opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper() end From 9ae5afde4292f2c7c7a80415e826c1905ddb35d6 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 7 Jul 2024 12:42:10 +1000 Subject: [PATCH 4/6] feat(#2127): add help --- doc/nvim-tree-lua.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 8e588a14ab2..105b393e301 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -620,7 +620,11 @@ Following is the default configuration. See |nvim-tree-opts| for details. default_yes = false, }, }, - experimental = {}, + experimental = { + open = { + relative_path = false, + }, + }, log = { enable = false, truncate = false, @@ -1536,6 +1540,12 @@ Confirmation prompts. Experimental features that may become default or optional functionality. In the event of a problem please disable the experiment and raise an issue. + *nvim-tree.open.relative_path* + Buffers opened by nvim-tree will use with relative paths instead of + absolute. + Execute |:ls| to see the paths of all open buffers. + Type: `boolean`, Default: `false` + ============================================================================== 5.20 OPTS: LOG *nvim-tree-opts-log* @@ -2812,6 +2822,7 @@ highlight group is not, hard linking as follows: > |nvim-tree.modified.show_on_open_dirs| |nvim-tree.notify.threshold| |nvim-tree.on_attach| +|nvim-tree.open.relative_path| |nvim-tree.prefer_startup_root| |nvim-tree.reload_on_bufenter| |nvim-tree.renderer.add_trailing| From 40544215968860b4709fba9c7ad1d1f3b7e0d4a3 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 7 Jul 2024 12:46:05 +1000 Subject: [PATCH 5/6] feat(#2127): normalise relative_path in config hierarchy --- doc/nvim-tree-lua.txt | 10 ++++++---- lua/nvim-tree.lua | 6 ++++-- lua/nvim-tree/actions/node/open-file.lua | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 105b393e301..24434101b7f 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -621,8 +621,10 @@ Following is the default configuration. See |nvim-tree-opts| for details. }, }, experimental = { - open = { - relative_path = false, + actions = { + open_file = { + relative_path = false, + }, }, }, log = { @@ -1540,7 +1542,7 @@ Confirmation prompts. Experimental features that may become default or optional functionality. In the event of a problem please disable the experiment and raise an issue. - *nvim-tree.open.relative_path* + *nvim-tree.actions.open_file.relative_path* Buffers opened by nvim-tree will use with relative paths instead of absolute. Execute |:ls| to see the paths of all open buffers. @@ -2762,6 +2764,7 @@ highlight group is not, hard linking as follows: > |nvim-tree.actions.open_file| |nvim-tree.actions.open_file.eject| |nvim-tree.actions.open_file.quit_on_open| +|nvim-tree.actions.open_file.relative_path| |nvim-tree.actions.open_file.resize_window| |nvim-tree.actions.open_file.window_picker| |nvim-tree.actions.open_file.window_picker.chars| @@ -2822,7 +2825,6 @@ highlight group is not, hard linking as follows: > |nvim-tree.modified.show_on_open_dirs| |nvim-tree.notify.threshold| |nvim-tree.on_attach| -|nvim-tree.open.relative_path| |nvim-tree.prefer_startup_root| |nvim-tree.reload_on_bufenter| |nvim-tree.renderer.add_trailing| diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index ac99ef52176..e29fa95bb32 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -585,8 +585,10 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS }, }, experimental = { - open = { - relative_path = false, + actions = { + open_file = { + relative_path = false, + }, }, }, log = { diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index c77c5108e97..130106106cb 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -419,7 +419,7 @@ end function M.setup(opts) M.quit_on_open = opts.actions.open_file.quit_on_open M.resize_window = opts.actions.open_file.resize_window - M.relative_path = opts.experimental.open.relative_path + M.relative_path = opts.experimental.actions.open_file.relative_path if opts.actions.open_file.window_picker.chars then opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper() end From 6f5d22d8535364a660bcfa7702d544791ff0f5d6 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 7 Jul 2024 12:48:12 +1000 Subject: [PATCH 6/6] feat(#2127): update help --- 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 24434101b7f..e4097f15394 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1542,7 +1542,7 @@ Confirmation prompts. Experimental features that may become default or optional functionality. In the event of a problem please disable the experiment and raise an issue. - *nvim-tree.actions.open_file.relative_path* + *nvim-tree.experimental.actions.open_file.relative_path* Buffers opened by nvim-tree will use with relative paths instead of absolute. Execute |:ls| to see the paths of all open buffers. @@ -2764,7 +2764,6 @@ highlight group is not, hard linking as follows: > |nvim-tree.actions.open_file| |nvim-tree.actions.open_file.eject| |nvim-tree.actions.open_file.quit_on_open| -|nvim-tree.actions.open_file.relative_path| |nvim-tree.actions.open_file.resize_window| |nvim-tree.actions.open_file.window_picker| |nvim-tree.actions.open_file.window_picker.chars| @@ -2784,6 +2783,7 @@ highlight group is not, hard linking as follows: > |nvim-tree.diagnostics.show_on_open_dirs| |nvim-tree.disable_netrw| |nvim-tree.experimental| +|nvim-tree.experimental.actions.open_file.relative_path| |nvim-tree.filesystem_watchers.debounce_delay| |nvim-tree.filesystem_watchers.enable| |nvim-tree.filesystem_watchers.ignore_dirs|