Merge branch 'feature/001--lua-runtime'

pull/14/head release/1.0.0
Iron-E 2 years ago
commit 7d1d39f915
No known key found for this signature in database
GPG Key ID: 19B71B7B7B021D22

@ -12,9 +12,7 @@ Note that cross-compatability does not mean that `vim-libmodal` and `nvim-libmod
# Requirements
* Neovim 0.4+.
* For compatability with `vim-libmodal`, Neovim 0.5+.
* For statusbar integration, Neovim 0.5+.
* Neovim 0.5+.
* `vim-libmodal` is _not_ installed.
[libmodal]: https://github.com/Iron-E/vim-libmodal

@ -35,7 +35,7 @@ See: |libmodal-usage|, |lua|, |lua-require-example|.
1. `libmodal` *libmodal-lua-libmodal*
This is the base of |libmodal|. It can be imported using: >
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
<if |libmodal| is in your 'runtimepath'.
--------------------------------------------------------------------------------
@ -190,12 +190,12 @@ FUNCTIONS *libmodal-lua-ParseTable-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Create a mock set of user mappings.
local userTable = {
['zf'] = "echo 'Hello!'",
['zfo'] = "tabnew"
zf = "echo 'Hello!'",
zfo = "tabnew"
}
-- Create a new `ParseTable`
@ -225,14 +225,14 @@ FUNCTIONS *libmodal-lua-ParseTable-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Simulate user input.
local userInput = {122, 102} -- {'z', 'f'}
-- Create a dummy `ParseTable`.
local parseTable = libmodal.mode.ParseTable.new({
['zfo'] = 'echo "Hello!"'
zfo = 'echo "Hello!"'
})
-- Inspect it.
print(vim.inspect(parseTable))
@ -257,7 +257,7 @@ FUNCTIONS *libmodal-lua-ParseTable-functions*
>
-- Create a dummy `ParseTable`.
local parseTable = libmodal.mode.ParseTable.new({
['zfo'] = 'echo "Hello!"'
zfo = 'echo "Hello!"'
})
-- Inspect it.
print(vim.inspect(parseTable))
@ -288,8 +288,8 @@ FUNCTIONS *libmodal-lua-ParseTable-functions*
local parseTable = libmodal.mode.ParseTable.new({})
-- Create some dummy keybindings.
local unparsedUserKeybinds = {
['zfo'] = 'echo "Hello!"',
['zfc'] = 'split'
zfo = 'echo "Hello!"',
zfc = 'split'
}
-- Add the dummy keybindings.
@ -312,16 +312,14 @@ 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,
anchor = 'SW',
col = vim.go.columns - 1,
focusable = false,
height = 1,
relative = 'editor',
row = vim.go.lines - vim.go.cmdheight - 1,
style = 'minimal',
width = 25,
}
<
@ -340,16 +338,14 @@ VARIABLES *libmodal-lua-Popup-variables*
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'] = 1
anchor = 'SW',
col = vim.go.columns - 1,
focusable = false,
height = 1,
relative = 'editor',
row = vim.go.lines - vim.go.cmdheight - 1,
style = 'minimal',
width = 1
}
<
@ -615,16 +611,12 @@ FUNCTIONS *libmodal-lua-globals-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Get Lua's truth values.
local falseValue = false
local trueValue = true
-- Get Vim's `v:` truth values.
local v_falseValue = vim.api.nvim_get_vvar('false')
local v_trueValue = vim.api.nvim_get_vvar('true')
-- Get Vimscript's truth values.
local vim_falseValue = libmodal.globals.VIM_FALSE
local vim_trueValue = libmodal.globals.VIM_TRUE
@ -655,16 +647,12 @@ FUNCTIONS *libmodal-lua-globals-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Get Lua's truth values.
local falseValue = false
local trueValue = true
-- Get Vim's `v:` truth values.
local v_falseValue = vim.api.nvim_get_vvar('false')
local v_trueValue = vim.api.nvim_get_vvar('true')
-- Get Vimscript's truth values.
local vim_falseValue = libmodal.globals.VIM_FALSE
local vim_trueValue = libmodal.globals.VIM_TRUE
@ -697,7 +685,7 @@ FUNCTIONS *libmodal-lua-indicator-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
local indicator = libmodal.utils.Indicator.mode('FOO')
libmodal.utils.api.nvim_lecho(indicator)
<
@ -716,7 +704,7 @@ FUNCTIONS *libmodal-lua-indicator-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
local indicator = libmodal.utils.Indicator.prompt('FOO')
print(indicator) -- you can't use `nvim_lecho` with this one.
<
@ -766,7 +754,7 @@ FUNCTIONS *libmodal-lua-HighlightSegment-Functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
local api = libmodal.utils.api
local HighlightSegment = libmodal.Indicator.HighlightSegment
@ -801,11 +789,11 @@ FUNCTIONS *libmodal-lua-Layer-function
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
local layer = libmodal.Layer.new({
['n'] = {
['gg'] = {
['rhs'] = G
n = {
gg = {
rhs = G
}
}
})
@ -835,24 +823,24 @@ FUNCTIONS *libmodal-lua-Layer-function
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
local layer = libmodal.Layer.new({
['n'] = {
['gg'] = {
['rhs'] = G
n = {
gg = {
rhs = G
}
}
})
-- this adds a binding for `G` to `gg` in normal mode.
layer:map('n', 'G', 'gg', {['noremap'] = true})
layer:map('n', 'G', 'gg', {noremap = true})
-- use `layer:exit()` or close the buffer to exit.
layer:enter()
-- you can also call `:map()` after entering.
-- this adds a binding for `o` to `gg` in visual mode.
layer:map('v', 'o', 'gg', {['noremap'] = true})
layer:map('v', 'o', 'gg', {noremap = true})
<
See also: ~
@ -871,17 +859,17 @@ FUNCTIONS *libmodal-lua-Layer-function
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
local layer = libmodal.Layer.new({
['n'] = {
['gg'] = {
['rhs'] = G
n = {
gg = {
rhs = G
}
}
})
-- This adds a binding for `G` to `gg` in normal mode.
layer:map('n', 'G', 'gg', {['noremap'] = true})
layer:map('n', 'G', 'gg', {noremap = true})
-- Unmap the initial `gg`.
layer:unmap('n', 'gg')
@ -909,11 +897,11 @@ FUNCTIONS *libmodal-lua-Layer-function
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
local layer = libmodal.Layer.new({
['n'] = {
['gg'] = {
['rhs'] = G
n = {
gg = {
rhs = G
}
}
})
@ -963,7 +951,7 @@ Additionally, one may alter the actual `function`s that are used by a `Mode`
without forking |libmodal|. By using `setmetatable`, and `vim.inspect()`, one
can grab code from the |nvim-libmodal| repository and change whatever they
want to for their mode specifically. >
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
local Mode = libmodal.Mode
local HighlightSegment = libmodal.Indicator.HighlightSegment
@ -1170,7 +1158,7 @@ FUNCTIONS *libmodal-lua-utils-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Run `pcall` on an anonymous function.
local noErrors, pcall_err = pcall(function()
@ -1213,7 +1201,7 @@ FUNCTIONS *libmodal-lua-api-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- This function is called every time the user presses a key.
local function _instruction()
@ -1235,7 +1223,7 @@ FUNCTIONS *libmodal-lua-api-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
libmodal.utils.api.nvim_bell()
<
@ -1245,26 +1233,6 @@ FUNCTIONS *libmodal-lua-api-functions*
'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')
-- Set a mock variable to 3.
libmodal.utils.api.nvim_set_var('foo', 3)
print(libmodal.utils.api.nvim_exists('g', 'foo')) -- true
libmodal.utils.api.nvim_command('unlet g:foo')
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.
@ -1276,7 +1244,7 @@ FUNCTIONS *libmodal-lua-api-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Get one character of user input.
local char = string.char(libmodal.utils.api.nvim_input())
@ -1297,7 +1265,7 @@ FUNCTIONS *libmodal-lua-api-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Create an indicator.
local indicator = libmodal.utils.Indicator.mode('FOO')
@ -1315,12 +1283,11 @@ FUNCTIONS *libmodal-lua-api-functions*
Example: ~
>
local libmodal = require('libmodal')
local api = vim.api
local libmodal = require 'libmodal'
-- Echo hello and prompt for input before continuing.
api.nvim_command("echo 'Hello!'")
api.nvim_call_function('getchar', {})
vim.api.nvim_command "echo 'Hello!'"
vim.fn.getchar()
-- Clear the screen.
libmodal.utils.api.nvim_redraw()
@ -1336,7 +1303,7 @@ FUNCTIONS *libmodal-lua-api-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Show an error.
libmodal.utils.api.nvim_show_err(
@ -1371,18 +1338,18 @@ FUNCTIONS *libmodal-lua-Help-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Create a table of mock user commands.
local commands = {
['close'] = 'tabclose',
['new'] = 'tabnew'
close = 'tabclose',
new = 'tabnew'
}
-- Create a table of mock user maps.
local maps = {
['zf'] = 'split',
['zfo'] = 'echo "Hello!"'
zf = 'split',
zfo = 'echo "Hello!"'
}
local commandHelp = libmodal.utils.Help.new(commands, 'COMMANDS')
@ -1395,18 +1362,18 @@ FUNCTIONS *libmodal-lua-Help-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Create a table of mock user commands.
local commands = {
['close'] = 'tabclose',
['new'] = 'tabnew'
close = 'tabclose',
new = 'tabnew'
}
-- Create a table of mock user maps.
local maps = {
['zf'] = 'split',
['zfo'] = 'echo "Hello!"'
zf = 'split',
zfo = 'echo "Hello!"'
}
local commandHelp = libmodal.utils.Help.new(commands, 'COMMANDS')
@ -1434,7 +1401,7 @@ FUNCTIONS *libmodal-lua-WindowState-functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
local windowState = libmodal.utils.WindowState.new()
print(vim.inspect(windowState))
<
@ -1449,18 +1416,17 @@ FUNCTIONS *libmodal-lua-WindowState-functions*
Example: ~
>
local libmodal = require('libmodal')
local api = vim.api
local libmodal = require 'libmodal'
-- Create a new `WindowState`.
local windowState = libmodal.utils.WindowState.new()
-- Set the 'winheight' to a new value.
api.nvim_set_option('winheight', 100)
vim.go.winheight = 100
-- Define a function to print the 'winheight' value.
local print_height = function()
api.nvim_command('echo &winheight')
vim.api.nvim_command 'echo &winheight'
end
-- Print the 'winheight' prior to `restore()`.
@ -1492,7 +1458,7 @@ FUNCTIONS *libmodal-lua-Vars.functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
local input = libmodal.Vars('input', 'FOO')
print(input:name()) -- 'fooModeInput'
@ -1510,10 +1476,10 @@ FUNCTIONS *libmodal-lua-Vars.functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
local input = libmodal.Vars('input', 'FOO')
vim.api.nvim_set_var(input:name(), 'test')
vim.g[input:name()] = 'test'
print(input:nvimGet())
<
@ -1527,7 +1493,7 @@ FUNCTIONS *libmodal-lua-Vars.functions*
Example: ~
>
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
local input = libmodal.Vars('input', 'FOO')
input:nvimSet('test')

@ -144,10 +144,10 @@ FUNCTIONS *libmodal-usage-function
map of user key-chord to Vim |command|s. Example: >
-- LUA
local modeInstruction = {
['zf'] = 'split',
['zfo'] = 'vsplit',
zf = 'split',
zfo = 'vsplit',
-- You can also use lua functions
['zfc'] = function() return 'tabnew' end
zfc = function() return 'tabnew' end
}
" VIMSCRIPT
@ -217,7 +217,7 @@ FUNCTIONS *libmodal-usage-function
{
[<mode>] = {
[<lhs>] = {
['rhs'] = <rhs>,
rhs = <rhs>,
<opts>
},
@ -259,9 +259,9 @@ FUNCTIONS *libmodal-usage-function
map of user inputs to Vim |command|s. Example: >
-- LUA
local modeInstruction = {
['new'] = 'tabnew',
['close'] = 'tabclose',
['last'] = 'tablast'
new = 'tabnew',
close = 'tabclose',
last = 'tablast'
}
" VIMSCRIPT
@ -334,7 +334,6 @@ See: |libmodal-usage|, |libmodal-use-case|, |lua-require-example|.
MODES *libmodal-examples-modes*
Using a callback `function`: >
local api = vim.api
local libmodal = require('libmodal')
local fooModeInputHistory = {}
@ -346,14 +345,14 @@ Using a callback `function`: >
function fooMode()
fooModeInputHistory[#fooModeInputHistory + 1] = string.char(
api.nvim_get_var('fooModeInput')
vim.g.fooModeInput
)
local index = 1
if fooModeInputHistory[1] == 'z' then
if fooModeInputHistory[2] == 'f' then
if fooModeInputHistory[3] == 'o' then
api.nvim_command("echom 'It works!'")
vim.api.nvim_command "echom 'It works!'"
else index = 3 end
else index = 2 end
end
@ -377,9 +376,9 @@ using a |key-mapping| `dict`: >
Using a |key-mapping| `table`: >
local libmodal = require('libmodal')
local fooModeCombos = {
['zf'] = 'split',
['zfo'] = 'vsplit',
['zfc'] = 'tabnew'
zf = 'split',
zfo = 'vsplit',
zfc = 'tabnew'
}
libmodal.mode.enter('FOO', fooModeCombos)
@ -393,17 +392,17 @@ Using a callback `function`: >
function fooMode()
local userInput = string.char(
vim.api.nvim_get_var('fooModeInput')
vim.g.fooModeInput
)
if userInput == '' then
vim.api.nvim_command("echom 'You cant leave using <Esc>.'")
vim.api.nvim_command "echom 'You cant leave using <Esc>.'"
elseif userInput == 'q' then
vim.api.nvim_set_var('fooModeExit', true)
vim.g.fooModeExit = true
end
end
vim.api.nvim_set_var('fooModeExit', 0)
vim.g.fooModeExit = false
libmodal.mode.enter('FOO', fooMode, true)
<
@ -421,10 +420,10 @@ Using a |key-mapping| `table`: >
local libmodal = require('libmodal')
local fooModeCombos = {
[''] = 'echom "You cant exit using escape."',
['q'] = 'let g:fooModeExit = 1'
q = 'let g:fooModeExit = 1'
}
vim.api.nvim_set_var('fooModeExit', 0)
vim.g.fooModeExit = false
libmodal.mode.enter('FOO', fooModeCombos, true)
<
@ -436,9 +435,9 @@ Using a callback `function`: >
local fooModeRecurse = 0
function fooMode()
local userInput = string.char(vim.api.nvim_get_var(
'foo' .. tostring(fooModeRecurse) .. 'ModeInput'
))
local userInput = string.char(vim.g[
'foo'..tostring(fooModeRecurse)..'ModeInput'
])
if userInput == 'z' then
fooModeRecurse = fooModeRecurse + 1
@ -475,7 +474,7 @@ Using a |key-mapping| `table`: >
local libmodal = require('libmodal')
local fooModeRecurse = 0
local fooModeCombos = {
['z'] = 'lua fooMode()'
z = 'lua fooMode()'
}
function fooMode()
@ -494,14 +493,14 @@ LAYERS *libmodal-examples-layer
-- 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
n = { -- normal mode
gg = { -- remap `gg`
rhs = 'G', -- map it to `G`
noremap = true -- don't remap
},
['G'] = { -- remap `G`
['rhs'] = 'gg', -- map it to `gg`
['noremap'] = true -- don't remap
G = { -- remap `G`
rhs = 'gg', -- map it to `gg`
noremap = true -- don't remap
}
}
})
@ -516,17 +515,16 @@ PROMPTS *libmodal-examples-prompt
Using a callback `function`: >
local libmodal = require('libmodal')
local api = vim.api
local commandList = {'new', 'close', 'last'}
function fooMode()
local userInput = vim.api.nvim_get_var('fooModeInput')
local userInput = vim.g.fooModeInput
if userInput == 'new' then
api.nvim_command('tabnew')
vim.api.nvim_command 'tabnew'
elseif userInput == 'close' then
api.nvim_command('tabclose')
vim.api.nvim_command 'tabclose'
elseif userInput == 'last' then
api.nvim_command('tablast')
vim.api.nvim_command 'tablast'
end
end
@ -546,9 +544,9 @@ Using a |command| `dict`: >
Using a |command| `table`: >
local libmodal = require('libmodal')
local commands = {
['new'] = 'tabnew',
['close'] = 'tabclose',
['last'] = 'tablast'
new = 'tabnew',
close = 'tabclose',
last = 'tablast'
}
libmodal.prompt.enter('BAR', commands)
@ -589,16 +587,16 @@ To enable 'timeout's, one may set the following |variables|:
Lua: ~
>
" Set libmodal modes to turn timeouts on.
vim.api.nvim_set_var('libmodalTimeouts', true)
vim.g.libmodalTimeouts = true
" Enable timeouts for specific mode.
vim.api.nvim_set_var('{name}ModeTimeouts', true)
vim.g[name..'ModeTimeouts'] = true
<
Vimscript: ~
>
" Set libmodal modes to turn timeouts on.
let g:libmodalTimeouts = 1
let g:libmodalTimeouts = v:true
" Enable timeouts for specific mode.
let g:{name}ModeTimeouts = 1
let g:{name}ModeTimeouts = v:true
<
@ -643,18 +641,17 @@ then reset it upon exit. Example:
<
Lua: ~
>
local api = vim.api
local libmodal = require('libmodal')
function fooMode()
-- Get the user's preferred timeout length.
local prevTimeoutLen = api.nvim_get_option('timeoutlen')
local prevTimeoutLen = vim.go.timeoutlen
-- Set it to something else, like 1500ms.
api.nvim_set_option('timeoutlen', 1500)
vim.go.timeoutlen = 1500
-- Enter a mode.
libmodal.mode.enter(…)
-- Restore the `timeoutlen`
api.nvim_set_option('timeoutlen', prevTimeoutLen)
vim.go.timeoutlen = prevTimeoutLen
end
<

@ -1,6 +1,5 @@
-- Imports
local api = vim.api
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Keep track of the user's input history manually.
local _inputHistory = {}
@ -19,7 +18,7 @@ local function fooMode()
-- Append to the input history, the latest button press.
_inputHistory[#_inputHistory + 1] = string.char(
-- The input is a character number.
api.nvim_get_var('fooModeInput')
vim.g.fooModeInput
)
-- Custom logic to test for each character index to see if it matches the 'zfo' mapping.
@ -27,7 +26,7 @@ local function fooMode()
if _inputHistory[1] == 'z' then
if _inputHistory[2] == 'f' then
if _inputHistory[3] == 'o' then
api.nvim_command("echom 'It works!'")
vim.api.nvim_command "echom 'It works!'"
else index = 3
end
else index = 2

@ -5,7 +5,7 @@ local libmodal = require('libmodal')
local fooModeRecurse = 0
-- Register 'z' as the map for recursing further (by calling the FooMode function again).
local fooModeCombos = {
['z'] = 'lua FooMode()'
z = 'lua FooMode()'
}
-- define the FooMode() function which is called whenever the user presses 'z'

@ -1,14 +1,14 @@
-- Imports
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Register key commands and what they do.
local fooModeCombos = {
[''] = 'echom "You cant exit using escape."',
['q'] = 'let g:fooModeExit = 1'
q = 'let g:fooModeExit = 1'
}
-- Tell the mode not to exit automatically.
vim.api.nvim_set_var('fooModeExit', 0)
vim.g.fooModeExit = false
-- Enter the mode using the key combos created before.
libmodal.mode.enter('FOO', fooModeCombos, true)

@ -1,19 +1,18 @@
-- Imports
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- A function which will split the window both horizontally and vertically.
local function _split_twice()
local cmd = vim.api.nvim_command
cmd('split')
cmd('vsplit')
vim.api.nvim_command 'split'
vim.api.nvim_command 'vsplit'
end
-- Register key combos for splitting windows and then closing windows
local fooModeCombos = {
['zf'] = 'split',
['zfo'] = 'vsplit',
['zfc'] = 'q',
['zff'] = _split_twice
zf = 'split',
zfo = 'vsplit',
zfc = 'q',
zff = _split_twice
}
-- Enter the mode using the key combos.

@ -3,14 +3,14 @@ local libmodal = require('libmodal')
-- create a new layer.
local exitFunc = libmodal.layer.enter({
['n'] = { -- normal mode mappings
['gg'] = { -- remap `gg`
['rhs'] = 'G', -- map it to `G`
['noremap'] = true, -- don't recursively map.
n = { -- normal mode mappings
gg = { -- remap `gg`
rhs = 'G', -- map it to `G`
noremap = true, -- don't recursively map.
},
['G'] = { -- remap `G`
['rhs'] = 'gg', -- map it to `gg`
['noremap'] = true -- don't recursively map.
G = { -- remap `G`
rhs = 'gg', -- map it to `gg`
noremap = true -- don't recursively map.
}
}
})

@ -3,14 +3,14 @@ local libmodal = require('libmodal')
-- create a new layer.
local layer = libmodal.Layer.new({
['n'] = { -- normal mode mappings
['gg'] = { -- remap `gg`
['rhs'] = 'G', -- map it to `G`
['noremap'] = true, -- don't recursively map.
n = { -- normal mode mappings
gg = { -- remap `gg`
rhs = 'G', -- map it to `G`
noremap = true, -- don't recursively map.
},
['G'] = { -- remap `G`
['rhs'] = 'gg', -- map it to `gg`
['noremap'] = true -- don't recursively map.
G = { -- remap `G`
rhs = 'gg', -- map it to `gg`
noremap = true -- don't recursively map.
}
}
})
@ -24,12 +24,12 @@ function LibmodalLayerExampleExit()
end
-- Add an additional mapping for `z`.
layer:map('n', 'z', 'gg', {['noremap'] = true})
layer:map('n', 'z', 'gg', {noremap = true})
-- add an additional mapping for `q`.
layer:map(
'n', 'q', ':lua LibmodalLayerExampleExit()<CR>',
{['noremap'] = true, ['silent'] = true}
{noremap = true, silent = true}
)
--[[ unmap `gg` and `G`. Notice they both return to their defaults,

@ -1,19 +1,18 @@
-- Imports
local libmodal = require('libmodal')
local api = vim.api
local libmodal = require 'libmodal'
-- The list of commands. Providing this will allow for autocomplete.
local commandList = {'new', 'close', 'last'}
-- The function which will be called whenever the user enters a command.
function FooMode()
local userInput = vim.api.nvim_get_var('fooModeInput')
local userInput = vim.g.fooModeInput
if userInput == 'new' then
api.nvim_command('tabnew')
vim.api.nvim_command 'tabnew'
elseif userInput == 'close' then
api.nvim_command('tabclose')
vim.api.nvim_command 'tabclose'
elseif userInput == 'last' then
api.nvim_command('tablast')
vim.api.nvim_command 'tablast'
end
end

@ -1,12 +1,12 @@
-- Import
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Define commands through a dictionary.
local commands = {
['new'] = 'tabnew',
['close'] = 'tabclose',
['last'] = 'tablast',
['exit'] = libmodal.utils.api.mode_exit
new = 'tabnew',
close = 'tabclose',
last = 'tablast',
exit = libmodal.utils.api.mode_exit
}
-- Begin the prompt.

@ -1,5 +1,5 @@
-- Imports
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Recurse counter
local fooModeRecurse = 1
@ -7,10 +7,10 @@ local fooModeRecurse = 1
-- Function which is called whenever the user presses a button
function FooMode()
-- Append to the input history, the latest button press.
local userInput = string.char(vim.api.nvim_get_var(
local userInput = string.char(vim.g[
-- The input is a character number.
'foo' .. tostring(fooModeRecurse) .. 'ModeInput'
))
])
-- If the user pressed 'z', then increase the counter and recurse.
if userInput == 'z' then

@ -1,25 +1,24 @@
-- Imports
local api = vim.api
local libmodal = require('libmodal')
local libmodal = require 'libmodal'
-- Function which is called whenever the user presses a button
local function fooMode()
-- Append to the input history, the latest button press.
local userInput = string.char(
-- The input is a character number.
api.nvim_get_var('fooModeInput')
vim.g.fooModeInput
)
if userInput == '' then
api.nvim_command("echom 'You cant leave using <Esc>.'")
vim.api.nvim_command "echom 'You cant leave using <Esc>.'"
elseif userInput == 'q' then
-- If the user presses 'q', libmodal will exit the mode.
api.nvim_set_var('fooModeExit', true)
vim.g.fooModeExit = true
end
end
-- Tell libmodal not to exit the mode immediately.
api.nvim_set_var('fooModeExit', 0)
vim.g.fooModeExit = false
-- Enter the mode.
libmodal.mode.enter('FOO', fooMode, true)

@ -12,17 +12,17 @@ local libmodal = require('libmodal/src')
*/
--]]
libmodal.layer = {['enter'] = function(keymap)
libmodal.layer = {enter = function(keymap)
local layer = libmodal.Layer.new(keymap)
layer:enter()
return function() layer:exit() end
end}
libmodal.mode = {['enter'] = function(name, instruction, ...)
libmodal.mode = {enter = function(name, instruction, ...)
libmodal.Mode.new(name, instruction, ...):enter()
end}
libmodal.prompt = {['enter'] = function(name, instruction, ...)
libmodal.prompt = {enter = function(name, instruction, ...)
libmodal.Prompt.new(name, instruction, ...):enter()
end}

@ -23,8 +23,8 @@ local HighlightSegment = {}
--------------------------------
function HighlightSegment.new(hlgroup, str)
return {
['hl'] = hlgroup,
['str'] = str
hl = hlgroup,
str = str
}
end

@ -5,7 +5,7 @@
--]]
local Indicator = {
['HighlightSegment'] = require('libmodal/src/Indicator/HighlightSegment')
HighlightSegment = require('libmodal/src/Indicator/HighlightSegment')
}
-- highlight group names

@ -13,7 +13,7 @@ local libmodal_api = require('libmodal/src/utils/api')
*/
--]]
local Layer = {['TYPE'] = 'libmodal-layer'}
local Layer = {TYPE = 'libmodal-layer'}
local _BUFFER_CURRENT = 0
local _ERR_NO_MAP = 'E5555: API call: E31: No such mapping'
@ -142,7 +142,7 @@ function _metaLayer:map(mode, lhs, rhs, options)
-- add the new mapping to the keymap
self._keymap[mode][lhs] = vim.tbl_extend('force',
options, {['rhs'] = rhs}
options, {rhs = rhs}
)
end
@ -239,7 +239,7 @@ end
-----------------------------------------------------
function Layer.new(keymap)
return setmetatable(
{['_keymap'] = keymap},
{_keymap = keymap},
_metaLayer
)
end

@ -1,8 +1,4 @@
--[[
/*
* IMPORTS
*/
--]]
--[[/* IMPORTS */]]
local classes = require('libmodal/src/classes')
local globals = require('libmodal/src/globals')
@ -10,26 +6,17 @@ local ParseTable = require('libmodal/src/collections/ParseTable')
local utils = require('libmodal/src/utils')
local Vars = require('libmodal/src/Vars')
local vim = vim
local api = vim.api
--[[
/*
* MODULE
*/
--]]
--[[/* MODULE */]]
local Mode = {['TYPE'] = 'libmodal-mode'}
local Mode = {TYPE = 'libmodal-mode'}
local _HELP = '?'
local _TIMEOUT = {
['CHAR'] = 'ø',
['LEN'] = api.nvim_get_option('timeoutlen'),
['SEND'] = function(__self)
api.nvim_feedkeys(__self.CHAR, 'nt', false)
end
CHAR = 'ø',
LEN = vim.go.timeoutlen,
SEND = function(self) vim.api.nvim_feedkeys(self.CHAR, 'nt', false) end
}
_TIMEOUT.NR = string.byte(_TIMEOUT.CHAR)
_TIMEOUT.CHAR_NUMBER = string.byte(_TIMEOUT.CHAR)
--[[
/*
@ -40,9 +27,9 @@ _TIMEOUT.NR = string.byte(_TIMEOUT.CHAR)
local _metaMode = classes.new(Mode.TYPE)
local _metaInputBytes = classes.new(nil, {
['clear'] = function(__self)
for i, _ in ipairs(__self) do
__self[i] = nil
clear = function(self)
for i, _ in ipairs(self) do
self[i] = nil
end
end
})
@ -62,7 +49,7 @@ classes = nil
-----------------------------------------------------------
function _metaMode._commandTableExecute(instruction)
if type(instruction) == globals.TYPE_FUNC then instruction()
else api.nvim_command(instruction) end
else vim.api.nvim_command(instruction) end
end
-----------------------------------------------
@ -180,7 +167,7 @@ function _metaMode:_initMappings()
self._timeouts = Vars.new('timeouts', self._name)
-- Read the correct timeout variable.
if utils.api.nvim_exists('g', self._timeouts:name())
if vim.g[self._timeouts:name()] ~= nil
then self._timeouts.enabled =
self._timeouts:nvimGet()
else self._timeouts.enabled =
@ -211,7 +198,7 @@ function _metaMode:_inputLoop()
local userInput = utils.api.nvim_input()
-- Return if there was a timeout event.
if userInput == _TIMEOUT.NR then
if userInput == _TIMEOUT.CHAR_NUMBER then
return true
end
@ -285,12 +272,12 @@ function Mode.new(name, instruction, ...)
-- Inherit the metatable.
local self = setmetatable(
{
['exit'] = Vars.new('exit', name),
['indicator'] = require('libmodal/src/Indicator').mode(name),
['input'] = Vars.new('input', name),
['_instruction'] = instruction,
['_name'] = name,
['_winState'] = utils.WindowState.new(),
exit = Vars.new('exit', name),
indicator = require('libmodal/src/Indicator').mode(name),
input = Vars.new('input', name),
_instruction = instruction,
_name = name,
_winState = utils.WindowState.new(),
},
_metaMode
)

@ -1,23 +1,12 @@
--[[
/*
* IMPORTS
*/
--]]
--[[/* IMPORTS */]]
local globals = require('libmodal/src/globals')
local utils = require('libmodal/src/utils')
local Vars = require('libmodal/src/Vars')
local vim = vim
local api = vim.api
--[[
/*
* MODULE
*/
--]]
--[[/* MODULE */]]
local Prompt = {['TYPE'] = 'libmodal-prompt'}
local Prompt = {TYPE = 'libmodal-prompt'}
local _HELP = 'help'
local _REPLACEMENTS = {
@ -55,14 +44,14 @@ function _metaPrompt:_executeInstruction(userInput)
if type(to_execute) == globals.TYPE_FUNC then
to_execute()
else
api.nvim_command(instruction[userInput])
vim.api.nvim_command(instruction[userInput])
end
elseif userInput == _HELP then -- The user did not define a 'help' command, so use the default.
self._help:show()
else -- show an error.
utils.api.nvim_show_err(globals.DEFAULT_ERROR_TITLE, 'Unknown command')
end
elseif type(instruction) == globals.TYPE_STR and vim.fn then -- The instruction is a function. Works on Neovim 0.5+.
elseif type(instruction) == globals.TYPE_STR then -- The instruction is a function. Works on Neovim 0.5+.
vim.fn[instruction]()
else -- attempt to call the instruction.
instruction()
@ -87,16 +76,13 @@ function _metaPrompt:_inputLoop()
local userInput = ''
-- echo the highlighting
api.nvim_command('echohl ' .. self.indicator.hl)
vim.api.nvim_command('echohl ' .. self.indicator.hl)
-- set the user input variable
if self._completions
then userInput =
api.nvim_call_function('libmodal#_inputWith', {
self.indicator.str, self._completions
})
if self._completions then userInput =
vim.fn['libmodal#_inputWith'](self.indicator.str, self._completions)
else userInput =
api.nvim_call_function('input', {self.indicator})
vim.fn.input(self.indicator)
end
-- determine what to do with the input
@ -203,11 +189,11 @@ function Prompt.new(name, instruction, ...)
local self = setmetatable(
{
['exit'] = Vars.new('exit', name),
['indicator'] = require('libmodal/src/Indicator').prompt(name),
['input'] = require('libmodal/src/Vars').new('input', name),
['_instruction'] = instruction,
['_name'] = name
exit = Vars.new('exit', name),
indicator = require('libmodal/src/Indicator').prompt(name),
input = require('libmodal/src/Vars').new('input', name),
_instruction = instruction,
_name = name
},
_metaPrompt
)

@ -1,8 +1,4 @@
--[[
/*
* IMPORTS
*/
--]]
--[[/* IMPORTS */]]
local api = vim.api
@ -12,11 +8,9 @@ local api = vim.api
*/
--]]
local _TIMEOUT_GLOBAL_NAME = 'libmodalTimeouts'
local Vars = {
[_TIMEOUT_GLOBAL_NAME] = api.nvim_get_var(_TIMEOUT_GLOBAL_NAME),
['TYPE'] = 'libmodal-vars'
libmodalTimeouts = vim.g.libmodalTimeouts,
TYPE = 'libmodal-vars'
}
--[[
@ -48,7 +42,7 @@ end
]]
------------------------------------
function _metaVars:nvimGet()
return api.nvim_get_var(self:name())
return vim.g[self:name()]
end
-----------------------------------------
@ -61,7 +55,7 @@ end
]]
-----------------------------------------
function _metaVars:nvimSet(val)
api.nvim_set_var(self:name(), val)
vim.g[self:name()] = val
end
--[[

@ -15,8 +15,8 @@ local globals = require('libmodal/src/globals')
local _REGEX_ALL = '.'
local ParseTable = {
['CR'] = 13, -- The number corresponding to <CR> in vim.
['TYPE'] = 'libmodal-parse-table',
CR = 13, -- The number corresponding to <CR> in vim.
TYPE = 'libmodal-parse-table',
--------------------------------------
--[[ SUMMARY:
@ -30,7 +30,7 @@ local ParseTable = {
* The split `str`.
]]
--------------------------------------
['stringSplit'] = function(str, regex)
stringSplit = function(str, regex)
local split = {}
for char in string.gmatch(str, regex) do
split[#split + 1] = char

@ -1,31 +1,16 @@
--[[
/*
* IMPORTS
*/
--]]
local vim = vim
local api = vim.api
--[[
/*
* MODULE
*/
--]]
--[[/* MODULE */]]
local Popup = require('libmodal/src/classes').new(
'libmodal-popup',
{['config'] = {
['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'] = 1
{config = {
anchor = 'SW',
col = vim.go.columns - 1,
focusable = false,
height = 1,
relative = 'editor',
row = vim.go.lines - vim.go.cmdheight - 1,
style = 'minimal',
width = 1
}}
)
@ -42,7 +27,7 @@ local Popup = require('libmodal/src/classes').new(
]]
----------------------------
local function valid(window)
return window and api.nvim_win_is_valid(window)
return window and vim.api.nvim_win_is_valid(window)
end
--[[
@ -64,7 +49,7 @@ local _metaPopup = require('libmodal/src/classes').new(Popup.TYPE)
-------------------------------------
function _metaPopup:close(keepBuffer)
if valid(self.window) then
api.nvim_win_close(self.window, false)
vim.api.nvim_win_close(self.window, false)
end
self.window = nil
@ -85,11 +70,11 @@ function _metaPopup:open(config)
if not config then config = Popup.config end
if valid(self.window) then
config = vim.tbl_extend('keep', config, api.nvim_win_get_config(self.window))
config = vim.tbl_extend('keep', config, vim.api.nvim_win_get_config(self.window))
self:close(true)
end
self.window = api.nvim_open_win(self.buffer, false, config)
self.window = vim.api.nvim_open_win(self.buffer, false, config)
end
---------------------------------------
@ -116,22 +101,18 @@ function _metaPopup:refresh(inputBytes)
self._inputChars = chars
end
api.nvim_buf_set_lines(self.buffer, 0, 1, true, {
vim.api.nvim_buf_set_lines(self.buffer, 0, 1, true, {
table.concat(self._inputChars)
})
if not valid(self.window) or api.nvim_win_get_tabpage(self.window) ~= api.nvim_get_current_tabpage() then
if not valid(self.window) or vim.api.nvim_win_get_tabpage(self.window) ~= vim.api.nvim_get_current_tabpage() then
self:open()
end
api.nvim_win_set_width(self.window, #self._inputChars)
vim.api.nvim_win_set_width(self.window, #self._inputChars)
end
--[[
/*
* CLASS `Popup`
*/
--]]
--[[/* CLASS `Popup` */]]
--------------------
--[[ SUMMARY:
@ -142,12 +123,10 @@ end
]]
--------------------
function Popup.new(config)
local buf = api.nvim_create_buf(false, true)
local self = setmetatable(
{
['buffer'] = buf,
['_inputChars'] = {},
buffer = vim.api.nvim_create_buf(false, true),
_inputChars = {},
},
_metaPopup
)
@ -157,10 +136,6 @@ function Popup.new(config)
return self
end
--[[
/*
* PUBLICIZE `Popup`
*/
--]]
--[[/* PUBLICIZE `Popup` */]]
return Popup

@ -4,7 +4,7 @@
*/
--]]
local Stack = {['TYPE'] = 'libmodal-stack'}
local Stack = {TYPE = 'libmodal-stack'}
--[[
/*

@ -1,5 +1,5 @@
return {
['ParseTable'] = require('libmodal/src/collections/ParseTable'),
['Popup'] = require('libmodal/src/collections/Popup'),
['Stack'] = require('libmodal/src/collections/Stack')
ParseTable = require('libmodal/src/collections/ParseTable'),
Popup = require('libmodal/src/collections/Popup'),
Stack = require('libmodal/src/collections/Stack')
}

@ -2,17 +2,17 @@ local _VIM_FALSE = 0
local _VIM_TRUE = 1
return {
['DEFAULT_ERROR_TITLE'] = 'vim-libmodal error',
DEFAULT_ERROR_TITLE = 'vim-libmodal error',
['ESC_NR'] = 27,
ESC_NR = 27,
['TYPE_FUNC'] = 'function',
['TYPE_NUM'] = 'number',
['TYPE_STR'] = 'string',
['TYPE_TBL'] = 'table',
TYPE_FUNC = 'function',
TYPE_NUM = 'number',
TYPE_STR = 'string',
TYPE_TBL = 'table',
['VIM_FALSE'] = _VIM_FALSE,
['VIM_TRUE'] = _VIM_TRUE,
VIM_FALSE = _VIM_FALSE,
VIM_TRUE = _VIM_TRUE,
is_false = function(val)
return val == false or val == _VIM_FALSE

@ -1,10 +1,10 @@
return {
['classes'] = require('libmodal/src/classes'),
['collections'] = require('libmodal/src/collections'),
['globals'] = require('libmodal/src/globals'),
['Indicator'] = require('libmodal/src/Indicator'),
['Layer'] = require('libmodal/src/Layer'),
['Mode'] = require('libmodal/src/Mode'),
['Prompt'] = require('libmodal/src/Prompt'),
['utils'] = require('libmodal/src/utils')
classes = require('libmodal/src/classes'),
collections = require('libmodal/src/collections'),
globals = require('libmodal/src/globals'),
Indicator = require('libmodal/src/Indicator'),
Layer = require('libmodal/src/Layer'),
Mode = require('libmodal/src/Mode'),
Prompt = require('libmodal/src/Prompt'),
utils = require('libmodal/src/utils')
}

@ -1,57 +1,55 @@
--[[
/*
* IMPORTS
*/
--]]
local vim = vim
--[[/* IMPORTS */]]
local globals = require('libmodal/src/globals')
--[[
/*
* MODULE
*/
--]]
--[[/* Utilities */]]
--- Align `tbl` according to the `longestKeyLen`.
--- @param tbl table what to align.
--- @param longestKeyLen number how long the longest key is.
--- @return table aligned
local function tabAlign(tbl, longestKeyLen)
local toPrint = {}
for key, value in pairs(tbl) do
toPrint[#toPrint + 1] = key
local len = string.len(key)
local byte = string.byte(key)
-- account for ASCII chars that take up more space.
if byte <= 32 or byte == 127 then len = len + 1 end
for _ = len, longestKeyLen do
toPrint[#toPrint + 1] = ' '
end
toPrint[#toPrint + 1] = table.concat(
{'', '\n'},
(type(value) == globals.TYPE_STR) and value or '<lua function>'
)
end
return toPrint
end
--[[/* MODULE */]]
local Help = {['TYPE'] = 'libmodal-help'}
local Help = {TYPE = 'libmodal-help'}
--[[
/*
* META `Help`
*/
--]]
--[[/* META `Help` */]]
local _metaHelp = require('libmodal/src/classes').new(Help.TYPE)
-------------------------
--[[ SUMMARY:
* Show the contents of this `Help`.
]]
-------------------------
--- Show the contents of this `Help`.
function _metaHelp:show()
for _, helpText in ipairs(self) do
print(helpText)
end
vim.api.nvim_call_function('getchar', {})
vim.fn.getchar()
end
--[[
/*
* CLASS `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`.
]]
----------------------------------------
--[[/* CLASS `Help` */]]
--- Create a default help table with `commandsOrMaps` and vim expressions.
--- @param commandsOrMaps table commands or mappings to vim expressions.
--- @return table Help
function Help.new(commandsOrMaps, title)
-- find the longest key in the table.
local longestKeyLen = 0
@ -67,68 +65,21 @@ function Help.new(commandsOrMaps, title)
longestKeyLen = string.len(title)
end
-- define the separator for entries in the help table.
local SEPARATOR_TEMPLATE = {'', '\n'}
----------------------
--[[ SUMMARY:
* Align `tbl` according to the `longestKey`.
]]
--[[ PARAMS:
* `tbl` => the table to align.
]]
--[[ RETURNS:
* The aligned `tbl`.
]]
----------------------
local function tabAlign(tbl)
local toPrint = {}
for key, value in pairs(tbl) do
toPrint[#toPrint + 1] = key
local len = string.len(key)
local byte = string.byte(key)
-- account for ASCII chars that take up more space.
if byte <= 32 or byte == 127 then len = len + 1 end
for _ = len, longestKeyLen do
toPrint[#toPrint + 1] = ' '
end
toPrint[#toPrint + 1] = table.concat(
SEPARATOR_TEMPLATE,
(type(value) == globals.TYPE_STR) and value or '<lua function>'
)
end
return toPrint
end
-- define the separator for the help table.
local helpSeparator = {}
for i = 1, string.len(title) do
helpSeparator[i] = '-'
end
for i = 1, string.len(title) do helpSeparator[i] = '-' end
helpSeparator = table.concat(helpSeparator)
-- Create a new `Help`.
return setmetatable(
{
[1] = ' ',
[2] = table.concat(tabAlign({
[title] = 'VIM EXPRESSION'
})),
[3] = table.concat(tabAlign({
[helpSeparator] = '--------------'
})),
[4] = table.concat(tabAlign(commandsOrMaps)),
[2] = table.concat(tabAlign({[title] = 'VIM EXPRESSION'}, longestKeyLen)),
[3] = table.concat(tabAlign({[helpSeparator] = '--------------'}, longestKeyLen)),
[4] = table.concat(tabAlign(commandsOrMaps, longestKeyLen)),
},
_metaHelp
)
end
--[[
/*
* PUBLICIZE `Help`.
*/
--]]
return Help

@ -1,11 +1,6 @@
--[[
/*
* IMPORTS
*/
--]]
--[[/* IMPORTS */]]
local api = vim.api
local libmodal_api = require('libmodal/src/utils/api')
local api = require('libmodal/src/utils/api')
--[[
/*
@ -13,10 +8,7 @@ local libmodal_api = require('libmodal/src/utils/api')
*/
--]]
local WindowState = {['TYPE'] = 'libmodal-window-state'}
local height = 'winheight'
local width = 'winwidth'
local WindowState = {TYPE = 'libmodal-window-state'}
--[[
/*
@ -32,9 +24,9 @@ local _metaWindowState = require('libmodal/src/classes').new(WindowState.TYPE)
]]
-----------------------------------
function _metaWindowState:restore()
api.nvim_set_option(height, self.height)
api.nvim_set_option(width, self.width)
libmodal_api.nvim_redraw()
vim.go.winheight = self.height
vim.go.winwidth = self.width
api.nvim_redraw()
end
--[[
@ -54,8 +46,8 @@ end
function WindowState.new()
return setmetatable(
{
['height'] = api.nvim_get_option(height),
['width'] = api.nvim_get_option(width),
height = vim.go.winheight,
width = vim.go.winwidth,
},
_metaWindowState
)

@ -1,21 +1,14 @@
--[[
/*
* MODULE
*/
--]]
--[[/* IMPORTS */]]
local api = {}
local globals = require('libmodal/src/globals')
local vim_api = vim.api
local HighlightSegment = require('libmodal/src/Indicator/HighlightSegment')
---------------------------------
--[[ SUMMARY:
* Send a character to exit a mode.
]]
--[[ PARAMS:
* `exit_char` => the character used to exit the mode, or ESCAPE if none was provided.
]]
---------------------------------
--[[/* MODULE */]]
local api = {}
--- Send a character to exit a mode.
--- @param exit_char string the character used to exit the mode, or ESCAPE if none was provided.
function api.mode_exit(exit_char)
-- If there was no provided `exit_char`, or it is a character code.
if not exit_char or type(exit_char) == globals.TYPE_NUM then
@ -24,57 +17,17 @@ function api.mode_exit(exit_char)
end
-- Exit the prompt by sending an escape key.
vim_api.nvim_feedkeys(exit_char, 'nt', false)
vim.api.nvim_feedkeys(exit_char, 'nt', false)
end
------------------------
--[[ SUMMARY:
* Make vim ring the visual/audio bell, if it is enabled.
]]
------------------------
--- Make vim ring the visual/audio bell, if it is enabled.
function api.nvim_bell()
vim_api.nvim_command('normal '..string.char(27)) -- escape char
vim.api.nvim_command('normal '..string.char(27)) -- escape char
end
------------------------------------
--[[ 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)
return vim_api.nvim_call_function('exists', {scope..':'..var}) == require('libmodal/src/globals').VIM_TRUE
end
-------------------------
--[[ SUMMARY:
* 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))
```
However, I'm not sure if it would accidentally affect text.
]]
-------------------------
--- Gets one character of user input, as a number.
function api.nvim_input()
return vim_api.nvim_call_function('getchar', {})
return vim.fn.getchar()
end
--------------------------
@ -84,7 +37,7 @@ end
]]
--------------------------
function api.nvim_redraw()
vim_api.nvim_command('mode')
vim.api.nvim_command 'mode'
end
---------------------------------
@ -110,9 +63,9 @@ function api.nvim_lecho(hlTables)
lecho_template[2] = tostring(hlTable.hl)
lecho_template[4] = tostring(hlTable.str)
vim_api.nvim_command(table.concat(lecho_template))
vim.api.nvim_command(table.concat(lecho_template))
end
vim_api.nvim_command('echohl None')
vim.api.nvim_command 'echohl None'
end
--------------------------------------
@ -125,18 +78,11 @@ end
]]
--------------------------------------
function api.nvim_show_err(title, msg)
local HighlightSegment = require('libmodal/src/Indicator/HighlightSegment')
api.nvim_lecho({
HighlightSegment.new('Title', tostring(title)..'\n'),
HighlightSegment.new('Error', tostring(msg)),
})
vim_api.nvim_call_function('getchar', {})
vim.fn.getchar()
end
--[[
/*
* PUBLICIZE MODULE
*/
--]]
return api

