-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shallowly switching between libmodal modes #28
Comments
My thinking about it is like this:
I opened a PR for this :) local M = {}
M.mode1 = {
m = function()
vim.notify('Mode 1')
end,
n = function(self)
require('libmodal').mode.enter('My mode 2', M.mode2)
self:exit()
end
}
M.mode2 = {
m = function()
vim.notify('Mode 2')
end,
n = function(self)
require('libmodal').mode.enter('Mode 1', M.mode1)
self:exit()
end
}
vim.keymap.set('n', 'M', function()
require('libmodal').mode.enter('Mode 1', M.mode1)
end) |
Calling autocmd ModeChanged customMode1:customMode2 ... Since your solution switches custom modes via normal mode they would have to listen for One alternative solution that might be a little cleaner API-wise could be to add a new What do you say? Would that be possible to implement? 🙂 |
I'm sure something like what you describe could be implemented— I just want to make sure I understand the details first.
tl;dr: if it's exiting to normal before entering the new mode, that's a bug, and if it's happening to you I'll fix it 😁 Just to be clear,
So, to annotate the example above: { -- Foo mode
n = function(self)
-- enter Bar mode
libmodal.mode.enter('Bar', keymap)
-- Bar mode has exited
-- flag Foo mode to exit instead of taking input again
self:exit()
end,
} Because of this, Thus
Which of these suits your needs best? -- 1. Swap means "enter another mode and after it exits, exit the current mode"
libmodal.mode.swap = function(...)
return function(self)
libmodal.mode.enter(...)
self:exit()
end
end -- 2. Swap means "exit the current mode, and then enter a new mode"
libmodal.mode.swap = function(...)
return function(self)
self:exit(function() -- ← this doesn't work right now, just bikeshedding!
libmodal.mode.enter(...)
end)
end
end |
Ah, you're right!
I'm not sure what the difference would be between the two, but to me the latter one makes more sense semantically since it first exit, then enter the next mode, right? Would there be any difference in behaviour between the two versions? |
Ultimately the big difference will be in the { -- Foo mode
-- `swap` v1
n = function(self)
libmodal.mode.enter('Bar', {})
self:exit()
end,
-- `swap` v2
m = function(self)
self:exit(function() -- ← again, this is hypothetical
libmodal.mode.enter('Bar', {})
end)
end,
} Entering this mode (from Normal) emits
|
Hmm, I think both version should work for me so v1 is probably fine. What do you think? 🙂 |
I'll implement version one, it seems the simplest 👍 |
Hi agan! I'm trying to switch between multiple libmodal modes. However, exiting libmodal seems to require one
<Esc>
press per mode switched. My expected behaviour is that pressing<Esc>
would immediately take me to Normal mode, just like how all Vim modes work. Do you agree? If not, is there some other way to exitlibmodal
? There doesn't seem to be arequire('libmodal').mode.exit()
that I can create a mapping for 🙂To reproduce:
M
to enter Mode 1m
: "Mode 1" is notifiedn
n
to enter Mode 2m
: "Mode 2" is notified<Esc>
twice to reach Normal modeThe text was updated successfully, but these errors were encountered: