Skip to content

Commit ac97661

Browse files
authored
Merge pull request #7 from Iron-E/feature/lua-function-instructions
Feature/lua function instructions
2 parents 38b7261 + d35778c commit ac97661

File tree

10 files changed

+385
-264
lines changed

10 files changed

+385
-264
lines changed

doc/libmodal-lua.txt

Lines changed: 194 additions & 160 deletions
Large diffs are not rendered by default.

doc/libmodal.txt

Lines changed: 82 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
*libmodal.txt* Create modes for Neovim
1+
*libmodal.txt* Create modes for Neovim
22
*libmodal*
33
*nvim-libmodal*
44

5-
=============================================================================
6-
0. Table of Contents *libmodal-toc*
5+
================================================================================
6+
0. Table of Contents *libmodal-toc*
77

88
1. About ................ |libmodal-about|
99
2. Usage ................ |libmodal-usage|
@@ -15,8 +15,8 @@
1515
8. Changelog ............ |libmodal-changelog|
1616
9. Credits .............. |libmodal-credits|
1717

18-
==============================================================================
19-
1. About *libmodal-about*
18+
================================================================================
19+
1. About *libmodal-about*
2020

2121
|nvim-libmodal|:
2222
- Author, Iron-E @ https://github.com/Iron-E & https://gitlab.com/Iron_E
@@ -33,8 +33,8 @@ modes is also creator-defined, and is outlined in |libmodal-usage|.
3333

3434
See: |vim-modes|
3535

36-
------------------------------------------------------------------------------
37-
USE CASE *libmodal-use-case-example*
36+
--------------------------------------------------------------------------------
37+
USE CASE *libmodal-use-case-example*
3838

3939
As an |init.vim| configuration grows, it becomes harder to create keybindings
4040
that alphabetically represent the action that they perform. To get around
@@ -69,8 +69,8 @@ buffers persevere).
6969

7070
See: |libmodal-usage|
7171

72-
==============================================================================
73-
2. Usage *libmodal-usage*
72+
================================================================================
73+
2. Usage *libmodal-usage*
7474

7575
The |libmodal| interface is designed completely in |Lua|. It is compatable
7676
with Vimscript, and so one may either:
@@ -92,8 +92,8 @@ Note: Examples for all topics covered here can be found in the "examples"
9292
See: |api|, |lua-api|, https://github.com/Iron-E/nvim-tabmode,
9393
https://gist.github.com/Iron-E/f36116e8862ea03fd195e4e0a48cb05d
9494

95-
------------------------------------------------------------------------------
96-
FUNCTIONS *libmodal-usage-functions*
95+
--------------------------------------------------------------------------------
96+
FUNCTIONS *libmodal-usage-functions*
9797

9898
*libmodal-mode* *libmodal#Enter()* *libmodal.mode.enter()*
9999
`libmodal.mode`.enter({name}, {instruction} [, {supressExit}])
@@ -127,7 +127,8 @@ FUNCTIONS *libmodal-usage-functions*
127127
local modeInstruction = {
128128
['zf'] = 'split',
129129
['zfo'] = 'vsplit',
130-
['zfc'] = 'tabnew'
130+
-- You can also use lua functions
131+
['zfc'] = function() return 'tabnew' end
131132
}
132133
133134
" VIMSCRIPT
@@ -286,8 +287,8 @@ FUNCTIONS *libmodal-usage-functions*
286287
|libmodal-examples-prompt| For examples of this function.
287288

288289

289-
==============================================================================
290-
3. Examples *libmodal-examples*
290+
================================================================================
291+
3. Examples *libmodal-examples*
291292

292293
Below are examples written in |Lua| to help show how specific features of
293294
|libmodal| may be implemented. In each example, the name of the mode is
@@ -300,8 +301,8 @@ all be tested using the |luafile| |command|.
300301

301302
See: |libmodal-usage|, |libmodal-use-case|, |lua-require-example|.
302303

303-
------------------------------------------------------------------------------
304-
MODES *libmodal-examples-modes*
304+
--------------------------------------------------------------------------------
305+
MODES *libmodal-examples-modes*
305306

306307
Using a callback `function`: >
307308
local api = vim.api
@@ -356,7 +357,7 @@ Using a |key-mapping| `table`: >
356357
<
357358

358359
Exit Supression ~
359-
*libmodal-examples-supress-exit*
360+
*libmodal-examples-supress-exit*
360361

361362
Using a callback `function`: >
362363
local libmodal = require('libmodal')
@@ -399,7 +400,7 @@ Using a |key-mapping| `table`: >
399400
<
400401

401402
Submodes ~
402-
*libmodal-examples-submodes*
403+
*libmodal-examples-submodes*
403404

404405
Using a callback `function`: >
405406
local libmodal = require('libmodal')
@@ -457,8 +458,8 @@ Using a |key-mapping| `table`: >
457458
fooMode()
458459
<
459460

