Document changes to ParseTable

pull/3/head release/0.6.0-rc1
Iron-E 4 years ago
parent 5d0a8be10e
commit b4eef027f5
No known key found for this signature in database
GPG Key ID: 19B71B7B7B021D22

@ -17,13 +17,13 @@ See: |libmodal-usage|, |lua|, |lua-require-example|.
2. `libmodal.classes` ..................... |libmodal-lua-classes|
3. `libmodal.collections` ................. |libmodal-lua-collections|
3.1. `libmodal.collections.ParseTable` ...... |libmodal-lua-ParseTable|
3.2. `libmodal.collections.Stack` ........... |libmodal-lua-Stack|
3.2. `libmodal.collections.Popup` ........... |libmodal-lua-Popup|
3.3. `libmodal.collections.Stack` ........... |libmodal-lua-Stack|
4. `libmodal.globals` ..................... |libmodal-lua-globals|
5. `libmodal.Indicator` ................... |libmodal-lua-Indicator|
5.1. `libmodal.Indicator.HighlightSegment` .. |libmodal-lua-HighlightSegment|
6. `libmodal.Layer` ....................... |libmodal-lua-Layer|
6. `libmodal.Mode` ........................ |libmodal-lua-Mode|
7.1. `libmodal.Mode.Popup` .................. |libmodal-lua-Popup|
7. `libmodal.Mode` ........................ |libmodal-lua-Mode|
8. `libmodal.Prompt` ...................... |libmodal-lua-Prompt|
9. `libmodal.utils` ....................... |libmodal-lua-utils|
9.1. `libmodal.utils.api` ................... |libmodal-lua-api|
@ -130,6 +130,51 @@ functions *libmodal-lua-ParseTable-functions*
------------------------------------------------------------------------------
FUNCTIONS *libmodal-lua-ParseTable-functions*
`ParseTable`.stringSplit({str}, {regex}) *libmodal-lua-ParseTable.stringSplit()*
Split some {str} into a `table` with a {regex} expression.
Parameters: ~
{str} The `string` to split.
{regex} The regex expression to split {str} with.
Return: ~
* The split {str} as a `table`.
Example: ~
>
local ParseTable = require('libmodal').collections.ParseTable
print(vim.inspect(ParseTable.stringSplit('testing split', ' ')))
<
`ParseTable`.parse({key}) *libmodal-lua-ParseTable.parse()*
Parse some {key} so that it can be stored by a `ParseTable` instance.
Note: this method can be locally overridden in order to change the
`ParseTable`'s behavior. Example:
>
local ParseTable = require('libmodal').collections.ParseTable
ParseTable.parse = function(key)
return ParseTable.splitString(key, ' ')
end
<
Parameters: ~
{key} The key of the `table` to parse.
Return: ~
* The parsed {key}. Should be a `table`.
Example: ~
>
local ParseTable = require('libmodal').collections.ParseTable
print(vim.inspect(ParseTable.parse('testkey')))
<
`ParseTable`.new({userTable}) *libmodal-lua-ParseTable.new()*
Create a new `ParseTable` from a user-defined `table` of combos.
@ -258,7 +303,111 @@ FUNCTIONS *libmodal-lua-ParseTable-functions*
{tableToUnite}.
==============================================================================
3.2. `libmodal.collections.Stack` *libmodal-lua-Stack*
3.2. `libmodal.collections.Popup` *libmodal-lua-Popup*
When `:enter()`ing a `Mode`, an |api-floatwin| is displayed at the bottom
right-hand corner of the screen. `libmodal.Mode.Popup` is responsible for
opening it and keeping updated.
Whenever a `Popup` is created, it is immediately opened. Additionally, it is
opened with the following options: >
local _winOpenOpts = {
['anchor'] = 'SW',
['col'] = api.nvim_get_option('columns') - 1,
['focusable'] = false,
['height'] = 1,
['relative'] = 'editor',
['row'] = api.nvim_get_option('lines')
- api.nvim_get_option('cmdheight')
- 1,
['style'] = 'minimal',
['width'] = 25,
}
<
------------------------------------------------------------------------------
VARIABLES *libmodal-lua-Popup-variables*
`Popup`.config *libmodal-lua-Popup.apiOptions*
The options used when opening a `Popup`.
Note: this can be overwritten to change the default behavior of `Popup`.
Type: ~
|nvim_open_win| {config} `table`.
Value: ~
>
{
['anchor'] = 'SW',
['col'] = api.nvim_get_option('columns') - 1,
['focusable'] = false,
['height'] = 1,
['relative'] = 'editor',
['row'] = api.nvim_get_option('lines')
- api.nvim_get_option('cmdheight')
- 1,
['style'] = 'minimal',
['width'] = 25
}
<
`self`.buffer *libmodal-lua-Popup.buffer*
The scratch buffer used by `Popup` to display text.
Type: ~
|nvim_create_buf| handle.
Value: ~
`vim.api.nvim_create_buf(false, true)`
`self`.window *libmodal-lua-Popup.window*
The window used to display the contents of `Popup.buffer`.
Type: ~
|nvim_open_win| handle.
Value: ~
`vim.api.nvim_open_win(self.buffer, false, Popup.config)`
------------------------------------------------------------------------------
FUNCTIONS *libmodal-lua-Popup-functions*
`self`:close() *libmodal-lua-Popup.close()*
Close the window that this `Popup` represents.
Note: All variables of `Popup` are de-initialized after this method.
`self`:refresh({inputBytes}) *libmodal-lua-Popup.refresh()*
Update the content of the `Popup` using an array-like `table` of
|char2nr|s.
Note: This is normally used to add what the user is typing. If you have a
`function` `Mode` {instruction}, then you can use `Popup` and this
function to manually show user input as it is typed.
Parameters: ~
{inputBytes} An array-like `table` of |char2nr|s to write to the
`Popup`.
`Popup`.new() *libmodal-lua-Popup.new()*
Create a new `Popup` and immediately open it.
Return: ~
* A new `Popup`.
See also: ~
|libmodal-lua-Popup| For the options used to spawn the window.
==============================================================================
4.2. `libmodal.collections.Stack` *libmodal-lua-Stack*
The `libmodal.collections.Stack` is a simple implementation of a Stack data
structure. It is designed with reuse of resources in mind, as
@ -921,109 +1070,6 @@ FUNCTIONS *libmodal-lua-Mode-functions*
|libmodal-mode| For more information, as all of the parameters are
the same.
==============================================================================
7.1. `libmodal.Mode.Popup` *libmodal-lua-Popup*
When `:enter()`ing a `Mode`, an |api-floatwin| is displayed at the bottom
right-hand corner of the screen. `libmodal.Mode.Popup` is responsible for
opening it and keeping updated.
Whenever a `Popup` is created, it is immediately opened. Additionally, it is
opened with the following options: >
local _winOpenOpts = {
['anchor'] = 'SW',
['col'] = api.nvim_get_option('columns') - 1,
['focusable'] = false,
['height'] = 1,
['relative'] = 'editor',
['row'] = api.nvim_get_option('lines')
- api.nvim_get_option('cmdheight')
- 1,
['style'] = 'minimal',
['width'] = 25,
}
<
------------------------------------------------------------------------------
VARIABLES *libmodal-lua-Popup-variables*
`Popup`.config *libmodal-lua-Popup.apiOptions*
The options used when opening a `Popup`.
Note: this can be overwritten to change the default behavior of `Popup`.
Type: ~
|nvim_open_win| {config} `table`.
Value: ~
>
{
['anchor'] = 'SW',
['col'] = api.nvim_get_option('columns') - 1,
['focusable'] = false,
['height'] = 1,
['relative'] = 'editor',
['row'] = api.nvim_get_option('lines')
- api.nvim_get_option('cmdheight')
- 1,
['style'] = 'minimal',
['width'] = 25
}
<
`self`.buffer *libmodal-lua-Popup.buffer*
The scratch buffer used by `Popup` to display text.
Type: ~
|nvim_create_buf| handle.
Value: ~
`vim.api.nvim_create_buf(false, true)`
`self`.window *libmodal-lua-Popup.window*
The window used to display the contents of `Popup.buffer`.
Type: ~
|nvim_open_win| handle.
Value: ~
`vim.api.nvim_open_win(self.buffer, false, Popup.config)`
------------------------------------------------------------------------------
FUNCTIONS *libmodal-lua-Popup-functions*
`self`:close() *libmodal-lua-Popup.close()*
Close the window that this `Popup` represents.
Note: All variables of `Popup` are de-initialized after this method.
`self`:refresh({inputBytes}) *libmodal-lua-Popup.refresh()*
Update the content of the `Popup` using an array-like `table` of
|char2nr|s.
Note: This is normally used to add what the user is typing. If you have a
`function` `Mode` {instruction}, then you can use `Popup` and this
function to manually show user input as it is typed.
Parameters: ~
{inputBytes} An array-like `table` of |char2nr|s to write to the
`Popup`.
`Popup`.new() *libmodal-lua-Popup.new()*
Create a new `Popup` and immediately open it.
Return: ~
* A new `Popup`.
See also: ~
|libmodal-lua-Popup| For the options used to spawn the window.
==============================================================================
8. `libmodal.Prompt` *libmodal-lua-Prompt*

