feat: `Mode:exit` (#30)
* fix(Mode): adapt to changes in `timeoutlen` * feat(libmodal): do `self:exit()` inside callback * docs: `Mode:exit` * style: .editorconfig * docs(libmodal): fix broken example * feat(Mode): `self:switch` * docs: `Mode:switch` * feat(libmodal): `mode.switch` Wraps `Mode:switch` for convenience * docs: `libmodal.mode.switch` * docs(examples): `*.switch`pull/32/head
parent
3966014dbc
commit
1ecc4add3b
@ -0,0 +1,63 @@
|
||||
root = false
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = tab
|
||||
indent_style = tab
|
||||
insert_final_newline = true
|
||||
tab_width = 3
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[doc/*.txt]
|
||||
max_line_length = 80
|
||||
|
||||
[*.{yaml,yml}]
|
||||
indent_style = space
|
||||
|
||||
[*.lua]
|
||||
align_array_table = true
|
||||
align_call_args = false
|
||||
align_continuous_assign_statement = false
|
||||
align_continuous_inline_comment = true
|
||||
align_continuous_rect_table_field = false
|
||||
align_function_params = false
|
||||
align_if_branch = false
|
||||
auto_collapse_lines = true
|
||||
break_all_list_when_line_exceed = true
|
||||
call_arg_parentheses = remove_table_only
|
||||
continuation_indent = 1
|
||||
detect_end_of_line = false
|
||||
ignore_space_after_colon = false
|
||||
ignore_spaces_inside_function_call = false
|
||||
line_space_after_comment = max(2)
|
||||
line_space_after_do_statement = max(2)
|
||||
line_space_after_expression_statement = max(2)
|
||||
line_space_after_for_statement = max(2)
|
||||
line_space_after_function_statement = fixed(2)
|
||||
line_space_after_if_statement = max(2)
|
||||
line_space_after_local_or_assign_statement = max(2)
|
||||
line_space_after_repeat_statement = max(2)
|
||||
line_space_after_while_statement = max(2)
|
||||
max_line_length = 120
|
||||
never_indent_before_if_condition = false
|
||||
never_indent_comment_on_if_branch = false
|
||||
quote_style = single
|
||||
remove_call_expression_list_finish_comma = false
|
||||
space_after_comma = true
|
||||
space_after_comma_in_for_statement = true
|
||||
space_around_concat_operator = true
|
||||
space_around_math_operator = true
|
||||
space_around_table_append_operator = false
|
||||
space_around_table_field_list = true
|
||||
space_before_attribute = true
|
||||
space_before_closure_open_parenthesis = false
|
||||
space_before_function_call_open_parenthesis = false
|
||||
space_before_function_call_single_arg = false
|
||||
space_before_function_open_parenthesis = false
|
||||
space_before_inline_comment = 1
|
||||
space_before_open_square_bracket = false
|
||||
space_inside_function_call_parentheses = false
|
||||
space_inside_function_param_list_parentheses = false
|
||||
space_inside_square_brackets = false
|
||||
trailing_table_separator = smart
|
@ -1,71 +1,77 @@
|
||||
--- @class libmodal
|
||||
local libmodal = setmetatable(
|
||||
{
|
||||
layer =
|
||||
{
|
||||
--- enter a new layer.
|
||||
--- @param keymap table the keymaps (e.g. `{n = {gg = {rhs = 'G', silent = true}}}`)
|
||||
--- @param exit_char? string a character which can be used to exit the layer from normal mode.
|
||||
--- @return fun()|nil exit a function to exit the layer, or `nil` if `exit_char` is passed
|
||||
enter = function(keymap, exit_char)
|
||||
local layer = require('libmodal.Layer').new(keymap)
|
||||
layer:enter()
|
||||
local libmodal = setmetatable({}, {
|
||||
__index = function(tbl, key)
|
||||
if key ~= 'Layer' then
|
||||
return rawget(tbl, key)
|
||||
else
|
||||
if vim.deprecate then
|
||||
vim.deprecate('`libmodal.Layer`', '`libmodal.layer`', '4.0.0', 'nvim-libmodal')
|
||||
else
|
||||
vim.notify_once(
|
||||
'`libmodal.Layer` is deprecated in favor of `libmodal.layer`. It will work FOR NOW, but uncapitalize that `L` please :)',
|
||||
vim.log.levels.WARN,
|
||||
{title = 'nvim-libmodal'}
|
||||
)
|
||||
end
|
||||
|
||||
if exit_char then
|
||||
layer:map('n', exit_char, function() layer:exit() end, {})
|
||||
else
|
||||
return function() layer:exit() end
|
||||
end
|
||||
end,
|
||||
return rawget(tbl, 'layer')
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
--- create a new layer.
|
||||
--- @param keymap table the keymaps (e.g. `{n = {gg = {rhs = 'G', silent = true}}}`)
|
||||
--- @return libmodal.Layer
|
||||
new = function(keymap)
|
||||
return require('libmodal.Layer').new(keymap)
|
||||
end,
|
||||
},
|
||||
libmodal.layer = {}
|
||||
|
||||
mode =
|
||||
{
|
||||
--- enter a mode.
|
||||
--- @param name string the name of the mode.
|
||||
--- @param instruction fun()|string|table a Lua function, keymap dictionary, Vimscript command.
|
||||
enter = function(name, instruction, supress_exit)
|
||||
require('libmodal.Mode').new(name, instruction, supress_exit):enter()
|
||||
end
|
||||
},
|
||||
--- enter a new layer.
|
||||
--- @param keymap table the keymaps (e.g. `{n = {gg = {rhs = 'G', silent = true}}}`)
|
||||
--- @param exit_char? string a character which can be used to exit the layer from normal mode.
|
||||
--- @return fun()|nil exit a function to exit the layer, or `nil` if `exit_char` is passed
|
||||
function libmodal.layer.enter(keymap, exit_char)
|
||||
local layer = require('libmodal.Layer').new(keymap)
|
||||
layer:enter()
|
||||
|
||||
prompt =
|
||||
{
|
||||
--- enter a prompt.
|
||||
--- @param name string the name of the prompt
|
||||
--- @param instruction fun()|{[string]: fun()|string} what to do with user input
|
||||
--- @param user_completions? string[] a list of possible inputs, provided by the user
|
||||
enter = function(name, instruction, user_completions)
|
||||
require('libmodal.Prompt').new(name, instruction, user_completions):enter()
|
||||
end
|
||||
}
|
||||
},
|
||||
{
|
||||
__index = function(tbl, key)
|
||||
if key ~= 'Layer' then
|
||||
return rawget(tbl, key)
|
||||
else
|
||||
if vim.deprecate then
|
||||
vim.deprecate('`libmodal.Layer`', '`libmodal.layer`', '4.0.0', 'nvim-libmodal')
|
||||
else
|
||||
vim.notify_once(
|
||||
'`libmodal.Layer` is deprecated in favor of `libmodal.layer`. It will work FOR NOW, but uncapitalize that `L` please :)',
|
||||
vim.log.levels.WARN,
|
||||
{title = 'nvim-libmodal'}
|
||||
)
|
||||
end
|
||||
if exit_char then
|
||||
layer:map('n', exit_char, function() layer:exit() end, {})
|
||||
else
|
||||
return function() layer:exit() end
|
||||
end
|
||||
end
|
||||
|
||||
return rawget(tbl, 'layer')
|
||||
end
|
||||
end,
|
||||
}
|
||||
)
|
||||
--- create a new layer.
|
||||
--- @param keymap table the keymaps (e.g. `{n = {gg = {rhs = 'G', silent = true}}}`)
|
||||
--- @return libmodal.Layer
|
||||
function libmodal.layer.new(keymap)
|
||||
return require('libmodal.Layer').new(keymap)
|
||||
end
|
||||
|
||||
libmodal.mode = {}
|
||||
|
||||
--- enter a mode.
|
||||
--- @param name string the name of the mode.
|
||||
--- @param instruction fun()|string|table a Lua function, keymap dictionary, Vimscript command.
|
||||
function libmodal.mode.enter(name, instruction, supress_exit)
|
||||
local mode = require('libmodal.Mode').new(name, instruction, supress_exit)
|
||||
mode:enter()
|
||||
end
|
||||
|
||||
--- `enter` a mode using the arguments given, and do not return to the current mode.
|
||||
--- @param ... unknown arguments to `libmodal.mode.enter`
|
||||
--- @return fun(self: libmodal.Mode) switcher enters the mode
|
||||
--- @see libmodal.mode.enter which this function takes the same arguments as
|
||||
function libmodal.mode.switch(...)
|
||||
local args = { ... }
|
||||
return function(self)
|
||||
self:switch(unpack(args))
|
||||
end
|
||||
end
|
||||
|
||||
libmodal.prompt = {}
|
||||
|
||||
--- enter a prompt.
|
||||
--- @param name string the name of the prompt
|
||||
--- @param instruction fun()|{[string]: fun()|string} what to do with user input
|
||||
--- @param user_completions? string[] a list of possible inputs, provided by the user
|
||||
function libmodal.prompt.enter(name, instruction, user_completions)
|
||||
require('libmodal.Prompt').new(name, instruction, user_completions):enter()
|
||||
end
|
||||
|
||||
return libmodal
|
||||
|
Loading…
Reference in New Issue