460-
------------------------------------------------------------------------------
461-
LAYERS *libmodal-examples-layers*
461+
--------------------------------------------------------------------------------
462+
LAYERS *libmodal-examples-layers*
462463
>
463464
local libmodal = require('libmodal')
464465
@@ -481,8 +482,8 @@ LAYERS *libmodal-examples-layers*
481482
vim.schedule_wrap(exitFunc)
482483
)
483484
<
484-
------------------------------------------------------------------------------
485-
PROMPTS *libmodal-examples-prompts*
485+
--------------------------------------------------------------------------------
486+
PROMPTS *libmodal-examples-prompts*
486487

487488
Using a callback `function`: >
488489
local libmodal = require('libmodal')
@@ -524,14 +525,14 @@ Using a |command| `table`: >
524525
libmodal.prompt.enter('BAR', commands)
525526
<
526527

527-
==============================================================================
528-
4. Configuration *libmodal-configuration*
528+
================================================================================
529+
4. Configuration *libmodal-configuration*
529530

530531
The following specifies what settings may be used to configure
531532
|libmodal-mode|s and |libmodal-prompt|s.
532533

533-
------------------------------------------------------------------------------
534-
HIGHLIGHT GROUPS *libmodal-highlight-groups*
534+
--------------------------------------------------------------------------------
535+
HIGHLIGHT GROUPS *libmodal-highlight-groups*
535536

536537

537538
The following |highlight-groups| can be |config|ured to change a mode's |color|s:
@@ -548,8 +549,8 @@ Note: `LibmodalStar`'s name — while not indicative of its use — is used for
548549
when Neovim 0.5 launches that will introduce interoperaability between
549550
the two.
550551

551-
------------------------------------------------------------------------------
552-
TIMEOUTS *libmodal-timeouts* *g:libmodalTimeouts*
552+
--------------------------------------------------------------------------------
553+
TIMEOUTS *libmodal-timeouts* *g:libmodalTimeouts*
553554

554555
When `libmodal.mode.enter()`'s {instruction} argument is a `table`, mode
555556
creators may also enable the use of Vim's built-in 'timeout' feature.
@@ -631,8 +632,8 @@ then reset it upon exit. Example:
631632
Mode creators who use `function` {instruction}s may define timeouts manually
632633
using |timers|, which is how |libmodal| implements them internally.
633634

634-
==============================================================================
635-
5. License *libmodal-license*
635+
================================================================================
636+
5. License *libmodal-license*
636637

637638
`nvim-libmodal` – Create new "modes" for Neovim.
638639
Copyright © 2020 Iron-E
@@ -650,66 +651,66 @@ GNU General Public License for more details.
650651
You should have received a copy of the GNU General Public License
651652
along with this program. If not, see <http://www.gnu.org/licenses/>.
652653

653-
==============================================================================
654-
6. Bugs *libmodal-bugs*
654+
================================================================================
655+
6. Bugs *libmodal-bugs*
655656

656657
* `libmodal#Enter()` does not work when {instruction} is a |funcref|.
657658
* See |E5004|.
658659
* `libmodal#Prompt()` does not work when {instruction} is a |funcref|.
659660
* See |E5004|.
660661

661-
==============================================================================
662-
7. Contributing *libmodal-contributing*
662+
================================================================================
663+
7. Contributing *libmodal-contributing*
663664

664665
The following describes what should be done if an individual wishes to
665666
contribute something to the `Iron-E/nvim-libmodal` repository.
666667

667-
------------------------------------------------------------------------------
668-
CODE *libmodal-contributing-code*
668+
--------------------------------------------------------------------------------
669+
CODE *libmodal-contributing-code*
669670

670-
Bugfixes ~
671+
Bugfixes ~
671672

672-
If you discover a bug and believe you know the solution to fixing it, then
673-
submit a bug report and state that you are working on a fix (and what that
674-
fix might be), and what general timeframe the fix may be completed in
675-
(months, weeks, days, etc.).
673+
If you discover a bug and believe you know the solution to fixing it, then
674+
submit a bug report and state that you are working on a fix (and what that
675+
fix might be), and what general timeframe the fix may be completed in
676+
(months, weeks, days, etc.).
676677

677-
When the fix is complete, submit a PR that references the issue you
678-
submitted.
678+
When the fix is complete, submit a PR that references the issue you
679+
submitted.
679680

680-
Features ~
681+
Features ~
681682

682-
If there is a feature you would like to be a part of |libmodal|, the best
683-
thing you can do is submit a feature request, and then state that you are
684-
working on a pull request (PR) so others don't attempt to do the same work
685-
at the same time.
683+
If there is a feature you would like to be a part of |libmodal|, the best
684+
thing you can do is submit a feature request, and then state that you are
685+
working on a pull request (PR) so others don't attempt to do the same work
686+
at the same time.
686687

687-
When you believe your feature is complete, write some examples for it in
688-
the `examples/lua` folder, and add them to |libmodal-examples| as
689-
appropriate.
688+
When you believe your feature is complete, write some examples for it in
689+
the `examples/lua` folder, and add them to |libmodal-examples| as
690+
appropriate.
690691

