Skip to content

chore/remove globals #1279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,9 @@ These are being migrated to the setup function incrementally, check [this issue]
```vim
" vimrc
let g:nvim_tree_git_hl = 1 "0 by default, will enable file highlight for git attributes (can be used without the icons).
let g:nvim_tree_highlight_opened_files = 1 "0 by default, will enable folder and file icon highlight for opened files/directories.
let g:nvim_tree_root_folder_modifier = ':~' "This is the default. See :help filename-modifiers for more options
let g:nvim_tree_add_trailing = 1 "0 by default, append a trailing slash to folder names
let g:nvim_tree_group_empty = 1 " 0 by default, compact folders that only contain a single folder into one node in the file tree
let g:nvim_tree_icon_padding = ' ' "one space by default, used for rendering the space between the icon and the filename. Use with caution, it could break rendering if you set an empty string depending on your font.
let g:nvim_tree_symlink_arrow = ' >> ' " defaults to ' ➛ '. used as a separator between symlinks' source and target.
let g:nvim_tree_respect_buf_cwd = 1 "0 by default, will change cwd of nvim-tree to that of new buffer's when opening nvim-tree.
let g:nvim_tree_create_in_closed_folder = 1 "0 by default, When creating files, sets the path of a file when cursor is on a closed folder to the parent folder when 0, and inside the folder when 1.
let g:nvim_tree_special_files = { 'README.md': 1, 'Makefile': 1, 'MAKEFILE': 1 } " List of filenames that gets highlighted with NvimTreeSpecialFile
let g:nvim_tree_show_icons = {
\ 'git': 1,
\ 'folders': 0,
Expand Down Expand Up @@ -146,6 +140,9 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
},
},
renderer = {
add_trailing = false,
highlight_opened_files = "none",
root_folder_modifier = ":~",
indent_markers = {
enable = false,
icons = {
Expand All @@ -157,7 +154,10 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
icons = {
webdev_colors = true,
git_placement = "before",
padding = " ",
symlink_arrow = " ➛ ",
},
special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
},
hijack_directories = {
enable = true,
Expand Down
77 changes: 33 additions & 44 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ Values may be functions. Warning: this may result in unexpected behaviour.
},
},
renderer = {
add_trailing = false,
highlight_opened_files = "none",
root_folder_modifier = ":~",
indent_markers = {
enable = false,
icons = {
Expand All @@ -125,7 +128,10 @@ Values may be functions. Warning: this may result in unexpected behaviour.
icons = {
webdev_colors = true,
git_placement = "before",
padding = " ",
symlink_arrow = " ➛ ",
},
special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
},
hijack_directories = {
enable = true,
Expand Down Expand Up @@ -420,6 +426,20 @@ Window / buffer setup.
*nvim-tree.renderer*
UI rendering setup

*nvim-tree.renderer.add_trailing*
Appends a trailing slash to folder names.
Type: `boolean`, Default: `false`

*nvim-tree.renderer.highlight_opened_files*
Highlight icons and/or names for opened files.
Value can be `"none"`, `"icon"`, `"name"` or `"all"`.
Type: `string`, Default: `"none"`

*nvim-tree.renderer.root_folder_modifier*
In what format to show root folder. See `:help filename-modifiers` for
available options.
Type: `string`, Default: `":~"`

*nvim-tree.renderer.indent_markers*
Configuration options for tree indent markers.

Expand All @@ -446,6 +466,19 @@ UI rendering setup
Note that the diagnostic signs will take precedence over the git signs.
Type: `after`, `before` or `signcolumn`, Default: `before`

*nvim-tree.renderer.icons.padding*
Inserted between icon and filename.
Use with caution, it could break rendering if you set an empty string depending on your font.
Type: `string`, Default: `" "`

*nvim-tree.renderer.icons.symlink_arrow*
Used as a separator between symlinks' source and target.
Type: `string`, Default: `" ➛ "`

*nvim-tree.renderer.special_files*
A list of filenames that gets highlighted with `NvimTreeSpecialFile`.
Type: `table`, Default: `{ "Cargo.toml", "Makefile", "README.md", "readme.md", }`

*nvim-tree.filters*
Filtering options.

Expand Down Expand Up @@ -601,17 +634,6 @@ if folder is 1, you can also set `folder_arrows = 1` to show small arrows
next to the folder icons but this will not work when you set
|renderer.indent_markers.enable| (because of UI conflict).

|g:nvim_tree_highlight_opened_files| *g:nvim_tree_highlight_opened_files*

Highlight icons and/or names for opened files and directories
Default is 0

Must be:
0: No highlight
1: Enable highligting for folders and file icons only.
2: Enable highligting for folders and file names only.
3: Enable highligting for folders and both file icons and names.

|g:nvim_tree_icons| *g:nvim_tree_icons*

You can set icons for:
Expand Down Expand Up @@ -655,44 +677,11 @@ You can set icons for:
You can enable file highlight for git attributes by setting this property.
This can be used with or without the icons.

|g:nvim_tree_root_folder_modifier| *g:nvim_tree_root_folder_modifier*

In what format to show root folder. See `:help filename-modifiers` for
available options.
Default is `:~`

|g:nvim_tree_add_trailing| *g:nvim_tree_add_trailing*

Can be 0 or 1. When 1, appends a trailing slash to folder names.
0 by default.

|g:nvim_tree_group_empty| *g:nvim_tree_group_empty*

Can be 0 or 1. When 1, folders that contain only one folder are grouped
together. 0 by default.

|g:nvim_tree_special_files| *g:nvim_tree_special_files*

A list of filenames that gets highlighted with `NvimTreeSpecialFile`.
default table is

>
{
["Cargo.toml"] = true,
Makefile = true,
["README.md"] = true,
["readme.md"] = true,
}
<

|g:nvim_tree_icon_padding| *g:nvim_tree_icon_padding*

One space by default, used for rendering the space between the icon and the filename. Use with caution, it could break rendering if you set an empty string depending on your font.

|g:nvim_tree_symlink_arrow| *g:nvim_tree_symlink_arrow*

Defaults to ' ➛ '. Used as a separator between symlinks' source and target.

|g:nvim_tree_respect_buf_cwd| *g:nvim_tree_respect_buf_cwd*

Can be 0 or 1. 0 by default.
Expand Down
6 changes: 6 additions & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
},
},
renderer = {
add_trailing = false,
highlight_opened_files = "none",
root_folder_modifier = ":~",
indent_markers = {
enable = false,
icons = {
Expand All @@ -383,7 +386,10 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
icons = {
webdev_colors = true,
git_placement = "before",
padding = " ",
symlink_arrow = " ➛ ",
},
special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
},
hijack_directories = {
enable = true,
Expand Down
53 changes: 53 additions & 0 deletions lua/nvim-tree/legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,59 @@ local g_migrations = {
o.renderer.indent_markers.enable = vim.g.nvim_tree_indent_markers == 1
end
end,

nvim_tree_add_trailing = function(o)
utils.table_create_missing(o, "renderer")
if o.renderer.add_trailing == nil then
o.renderer.add_trailing = vim.g.nvim_tree_add_trailing == 1
end
end,

nvim_tree_highlight_opened_files = function(o)
utils.table_create_missing(o, "renderer")
if o.renderer.highlight_opened_files == nil then
if vim.g.nvim_tree_highlight_opened_files == 1 then
o.renderer.highlight_opened_files = "icon"
elseif vim.g.nvim_tree_highlight_opened_files == 2 then
o.renderer.highlight_opened_files = "name"
elseif vim.g.nvim_tree_highlight_opened_files == 3 then
o.renderer.highlight_opened_files = "all"
end
end
end,

nvim_tree_root_folder_modifier = function(o)
utils.table_create_missing(o, "renderer")
if o.renderer.root_folder_modifier == nil then
o.renderer.root_folder_modifier = vim.g.nvim_tree_root_folder_modifier
end
end,

nvim_tree_special_files = function(o)
utils.table_create_missing(o, "renderer")
if o.renderer.special_files == nil and type(vim.g.nvim_tree_special_files) == "table" then
o.renderer.special_files = {}
for k, v in pairs(vim.g.nvim_tree_special_files) do
if v ~= 0 then
table.insert(o.renderer.special_files, k)
end
end
end
end,

nvim_tree_icon_padding = function(o)
utils.table_create_missing(o, "renderer.icons")
if o.renderer.icons.padding == nil then
o.renderer.icons.padding = vim.g.nvim_tree_icon_padding
end
end,

nvim_tree_symlink_arrow = function(o)
utils.table_create_missing(o, "renderer.icons")
if o.renderer.icons.symlink_arrow == nil then
o.renderer.icons.symlink_arrow = vim.g.nvim_tree_symlink_arrow
end
end,
}

local function refactored(opts)
Expand Down
26 changes: 10 additions & 16 deletions lua/nvim-tree/renderer/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function Builder:configure_trailing_slash(with_trailing)
return self
end

function Builder:configure_special_map(special_map)
self.special_map = special_map
function Builder:configure_special_files(special_files)
self.special_files = special_files
return self
end

Expand All @@ -50,14 +50,8 @@ function Builder:configure_filter(filter, prefix)
return self
end

function Builder:configure_opened_file_highlighting(level)
if level == 1 then
self.open_file_highlight = "icon"
elseif level == 2 then
self.open_file_highlight = "name"
elseif level == 3 then
self.open_file_highlight = "all"
end
function Builder:configure_opened_file_highlighting(highlight_opened_files)
self.highlight_opened_files = highlight_opened_files

return self
end
Expand Down Expand Up @@ -128,7 +122,7 @@ function Builder:_build_folder(node, padding, git_hl, git_icons_tbl)
end

local foldername_hl = "NvimTreeFolderName"
if self.special_map[node.absolute_path] then
if self.special_files[node.absolute_path] then
foldername_hl = "NvimTreeSpecialFolderName"
elseif node.open then
foldername_hl = "NvimTreeOpenedFolderName"
Expand Down Expand Up @@ -183,12 +177,12 @@ function Builder:_highlight_opened_files(node, offset, icon_length, git_icons_le
local from = offset
local to = offset

if self.open_file_highlight == "icon" then
if self.highlight_opened_files == "icon" then
to = from + icon_length
elseif self.open_file_highlight == "name" then
elseif self.highlight_opened_files == "name" then
from = offset + icon_length + git_icons_length
to = from + #node.name
elseif self.open_file_highlight == "all" then
elseif self.highlight_opened_files == "all" then
to = from + icon_length + git_icons_length + #node.name
end

Expand All @@ -209,15 +203,15 @@ function Builder:_build_file(node, padding, git_highlight, git_icons_tbl)
local col_start = offset + #icon + git_icons_length
local col_end = col_start + #node.name

if self.special_map[node.absolute_path] or self.special_map[node.name] then
if vim.tbl_contains(self.special_files, node.absolute_path) or vim.tbl_contains(self.special_files, node.name) then
self:_insert_highlight("NvimTreeSpecialFile", col_start, col_end)
elseif node.executable then
self:_insert_highlight("NvimTreeExecFile", col_start, col_end)
elseif self.picture_map[node.extension] then
self:_insert_highlight("NvimTreeImageFile", col_start, col_end)
end

local should_highlight_opened_files = self.open_file_highlight and vim.fn.bufloaded(node.absolute_path) > 0
local should_highlight_opened_files = self.highlight_opened_files and vim.fn.bufloaded(node.absolute_path) > 0
if should_highlight_opened_files then
self:_highlight_opened_files(node, offset, #icon, git_icons_length)
end
Expand Down
12 changes: 6 additions & 6 deletions lua/nvim-tree/renderer/components/icons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ local icon_config = require "nvim-tree.renderer.icon-config"

local M = { i = {} }

local function config_symlinks()
local function config_symlinks(config)
M.i.symlink = #M.icons.symlink > 0 and M.icons.symlink .. M.padding or ""
M.i.symlink_arrow = vim.g.nvim_tree_symlink_arrow or " ➛ "
M.i.symlink_arrow = config.symlink_arrow
end

local function empty()
Expand Down Expand Up @@ -78,14 +78,14 @@ local function config_folder_icon()
end
end

function M.reset_config(webdev_colors)
function M.reset_config(config)
M.configs = icon_config.get_config()
M.icons = M.configs.icons
M.padding = vim.g.nvim_tree_icon_padding or " "
M.devicons = M.configs.has_devicons and require "nvim-web-devicons" or nil
M.webdev_colors = webdev_colors
M.padding = config.padding
M.webdev_colors = config.webdev_colors

config_symlinks()
config_symlinks(config)
config_file_icon()
config_folder_icon()
end
Expand Down
Loading