Merge pull request #6 from Iron-E/feature/vim-libmodal-compatability
Feature/vim libmodal compatabilitypull/7/head release/0.7.0
commit
00b5b38204
@ -0,0 +1,36 @@
|
|||||||
|
" Keep track of the user's input history manually.
|
||||||
|
let s:inputHistory = []
|
||||||
|
|
||||||
|
" Clear the input history if it grows too long for our usage.
|
||||||
|
function! s:clear(indexToCheck) abort
|
||||||
|
if len(s:inputHistory) > a:indexToCheck
|
||||||
|
for i in range(len(s:inputHistory))
|
||||||
|
let s:inputHistory[i] = v:null
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" This is the function that will be called whenever the user presses a button.
|
||||||
|
function! s:fooMode() abort
|
||||||
|
" Append to the input history, the latest button press.
|
||||||
|
let s:inputHistory = add(s:inputHistory, nr2char(g:fooModeInput)) " The input is a character number.
|
||||||
|
|
||||||
|
" Custom logic to test for each character index to see if it matches the 'zfo' mapping.
|
||||||
|
let l:index = 0
|
||||||
|
if s:inputHistory[0] == 'z'
|
||||||
|
if get(s:inputHistory, 1, v:null) == 'f'
|
||||||
|
if get(s:inputHistory, 2, v:null) == 'o'
|
||||||
|
echom 'It works!'
|
||||||
|
else
|
||||||
|
let l:index = 2
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let l:index = 1
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
call s:clear(l:index)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Enter the mode to begin the demo.
|
||||||
|
lua require('libmodal').mode.enter('FOO', 's:fooMode')
|
@ -1,14 +1,18 @@
|
|||||||
|
" Recurse counter.
|
||||||
let s:barModeRecurse = 0
|
let s:barModeRecurse = 0
|
||||||
|
|
||||||
|
" Register 'z' as the map for recursing further (by calling the BarMode function again).
|
||||||
let s:barModeCombos = {
|
let s:barModeCombos = {
|
||||||
\ 'z': 'BarModeEnter',
|
\ 'z': 'BarModeEnter',
|
||||||
\}
|
\}
|
||||||
|
|
||||||
|
" define the BarMode() function which is called whenever the user presses 'z'
|
||||||
function! s:BarMode()
|
function! s:BarMode()
|
||||||
let s:barModeRecurse += 1
|
let s:barModeRecurse += 1
|
||||||
call libmodal#Enter('BAR' . s:barModeRecurse, s:barModeCombos)
|
call libmodal#Enter('BAR' . s:barModeRecurse, s:barModeCombos)
|
||||||
let s:barModeRecurse -= 1
|
let s:barModeRecurse -= 1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Call BarMode() initially to begin the demo.
|
||||||
command! BarModeEnter call s:BarMode()
|
command! BarModeEnter call s:BarMode()
|
||||||
execute 'BarModeEnter'
|
execute 'BarModeEnter'
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
|
" Register key combos for splitting windows and then closing windows
|
||||||
let s:barModeCombos = {
|
let s:barModeCombos = {
|
||||||
\ 'zf': 'split',
|
\ 'zf': 'split',
|
||||||
\ 'zfo': 'vsplit',
|
\ 'zfo': 'vsplit',
|
||||||
\ 'zfc': 'q'
|
\ 'zfc': 'q'
|
||||||
\}
|
\}
|
||||||
|
|
||||||
|
" Enter the mode using the key combos.
|
||||||
call libmodal#Enter('BAR', s:barModeCombos)
|
call libmodal#Enter('BAR', s:barModeCombos)
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
" Create a new layer.
|
||||||
|
let s:layer = {
|
||||||
|
\ 'n': {
|
||||||
|
\ 'gg': {
|
||||||
|
\ 'rhs': 'G',
|
||||||
|
\ 'noremap': v:true,
|
||||||
|
\ },
|
||||||
|
\ 'G': {
|
||||||
|
\ 'rhs': 'gg',
|
||||||
|
\ 'noremap': v:true
|
||||||
|
\ }
|
||||||
|
\ }
|
||||||
|
\}
|
||||||
|
|
||||||
|
" Capture the exit function
|
||||||
|
let s:exitFunc = luaeval("require('libmodal').layer.enter(_A)", s:layer)
|
||||||
|
|
||||||
|
" Call the exit function in 5 seconds.
|
||||||
|
call timer_start(5000, s:exitFunc)
|
@ -1,14 +1,19 @@
|
|||||||
|
-- Imports
|
||||||
local libmodal = require('libmodal')
|
local libmodal = require('libmodal')
|
||||||
|
|
||||||
|
-- Recurse counter.
|
||||||
local fooModeRecurse = 0
|
local fooModeRecurse = 0
|
||||||
|
-- Register 'z' as the map for recursing further (by calling the FooMode function again).
|
||||||
local fooModeCombos = {
|
local fooModeCombos = {
|
||||||
['z'] = 'lua FooMode()'
|
['z'] = 'lua FooMode()'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- define the FooMode() function which is called whenever the user presses 'z'
|
||||||
function FooMode()
|
function FooMode()
|
||||||
fooModeRecurse = fooModeRecurse + 1
|
fooModeRecurse = fooModeRecurse + 1
|
||||||
libmodal.mode.enter('FOO' .. fooModeRecurse, fooModeCombos)
|
libmodal.mode.enter('FOO' .. fooModeRecurse, fooModeCombos)
|
||||||
fooModeRecurse = fooModeRecurse - 1
|
fooModeRecurse = fooModeRecurse - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Call FooMode() initially to begin the demo.
|
||||||
FooMode()
|
FooMode()
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
|
-- Imports
|
||||||
local libmodal = require('libmodal')
|
local libmodal = require('libmodal')
|
||||||
|
|
||||||
|
-- Register key combos for splitting windows and then closing windows
|
||||||
local fooModeCombos = {
|
local fooModeCombos = {
|
||||||
['zf'] = 'split',
|
['zf'] = 'split',
|
||||||
['zfo'] = 'vsplit',
|
['zfo'] = 'vsplit',
|
||||||
['zfc'] = 'q'
|
['zfc'] = 'q'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Enter the mode using the key combos.
|
||||||
libmodal.mode.enter('FOO', fooModeCombos)
|
libmodal.mode.enter('FOO', fooModeCombos)
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
|
-- Import
|
||||||
local libmodal = require('libmodal')
|
local libmodal = require('libmodal')
|
||||||
|
|
||||||
|
-- Define commands through a dictionary.
|
||||||
local commands = {
|
local commands = {
|
||||||
['new'] = 'tabnew',
|
['new'] = 'tabnew',
|
||||||
['close'] = 'tabclose',
|
['close'] = 'tabclose',
|
||||||
['last'] = 'tablast'
|
['last'] = 'tablast'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Begin the prompt.
|
||||||
libmodal.prompt.enter('FOO', commands)
|
libmodal.prompt.enter('FOO', commands)
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
" This is the list of commands— used for auto completion.
|
||||||
|
let s:commandList = ['new', 'close', 'last']
|
||||||
|
|
||||||
|
" This function will be called whenever a command is entered.
|
||||||
|
function! s:fooMode() abort
|
||||||
|
let l:userInput = g:fooModeInput
|
||||||
|
if userInput == 'new'
|
||||||
|
tabnew
|
||||||
|
elseif userInput == 'close'
|
||||||
|
tabclose
|
||||||
|
elseif userInput == 'last'
|
||||||
|
tablast
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" You have to convert s:commandList from a Vimscript list to a lua table using luaeval().
|
||||||
|
call luaeval("require('libmodal').prompt.enter('FOO', 's:fooMode', _A)", s:commandList)
|
@ -0,0 +1,21 @@
|
|||||||
|
" This is a counter.
|
||||||
|
let s:fooModeRecurse = 1
|
||||||
|
|
||||||
|
" This is a function to increase the counter every time that 'z' is pressed.
|
||||||
|
function! s:fooMode() abort
|
||||||
|
let l:userInput = nr2char(g:foo{s:fooModeRecurse}ModeInput)
|
||||||
|
|
||||||
|
if l:userInput == 'z'
|
||||||
|
let s:fooModeRecurse += 1
|
||||||
|
call s:enter()
|
||||||
|
let s:fooModeRecurse -= 1
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" This function wraps around calling libmodal so that the other function can recursively call it.
|
||||||
|
function! s:enter() abort
|
||||||
|
call luaeval("require('libmodal').mode.enter('FOO'.._A, 's:fooMode')", s:fooModeRecurse)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Begin the recursion.
|
||||||
|
call s:enter()
|
Loading…
Reference in New Issue