Skip to content

Commit ca0904e

Browse files
authored
chore: add utils.enumerate_options (#2953)
1 parent 5ad8762 commit ca0904e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lua/nvim-tree/utils.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,4 +571,32 @@ function M.is_executable(absolute_path)
571571
end
572572
end
573573

574+
---List of all option info/values
575+
---@param opts vim.api.keyset.option passed directly to vim.api.nvim_get_option_info2 and vim.api.nvim_get_option_value
576+
---@param was_set boolean filter was_set
577+
---@return { info: vim.api.keyset.get_option_info, val: any }[]
578+
function M.enumerate_options(opts, was_set)
579+
local res = {}
580+
581+
local infos = vim.tbl_filter(function(info)
582+
if opts.buf and info.scope ~= "buf" then
583+
return false
584+
elseif opts.win and info.scope ~= "win" then
585+
return false
586+
else
587+
return true
588+
end
589+
end, vim.api.nvim_get_all_options_info())
590+
591+
for _, info in vim.spairs(infos) do
592+
local _, info2 = pcall(vim.api.nvim_get_option_info2, info.name, opts)
593+
if not was_set or info2.was_set then
594+
local val = pcall(vim.api.nvim_get_option_value, info.name, opts)
595+
table.insert(res, { info = info2, val = val })
596+
end
597+
end
598+
599+
return res
600+
end
601+
574602
return M

0 commit comments

Comments
 (0)