You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nvim-libmodal/lua/libmodal/src/Vars.lua

101 lines
1.8 KiB
Lua

--[[
/*
* IMPORTS
*/
--]]
local api = vim.api
local classes = require('libmodal/src/classes')
local globals = require('libmodal/src/globals')
--[[
/*
* MODULE
*/
--]]
4 years ago
local _TIMEOUT_GLOBAL_NAME = 'libmodalTimeouts'
4 years ago
local Vars = {
[_TIMEOUT_GLOBAL_NAME] = api.nvim_get_var(_TIMEOUT_GLOBAL_NAME),
['TYPE'] = 'libmodal-vars'
4 years ago
}
--[[
/*
* META `_metaVars`
*/
--]]
local _metaVars = classes.new(Vars.TYPE)
4 years ago
---------------------------------
--[[ SUMMARY:
* Get the name of `modeName`s global setting.
]]
--[[ PARAMS:
* `modeName` => the name of the mode.
]]
4 years ago
---------------------------------
function _metaVars:name()
return string.lower(self._modeName) .. self._varName
end
------------------------------------
--[[ SUMMARY:
* Retrieve a variable value.
]]
--[[ PARAMS:
* `modeName` => the mode name this value is being retrieved for.
]]
------------------------------------
4 years ago
function _metaVars:nvimGet()
return api.nvim_get_var(self:name())
end
-----------------------------------------
--[[ SUMMARY:
* Set a variable value.
]]
--[[ PARAMS:
* `modeName` => the mode name this value is being retrieved for.
* `val` => the value to set `self`'s Vimscript var to.
]]
-----------------------------------------
4 years ago
function _metaVars:nvimSet(val)
api.nvim_set_var(self:name(), val)
end
--[[
/*
* CLASS `VARS`
*/
--]]
--------------------------
--[[ SUMMARY:
* Create a new entry in `Vars`
]]
--[[ PARAMS:
* `keyName` => the name of the key used to refer to this variable in `Vars`.
]]
--------------------------
4 years ago
function Vars.new(keyName, modeName)
local self = setmetatable({}, _metaVars)
4 years ago
self._modeName = modeName
self._varName = 'Mode' .. string.upper(
string.sub(keyName, 0, 1)
) .. string.sub(keyName, 2)
return self
end
--[[
/*
* PUBLICIZE MODULE
*/
--]]
return Vars