Remove `name`

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

@ -780,7 +780,7 @@ FUNCTIONS *libmodal-lua-Layer-functions*
Example: ~ Example: ~
> >
local libmodal = require('libmodal') local libmodal = require('libmodal')
local layer = libmodal.Layer.new('FOO', { local layer = libmodal.Layer.new({
['n'] = { ['n'] = {
['gg'] = { ['gg'] = {
['rhs'] = G ['rhs'] = G
@ -814,7 +814,7 @@ FUNCTIONS *libmodal-lua-Layer-functions*
Example: ~ Example: ~
> >
local libmodal = require('libmodal') local libmodal = require('libmodal')
local layer = libmodal.Layer.new('FOO', { local layer = libmodal.Layer.new({
['n'] = { ['n'] = {
['gg'] = { ['gg'] = {
['rhs'] = G ['rhs'] = G
@ -850,7 +850,7 @@ FUNCTIONS *libmodal-lua-Layer-functions*
Example: ~ Example: ~
> >
local libmodal = require('libmodal') local libmodal = require('libmodal')
local layer = libmodal.Layer.new('FOO', { local layer = libmodal.Layer.new({
['n'] = { ['n'] = {
['gg'] = { ['gg'] = {
['rhs'] = G ['rhs'] = G
@ -888,7 +888,7 @@ FUNCTIONS *libmodal-lua-Layer-functions*
Example: ~ Example: ~
> >
local libmodal = require('libmodal') local libmodal = require('libmodal')
local layer = libmodal.Layer.new('FOO', { local layer = libmodal.Layer.new({
['n'] = { ['n'] = {
['gg'] = { ['gg'] = {
['rhs'] = G ['rhs'] = G
@ -910,29 +910,18 @@ FUNCTIONS *libmodal-lua-Layer-functions*
See also: ~ See also: ~
|libmodal-lua-Layer.enter()| How to enter the `Layer`. |libmodal-lua-Layer.enter()| How to enter the `Layer`.
`Layer`.new() *libmodal-lua-Layer.new()* `Layer`.new({keymap}) *libmodal-lua-Layer.new()*
Create a new `Layer` for `mappings`. Create a new `Layer` for `mappings`.
Parameters: ~ Parameters: ~
{name} The name of the `Layer`. {keymap} The list of |map|pings to replace.
{mappings} The list of |map|pings to replace.
Example: ~
>
local libmodal = require('libmodal')
local layer = libmodal.Layer.new('FOO', {
['n'] = {
['gg'] = {
['rhs'] = G
}
}
})
Returns: ~ Returns: ~
* A new `Layer`. * A new `Layer`.
<
See also: ~
|libmodal-layer| For more information about the parameters.
============================================================================== ==============================================================================
7. `libmodal.Mode` *libmodal-lua-Mode* 7. `libmodal.Mode` *libmodal-lua-Mode*

@ -176,7 +176,7 @@ FUNCTIONS *libmodal-usage-functions*
|libmodal-examples-mode| For examples of this function. |libmodal-examples-mode| For examples of this function.
`libmodal.layer`.enter({name}, {keymap}) *libmodal-layer* *libmodal.layer.enter()* `libmodal.layer`.enter({keymap}) *libmodal-layer* *libmodal.layer.enter()*
While a |libmodal-mode| ignores behavior that has not been explicitly While a |libmodal-mode| ignores behavior that has not been explicitly
defined, a |libmodal-layer| allows unrecognized |input| to be passed back defined, a |libmodal-layer| allows unrecognized |input| to be passed back
@ -187,14 +187,27 @@ FUNCTIONS *libmodal-usage-functions*
overwritten. overwritten.
Parameters: ~ Parameters: ~
{name} The name of the layer. {keymap} The keymap for the layer. General template is this: >
{keymap} The keymap for the layer. {
[<mode>] = {
[<lhs>] = {
['rhs'] = <rhs>,
<opts>
},
},
}
< Where {mode}, {lhs}, {rhs}, and {opts} are the same as in
|nvim_set_keymap()|
Return: ~ Return: ~
* The `function` used to undo changes made by the layer. * The `function` used to undo changes made by the layer.
See also: ~ See also: ~
|libmodal-examples-layers| For an example. |libmodal-examples-layers| For an example.
|nvim_set_keymap()| For more information about {keymap}.
*libmodal-prompt* *libmodal#Prompt()* *libmodal.prompt.enter()* *libmodal-prompt* *libmodal#Prompt()* *libmodal.prompt.enter()*
`libmodal.prompt`.enter({name}, {instruction} [, {completions}]) `libmodal.prompt`.enter({name}, {instruction} [, {completions}])
@ -437,23 +450,19 @@ LAYERS *libmodal-examples-layers*
> >
local libmodal = require('libmodal') local libmodal = require('libmodal')
-- create the keymap -- save the exit function
-- `gg` and `G` will be switched. local exitFunc = libmodal.layer.enter({
local layerKeymap = { ['n'] = { -- normal mode
['n'] = { ['gg'] = { -- remap `gg`
['gg'] = { ['rhs'] = 'G', -- map it to `G`
['rhs'] = 'G', ['noremap'] = true -- don't remap
['noremap'] = true
}, },
['G'] = { ['G'] = { -- remap `G`
['rhs'] = 'gg', ['rhs'] = 'gg', -- map it to `gg`
['noremap'] = true ['noremap'] = true -- don't remap
} }
} }
} })
-- save the exit function
local exitFunc = libmodal.layer.exit()
-- exit the mode in five seconds -- exit the mode in five seconds
vim.loop.new_timer():start(5000, 0, vim.loop.new_timer():start(5000, 0,

@ -1,7 +1,7 @@
local libmodal = require('libmodal') local libmodal = require('libmodal')
-- create a new layer. -- create a new layer.
local exitFunc = libmodal.layer.enter('FOO', { local exitFunc = libmodal.layer.enter({
['n'] = { -- normal mode mappings ['n'] = { -- normal mode mappings
['gg'] = { -- remap `gg` ['gg'] = { -- remap `gg`
['rhs'] = 'G', -- map it to `G` ['rhs'] = 'G', -- map it to `G`

@ -1,7 +1,7 @@
local libmodal = require('libmodal') local libmodal = require('libmodal')
-- create a new layer. -- create a new layer.
local layer = libmodal.Layer.new('FOO', { local layer = libmodal.Layer.new({
['n'] = { -- normal mode mappings ['n'] = { -- normal mode mappings
['gg'] = { -- remap `gg` ['gg'] = { -- remap `gg`
['rhs'] = 'G', -- map it to `G` ['rhs'] = 'G', -- map it to `G`

@ -12,8 +12,8 @@ local libmodal = require('libmodal/src')
*/ */
--]] --]]
libmodal.layer = {['enter'] = function(name, mappings) libmodal.layer = {['enter'] = function(keymap)
local layer = libmodal.Layer.new(name, mappings) local layer = libmodal.Layer.new(keymap)
layer:enter() layer:enter()
return function() layer:exit() end return function() layer:exit() end
end} end}

@ -48,7 +48,7 @@ local _metaLayer = require('libmodal/src/classes').new(Layer.TYPE)
--------------------------- ---------------------------
function _metaLayer:enter() function _metaLayer:enter()
if self._priorKeymap then if self._priorKeymap then
error('This layer has already been entered.') error('This layer has already been entered. `:exit()` before entering again.')
end end
-- add local aliases. -- add local aliases.
@ -227,19 +227,18 @@ end
----------------------------------------------------- -----------------------------------------------------
--[[ SUMMARY: --[[ SUMMARY:
* Create a new `Layer` for `commands`, `mappings`, and `options`. * Create a new `Layer` for the buffer-local keymap.
]] ]]
--[[ PARAMS: --[[ PARAMS:
* `name` => the name of the layer.
* `mappings` => the list of user mappings to replace. * `mappings` => the list of user mappings to replace.
]] ]]
--[[ RETURNS: --[[ RETURNS:
* A new `Layer`. * A new `Layer`.
]] ]]
----------------------------------------------------- -----------------------------------------------------
function Layer.new(name, mappings) function Layer.new(keymap)
return setmetatable( return setmetatable(
{['_keymap'] = mappings, ['name'] = name}, {['_keymap'] = keymap},
_metaLayer _metaLayer
) )
end end

Loading…
Cancel
Save