Skip to content

Commit 4a598d3

Browse files
committed
Merge branch 'master' into sync-close-through-tabs
2 parents 43ee246 + e81742f commit 4a598d3

32 files changed

+307
-333
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ Setup should be run in a lua file or in a lua heredoc [:help lua-heredoc](https:
6262
vim.g.loaded_netrw = 1
6363
vim.g.loaded_netrwPlugin = 1
6464

65+
-- set termguicolors to enable highlight groups
66+
vim.opt.termguicolors = true
67+
6568
-- empty setup using defaults
6669
require("nvim-tree").setup()
6770

doc/nvim-tree-lua.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ Setup should be run in a lua file or in a |lua-heredoc| if using in a vim file.
6969
vim.g.loaded_netrw = 1
7070
vim.g.loaded_netrwPlugin = 1
7171

72+
-- set termguicolors to enable highlight groups
73+
vim.opt.termguicolors = true
74+
7275
-- empty setup using defaults
7376
require("nvim-tree").setup()
7477

@@ -1338,6 +1341,9 @@ Example (in your `init.vim`):
13381341
You should have 'termguicolors' enabled, otherwise, colors will not be
13391342
applied.
13401343

1344+
To view the active highlight groups run `:so $VIMRUNTIME/syntax/hitest.vim`
1345+
as per |:highlight|
1346+
13411347
Default linked group follows name.
13421348

13431349
NvimTreeSymlink

lua/nvim-tree.lua

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
local luv = vim.loop
2-
local api = vim.api
3-
41
local lib = require "nvim-tree.lib"
52
local log = require "nvim-tree.log"
63
local colors = require "nvim-tree.colors"
@@ -29,7 +26,7 @@ end
2926

3027
function M.change_root(filepath, bufnr)
3128
-- skip if current file is in ignore_list
32-
local ft = api.nvim_buf_get_option(bufnr, "filetype") or ""
29+
local ft = vim.api.nvim_buf_get_option(bufnr, "filetype") or ""
3330
for _, value in pairs(_config.update_focused_file.ignore_list) do
3431
if utils.str_find(filepath, value) or utils.str_find(ft, value) then
3532
return
@@ -75,7 +72,7 @@ function M.toggle(find_file, no_focus, cwd, bang)
7572
if view.is_visible() then
7673
M.close()
7774
else
78-
local previous_buf = api.nvim_get_current_buf()
75+
local previous_buf = vim.api.nvim_get_current_buf()
7976
M.open(cwd)
8077
if _config.update_focused_file.enable or find_file then
8178
M.find_file(false, previous_buf, bang)
@@ -106,8 +103,8 @@ function M.open_replacing_current_buffer(cwd)
106103
return
107104
end
108105

109-
local buf = api.nvim_get_current_buf()
110-
local bufname = api.nvim_buf_get_name(buf)
106+
local buf = vim.api.nvim_get_current_buf()
107+
local bufname = vim.api.nvim_buf_get_name(buf)
111108
if bufname == "" or vim.loop.fs_stat(bufname) == nil then
112109
return
113110
end
@@ -126,8 +123,8 @@ end
126123

127124
function M.tab_change()
128125
if view.is_visible { any_tabpage = true } then
129-
local bufname = api.nvim_buf_get_name(0)
130-
local ft = api.nvim_buf_get_option(0, "ft")
126+
local bufname = vim.api.nvim_buf_get_name(0)
127+
local ft = vim.api.nvim_buf_get_option(0, "ft")
131128
for _, filter in ipairs(M.config.ignore_buf_on_tab_change) do
132129
if bufname:match(filter) ~= nil or ft:match(filter) ~= nil then
133130
return
@@ -140,26 +137,26 @@ end
140137

141138
local function find_existing_windows()
142139
return vim.tbl_filter(function(win)
143-
local buf = api.nvim_win_get_buf(win)
144-
return api.nvim_buf_get_name(buf):match "NvimTree" ~= nil
145-
end, api.nvim_list_wins())
140+
local buf = vim.api.nvim_win_get_buf(win)
141+
return vim.api.nvim_buf_get_name(buf):match "NvimTree" ~= nil
142+
end, vim.api.nvim_list_wins())
146143
end
147144

