Structural improvements; begin to implement mode.enter
parent
15d1320720
commit
b35e436abc
@ -0,0 +1,17 @@
|
|||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
local globals = {}
|
||||||
|
|
||||||
|
globals.VIM_FALSE = 0
|
||||||
|
globals.VIM_TRUE = 1
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* PUBLICIZE MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
return globals
|
||||||
|
|
@ -0,0 +1,17 @@
|
|||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
local base = {}
|
||||||
|
base.globals = require('libmodal/src/base/globals')
|
||||||
|
|
||||||
|
-- TODO
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* PUBLICIZE MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
return base
|
||||||
|
|
@ -1,35 +0,0 @@
|
|||||||
--[[
|
|
||||||
/*
|
|
||||||
* IMPORTS
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
local libmodal = require('libmodal/src')
|
|
||||||
|
|
||||||
--[[
|
|
||||||
/*
|
|
||||||
* MODULE
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
libmodal.mode = {}
|
|
||||||
|
|
||||||
--------------------------------
|
|
||||||
--[[ SUMMARY:
|
|
||||||
* Enter a mode.
|
|
||||||
]]
|
|
||||||
|
|
||||||
--[[ PARAMETERS:
|
|
||||||
* `args[1]` => the mode name.
|
|
||||||
* `args[2]` => the mode callback, or mode combo table.
|
|
||||||
* `args[3]` => optional exit supresion flag.
|
|
||||||
]]
|
|
||||||
--------------------------------
|
|
||||||
function libmodal.mode.enter(...)
|
|
||||||
local args = {...}
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
/*
|
|
||||||
* PUBLICIZE MODULE
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
return libmodal.mode
|
|
@ -0,0 +1,64 @@
|
|||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* IMPORTS
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local globals = require('libmodal/src/base/globals')
|
||||||
|
local utils = require('libmodal/src/utils')
|
||||||
|
local api = utils.api
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local mode = {}
|
||||||
|
|
||||||
|
--------------------------------
|
||||||
|
--[[ SUMMARY:
|
||||||
|
* Enter a mode.
|
||||||
|
]]
|
||||||
|
|
||||||
|
--[[ PARAMETERS:
|
||||||
|
* `args[1]` => the mode name.
|
||||||
|
* `args[2]` => the mode callback, or mode combo table.
|
||||||
|
* `args[3]` => optional exit supresion flag.
|
||||||
|
]]
|
||||||
|
--------------------------------
|
||||||
|
function mode.enter(...)
|
||||||
|
local args = {...}
|
||||||
|
|
||||||
|
--[[ VAR INIT ]]
|
||||||
|
|
||||||
|
-- Create the indicator for the mode.
|
||||||
|
local indicator = utils.Indicator:new(args[1])
|
||||||
|
-- Grab the state of the window.
|
||||||
|
local winState = utils.WindowState.new()
|
||||||
|
-- Convert the name into one that can be used for variables.
|
||||||
|
local modeName = string.lower(args[1])
|
||||||
|
local handleExitEvents = false
|
||||||
|
if #args > 2 and args[3] then
|
||||||
|
handleExitEvents = true
|
||||||
|
end
|
||||||
|
-- Determine whether a callback was specified, or a combo table.
|
||||||
|
local doTimeout = nil
|
||||||
|
if type(args[2]) == 'table' then
|
||||||
|
if api.nvim_exists('g', utils.vars.timeout.name(modeName)) then
|
||||||
|
doTimeout = utils.vars.get(vars.timeout, modeName)
|
||||||
|
else
|
||||||
|
doTimeout = utils.vars.libmodalTimeout
|
||||||
|
end
|
||||||
|
print(doTimeout)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* PUBLICIZE MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
mode.enter('test', {})
|
||||||
|
return mode
|
||||||
|
|
@ -1,60 +0,0 @@
|
|||||||
--[[
|
|
||||||
/*
|
|
||||||
* IMPORTS
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
local libmodal = require('libmodal/src')
|
|
||||||
|
|
||||||
--[[
|
|
||||||
/*
|
|
||||||
* MODULE
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
libmodal.utils = {}
|
|
||||||
libmodal.utils.Indicator = {}
|
|
||||||
libmodal.utils.Indicator.Entry = {}
|
|
||||||
|
|
||||||
--[[
|
|
||||||
/*
|
|
||||||
* INDICATOR
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
|
|
||||||
-----------------------------------------------
|
|
||||||
--[[ SUMMARY:
|
|
||||||
* Create a new `Indicator`.
|
|
||||||
]]
|
|
||||||
|
|
||||||
--[[ PARAMS:
|
|
||||||
* `modeName` => the name of the mode that this `Indicator` is for.
|
|
||||||
]]
|
|
||||||
-----------------------------------------------
|
|
||||||
function libmodal.utils.Indicator:new(modeName)
|
|
||||||
return {
|
|
||||||
self.Entry.new('LibmodalStar', '*')(),
|
|
||||||
self.Entry.new( 'None', '*' )(),
|
|
||||||
self.Entry.new( 'LibmodalPrompt', tostring(modeName) )(),
|
|
||||||
self.Entry.new('None', ' > ')(),
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
--[[ SUMMARY:
|
|
||||||
* Create a new `Indicator.Entry`.
|
|
||||||
]]
|
|
||||||
|
|
||||||
--[[ PARAMS:
|
|
||||||
* `hlgroup` => The `highlight-group` to be used for this `Indicator.Entry`.
|
|
||||||
* `str` => The text for this `Indicator.Entry`.
|
|
||||||
]]
|
|
||||||
--------------------------------------------------------
|
|
||||||
function libmodal.utils.Indicator.Entry.new(hlgroup, str)
|
|
||||||
return {hlgroup, str}
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
/*
|
|
||||||
* PUBLICIZE MODULE
|
|
||||||
*/
|
|
||||||
--]]
|
|
||||||
return libmodal.utils
|
|
@ -0,0 +1,33 @@
|
|||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
local Entry = {}
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* STRUCT `Entry`
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
--[[ SUMMARY:
|
||||||
|
* Create a new `Indicator.Entry`.
|
||||||
|
]]
|
||||||
|
|
||||||
|
--[[ PARAMS:
|
||||||
|
* `hlgroup` => The `highlight-group` to be used for this `Indicator.Entry`.
|
||||||
|
* `str` => The text for this `Indicator.Entry`.
|
||||||
|
]]
|
||||||
|
--------------------------------------------------------
|
||||||
|
function Entry.new(hlgroup, str)
|
||||||
|
return {hlgroup, str}
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* PUBLICIZE MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
return Entry
|
@ -0,0 +1,44 @@
|
|||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* IMPORTS
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
local Entry = require('libmodal/src/utils/Indicator/Entry')
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
local Indicator = {}
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* STRUCT `Indicator`
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
-----------------------------------------------
|
||||||
|
--[[ SUMMARY:
|
||||||
|
* Create a new `Indicator`.
|
||||||
|
]]
|
||||||
|
|
||||||
|
--[[ PARAMS:
|
||||||
|
* `modeName` => the name of the mode that this `Indicator` is for.
|
||||||
|
]]
|
||||||
|
-----------------------------------------------
|
||||||
|
function Indicator:new(modeName)
|
||||||
|
return {
|
||||||
|
Entry.new('LibmodalStar', '*'),
|
||||||
|
Entry.new( 'None', '*' ),
|
||||||
|
Entry.new( 'LibmodalPrompt', tostring(modeName) ),
|
||||||
|
Entry.new('None', ' > '),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* PUBLICIZE MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
return Indicator
|
@ -0,0 +1,33 @@
|
|||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* IMPORTS
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
local api = vim.api
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
local WindowState = {}
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* STRUCT `WindowState`
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
function WindowState.new()
|
||||||
|
return {
|
||||||
|
['height'] = api.nvim_get_option('winheight'),
|
||||||
|
['width'] = api.nvim_get_option('winwidth')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* PUBLICIZE MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
return WindowState
|
@ -0,0 +1,37 @@
|
|||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* IMPORTS
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local globals = require('libmodal/src/base/globals')
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local api = vim.api
|
||||||
|
|
||||||
|
-----------------------------------
|
||||||
|
--[[ SUMMARY:
|
||||||
|
* Check whether or not some variable exists.
|
||||||
|
]]
|
||||||
|
|
||||||
|
--[[
|
||||||
|
* `scope` => The scope of the variable (i.e. `g`, `l`, etc.)
|
||||||
|
* `var` => the variable to check for.
|
||||||
|
]]
|
||||||
|
-----------------------------------
|
||||||
|
function api.nvim_exists(scope, var)
|
||||||
|
return api.nvim_eval("exists('" .. scope .. ":" .. var .. "')") ~= globals.VIM_FALSE
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* PUBLICIZE MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
return api
|
@ -0,0 +1,19 @@
|
|||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local utils = {}
|
||||||
|
utils.api = require('libmodal/src/utils/api')
|
||||||
|
utils.Indicator = require('libmodal/src/utils/Indicator')
|
||||||
|
utils.WindowState = require('libmodal/src/utils/WindowState')
|
||||||
|
utils.vars = require('libmodal/src/utils/vars')
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* PUBLICIZE MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
return utils
|
@ -0,0 +1,74 @@
|
|||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* IMPORTS
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local api = vim.api
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local vars = {
|
||||||
|
combos = {},
|
||||||
|
input = {},
|
||||||
|
libmodalTimeout = api.nvim_get_var('libmodalTimeouts'),
|
||||||
|
timeout = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* HELPERS
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
-------------------------------
|
||||||
|
--[[ SUMMARY:
|
||||||
|
* Create a new entry in `vars`
|
||||||
|
]]
|
||||||
|
|
||||||
|
--[[ PARAMS:
|
||||||
|
* `keyName` => the name of the key used to refer to this variable in `vars`.
|
||||||
|
* `varName` => the name of the variable as it is stored in vim.
|
||||||
|
]]
|
||||||
|
-------------------------------
|
||||||
|
local function new(keyName, varName)
|
||||||
|
vars[keyName] = {
|
||||||
|
name = function(modeName)
|
||||||
|
return modeName .. varName
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-------------------------------
|
||||||
|
--[[ SUMMARY:
|
||||||
|
* Retrieve a variable value.
|
||||||
|
]]
|
||||||
|
|
||||||
|
--[[ PARAMS:
|
||||||
|
* `var` => the `vars.*` table to retrieve the value of.
|
||||||
|
* `modeName` => the mode name this value is being retrieved for.
|
||||||
|
]]
|
||||||
|
-------------------------------
|
||||||
|
function vars.get(var, modeName)
|
||||||
|
return api.nvim_get_vars(var.name(modeName))
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* VARS
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
new('combos' , 'ModeCombos')
|
||||||
|
new('input' , 'ModeInput')
|
||||||
|
new('timeout' , 'ModeTimeout')
|
||||||
|
|
||||||
|
--[[
|
||||||
|
/*
|
||||||
|
* PUBLICIZE MODULE
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
return vars
|
Loading…
Reference in New Issue