nvim-libmodal/examples/lua/submodes.lua

29 lines
766 B
Lua
Raw Normal View History

local libmodal = require 'libmodal'
2020-08-27 16:10:01 +00:00
2022-04-26 15:33:37 +00:00
-- recurse counter
local foo_mode_recurse = 1
2022-04-26 15:33:37 +00:00
-- function which is called whenever the user presses a button
2020-07-03 17:01:04 +00:00
function FooMode()
2022-04-26 15:33:37 +00:00
-- append to the input history, the latest button press
local userInput = string.char(vim.g[
2022-04-26 15:33:37 +00:00
-- the input is a character number
'foo' .. tostring(foo_mode_recurse) .. 'ModeInput'
])
2022-04-26 15:33:37 +00:00
-- if the user pressed 'z', then increase the counter and recurse
2020-05-13 22:22:25 +00:00
if userInput == 'z' then
foo_mode_recurse = foo_mode_recurse + 1
2020-07-03 17:01:04 +00:00
Enter()
foo_mode_recurse = foo_mode_recurse - 1
end
end
2022-04-26 15:33:37 +00:00
-- function to wrap around entering the mode so it can be recursively called
2020-07-03 17:01:04 +00:00
function Enter()
libmodal.mode.enter('FOO' .. foo_mode_recurse, FooMode)
end
2022-04-26 15:33:37 +00:00
-- initially call the function to begin the demo
2020-07-03 17:01:04 +00:00
Enter()