mirror of
https://github.com/nvim-tree/nvim-tree.lua
synced 2024-09-16 14:34:03 +02:00
feat(#2127): add experimental.actions.open_file.relative_path to open files with a relative path rather than absolute (#2805)
* temp workaround for issue #2803 * fix #2127 and #2803 * chore(#2127): read the configuration correctly * feat(#2127): add help * feat(#2127): normalise relative_path in config hierarchy * feat(#2127): update help --------- Co-authored-by: eph <eph@MacBook-Pro.local> Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
parent
74e94625b1
commit
869c064721
3 changed files with 40 additions and 3 deletions
|
@ -620,7 +620,13 @@ Following is the default configuration. See |nvim-tree-opts| for details.
|
|||
default_yes = false,
|
||||
},
|
||||
},
|
||||
experimental = {},
|
||||
experimental = {
|
||||
actions = {
|
||||
open_file = {
|
||||
relative_path = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
log = {
|
||||
enable = false,
|
||||
truncate = false,
|
||||
|
@ -1539,6 +1545,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.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.
|
||||
Type: `boolean`, Default: `false`
|
||||
|
||||
==============================================================================
|
||||
5.20 OPTS: LOG *nvim-tree-opts-log*
|
||||
|
||||
|
@ -2774,6 +2786,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|
|
||||
|
|
|
@ -584,7 +584,13 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
|||
default_yes = false,
|
||||
},
|
||||
},
|
||||
experimental = {},
|
||||
experimental = {
|
||||
actions = {
|
||||
open_file = {
|
||||
relative_path = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
log = {
|
||||
enable = false,
|
||||
truncate = false,
|
||||
|
|
|
@ -190,6 +190,9 @@ local function open_file_in_tab(filename)
|
|||
if M.quit_on_open then
|
||||
view.close()
|
||||
end
|
||||
if M.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 M.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 M.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
end
|
||||
vim.cmd("tab :drop " .. vim.fn.fnameescape(filename))
|
||||
end
|
||||
|
||||
|
@ -310,7 +319,12 @@ local function open_in_new_window(filename, mode)
|
|||
end
|
||||
end
|
||||
|
||||
local fname = utils.escape_special_chars(vim.fn.fnameescape(filename))
|
||||
local fname
|
||||
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))
|
||||
end
|
||||
|
||||
local command
|
||||
if create_new_window then
|
||||
|
@ -346,6 +360,9 @@ end
|
|||
|
||||
local function edit_in_current_buf(filename)
|
||||
require("nvim-tree.view").abandon_current_window()
|
||||
if M.relative_path then
|
||||
filename = utils.path_relative(filename, vim.fn.getcwd())
|
||||
end
|
||||
vim.cmd("keepalt keepjumps edit " .. vim.fn.fnameescape(filename))
|
||||
end
|
||||
|
||||
|
@ -402,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.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
|
||||
|
|
Loading…
Reference in a new issue