2020-09-10 18:30:43 +00:00
|
|
|
|
*libmodal.txt* Create modes for Neovim
|
2020-05-14 02:55:57 +00:00
|
|
|
|
*libmodal*
|
|
|
|
|
*nvim-libmodal*
|
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
================================================================================
|
2020-11-14 01:18:27 +00:00
|
|
|
|
0. Table of Contents *libmodal-toc*
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
2020-05-14 02:55:57 +00:00
|
|
|
|
1. About ................ |libmodal-about|
|
|
|
|
|
2. Usage ................ |libmodal-usage|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
3. Examples ............. |libmodal-examples|
|
|
|
|
|
4. Configuration ........ |libmodal-configuration|
|
|
|
|
|
5. License .............. |libmodal-license|
|
|
|
|
|
6. Bugs ................. |libmodal-bugs|
|
|
|
|
|
7. Contributing ......... |libmodal-contributing|
|
2022-04-20 17:50:29 +00:00
|
|
|
|
8. Credits .............. |libmodal-credits|
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
================================================================================
|
2020-11-14 01:18:27 +00:00
|
|
|
|
1. About *libmodal-about*
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
|
|
|
|
|nvim-libmodal|:
|
|
|
|
|
- Author, Iron-E @ https://github.com/Iron-E & https://gitlab.com/Iron_E
|
|
|
|
|
- GitHub @ https://github.com/Iron-E/nvim-libmodal
|
|
|
|
|
|
|
|
|
|
Complete rewrite of |vim-libmodal|:
|
|
|
|
|
- Author, Iron-E @ https://github.com/Iron-E & https://gitlab.com/Iron_E
|
|
|
|
|
- GitHub @ https://github.com/Iron-E/vim-libmodal
|
|
|
|
|
|
|
|
|
|
|libmodal| is a Neovim library/|plugin| aimed at simplifying the creation
|
|
|
|
|
of new "modes" (e.g. |Insert|, |Normal|). The entrance of modes is
|
|
|
|
|
creator-defined, and their exit defaults to <Esc>. The use and name of
|
|
|
|
|
modes is also creator-defined, and is outlined in |libmodal-usage|.
|
|
|
|
|
|
|
|
|
|
See: |vim-modes|
|
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
--------------------------------------------------------------------------------
|
2020-11-14 01:18:27 +00:00
|
|
|
|
USE CASE *libmodal-use-case-example*
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
|
|
|
|
As an |init.vim| configuration grows, it becomes harder to create keybindings
|
|
|
|
|
that alphabetically represent the action that they perform. To get around
|
|
|
|
|
this, |libmodal| allows users to create a new "layer" of keybindings contained
|
|
|
|
|
within a pseudo-|vim-mode|. This layer of keybindings can be bound to a
|
|
|
|
|
command which executes `libmodal.mode.enter()` or `libmodal.prompt.enter()`,
|
|
|
|
|
and any settings outside of these commands are preserved.
|
|
|
|
|
|
2020-05-19 06:17:07 +00:00
|
|
|
|
For example, say that a user of Neovim regularly uses |:diffsplit| to merge
|
|
|
|
|
changes from `git`. They might define a "DIFF" mode that takes input and
|
|
|
|
|
directly translates it into |:diff|* operations. This would allow them to
|
|
|
|
|
|
|
|
|
|
For instance, perhaps this mode is defined so that `n` goes to the next diff
|
|
|
|
|
(like `]c`), and `N` goes to the previous diff (like `[c`). This would make
|
|
|
|
|
going from diff to diff more rememberable, as `n` is commonly used because of
|
|
|
|
|
`/` searches.
|
|
|
|
|
|
|
|
|
|
Suppose that the mode also numbers each |:buffer|, so that you don't have
|
|
|
|
|
to remember which |:diffsplit| to |:diffget| from. The numbers would disappear
|
|
|
|
|
when you leave the mode.
|
|
|
|
|
|
|
|
|
|
Finally, there could be a help key, `?`, which would show exactly which keys
|
|
|
|
|
have been mapped and what they do.
|
|
|
|
|
|
|
|
|
|
You can see such a mode here:
|
2020-11-14 01:18:27 +00:00
|
|
|
|
- https://gist.github.com/Iron-E/f36116e8862ea03fd195e4e0a48cb05d
|
2020-05-19 06:17:07 +00:00
|
|
|
|
|
|
|
|
|
Outside of the |libmodal-mode|, `n` still searches for the |last-pattern|, and
|
|
|
|
|
the buffers are not visibly numbered. Any setup that a |libmodal-mode| does to
|
|
|
|
|
inderpret keybindings is undone before the mode ends (while any changes to
|
|
|
|
|
buffers persevere).
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
|
|
|
|
See: |libmodal-usage|
|
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
================================================================================
|
2020-11-14 01:18:27 +00:00
|
|
|
|
2. Usage *libmodal-usage*
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-17 21:02:10 +00:00
|
|
|
|
The |libmodal| interface is designed completely in |Lua|. It is compatable
|
|
|
|
|
with Vimscript, and so one may either:
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-17 21:02:10 +00:00
|
|
|
|
1. Define a |Lua| interface for your mode (see |libmodal-examples|).
|
2020-11-14 01:18:27 +00:00
|
|
|
|
- Use |lua-require| as a |user-command|.
|
|
|
|
|
- See |lua-require-example| for information about how to do this.
|
|
|
|
|
- See `Iron-E/nvim-tabmode` for a complete example.
|
|
|
|
|
- See `Iron-E/mode-fugidiff.lua` on GitHub Gists for another example.
|
2020-05-17 21:02:10 +00:00
|
|
|
|
2. |call| `libmodal#Enter()` or `libmodal#Prompt()` from Vimscript.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
The following is a reference for high-level functions meant to be used by mode
|
|
|
|
|
creators. For those who wish to see a low-level specification of |libmodal|,
|
|
|
|
|
see |libmodal-lua|.
|
|
|
|
|
|
|
|
|
|
Note: Examples for all topics covered here can be found in the "examples"
|
|
|
|
|
folder at the root of the repository.
|
|
|
|
|
|
2020-05-19 06:17:07 +00:00
|
|
|
|
See: |api|, |lua-api|, https://github.com/Iron-E/nvim-tabmode,
|
|
|
|
|
https://gist.github.com/Iron-E/f36116e8862ea03fd195e4e0a48cb05d
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
--------------------------------------------------------------------------------
|
2020-11-14 01:18:27 +00:00
|
|
|
|
VARIABLES *libmodal-usage-variables*
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2023-02-17 18:12:37 +00:00
|
|
|
|
`vim.g`.libmodalActiveModeName *g:libmodalActiveModeName*
|
2020-11-14 01:18:27 +00:00
|
|
|
|
|
|
|
|
|
The name of the currently active |libmodal-mode|.
|
|
|
|
|
|
|
|
|
|
Type: ~
|
|
|
|
|
`string`
|
|
|
|
|
|
|
|
|
|
Default Value: ~
|
|
|
|
|
`nil`
|
|
|
|
|
|
|
|
|
|
See also: ~
|
2022-04-26 15:14:55 +00:00
|
|
|
|
|g:| For more information about global variables.
|
|
|
|
|
|vim.g| For info about accessing |g:| from lua.
|
2020-11-14 01:18:27 +00:00
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
FUNCTIONS *libmodal-usage-functions*
|
|
|
|
|
|
|
|
|
|
*libmodal-mode* *libmodal#Enter()* *libmodal.mode.enter()*
|
2022-04-25 21:59:33 +00:00
|
|
|
|
`libmodal.mode`.enter({name}, {instruction} [, {supress_exit}])
|
|
|
|
|
`libmodal`#Enter({name}, {instruction} [, {supress_exit}])
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
|
|
|
|
Enter a new |vim-mode| using {instruction} to determine what actions will
|
|
|
|
|
be taken upon specific user inputs.
|
|
|
|
|
|
|
|
|
|
User input is taken one character at a time using |getchar()|. It is
|
|
|
|
|
passed through a |g:var| determined by the {name} of the mode. For
|
|
|
|
|
example, if {name} is "FOO" then the |g:var| is `g:fooModeInput`.
|
|
|
|
|
Additionally, this input is reported as a |char2nr| number, and as such
|
|
|
|
|
should be decoded with `string.char()` (|nr2char| in |Lua|) if working
|
|
|
|
|
with raw characters is desired.
|
|
|
|
|
|
|
|
|
|
To take input on a line-by-line basis, see |libmodal-prompt|.
|
|
|
|
|
|
2020-05-17 21:02:10 +00:00
|
|
|
|
Note: `libmodal.mode.enter()`/`libmodal#Enter()` may be called from inside
|
2022-04-26 15:14:55 +00:00
|
|
|
|
itself. See |libmodal-examples| for an example.
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
|
|
|
|
{name} The name of the mode (e.g. |INSERT|).
|
|
|
|
|
|
|
|
|
|
- Case-sensitive. Caps are recommended.
|
|
|
|
|
|
|
|
|
|
{instruction} What to do when accepting user input.
|
|
|
|
|
|
2020-05-17 21:02:10 +00:00
|
|
|
|
- If {instruction} is a `dict`/`table`, then it is treated as a
|
|
|
|
|
map of user key-chord to Vim |command|s. Example: >
|
|
|
|
|
-- LUA
|
2020-05-15 02:12:15 +00:00
|
|
|
|
local modeInstruction = {
|
2021-07-07 18:25:14 +00:00
|
|
|
|
zf = 'split',
|
|
|
|
|
zfo = 'vsplit',
|
2020-09-10 18:30:43 +00:00
|
|
|
|
-- You can also use lua functions
|
2021-07-07 18:25:14 +00:00
|
|
|
|
zfc = function() return 'tabnew' end
|
2020-05-15 02:12:15 +00:00
|
|
|
|
}
|
2020-05-17 21:02:10 +00:00
|
|
|
|
|
|
|
|
|
" VIMSCRIPT
|
|
|
|
|
let s:modeInstruction = {
|
|
|
|
|
'zf': 'split',
|
|
|
|
|
'zfo': 'vsplit',
|
|
|
|
|
'zfc': 'tabnew'
|
|
|
|
|
}
|
2020-05-14 02:55:57 +00:00
|
|
|
|
<
|
|
|
|
|
|
2020-05-17 21:02:10 +00:00
|
|
|
|
Note: If no `?` key is defined, one will be created automatically.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-17 21:02:10 +00:00
|
|
|
|
- If {instruction} is a `function`, then it is called every time
|
|
|
|
|
that |getchar()| completes. The user input is received through
|
|
|
|
|
`g:{name}ModeInput` (see above).
|
|
|
|
|
|
2020-08-26 22:26:11 +00:00
|
|
|
|
*Error you cannot pass a funcref to Lua from Vimscript!
|
|
|
|
|
- If you want to use a |funcref()| for {instruction}, it
|
2022-05-17 04:00:38 +00:00
|
|
|
|
must be the name of the function as a `string`. >
|
2020-08-27 15:37:23 +00:00
|
|
|
|
" VIMSCRIPT
|
|
|
|
|
function! s:foo() abort
|
|
|
|
|
echo 'It works'
|
|
|
|
|
call getchar()
|
|
|
|
|
endfunction
|
|
|
|
|
lua require('libmodal').mode.enter('FOO', 's:foo')
|
|
|
|
|
<
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
Note: Some QoL features are available by default when
|
2020-05-17 21:02:10 +00:00
|
|
|
|
specifying a `dict`/`table` value for {instruction} that
|
|
|
|
|
would otherwise have to be programmed manually if a
|
|
|
|
|
`function` is specified.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
- A user's typed characters will show in the
|
|
|
|
|
lower right corner when {instruction} is a table.
|
|
|
|
|
- If `g:libmodalTimeouts` is enabled, then user input will be
|
2020-05-17 21:02:10 +00:00
|
|
|
|
subjected to the |timeoutlen|.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2022-04-25 21:59:33 +00:00
|
|
|
|
{supress_exit} Whether or not to automatically exit the mode upon an
|
|
|
|
|
<Esc> press.
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
2020-05-17 21:02:10 +00:00
|
|
|
|
- If |v:false|/`false`, then <Esc> is automatically mapped to
|
2020-05-15 02:12:15 +00:00
|
|
|
|
exiting.
|
2020-05-17 21:02:10 +00:00
|
|
|
|
- If |v:true|/`true`, then <Esc> is ignored unless specified by
|
2020-05-15 02:12:15 +00:00
|
|
|
|
the user. In such cases, the user should set the
|
|
|
|
|
`g:`{name}`ModeExit` variable to `true` when exiting is
|
2022-04-26 15:14:55 +00:00
|
|
|
|
desired. See |libmodal-examples|.
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
|
|
|
|
See also: ~
|
2022-04-26 15:14:55 +00:00
|
|
|
|
|lua-eval| For type conversions between Vimscript to |Lua|.
|
|
|
|
|
|libmodal-examples| For examples of this function.
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
|
|
|
|
|
2022-04-26 15:14:55 +00:00
|
|
|
|
*libmodal-layer* *libmodal.layer*
|
|
|
|
|
`libmodal.layer`.enter({keymap} [, {exit_char}]) *libmodal.layer.enter()*
|
2020-05-25 02:40:42 +00:00
|
|
|
|
|
|
|
|
|
While a |libmodal-mode| ignores behavior that has not been explicitly
|
2020-05-25 06:20:57 +00:00
|
|
|
|
defined, a |libmodal-layer| allows unrecognized |input| to be passed back
|
|
|
|
|
into Neovim for analysis.
|
2020-05-25 02:40:42 +00:00
|
|
|
|
|
|
|
|
|
So, if you have only defined a few keybindings, all of the remaining ones
|
|
|
|
|
from a user's configuration would still work— only new keymaps will be
|
|
|
|
|
overwritten.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2020-05-26 19:48:44 +00:00
|
|
|
|
{keymap} The keymap for the layer. General template is this: >
|
|
|
|
|
{
|
|
|
|
|
[<mode>] = {
|
|
|
|
|
[<lhs>] = {
|
2021-07-07 18:25:14 +00:00
|
|
|
|
rhs = <rhs>,
|
2020-05-26 19:48:44 +00:00
|
|
|
|
<opts>
|
|
|
|
|
},
|
|
|
|
|
…
|
|
|
|
|
},
|
|
|
|
|
…
|
|
|
|
|
}
|
|
|
|
|
< Where {mode}, {lhs}, {rhs}, and {opts} are the same as in
|
2022-04-25 21:59:33 +00:00
|
|
|
|
|vim.keymap.set()| (except you should not use multiple `<mode>` at
|
|
|
|
|
one time, despite |vim.keymap.set()| supporting it).
|
|
|
|
|
|
|
|
|
|
{exit_char} The character used to exit the layer.
|
2020-05-26 19:48:44 +00:00
|
|
|
|
|
2020-05-25 02:40:42 +00:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-04-25 21:59:33 +00:00
|
|
|
|
- The `function` used to undo changes made by the layer, or `nil` if
|
|
|
|
|
{exit_char} is provided.
|
2020-05-25 02:40:42 +00:00
|
|
|
|
|
2020-05-25 06:20:57 +00:00
|
|
|
|
See also: ~
|
2022-04-26 15:14:55 +00:00
|
|
|
|
|libmodal-examples| For an example.
|
|
|
|
|
|vim.keymap.set()| For more information about `opts`.
|
|
|
|
|
|
|
|
|
|
`libmodal.layer`.new({keymap}) *libmodal.layer.new()*
|
|
|
|
|
|
|
|
|
|
See |libmodal.layer.enter()| for more information. This function only
|
|
|
|
|
differs from |libmodal.layer.enter()| in that instead of entering the layer
|
|
|
|
|
immediately, it returns a |libmodal.Layer| object for you to manipulate.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
|
|
|
|
{keymap} The keymap for the layer. General template is this: >
|
|
|
|
|
{
|
|
|
|
|
[<mode>] = {
|
|
|
|
|
[<lhs>] = {
|
|
|
|
|
rhs = <rhs>,
|
|
|
|
|
<opts>
|
|
|
|
|
},
|
|
|
|
|
…
|
|
|
|
|
},
|
|
|
|
|
…
|
|
|
|
|
}
|
|
|
|
|
< Where {mode}, {lhs}, {rhs}, and {opts} are the same as in
|
|
|
|
|
|vim.keymap.set()| (except you should not use multiple `<mode>` at
|
|
|
|
|
one time, despite |vim.keymap.set()| supporting it).
|
|
|
|
|
|
|
|
|
|
Return: ~
|
|
|
|
|
- A |libmodal.Layer| object.
|
|
|
|
|
|
|
|
|
|
See also: ~
|
|
|
|
|
|libmodal-layer| For more information about layers.
|
|
|
|
|
|libmodal-examples| For an example.
|
|
|
|
|
|vim.keymap.set()| For more information about `opts`.
|
|
|
|
|
|
|
|
|
|
*libmodal-Layer* *libmodal.Layer*
|
|
|
|
|
`libmodal.Layer`:enter() *libmodal.Layer:enter()*
|
|
|
|
|
|
|
|
|
|
Applies the {keymap} which was provided by |libmodal.layer.new|. These two
|
|
|
|
|
code snippets are equivalent: >
|
|
|
|
|
local libmodal = require 'libmodal'
|
|
|
|
|
|
|
|
|
|
-- enter a layer directly
|
|
|
|
|
libmodal.layer.enter({n = gg = {rhs = 'G'}})
|
|
|
|
|
|
|
|
|
|
-- enter a layer manually
|
|
|
|
|
local layer = libmodal.layer.new({n = gg = {rhs = 'G'}})
|
|
|
|
|
layer:enter()
|
|
|
|
|
<
|
|
|
|
|
See also: ~
|
2022-05-17 04:00:38 +00:00
|
|
|
|
|libmodal.layer.enter| A shortcut to access this function.
|
|
|
|
|
|libmodal.layer.new| How to create a |libmodal.Layer|
|
|
|
|
|
|
|
|
|
|
`libmodal.Layer`:is_active() *libmodal.Layer:is_active()*
|
|
|
|
|
|
|
|
|
|
Return: ~
|
|
|
|
|
- `true` if the |Layer:enter()| has been called, but not
|
|
|
|
|
|Layer:exit()|. `false` otherwise.
|
|
|
|
|
|
|
|
|
|
See also: ~
|
|
|
|
|
|libmodal.Layer:enter()| A shortcut to access this function.
|
|
|
|
|
|libmodal.Layer.exit()| How to create a |libmodal.Layer|
|
2022-04-26 15:14:55 +00:00
|
|
|
|
|
|
|
|
|
`libmodal.Layer`:map({mode}, {lhs}, {rhs}, {opts}) *libmodal.Layer:map()*
|
|
|
|
|
|
|
|
|
|
{mode}, {lhs}, {rhs}, and {opts} are the same as in |vim.keymap.set()|
|
|
|
|
|
except that a {mode} table is not supported.
|
|
|
|
|
|
|
|
|
|
See also: ~
|
|
|
|
|
|libmodal-examples| For an example.
|
|
|
|
|
|vim.keymap.set()| For information about the args.
|
|
|
|
|
|
|
|
|
|
`libmodal.Layer`:unmap({mode}, {lhs}) *libmodal.Layer:unmap()*
|
|
|
|
|
|
|
|
|
|
{mode} and {lhs} are the same as in |vim.keymap.del()| except that a {mode}
|
|
|
|
|
table is not supported.
|
|
|
|
|
|
|
|
|
|
Note: this function cannot be called until after |libmodal.Layer:enter()|
|
|
|
|
|
|
|
|
|
|
See also: ~
|
|
|
|
|
|libmodal-examples| For an example.
|
|
|
|
|
|vim.keymap.del()| For information about the args.
|
2020-05-25 02:40:42 +00:00
|
|
|
|
|
2022-04-25 21:59:33 +00:00
|
|
|
|
*libmodal-prompt* *libmodal#Prompt()* *libmodal.prompt.enter()*
|
|
|
|
|
`libmodal.prompt`.enter({name}, {instruction} [, {completions}])
|
|
|
|
|
`libmodal`#Prompt({name}, {instruction} [, {completions}])
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
|
|
|
|
Besides accepting user input like keys in |Normal-mode|, |libmodal| is
|
|
|
|
|
also capable of prompting the user for |input| like |Cmdline-mode|. To
|
|
|
|
|
define a |Cmdline-mode|-like prompt, use this function rather than
|
2020-05-17 21:02:10 +00:00
|
|
|
|
`libmodal.mode.enter()`/`libmodal#Enter()`.
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
|
|
|
|
User input is taken using |input()|. It is passed through a |g:var|
|
|
|
|
|
determined by the {name} of the mode. For example, if {name} is "FOO"
|
|
|
|
|
then the |g:var| is `g:fooModeInput`.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
|
|
|
|
{name} The name of the mode (e.g. |INSERT|).
|
|
|
|
|
|
|
|
|
|
- Case-sensitive. Caps are recommended.
|
|
|
|
|
|
|
|
|
|
{instruction} What to do when accepting user input.
|
|
|
|
|
|
2020-05-17 21:02:10 +00:00
|
|
|
|
- If {instruction} is a `dict`/`table`, then it is treated as a
|
|
|
|
|
map of user inputs to Vim |command|s. Example: >
|
|
|
|
|
-- LUA
|
|
|
|
|
local modeInstruction = {
|
2021-07-07 18:25:14 +00:00
|
|
|
|
new = 'tabnew',
|
|
|
|
|
close = 'tabclose',
|
|
|
|
|
last = 'tablast'
|
2020-05-17 21:02:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
" VIMSCRIPT
|
|
|
|
|
let s:modeInstruction = {
|
|
|
|
|
'new': 'tabnew',
|
|
|
|
|
'close': 'tabclose',
|
|
|
|
|
'last': 'tablast'
|
|
|
|
|
}
|
2020-05-14 02:55:57 +00:00
|
|
|
|
<
|
2020-05-15 02:12:15 +00:00
|
|
|
|
- If {instruction} is a `function`, then it is called
|
|
|
|
|
every time that |input()| completes. The user input
|
|
|
|
|
is received through `g:{name}ModeInput` (see above).
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-08-26 22:26:11 +00:00
|
|
|
|
*Error you cannot pass a funcref to Lua from Vimscript!
|
|
|
|
|
- If you want to use a |funcref()| for {instruction}, it
|
|
|
|
|
must be the name of the function as a `string`.
|
2020-08-27 15:37:23 +00:00
|
|
|
|
" VIMSCRIPT
|
|
|
|
|
function! s:foo() abort
|
|
|
|
|
echo 'It works'
|
|
|
|
|
call getchar()
|
|
|
|
|
endfunction
|
|
|
|
|
lua require('libmodal').prompt.enter('FOO', 's:foo')
|
|
|
|
|
<
|
2020-05-17 21:02:10 +00:00
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
Note: If you want to create commands with arguments, you will
|
|
|
|
|
need to use a `function`.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
{completions} An array-like `table` of commands that are offered by
|
|
|
|
|
the prompt.
|
|
|
|
|
|
|
|
|
|
- Automatically generated when {instruction} is a `table`.
|
|
|
|
|
- Used to provide auto-completion when the user is typing.
|
|
|
|
|
- If unspecified, and {instruction} is not a `table`, then no
|
|
|
|
|
completions will be provided.
|
|
|
|
|
|
|
|
|
|
Note: If no `help` command is defined, one will be created
|
|
|
|
|
automatically.
|
|
|
|
|
|
2022-04-25 21:59:33 +00:00
|
|
|
|
Note: The user may set the `g:`{name}`ModeExit` variable to
|
|
|
|
|
`true` at any time to prematurely exit.
|
2020-12-19 23:27:35 +00:00
|
|
|
|
|
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
See also: ~
|
2022-04-26 15:14:55 +00:00
|
|
|
|
|lua-eval| For type conversions between Vimscript to |Lua|.
|
|
|
|
|
|libmodal-examples| For examples of this function.
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
2023-02-17 18:12:37 +00:00
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
EVENTS *libmodal-usage-events*
|
|
|
|
|
|
2023-02-17 20:34:43 +00:00
|
|
|
|
|libmodal| fires the |ModeChanged| |autocommand| |{event}| when entering and
|
|
|
|
|
exiting |libmodal-mode|s.
|
2023-02-17 18:12:37 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
================================================================================
|
2020-11-14 01:18:27 +00:00
|
|
|
|
3. Examples *libmodal-examples*
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
2022-04-25 21:59:33 +00:00
|
|
|
|
See the official examples at the link below:
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2022-04-25 21:59:33 +00:00
|
|
|
|
https://github.com/Iron-E/nvim-libmodal/tree/master/examples
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
================================================================================
|
2020-11-14 01:18:27 +00:00
|
|
|
|
4. Configuration *libmodal-configuration*
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
2020-05-16 21:19:26 +00:00
|
|
|
|
The following specifies what settings may be used to configure
|
|
|
|
|
|libmodal-mode|s and |libmodal-prompt|s.
|
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
--------------------------------------------------------------------------------
|
2020-11-14 01:18:27 +00:00
|
|
|
|
HIGHLIGHT GROUPS *libmodal-highlight-groups*
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The following |highlight-groups| can be |config|ured to change a mode's |color|s:
|
|
|
|
|
|
2020-05-15 21:39:28 +00:00
|
|
|
|
Name Default Description
|
|
|
|
|
---------------- ------------ --------------------------
|
|
|
|
|
`LibmodalPrompt` `ModeMsg` Color for the mode text.
|
|
|
|
|
`LibmodalStar` `StatusLine` Color for the prompt text.
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
|
|
|
|
Note: `LibmodalStar`'s name — while not indicative of its use — is used for
|
|
|
|
|
the sake of backwards compatability.
|
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
--------------------------------------------------------------------------------
|
2020-11-14 01:18:27 +00:00
|
|
|
|
TIMEOUTS *libmodal-timeouts* *g:libmodalTimeouts*
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
|
|
|
|
When `libmodal.mode.enter()`'s {instruction} argument is a `table`, mode
|
|
|
|
|
creators may also enable the use of Vim's built-in 'timeout' feature.
|
|
|
|
|
|
|
|
|
|
To enable 'timeout's, one may set the following |variables|:
|
2020-05-15 21:39:28 +00:00
|
|
|
|
|
|
|
|
|
Lua: ~
|
|
|
|
|
>
|
|
|
|
|
" Set libmodal modes to turn timeouts on.
|
2021-07-07 18:25:14 +00:00
|
|
|
|
vim.g.libmodalTimeouts = true
|
2020-05-15 21:39:28 +00:00
|
|
|
|
" Enable timeouts for specific mode.
|
2021-07-07 18:25:14 +00:00
|
|
|
|
vim.g[name..'ModeTimeouts'] = true
|
2020-05-15 21:39:28 +00:00
|
|
|
|
<
|
|
|
|
|
Vimscript: ~
|
2020-05-14 02:55:57 +00:00
|
|
|
|
>
|
|
|
|
|
" Set libmodal modes to turn timeouts on.
|
2021-07-07 18:25:14 +00:00
|
|
|
|
let g:libmodalTimeouts = v:true
|
2020-05-14 02:55:57 +00:00
|
|
|
|
" Enable timeouts for specific mode.
|
2021-07-07 18:25:14 +00:00
|
|
|
|
let g:{name}ModeTimeouts = v:true
|
2020-05-14 02:55:57 +00:00
|
|
|
|
<
|
2020-05-15 21:39:28 +00:00
|
|
|
|
|
|
|
|
|
|
2020-05-14 02:55:57 +00:00
|
|
|
|
Similarly, to disable them, one may set them to `0`.
|
|
|
|
|
|
2020-05-15 21:39:28 +00:00
|
|
|
|
When `g:libmodalTimeouts` or `g:{name}ModeTimeouts` is set to `1`, |libmodal|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
will automatically execute commands that have mappings that might also be
|
|
|
|
|
longer mappings. For example:
|
|
|
|
|
If a mode specifies `zf` and `zfo` as mappings,
|
|
|
|
|
- Turning 'timeout's on will cause `zf` to be executed if the user waits
|
|
|
|
|
for 'timeoutlen' without typing another character.
|
|
|
|
|
- If 'timeout' were to be off in this case, then the user would either
|
|
|
|
|
have to hit <CR> to execute `zf` or hit `o` to execute `zfo`.
|
|
|
|
|
|
|
|
|
|
NOTE: `g:libmodalTimeouts` defaults to the 'timeout' value.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
NOTE: The `g:limbodalTimeouts` variable should NOT be defined by plugins.
|
|
|
|
|
- Allow users to decide whether or not they want timeouts to be
|
|
|
|
|
enabled globally themselves.
|
|
|
|
|
|
|
|
|
|
NOTE: Mode-specific timeout variables will override `g:libmodalTimeouts`.
|
|
|
|
|
|
|
|
|
|
When enabled, |libmodal-timeouts| will reference the mode user's 'timeoutlen'
|
2020-05-14 02:55:57 +00:00
|
|
|
|
as specified in their |config|. This way, modes will feel consistent to users
|
|
|
|
|
by default.
|
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
However, mode creators may change 'timeoutlen' upon entrance of a mode, and
|
2020-05-14 02:55:57 +00:00
|
|
|
|
then reset it upon exit. Example:
|
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
Vimscript: ~
|
2020-05-14 02:55:57 +00:00
|
|
|
|
>
|
2020-05-15 02:12:15 +00:00
|
|
|
|
function! s:FooMode() abort
|
|
|
|
|
" Get the user's preferred timeout length.
|
|
|
|
|
let l:timeoutlen = &timeoutlen
|
|
|
|
|
" Set it to something else, like 1500ms
|
|
|
|
|
let &timeoutlen = 1500
|
|
|
|
|
" Enter a mode
|
|
|
|
|
call libmodal#Enter(…)
|
|
|
|
|
" Reset the timeout
|
|
|
|
|
let &timeoutlen = l:timeoutlen
|
|
|
|
|
endfunction
|
|
|
|
|
<
|
|
|
|
|
Lua: ~
|
|
|
|
|
>
|
|
|
|
|
local libmodal = require('libmodal')
|
|
|
|
|
|
|
|
|
|
function fooMode()
|
|
|
|
|
-- Get the user's preferred timeout length.
|
2021-07-07 18:25:14 +00:00
|
|
|
|
local prevTimeoutLen = vim.go.timeoutlen
|
2020-05-15 02:12:15 +00:00
|
|
|
|
-- Set it to something else, like 1500ms.
|
2021-07-07 18:25:14 +00:00
|
|
|
|
vim.go.timeoutlen = 1500
|
2020-05-15 02:12:15 +00:00
|
|
|
|
-- Enter a mode.
|
|
|
|
|
libmodal.mode.enter(…)
|
|
|
|
|
-- Restore the `timeoutlen`
|
2021-07-07 18:25:14 +00:00
|
|
|
|
vim.go.timeoutlen = prevTimeoutLen
|
2020-05-15 02:12:15 +00:00
|
|
|
|
end
|
2020-05-14 02:55:57 +00:00
|
|
|
|
<
|
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
Mode creators who use `function` {instruction}s may define timeouts manually
|
|
|
|
|
using |timers|, which is how |libmodal| implements them internally.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
================================================================================
|
2020-11-14 01:18:27 +00:00
|
|
|
|
5. License *libmodal-license*
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
`nvim-libmodal` – Create new "modes" for Neovim.
|
|
|
|
|
Copyright © 2020 Iron-E
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
================================================================================
|
2020-11-14 01:18:27 +00:00
|
|
|
|
6. Bugs *libmodal-bugs*
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-11-14 01:18:27 +00:00
|
|
|
|
- `libmodal#Enter()` does not work when {instruction} is a |funcref|.
|
|
|
|
|
- See |E5004|.
|
|
|
|
|
- `libmodal#Prompt()` does not work when {instruction} is a |funcref|.
|
|
|
|
|
- See |E5004|.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
================================================================================
|
2020-11-14 01:18:27 +00:00
|
|
|
|
7. Contributing *libmodal-contributing*
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-16 21:19:26 +00:00
|
|
|
|
The following describes what should be done if an individual wishes to
|
|
|
|
|
contribute something to the `Iron-E/nvim-libmodal` repository.
|
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
--------------------------------------------------------------------------------
|
2020-11-14 01:18:27 +00:00
|
|
|
|
CODE *libmodal-contributing-code*
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
Bugfixes ~
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
If you discover a bug and believe you know the solution to fixing it, then
|
|
|
|
|
submit a bug report and state that you are working on a fix (and what that
|
|
|
|
|
fix might be), and what general timeframe the fix may be completed in
|
|
|
|
|
(months, weeks, days, etc.).
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
When the fix is complete, submit a PR that references the issue you
|
|
|
|
|
submitted.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
Features ~
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
If there is a feature you would like to be a part of |libmodal|, the best
|
|
|
|
|
thing you can do is submit a feature request, and then state that you are
|
|
|
|
|
working on a pull request (PR) so others don't attempt to do the same work
|
|
|
|
|
at the same time.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
When you believe your feature is complete, write some examples for it in
|
|
|
|
|
the `examples/lua` folder, and add them to |libmodal-examples| as
|
|
|
|
|
appropriate.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
Assure that all existing |libmodal-examples| continue to work with your
|
|
|
|
|
feature, unless a breaking change was discussed on the feature request.
|
|
|
|
|
If you need help getting them to pass, you can ask for help on the PR.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
Reference the issue you submitted on the PR so that the two show up
|
|
|
|
|
together when looking back at the history.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
Contributing documentation is not necessary but appreciated, since the
|
|
|
|
|
person who knows the most about the feature being implemented is most
|
|
|
|
|
likely the one implementing it.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
--------------------------------------------------------------------------------
|
2020-11-14 01:18:27 +00:00
|
|
|
|
DOCUMENTATION *libmodal-contributing-documentation*
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-05-15 02:12:15 +00:00
|
|
|
|
If there is a problem with the documentation, or you see an area where it
|
|
|
|
|
could be improved, don't hesitate to submit an issue and a PR. At the very
|
|
|
|
|
least it will exist in history if such an issue comes up again, and likely it
|
|
|
|
|
will serve to help yourself and others with more clear and concise wording, or
|
|
|
|
|
with more helpful and practical examples.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
--------------------------------------------------------------------------------
|
2020-11-14 01:18:27 +00:00
|
|
|
|
ISSUES *libmodal-contributing-issues*
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
|
|
|
|
Issues are greatly welcomed on the GitHub repository, whether they are bug
|
|
|
|
|
reports, feature requests, documentation improvements, or misunderstandings:
|
|
|
|
|
it's all good to have in the archive.
|
|
|
|
|
|
|
|
|
|
When submitting an issue, please describe the following:
|
|
|
|
|
|
|
|
|
|
1. Context regarding the issue (how you discovered it, pertinent information,
|
|
|
|
|
etc.)
|
|
|
|
|
2. Detailed description of the issue.
|
|
|
|
|
3. Steps to reproduce (if applicable).
|
|
|
|
|
4. Expected behavior (if applicable).
|
|
|
|
|
5. Attached media (screenshots, logs, etc.) (if applicable).
|
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
================================================================================
|
2022-04-20 17:50:29 +00:00
|
|
|
|
8. Credits *libmodal-credits*
|
2020-05-15 02:12:15 +00:00
|
|
|
|
|
|
|
|
|
Credit Reason
|
|
|
|
|
--------------------- ----------------------------------
|
|
|
|
|
Daniel Steinberg |vim-win| creator and inspiration.
|
|
|
|
|
Iron-E Primary contibuter/maintainer.
|
|
|
|
|
neoclide/|coc-nvim| Development environment provider.
|
|
|
|
|
r/Neovim |Lua| and Neovim reference.
|
|
|
|
|
Roberto Ierusalimschy "Programming In Lua: 5.1".
|
|
|
|
|
Steve Losh "Learn Vimscript The Hard Way".
|
|
|
|
|
tbastos/vim-lua Syntax highlighting for |Lua|.
|
|
|
|
|
u/Mambu38 |Lua| reference.
|
|
|
|
|
u/oryiesis Inspiration.
|
|
|
|
|
www.lua-users.org |Lua| reference.
|
|
|
|
|
www.stackoverflow.com Vimscript and |Lua| reference.
|
2020-05-14 02:55:57 +00:00
|
|
|
|
|
2020-09-10 18:30:43 +00:00
|
|
|
|
================================================================================
|
|
|
|
|
vim:tw=80:ts=4:ft=help:norl:
|