Open LFDM opened 10 years ago
Why such API is necessary? Do you have any real-life example that you need them?
Let's say I use CtrlP
and have a submode defined that jumps between tags. I start a tag search with :CtrlPTag
and there are multiple tags matching my query. I could be immediately dropped off inside my tag handling submode then.
Two more examples.
I have a file where I made several changes in different places, but they don't belong in a single commit. I use the GitGutter
to jump between the changed hunks, of course inside a submode. With this submode I can stage or revert individual hunks. A very common workflow is to stage a hunk, go to fugitive (triggered by a submode mapping) and commit the work. After that I'd like to go to the next hunk, stage it, commit... But fugitive threw me out of my submode. So I could write a function that brings me back again.
A leave
function would be handy in case there are in fact no changes in the file I try to jump through with gitgutter (I might be inside the wrong buffer by mistake for example). I enter the submode, nothing happens, the submode leaves by itself because it detects that there is nothing to go to. (I know I could workaround such things, but it would be much cleaner to have an actual function to go to)
Submode could be facilitated in plugin programming with these functions more easily as well, basically providing an api for temporarily remapping keys on certain events. Image submodes that have no enter_with
mapping defined at all, which only get called directly in certain conditions from a plugin.
I want this to be able to use :map-operator in a submode. As it is, movement commands get cleared, so there is no way to give movement to an operator.
Example
call submode#map('mymode', 'n', 's', 's', ':leave<CR>:set opfunc=mymode#sendmove<CR>g@')
function! mymode#sendmove(...)
" handle the operator
call enter
endfunction
It'd be nice to be able to do recursive submodes. For example I have a submode for all my window navigation, but it's sort of awkward to flatten conceptual subdomains like "window resizing", "window reshuffling", etc. into a single submode.
If I could hit r
inside the window navigation submode to enter the "window resizing" submode, or m
to enter the "window movement" submode, that would make the mnemonics a bit easier.
Sorry, forgot to mention why this is relevant to the issue. If we could do :call entersomemode
as one of the mappings for a submode, I think that would provide some primitive support for recursive submodes (although you wouldn't be popped back to the outer submode when you hit the key to leave the submode).
Two public utility functions/commands could help in scripting submodes. I think there is currently no real way to do this from outside the submode plugin and even inside of it you have to fake it a bit.