kana / vim-submode

Vim plugin: Create your own submodes
http://www.vim.org/scripts/script.php?script_id=2467
217 stars 24 forks source link

Public interface to enter and leave submodes #17

Open LFDM opened 10 years ago

LFDM commented 10 years ago

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.

kana commented 10 years ago

Why such API is necessary? Do you have any real-life example that you need them?

LFDM commented 10 years ago

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.

LFDM commented 10 years ago

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.

isovector commented 9 years ago

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
masaeedu commented 5 years ago

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.

masaeedu commented 5 years ago

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).