148145
local function is_file_readable(fname)
149-
local stat = luv.fs_stat(fname)
150-
return stat and stat.type == "file" and luv.fs_access(fname, "R")
146+
local stat = vim.loop.fs_stat(fname)
147+
return stat and stat.type == "file" and vim.loop.fs_access(fname, "R")
151148
end
152149

153150
function M.find_file(with_open, bufnr, bang)
154151
if not with_open and not core.get_explorer() then
155152
return
156153
end
157154

158-
bufnr = bufnr or api.nvim_get_current_buf()
159-
if not api.nvim_buf_is_valid(bufnr) then
155+
bufnr = bufnr or vim.api.nvim_get_current_buf()
156+
if not vim.api.nvim_buf_is_valid(bufnr) then
160157
return
161158
end
162-
local bufname = api.nvim_buf_get_name(bufnr)
159+
local bufname = vim.api.nvim_buf_get_name(bufnr)
163160
local filepath = utils.canonical_path(vim.fn.fnamemodify(bufname, ":p"))
164161
if not is_file_readable(filepath) then
165162
return
@@ -186,8 +183,8 @@ function M.open_on_directory()
186183
return
187184
end
188185

189-
local buf = api.nvim_get_current_buf()
190-
local bufname = api.nvim_buf_get_name(buf)
186+
local buf = vim.api.nvim_get_current_buf()
187+
local bufname = vim.api.nvim_buf_get_name(buf)
191188
if vim.fn.isdirectory(bufname) ~= 1 then
192189
return
193190
end
@@ -203,7 +200,7 @@ end
203200

204201
local prev_line
205202
function M.place_cursor_on_node()
206-
local l = api.nvim_win_get_cursor(0)[1]
203+
local l = vim.api.nvim_win_get_cursor(0)[1]
207204
if l == prev_line then
208205
return
209206
end
@@ -214,22 +211,22 @@ function M.place_cursor_on_node()
214211
return
215212
end
216213

217-
local line = api.nvim_get_current_line()
218-
local cursor = api.nvim_win_get_cursor(0)
214+
local line = vim.api.nvim_get_current_line()
215+
local cursor = vim.api.nvim_win_get_cursor(0)
219216
local idx = vim.fn.stridx(line, node.name)
220217

221218
if idx >= 0 then
222-
api.nvim_win_set_cursor(0, { cursor[1], idx })
219+
vim.api.nvim_win_set_cursor(0, { cursor[1], idx })
223220
end
224221
end
225222

226223
function M.on_enter(netrw_disabled)
227-
local bufnr = api.nvim_get_current_buf()
228-
local bufname = api.nvim_buf_get_name(bufnr)
229-
local buftype = api.nvim_buf_get_option(bufnr, "filetype")
224+
local bufnr = vim.api.nvim_get_current_buf()
225+
local bufname = vim.api.nvim_buf_get_name(bufnr)
226+
local buftype = vim.api.nvim_buf_get_option(bufnr, "filetype")
230227
local ft_ignore = _config.ignore_ft_on_setup
231228

232-
local stats = luv.fs_stat(bufname)
229+
local stats = vim.loop.fs_stat(bufname)
233230
local is_dir = stats and stats.type == "directory"
234231
local is_file = stats and stats.type == "file"
235232
local cwd
@@ -239,7 +236,7 @@ function M.on_enter(netrw_disabled)
239236
vim.cmd("noautocmd cd " .. cwd)
240237
end
241238

242-
local lines = not is_dir and api.nvim_buf_get_lines(bufnr, 0, -1, false) or {}
239+
local lines = not is_dir and vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) or {}
243240
local buf_has_content = #lines > 1 or (#lines == 1 and lines[1] ~= "")
244241