691-
Assure that all existing |libmodal-examples| continue to work with your
692-
feature, unless a breaking change was discussed on the feature request.
693-
If you need help getting them to pass, you can ask for help on the PR.
692+
Assure that all existing |libmodal-examples| continue to work with your
693+
feature, unless a breaking change was discussed on the feature request.
694+
If you need help getting them to pass, you can ask for help on the PR.
694695

695-
Reference the issue you submitted on the PR so that the two show up
696-
together when looking back at the history.
696+
Reference the issue you submitted on the PR so that the two show up
697+
together when looking back at the history.
697698

698-
Contributing documentation is not necessary but appreciated, since the
699-
person who knows the most about the feature being implemented is most
700-
likely the one implementing it.
699+
Contributing documentation is not necessary but appreciated, since the
700+
person who knows the most about the feature being implemented is most
701+
likely the one implementing it.
701702

702-
------------------------------------------------------------------------------
703-
DOCUMENTATION *libmodal-contributing-documentation*
703+
--------------------------------------------------------------------------------
704+
DOCUMENTATION *libmodal-contributing-documentation*
704705

705706
If there is a problem with the documentation, or you see an area where it
706707
could be improved, don't hesitate to submit an issue and a PR. At the very
707708
least it will exist in history if such an issue comes up again, and likely it
708709
will serve to help yourself and others with more clear and concise wording, or
709710
with more helpful and practical examples.
710711

711-
------------------------------------------------------------------------------
712-
ISSUES *libmodal-contributing-issues*
712+
--------------------------------------------------------------------------------
713+
ISSUES *libmodal-contributing-issues*
713714

714715
Issues are greatly welcomed on the GitHub repository, whether they are bug
715716
reports, feature requests, documentation improvements, or misunderstandings:
@@ -724,8 +725,18 @@ When submitting an issue, please describe the following:
724725
4. Expected behavior (if applicable).
725726
5. Attached media (screenshots, logs, etc.) (if applicable).
726727

727-
==============================================================================
728-
8. Changelog *libmodal-changelog*
728+
================================================================================
729+
8. Changelog *libmodal-changelog*
730+
731+
0.8.0 ~
732+
733+
Additions: ~
734+
* Ability to use |lua| `function`s as values in a |libmodal-mode|
735+
{instruction} `table` .
736+
* Ability to use |lua| `function`s as values in a |libmodal-prompt|
737+
{instruction} `table` .
738+
* Add |libmodal-mode| and |libmodal-prompt| kill functions
739+
(|libmodal-lua-utils-exit|).
729740

730741
0.7.0 ~
731742

@@ -837,8 +848,8 @@ When submitting an issue, please describe the following:
837848
0.3.1 ~
838849

839850
Fixes: ~
840-
* Fix bug where everytime `api.nvim_lecho()` was called, its {hlTables} would
841-
infinitely grow with placeholder "None" entries.
851+
* Fix bug where everytime `api.nvim_lecho()` was called, its {hlTables}
852+
would infinitely grow with placeholder "None" entries.
842853

843854
0.3.0 ~
844855

@@ -866,8 +877,8 @@ When submitting an issue, please describe the following:
866877
Additions: ~
867878
* |libmodal-mode| implementation from |vim-libmodal|.
868879

869-
==============================================================================
870-
9. Credits *libmodal-credits*
880+
================================================================================
881+
9. Credits *libmodal-credits*
871882

872883
Credit Reason
873884
--------------------- ----------------------------------
@@ -883,5 +894,5 @@ u/oryiesis Inspiration.
883894
www.lua-users.org |Lua| reference.
884895
www.stackoverflow.com Vimscript and |Lua| reference.
885896

886-
==============================================================================
887-
vim:tw=78:ts=4:ft=help:norl:
897+
================================================================================
898+
vim:tw=80:ts=4:ft=help:norl:

examples/lua/key-combos-submode.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ function FooMode()
1515
fooModeRecurse = fooModeRecurse - 1
1616
end
1717

18+
-- Define the character 'f' as the function we defined— but directly through lua, instead of vimL.
19+
fooModeCombos['f'] = FooMode
20+
1821
-- Call FooMode() initially to begin the demo.
1922
FooMode()

examples/lua/key-combos.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
-- Imports
22
local libmodal = require('libmodal')
33

4+
-- A function which will split the window both horizontally and vertically.
5+
local function _split_twice()
6+
local cmd = vim.api.nvim_command
7+
cmd('split')
8+
cmd('vsplit')
9+
end
10+
411
-- Register key combos for splitting windows and then closing windows
512
local fooModeCombos = {
613
['zf'] = 'split',
714
['zfo'] = 'vsplit',
8-
['zfc'] = 'q'
15+
['zfc'] = 'q',
16+
['zff'] = _split_twice
917
}
1018

1119
-- Enter the mode using the key combos.

examples/lua/prompt-commands.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ local libmodal = require('libmodal')
55
local commands = {
66
['new'] = 'tabnew',
77
['close'] = 'tabclose',
8-
['last'] = 'tablast'
8+
['last'] = 'tablast',
9+
['exit'] = libmodal.utils.api.mode_exit
910
}
1011

1112
-- Begin the prompt.

0 commit comments

Comments
 (0)