diff options
Diffstat (limited to 'runtime/lua')
| -rw-r--r-- | runtime/lua/vim/_meta.lua | 45 | 
1 files changed, 29 insertions, 16 deletions
| diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua index 1706956bca..59cf837a1d 100644 --- a/runtime/lua/vim/_meta.lua +++ b/runtime/lua/vim/_meta.lua @@ -10,29 +10,39 @@ local SET_TYPES = setmetatable({    GLOBAL = 2,  }, { __index = error }) -local options_info = {} -for _, v in pairs(a.nvim_get_all_options_info()) do -  options_info[v.name] = v -  if v.shortname ~= '' then -    options_info[v.shortname] = v +local options_info = nil +local buf_options = nil +local glb_options = nil +local win_options = nil + +local function _setup() +  if options_info ~= nil then +    return +  end +  options_info = {} +  for _, v in pairs(a.nvim_get_all_options_info()) do +    options_info[v.name] = v +    if v.shortname ~= '' then +      options_info[v.shortname] = v +    end    end -end -local get_scoped_options = function(scope) -  local result = {} -  for name, option_info in pairs(options_info) do -    if option_info.scope == scope then -      result[name] = true +  local function get_scoped_options(scope) +    local result = {} +    for name, option_info in pairs(options_info) do +      if option_info.scope == scope then +        result[name] = true +      end      end + +    return result    end -  return result +  buf_options = get_scoped_options('buf') +  glb_options = get_scoped_options('global') +  win_options = get_scoped_options('win')  end -local buf_options = get_scoped_options('buf') -local glb_options = get_scoped_options('global') -local win_options = get_scoped_options('win') -  local function make_meta_accessor(get, set, del, validator)    validator = validator or function()      return true @@ -90,6 +100,7 @@ do -- buffer option accessor      return make_meta_accessor(get, set, nil, function(k)        if type(k) == 'string' then +        _setup()          if win_options[k] then            error(string.format([['%s' is a window option, not a buffer option. See ":help %s"]], k, k))          elseif glb_options[k] then @@ -119,6 +130,7 @@ do -- window option accessor      return make_meta_accessor(get, set, nil, function(k)        if type(k) == 'string' then +        _setup()          if buf_options[k] then            error(string.format([['%s' is a buffer option, not a window option. See ":help %s"]], k, k))          elseif glb_options[k] then @@ -610,6 +622,7 @@ local create_option_metatable = function(set_type)    local set_mt, option_mt    local make_option = function(name, value) +    _setup()      local info = assert(options_info[name], 'Not a valid option name: ' .. name)      if type(value) == 'table' and getmetatable(value) == option_mt then | 
