From 85214c7487fbeefbe249419c82b19f63b73676b5 Mon Sep 17 00:00:00 2001 From: Iron-E Date: Tue, 26 May 2020 15:48:44 -0400 Subject: [PATCH] Remove `name` --- doc/libmodal-lua.txt | 29 ++++++++--------------- doc/libmodal.txt | 43 +++++++++++++++++++++-------------- examples/lua/layer-simple.lua | 2 +- examples/lua/layer.lua | 2 +- lua/libmodal/init.lua | 4 ++-- lua/libmodal/src/Layer.lua | 9 ++++---- 6 files changed, 43 insertions(+), 46 deletions(-) diff --git a/doc/libmodal-lua.txt b/doc/libmodal-lua.txt index 657dd6d..25c31f4 100644 --- a/doc/libmodal-lua.txt +++ b/doc/libmodal-lua.txt @@ -780,7 +780,7 @@ FUNCTIONS *libmodal-lua-Layer-functions* Example: ~ > local libmodal = require('libmodal') - local layer = libmodal.Layer.new('FOO', { + local layer = libmodal.Layer.new({ ['n'] = { ['gg'] = { ['rhs'] = G @@ -814,7 +814,7 @@ FUNCTIONS *libmodal-lua-Layer-functions* Example: ~ > local libmodal = require('libmodal') - local layer = libmodal.Layer.new('FOO', { + local layer = libmodal.Layer.new({ ['n'] = { ['gg'] = { ['rhs'] = G @@ -850,7 +850,7 @@ FUNCTIONS *libmodal-lua-Layer-functions* Example: ~ > local libmodal = require('libmodal') - local layer = libmodal.Layer.new('FOO', { + local layer = libmodal.Layer.new({ ['n'] = { ['gg'] = { ['rhs'] = G @@ -888,7 +888,7 @@ FUNCTIONS *libmodal-lua-Layer-functions* Example: ~ > local libmodal = require('libmodal') - local layer = libmodal.Layer.new('FOO', { + local layer = libmodal.Layer.new({ ['n'] = { ['gg'] = { ['rhs'] = G @@ -910,29 +910,18 @@ FUNCTIONS *libmodal-lua-Layer-functions* See also: ~ |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`. Parameters: ~ - {name} The name of the `Layer`. - {mappings} The list of |map|pings to replace. - - Example: ~ -> - local libmodal = require('libmodal') - local layer = libmodal.Layer.new('FOO', { - ['n'] = { - ['gg'] = { - ['rhs'] = G - } - } - }) - + {keymap} The list of |map|pings to replace. Returns: ~ * A new `Layer`. -< + + See also: ~ + |libmodal-layer| For more information about the parameters. ============================================================================== 7. `libmodal.Mode` *libmodal-lua-Mode* diff --git a/doc/libmodal.txt b/doc/libmodal.txt index cc71c1e..ae704b4 100644 --- a/doc/libmodal.txt +++ b/doc/libmodal.txt @@ -176,7 +176,7 @@ FUNCTIONS *libmodal-usage-functions* |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 defined, a |libmodal-layer| allows unrecognized |input| to be passed back @@ -187,14 +187,27 @@ FUNCTIONS *libmodal-usage-functions* overwritten. Parameters: ~ - {name} The name of the layer. - {keymap} The keymap for the layer. + {keymap} The keymap for the layer. General template is this: > + { + [] = { + [] = { + ['rhs'] = , + + }, + … + }, + … + } +< Where {mode}, {lhs}, {rhs}, and {opts} are the same as in + |nvim_set_keymap()| + Return: ~ * The `function` used to undo changes made by the layer. See also: ~ |libmodal-examples-layers| For an example. + |nvim_set_keymap()| For more information about {keymap}. *libmodal-prompt* *libmodal#Prompt()* *libmodal.prompt.enter()* `libmodal.prompt`.enter({name}, {instruction} [, {completions}]) @@ -437,23 +450,19 @@ LAYERS *libmodal-examples-layers* > local libmodal = require('libmodal') - -- create the keymap - -- `gg` and `G` will be switched. - local layerKeymap = { - ['n'] = { - ['gg'] = { - ['rhs'] = 'G', - ['noremap'] = true + -- save the exit function + local exitFunc = libmodal.layer.enter({ + ['n'] = { -- normal mode + ['gg'] = { -- remap `gg` + ['rhs'] = 'G', -- map it to `G` + ['noremap'] = true -- don't remap }, - ['G'] = { - ['rhs'] = 'gg', - ['noremap'] = true + ['G'] = { -- remap `G` + ['rhs'] = 'gg', -- map it to `gg` + ['noremap'] = true -- don't remap } } - } - - -- save the exit function - local exitFunc = libmodal.layer.exit() + }) -- exit the mode in five seconds vim.loop.new_timer():start(5000, 0, diff --git a/examples/lua/layer-simple.lua b/examples/lua/layer-simple.lua index eadb696..b62ada2 100644 --- a/examples/lua/layer-simple.lua +++ b/examples/lua/layer-simple.lua @@ -1,7 +1,7 @@ local libmodal = require('libmodal') -- create a new layer. -local exitFunc = libmodal.layer.enter('FOO', { +local exitFunc = libmodal.layer.enter({ ['n'] = { -- normal mode mappings ['gg'] = { -- remap `gg` ['rhs'] = 'G', -- map it to `G` diff --git a/examples/lua/layer.lua b/examples/lua/layer.lua index a07bd77..ff59416 100644 --- a/examples/lua/layer.lua +++ b/examples/lua/layer.lua @@ -1,7 +1,7 @@ local libmodal = require('libmodal') -- create a new layer. -local layer = libmodal.Layer.new('FOO', { +local layer = libmodal.Layer.new({ ['n'] = { -- normal mode mappings ['gg'] = { -- remap `gg` ['rhs'] = 'G', -- map it to `G` diff --git a/lua/libmodal/init.lua b/lua/libmodal/init.lua index c4834e8..f489803 100644 --- a/lua/libmodal/init.lua +++ b/lua/libmodal/init.lua @@ -12,8 +12,8 @@ local libmodal = require('libmodal/src') */ --]] -libmodal.layer = {['enter'] = function(name, mappings) - local layer = libmodal.Layer.new(name, mappings) +libmodal.layer = {['enter'] = function(keymap) + local layer = libmodal.Layer.new(keymap) layer:enter() return function() layer:exit() end end} diff --git a/lua/libmodal/src/Layer.lua b/lua/libmodal/src/Layer.lua index 0ec75c0..5a6cbf9 100644 --- a/lua/libmodal/src/Layer.lua +++ b/lua/libmodal/src/Layer.lua @@ -48,7 +48,7 @@ local _metaLayer = require('libmodal/src/classes').new(Layer.TYPE) --------------------------- function _metaLayer:enter() if self._priorKeymap then - error('This layer has already been entered.') + error('This layer has already been entered. `:exit()` before entering again.') end -- add local aliases. @@ -227,19 +227,18 @@ end ----------------------------------------------------- --[[ SUMMARY: - * Create a new `Layer` for `commands`, `mappings`, and `options`. + * Create a new `Layer` for the buffer-local keymap. ]] --[[ PARAMS: - * `name` => the name of the layer. * `mappings` => the list of user mappings to replace. ]] --[[ RETURNS: * A new `Layer`. ]] ----------------------------------------------------- -function Layer.new(name, mappings) +function Layer.new(keymap) return setmetatable( - {['_keymap'] = mappings, ['name'] = name}, + {['_keymap'] = keymap}, _metaLayer ) end