Optimize module loading, update docs
parent
eb6f39b43a
commit
d8da47fa71
@ -1,7 +1,7 @@
|
|||||||
let s:barModeCombos = {
|
let s:barModeCombos = {
|
||||||
\ 'zf': 'split',
|
\ 'zf': 'split',
|
||||||
\ 'zfo': 'vsplit',
|
\ 'zfo': 'vsplit',
|
||||||
\ 'zfc': 'tabnew'
|
\ 'zfc': 'q'
|
||||||
\}
|
\}
|
||||||
|
|
||||||
call libmodal#Enter('BAR', s:barModeCombos)
|
call libmodal#Enter('BAR', s:barModeCombos)
|
||||||
|
@ -1,127 +0,0 @@
|
|||||||
--[[
|
|
||||||
/*
|
|
||||||
* MODULE
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
|
|
||||||
local ModeLayer = {['TYPE'] = 'libmodal-mode-layer'}
|
|
||||||
|
|
||||||
--[[
|
|
||||||
/*
|
|
||||||
* META `ModeLayer`
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
|
|
||||||
local _metaModeLayer = require('libmodal/src/classes').new(ModeLayer.TYPE)
|
|
||||||
|
|
||||||
function _metaModeLayer:map(keys, mapping)
|
|
||||||
local priorInstruction = self._priorInstruction
|
|
||||||
local layerInstruction = self._instruction
|
|
||||||
|
|
||||||
if priorInstruction then
|
|
||||||
local modeInstruction = self._mode._instruction
|
|
||||||
|
|
||||||
-- only save the value from `mode` when adding a new mapping.
|
|
||||||
if not layerInstruction[keys] then
|
|
||||||
priorInstruction[keys] = modeInstruction:parseGet(keys)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- map the keys to mode.
|
|
||||||
modeInstruction:parsePut(keys, mapping)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- add the keys to the instruction.
|
|
||||||
layerInstruction[keys] = mapping
|
|
||||||
end
|
|
||||||
|
|
||||||
function _metaModeLayer:unmap(keys)
|
|
||||||
local priorInstruction = self._priorInstruction or {}
|
|
||||||
local layerInstruction = self._instruction
|
|
||||||
|
|
||||||
if priorInstruction[keys] then
|
|
||||||
self._mode._instruction:parsePut(keys, priorInstruction[keys])
|
|
||||||
priorInstruction[keys] = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- remove `keys` from the instruction.
|
|
||||||
layerInstruction[keys] = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-------------------------------
|
|
||||||
--[[ SUMMARY:
|
|
||||||
* Enter the `ModeLayer`, replacing any conflicting mappings.
|
|
||||||
]]
|
|
||||||
-------------------------------
|
|
||||||
function _metaModeLayer:enter()
|
|
||||||
-- Create aliases.
|
|
||||||
local layerMode = self._mode
|
|
||||||
local layerInstruction = self._instruction
|
|
||||||
|
|
||||||
-- Create a new `priorInstruction`.
|
|
||||||
local priorInstruction = nil
|
|
||||||
|
|
||||||
if self._isTable then -- the layer is a table
|
|
||||||
local modeInstruction = mode._instruction
|
|
||||||
priorInstruction = {}
|
|
||||||
|
|
||||||
for keys, mapping in pairs(layerInstruction) do
|
|
||||||
priorInstruction[keys] = modeInstruction:parseGet(keys)
|
|
||||||
modeInstruction:parsePut(keys, mapping)
|
|
||||||
end
|
|
||||||
else -- the layer is a function
|
|
||||||
priorInstruction = layerMode._instruction
|
|
||||||
mode._instruction = layerInstruction
|
|
||||||
end
|
|
||||||
|
|
||||||
self._priorInstruction = priorInstruction
|
|
||||||
end
|
|
||||||
|
|
||||||
-------------------------------
|
|
||||||
--[[ SUMMARY:
|
|
||||||
* Exit the `ModeLayer`, and restore any overwritten mappings.
|
|
||||||
]]
|
|
||||||
-------------------------------
|
|
||||||
function _metaModeLayer:exit()
|
|
||||||
if self._isTable then
|
|
||||||
local modeInstruction = self._mode._instruction
|
|
||||||
|
|
||||||
for keys, mapping in pairs(self._priorInstruction) do
|
|
||||||
modeInstruction:parsePut(keys, mapping)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self._mode._instruction = self._priorInstruction
|
|
||||||
end
|
|
||||||
|
|
||||||
self._priorInstruction = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
/*
|
|
||||||
* CLASS `ModeLayer`
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
|
|
||||||
-----------------------------------------
|
|
||||||
--[[ SUMMARY:
|
|
||||||
* Create a new `ModeLayer`.
|
|
||||||
]]
|
|
||||||
-----------------------------------------
|
|
||||||
function ModeLayer.new(mode, instruction)
|
|
||||||
if require('libmodal/src/classes').type(mode) == require('libmodal/src/Mode').TYPE
|
|
||||||
and type(mode._instruction) == type(instruction)
|
|
||||||
then
|
|
||||||
return setmetatable(
|
|
||||||
{
|
|
||||||
['_isTable'] = type(instruction) == require('libmodal/src/globals').TYPE_TBL,
|
|
||||||
['_instruction'] = instruction,
|
|
||||||
['_mode'] = mode
|
|
||||||
}, _metaModeLayer
|
|
||||||
)
|
|
||||||
else
|
|
||||||
error('Either `mode` is not a `Mode`, '
|
|
||||||
.. 'or `instruction` is not the same type '
|
|
||||||
.. 'as it was when `mode` was created.'
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,101 +0,0 @@
|
|||||||
--[[
|
|
||||||
/*
|
|
||||||
* IMPORTS
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
|
|
||||||
local classes = require('libmodal/src/classes')
|
|
||||||
|
|
||||||
--[[
|
|
||||||
/*
|
|
||||||
* MODULE
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
|
|
||||||
local PromptLayer = {['TYPE'] = 'libmodal-prompt-layer'}
|
|
||||||
|
|
||||||
--[[
|
|
||||||
/*
|
|
||||||
* META `PromptLayer`
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
|
|
||||||
local _metaPromptLayer = classes.new(PromptLayer.TYPE)
|
|
||||||
|
|
||||||
-------------------------------
|
|
||||||
--[[ SUMMARY:
|
|
||||||
* Enter the `PromptLayer`, replacing any conflicting executes.
|
|
||||||
]]
|
|
||||||
-------------------------------
|
|
||||||
function _metaPromptLayer:enter()
|
|
||||||
-- Create aliases.
|
|
||||||
local layerPrompt = self._prompt
|
|
||||||
local layerInstruction = self._instruction
|
|
||||||
|
|
||||||
-- Create a new `priorInstruction`.
|
|
||||||
local priorInstruction = nil
|
|
||||||
|
|
||||||
if self._isTable then -- the layer is a table
|
|
||||||
local promptInstruction = prompt._instruction
|
|
||||||
priorInstruction = {}
|
|
||||||
|
|
||||||
for command, execute in pairs(layerInstruction) do
|
|
||||||
priorInstruction[command] = promptInstruction[command]
|
|
||||||
promptInstruction[command] = execute
|
|
||||||
end
|
|
||||||
else -- the layer is a function
|
|
||||||
priorInstruction = layerPrompt._instruction
|
|
||||||
prompt._instruction = layerInstruction
|
|
||||||
end
|
|
||||||
|
|
||||||
self._priorInstruction = priorInstruction
|
|
||||||
end
|
|
||||||
|
|
||||||
-------------------------------
|
|
||||||
--[[ SUMMARY:
|
|
||||||
* Exit the `PromptLayer`, and restore any overwritten executes.
|
|
||||||
]]
|
|
||||||
-------------------------------
|
|
||||||
function _metaPromptLayer:exit()
|
|
||||||
if self._isTable then
|
|
||||||
local promptInstruction = self._prompt._instruction
|
|
||||||
|
|
||||||
for command, execute in pairs(self._priorInstruction) do
|
|
||||||
promptInstruction[command] = execute
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self._prompt._instruction = self._priorInstruction
|
|
||||||
end
|
|
||||||
|
|
||||||
self._priorInstruction = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
/*
|
|
||||||
* CLASS `PromptLayer`
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
|
|
||||||
-----------------------------------------
|
|
||||||
--[[ SUMMARY:
|
|
||||||
* Create a new `PromptLayer`.
|
|
||||||
]]
|
|
||||||
-----------------------------------------
|
|
||||||
function PromptLayer.new(prompt, instruction)
|
|
||||||
if classes.type(prompt) == require('libmodal/src/Prompt').TYPE
|
|
||||||
and type(prompt._instruction) == type(instruction)
|
|
||||||
then
|
|
||||||
return setmetatable(
|
|
||||||
{
|
|
||||||
['_isTable'] = type(instruction) == require('libmodal/src/globals').TYPE_TBL,
|
|
||||||
['_instruction'] = instruction,
|
|
||||||
['_prompt'] = prompt
|
|
||||||
}, _metaPromptLayer
|
|
||||||
)
|
|
||||||
else
|
|
||||||
error('Either `prompt` is not a `Prompt`, '
|
|
||||||
.. 'or `instruction` is not the same type '
|
|
||||||
.. 'as it was when `prompt` was created.'
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,44 +1,37 @@
|
|||||||
--[[
|
return {
|
||||||
/*
|
-------------------------
|
||||||
* MODULE
|
--[[ SUMMARY:
|
||||||
*/
|
* Define a class-metatable.
|
||||||
--]]
|
]]
|
||||||
|
--[[
|
||||||
local classes = {}
|
* `name` => the name of the class.
|
||||||
|
* `base` => the base class to use (`{}` by default).
|
||||||
--------------------------
|
]]
|
||||||
--[[ SUMMARY:
|
-------------------------
|
||||||
* Define a class-metatable.
|
new = function(name, ...)
|
||||||
]]
|
-- set self to `base`, or `{}` if nil.
|
||||||
--[[
|
local self = unpack({...}) or {}
|
||||||
* `name` => the name of the class.
|
|
||||||
* `base` => the base class to use (`{}` by default).
|
-- set `__index`.
|
||||||
]]
|
if not self.__index then
|
||||||
--------------------------------
|
self.__index = self
|
||||||
function classes.new(name, ...)
|
end
|
||||||
-- set self to `base`, or `{}` if nil.
|
|
||||||
local self = unpack({...}) or {}
|
-- set `__type`.
|
||||||
|
self.__type = name
|
||||||
-- set `__index`.
|
|
||||||
if not self.__index then
|
return self
|
||||||
self.__index = self
|
end,
|
||||||
|
|
||||||
|
------------------
|
||||||
|
--[[ SUMMARY:
|
||||||
|
* Get the type of some value `v`, if it has one.
|
||||||
|
]]
|
||||||
|
--[[ PARAMS:
|
||||||
|
* `v` => the value to get the type of.
|
||||||
|
]]
|
||||||
|
------------------
|
||||||
|
type = function(v)
|
||||||
|
return v.__type or type(v)
|
||||||
end
|
end
|
||||||
|
}
|
||||||
-- set `__type`.
|
|
||||||
self.__type = name
|
|
||||||
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
------------------------
|
|
||||||
function classes.type(v)
|
|
||||||
return v.__type or type(v)
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
/*
|
|
||||||
* PUBLICIZE `classes`
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
|
|
||||||
return classes
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
local collections = {}
|
return {
|
||||||
|
['ParseTable'] = require('libmodal/src/collections/ParseTable'),
|
||||||
collections.ParseTable = require('libmodal/src/collections/ParseTable')
|
['Popup'] = require('libmodal/src/collections/Popup'),
|
||||||
collections.Stack = require('libmodal/src/collections/Stack')
|
['Stack'] = require('libmodal/src/collections/Stack')
|
||||||
|
}
|
||||||
return collections
|
|
||||||
|
@ -1,24 +1,10 @@
|
|||||||
--[[
|
return {
|
||||||
/*
|
['classes'] = require('libmodal/src/classes'),
|
||||||
* MODULE
|
['collections'] = require('libmodal/src/collections'),
|
||||||
*/
|
['globals'] = require('libmodal/src/globals'),
|
||||||
--]]
|
['Indicator'] = require('libmodal/src/Indicator'),
|
||||||
|
['Layer'] = require('libmodal/src/Layer'),
|
||||||
local libmodal = {}
|
['Mode'] = require('libmodal/src/Mode'),
|
||||||
|
['Prompt'] = require('libmodal/src/Prompt'),
|
||||||
libmodal.classes = require('libmodal/src/classes')
|
['utils'] = require('libmodal/src/utils')
|
||||||
libmodal.collections = require('libmodal/src/collections')
|
}
|
||||||
libmodal.globals = require('libmodal/src/globals')
|
|
||||||
libmodal.Indicator = require('libmodal/src/Indicator')
|
|
||||||
libmodal.Layer = require('libmodal/src/Layer')
|
|
||||||
libmodal.Mode = require('libmodal/src/Mode')
|
|
||||||
libmodal.Prompt = require('libmodal/src/Prompt')
|
|
||||||
libmodal.utils = require('libmodal/src/utils')
|
|
||||||
|
|
||||||
--[[
|
|
||||||
/*
|
|
||||||
* PUBLICIZE MODULE
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
|
|
||||||
return libmodal
|
|
||||||
|
Loading…
Reference in New Issue