@@ -661,32 +661,29 @@ function M.is_executable(absolute_path)
661661 end
662662end
663663
664- --- List of all option info/values
665- --- @param opts vim.api.keyset.option passed directly to vim.api.nvim_get_option_info2 and vim.api.nvim_get_option_value
666- --- @param was_set boolean filter was_set
667- --- @return { info : vim.api.keyset.get_option_info , val : any } []
668- function M .enumerate_options (opts , was_set )
669- local res = {}
670-
671- local infos = vim .tbl_filter (function (info )
672- if opts .buf and info .scope ~= " buf" then
673- return false
674- elseif opts .win and info .scope ~= " win" then
675- return false
664+ --- @class UtilEnumerateOptionsOpts
665+ --- @field keyset_opts vim.api.keyset.option
666+ --- @field was_set boolean ? as per vim.api.keyset.get_option_info
667+
668+ --- Option name/values
669+ --- @param opts UtilEnumerateOptionsOpts
670+ --- @return table<string , any>
671+ function M .enumerate_options (opts )
672+ -- enumerate all options, limiting buf and win scopes
673+ return vim .tbl_map (function (info )
674+ if opts .keyset_opts .buf and info .scope ~= " buf" then
675+ return nil
676+ elseif opts .keyset_opts .win and info .scope ~= " win" then
677+ return nil
676678 else
677- return true
679+ -- optional, lazy was_set check
680+ if not opts .was_set or vim .api .nvim_get_option_info2 (info .name , opts .keyset_opts ).was_set then
681+ return vim .api .nvim_get_option_value (info .name , opts .keyset_opts )
682+ else
683+ return nil
684+ end
678685 end
679686 end , vim .api .nvim_get_all_options_info ())
680-
681- for _ , info in vim .spairs (infos ) do
682- local _ , info2 = pcall (vim .api .nvim_get_option_info2 , info .name , opts )
683- if not was_set or info2 .was_set then
684- local val = pcall (vim .api .nvim_get_option_value , info .name , opts )
685- table.insert (res , { info = info2 , val = val })
686- end
687- end
688-
689- return res
690687end
691688
692689return M
0 commit comments