Visual indicator of next jump
I'm very interested in having an indicator of where Luasnip will jump to next (assuming there are no expansions available at the cursor). This indicator could be a token such as * and it should be updated once jumps or expansions happen. This would be useful in many languages such as latex, where snippets get nested and it is easy to get confused about where the cursor is going to jump to next.
Here's an example, where | indicates current cursor, * indicates next jump and I'm assuming a snippet that expands $ into $|$* and another one that expands fr into \frac{|}{*}:
My fraction is $ -> [expand]
My fraction is $|$* -> [write "fr"]
My fraction is $fr|$* -> [expand]
My fraction is $\frac{|}{*}$ -> [write "fr"]
My fraction is $\frac{fr|}{*}$ -> [expand]
My fraction is $\frac{\frac{|}{*}}{}$ -> [write "3", jump, write "4"]
My fraction is $\frac{\frac{3}{4|}}{*}$ -> [jump, write "5"]
My fraction is $\frac{\frac{3}{4}}{5|}*$ -> [jump]
My fraction is $\frac{\frac{3}{4}}{5}|$* -> [jump]
My fraction is $\frac{\frac{3}{4}}{5}|$
Is it possible/straightforward to implement this? I suspect #676 is helpful, but I can't figure out how to do it.
Cool idea!
You could replace jump with a function which
- removes previous marker
- jumps
- sets next marker
The main issue are the markers: they have to move with text. This can be achieved with extmarks and virtual text once this PR is merged, until then you'd have to place the text of the mark manually (nvim_buf_set_text) and place an extmark on top of it.
Set next marker would then be
- find position of next jump
- insert marker-text
- put extmark over text (they can have a beginning and end), make sure the gravities are set correctly ("inwards", so that they exactly delimit the inserted text), and store the extmarks id
And remove previous marker would be
- get range of previous extmarks id in buffer
- remove text present there (
buf_set_textto empty string)
What's missing, a bit, in that description is how the initial mark should be handled. Modifying expand such that it removes the old marks, if any are present, and then places the new one should work just fine.
(Modifying expand in this case would mean replacing ls.snip_expand with a function which handles the marks and calls the original ls.snip_expand)