Begin work on dev documentation

pull/3/head
Iron-E 4 years ago
parent 3a23642798
commit 55629e77a0
No known key found for this signature in database
GPG Key ID: 19B71B7B7B021D22

@ -1,231 +1,258 @@
*libmodal-lua.txt* Create modes for Neovim Lua Referenc *libmodal-lua.txt* Create modes for Neovim Lua Referenc
*libmodal-lua* *libmodal-lua*
*nvim-libmodal-lua* *libmodal-dev*
1. libmodal ............................. |libmodal-lua-libmodal| =============================================================================
2. libmodal.mode ........................ |libmodal-lua-mode| 0. Table of Contents *libmodal-lua-toc*
2.1. libmodal.mode.ParseTable ............. |libmodal-lua-parsetable|
3. libmodal.prompt ...................... |libmodal-lua-prompt|
4. libmodal.utils ....................... |libmodal-lua-utils|
4.1. libmodal.utils.api ................... |libmodal-lua-api|
4.2. libmodal.utils.Indicator ............. |libmodal-lua-indicator|
4.3. libmodal.utils.Indicator.Entry ....... |libmodal-lua-entry|
4.4. libmodal.utils.vars .................. |libmodal-lua-vars|
4.5. libmodal.utils.WindowState ........... |libmodal-lua-windowstate|
1. `libmodal` ............................. |libmodal-lua-libmodal|
2. `libmodal.base.globals` ................ |libmodal-lua-globals|
3. `libmodal.mode.ParseTable` ............. |libmodal-lua-ParseTable|
4. `libmodal.utils` ....................... |libmodal-lua-utils|
4.1. `libmodal.utils.api` ................... |libmodal-lua-api|
4.2. `libmodal.utils.Help` .................. |libmodal-lua-Help|
4.3. `libmodal.utils.Indicator` ............. |libmodal-lua-Indicator|
4.3.1. `libmodal.utils.Indicator.Entry` ....... |libmodal-lua-Entry|
4.4. `libmodal.utils.vars` .................. |libmodal-lua-vars|
4.5. `libmodal.utils.WindowState` ........... |libmodal-lua-Windowstate|
============================================================================ ==============================================================================
1. `libmodal` *libmodal-lua-libmodal*
--[[ Modules: ~
/*
* MODULE `libmodal`
*/
--]]
libmodal = require('libmodal/src') * `libmodal`
libmodal.mode = require('libmodal/src/mode') * `libmodal.base`
libmodal.prompt = require('libmodal/src/prompt') * `libmodal.base.globals`
libmodal.utils = require('libmodal/src/utils') * `libmodal.mode`
* `libmodal.mode.ParseTable`
* `libmodal.prompt`
* `libmodal.utils`
* `libmodal.utils.api`
* `libmodal.utils.Help`
* `libmodal.utils.Indicator`
* `libmodal.utils.vars`
* `libmodal.utils.WindowState`
--[[ ==============================================================================
/* 2. `libmodal.base.globals` *libmodal-lua-globals*
* MODULE `libmodal.mode` %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
--]]
mode.ParseTable = require('libmodal/src/mode/ParseTable') TODO.
local _TIMEOUT_CHAR = 'ø' ==============================================================================
local _TIMEOUT_NR = string.byte(_TIMEOUT_CHAR) 3. `libmodal.mode.ParseTable` *libmodal-lua-ParseTable*
local _TIMEOUT_LEN = api.nvim_get_option('timeoutlen')
======================== A `ParseTable` is a pseudo-parse tree of a given user collection of
--[[ SUMMARY: keybinding:expression pairs.
* Enter a mode.
]]
--[[ PARAMS:
* `args[1]` => the mode name.
* `args[2]` => the mode callback, or mode combo table.
* `args[3]` => optional exit supresion flag.
]]
------------------------
function mode.enter(...)
--[[ See: |libmodal-mode| for more information.
/*
* MODULE `libmodal.mode.ParseTable` %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
--]]
-- The number corresponding to <CR> in vim. Variables ~
ParseTable.CR = 13 *libmodal-lua-ParseTable-variables*
================================== `ParseTable`.CR *libmodal-lua-ParseTable-CR*
--[[ SUMMARY:
* Create a new parse table from a user-defined table.
]]
--[[ PARAMS:
* `userTable` => the table of combos defined by the user.
]]
----------------------------------
function ParseTable.new(userTable)
================================ The character number for <CR>.
--[[ SUMMARY:
* Get a value from this `ParseTable`.
]]
--[[ PARAMS:
* `key` => the PARSED key to get.
]]
--[[
* `function` => when `key` is a full match.
* `table` => when the `key` partially mathes.
* `false` => when `key` is not ANYWHERE.
]]
--------------------------------
function parseTable:get(keyDict)
======================================== Value: ~
--[[ SUMMARY: 13
* Put `value` into the parse tree as `key`.
]]
--[[ PARAMS:
* `key` => the key that `value` is reffered to by.
* `value` => the value to store as `key`.
]]
----------------------------------------
function parseTable:parsePut(key, value)
=============================================
--[[ SUMMARY:
* Create the union of `self` and `tableToUnite`
]]
--[[ PARAMS:
* `tableToUnite` => the table to unite with `self.`
]]
---------------------------------------------
function parseTable:parsePutAll(tableToUnite)
--[[ Functions ~
/* *libmodal-lua-ParseTable-functions*
* MODULE `libmodal.prompt` %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
--]]
========================== `ParseTable`.new({userTable}) *libmodal-lua-ParseTable.new()*
--[[ SUMMARY:
* Enter a prompt.
]]
--[[ PARAMS:
* `args[1]` => the prompt name.
* `args[2]` => the prompt callback, or mode command table.
* `args[3]` => a completions table.
]]
--------------------------
function prompt.enter(...)
--[[ Create a new `ParseTable` from a user-defined `table` of combos.
/*
* MODULE `libmodal.utils` %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
--]]
local utils = {} All keys of a `ParseTable` are numbers of characters.
utils.api = require('libmodal/src/utils/api')
utils.Indicator = require('libmodal/src/utils/Indicator')
utils.vars = require('libmodal/src/utils/vars')
utils.WindowState = require('libmodal/src/utils/WindowState')
--[[ Parameters: ~
/* {userTable} the table of combos defined by the user (see
* FUNCTIONS `libmodal.mode.enter()`)
*/
--]]
==================================== Return: ~
--[[ SUMMARY: A new `ParseTable`.
* Show a default help table with `commands` and vim expressions.
]]
--[[ PARAMS:
* `commands` => the table of commands to vim expressions.
]]
------------------------------------
function utils.commandHelp(commands)
Example: ~
>
local libmodal = require('libmodal')
local userTable = {
['zf'] = "echo 'Hello!'"
['zfo'] = "tabnew"
}
================================== local parseTable = libmodal.mode.ParseTable.new(userTable)
--[[ SUMMARY: print(vim.inspect(parseTable))
* Show an error from `pcall()`. <
]]
--[[ PARAMS:
`pcallErr` => the error generated by `pcall()`.
]]
----------------------------------
function utils.showError(pcallErr)
--[[ See Also: ~
/* |char2nr|, |nr2char| For character to number conversion and vice
* MODULE `libmodal.utils.api` %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% versa.
*/
--]]
local api = vim.api |libmodal-mode| For information about {userTable}.
========================
--[[ SUMMARY:
* Make vim ring the visual/audio bell, if it is enabled.
]]
------------------------
function api.nvim_bell()
=========================== `self`:get({keyDict}) *libmodal-lua-ParseTable.get()*
--[[ SUMMARY:
* Echo a string to Vim.
]]
--[[ PARAMS:
* `str` => the string to echo.
]]
---------------------------
function api.nvim_echo(str)
==================================== Get a value from an instance of `ParseTable`.
--[[ SUMMARY:
* Check whether or not some variable exists.
]]
--[[ PARAMS:
* `scope` => The scope of the variable (i.e. `g`, `l`, etc.)
* `var` => the variable to check for.
]]
------------------------------------
function api.nvim_exists(scope, var)
========================= Parameters: ~
--[[ SUMMARY: {keyDict} a string of key characters as bytes.
* Gets one character of user input, as a number.
]]
--[[ REMARKS:
* This could also be:
```lua
local cmd = {
'"while 1"',
'"let c = getchar(0)"',
'"if empty(c)"',
'"sleep 20m"',
'"else"',
'"echo c"',
'"break"',
'"endif"',
'"endwhile"'
}
return tonumber(vim.api.nvim_call_function("execute",cmd)) Return: ~
``` A `function` {keyDict} is a full match.
However, I'm not sure if it would accidentally affect text. A `table` the {keyDict} partially matches.
]] * `false` {keyDict} is not ANYWHERE.
-------------------------
function api.nvim_input() Example: ~
>
-- Simulate user input.
local userInput = {122, 102} -- {'z', 'f'}
-- Create a dummy `ParseTable`.
local parseTable = libmodal.mode.ParseTable.new({
['zfo'] = 'echo "Hello!"'
})
-- Inspect it.
print(vim.inspect(parseTable))
-- this will return a `table`
local tbl = parseTable:get(userInput)
-- Inspect it to show the difference.
print(vim.inspect(tbl))
<
`self`:parsePut({key}, {value}) *libmodal-lua-ParseTable.parsePut()*
Put `value` into the parse tree as `key`.
Parameters: ~
{key} the key that {value} is reffered to by. A `char`, not a
`byte`.
{value} the value to store as {key}. A `string` to |execute|.
Example: ~
>
-- Create a dummy `ParseTable`.
local parseTable = libmodal.mode.ParseTable.new({
['zfo'] = 'echo "Hello!"'
})
-- Inspect it.
print(vim.inspect(parseTable))
-- this will return a `table`
parseTable:parsePut({'zfc', 'split'})
-- Inspect it to show the difference.
print(vim.inspect(parseTable))
<
See also: ~
|libmodal-lua-parsetable-parseputall| for how to put multiple {key}s
and {value}s at a time.
`self`:parsePutAll({tableToUnite}) *libmodal-lua-ParseTable.parsePutAll()*
Create the union of `self` and `tableToUnite`
Interally calls |libmodal-lua-parsetable-parseput| on every key:value pair
in {tableToUnite}.
Parameters: ~
{tableToUnite} the table to unite with `self.`
Example: ~
>
-- Create an empty `ParseTable`.
local parseTable = libmodal.mode.ParseTable.new({})
-- Create some dummy keybindings.
local unparsedUserKeybinds = {
['zfo'] = 'echo "Hello!"',
['zfc'] = 'split'
}
-- Add the dummy keybindings.
parseTable:parsePut(unparsedUserKeybinds)
-- Inspect it to show the difference.
print(vim.inspect(parseTable))
<
See also: ~
|libmodal-lua-parsetable-parseput| For more information on
{tableToUnite}.
=============================================================================
4. `libmodal.utils` *libmodal-lua-utils*
Provides extra utilities to the |libmodal| library.
Functions ~
`utils`.showError({pcallErr}) *libmodal-lua-utils.showError*
Show an error from `pcall()`.
Parameters: ~
{pcallErr} the error generated by `pcall()`.
=============================================================================
4.1. `libmodal.utils.api` *libmodal-lua-api*
Functions ~
`api`.nvim_bell() *libmodal-lua-api.nvim_bell()*
Make vim ring the visual/audio bell, if it is enabled.
See also: ~
'belloff' For bell settings.
'errorbells' For bell settings.
'visualbell' For bell settings.
`api`.nvim_exists({scope}, {var}) *libmodal-lua-api.nvim_exists()*
Check whether or not some |variable| exists.
Parameters: ~
{scope} The scope of the |variable| (i.e. `g:`, `l:`, etc.)
{var} The |variable| to check for.
Example: ~
>
local libmodal = require('libmodal')
libmodal.utils.api.nvim_command('unlet g:foo')
-- Note that the colon should not go after the scope identifier.
print(libmodal.utils.api.nvim_exists('g', 'foo')) -- false
<
`api`.nvim_input() *libmodal-lua-api.nvim_input()*
Gets one character of user input, as a number.
Uses |getchar()|.
Return: ~
One character of user input, as a number (byte).
Example: ~
>
local libmodal = require('libmodal')
local char = string.char(libmodal.utils.api.nvim_input())
-- … wait for user to press a character …
print(char)
<
CONTINUE HERE
`api`.nvim_lecho({hlTables}) *libmodal-lua-api.nvim_lecho()*
=================================
--[[ SUMMARY: --[[ SUMMARY:
* Echo a table of {`hlgroup`, `str`} tables. * Echo a table of {`hlgroup`, `str`} tables.
* Meant to be read as "nvim list echo". * Meant to be read as "nvim list echo".
@ -233,18 +260,16 @@ function api.nvim_input()
--[[ PARAMS: --[[ PARAMS:
* `hlTables` => the tables to echo with highlights. * `hlTables` => the tables to echo with highlights.
]] ]]
---------------------------------
function api.nvim_lecho(hlTables)
========================== `api`.nvim_redraw() *libmodal-lua-api.nvim_redraw()*
--[[ SUMMARY: --[[ SUMMARY:
* Run `mode` to refresh the screen. * Run `mode` to refresh the screen.
* The function was not named `nvim_mode` because that would be really confusing given the name of this plugin. * The function was not named `nvim_mode` because that would be really confusing given the name of this plugin.
]] ]]
--------------------------
function api.nvim_redraw()
====================================== `api`.nvim_show_err({title}, {msg}) *libmodal-lua-api.nvim_show_err()*
--[[ SUMMARY: --[[ SUMMARY:
* Show a `title` error. * Show a `title` error.
]] ]]
@ -252,51 +277,81 @@ function api.nvim_redraw()
* `title` => the title of the error. * `title` => the title of the error.
* `msg` => the message of the error. * `msg` => the message of the error.
]] ]]
--------------------------------------
function api.nvim_show_err(title, msg)
--[[ ==============================================================================
/* 4.2. `libmodal.utils.Help` *libmodal-lua-Help*
* MODULE `libmodal.utils.Indicator` %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
--]]
================================= TODO.
--[[ SUMMARY:
* Create a new `Indicator` for a mode.
]]
--[[ PARAMS:
* `modeName` => the name of the mode that this `Indicator` is for.
]]
---------------------------------
function Indicator.mode(modeName)
=================================== ==============================================================================
--[[ SUMMARY: 4.3. `libmodal.utils.Indicator` *libmodal-lua-Indicator*
* Create a new `Indicator` for a prompt.
]]
--[[ PARAMS:
* `modeName` => the name of the mode that this `Indicator` is for.
]]
-----------------------------------
function Indicator.prompt(modeName)
--[[ Functions ~
/*
* MODULE `libmodal.utils.Indicator.Entry` %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% `Indicator`.mode({modeName}) *libmodal-lua-Indicator.mode()*
*/
--]] Create a new `Indicator` for a mode.
Parameters: ~
{modeName} The name of the mode that this `Indicator` is for.
Example: ~
>
local libmodal = require('libmodal')
local indicator = libmodal.utils.Indicator.new('FOO')
libmodal.utils.api.nvim_lecho(indicator)
<
See also: ~
|libmodal-mode| For this function's use.
|libmodal-lua-api.nvim_lecho()| For effective |echo|ing of this
function.
`Indicator`.prompt({modeName}) *libmodal-lua-Indicator.prompt()*
Create a new `Indicator` for a prompt.
Parameters: ~
{modeName} The name of the mode that this `Indicator` is for.
Example: ~
>
local libmodal = require('libmodal')
local indicator = libmodal.utils.Indicator.new('FOO')
print(indicator) -- you can't use `nvim_lecho` with this one.
<
See also: ~
|libmodal-prompt| For this function's use.
================================
--[[ SUMMARY: ==============================================================================
* Create a new `Indicator.Entry`. 4.3.1. `libmodal.utils.Indicator.Entry` *libmodal-lua-Entry*
]]
--[[ PARAMS: Functions ~
* `hlgroup` => The `highlight-group` to be used for this `Indicator.Entry`.
* `str` => The text for this `Indicator.Entry`. `Entry`.new({hlgroup}, {str}) *libmodal-lua-Entry.new()*
]]
-------------------------------- Create a new `Indicator.Entry`.
function Entry.new(hlgroup, str)
Parameters: ~
{hlgroup} The |highlight-group| to be used for this `Indicator.Entry`.
{str} The text for this `Indicator.Entry`.
Return: ~
A new `Indicator.Entry`.
Example: ~
>
local libmodal = require('libmodal')
local entry = libmodal.utils.Indicator.Entry.new('Error', 'EXAMPLE!')
print(vim.inspect(entry))
<
==============================================================================
4.4. `libmodal.utils.vars` *libmodal-lua-vars*
CONTINUE HERE.
--[[ --[[
/* /*
@ -374,25 +429,30 @@ new('timeout' )
new('timer' ) new('timer' )
new('windows' ) new('windows' )
--[[ ==============================================================================
/* 4.5 `libmodal.utils.WindowState` *libmodal-lua-WindowState*
* MODULE `libmodal.utils.WindowState` %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
--]]
========================== `WindowState`.new() *libmodal-lua-WindowState.new()*
--[[ SUMMARY:
* Create a table representing the size of the current window.
]]
--[[ RETURNS:
* The new `WindowState`.
]]
--------------------------
function WindowState.new()
=========================== Create a table representing the size of the current window.
--[[ SUMMARY
* Restore the state of `self`. Return: ~
]] The new `WindowState`.
---------------------------
function winState:restore() Example: ~
>
local libmodal = require('libmodal')
local windowState = libmodal.utils.WindowState.new()
print(vim.inspect(windowState))
<
See also: ~
'winheight' The `height` property of a `WindowState`.
'winwidth' The `width` property of a `WindowState`.
`self`:restore() *libmodal-lua-WindowState.restore()*
Restore the state of this `WindowState`.
==============================================================================
vim:tw=78:ts=4:ft=help:norl:

@ -3,14 +3,13 @@
* MODULE * MODULE
*/ */
--]] --]]
local libmodal = require('libmodal/src') local libmodal = require('libmodal/src')
libmodal.mode = require('libmodal/src/mode')
libmodal.prompt = require('libmodal/src/prompt')
libmodal.utils = require('libmodal/src/utils')
--[[ --[[
/* /*
* PUBLICIZE MODULE * PUBLICIZE MODULE
*/ */
--]] --]]
return libmodal return libmodal