@ -714,6 +714,23 @@ When submitting an issue, please describe the following:
* New class `libmodal.Layer`.
* New function `libmodal.layer.enter()`.
* New examples for new additions.
* `libmodal.collections.ParseTable`:
* Added new `:parseGet()` method to replace the `:get()`
implementation.
*
* Added new `libmodal.collections.ParseTable.parse()` method.
* You can override it to change how the `ParseTable` parses its keys.
* Added `ParseTable.stringSplit()`.
Breaking Changes: ~
* Moved `libmodal.Mode.Popup` to `libmodal.collections.Popup`.
* Changed `libmodal.collections.ParseTable.parseGet()` back to
`libmodal.collections.ParseTable.get()`.
* `:get()` requires that keys have been parsed according to
`.parse()`.
Changes: ~
* Exposed more functionality of `libmodal.collections.Popup`.
0.5.0 ~

@ -10,9 +10,7 @@ local ParseTable = require('libmodal/src/collections/ParseTable')
local utils = require('libmodal/src/utils')
local Vars = require('libmodal/src/Vars')
local api = utils.api
local collections = nil
local api = utils.api
--[[
/*
@ -65,7 +63,7 @@ function _metaMode:_checkInputForMapping()
inputBytes[#inputBytes + 1] = self.input:nvimGet()
-- Get the command based on the users input.
local cmd = self.mappings:get(ParseTable.tableReverse(inputBytes))
local cmd = self.mappings:get(inputBytes)
-- Get the type of the command.
local commandType = type(cmd)

@ -4,7 +4,7 @@
*/
--]]
local globals = require('libmodal/src/globals')
local globals = require('libmodal/src/globals')
--[[
/*
@ -15,31 +15,31 @@ local globals = require('libmodal/src/globals')
local _REGEX_ALL = '.'
local ParseTable = {
['CR'] = 13, -- The number corresponding to <CR> in vim.
['TYPE'] = 'libmodal-parse-table'
}
-------------------------------------------
--[[ SUMMARY:
* Split some `str` over a `regex`.
]]
--[[ PARAMS:
* `str` => the string to split.
* `regex` => the regex to split `str` with.
]]
--[[ RETURNS:
* The split `str`.
]]
-------------------------------------------
function ParseTable.stringSplit(str, regex)
local split = {}
for char in string.gmatch(str, regex) do
split[#split + 1] = char
['CR'] = 13, -- The number corresponding to <CR> in vim.
['TYPE'] = 'libmodal-parse-table',
--------------------------------------
--[[ SUMMARY:
* Split some `str` over a `regex`.
]]
--[[ PARAMS:
* `str` => the string to split.
* `regex` => the regex to split `str` with.
]]
--[[ RETURNS:
* The split `str`.
]]
--------------------------------------
['stringSplit'] = function(str, regex)
local split = {}
for char in string.gmatch(str, regex) do
split[#split + 1] = char
end
return split
end
return split
end
}
-------------------------------------
----------------------------------
--[[ SUMMARY:
* Reverse the elements of some table.
]]
@ -49,8 +49,8 @@ end
--[[ RETURNS:
* The reversed `tbl`.
]]
-------------------------------------
function ParseTable.tableReverse(tbl)
----------------------------------
local function _table_reverse(tbl)
local reversed = {}
while #reversed < #tbl do
-- look, no variables!
@ -71,7 +71,7 @@ end
]]
------------------------------
function ParseTable.parse(key)
return ParseTable.stringSplit(string.reverse(key), _REGEX_ALL)
return ParseTable.stringSplit(key, _REGEX_ALL)
end
-----------------------------------------
@ -113,7 +113,7 @@ local function _get(parseTable, splitKey)
return nil
end
-----------------------------------------
------------------------------------------------
--[[ SUMMARY:
* Update the values of some `dict` using a `splitKey`.
]]
@ -121,8 +121,8 @@ end
* `parseTable` => the parseTable to update.
* `splitKey` => the key split into groups.
]]
-----------------------------------------
local function _put(parseTable, splitKey, value) -- †
------------------------------------------------
local function _put(parseTable, splitKey, value)
--[[ Get the next character in the table. ]]
local k = string.byte(table.remove(splitKey))
@ -141,7 +141,7 @@ local function _put(parseTable, splitKey, value) -- †
parseTable[k][ParseTable.CR] = value
else parseTable[k] = value -- parseTable[k] is not a table, go ahead and clobber the value.
end
end -- ‡
end
--[[
/*
@ -151,7 +151,7 @@ end -- ‡
local _metaParseTable = require('libmodal/src/classes').new(ParseTable.TYPE)
------------------------------------------
-------------------------------------
--[[ SUMMARY:
* Get a value from this `ParseTable`.
]]
@ -163,9 +163,9 @@ local _metaParseTable = require('libmodal/src/classes').new(ParseTable.TYPE)
* `table` => when the `key` partially mathes.
* `false` => when `key` is not ANYWHERE.
]]
------------------------------------------
-------------------------------------
function _metaParseTable:get(keyDict)
return _get(self, keyDict)
return _get(self, _table_reverse(keyDict))
end
--------------------------------------
@ -182,7 +182,7 @@ end
]]
--------------------------------------
function _metaParseTable:parseGet(key)
local parsedTable = ParseTable.parse(key)
local parsedTable = ParseTable.parse(string.reverse(key))
-- convert all of the strings to bytes.
for i, v in ipairs(parsedTable) do
@ -202,7 +202,7 @@ end
]]
---------------------------------------------
function _metaParseTable:parsePut(key, value)
_put(self, ParseTable.parse(key), value)
_put(self, ParseTable.parse(string.reverse(key)), value)
end
--------------------------------------------------

Loading…
Cancel
Save