@ -1,47 +1,23 @@
--[[
/*
* MODULE
*/
--]]
--[[/* MODULE */]]
local utils = {}
utils.api = require('libmodal/src/utils/api')
utils.Help = require('libmodal/src/utils/Help')
utils.WindowState = require('libmodal/src/utils/WindowState')
--[[
/*
* FUNCTIONS
*/
--]]
--[[/* FUNCTIONS */]]
----------------------------------
--[[ SUMMARY:
* Show an error from `pcall()`.
]]
--[[ PARAMS:
`pcall_err` => the error generated by `pcall()`.
]]
----------------------------------
--- Show an error from `pcall()`.
--- @param pcall_err string the error generated by `pcall()`.
function utils.show_error(pcall_err)
local api = vim.api
utils.api.nvim_bell()
utils.api.nvim_show_err(
require('libmodal/src/globals').DEFAULT_ERROR_TITLE,
api.nvim_get_vvar('throwpoint')
.. '\n' ..
api.nvim_get_vvar('exception')
.. '\n' ..
tostring(pcall_err)
vim.v.throwpoint..'\n'..vim.v.exception..'\n'..pcall_err
)
end
--[[
/*
* PUBLICIZE MODULE
*/
--]]
--[[/* PUBLICIZE MODULE */]]
return utils

@ -0,0 +1,12 @@
if vim.g.loaded_libmodal then return end
vim.g.loaded_libmodal = true
vim.g.libmodalTimeouts = vim.g.libmodalTimeouts or vim.go.timeout
-- The default highlight groups (for colors) are specified below.
-- Change these default colors by defining or linking the corresponding highlight group.
vim.cmd
[[
highlight default link LibmodalPrompt ModeMsg
highlight default link LibmodalStar StatusLine
]]

@ -1,17 +0,0 @@
if exists('g:loaded_libmodal')
finish
endif
let g:loaded_libmodal = 1
if !exists('g:libmodalTimeouts')
let g:libmodalTimeouts = &timeout
endif
" ************************************************************
" * User Configuration
" ************************************************************
" The default highlight groups (for colors) are specified below.
" Change these default colors by defining or linking the corresponding highlight group.
highlight default link LibmodalPrompt ModeMsg
highlight default link LibmodalStar StatusLine
Loading…
Cancel
Save