@ -14,5 +14,5 @@ libmodal.utils = require('libmodal/src/utils')
* PUBLICIZE MODULE * PUBLICIZE MODULE
*/ */
--]] --]]
return libmodal
return libmodal

@ -48,10 +48,8 @@ end
--------------------------------- ---------------------------------
local function _tableReverse(tbl) local function _tableReverse(tbl)
local reversed = {} local reversed = {}
local i = #tbl while #reversed < #tbl do
while i > 0 do reversed[#reversed + 1] = tbl[#tbl - #reversed]
reversed[#reversed + 1] = tbl[i]
i = i - 1
end end
return reversed return reversed
end end

@ -25,6 +25,7 @@ mode.ParseTable = require('libmodal/src/mode/ParseTable')
*/ */
--]] --]]
local _HELP = '?'
local _TIMEOUT_CHAR = 'ø' local _TIMEOUT_CHAR = 'ø'
local _TIMEOUT_NR = string.byte(_TIMEOUT_CHAR) local _TIMEOUT_NR = string.byte(_TIMEOUT_CHAR)
local _TIMEOUT_LEN = api.nvim_get_option('timeoutlen') local _TIMEOUT_LEN = api.nvim_get_option('timeoutlen')
@ -89,7 +90,11 @@ local function _comboSelect(modeName)
local clearUserInput = false local clearUserInput = false
-- if there was no matching command -- if there was no matching command
if cmd == false then clearUserInput = true if cmd == false then
if vars.help.instances[modeName] then
vars.help.instances[modeName]:show()
end
clearUserInput = true
-- The command was a table, meaning that it MIGHT match. -- The command was a table, meaning that it MIGHT match.
elseif commandType == globals.TYPE_TBL then elseif commandType == globals.TYPE_TBL then
-- Create a new timer -- Create a new timer
@ -147,6 +152,11 @@ local function _initCombos(modeName, comboTable)
vars.buffers.instances[modeName] = buf vars.buffers.instances[modeName] = buf
vars.windows.instances[modeName] = api.nvim_call_function('libmodal#_winOpen', {buf}) vars.windows.instances[modeName] = api.nvim_call_function('libmodal#_winOpen', {buf})
-- Determine if a default `Help` should be created.
if not comboTable[_HELP] then
vars.help.instances[modeName] = utils.Help.new(comboTable, 'KEY MAP')
end
-- Build the parse tree. -- Build the parse tree.
vars.combos.instances[modeName] = mode.ParseTable.new(comboTable) vars.combos.instances[modeName] = mode.ParseTable.new(comboTable)