245242
local buf_is_dir = is_dir and netrw_disabled
@@ -270,7 +267,7 @@ function M.on_enter(netrw_disabled)
270267
-- Session that left a NvimTree Buffer opened, reopen with it
271268
local existing_tree_wins = find_existing_windows()
272269
if existing_tree_wins[1] then
273-
api.nvim_set_current_win(existing_tree_wins[1])
270+
vim.api.nvim_set_current_win(existing_tree_wins[1])
274271
end
275272

276273
if should_open or should_hijack or existing_tree_wins[1] ~= nil then
@@ -302,27 +299,27 @@ local function manage_netrw(disable_netrw, hijack_netrw)
302299
end
303300

304301
local function setup_vim_commands()
305-
api.nvim_create_user_command("NvimTreeOpen", function(res)
302+
vim.api.nvim_create_user_command("NvimTreeOpen", function(res)
306303
M.open(res.args)
307304
end, { nargs = "?", complete = "dir" })
308-
api.nvim_create_user_command("NvimTreeClose", view.close, { bar = true })
309-
api.nvim_create_user_command("NvimTreeToggle", function(res)
305+
vim.api.nvim_create_user_command("NvimTreeClose", view.close, { bar = true })
306+
vim.api.nvim_create_user_command("NvimTreeToggle", function(res)
310307
M.toggle(false, false, res.args)
311308
end, { nargs = "?", complete = "dir" })
312-
api.nvim_create_user_command("NvimTreeFocus", M.focus, { bar = true })
313-
api.nvim_create_user_command("NvimTreeRefresh", reloaders.reload_explorer, { bar = true })
314-
api.nvim_create_user_command("NvimTreeClipboard", copy_paste.print_clipboard, { bar = true })
315-
api.nvim_create_user_command("NvimTreeFindFile", function(res)
309+
vim.api.nvim_create_user_command("NvimTreeFocus", M.focus, { bar = true })
310+
vim.api.nvim_create_user_command("NvimTreeRefresh", reloaders.reload_explorer, { bar = true })
311+
vim.api.nvim_create_user_command("NvimTreeClipboard", copy_paste.print_clipboard, { bar = true })
312+
vim.api.nvim_create_user_command("NvimTreeFindFile", function(res)
316313
M.find_file(true, nil, res.bang)
317314
end, { bang = true, bar = true })
318-
api.nvim_create_user_command("NvimTreeFindFileToggle", function(res)
315+
vim.api.nvim_create_user_command("NvimTreeFindFileToggle", function(res)
319316
M.toggle(true, false, res.args, res.bang)
320317
end, { bang = true, nargs = "?", complete = "dir" })
321-
api.nvim_create_user_command("NvimTreeResize", function(res)
318+
vim.api.nvim_create_user_command("NvimTreeResize", function(res)
322319
M.resize(res.args)
323320
end, { nargs = 1, bar = true })
324-
api.nvim_create_user_command("NvimTreeCollapse", collapse_all.fn, { bar = true })
325-
api.nvim_create_user_command("NvimTreeCollapseKeepBuffers", function()
321+
vim.api.nvim_create_user_command("NvimTreeCollapse", collapse_all.fn, { bar = true })
322+
vim.api.nvim_create_user_command("NvimTreeCollapseKeepBuffers", function()
326323
collapse_all.fn(true)
327324
end, { bar = true })
328325
end
@@ -336,10 +333,10 @@ function M.change_dir(name)
336333
end
337334

338335
local function setup_autocommands(opts)
339-
local augroup_id = api.nvim_create_augroup("NvimTree", { clear = true })
336+
local augroup_id = vim.api.nvim_create_augroup("NvimTree", { clear = true })
340337
local function create_nvim_tree_autocmd(name, custom_opts)
341338
local default_opts = { group = augroup_id }
342-
api.nvim_create_autocmd(name, vim.tbl_extend("force", default_opts, custom_opts))
339+
vim.api.nvim_create_autocmd(name, vim.tbl_extend("force", default_opts, custom_opts))
343340
end
344341

345342
-- reset highlights when colorscheme is changed
@@ -415,9 +412,9 @@ local function setup_autocommands(opts)
415412
create_nvim_tree_autocmd("BufEnter", {
416413
pattern = "NvimTree_*",
417414
callback = function()
418-
local bufnr = api.nvim_get_current_buf()
415+
local bufnr = vim.api.nvim_get_current_buf()
419416
vim.schedule(function()
420-
api.nvim_buf_call(bufnr, function()
417+
vim.api.nvim_buf_call(bufnr, function()
421418
vim.cmd [[norm! zz]]
422419
end)
423420
end)

lua/nvim-tree/actions/finders/find-file.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
local log = require "nvim-tree.log"
2-
local uv = vim.loop
32
local view = require "nvim-tree.view"
43
local utils = require "nvim-tree.utils"
54
local renderer = require "nvim-tree.renderer"
@@ -20,7 +19,7 @@ function M.fn(fname)
2019

2120
local ps = log.profile_start("find file %s", fname)
2221
-- always match against the real path
23-
local fname_real = uv.fs_realpath(fname)
22+
local fname_real = vim.loop.fs_realpath(fname)
2423
if not fname_real then
2524
return
2625
end

lua/nvim-tree/actions/finders/search-node.lua

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
local api = vim.api
2-
local uv = vim.loop
3-
41
local core = require "nvim-tree.core"
52
local filters = require "nvim-tree.explorer.filters"
63
local find_file = require("nvim-tree.actions.finders.find-file").fn
@@ -17,22 +14,22 @@ local function search(search_dir, input_path)
1714
local function iter(dir)
1815
local realpath, path, name, stat, handle, _
1916

20-
handle, _ = uv.fs_scandir(dir)
17+
handle, _ = vim.loop.fs_scandir(dir)
2118
if not handle then
2219
return
2320
end
2421

25-
realpath, _ = uv.fs_realpath(dir)
22+
realpath, _ = vim.loop.fs_realpath(dir)
2623
if not realpath or vim.tbl_contains(realpaths_searched, realpath) then
2724
return
2825
end
2926
table.insert(realpaths_searched, realpath)
3027

31-
name, _ = uv.fs_scandir_next(handle)
28+
name, _ = vim.loop.fs_scandir_next(handle)
3229
while name do
3330
path = dir .. "/" .. name
3431

35-
stat, _ = uv.fs_stat(path)
32+
stat, _ = vim.loop.fs_stat(path)
3633
if not stat then
3734
break
3835
end
@@ -50,7 +47,7 @@ local function search(search_dir, input_path)
5047
end
5148
end
5249

53-
name, _ = uv.fs_scandir_next(handle)
50+
name, _ = vim.loop.fs_scandir_next(handle)
5451
end
5552
end
5653

@@ -63,19 +60,19 @@ function M.fn()
6360
end
6461

6562
-- temporarily set &path
66-
local bufnr = api.nvim_get_current_buf()
67-
local path_existed, path_opt = pcall(api.nvim_buf_get_option, bufnr, "path")
68-
api.nvim_buf_set_option(bufnr, "path", core.get_cwd() .. "/**")
63+
local bufnr = vim.api.nvim_get_current_buf()
64+
local path_existed, path_opt = pcall(vim.api.nvim_buf_get_option, bufnr, "path")
65+
vim.api.nvim_buf_set_option(bufnr, "path", core.get_cwd() .. "/**")
6966

7067
vim.ui.input({ prompt = "Search: ", completion = "file_in_path" }, function(input_path)
7168
if not input_path or input_path == "" then
7269
return
7370
end
7471
-- reset &path
7572
if path_existed then
76-
api.nvim_buf_set_option(bufnr, "path", path_opt)
73+
vim.api.nvim_buf_set_option(bufnr, "path", path_opt)
7774
else
78-
api.nvim_buf_set_option(bufnr, "path", nil)
75+
vim.api.nvim_buf_set_option(bufnr, "path", nil)
7976
end
8077

8178
-- strip trailing slash

0 commit comments

Comments
 (0)