@@ -2,142 +2,6 @@ local config = require("nvim-tree.config")
22
33local M = {}
44
5- local function setup_autocommands ()
6- local augroup_id = vim .api .nvim_create_augroup (" NvimTree" , { clear = true })
7-
8- vim .api .nvim_create_autocmd (" BufWipeout" , {
9- group = augroup_id ,
10- pattern = " NvimTree_*" ,
11- callback = function ()
12- require (" nvim-tree.view" ).wipeout ()
13- end ,
14- })
15-
16- if config .g .tab .sync .open then
17- vim .api .nvim_create_autocmd (" TabEnter" , {
18- group = augroup_id ,
19- callback = vim .schedule_wrap (function ()
20- require (" nvim-tree.actions.tree.open" ).tab_enter ()
21- end )
22- })
23- end
24-
25- if config .g .sync_root_with_cwd then
26- vim .api .nvim_create_autocmd (" DirChanged" , {
27- group = augroup_id ,
28- callback = function ()
29- require (" nvim-tree.actions.tree.change-dir" ).fn (vim .loop .cwd ())
30- end ,
31- })
32- end
33-
34- if config .g .update_focused_file .enable then
35- vim .api .nvim_create_autocmd (" BufEnter" , {
36- group = augroup_id ,
37- callback = function (event )
38- if type (config .g .update_focused_file .exclude ) == " function" and config .g .update_focused_file .exclude (event ) then
39- return
40- end
41- require (" nvim-tree.utils" ).debounce (" BufEnter:find_file" , config .g .view .debounce_delay , function ()
42- require (" nvim-tree.actions.tree.find-file" ).fn ()
43- end )
44- end ,
45- })
46- end
47-
48- if config .g .hijack_directories .enable and (config .g .disable_netrw or config .g .hijack_netrw ) then
49- vim .api .nvim_create_autocmd ({ " BufEnter" , " BufNewFile" }, {
50- group = augroup_id ,
51- nested = true ,
52- callback = function (data )
53- local bufname = vim .api .nvim_buf_get_name (data .buf )
54- if vim .fn .isdirectory (bufname ) == 1 then
55- require (" nvim-tree.actions.tree.open" ).open_on_directory (bufname )
56- end
57- end ,
58- })
59- end
60-
61- if config .g .view .centralize_selection then
62- vim .api .nvim_create_autocmd (" BufEnter" , {
63- group = augroup_id ,
64- pattern = " NvimTree_*" ,
65- callback = vim .schedule_wrap (function ()
66- vim .api .nvim_buf_call (0 , function ()
67- local is_term_mode = vim .api .nvim_get_mode ().mode == " t"
68- if is_term_mode then
69- return
70- end
71- vim .cmd ([[ norm! zz]] )
72- end )
73- end )
74- })
75- end
76-
77- if config .g .diagnostics .enable then
78- vim .api .nvim_create_autocmd (" DiagnosticChanged" , {
79- group = augroup_id ,
80- callback = function (ev )
81- require (" nvim-tree.diagnostics" ).update_lsp (ev )
82- end ,
83- })
84-
85- vim .api .nvim_create_autocmd (" User" , {
86- group = augroup_id ,
87- pattern = " CocDiagnosticChange" ,
88- callback = function ()
89- require (" nvim-tree.diagnostics" ).update_coc ()
90- end ,
91- })
92- end
93-
94- if config .g .view .float .enable and config .g .view .float .quit_on_focus_loss then
95- vim .api .nvim_create_autocmd (" WinLeave" , {
96- group = augroup_id ,
97- pattern = " NvimTree_*" ,
98- callback = function ()
99- if require (" nvim-tree.utils" ).is_nvim_tree_buf (0 ) then
100- require (" nvim-tree.view" ).close ()
101- end
102- end ,
103- })
104- end
105-
106- -- Handles event dispatch when tree is closed by `:q`
107- vim .api .nvim_create_autocmd (" WinClosed" , {
108- group = augroup_id ,
109- pattern = " *" ,
110- --- @param ev vim.api.keyset.create_autocmd.callback_args
111- callback = function (ev )
112- if not vim .api .nvim_buf_is_valid (ev .buf ) then
113- return
114- end
115- if vim .api .nvim_get_option_value (" filetype" , { buf = ev .buf }) == " NvimTree" then
116- require (" nvim-tree.events" )._dispatch_on_tree_close ()
117- end
118- end ,
119- })
120-
121- if config .g .renderer .full_name then
122- local group = vim .api .nvim_create_augroup (" nvim_tree_floating_node" , { clear = true })
123- vim .api .nvim_create_autocmd ({ " BufLeave" , " CursorMoved" }, {
124- group = group ,
125- pattern = { " NvimTree_*" },
126- callback = function ()
127- require (" nvim-tree.renderer.components.full-name" ).hide ()
128- end ,
129- })
130-
131- vim .api .nvim_create_autocmd ({ " CursorMoved" }, {
132- group = group ,
133- pattern = { " NvimTree_*" },
134- callback = function ()
135- require (" nvim-tree.renderer.components.full-name" ).show ()
136- end ,
137- })
138- end
139- end
140-
1415--- `require("nvim-tree").setup` must be called once to initialise nvim-tree.
1426---
1437--- Call again to apply a change in configuration without restarting Nvim.
@@ -173,7 +37,7 @@ function M.setup(config_user)
17337 require (" nvim-tree.view-state" ).initialize ()
17438
17539 -- idempotent au (re)definition
176- setup_autocommands ()
40+ require ( " nvim-tree.autocmd " ). global ()
17741
17842 -- subsequent calls to setup clear all state
17943 if vim .g .NvimTreeSetup == 1 then
0 commit comments