1
1
local luv = vim .loop
2
2
local api = vim .api
3
3
4
- local lib = require ' nvim-tree.lib'
5
- local colors = require ' nvim-tree.colors'
6
- local renderer = require ' nvim-tree.renderer'
7
- local view = require ' nvim-tree.view'
8
- local utils = require ' nvim-tree.utils'
9
- local change_dir = require ' nvim-tree.actions.change-dir'
10
- local legacy = require ' nvim-tree.legacy'
4
+ local lib = require " nvim-tree.lib"
5
+ local colors = require " nvim-tree.colors"
6
+ local renderer = require " nvim-tree.renderer"
7
+ local view = require " nvim-tree.view"
8
+ local utils = require " nvim-tree.utils"
9
+ local change_dir = require " nvim-tree.actions.change-dir"
10
+ local legacy = require " nvim-tree.legacy"
11
11
12
12
local _config = {}
13
13
@@ -19,7 +19,7 @@ function M.focus()
19
19
end
20
20
21
21
--- @deprecated
22
- M .on_keypress = require ' nvim-tree.actions' .on_keypress
22
+ M .on_keypress = require ( " nvim-tree.actions" ) .on_keypress
23
23
24
24
function M .toggle (find_file , no_focus )
25
25
if view .is_visible () then
@@ -56,60 +56,59 @@ function M.open_replacing_current_buffer()
56
56
return
57
57
end
58
58
59
- local cwd = vim .fn .fnamemodify (bufname , ' :p:h' )
59
+ local cwd = vim .fn .fnamemodify (bufname , " :p:h" )
60
60
if not TreeExplorer or cwd ~= TreeExplorer .cwd then
61
61
lib .init (cwd )
62
62
end
63
- view .open_in_current_win ( { hijack_current_buf = false , resize = false })
64
- require " nvim-tree.renderer" .draw ()
65
- require " nvim-tree.actions.find-file" .fn (bufname )
63
+ view .open_in_current_win { hijack_current_buf = false , resize = false }
64
+ require ( " nvim-tree.renderer" ) .draw ()
65
+ require ( " nvim-tree.actions.find-file" ) .fn (bufname )
66
66
end
67
67
68
68
function M .tab_change ()
69
- if view .is_visible ( { any_tabpage = true }) then
69
+ if view .is_visible { any_tabpage = true } then
70
70
local bufname = vim .api .nvim_buf_get_name (0 )
71
- if bufname :match ( " Neogit" ) ~= nil or bufname :match ( " --graph" ) ~= nil then
71
+ if bufname :match " Neogit" ~= nil or bufname :match " --graph" ~= nil then
72
72
return
73
73
end
74
- view .open ( { focus_tree = false })
75
- require " nvim-tree.renderer" .draw ()
74
+ view .open { focus_tree = false }
75
+ require ( " nvim-tree.renderer" ) .draw ()
76
76
end
77
77
end
78
78
79
79
local function find_existing_windows ()
80
- return vim .tbl_filter (
81
- function (win )
82
- local buf = api .nvim_win_get_buf (win )
83
- return api .nvim_buf_get_name (buf ):match (" NvimTree" ) ~= nil
84
- end ,
85
- api .nvim_list_wins ()
86
- )
80
+ return vim .tbl_filter (function (win )
81
+ local buf = api .nvim_win_get_buf (win )
82
+ return api .nvim_buf_get_name (buf ):match " NvimTree" ~= nil
83
+ end , api .nvim_list_wins ())
87
84
end
88
85
89
86
local function is_file_readable (fname )
90
87
local stat = luv .fs_stat (fname )
91
- return stat and stat .type == " file" and luv .fs_access (fname , ' R ' )
88
+ return stat and stat .type == " file" and luv .fs_access (fname , " R " )
92
89
end
93
90
94
91
local function update_base_dir_with_filepath (filepath , bufnr )
95
- local ft = api .nvim_buf_get_option (bufnr , ' filetype' ) or " "
92
+ local ft = api .nvim_buf_get_option (bufnr , " filetype" ) or " "
96
93
for _ , value in pairs (_config .update_focused_file .ignore_list ) do
97
94
if utils .str_find (filepath , value ) or utils .str_find (ft , value ) then
98
95
return
99
96
end
100
97
end
101
98
102
99
if not vim .startswith (filepath , TreeExplorer .cwd ) then
103
- change_dir .fn (vim .fn .fnamemodify (filepath , ' :p:h' ))
100
+ change_dir .fn (vim .fn .fnamemodify (filepath , " :p:h" ))
104
101
end
105
102
end
106
103
107
104
function M .find_file (with_open , bufnr )
108
- if not with_open and not TreeExplorer then return end
105
+ if not with_open and not TreeExplorer then
106
+ return
107
+ end
109
108
110
109
bufnr = bufnr or api .nvim_get_current_buf ()
111
110
local bufname = api .nvim_buf_get_name (bufnr )
112
- local filepath = utils .canonical_path (vim .fn .fnamemodify (bufname , ' :p ' ))
111
+ local filepath = utils .canonical_path (vim .fn .fnamemodify (bufname , " :p " ))
113
112
if not is_file_readable (filepath ) then
114
113
return
115
114
end
@@ -123,19 +122,19 @@ function M.find_file(with_open, bufnr)
123
122
if _config .update_focused_file .update_cwd then
124
123
update_base_dir_with_filepath (filepath , bufnr )
125
124
end
126
- require " nvim-tree.actions.find-file" .fn (filepath )
125
+ require ( " nvim-tree.actions.find-file" ) .fn (filepath )
127
126
end )
128
127
end
129
128
130
129
M .resize = view .resize
131
130
132
131
local function should_abort_auto_close ()
133
132
local buf = api .nvim_get_current_buf ()
134
- local buftype = api .nvim_buf_get_option (buf , ' ft ' )
133
+ local buftype = api .nvim_buf_get_option (buf , " ft " )
135
134
local modified = vim .tbl_filter (function (b )
136
- return api .nvim_buf_get_option (b , ' modified' )
135
+ return api .nvim_buf_get_option (b , " modified" )
137
136
end , api .nvim_list_bufs ())
138
- return # modified > 0 or buftype :match ( ' Telescope' ) ~= nil
137
+ return # modified > 0 or buftype :match " Telescope" ~= nil
139
138
end
140
139
141
140
function M .auto_close ()
@@ -154,9 +153,9 @@ function M.auto_close()
154
153
return api .nvim_win_get_tabpage (w ) == curtab
155
154
end , windows )
156
155
if # windows == 1 then
157
- api .nvim_command ( ' :silent qa!' )
156
+ api .nvim_command " :silent qa!"
158
157
elseif # wins_in_tabpage == 1 then
159
- api .nvim_command ( ' :tabclose' )
158
+ api .nvim_command " :tabclose"
160
159
end
161
160
end , 50 )
162
161
end
@@ -199,23 +198,23 @@ function M.place_cursor_on_node()
199
198
local idx = vim .fn .stridx (line , node .name )
200
199
201
200
if idx >= 0 then
202
- api .nvim_win_set_cursor (0 , {cursor [1 ], idx })
201
+ api .nvim_win_set_cursor (0 , { cursor [1 ], idx })
203
202
end
204
203
end
205
204
206
205
function M .on_enter (netrw_disabled )
207
206
local bufnr = api .nvim_get_current_buf ()
208
207
local bufname = api .nvim_buf_get_name (bufnr )
209
- local buftype = api .nvim_buf_get_option (bufnr , ' filetype' )
208
+ local buftype = api .nvim_buf_get_option (bufnr , " filetype" )
210
209
local ft_ignore = _config .ignore_ft_on_setup
211
210
212
211
local stats = luv .fs_stat (bufname )
213
- local is_dir = stats and stats .type == ' directory'
212
+ local is_dir = stats and stats .type == " directory"
214
213
local cwd
215
214
if is_dir then
216
215
cwd = vim .fn .expand (bufname )
217
216
-- INFO: could potentially conflict with rooter plugins
218
- vim .cmd (" noautocmd cd " .. cwd )
217
+ vim .cmd (" noautocmd cd " .. cwd )
219
218
end
220
219
221
220
local lines = not is_dir and api .nvim_buf_get_lines (bufnr , 0 , - 1 , false ) or {}
@@ -236,7 +235,10 @@ function M.on_enter(netrw_disabled)
236
235
end
237
236
end
238
237
239
- local should_hijack = _config .hijack_directories .enable and _config .hijack_directories .auto_open and is_dir and not should_be_preserved
238
+ local should_hijack = _config .hijack_directories .enable
239
+ and _config .hijack_directories .auto_open
240
+ and is_dir
241
+ and not should_be_preserved
240
242
241
243
-- Session that left a NvimTree Buffer opened, reopen with it
242
244
local existing_tree_wins = find_existing_windows ()
@@ -249,7 +251,7 @@ function M.on_enter(netrw_disabled)
249
251
lib .open ()
250
252
251
253
if should_focus_other_window then
252
- vim .cmd ( " noautocmd wincmd p" )
254
+ vim .cmd " noautocmd wincmd p"
253
255
end
254
256
end
255
257
M .initialized = true
@@ -345,15 +347,15 @@ local DEFAULT_OPTS = {
345
347
enable = true ,
346
348
auto_open = true ,
347
349
},
348
- update_focused_file = {
350
+ update_focused_file = {
349
351
enable = false ,
350
352
update_cwd = false ,
351
- ignore_list = {}
353
+ ignore_list = {},
352
354
},
353
355
ignore_ft_on_setup = {},
354
356
system_open = {
355
- cmd = nil ,
356
- args = {}
357
+ cmd = nil ,
358
+ args = {},
357
359
},
358
360
diagnostics = {
359
361
enable = false ,
@@ -363,12 +365,12 @@ local DEFAULT_OPTS = {
363
365
info = " " ,
364
366
warning = " " ,
365
367
error = " " ,
366
- }
368
+ },
367
369
},
368
370
filters = {
369
371
dotfiles = false ,
370
372
custom = {},
371
- exclude = {}
373
+ exclude = {},
372
374
},
373
375
git = {
374
376
enable = true ,
@@ -385,8 +387,8 @@ local DEFAULT_OPTS = {
385
387
resize_window = false ,
386
388
window_picker = {
387
389
enable = true ,
388
- }
389
- }
390
+ },
391
+ },
390
392
},
391
393
}
392
394
@@ -395,7 +397,7 @@ local function merge_options(conf)
395
397
conf .hijack_directories = conf .update_to_buf_dir
396
398
conf .update_to_buf_dir = nil
397
399
end
398
- return vim .tbl_deep_extend (' force' , DEFAULT_OPTS , conf or {})
400
+ return vim .tbl_deep_extend (" force" , DEFAULT_OPTS , conf or {})
399
401
end
400
402
401
403
function M .setup (conf )
@@ -413,13 +415,13 @@ function M.setup(conf)
413
415
414
416
manage_netrw (opts .disable_netrw , opts .hijack_netrw )
415
417
416
- require ' nvim-tree.actions' .setup (opts )
417
- require ' nvim-tree.colors' .setup ()
418
- require ' nvim-tree.diagnostics' .setup (opts )
419
- require ' nvim-tree.explorer' .setup (opts )
420
- require ' nvim-tree.git' .setup (opts )
421
- require ' nvim-tree.view' .setup (opts )
422
- require ' nvim-tree.lib' .setup (opts )
418
+ require ( " nvim-tree.actions" ) .setup (opts )
419
+ require ( " nvim-tree.colors" ) .setup ()
420
+ require ( " nvim-tree.diagnostics" ) .setup (opts )
421
+ require ( " nvim-tree.explorer" ) .setup (opts )
422
+ require ( " nvim-tree.git" ) .setup (opts )
423
+ require ( " nvim-tree.view" ) .setup (opts )
424
+ require ( " nvim-tree.lib" ) .setup (opts )
423
425
424
426
setup_vim_commands ()
425
427
setup_autocommands (opts )
0 commit comments