@ -116,6 +116,7 @@ function prompt.enter(...)
end end
if not containedHelp then -- assign it. if not containedHelp then -- assign it.
completions[#completions + 1] = _HELP completions[#completions + 1] = _HELP
vars.help.instances[modeName] = utils.Help.new(args[2], 'COMMAND')
end end
elseif #args > 2 then -- assign completions as the custom completions table provided. elseif #args > 2 then -- assign completions as the custom completions table provided.
completions = args[3] completions = args[3]
@ -144,7 +145,7 @@ function prompt.enter(...)
if args[2][userInput] then -- there is a defined command for the input. if args[2][userInput] then -- there is a defined command for the input.
api.nvim_command(args[2][userInput]) api.nvim_command(args[2][userInput])
elseif userInput == _HELP then -- the user did not define a 'help' command, so use the default. elseif userInput == _HELP then -- the user did not define a 'help' command, so use the default.
utils.commandHelp(args[2]) vars.help.instances[modeName]:show()
else -- show an error. else -- show an error.
api.nvim_show_err(globals.DEFAULT_ERROR_MESSAGE, 'Unknown command') api.nvim_show_err(globals.DEFAULT_ERROR_MESSAGE, 'Unknown command')
end end

@ -0,0 +1,98 @@
--[[
/*
* CLASS `Help`
*/
--]]
local Help = {}
----------------------------------------
--[[ SUMMARY:
* Create a default help table with `commandsOrMaps` and vim expressions.
]]
--[[ PARAMS:
* `commandsOrMaps` => the table of commands or mappings to vim expressions.
]]
--[[ RETURNS:
* A new `Help`.
]]
----------------------------------------
function Help.new(commandsOrMaps, title)
-- find the longest key in the table.
local longestKey = 0
for k, v in pairs(commandsOrMaps) do
local len = string.len(k)
if len > longestKey then
longestKey = len
end
end
-- adjust the longest key length if the table header is longer.
if longestKey < string.len(title) then
longestKey = string.len(title)
end
-- define the separator for entries in the help table.
local SEPARATOR = ''
----------------------
--[[ SUMMARY:
* Align `tbl` according to the `longestKey`.
]]
--[[ PARAMS:
* `tbl` => the table to align.
]]
--[[ RETURNS:
* The aligned `tbl`.
]]
----------------------
function tabAlign(tbl)
local toPrint = {}
for k, v in pairs(tbl) do
toPrint[#toPrint + 1] = k
local i = longestKey - string.len(k)
while i > 0 do
toPrint[#toPrint + 1] = ' '
i = i - 1
end
toPrint[#toPrint + 1] = SEPARATOR .. v .. '\n'
end
return toPrint
end
-- define the separator for the help table.
local helpSeparator = {}
while #helpSeparator < string.len(title) do
helpSeparator[#helpSeparator + 1] = '-'
end
helpSeparator = table.concat(helpSeparator)
-- Create a new `Help`.
return {
[1] = ' ',
[2] = table.concat(tabAlign({
[title] = 'VIM EXPRESSION',
[helpSeparator] = '--------------'
})),
[3] = table.concat(tabAlign(commandsOrMaps)),
-----------------------
--[[ SUMMARY:
* Show the contents of this `Help`.
]]
-----------------------
show = function(__self)
for _, v in ipairs(__self) do
print(v)
end
vim.api.nvim_call_function('getchar', {})
end
}
end
--[[
/*
* PUBLICIZE `Help`.
*/
--]]
return Help

@ -24,18 +24,6 @@ function api.nvim_bell()
api.nvim_command('normal ' .. string.char(27)) -- escape char api.nvim_command('normal ' .. string.char(27)) -- escape char
end end
---------------------------
--[[ SUMMARY:
* Echo a string to Vim.
]]
--[[ PARAMS:
* `str` => the string to echo.
]]
---------------------------
function api.nvim_echo(str)
api.nvim_command("echo " .. tostring(str))
end
------------------------------------ ------------------------------------
--[[ SUMMARY: --[[ SUMMARY:
* Check whether or not some variable exists. * Check whether or not some variable exists.

@ -15,6 +15,7 @@ local globals = require('libmodal/src/base/globals')
local utils = {} local utils = {}
utils.api = require('libmodal/src/utils/api') utils.api = require('libmodal/src/utils/api')
utils.Help = require('libmodal/src/utils/Help')
utils.Indicator = require('libmodal/src/utils/Indicator') utils.Indicator = require('libmodal/src/utils/Indicator')
utils.vars = require('libmodal/src/utils/vars') utils.vars = require('libmodal/src/utils/vars')
utils.WindowState = require('libmodal/src/utils/WindowState') utils.WindowState = require('libmodal/src/utils/WindowState')
@ -25,71 +26,6 @@ utils.WindowState = require('libmodal/src/utils/WindowState')
*/ */
--]] --]]
------------------------------------
--[[ SUMMARY:
* Show a default help table with `commands` and vim expressions.
]]
--[[ PARAMS:
* `commands` => the table of commands to vim expressions.
]]
------------------------------------
function utils.commandHelp(commands)
-- find the longest key in the table.
local longestKey = 0
for k, v in pairs(commands) do
local len = string.len(k)
if len > longestKey then
longestKey = len
end
end
-- define the table header on the left side.
local LEFT_TBL_HEADER = 'COMMAND'
-- adjust the longest key length if the table header is longer.
if longestKey < string.len(LEFT_TBL_HEADER) then
longestKey = string.len(LEFT_TBL_HEADER)
end
-- define the separator for entries in the help table.
local SEPARATOR = ''
----------------------
--[[ SUMMARY:
* Align `tbl` according to the `longestKey`.
]]
--[[ PARAMS:
* `tbl` => the table to align.
]]
--[[ RETURNS:
* The aligned `tbl`.
]]
----------------------
function tabAlign(tbl)
local toPrint = {}
for k, v in pairs(tbl) do
toPrint[#toPrint + 1] = k
local i = longestKey - string.len(k)
while i > 0 do
toPrint[#toPrint + 1] = ' '
i = i - 1
end
toPrint[#toPrint + 1] = SEPARATOR .. v .. '\n'
end
return toPrint
end
-- print the table headers.
print(' '); print(table.concat(tabAlign({
[LEFT_TBL_HEADER] = 'VIM EXPRESSION',
['-------'] = '--------------'
})))
-- print the help table.
print(table.concat(tabAlign(commands)))
-- pause redrawing of the prompt.
api.nvim_call_function('getchar', {})
end
---------------------------------- ----------------------------------
--[[ SUMMARY: --[[ SUMMARY:
* Show an error from `pcall()`. * Show an error from `pcall()`.

@ -88,6 +88,7 @@ new('buffers' )
new('combos' ) new('combos' )
new('completions' ) new('completions' )
new('exit' ) new('exit' )
new('help' )
new('input' ) new('input' )
new('timeout' ) new('timeout' )
new('timer' ) new('timer' )

117
pee

@ -1,117 +0,0 @@
local api = vim.api
local libmodal = require('libmodal')
local barModeInputHistory = {}
local function clearHistory(indexToCheck)
if #barModeInputHistory >= indexToCheck then
barModeInputHistory = {}
end
end
function barMode()
barModeInputHistory[#barModeInputHistory + 1] = string.char(
api.nvim_get_var('barModeInput')
)
local index = 1
if barModeInputHistory[1] == 'z' then
if barModeInputHistory[2] == 'f' then
if barModeInputHistory[3] == 'o' then
api.nvim_command("echom 'It works!'")
else index = 3 end
else index = 2 end
end
clearHistory(index)
end
libmodal.mode.enter('BAR', barMode)
local libmodal = require('libmodal')
local barModeRecurse = 0
local barModeCombos = {
['z'] = 'lua barMode()'
}
function barMode()
barModeRecurse = barModeRecurse + 1
libmodal.mode.enter('BAR' .. barModeRecurse, barModeCombos)
barModeRecurse = barModeRecurse - 1
end
barMode()
local libmodal = require('libmodal')
local barModeCombos = {
[''] = 'echom "You cant exit using escape."',
['q'] = 'let g:barModeExit = 1'
}
vim.api.nvim_set_var('barModeExit', 0)
libmodal.mode.enter('BAR', barModeCombos, true)
local libmodal = require('libmodal')
local barModeCombos = {
['zf'] = 'split',
['zfo'] = 'vsplit',
['zfc'] = 'tabnew'
}
libmodal.mode.enter('BAR', barModeCombos)
local libmodal = require('libmodal')
local api = vim.api
local commandList = {'new', 'close', 'last'}
function barMode()
local userInput = vim.api.nvim_get_var('barModeInput')
if userInput == 'new' then
api.nvim_command('tabnew')
elseif userInput == 'close' then
api.nvim_command('tabclose')
elseif userInput == 'last' then
api.nvim_command('tablast')
end
end
libmodal.prompt.enter('BAR', barMode, commandList)
local libmodal = require('libmodal')
local commands = {
['new'] = 'tabnew',
['close'] = 'tabclose',
['last'] = 'tablast'
}
libmodal.prompt.enter('BAR', commands)
local libmodal = require('libmodal')
local barModeRecurse = 0
function barMode()
local userInput = string.char(vim.api.nvim_get_var(
'bar' .. tostring(barModeRecurse) .. 'ModeInput'
))
if userInput == 'z' then
barModeRecurse = barModeRecurse + 1
enter()
barModeRecurse = barModeRecurse - 1
end
end
function enter()
libmodal.mode.enter('BAR' .. barModeRecurse, barMode)
end
enter()
local libmodal = require('libmodal')
function barMode()
local userInput = string.char(
vim.api.nvim_get_var('barModeInput')
)
if userInput == '' then
vim.api.nvim_command("echom 'You cant leave using <Esc>.'")
elseif userInput == 'q' then
vim.api.nvim_set_var('barModeExit', true)
end
end
vim.api.nvim_set_var('barModeExit', 0)
libmodal.mode.enter('BAR', barMode, true)
Loading…
Cancel
Save