From 137628acb670d19cd13b3008eae59626feef57c6 Mon Sep 17 00:00:00 2001 From: kiyan Date: Sat, 2 Oct 2021 13:53:51 +0200 Subject: [PATCH] chore: update_to_buf_dir allow auto_open configuration also improve the documentation with doc references --- README.md | 7 +++- doc/nvim-tree-lua.txt | 80 +++++++++++++++++++++++++++---------------- lua/nvim-tree.lua | 27 ++++++++------- 3 files changed, 71 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 6071f2fe..2fc73b27 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,12 @@ require'nvim-tree'.setup { -- opens the tree when changing/opening a new tab if the tree wasn't previously opened open_on_tab = false, -- hijacks new directory buffers when they are opened. - update_to_buf_dir = true, + update_to_buf_dir = { + -- enable the feature + enable = true, + -- allow to open the tree if it was previously closed + auto_open = true, + }, -- hijack the cursor in the tree to put it at the start of the filename hijack_cursor = false, -- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 04fbd75d..6e1a6900 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -59,7 +59,7 @@ Resize the NvimTree window to the given size. Example: `:NvimTreeresize 50` resizes the window to the width of 50. ============================================================================== -SETUP *nvim-tree-setup* +SETUP *nvim-tree.setup* To configure the tree (and make it runnable), you should call the setup function. @@ -70,7 +70,10 @@ function. hijack_netrw = true, open_on_setup = false, ignore_ft_on_setup = {}, - update_to_buf_dir = true, + update_to_buf_dir = { + enable = true, + auto_open = true, + }, auto_close = false, open_on_tab = false, hijack_cursor = false, @@ -101,51 +104,65 @@ As options are currently being migrated, configuration of global options in |nvim-tree-options| should be done BEFORE the setup call. Here is a list of the options available in the setup call: + +*nvim-tree.disable_netrw* - |disable_netrw|: completely disable netrw type: `boolean` default: `true` +*nvim-tree.hijack_netrw* - |hijack_netrw|: hijack netrw windows (overriden if |disable_netrw| is `true`) type: `boolean` default: `true` +*nvim-tree.open_on_setup* - |open_on_setup|: will automatically open the tree when running setup if current buffer is a directory, is empty or is unnamed. type: `boolean` default: `false` +*nvim-tree.ignore_ft_on_setup* - |ignore_ft_on_setup|: list of filetypes that will make |open_on_setup| not 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_close* - |auto_close|: force closing neovim when the tree is the last window in the view. type: `boolean` default: `false` +*nvim-tree.open_on_tab* - |open_on_tab|: opens the tree automatically when switching tabpage or opening a new tabpage if the tree was previously open. type: `boolean` default: `false` +*nvim-tree.update_to_buf_dir* - |update_to_buf_dir|: hijacks new directory buffers when they are opened (`:e dir`). - If |open_on_setup| is enabled, it will open the tree if the tree is closed. - Disable this option if you use vim-dirvish. - type: `boolean` - default: `true` + - |update_to_buf_dir.enable|: enable the feature. Disable this option if you use vim-dirvish. + type: `boolean` + default: `true` + - |update_to_buf_dir.auto_open|: opens the tree if the tree was previously closed. + type: `boolean` + default: `true` + +*nvim-tree.hijack_cursor* - |hijack_cursor|: keeps the cursor on the first letter of the filename when moving in the tree. type: `boolean` default: `false` +*nvim-tree.update_cwd* - |update_cwd|: changes the tree root directory on `DirChanged` and refreshes the tree. type: `boolean` default: `false` +*nvim-tree.update_focused_file* - |update_focused_file|: update the focused file on `BufEnter`, un-collapses the folders recursively until it finds the file @@ -166,6 +183,7 @@ Here is a list of the options available in the setup call: type: `{string}` default: `{}` +*nvim-tree.system_open* - |system_open|: configuration options for the system open command - |system_open.cmd|: the command to run, leaving nil should work but @@ -177,36 +195,38 @@ Here is a list of the options available in the setup call: type: `{string}` default: `{}` +*nvim-tree.lsp_diagnostics* - |lsp_diagnostics|: show lsp diagnostics in the signcolumn type: `boolean` default: false +*nvim-tree.view* - |view|: window / buffer setup -- |view.width|: width of the window, can be either a `%` string or - a number representing columns - type: `string | number` - default: `30` - -- |view.side|: side of the tree, can be one of 'left' | 'right' | 'bottom' | 'top' - Note that bottom/top are not working correctly yet. - type: `string` - default: 'left' - -- |view.auto_resize|: auto resize the tree after opening a file - type: `boolean` - default: false - -- |view.mappings|: configuration options for keymaps - -- |view.mappings.custom_only|: will use only the provided user mappings and not the default - otherwise, extends the default mappings with the provided user mappings - type: `boolean` - default: false - -- |view,mappings.list|: a list of keymaps that will extend or override the default keymaps - type: list of `{ key: table of strings or string, mode: string (vim-mode), cb: callback function as a string }` - default: {} + - |view.width|: width of the window, can be either a `%` string or + a number representing columns + type: `string | number` + default: `30` + + - |view.side|: side of the tree, can be one of 'left' | 'right' | 'bottom' | 'top' + Note that bottom/top are not working correctly yet. + type: `string` + default: 'left' + + - |view.auto_resize|: auto resize the tree after opening a file + type: `boolean` + default: false + + - |view.mappings|: configuration options for keymaps + + - |view.mappings.custom_only|: will use only the provided user mappings and not the default + otherwise, extends the default mappings with the provided user mappings + type: `boolean` + default: false + + - |view,mappings.list|: a list of keymaps that will extend or override the default keymaps + type: list of `{ key: table of strings or string, mode: string (vim-mode), cb: callback function as a string }` + default: {} ============================================================================== OPTIONS *nvim-tree-options* diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 053ceb23..94779f2e 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -12,15 +12,6 @@ local _config = { is_windows = vim.fn.has('win32') == 1 or vim.fn.has('win32unix') == 1, is_macos = vim.fn.has('mac') == 1 or vim.fn.has('macunix') == 1, is_unix = vim.fn.has('unix') == 1, - update_focused_file = { - enable = false, - update_cwd = false, - ignore_list = {}, - }, - system_open = {}, - ignore_ft_on_setup = {}, - open_on_setup = false, - update_to_buf_dir = true, } local M = {} @@ -302,7 +293,8 @@ function M.on_leave() end function M.open_on_directory() - if not (_config.update_to_buf_dir and (_config.open_on_setup or view.win_open())) then + local should_proceed = _config.update_to_buf_dir.auto_open or view.win_open() + if not _config.update_to_buf_dir.enable or not should_proceed then return end local buf = api.nvim_get_current_buf() @@ -408,7 +400,10 @@ local DEFAULT_OPTS = { hijack_netrw = true, open_on_setup = false, open_on_tab = false, - update_to_buf_dir = true, + update_to_buf_dir = { + enable = true, + auto_open = true, + }, auto_close = false, hijack_cursor = false, update_cwd = false, @@ -434,7 +429,15 @@ function M.setup(conf) _config.system_open = opts.system_open _config.open_on_setup = opts.open_on_setup _config.ignore_ft_on_setup = opts.ignore_ft_on_setup - _config.update_to_buf_dir = opts.update_to_buf_dir + if type(opts.update_to_buf_dir) == "boolean" then + require'nvim-tree.utils'.echo_warning("update_to_buf_dir is now a table, see :help nvim-tree.update_to_buf_dir") + _config.update_to_buf_dir = { + enable = opts.update_to_buf_dir, + auto_open = opts.update_to_buf_dir, + } + else + _config.update_to_buf_dir = opts.update_to_buf_dir + end require'nvim-tree.colors'.setup() require'nvim-tree.view'.setup(opts.view or {})