feat(tab_change): introduce new option to filter buffer by bufname or ft
Also fixes changing tab by deferring the call on tab enter. New option `ignore_buf_on_tab_change` to avoid opening for some tabs. Some example could be neogit, vim fugitive, man pages ...
This commit is contained in:
parent
1e3c578eeb
commit
79434c2b3c
@ -167,6 +167,7 @@ Subsequent calls to setup will replace the previous configuration.
|
|||||||
open_on_setup = false,
|
open_on_setup = false,
|
||||||
open_on_setup_file = false,
|
open_on_setup_file = false,
|
||||||
open_on_tab = false,
|
open_on_tab = false,
|
||||||
|
ignore_buf_on_tab_change = {},
|
||||||
sort_by = "name",
|
sort_by = "name",
|
||||||
root_dirs = {},
|
root_dirs = {},
|
||||||
prefer_startup_root = false,
|
prefer_startup_root = false,
|
||||||
@ -364,11 +365,15 @@ Will ignore the buffer, when deciding to open the tree on setup.
|
|||||||
Type: `boolean`, Default: `false`
|
Type: `boolean`, Default: `false`
|
||||||
|
|
||||||
*nvim-tree.ignore_ft_on_setup*
|
*nvim-tree.ignore_ft_on_setup*
|
||||||
List of filetypes that will make `open_on_setup` not open.
|
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
|
You can use this option if you don't want the tree to open
|
||||||
in some scenarios (eg using vim startify).
|
in some scenarios (eg using vim startify).
|
||||||
Type: {string}, Default: `{}`
|
Type: {string}, Default: `{}`
|
||||||
|
|
||||||
|
*nvim-tree.ignore_buf_on_tab_change*
|
||||||
|
List of filetypes or buffer names that will prevent `open_on_tab` to open.
|
||||||
|
Type: {string}, Default: `{}`
|
||||||
|
|
||||||
*nvim-tree.auto_reload_on_write*
|
*nvim-tree.auto_reload_on_write*
|
||||||
Reloads the explorer every time a buffer is written to.
|
Reloads the explorer every time a buffer is written to.
|
||||||
Type: `boolean`, Default: `true`
|
Type: `boolean`, Default: `true`
|
||||||
|
|||||||
@ -122,8 +122,11 @@ end
|
|||||||
function M.tab_change()
|
function M.tab_change()
|
||||||
if view.is_visible { any_tabpage = true } then
|
if view.is_visible { any_tabpage = true } then
|
||||||
local bufname = api.nvim_buf_get_name(0)
|
local bufname = api.nvim_buf_get_name(0)
|
||||||
if bufname:match "Neogit" ~= nil or bufname:match "--graph" ~= nil then
|
local ft = api.nvim_buf_get_option(0, "ft")
|
||||||
return
|
for _, filter in ipairs(M.config.ignore_buf_on_tab_change) do
|
||||||
|
if bufname:match(filter) ~= nil or ft:match(filter) ~= nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
view.open { focus_tree = false }
|
view.open { focus_tree = false }
|
||||||
require("nvim-tree.renderer").draw()
|
require("nvim-tree.renderer").draw()
|
||||||
@ -350,7 +353,7 @@ local function setup_autocommands(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if opts.open_on_tab then
|
if opts.open_on_tab then
|
||||||
create_nvim_tree_autocmd("TabEnter", { callback = M.tab_change })
|
create_nvim_tree_autocmd("TabEnter", { callback = vim.schedule_wrap(M.tab_change) })
|
||||||
end
|
end
|
||||||
if opts.hijack_cursor then
|
if opts.hijack_cursor then
|
||||||
create_nvim_tree_autocmd("CursorMoved", { pattern = "NvimTree_*", callback = M.place_cursor_on_node })
|
create_nvim_tree_autocmd("CursorMoved", { pattern = "NvimTree_*", callback = M.place_cursor_on_node })
|
||||||
@ -424,6 +427,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
|||||||
open_on_setup = false,
|
open_on_setup = false,
|
||||||
open_on_setup_file = false,
|
open_on_setup_file = false,
|
||||||
open_on_tab = false,
|
open_on_tab = false,
|
||||||
|
ignore_buf_on_tab_change = {},
|
||||||
sort_by = "name",
|
sort_by = "name",
|
||||||
root_dirs = {},
|
root_dirs = {},
|
||||||
prefer_startup_root = false,
|
prefer_startup_root = false,
|
||||||
@ -665,6 +669,7 @@ function M.setup(conf)
|
|||||||
_config.open_on_setup_file = opts.open_on_setup_file
|
_config.open_on_setup_file = opts.open_on_setup_file
|
||||||
_config.ignore_buffer_on_setup = opts.ignore_buffer_on_setup
|
_config.ignore_buffer_on_setup = opts.ignore_buffer_on_setup
|
||||||
_config.ignore_ft_on_setup = opts.ignore_ft_on_setup
|
_config.ignore_ft_on_setup = opts.ignore_ft_on_setup
|
||||||
|
_config.ignore_buf_on_tab_change = opts.ignore_buf_on_tab_change
|
||||||
_config.hijack_directories = opts.hijack_directories
|
_config.hijack_directories = opts.hijack_directories
|
||||||
_config.hijack_directories.enable = _config.hijack_directories.enable and netrw_disabled
|
_config.hijack_directories.enable = _config.hijack_directories.enable and netrw_disabled
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user